Skip to content

Instantly share code, notes, and snippets.

<% 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 -%>
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],
word_signature = ->(word){
word.split('').sort.join('')
}
word_minus_letters_on_indexes = ->(word, ind){
list = word.split('')
list[ind] = nil
list.flatten.join
}
class Fibonacci
include Enumerable
def initialize
@f1 = @f2 = 1
end
def each
yield @f1
loop do
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!
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
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
[
{
"caption": "SublimeREPL: SML",
"command": "run_existing_window_command", "args":
{
"id": "repl_sml",
"file": "config/SML/Main.sublime-menu"
}
}
]
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
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