Skip to content

Instantly share code, notes, and snippets.

View garth's full-sized avatar

Garth Williams garth

View GitHub Profile
@garth
garth / vlcrc.js
Created October 5, 2011 21:30
Remote control multiple VLC apps via the command line using nodejs
// To start vlc with telnet remote control:
// ./VLC --extraintf rc --rc-host 0.0.0.0:3000
//
// To connect to multiple vlc's
// node vlcrc.js host1:3000 host2:3000
var net = require('net');
var readline = require('readline');
//addresses of servers
@garth
garth / gist:1388969
Created November 23, 2011 15:29
Convert url image ref into inline base 64 in css with nodejs
var css = 'insert lots of css here';
var files = {};
css = css.replace(/url\((\S*)\.(png|jpg|jpeg|gif)\)/g, function(match, file, type)
{
var fileName = file + '.' + type;
var size = fs.statSync(fileName).size;
if (size > 4096) {
console.log('Skipping ' + fileName + ' (' + (Math.round(size/1024*100)/100) + 'k)');
return match;
@garth
garth / template.js
Created November 30, 2011 14:15
Use requirejs to dynamically load sproutcore20 handlebars templates
// dynamically load sproutcore20 handlebars templates
// add this file to the same dir as your data-main js to load a template as a dependency do
//
// define(['template!template'] function(){
// //do some SproutCore[ing]
// });
//
// templates should be located in templates folder and have a .handlebars extension
// removed partial support {{> partial}} which doesn't work in SC.Handlebars use
@garth
garth / Jakefile.js
Created December 1, 2011 12:06
Example Jakefile from ViennaJS meetup
// Jake is like Rake for nodejs https://github.com/mde/jake
//
// Assumes that Jake will be run in the root of the web app with coffee files in /js/ and
// a single app.less file in /css/ that can include references to other .less files
//
//requires
var sys = require('util');
var execute = require('child_process').exec;
var fs = require('fs');
@garth
garth / handlebars-defined-helper.js
Created December 1, 2011 14:05
Handlebars block helper for only outputting when a property is defined
// only output the block if the object property exists/is defined
//
// {{#defined property}}
// Property exists
// {{/defined}}
Handlebars.registerHelper('defined', function(property, block) {
return typeof(this[property]) !== 'undefined' ? block(this) : '';
});
@garth
garth / Jakefile.js
Created January 16, 2012 18:37 — forked from wagenet/Assetfile.rb
Precompile .handlebars templates with Jake (nodejs)
var fs = require('fs')
var vm = require('vm')
var handlebarsjs = fs.readFileSync('path/to/handlebars.js', 'utf8')
var emberjs = fs.readFileSync('path/to/ember.js', 'utf8')
var templatesDir = 'path/to/template/dir'
desc('Compile all .handlebars templates')
task({ 'handlebars': [] }, function () {
process.stdout.write('Compiling .handlebars templates')
@garth
garth / gist:2477814
Created April 24, 2012 08:19
Configure IIS for iisnode
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<!-- stop IIS from replacing non 200 response bodies -->
<httpErrors existingResponse="PassThrough" />
<!-- send all incoming requests to nodejs -->
@garth
garth / log.js
Created May 1, 2012 19:36
Wasted quite a bit of time today trying to get flatiron winston configured with custom levels and colors, so here's a working sample.
var winston = require('winston')
require('winston-mongodb')
// prepare some custom log levels
var customLevels = {
levels: {
debug: 0,
info: 1,
warning: 2,
error: 3
@garth
garth / AutoCompleteIndex.cs
Created June 21, 2012 11:01
Create a fast auto complete index in memory with optional Soundex
/// <summary>
/// Creates a fast lookup for auto complete lists
/// </summary>
/// <typeparam name="T">Object type to to lookup</typeparam>
public class AutoComplete<T> {
private Dictionary<int, List<KeyValuePair<T, int>>> directory = new Dictionary<int, List<KeyValuePair<T, int>>>();
private int minMatchLength;
private bool enableSoundexMatching;
/// <summary>
@garth
garth / run-mocha.js
Created July 10, 2012 09:19 — forked from joeytrapp/run-mocha.js
JavaScript: PhantomJS Mocha Scrapper
/*global phantom:true, console:true, WebPage:true, Date:true*/
(function () {
var url, timeout, page, defer;
if (phantom.args.length < 1) {
console.log("Usage: phantomjs run-mocha.js URL [timeout]");
phantom.exit();
}
url = phantom.args[0];