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 / gist:923529
Created April 16, 2011 21:41
Github API View
General API Info
How to authenticate as a user, URL schema, secure and unsecured access and access limitations.
>> Authentication
Users API
API for accessing and modifying user information.
>> Searching for Users
>> Getting User Information
@csanz
csanz / javascript_engineer.js
Created March 24, 2011 19:16
Javascript Engineer @ Storify.com
var reqs = require('smart'),
skills = require('javascript_html_css_mongodb'),
passion = require('change_the_world_of_storytelling');
/**
We are looking for talented + well-rounded developers to
join storify.com's core engineering team. We are young,
funded and picking up a lot of momentum. We run a pure
Javascript stack, from node.js on the server, mongodb on the
backend and jQuery on the browser. We are also
fanatics about HTML5 and CSS3.
@csanz
csanz / javascript_engineer.js
Created March 24, 2011 09:04
Javascript Engineer @ Storify.com
var reqs, skills, passion;
reqs = require('smart');
skills = require('javascript_html_css_mongodb');
passion = require('change_the_world_of_storytelling');
/**
We are looking for talented + well-rounded developers to
join storify.com's core engineering team. We are young,
funded and picking up a lot of momentum. We run a pure
Javascript stack, from node.js on the server, mongodb on the
backend and jQuery on the browser. We are also
@csanz
csanz / get_elapsed_time.js
Created March 22, 2011 00:14
get the elapsed time from a server
/* usage
node get_elapsed_time.js -u localhost -p 8000 */
var start, elapsed, end, argv, http;
argv = require('optimist').argv;
http = require('http');
if (argv.u.length == 0) return console.log('need url');
start = new Date();
http.get({ host : argv.u , port: (argv.p) ? argv.p : 80}, function(res){
console.log('\nnget console util\n');
@csanz
csanz / gist:879067
Created March 21, 2011 05:10
dup results.
[
{
"name" : "Mike",
"count" : 3
},
{
"name" : "chris",
"count" : 4
},
{
> db.users.find();
{ "_id" : ObjectId("4d82e8e0a212e32240e91d49"), "name" : "Mike" }
{ "_id" : ObjectId("4d8393086a370e29032422ce"), "name" : "Mike" }
{ "_id" : ObjectId("4d83930a6a370e29032422cf"), "name" : "Mike" }
{ "_id" : ObjectId("4d83930f6a370e29032422d0"), "name" : "chris" }
{ "_id" : ObjectId("4d8393106a370e29032422d1"), "name" : "chris" }
{ "_id" : ObjectId("4d8393126a370e29032422d2"), "name" : "chris" }
{ "_id" : ObjectId("4d8393136a370e29032422d3"), "name" : "chris" }
{ "_id" : ObjectId("4d8393176a370e29032422d4"), "name" : "jenn" }
{ "_id" : ObjectId("4d83931e6a370e29032422d5"), "name" : "denise" }
@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.
*/
@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
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 / 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"}