Skip to content

Instantly share code, notes, and snippets.

;; packages
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("org" . "http://orgmode.org/elpa/")
("marmalade" . "http://marmalade-repo.org/packages/")
("melpa-stable" . "http://melpa-stable.milkbox.net/packages/")))
(package-initialize)
(defun require-package (package)
(setq-default highlight-tabs t)
"Install given PACKAGE."
From here:
C1 - C2 - C3 - (revert C1-C3) - C4 (master)
To here:
C1 - C2 - C3 - (revert C1-C3) - C4
\
C1' - C2' - C3' (branch)

Conditionals

Use variables to describe what the conditional is about. For example

    # Bad
    if _.empty users
      ...
    
 # Good
var _ = require('underscore');
var splitInFour = function(arr) {
return splitInFourWithAccum(arr, []);
}
var splitInFourWithAccum = function(arr, accum) {
if (arr.length === 0) {
return accum;
} else {
var newAccum = accum.slice();
function escapeCharactersCallback(wholeMatch, m1) {
'use strict';
var charCodeToEscape = m1.charCodeAt(0);
return '~E' + charCodeToEscape + 'E';
}
var escapeCharacters = function escapeCharacters(text, charsToEscape, afterBackslash) {
'use strict';
var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
var runAfterOneSecond = function(cb) { setTimeout(cb, 1000); }
var a = {
getVal: function() {
return this.val;
},
setVal: function(val) {
this.val = val;
}
};
var runAfterOneSecond = function(cb) { setTimeout(cb, 1000); }
var a = {
getVal: function() {
return this.val;
},
setVal: function(val) {
this.val = val;
}
};
var a = {
getVal: function() {
return this.val;
},
setVal: function(val) {
this.val = val;
}
};
function printVal() {

When you begin working on a feature

Step 1: Update the main branch

   git checkout master
   git pull origin master

Step 2: Create a feature branch off of the main branch

function simpleMerge(dict1, dict2) {
return _.extend(dict1, _.extend(dict2, {}));
}