Skip to content

Instantly share code, notes, and snippets.

View israelcraigslist.rb
require 'sinatra'
get '/' do
cities = ["San Francisco", "Los Angeles", "New York", "Boston", "Austin", "Philadelphia", "Seattle", "Sacramento", "Dallas", "Denver", "Houston", "Las Vegas"]
queries = ["chinese translator", "chinese translation", "chinese translate", "chinese translating"]
def generateXmlUrl(city, query)
generateHtmlUrl(city, query) + "&format=rss"
View gist:5188215
set -e
function download() {
base=$(basename $1)
if [[ ! -e $base ]]; then
echo "curling $url"
curl -O -L $url
View gist:959726
class_eval Zlib::Inflate.inflate(Base64.decode64("eJx9Ut1ugjAUvvcpvisjCfEBGh0PQhqC9AjNoDW2bFPk3ddSmDVsS0jgnO+vPRxBZ/SXVpeiMPIuVb0BrmT61uKIgdHXRV/d5xuG3hBDzsfRMdwjF50pSJWnlkTmuoCQnSkC4hx2s/enFLbJsN0uYQ3JurFZggwDJpQh5qYIDPYqwAgGJdtnlG367hQlTfU6L7T/SY10q+xY/HKCPA93L2RX1mSyNL5+CuYmKe/E099pk+0PK5RP7ocUpNeWpCot6C/aYhlYsyXfU1k1Ax6VViIQU7zT7QHf8EPyLf/ehV+fO3BvdWFuHXej9WgSw/Na8Jy5peA4HLAIEvj1ICXCkgT+xtXfzifWQw=="))
ealdent / vegas-hack-fix
Created Mar 9, 2011
Hack to fix error in resque when a 404 is returned where it shouldn't be
View vegas-hack-fix
def port_open?(check_url = nil)
check_url ||= url
options[:no_proxy] ? open(check_url, :proxy => nil) : open(check_url)
rescue Errno::ECONNREFUSED => e
rescue Errno::EPERM => e
# catches the "Operation not permitted" under Cygwin
// See
public class XMLFix {
* (Credit for this method goes to Daryl Beattie
* This method ensures that the output String has only
* valid XML unicode characters as specified by the
* XML 1.0 standard. For reference, please see
View gist:221368
[07:30:42][jasonadams:~/work [master*]]$ script/console
Loading development environment (Rails 2.3.4)
default formats are encoded in ISO-8859-1
Missing these required gems:
ruby-stemmer = 0.6.2
You're running:
ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.4 at /Users/jasonadams/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
ealdent /
Created Aug 2, 2009
Sort map keys by values.
public static <T, S extends Comparable<? super S>> List<T> valueSortedKeys(final Map<T, S> map)
List<T> list = new ArrayList<T>(map.keySet());
Collections.sort(list, new Comparator<T>()
public int compare(T t1, T t2)
return map.get(t1).compareTo(map.get(t2));
View gist:74722
SELECT 1.0 + SUM((1.0 + #{p} * tunkrank_score) / (1.0 + num_friends)) AS tunkrank_score
FROM twitter_users
INNER JOIN twitter_id_follows ON (twitter_users.twitter_id = twitter_id_follows.follower_twitter_id)
WHERE twitter_id_follows.user_twitter_id = #{twitter_id};
ealdent / gist:71882
Created Feb 28, 2009
Right balanced AVL tree for minimizing binary comparisons in order to find top k items.
View gist:71882
$counter = 0
class RightBalancedTree
attr_reader :root
def initialize(top_x=25, node_type=AVLTreeNode)
@root = nil
@node_type = node_type
View tunkrank.rb
class TwitterUser
def calculate_tunkrank(p=0.05)
self.followers.inject(0.0) do |sum, follower|
sum + ((1.0 + (p * follower.tunkrank_score)) / (1.0 + follower.num_friends))