Skip to content

Instantly share code, notes, and snippets.

View willf's full-sized avatar
✒️
pondering

Will Fitzgerald willf

✒️
pondering
View GitHub Profile
@willf
willf / gist:965733
Created May 11, 2011 01:18
TestOutOfBounds that doesn't work
func TestIsBad(t *testing.T) {
v := MakeBitSet(64)
defer recover()
v.SetBit(100)
t.Fail()
}
@willf
willf / gist:1104848
Created July 25, 2011 18:45
Read each line in c# from the console
static void Main(string[] args)
{
string line;
while ((line = Console.ReadLine()) != null)
{
line = line.Trim();
Process(line);
}
}
@willf
willf / retweets.sh
Created November 23, 2011 00:10
Get retweets
egrep -io "rt +@\w+" nsports.tsv | perl -pe "s/ +/ /g" | cut -f2 -d\ | sort | uniq -c | sort -rn | head
@willf
willf / track_tweets.rb
Created November 23, 2011 00:24
Track tweets on some topic
require 'rubygems'
require 'tweetstream'
require 'date'
TweetStream.configure do |config|
config.consumer_key = '<your key>'
config.consumer_secret = '<your secret>'
config.oauth_token = '<your token>'
config.oauth_token_secret = '<your token secret>'
config.auth_method = :oauth
@willf
willf / get_accessor.scala
Created December 15, 2011 23:14
Mongo DB get accessors and how the act in the presence of a missing key/value pair
scala> new BasicDBObject().get("missing") => java.lang.Object = null
scala> new BasicDBObject().getBoolean("missing") => Boolean = false
scala> new BasicDBObject().getDouble("missing") throws java.lang.NullPointerException
scala> new BasicDBObject().getInt("missing") throws java.lang.NullPointerException
scala> new BasicDBObject().getLong("missing") throws java.lang.NullPointerException
scala> new BasicDBObject().getString("missing") => java.lang.String = null
@willf
willf / inverted_index.scala
Created December 23, 2011 16:54
Create an inverted index from a file
/**
* From a file that contains
* doc_id w1 w2 w3 ... lines, separated by tabs
* return an inverted index Map of w -> Set(doc_id)
*
* @param filename well isn't it obvious
* @return Map[String,Set[String]]
*/
import scala.collection.immutable.Map
@willf
willf / split_random.rb
Created January 24, 2012 23:09
Another version of split random
class Array
# split array into groups up to n items, randomly choosing the size.
def split_random(n)
size == 0 ? self : (size == 1 ? [self] : self[1..-1].reduce([[self[0]]]){|ll, elt| (rand(n)==(n-1) || ll[-1].size==n) ? ll + [[elt]] : ll[0..-2] + [ll[-1] +[elt]]})
end
end
@willf
willf / resolve.rb
Last active October 1, 2015 02:38
Resolve a (possible) redirect
require 'net/http'
def resolve(uri_str,limit=5)
$stderr.puts("Resolving #{uri_str}")
limit.times do |i|
uri = URI.parse(uri_str)
raise "No host given #{uri_str}" unless uri.host
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Head.new(uri.request_uri)
response = http.request(request)
"@0xabad1dea I love the term \"Cutie Twitter\""
"@AccuRayno I love the term \"not as brutal\". I wonder what color it would be if the forecast was \"brutal\"?"
"@Ashton5SOS @Smallzy I love the word wallop!!"
"@CL_Hellisen @MindTheCurvesZA gorgeous! i love the expression, the pose!"
"@DannyNoriega danny i have like a major problem...i hate the word fag and my neighbor calls me\" gay spic fag boy\" what do i do? ps. i love u"
"@Gwenelope love the word Luddite. Almost as much as I love the words palimpsest and velvet #randomtweet"
"@JMamuds I love the term “organic mass”"
"@JamesTharpy24 I love the term meddler in the middle for TP. It more accurately described what we really do in our classroom."
"@Mikah_Clark Hello. Nerd. Also, I love the word abysmal and have been wanting to use it in a convo for like three days now. Deal."
"@NinBendo1 I hate the term, Christian. I am a follower of Christ. And He says to love EVERYONE. So, that is how I choose to live."
@willf
willf / fizzbuzz.rb
Created November 2, 2012 15:43
World's best Ruby FizzBuzz
class FizzBuzz
private
@@pairs = [
[3, "fizz"],
[5, "buzz"]
]
def self.strings_for(n)