This file contains hidden or 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 "thread" | |
class BoundedQueue | |
def initialize(max_size = :infinite) | |
@lock = Mutex.new | |
@items = [] | |
@item_available = ConditionVariable.new | |
@max_size = max_size | |
@space_available = ConditionVariable.new | |
end |
This file contains hidden or 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
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title>table test</title> | |
</head> | |
<body> | |
<h1>table test</h1> | |
<table> | |
<colgroup> |
This file contains hidden or 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
Open3.pipeline_r( | |
%W[xmllint --xinclude --xmlout #{spine_file}], | |
# In order to clean up extraneous namespace declarations we need a second | |
# xmllint process | |
%W[xmllint --format --nsclean --xmlout -]) do |output, wait_thr| | |
open(codex_file, 'w') do |f| | |
IO.copy_stream(output, f) | |
end | |
end |
This file contains hidden or 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 SomeORM | |
def self.attributes(*names) | |
if const_defined?(:DynamicAttributes, false) | |
mod = const_get(:DynamicAttributes) | |
else | |
mod = const_set(:DynamicAttributes, Module.new) | |
include mod | |
end | |
mod.module_eval do | |
names.each do |name| |
This file contains hidden or 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 next_state | |
(board, x, y) -> | |
cell = cell_at(board, x, y) | |
live_count = live_neighbors(board, x, y) | |
next_state(cell, live_count) | |
end | |
("o", live_count) when live_count in 2..3 -> "o" | |
("o", _) -> "." | |
(".", live_count) when live_count === 3 -> "o" | |
(".", _) -> "." |
This file contains hidden or 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 'thread' | |
require 'benchmark' | |
module FibSolver | |
def self.fib(scheduler_queue, my_queue) | |
loop do | |
scheduler_queue << [:ready, my_queue] | |
message, *args = my_queue.pop | |
case message | |
when :fib |
This file contains hidden or 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
defmodule Life do | |
def run(board) when is_binary(board) do | |
board |> parse_board |> run | |
end | |
def run(board) do | |
IO.write("\e[H\e[2J") | |
Life.print_board board | |
:timer.sleep 1000 | |
board = next_board(board) |
This file contains hidden or 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
module Node | |
def inspect | |
"<<#{self}>>" | |
end | |
end | |
Number = Struct.new(:value) do | |
include Node | |
def to_s |
This file contains hidden or 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
# An experiment in higher-order (?) messages in Ruby. | |
class Message | |
attr_reader :name | |
attr_reader :arguments | |
def initialize(name, *arguments) | |
@name = name | |
@arguments = arguments | |
end |