Skip to content

Instantly share code, notes, and snippets.

View vasanthk's full-sized avatar

Vasa vasanthk

View GitHub Profile
@vasanthk
vasanthk / squash-pr-commits-to-one.txt
Last active August 29, 2015 14:23
Squash PR commits into a single commit
git fetch upstream
git checkout mybranch
git merge upstream/master
# if necessary, resolve conflicts and git commit
# ...
git reset --soft upstream/master
git commit -am 'Some cool description for a single commit'
git push -f
App Life Cycles
- Response
- Animations
- Idle
- Load (XHR, Websockets, HTML imports)
In Chronological Order:
Load (~1 sec) Initial page load
Idle (~ 50ms) Lazy load items
Response (~100ms) On interaction, respond within 100ms
@vasanthk
vasanthk / react-folder-structure.md
Last active November 30, 2023 14:29 — forked from ryanflorence/folder-structure.md
React Folder Structure

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I lead the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can'

@vasanthk
vasanthk / constants-es5.js
Last active January 11, 2021 13:28
Constants in ES5 - How does this work?
'use strict';
// define favorite as a non-writable `constant` and give it the value 7
Object.defineProperties(window, {
favorite: {
value: 7,
enumerable: true
}
});
// ^ descriptors are by default false and const are enumerable
var favorite = 7;
@vasanthk
vasanthk / git-log-json.md
Created July 12, 2015 07:16
Git log in JSON format

Get Git log in JSON format

git log --pretty=format:'{%n  "commit": "%H",%n  "abbreviated_commit": "%h",%n  "tree": "%T",%n  "abbreviated_tree": "%t",%n  "parent": "%P",%n  "abbreviated_parent": "%p",%n  "refs": "%D",%n  "encoding": "%e",%n  "subject": "%s",%n  "sanitized_subject_line": "%f",%n  "body": "%b",%n  "commit_notes": "%N",%n  "verification_flag": "%G?",%n  "signer": "%GS",%n  "signer_key": "%GK",%n  "author": {%n    "name": "%aN",%n    "email": "%aE",%n    "date": "%aD"%n  },%n  "commiter": {%n    "name": "%cN",%n    "email": "%cE",%n    "date": "%cD"%n  }%n},'

The only information that aren't fetched are:

  • %B: raw body (unwrapped subject and body)
  • %GG: raw verification message from GPG for a signed commit
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@vasanthk
vasanthk / reduce.js
Created July 24, 2015 21:42
Using reduce(), instead of filter() and map()
tollCountries = phoneNumbers.reduce(function(countries, nums) {
if(!num.tollFree) {
countries.push({
// Push it in whatever format you need it.
})
}
return countries;
}, [])
@vasanthk
vasanthk / ReduxMicroBoilerplate.js
Last active August 29, 2015 14:26 — forked from gaearon/ReduxMicroBoilerplate.js
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@vasanthk
vasanthk / react-autobinding.md
Last active September 15, 2015 18:15
AutoBinding in React

AutoBinding in React

Just for quicker reference from here

1. ES5 (No class)

var Button = React.createClass({
  handler:function(e){
   ....
  },