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 CallbackRegister | |
def initialize | |
@callbacks = {read: [], write: []} | |
end | |
def each(type, &block) | |
@callbacks[type].each do |callback| | |
yield callback | |
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 process_partial_file_input(data) | |
# Do something cool with data | |
end | |
# Event loop | |
big_file = "network/path/big_file.xlsx" | |
file_handler = open(big_file) | |
files_to_look_after = [file_handler] |
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
function x() { | |
alert(x); | |
var x = "Interesting…" | |
} |
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
function x() { | |
if(true) { | |
var x = "Interesting" | |
} | |
alert(x); | |
} |
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 multiply_by_two | |
multiplicand = 2 | |
test_method | |
end | |
def multiply_by_three | |
multiplicand = 3 | |
test_method | |
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 test_method | |
method_variable = 4 | |
different_variable = [1,2,3] | |
different_variable.map do |number| | |
number * method_variable | |
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 DoorLock | |
def initialize(locked) | |
@locked = locked | |
@mutex = Mutex.new | |
end | |
def open? | |
@mutex.synchronize { !@locked } | |
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
4.times.map do | |
t = Thread.current | |
t["#{dynamic_variable_name}".to_sym] = method_call | |
end | |
joined_threads = threads.map &:join | |
joined_threads.each do |t| | |
# The keys method returns all thread local variables by names | |
# analog to the Hash#keys method | |
t.keys.each do |key| |
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 DoorLock | |
def initialize(locked) | |
@locked = locked | |
end | |
def open? | |
!@locked | |
end | |
def unlock! |
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
resource_a = [] | |
threads = [] | |
threads << Thread.new do |t| | |
50.times do |i| | |
resource_a << i | |
end | |
end | |
threads << Thread.new do |t| |
NewerOlder