Skip to content

Instantly share code, notes, and snippets.

View TheSavior's full-sized avatar

Eli White TheSavior

View GitHub Profile
@TheSavior
TheSavior / gist:5bff50474be2dd622b81
Last active August 29, 2015 14:14
Block spacing

Require a blank line after blocks.

Valid
function () {
    for (var i = 0; i < 2; i++) {
        if (true) {
            return false;
        }
@TheSavior
TheSavior / gist:253441fd8b503a30c79e
Created March 15, 2015 01:08
Get common git sha ancestor between a sha and a branch
getCommonAncestor: function(headSha, baseBranch) {
return new Bluebird(function(resolve) {
var command = "bash -c 'diff -u <(git rev-list --all " + headSha + ") "+
"<(git rev-list --first-parent " + baseBranch+")' "+
"| sed -ne 's/^ //p' | head -1";
execute(command, function(data) {
resolve(data);
});
});
@TheSavior
TheSavior / SassMeister-input.scss
Created August 17, 2015 17:00
Generated by SassMeister.com.
// ----
// libsass (v3.2.5)
// ----
$placeholder-name: 'foo';
@for $i from 1 through 4 {
%#{$placeholder-name}-#{$i} {
content: $i;
}
@TheSavior
TheSavior / exposeAdd.js
Last active October 13, 2015 16:32
Test Expose add and add2
var privateState = require('privatestate');
var utils = require('./utils');
describe('utils#add', function() {
it('should add two numbers', function() {
var add = privateState.getForTesting(utils, 'add');
var actual = add(2, 4);
assert.equal(actual, 6);
});
});
@TheSavior
TheSavior / exposeFunctions.js
Last active October 13, 2015 16:33
Expose helpers on functions
'use strict';
var privateState = require('privatestate');
function nameHelper(first, last) {
return first + ' ' + last;
}
function Person(first, last) {
this.first = first;
@TheSavior
TheSavior / exposePrivateFuncs.js
Last active October 13, 2015 16:33
Expose private functions object
var privateState = require('privatestate');
function formatString(date) {
return date.toDateString();
}
var Utils = {
getDateString: function(date) {
return 'today is ' + formatString(date);
}
@TheSavior
TheSavior / testPrivateFunctions.js
Last active October 12, 2015 22:31
Test Private Functions
var privateState = require('private-state');
var sinon = require('sinon');
var utils = require('./utils');
describe('utils#getDateString', function() {
it('should print value from formatString', function() {
var stub = sinon.stub().returns('today');
privateState.setFunctionForTesting(utils, 'formatString', stub);
var now = new Date(2015, 1, 1);
var Helper = {
msg: 'from helper'
};
module.exports = Helper;
var helper1 = require('./helper');
var Utils = {
getString: function() {
return helper1.msg;
}
};
module.exports = Utils;
var proxyquire = require('proxyquire');
describe('utils#getString', function() {
it('should print helper.msg', function() {
var HelperStub = {
msg: 'stub msg'
};
var utils = proxyquire('../server/utils', {
'./helper': HelperStub