Skip to content

Instantly share code, notes, and snippets.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class Lucky13 {
public static double getWinnings(double bet) throws MalformedURLException, IOException {
return (new BufferedReader(new InputStreamReader(((InputStream)(new URL("http://roulette.engineyard.com/").getContent())))).readLine().indexOf("13") != -1) ? 35 * bet : 0;
class Array
def recursive_reverse
return self if empty?
[pop, *recursive_reverse]
end
end
puts [1,2,3,4].recursive_reverse.inspect
@posts.try(:each) do |post|
# something with post
end
case "Foo BAR baz"
when /bar/i
puts "This will occur"
end
def with_scope(*locator)
locator.compact.empty? ? yield : within(*locator) { yield }
end
array = [1, 2, 3, 4, 5]
print_procs = []
array.each do |i|
print_procs.push lambda { puts i }
end
print_procs.each(&:call)
puts
def execute
x = 3
yield
end
x = 1
execute { puts x }
x = 1
block = lambda { puts x }
block.call
x = 3
block.call
actions = []
for i in [1, 2, 3, 4, 5]
actions.push lambda { puts i }
end
actions.each(&:call)
actions = []
[1, 2, 3, 4, 5].each do |i|
actions.push lambda { puts i }
end
actions.each(&:call)