This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<Foo> sort(List<Foo> foos) { | |
return Collections.sort(foos, new Comparator<Foo>() { | |
@Override | |
public int compare(Foo a, Foo b) { | |
//comparison logic | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
class PerfTest | |
def with_inject(array) | |
mapped_vals.inject(array, :<<) | |
end | |
def with_plus(array) | |
array + mapped_vals | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>> User.last.update_attributes(nil) | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Doer { | |
public void doStuff(Speaker speaker) { | |
speaker.speak(); | |
} | |
} | |
interface Speaker { | |
void speak(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MasterOfCeremonies { //I hate naming in potted examples | |
public void handle(Dog dog) { | |
dog.speak(); | |
} | |
} | |
class Dog { | |
public void speak() { | |
//something | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PrivacyExample | |
def some_public_method | |
self.some_private_method | |
end | |
def some_private_method | |
"o hai" | |
end | |
private :some_private_method | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CSVParser | |
def initialize(line_handler=nil) | |
@line_handler = line_handler | |
@current_line = [] | |
@lines = [] | |
end | |
def receive(chunk) | |
#handle the chunk depending on state | |
#if we detect end of line: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
B = Module.new | |
def ieval(&block) | |
instance_eval(&block) | |
end | |
end | |
B = Module.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
typeset -A files_by_sum | |
find $1 -maxdepth 1 | while read file; do | |
if [ -f $file ]; then #don't look at directories | |
sum=$(cat $file | md5sum | awk '{print $1}') | |
current=${files_by_sum[$sum]} | |
if [ $current ]; then | |
rm $file | |
ln -s $(basename $current) $file | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#What follows is an extremely contrived example of how this might | |
# look. Please don't pay attention to the incredibly naive JSON | |
# and HTML creation code, that's not supposed to be the point. | |
class Account | |
def show_on(view) | |
view.show_balance(self.balance) | |
view.show_holder(self.holder_name) | |
view.show_creation_date(self.created_at) | |
end |