Skip to content

Instantly share code, notes, and snippets.

View ngmaloney's full-sized avatar

Nick Maloney ngmaloney

View GitHub Profile
@ngmaloney
ngmaloney / gist:1473603
Created December 13, 2011 19:55
Nodeshot calling shell script
var cmd = './lib/bin/nodeshot ' + remote_url + ' ' + path + filename + ' ' + width + 'x' + height;
child = exec(cmd, {timeout: 20000}, function(error, stdout, stderr) {
//handler code here
}
@ngmaloney
ngmaloney / gist:1260782
Created October 4, 2011 02:38
RetentionCalculator
function retentionCalculator(opts) {
var opts = opts || {};
this.init = function(opts) {
this.price = opts.price || 300; //Product Price
this.margin = opts.margin || 0.085; //Profit Margin
this.cost = opts.cost || 0; //Retention Cost
this.lifetime = opts.lifetime || 3; //Product Lifetime
this.inflation = opts.inflation || 0.05; //Inflation Rate
this.network = opts.network || 100; //Network Size
this.influence = opts.influence || 0.01; //Network Conversion Influence
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
@ngmaloney
ngmaloney / extra-httpd-vhosts.conf
Created August 11, 2011 18:30
extra/httpd-vhosts.conf
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
@ngmaloney
ngmaloney / csvdiff.rb
Created July 22, 2011 17:58
Quick and Dirty delta between 2 csv files
#!/usr/bin/env ruby
#
# A 30 second hack job to compare two CSV files
#
file1 = ARGV[0] ? ARGV[0] : false
file2 = ARGV[1] ? ARGV[1] : false
file1_set = []
file2_set = []
delta = []
@ngmaloney
ngmaloney / get_meta_description.js
Created June 27, 2011 21:07
A Javascript function used to extract meta description from an HTML document.
/**
* Returns document meta description
*/
getMetaDescription = function() {
var metas = document.getElementsByTagName('meta');
for(var i in metas) {
if (typeof(metas[i].name) != 'undefined' && metas[i].name.toLowerCase() == "description") {
return encodeURIComponent(metas[i].content);
}
}
@ngmaloney
ngmaloney / gist:1018167
Created June 10, 2011 03:01
Solution to Puzzlenode.com #4 Robots vs Lasers
class RobotGuidanceSystem
attr_accessor :schematics
def initialize(input_file)
self.schematics = []
f = File.open(input_file) if File.exists? input_file
parse_schematics f.read if f
end
def run
@ngmaloney
ngmaloney / gist:981766
Created May 19, 2011 21:17
my.drush.inc
<?php
/**
* @file My Drush Commands
*/
/**
* Implementation of hook_drush_help()
*/
function my_drush_help($section) {
switch ($section) {
@ngmaloney
ngmaloney / gist:744545
Created December 17, 2010 05:52
Mongodb Max Length MapReduce
reduce = function(key,vals) {
return vals.sort(function(a,b){return b - a})[0];
}
map = function() {
var map_send = function(k,v) {
emit(k,v.toString().length);
}
@ngmaloney
ngmaloney / gist:733586
Created December 8, 2010 17:23
top comments by uid
select c.uid, c.cid, c.created
from (
select uid, max(created) as maxcreated
from comment group by uid
) as x inner join comment as c on c.uid = x.uid and c.created = x.maxcreated
order by maxcreated desc