Skip to content

Instantly share code, notes, and snippets.

syntax = r'''
<ts> := [ \t]*
# Variable delcarations
local_var := [a-z], [a-z0-9_]*
global_var := [A-Z], [a-z0-9_]+
# The chain of indexes and properties for objects
tail := (index/property/func_call)+
index := "[", expression, "]"
@dirk
dirk / conway.rs
Created June 28, 2012 21:18
Conway's game of life in Rust
use std;
use time;
import result::{ok, err};
import to_str::*;
// Count the number of live neighbors for a given cell.
// Neighbors are cells adjacent vertically, horizontally, or diagonally.
fn live_neighbors(board: [[bool]], row: int, column: int) -> int {
@dirk
dirk / environment.rb
Last active December 15, 2015 12:59
Fix for bug in Rails 2.3's vendored BlankSlate.
config.gem "toml", :version => "0.0.4"
class BlankSlate
class << self
# Hide the method named +name+ in the BlankSlate class. Don't
# hide +instance_eval+ or any method beginning with "__".
def hide(name)
# CHANGED: if instance_methods.include?(name.to_s) and
if instance_methods.include?(name.to_sym) and
name !~ /^(__|instance_eval)/
@hidden_methods ||= {}
@dirk
dirk / download-latest-chromium.rb
Created April 4, 2013 22:16
Download the latest Mac build of Chromium from their CI repo
#!/usr/bin/env ruby
version = `wget -O - -q http://commondatastorage.googleapis.com/chromium-browser-continuous/Mac/LAST_CHANGE`.strip
puts "Downloading Chromium continuous build version: #{version}"
STDOUT.flush
`wget -O "chromium-mac-continuous-#{version}.zip" http://commondatastorage.googleapis.com/chromium-browser-continuous/Mac/#{version}/chrome-mac.zip`
@dirk
dirk / state_machine.rb
Last active December 17, 2015 05:38
The only state machine I'll (probably) ever need.
class StateMachine
def initialize
@transitions = {}
end
def transition(opts, &block)
from = opts[:from]
to = opts[:to]
@transitions[from] ||= {}
@transitions[from][to] = block
end
class Module {
forwards_unary_ruby_methods
def [constant_name] {
"""
@constant_name Name (@String@) of constant's name.
@return @constant_name's value.
Returns the value of the constant with the given name in @self.
"""
# Fast nested constant implementation
class FastNestedConstant : Fancy AST NestedConstant {
def initialize: @line string: @string {
names = @string split: "::"
@toplevel = false
if: (@string =~ /^::/) then: { @toplevel = true; names shift }
@names = names map: |n| { n to_sym }
}
def bytecode: g {
$('p').each(function() {
if($(this).html() == '' && $(this).text() == '') {
$(this).remove()
}
});
# Pipe command to this to open in the browser (eg. bundle help install | pb)
alias pb="col -b | open -a /Applications/Chromium.app -f"

Keybase proof

I hereby claim:

  • I am dirk on github.
  • I am dirk (https://keybase.io/dirk) on keybase.
  • I have the public key with fingerprint 30B2 92C2 31E4 F85D 4B82  97CE DC57 4905 5034 B546

To claim this, I am signing this object: