Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
LINE_LENGTH = 78
Dir.chdir(ARGV.first) if ARGV.first
Dir['**/*'].each do |path|
next unless File.file?(path)
next if File.basename(path) =~ /^\./
separator = '*' * path.length
puts(separator, path, separator, '')
task :ok do
red = "\e[31m"
yellow = "\e[33m"
green = "\e[32m"
blue = "\e[34m"
purple = "\e[35m"
bold = "\e[1m"
normal = "\e[0m"
puts "", "#{bold}#{red}*#{yellow}*#{green}*#{blue}*#{purple}* #{green} ALL TESTS PASSED #{purple}*#{blue}*#{green}*#{yellow}*#{red}*#{normal}"
end
@threedaymonk
threedaymonk / email_steps.rb
Created June 30, 2009 13:46
Customised Cucumber step definitions for use with Test::Unit
#Commonly used email steps
#
# To add your own steps make a custom_email_steps.rb
# The provided methods are:
#
# reset_mailer
# open_last_email
# visit_in_email
# unread_emails_for
# mailbox_for
@threedaymonk
threedaymonk / scope_fix.rb
Created July 1, 2009 16:20
Overriding the default scope's order in a named scope
named_scope :completed_scope, :conditions => "events.end_at < NOW()", :order => "events.end_at DESC"
def self.completed
with_exclusive_scope do
completed_scope
end
end
require File.join(File.dirname(__FILE__), '..', 'test_helper')
class TrailingWhitespaceTest < ActiveSupport::TestCase
should "not have any trailing whitespace in source files because it complicates merging" do
errors = []
Dir.chdir(Rails.root) do
Dir["{app,lib}/**/*.{rb,html.erb,html,yml}"].each do |path|
File.read(path).split(/\n/).each_with_index do |line, number|
if line =~ /\s$/
errors << "|#{path}|#{number+1}|#{line}|"
end
@threedaymonk
threedaymonk / gist:145453
Created July 12, 2009 00:31
Simple quadratic interpolation in JavaScript/Canvas
<!DOCTYPE HTML>
<html>
<head>
<title>あ</title>
</head>
<body>
<canvas id="c" width="300" height="300"></canvas>
<script>
function lineN(context, data) {
@threedaymonk
threedaymonk / tidy_yaml.rb
Created July 15, 2009 12:48
Reformat simple YAML files into a nicely aligned and quoted form
require "yaml"
require "stringio"
def rewrite(buffer, data, column_width, depth=0)
data.sort.each do |key, value|
case value
when Hash
buffer.puts [" " * depth, key, ":"].join
rewrite(buffer, value, column_width, depth+1)
when Array
@threedaymonk
threedaymonk / notes.txt
Created July 18, 2009 21:08
Ubuntu installation
Disable trackpad tap:
synclient MaxTapTime=0
Load custom xkb layout:
setxkbmap xx
Use gnome keychain for ssh keys:
@threedaymonk
threedaymonk / hotfixes.rb
Created July 28, 2009 10:00
Integration tests (including Webrat) using multiple checkboxes and file attachments will fail (in Rails 2.3.2). This fixes them.
Dir["#{Rails.root}/lib/hotfixes/*.rb"].each do |hotfix|
load hotfix
end
@threedaymonk
threedaymonk / gist:164926
Created August 9, 2009 22:10
Transcribed lyrics of North Korean propaganda song
Transcribed subtitles of http://www.youtube.com/watch?v=pw6GwMTRQM0
더 높이
더 빨리
붉은기 추켜들고 혁명의 노래높이 질붕갈이 달리자
이 땅에 발붙이고 미래를 내다보며 우리의 식으로
더 높이 오르자 다 빨리 달리자