This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2011 by Dirk Gadsden | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a copy | |
// of this software and associated documentation files (the "Software"), to deal | |
// in the Software without restriction, including without limitation the rights | |
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
// copies of the Software, and to permit persons to whom the Software is | |
// furnished to do so, subject to the following conditions: | |
// | |
// The above copyright notice and this permission notice shall be included in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SpitefulStore | |
# A very mean cache store that loses everything you give it. | |
def read(key) | |
nil | |
end | |
def write(key, value) | |
value | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a light-hearted riposte to rkh's great almost-sinatra (https://github.com/rkh/almost-sinatra) project. | |
%w{rubygems sinatra}.each {|g| require g } | |
get '/' do '<html><head><title>Definitely Sinatra</title></head><body>Hello World</body></html>'; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'highline' | |
require 'net/http' | |
h = HighLine.new | |
count = 0 | |
while true | |
body = Net::HTTP.get URI.parse('http://feeds.gawker.com/kotaku/full') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 21 Mar. 2010: Pulled from tedb's fork to add cache_and_render method. | |
class ApplicationController < ActionController::Base | |
# Other random stuff. | |
protected | |
def cache_and_render(key, opts = {}) | |
cached = cache(key, opts) | |
render :text => cached |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project | |
include MongoMapper::Document | |
key :name, String, :required => true | |
key :description, String, :default => '' | |
key :status, Symbol, :required => true, :default => :open | |
key :client_id, ObjectId, :required => true | |
belongs_to :client | |
many :tasks, :dependent => :destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# heavily based off difflib.py - see that file for documentation | |
# ported from Python by Bill Atkins | |
# This does not support all features offered by difflib; it | |
# implements only the subset of features necessary | |
# to support a Ruby version of HTML Differ. You're welcome to finish this off. | |
# By default, String#each iterates by line. This isn't really appropriate | |
# for diff, so often a string will be split by // to get an array of one- | |
# character strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$now = microtime(true); | |
for($i = 0; $i < 1000000; $i++){ | |
$str = 2 + 'characters'; | |
} | |
echo microtime(true) - $now; | |
$now = microtime(true); | |
for($i = 0; $i < 1000000; $i++){ | |
$str = 2 . 'characters'; | |
} |