Skip to content

Instantly share code, notes, and snippets.

# Usage: redis-cli publish message.achannel hello
require 'sinatra'
require 'redis'
conns = Hash.new {|h, k| h[k] = [] }
Thread.abort_on_exception = true
get '/' do
# Usage: redis-cli publish message hello
require 'sinatra'
require 'redis'
conns = []
get '/' do
erb :index
end
@nguyenlocduy
nguyenlocduy / deploy.rb
Created October 18, 2012 15:04 — forked from andruby/deploy.rb
Start and Stop tasks for resque workers, with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
@nguyenlocduy
nguyenlocduy / MongoDB update all matching.js
Created October 13, 2012 03:43 — forked from sym3tri/MongoDB update all matching.js
How to update a single field in a MongoDB collection for all documents matching a specific criteria
// FROM: http://www.mongodb.org/display/DOCS/Updating#Updating-update%28%29
//
// db.collection.update( criteria, objNew, upsert, multi )
// criteria - query which selects the record to update;
// objNew - updated object or $ operators (e.g., $inc) which manipulate the object
// upsert - if this should be an "upsert"; that is, if the record does not exist, insert it
// multi - if all documents matching criteria should be updated
//
// SQL VERSION:
// UPDATE myTable SET dateField = '2011-01-01' WHERE condField = 'condValue'
@nguyenlocduy
nguyenlocduy / uri.js
Created September 7, 2012 09:26 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@nguyenlocduy
nguyenlocduy / 01. Gemfile
Created August 11, 2012 15:07 — forked from schleg/01. Gemfile
Setup for Devise + Omniauth
gem 'pg'
group :development do
gem 'ruby-debug'
end
gem 'rake', '~> 0.8.7'
gem 'devise'
gem 'oa-oauth', :require => 'omniauth/oauth'
gem 'omniauth'
gem 'haml'
gem 'dynamic_form'
@nguyenlocduy
nguyenlocduy / mailchimp_api_error_handle_honimid.rb
Created August 7, 2012 14:08
How to handle MailChimp API Error with Honimid
h = Hominid::API.new('<your key>')
begin
# Do a call for subscribing in here as well
render :text => "Subscribed, yay!"
rescue Hominid::APIError => error
render :text => "Error: #{error.message}"
end
$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});
@nguyenlocduy
nguyenlocduy / gist:3277877
Created August 6, 2012 19:40 — forked from chebyte/gist:1154889
Guide for configure Tomcat6, Solr 1.4, Sunspot for Rails Application on Ubuntu 8.04 or 10.04

Guide for configure Tomcat6, Solr 1.4, Sunspot for Rails Application on Ubuntu 8.04 or 10.04

1. Install the Java JRE and Ant

for ubuntu 8.04

add the following sources to /etc/apt/sources.list

deb http://us.archive.ubuntu.com/ubuntu/ hardy multiverse
deb-src http://us.archive.ubuntu.com/ubuntu/ hardy multiverse
deb http://us.archive.ubuntu.com/ubuntu/ hardy-updates multiverse

@nguyenlocduy
nguyenlocduy / uninstall_homebrew.sh
Created July 31, 2012 12:03 — forked from mxcl/uninstall_homebrew.sh
Uninstall Homebrew
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e