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 "thwait" | |
class Job; end | |
module Processor | |
def self.perform(worker_count, jobs) | |
workers = worker_count.times.map do | |
Thread.new do | |
while job = jobs.pop | |
yield job |
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 Foo | |
MY_CONST = "hello".freeze | |
end | |
puts Foo::MY_CONST # "hello" | |
Foo.const_set("MY_CONST", "new const") | |
puts Foo::MY_CONST # "new const" | |
class Foo | |
def self.my_const |
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 FooBar | |
attr_reader :a, :b | |
def initialize | |
@a = 1 | |
@b = 2 | |
@c = 3 | |
end | |
def see_the_c |
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 fibbonaci_iterate do | |
Stream.unfold([0, 1], fn [prev, curr] -> {curr, [curr, (prev + curr)]} end) | |
end | |
# fibbonaci_iterate |> Stream.take_every(10) |> Stream.map(fn(x) -> x * 2 end) |> Enum.take(5) | |
# [2, 178, 21892, 2692538, 331160282] | |
# note that the list was actually only enumerated once |
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 BuckFizz | |
def print | |
all.each do |buck_fizz| | |
puts buck_fizz | |
end | |
end | |
private | |
def all |
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 Triangle | |
attr_reader :a | |
attr_reader :b | |
attr_reader :c | |
def initialize(a, b, c) | |
@a, @b, @c = a, b, c | |
end | |
def type |
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
# full description: | |
# https://codility.com/demo/take-sample-test/ps/ | |
# tl;dr: Write a function that, given a zero-indexed non-empty array A consisting of N integers, returns the first covering prefix of A. | |
def solution(a) | |
last_unique = a.uniq.last | |
a.index { |el| el == last_unique } | |
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
class MyClass | |
def word | |
"word" | |
end | |
def go | |
word = word + "whatever" | |
word | |
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
class MyClass | |
def word | |
"word" | |
end | |
def go | |
word = word | |
word | |
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
class FacebookGraph | |
def initialize(token) | |
@graph = Koala::Facebook::API.new(token) | |
end | |
def profile | |
@graph.get_object('me') | |
end | |
def friends_ids |
NewerOlder