Yuri Leikind leikind

View gist:9794053
1 2 3 4 5 6 7 8 9 10
(defprotocol Inspect (inspect [c]))
 
(defprotocol Maths
(plus [this another])
(multiply [this another]))
 
(defrecord Rational [nom den]
 
Inspect
(inspect [this] (str (:nom this) "/" (:den this) ))
View view_column_sophia_date.rb
1 2 3 4 5 6 7 8 9 10
# {
# "docs"=>
# {
# "f"=>
# {
# "document_date"=>
# {
# "fr"=>"2014-02-07",
# "to"=>"2014-02-21"
# },
View resize_iframe_height.js
1 2 3 4 5 6 7 8 9 10
// Resize iframe height
 
jQuery(function(){
var iframes = $('iframe.resize-to-max-height');
 
var pageY = function (elem) {
return elem.offsetParent ? (elem.offsetTop + pageY(elem.offsetParent)) : elem.offsetTop;
}
 
if (iframes.length){
View water_and_blocks.ex
1 2 3 4 5 6 7 8 9 10
defmodule Rain do
def count_blocks_with_water(blocks) do
Enum.map(Enum.max(blocks)..0, &(&1)) |>
Enum.reduce 0, fn(level, sum) ->
 
sum +
(Enum.with_index(blocks) |>
Enum.filter(fn({block, _}) ->
block >= level
end) |>
View water_and_blocks.rb
1 2 3 4 5 6 7 8 9 10
 
def count_blocks_with_water blocks
blocks.max.downto(0).reduce(0){|sum, level|
sum +
blocks.each_with_index.select{|block, idx|
block >= level
}.map{|_, idx|
idx
}.each_cons(2).reduce(0){|accu, tuple|
accu + tuple[1] - tuple[0] - 1
View parallel_map.erl
1 2 3 4 5 6 7 8 9 10
your_map(Function, List) ->
ParentProcessPid = self(),
 
Pids = lists:map(
fun(Element) ->
spawn(
fun()->
ParentProcessPid ! {self(), Function(Element) }
end
)
View sequence_server.ex
1 2 3 4 5 6 7 8 9 10
defmodule Sequence.Server do
 
use GenServer.Behaviour
 
# External API
def start_link(current_number) do
:gen_server.start_link({ :local, :sequence }, __MODULE__, current_number, [])
end
 
def next_number do
View sequence_server.erl
1 2 3 4 5 6 7 8 9 10
-module(sequence_server).
 
-behaviour(gen_server).
 
% External API
-export([
start_link/1,
next_number/0,
increment_number/1
]).
View blocks.rb
1 2 3 4 5 6 7 8 9 10
 
#Standard library
 
File.open(path, "w") do |file|
file_data = file.read
end
Benchmark.bm do |x|
x.report { for i in 1..n; a = "1"; end }
View difference_between_private_and_protected.rb
1 2 3 4 5 6 7 8 9 10
# 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
Something went wrong with that request. Please try again.