Skip to content

Instantly share code, notes, and snippets.

@benolee
benolee / fractal.c
Created April 4, 2011 18:40
fractal.c
#include <unistd.h>
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
class String
def squish!
strip!
gsub!(/\s+/, ' ')
self
end
end
@benolee
benolee / gist:928025
Created April 19, 2011 14:25
easier way to do flash messages
- flash.each do |key, msg|
%div{ :id => key }= msg
it "registers a new temperature reading via the API" do
page.driver.post('/temperature/new', { :params => { :degrees => "30" } })
page.driver.status_code.should eql 200
end
# This is the current solution. It merely validates the string's inclusion in
# the given list, and saves it as a string.
ActiveRecord::Schema.define(:version => 20110101000000) do
create_table "foos", :force => true do |t|
t.string "bar"
end
end
class Foo < ActiveRecord::Base
def sort some_array # This "wraps" recursive_sort.
recursive_sort some_array, []
end
def recursive_sort unsorted_array, sorted_array
# Check to see if there is anything to sort
if unsorted_array.empty?
return sorted_array
else
# Start with the first member of unsorted array,
@benolee
benolee / gist:977515
Created May 17, 2011 22:05
Anagram game solver
module Anagram
class Wordlist
def load_words
@words = Hash.new{[]}
File.open("/usr/share/dict/words", "r") do |file|
while line = file.gets
word = line.chomp
@words[word.split('').sort!.join('')] += [word]
end
end
@benolee
benolee / howto_pow_ubuntu.txt
Created July 1, 2011 03:32
HowTo Ubuntu pow-like setup
$ sudo aptitude install apache2 dnsmasq
$ sudo vim /etc/dnsmasq.conf
# ...
address=/dev/127.0.0.1
listen-address=127.0.0.1
$ sudo vim /etc/dhcp3/dhclient.conf
# uncomment line 20:
@benolee
benolee / gist:1067470
Created July 6, 2011 15:11
easy way to do singleton modules
module Foo
extend self
def bar
"hello world"
end
end
Foo.bar
#=> "hello world"
if [[ -n "$PS1" ]]; then
HISTCONTROL=ignoredups:ignorespace
HISTSIZE=1000
HISTFILESIZE=2000
shopt -s histappend
shopt -s checkwinsize
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"