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 / Contiguous max
Created November 12, 2012 07:08
Calculate the maximum sum from a contiguous array of ints
class Program
{
static void Main(string[] args)
{
int[] nums = new int[] { 1, 4, -6, 2, 4, -1, 3 };
bigSum(nums);
return;
}
@TheSavior
TheSavior / Breadth First
Created November 12, 2012 07:26
Breadth First Traversal
class Program
{
static void Main(string[] args)
{
Node node = new Node(5);
var n2 = new Node(2);
node.Children.Add(n2);
var n4 = new Node(16);
@TheSavior
TheSavior / Program.cs
Created November 13, 2012 18:47
Fibonacci with Memoization
class Program
{
static Dictionary<int, int> nums;
static void Main(string[] args)
{
int testNum = 35;
int loops = 20;
nums = new Dictionary<int, int>();
@TheSavior
TheSavior / gist:4082450
Created November 15, 2012 23:44
Simple Regex Parsing
/*Implement a function which answers whether a given string matches a provided pattern. The pattern is written in a small regex-like language, consisting of:
- Lowercase latin characters (a to z)
- . (dot), which matches any latin character.
- *, indicates that the previous character is repeated 0 or more times.
- +, indicates that the previous character is repeated 1 or more times.
You can assume that the input pattern is well formed and the string to match consists of lowercase latin characters only.
Examples:
@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 helper1 = require('./helper');
var Utils = {
getString: function() {
return helper1.msg;
}
};
module.exports = Utils;
var Helper = {
msg: 'from helper'
};
module.exports = Helper;