Skip to content

Instantly share code, notes, and snippets.

# difference between private and protected in Ruby
class Person
def initialize age
@age = age
end
def compare1(another_person)
# this works because #age is protected
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
[
{
"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"
}
}
]
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!
class Fibonacci
include Enumerable
def initialize
@f1 = @f2 = 1
end
def each
yield @f1
loop do
@leikind
leikind / day1.elm
Last active December 6, 2015 12:28
module Day1 where
import Graphics.Element as G
import String
import List
import Maybe exposing ( Maybe(..) )
instructions =
"(((())))()((((((((())()(()))(()((((()(()(((()((()((()(()()()()()))(((()(()((((((((((())(()()((())()(((())))()(()(()((()(()))(()()()()((()((()(((()()(((((((()()())()((((()()(((((()(())()(())((())()()))()(((((((())(()())(()(((())(()))((())))(()((()())))()())((((())))(()(((((()(())(((()()((()((()((((((((((())(()())))))()))())()()((((()()()()()()((((((())())(((()())()((()()(((()()()))(((((()))(((()(()()()(()(()(((())()))(()(((()((())()(()())())))((()()()(()()(((()))(((()((((()(((((()()(()())((()())())(()((((((()(()()))((((()))))())((())()()((()(()))))((((((((()))(()()(((())())(())()((()()()()((()((()((()()(((())))(()((())()((((((((()((()(()()(((())())())))(())())))()((((()))))))())))()()))()())((()())()((()()()))(()()(((()(())((((())())((((((((()()()()())))()()()((((()()))))))()((((()(((()))(()()())))((()()(((()))()()())())(((())((()()(())()()()(((())))))()())((()))()))((())()()())()())
word_signature = ->(word){
word.split('').sort.join('')
}
word_minus_letters_on_indexes = ->(word, ind){
list = word.split('')
list[ind] = nil
list.flatten.join
}
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],