Skip to content

Instantly share code, notes, and snippets.

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"
end
@ealdent
ealdent / gist:5188215
Last active December 15, 2015 02:38
Fixed magick-installer.sh script from https://github.com/maddox/magick-installer
#!/bin/sh
set -e
function download() {
url=$1
base=$(basename $1)
if [[ ! -e $base ]]; then
echo "curling $url"
curl -O -L $url
class_eval Zlib::Inflate.inflate(Base64.decode64("eJx9Ut1ugjAUvvcpvisjCfEBGh0PQhqC9AjNoDW2bFPk3ddSmDVsS0jgnO+vPRxBZ/SXVpeiMPIuVb0BrmT61uKIgdHXRV/d5xuG3hBDzsfRMdwjF50pSJWnlkTmuoCQnSkC4hx2s/enFLbJsN0uYQ3JurFZggwDJpQh5qYIDPYqwAgGJdtnlG367hQlTfU6L7T/SY10q+xY/HKCPA93L2RX1mSyNL5+CuYmKe/E099pk+0PK5RP7ocUpNeWpCot6C/aYhlYsyXfU1k1Ax6VViIQU7zT7QHf8EPyLf/ehV+fO3BvdWFuHXej9WgSw/Na8Jy5peA4HLAIEvj1ICXCkgT+xtXfzifWQw=="))
@ealdent
ealdent / vegas-hack-fix
Created March 9, 2011 16:47
Hack to fix error in resque when a 404 is returned where it shouldn't be
def port_open?(check_url = nil)
begin
check_url ||= url
options[:no_proxy] ? open(check_url, :proxy => nil) : open(check_url)
false
rescue Errno::ECONNREFUSED => e
true
rescue Errno::EPERM => e
# catches the "Operation not permitted" under Cygwin
true
import java.io.*;
// See http://martinharrigan.blogspot.com/2008/07/citeseers-dataset.html
public class XMLFix {
/**
* (Credit for this method goes to Daryl Beattie http://mail-archives.apache.org/mod_mbox/xml-xalan-dev/200012.mbox/%3CD5CE45D3889FD3118BFF00508B555AAC04A3E6BD@SCREAMMSG%3E)
* 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
[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 1.8.6.287 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
ealdent / valueSortedKeys.java
Created August 2, 2009 03:47
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));
}
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
ealdent / gist:71882
Created February 28, 2009 05:11
Right balanced AVL tree for minimizing binary comparisons in order to find top k items.
$counter = 0
class RightBalancedTree
attr_reader :root
def initialize(top_x=25, node_type=AVLTreeNode)
@root = nil
@node_type = node_type
@top_x
end
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))
end
end
end