This file contains 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
<% grid(@countries_grid, :erb_mode => true) do |g| %> | |
<% g.column :column_name => 'Name', :attribute_name => 'name' do |country| %> | |
<b>Name: <%= link_to(country.name, country_path(country)) %></b> | |
<% end %> | |
<% end -%> |
This file contains 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
def screen_density diagonal_size_inches, width_pixels, height_pixels | |
Math.sqrt(width_pixels * width_pixels + height_pixels * height_pixels) / diagonal_size_inches | |
end | |
[ | |
['Kindle Fire', 7, 600, 1024], | |
['Nexus 10', 10.05, 2560, 1600], | |
['Kindle Fire HD', 7, 1280, 800], | |
['Asus Transformer Pad Infinity 700 Series', 10.1, 1920, 1200], | |
['Asus Transformer Pad TF300', 10.1, 1280, 800], |
This file contains 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
word_signature = ->(word){ | |
word.split('').sort.join('') | |
} | |
word_minus_letters_on_indexes = ->(word, ind){ | |
list = word.split('') | |
list[ind] = nil | |
list.flatten.join | |
} |
This file contains 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 Fibonacci | |
include Enumerable | |
def initialize | |
@f1 = @f2 = 1 | |
end | |
def each | |
yield @f1 | |
loop do |
This file contains 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 'fiber' | |
module Enumerable | |
def my_each | |
if block_given? # usual execution with a block | |
self.each do |e| | |
yield e | |
end | |
else # no block given! |
This file contains 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
su | |
# Install rbenv | |
git clone git://github.com/sstephenson/rbenv.git /usr/local/rbenv | |
# Add rbenv to the path: | |
echo '# rbenv setup' > /etc/profile.d/rbenv.sh | |
echo 'export RBENV_ROOT=/usr/local/rbenv' >> /etc/profile.d/rbenv.sh | |
echo 'export PATH="$RBENV_ROOT/bin:$PATH"' >> /etc/profile.d/rbenv.sh | |
echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh |
This file contains 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
[ | |
{ | |
"id": "tools", | |
"children": | |
[{ | |
"caption": "SublimeREPL", | |
"mnemonic": "r", | |
"id": "SublimeREPL", | |
"children": | |
[ |
This file contains 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
Show hidden characters
[ | |
{ | |
"caption": "SublimeREPL: SML", | |
"command": "run_existing_window_command", "args": | |
{ | |
"id": "repl_sml", | |
"file": "config/SML/Main.sublime-menu" | |
} | |
} | |
] |
This file contains 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
object PassByNameDemo extends App { | |
def badImplementationOfAnd(arg1: Boolean, arg2: Boolean) = if (arg1) arg2 else false | |
// Causes: java.lang.ArithmeticException: / by zero | |
// because the secons argument is always evaluated no matter if the first is true or false | |
// badImplementationOfAnd( 1 == 2, 3 == (1 / 0)) | |
def goodImplementationOfAnd(arg1: Boolean, arg2: => Boolean) = if (arg1) arg2 else false |
This file contains 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
object PassByNameDemo extends App { | |
def badImplementationOfAnd(arg1: Boolean, arg2: Boolean) = if (arg1) arg2 else false | |
// Causes: java.lang.ArithmeticException: / by zero | |
// because the second argument is always evaluated no matter if the first is true or false | |
// badImplementationOfAnd( 1 == 2, 3 == (1 / 0)) | |
def goodImplementationOfAnd(arg1: Boolean, arg2: => Boolean) = if (arg1) arg2 else false |