Skip to content

Instantly share code, notes, and snippets.

View harukizaemon's full-sized avatar

Simon Harris harukizaemon

View GitHub Profile
@harukizaemon
harukizaemon / gist:0c5dd4db7406d119b166
Created July 9, 2014 03:50
Replace assertThat with assertEquals
assertThat\((.*), is\((.*)\)\);
assertEquals($2, $1);
assertThat\((.*), nullValue\(\)\);
assertNull($1);

Keybase proof

I hereby claim:

  • I am harukizaemon on github.
  • I am haruki_zaemon (https://keybase.io/haruki_zaemon) on keybase.
  • I have a public key whose fingerprint is F16A BCF7 8D71 631E 4810 8091 FCFC 89CE 3725 4EF6

To claim this, I am signing this object:

public static boolean isPresent(final Optional<?> ... optionals) {
for (final Optional<?> optional : optionals) {
if (!optional.isPresent()) {
return false;
}
}
return optionals.length > 0;
}
if (myOptionalThing.isPresent()) {
myOptionalThing.get().doSomething();
}
// vs
myOptionalThing.ifPresent(MyOptionalThing::doSomething);
// vs
@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