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
#!/usr/bin/env ruby | |
puts "from original executable, args: #{ARGV.join(" ")}" |
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 "pstore" | |
module Notes | |
class << self | |
attr_accessor :store_location | |
def put_note(id, note) | |
store.transaction do | |
store[:notes] ||= {} | |
store[:notes][id] = note |
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
#!/usr/bin/env ruby | |
def exit_upon(*signals) | |
process_going_down = false | |
signals.map { |signal| signal.to_s.upcase }.each do |signal| | |
Signal.trap(signal) do | |
exit! if process_going_down # terminate if still executing the given block | |
process_going_down = true | |
yield(signal) if block_given? | |
exit! 0 |
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
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'thread' | |
class CountDownLatch | |
attr_reader :count | |
def initialize(to) | |
@count = to.to_i |
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
# coding: utf-8 | |
SIZE = ARGV.shift.to_i | |
FILENAME = ARGV.shift | |
if SIZE < 1 || FILENAME.nil? | |
puts "Usage: ruby #{File.basename(__FILE__)} <size> <file>" | |
exit 1 | |
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
# coding: utf-8 | |
module PFork | |
extend self | |
# Call function +fun+ in a child process, giving access to the child process | |
# id and capturing STDIN, STDOUT, and STDERR of the function call. | |
# | |
# Adapted from stdlib's Open3::popen3 and | |
# {Open4::popen4}[https://github.com/ahoward/open4] by Ara T. Howard, but |
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
# coding: utf-8 | |
# Test global state changing code with fork | |
# | |
# * You should avoid having global state altogether | |
# * That said, if you cannot avoid it, for one reason or another, | |
# you can execute state changing code in a child process | |
# * Fork a child process, execute state changing code there | |
# * The forked child process has its own memory space, separate | |
# from the parent process |
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 withBeforeAll(tests) { | |
var beforeAllCalled = false | |
var helpers = { | |
beforeAll: function (fun) { | |
beforeEach(function () { | |
if (beforeAllCalled) return | |
fun() | |
runs(function () { beforeAllCalled = true } ) | |
}) |
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
(ns pi-estimation | |
"See Opinion 18 in <http://programmers.blogoverflow.com/2012/08/20-controversial-programming-opinions/>") | |
;; Given that Pi can be estimated using the function 4 * (1 – 1/3 + 1/5 | |
;; – 1/7 + …) with more terms giving greater accuracy, write a function that | |
;; calculates Pi to an accuracy of 5 decimal places.) | |
;; with lazy-seq | |
(defn odds [] |
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
var subj0 = new Rx.Subject() | |
var obs0 = subj0.doAction(function(e) { console.log("obs0 doAction", e) }) | |
var subs0_1 = obs0.subscribe(function(e) { console.log("subs0_1", e) }) | |
subj0.onNext('a') | |
//> obs0 doAction a | |
//> subs0_1 a | |
var subs0_2 = obs0.subscribe(function(e) { console.log("subs0_2", e) }) | |
subj0.onNext('b') |
OlderNewer