Skip to content

Instantly share code, notes, and snippets.

View csanz's full-sized avatar
🎯
Focusing

Christian Sanz csanz

🎯
Focusing
View GitHub Profile
@csanz
csanz / to generate a human readable time range using ruby on rails
Created November 9, 2010 18:58
to generate a human readable time range using ruby on rails
def humanize secs
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].inject([]){ |s, (count, name)|
if secs > 0
secs, n = secs.divmod(count)
s.unshift "#{n.to_i} #{name}"
end
s
}.join(' ')
end
for a t-shirt? yeah right... ;)
@csanz
csanz / proxyManager.cpp
Created December 15, 2010 06:53
I wrote this a long time ago during my time at Disney Online... Nothing secret about, just a proxy changer I wrote for the devs.
/*************************************
load libraries
*************************************/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
/*************************************
initialize functions
@csanz
csanz / tradingPost.asp
Created December 15, 2010 06:57
I wrote this very simple API for one of the flash programmers. I ported this over to java a few weeks later.
<%
'//##Misc Methods
'//-------------
'//#######################################
sub view(string) '//process string and add delimeter
response.write(string) & ";"
end sub
@csanz
csanz / blastPayPlans.sql
Created December 15, 2010 07:02
SQL for pulling pay plans
/*
1) What are all the payplans that exist in GoReg that are associated with all the
various Blast products (i.e. clubblast, clubblast_scholastic, ...)
- break total down by product
- How many invoices exist in total that include one of these payplans?
Identify payplans that do not have a corresponding invoice (i.e. never used)
*/
SELECT PAY_PLAN.*, AFFILIATE.name As aff_name, PRODUCT.*,
@csanz
csanz / getFile.vb
Created December 15, 2010 07:11
cool file downloader... talk about REST 0.1 ahha
Call Ask()
Sub Ask()
Dim intDoIt
Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
strPage = InputBox("Enter Domain you wish to Grab","GRAB TOOL 1.2 - by Chris Sanz", "http://")
strPage = strPage
if strPage = "" then
@csanz
csanz / mongodb part 1
Created January 9, 2011 23:07
optimizing mongo db
> use sampledb
switched to db sampledb
> a = {"name" : "chris"};
{"name" : "chris"}
> b = {"name" : "jenn"};
{"name" : "jenn"}
> db.users.save(a)
> db.users.save(b);
> db.users.find();
{"_id" : ObjectId( "4d2a3decdf59a32a1973e8d3") , "name" : "chris"}
from file: https://github.com/ry/node/blob/6eca6b1ec05c5b386121a992dc7f6502f001f052/doc/api/http.markdown
issue: you are getting the body length, but you are not passing it anywhere.
var body = 'hello world';
response.writeHead(200, {
'Content-Length': body.length,
'Content-Type': 'text/plain' });
@csanz
csanz / stop.sh
Created March 13, 2011 02:22
stops a single node.js instance
#!/bin/bash
#author: csanz
pid=`ps afx | grep "node" | grep "$1" | grep "app.js" | awk '{print $1'}`
if [ -z $pid ]
then
echo "the node instance doesn't exists"
fi
if [ "$pid" != '' ]
then
@csanz
csanz / dupscript.js
Created March 21, 2011 01:44
Looking for duplicates / Simple script example
db.users.group({ key: { name:true },
cond: { "created_at"},
initial: { count: 0 },
reduce: function(obj,out) { out.count ++ ; }});
/*
Note1: make sure you put the initial declaration above reduce or else the count variable never gets set
Note2: group() can't handle more than 10000 unique keys, so for large dbs you are better off using straight up map reduce.
*/