Skip to content

Instantly share code, notes, and snippets.

void setup() {
size(200, 200);
for (var i = 0; i < 10000; i++) {
var x = (Math.random() - 0.5) * 150;
var y = (Math.random() - 0.5) * 150;
if ((Math.sqrt((x * x) + (y * y))) > 75) continue;
point(x + 100, y + 100);
}
$('p').each(function() {
if($(this).html() == '' && $(this).text() == '') {
$(this).remove()
}
});
# 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 {
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.
"""
@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
@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 / 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 / UIColor-hex.swift
Created October 22, 2015 06:35 — forked from blixt/HexToUIColor.swift
Swift UIColor extension that parses a hexadecimal color string
extension UIColor {
enum Error: ErrorType {
case Parsing(String)
}
convenience init(hex input: String) throws {
let hex = input.stringByTrimmingCharactersInSet(NSCharacterSet.alphanumericCharacterSet().invertedSet)
var int = UInt32()
guard NSScanner(string: hex).scanHexInt(&int) else {
throw Error.Parsing("Unable to scan hexadecimal integer")
import Foundation
// Must use <T> instead of <T: AnyObject> to be able to
// convert to structs (value types) like String.
func cast<T>(object: AnyObject) -> T? {
return object as? T
}
let string: String? = cast("i'm a string!")
require 'rubygems'
require 'benchmark/ips'
require 'ruby-prof'
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'lib')
require 'jbuilder'
require 'jbuilder/jbuilder_template'
module Rails
def self.cache