Skip to content

Instantly share code, notes, and snippets.

View stevej's full-sized avatar

Steve Jenson stevej

View GitHub Profile
@stevej
stevej / emacs-ant-compile.el
Created September 4, 2008 18:15
compile within emacs using ant
(defvar ant-command-history nil
"Ant command history variable")
(defun ant(&optional args)
"Runs ant in the current project. Starting at the directory
where the file being visited resides, a search is made for
build.xml recursively. A maven command is made from the first
directory where the build.xml file is found is then displayed in
the minibuffer. The command can be edited as needed and then
executed. Errors are navigate to as in any other compile mode"
type Bar = String // <-- compiler error
class Foo {
def get: Bar = "hello"
}
class Baz {
val foo = new FooImpl()
def bar: Bar = foo.get() // <-- compiler error if type Bar is defined inside of Foo
}
@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._
@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 / 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 / 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
# 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--
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
^
#!/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 }
# 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}