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
; The code in this file was mechanically extracted from the TeX | |
; source files of _Ansi Common Lisp_, except for bst-remove and | |
; bst-delete and their subroutines, which replace broken versions | |
; in the book. | |
; If you have questions or comments about this code, or you want | |
; something I didn't include, send mail to lispcode@paulgraham.com. | |
; This code is copyright 1995 by Paul Graham, but anyone who wants | |
; to use it is free to do so. |
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 DIContainer | |
def configure | |
yield self | |
end | |
def method_missing(key, val) | |
if key =~ /=$/ | |
key = key.to_s.chop | |
(class << self; self; end).class_eval do | |
attr_accessor 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
m = Mutex.new | |
c = ConditionVariable.new | |
tg = ThreadGroup.new | |
t = 5.times.map do |n| | |
tg.add(Thread.new do | |
print "starting #{n}\n" | |
m.synchronize do |
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 "thread" | |
require "connection_pool" | |
require "pp" | |
NUM_CLIENTS = 9 | |
MAX_AT_A_TIME = 3 | |
TIMEOUT = 10 | |
JOB_TIME = 3 | |
# we'll let people lease access to zero |
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
=begin | |
{ | |
"AccessKey": { | |
"UserName": "s3.deploy.foo", | |
"Status": "Active", | |
"CreateDate": "2016-11-04T16:25:27.123Z", | |
"SecretAccessKey": "secret", | |
"AccessKeyId": "access" | |
} | |
} |
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
defmodule DFA do | |
def accepts?(accept: accept_states, rules: rules, s: string) do | |
string | |
|> String.graphemes | |
|> List.foldl(1, fn(char, state) -> next(state: state, char: char, rules: rules) end) | |
|> member?(accept_states) | |
end | |
defp next(state: nil, char: _char, rules: _rules) do | |
nil |
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 'httparty' | |
require 'redis' | |
require 'json' | |
require 'timeout' | |
$publisher = Redis.new | |
$subscriber = Redis.new | |
CHANNEL = 'omg' |
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
# or `echo some-request | nc localhost 8181 -4u ` | |
MAX_READ = 1024 * 8 | |
FLAGS = 0 | |
c = Socket.new :INET, :DGRAM | |
s = Socket.pack_sockaddr_in 8181, "127.0.0.1" | |
c.send("some-request", FLAGS, s) | |
res = c.recv(MAX_READ) |
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
strace cmd 2> /dev/stdout | cut -d '(' -f 1 | sort | uniq | grep -v "[+=]" | sort -rn -k1,1 |
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
# A reminder that join conceptually combines the stacks of the parent and child threads. | |
# If you consider that the stack grows downard, the child stack will sit below the parent | |
# stack. See output below. | |
def main? | |
Thread.current == Thread.main | |
end | |
def name | |
if main? | |
"main" |
NewerOlder