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 / 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 / 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 / bitset.go
Created May 11, 2011 01:47
First implementation of bitsets
// Copyright 2011 Will Fitzgerald. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
Package bitset implements bitsets.
It provides methods for making a bitset of an arbitrary
upper limit, setting and testing bit locations, and clearing
bit locations as well as the entire set.
@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:965713
Created May 11, 2011 01:01
Writing a GO test to test for the presence of a failure
func TestOutOfBoundsBad(t *testing.T) {
v := MakeBitSet(64)
defer func() {
if r := recover(); r == nil {
t.Error("Out of index error within the next set of bits should have caused a panic")
}
}()
v.SetBit(1000)
}
@willf
willf / do a sync http requesst.fs
Created June 8, 2010 21:04
Do a synchronous http request
open System
open System.IO
open System.Net
open System.Web
// get contents synchronously
let http_sync (uri:Uri) =
let reader = new StreamReader(WebRequest.Create(uri).GetResponse().GetResponseStream())
reader.ReadToEnd()
@willf
willf / text of the first 10 LI items in a XHTML document
Created June 2, 2010 15:48
command line .. look for all LI or TRs in a document
need to change the DTD declarations to point to a local copy of the W3 DTD
locally:
> ls *.dtd *.ent
xhtml1-transitional.dtd xhtml-lat1.ent xhtml-special.ent xhtml-symbol.ent
change:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
@willf
willf / use parallelisms.fsharp
Created June 1, 2010 14:15
Simple use of PSeq
#if INTERACTIVE
#r"FSharp.PowerPack.Parallel.Seq.dll"
#endif
// or add dll to References
open Microsoft.FSharp.Collections
[1;2;3] |> PSeq.sum;;
@willf
willf / bash command to sort on a tsv column, not the first column.sh
Created May 25, 2010 15:23
sorting on numeric keys on in the first column
sort -k2 -rn -t" "
# where the text bewteen the "" is Ctrl-V TAB
@willf
willf / sequence lines of text in f#.fs
Created May 25, 2010 06:45
read a sequence of lines in F# #fsharp
open System
open System.IO
let readLines (sr:TextReader) =
Seq.initInfinite (fun _ -> sr.ReadLine())
|> Seq.takeWhile (fun x -> x <> null)
let consoleLines() =
readLines Console.In