Skip to content

Instantly share code, notes, and snippets.

View stevej's full-sized avatar

Steve Jenson stevej

View GitHub Profile
@stevej
stevej / doc_fix.patch
Created November 19, 2009 18:55
Fixing documentation output to say 'def'
Index: src/main/scala/sbt/DefaultProject.scala
===================================================================
--- src/main/scala/sbt/DefaultProject.scala (revision 1129)
+++ src/main/scala/sbt/DefaultProject.scala (working copy)
@@ -445,7 +445,7 @@
{
log.warn("No Main-Class attribute will be added automatically added:")
log.warn("Multiple classes with a main method were detected. Specify main class explicitly with:")
- log.warn(" override mainClass = Some(\"className\")")
+ log.warn(" override def mainClass = Some(\"className\")")
@stevej
stevej / gist:158982
Created July 30, 2009 22:51
multi-way-merge as a tail recursive function in Scala
trait Merge {
def m_way_merge(out: List[Int], xs: List[List[Int]]): List[Int] = {
val arrays = xs.remove(_ == Nil)
if (arrays.isEmpty) {
out
} else {
val idx: Int = arrays.findIndexOf((xs: List[Int]) => xs.head == arrays.map(_.head).sort(_ < _).head)
m_way_merge(out ::: List(arrays(idx).head), arrays.slice(0, idx) ::: arrays.slice(idx + 1, arrays.length) ::: List(arrays(idx).tail))
}
}
# Used in conjuction with mysqlbinlog, this awk script will print out
# the SQL operation and the table being modified.
# Collate with sort | uniq -c | sort -rn
/^UPDATE/{ print $1, $2 }
/^INSERT|^DELETE/{ print $1, $3}
#!/usr/bin/ruby
#
# Testing whether sorting then reversing is faster than sorting "the right way".
# Short answer: sort/reverse are written in C, your own sort function will be written in Ruby.
require 'benchmark'
n = 1_000
ids = (0..10_000).to_a.sort_by { rand }
scala> def foo!@$# = null
<console>:1: error: '=' expected but identifier found.
def foo!@$# = null
^
scala> def foo_!@$# = null
<console>:1: error: '=' expected but identifier found.
def foo_!@$# = null
^
# These are the results of running bonnie64 on my old MacBook Pro (Model 2,2) 2.3Ghz, 3G RAM, and 5400 RPM drive.
$ ./Bonnie -m lambdaold -s 8192
File './Bonnie.628', size: 8589934592
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
Reading intelligently...done
Seeker 2...Seeker 3...Seeker 1...start 'em...done...done...done...
-------Sequential Output-------- ---Sequential Input-- --Random--
@stevej
stevej / bonnie.output
Created November 15, 2008 06:13
The results of running bonnie64 on my new MacBook Pro
# This machine is a new MacBook Pro, 2.8Ghz Intel Core 2 Duo, 7200RPM drive with 4G RAM.
$ ./Bonnie -m lambdanew -s 8192
File './Bonnie.13603', size: 8589934592
Writing with putc()...^C
lambda:bonnie-64-read-only stevej$ ./Bonnie -m lambdanew -s 8192
File './Bonnie.13604', size: 8589934592
Writing with putc()...done
Rewriting...done
Writing intelligently...done
Reading with getc()...done
@stevej
stevej / atom_timeseries.rb
Created October 8, 2008 21:29
For a big file filled with atom entries, spit out the epoch of each atom entry's updated timestamp. Output to stdout. so pipe it to your file.
#!/usr/bin/ruby
# usage: ./atom_timeseries.rb file
# For a big file filled with atom entries, spit out
# the epoch of each atom entry's updated timestamp.
# Output to stdout. so pipe it to your file.
require 'Time'
file = File.new(ARGV[0], "r")
while (line = file.gets)
@stevej
stevej / json_directory.rb
Created October 6, 2008 17:30
Validates a directory full of JSON files.
#!/usr/bin/ruby
require 'rubygems'
require 'json'
dir = ARGV.shift
def readfile(filename)
return '[]' if File.directory?(filename)
body = ''
@stevej
stevej / gist:10017
Created September 10, 2008 19:04
Showing how to import from an instance of a class.
class Foo {
type Bar = Map[String, Map[String, Any]]
def bar(): Bar = Map()
}
class Baz {
val foo = new Foo()
import foo._