Skip to content

Instantly share code, notes, and snippets.

View TheSavior's full-sized avatar

Eli White TheSavior

View GitHub Profile
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
@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 / gist:4557808
Created January 17, 2013 17:36
Qth Largest element in an array
<?php
/*
INPUT:
- an unsorted array of integers, A
- an integer q, where 0 < q <= A.size
OUTPUT:
- find the q_th smallest element in A
@TheSavior
TheSavior / gist:4560896
Created January 17, 2013 23:31
Print array in spiral
<?php
// $a[0] = [ 1, 2, 3, 4]
// $a[1] = [ 5, 6, 7, 8]
// $a[2] = [ 9, 10, 11, 12]
// $a[3] = [13, 14, 15, 16]
// 1 2 3 4 8 12 11 10 9 5 6 7
/*
0,0 3,2
@TheSavior
TheSavior / gist:4561325
Created January 18, 2013 00:46
Check if the edit distance between two words is 1
<?php
/*
d = ['cat', 'cats', 'bat', 'beetle']
similar(q, d):
....
returns all words from d with edit distance 1
similar('cat', d) --> ['cat', 'cats', 'bat']
@TheSavior
TheSavior / gist:4758988
Created February 12, 2013 00:32
Difference between integers = k
/*Question:
Given a non-negative integer k and an array a containing random integers, determine the number of instances where two integers in the array have a numerical difference of k.
Do not assume anything about the given inputs unless it is strictly stated.
Example 1:
k = 4
a = [ 1, 1, 5, 6, 9, 16, 27]
@TheSavior
TheSavior / gist:5010053
Created February 22, 2013 01:28
Clear music folder of empty folders (or ones with stupid hidden files)
Get-ChildItem –Recurse –Include *.jpg,Desktop.ini,thumbs.db –Force | Remove-Item -force #–whatif
# pulled from http://guyellisrocks.com/powershell/powershell-script-to-remove-empty-directories/
$items = Get-ChildItem -Recurse
foreach($item in $items)
{
if( $item.PSIsContainer )
{
$subitems = Get-ChildItem -Recurse -LiteralPath $item.FullName
if($subitems -eq $null)
@TheSavior
TheSavior / .gitconfig
Created February 10, 2016 02:23
Git Aliases
[alias]
cleanup = "!git branch --merged | grep -v '\\*\\|master' | xargs -n 1 git branch -d && git remote prune origin"
cleanup-remote = "!git branch -r --merged | grep origin | grep -v '>' | grep -v master | xargs -L1 | cut -d"/" -f2- | xargs git push origin --delete"
old-branches = "!git for-each-ref --sort=committerdate --format='%1B[1;34m %(authordate:relative) %1B[m %(refname:short) %1B[1;32m%(authorname)%1B[m' refs/remotes"