Skip to content

Instantly share code, notes, and snippets.

@willm
willm / closure.js
Created June 14, 2012 19:48
closure in JS
var whatever = (function(that){
return function(){
//do stuff and enjoy access to the passed context via 'that'
}
}(this));
@willm
willm / webrequest.js
Created June 19, 2012 20:25
make web request in node
var http = require('http');
var req = http.request({host:'www.google.com',port:80,method: 'GET'},
function(res){
console.log('Status Code : %s', res.statusCode);
res.setEncoding('utf8');
res.on('data', function(chunk){
console.log(chunk);
});
});
@willm
willm / Stubbing config values
Last active October 11, 2015 13:27
Stubing Config Values
static void StubKeyInConfig(string appSettingsKey, string appSettingsValue)
{
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add(appSettingsKey, appSettingsValue);
config.Save();
ConfigurationManager.RefreshSection("appSettings");
}
@willm
willm / paths.md
Last active October 18, 2016 16:35
path to config files

Hosts file on windows

%systemroot%\system32\drivers\etc\

Docker config on ubuntu

/lib/systemd/system/docker.service

@willm
willm / gist:6080936
Created July 25, 2013 15:33
Spy function
var pSlice = Array.prototype.slice;
function createSpy(fn) {
function spy() {
// clone and coerce arguments into an array
var spiedArgs = pSlice.call(arguments);
// remember the arguments the spy was called with
spy.calls.push(spiedArgs);
// call the "behaviour" function passed when creating this
@willm
willm / Columns by name
Last active December 25, 2015 04:09
find all columns by name
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'YOUR_NAME_HERE'
@willm
willm / Serve current directory
Created October 10, 2013 23:10
starts a http server serving the current working directory.
python -m SimpleHTTPServer
@willm
willm / write as root
Created October 17, 2013 22:18
write a file as root
:w !sudo tee %
@willm
willm / global npm module location on windows (7)
Created December 17, 2013 16:24
global npm module location on windows (7)
C:\Users\william\AppData\Roaming\npm
@willm
willm / tabs to spaces
Created January 13, 2014 00:17
converts all tabls to 4 spaces in all python files in the current directory
find . -name "*.py" ! -type d -exec bash -c 'expand -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \;