Skip to content

Instantly share code, notes, and snippets.

@melborne
melborne / colors_on_shoes.rb
Created November 6, 2010 13:07
interactive color for checking ANSI colors
Shoes.app :title => 'Shoes Colors', :width => 600, :height => 600 do
colors = Shoes::COLORS.to_a.sort_by { |k, v| v.to_s }
colors.each do |name, color|
flow :width => 0.33 do
background color
para strong(name), "\n", color, :stroke => (color.dark? ? white : black),
:margin => 4, :align => 'center'
end
end
end
@melborne
melborne / qs_scoring.rb
Created November 7, 2010 09:26
quicksilver scoring algorithm in ruby
#!/usr/local/bin/ruby
# -*- encoding:utf-8 -*-
require 'readline'
require "/Users/keyes/Dropbox/lib/ruby_class_list/rbutils"
class String
def to_score(abbrev)
return 0.9 if abbrev.empty?
return 0.0 if length < abbrev.length
@melborne
melborne / lisr.rb
Last active September 24, 2015 04:57
List(Scheme) Interpreter in Ruby
#!/opt/local/bin/ruby1.9
#-*-encoding: utf-8-*-
class Env < Hash
def initialize(parms=[], args=[], outer=nil)
h = Hash[parms.zip(args)]
self.merge!(h)
@outer = outer
end
def find(key)
@melborne
melborne / bounce.pde
Created January 30, 2011 01:45
Processing demo: ball bounce
ArrayList letters;
PFont font;
int numLetters;
void setup(){
size(320, 460);
letters = new ArrayList();
numLetters = 100;
font = createFont("Helvetica", 18, true);
smooth();
@melborne
melborne / ease_sinatra.rb
Created January 30, 2011 09:06
Scaffolding Sinatra Basic Template
#!/usr/bin/env ruby
#-*-encoding: utf-8-*-
#
require "pathname"
class EaseSinatra
module Builder
MAIN_DIR = Pathname.pwd
BASE_NAME = "app" # MAIN_DIR.split[1]
MAIN_NAME = "#{BASE_NAME}.rb"
@melborne
melborne / clock.js
Created February 17, 2011 08:30
canvas animation demo: clock
var canvas = {};
$(document).ready(function(){
canvas.self = $("canvas#clock");
canvas.ctx = canvas.self[0].getContext('2d');
canvas.width = canvas.self.width();
canvas.height = canvas.self.height();
canvas.ctx.translate(canvas.width/2, canvas.height/2);
clock(70);
@melborne
melborne / private.xml
Created May 24, 2011 09:54
keybindings for keyremap4macbook
<?xml version="1.0"?>
<root>
<list>
<item>
<name>My Custom Keys</name>
<list>
<item>
<name>Remap Ctrl+Semicolon to Equal</name>
<identifier>remap.ctrlsemicolon2equal</identifier>
<autogen>--KeyToKey-- KeyCode::SEMICOLON, VK_CONTROL, KeyCode::EQUAL</autogen>
@melborne
melborne / app_for_chinatra.rb
Created June 5, 2011 06:18
Another syntax Sinatra
require './chinatra'
require 'haml'
require 'myroute'
@melborne
melborne / haskell_sequence.rb
Created July 7, 2011 14:02
Haskell-like Arithmetic Sequence in Ruby
# encoding: UTF-8
class Array
alias __eq__ ===
def ===(other)
if self.size == other.size and any? { |item| item.instance_of? Class }
other = other.to_enum
return all? { |item| item === other.next }
end
__eq__(other)
end
@melborne
melborne / Gemfile
Created July 11, 2011 07:28
GyaoRank
source :rubygems
gem 'sinatra'
gem 'haml'
gem 'sass'
gem 'dalli'
gem 'nokogiri'