Skip to content

Instantly share code, notes, and snippets.

@harukizaemon
harukizaemon / remove-javadoc.rb
Created February 9, 2009 05:25
Remove all JavaDoc from a File
#!/usr/bin/env ruby
# Usage: ./remove-javadoc.sh < [file-name]
print $<.to_a.join.gsub(/\/\*\*(.*)\*\//m, '')
@harukizaemon
harukizaemon / gist:125613
Created June 8, 2009 04:16
Simplest Chocolate Mousse Ever
Ingredients:
* 230 grams bittersweet chocolate (I prefer < 70%; anything more I find too bitter)
* ½ cup brewed coffee (optional)
* 4 eggs, separated
Directions:
1. In a double boiler, melt the chocolate and set aside to cool.
2. Separate the eggs.
3. In a medium size bowl beat the egg whites until peaks form.
4. In a separate bowl, mix together the chocolate, coffee, and egg yolks until well incorporated.
#########################################
# Run the following to generate some input:
# find . -iname '*.java' -type f -exec cat {} \; | grep -E '^(package|import)'
# Then run this script to generate a .dot file for importing into graphiz
require 'set'
@dependencies = Hash.new { |hash, key| hash[key] = Set.new }
def add_dependency?(from, to)
# Simplified from the original to exemplify the badness
begin
transaction do
@record.save! if @record.valid?
end
rescue ActiveRecord::RecordInvalid
end
tax n
| n > 60000 = calc n 60000 0.45
| n > 30000 = calc n 30000 0.30
| n > 15000 = calc n 15000 0.15
| otherwise = 0
where calc n t r = ((n - t) * r) + tax t
> tax 72000
=> 16500.0
taxRate threshold rate (total, amount)
| amount > threshold = (total + (amount - threshold) * rate, threshold)
| otherwise = (total, 0)
taxTable = [taxRate 60000 0.45, taxRate 30000 0.30, taxRate 15000 0.15]
tax amount = fst (calc(0, amount) taxTable)
where calc (total, remainder) [] = (total, remainder)
calc (total, remainder) (f:fs) = calc (f (total, remainder)) fs
Welcome to interactive ruby!
irb --> RUBY_VERSION
==> "1.9.1"
irb --> {} == {}
==> true
irb --> {}.eql?({})
==> true
Merriam-Webster notes, "Recent criticism of the use of myriad as a noun, both
in the plural form myriads and in the phrase a myriad of, seems to reflect a
mistaken belief that the word was originally and is still properly only an
adjective.... however, the noun is in fact the older form, dating to the 16th
century. The noun myriad has appeared in the works of such writers as Milton
(plural myriads) and Thoreau (a myriad of), and it continues to occur
frequently in reputable English. There is no reason to avoid it."
(via http://en.wikipedia.org/wiki/Myriad)
require 'rack'
module Rack
class Obama
CONTENT_TYPE = "nobel-prize/peace".freeze
def initialize(app)
@app = app
require 'rack'
module Rack
class Pot
CONTENT_TYPE = "application/coffee-pot-command".freeze
def initialize(app)
@app = app