Skip to content

Instantly share code, notes, and snippets.

@gaarf
gaarf / stealthtweeet.html
Created March 21, 2010 01:04
Stealth Tweets with Unicode
<!DOCTYPE HTML>
<html>
<head>
<title>Stealth Tweets with Unicode</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssfonts/fonts-min.css" />
<script src="http://yui.yahooapis.com/3.0.0/build/yui/yui-min.js"></script>
<script>
YUI().use('node',function(Y) {
@gaarf
gaarf / merge_master.rb
Created February 4, 2011 00:45
git merge master into all local branches
#!/usr/bin/env ruby
BRANCHES = []
`git branch`.each_line do |line|
branch = line.gsub(/[^\w]/, '')
if line[0]==42
STARTED_ON_BRANCH = branch
end
BRANCHES << branch
end
@gaarf
gaarf / safari_demo.png
Created March 24, 2011 23:26
a css triangle demo
safari_demo.png
@gaarf
gaarf / stream.js
Created April 11, 2011 03:09
twitter streamer for nodejs
var SECRETS = {
consumer_key: 'xxxxxxx',
consumer_secret: 'xxxxxxx',
access_token: 'xxxxxxx',
access_token_secret: 'xxxxxxx'
};
var OAuth = require('oauth').OAuth,
oa = new OAuth(null, null, SECRETS.consumer_key, SECRETS.consumer_secret, "1.0A", null, "HMAC-SHA1"),
start, request, counter;
@gaarf
gaarf / kittens.html
Created May 18, 2011 00:59
Re-order yourself some kittens
<!DOCTYPE HTML>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
$(function() {
var SLOT_COUNT = 5,
SLOT_WIDTH = 210, // css must match
SLOT_HALF_WIDTH = SLOT_WIDTH/2,
$xreorder = $('#xreorder').css('width',SLOT_WIDTH*SLOT_COUNT);
@gaarf
gaarf / test.js
Created November 6, 2011 03:09
Expresso or Node 0.6.0 issue?
// expresso
// this worked fine in 0.4.x
// but with node 0.6.0 results in:
// uncaught undefined: Error: connect ECONNREFUSED
// at errnoException (net.js:614:11)
// at Object.afterConnect [as oncomplete] (net.js:605:18)
@gaarf
gaarf / gist:1366188
Created November 15, 2011 04:52
Methods to deal with FB Signed Requests
# see https://github.com/ptarjan/base64url/blob/master/ruby.rb
def base64_url_decode(str)
str += '=' * (4 - str.length.modulo(4))
Base64.decode64(str.gsub("-", "+").gsub("_", "/"))
end
# see http://developers.facebook.com/docs/authentication/signed_request/
def valid_facebook_signature?(signature, encoded_data)
base64_url_decode(signature) == HMAC::SHA256.digest(FACEBOOK_APP_SECRET, encoded_data)
end
@gaarf
gaarf / .profile
Created February 22, 2012 19:53
my .profile
export VISUAL=nano
export EDITOR=nano
export CLICOLOR=1
export TERM=xterm-color
export LSCOLORS=gxgxcxdxbxegedabagacad # cyan directories
export NODE_ENV='development'
export RAILS_ENV=$NODE_ENV # haha
if [[ -s $HOME/.rvm/scripts/rvm ]] ; then source $HOME/.rvm/scripts/rvm ; fi
@gaarf
gaarf / gist:3094814
Created July 12, 2012 00:46
mongoose mapreduce (public)
SomeSchema.methods.mapReduce = function(callback) {
function map() {
/*global emit:true */
emit('something', {foos:this.foos, users:1});
}
function reduce(k, av) {
var foos = 0;
av.forEach(function(v) {
@gaarf
gaarf / gist:5256378
Created March 27, 2013 17:32
Mongoose regexp not working?
I am using Mongo v2.0.2, and currently on Mongoose v3.6.0.
I have a collection called "Users". Each doc has a String field called "ua", which is NOT indexed - but I tried with an indexed field and the behaviour is the same.
I want to find all the docs that have a ua containing, say, "Safari". So I try to use RegExp queries.
-----
Directly in Mongo console, everything works fine: