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 'net/https' | |
require 'excon' | |
require 'fileutils' | |
require 'uri' | |
require 'byebug' | |
class HttpClient | |
SLASH = "\u2215" | |
attr_reader :connection, :host, :opts |
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
#!/bin/usr/env ruby | |
# | |
require 'pp' | |
class App | |
def run | |
catch :done do | |
Signal.trap "INT" do | |
throw :done |
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
#!/bin/bash | |
function terminate { | |
local name=$1 | |
tmux has-session -t $name > /dev/null 2>&1 | |
if [ $? == 0 ]; then | |
echo "terminating $name" | |
tmux kill-session -t $name | |
fi |
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 'pp' | |
class Promise | |
def initialize(*args, &block) | |
@thread = Thread.new(args) do | |
@value = yield *args | |
end | |
end | |
def value |
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 'logger' | |
require 'monitor' | |
# Traditional log rotation, via /usr/sbin/logrotate, just renames | |
# the log file. It's the responsibiilty of the application to notice | |
# this and re-open it's log file at the original path. | |
# | |
# If the application fails to do this it will continue to write to | |
# the original, now renamed, log file. | |
# |
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 | |
# | |
# This works but channel is not intended to be used across threads so this needs | |
# to be re-worked. Instead rewrite it so that the subscribe loop is done manually | |
# inside that loop it will check for a message and queue it if one exist. check | |
# for a completed job and eithe ack/nack it. The entire rabbit connection | |
# and conversation will be inside that one thread | |
# |
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
# Demonstrate creating a command loop in a service with | |
# a unix domain socket. This would be run in a separate | |
# thread from the main application. Any data it acessess | |
# from the main app will have to be thread safe. | |
require "socket" | |
require 'pp' | |
PATH = '/tmp/simple.sock' # This is the location of the domain socket used by clients to | |
# connect with this 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
boss = fork do # Create a 'boss' process, that will be the parent of workers. | |
Process.setpgrp # Give 'boss' a new processes-group so that it's different | |
# than the top level script's process-group | |
5.times do # Create multiple workers, they share the boss's process group | |
fork do | |
done = false # We're not done when we start | |
Signal.trap('TERM') { done = true } # If worker receives 'TERM' start a graceful shutdown | |
1.upto(60) do # do some fake work for 60 seconds | |
break if done # or until we're done |
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 'everything' | |
# read config, setup logging here. | |
def run(job) | |
# This will happen in separate process which means all the memory | |
# it uses will be given back to the system after it's done | |
end | |
done = false |
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 'optparse' | |
require 'pp' | |
task :minitest do | |
options = {} | |
OptionParser.new do |opts| | |
opts.on("-f", "--filename FILENAME", "file to test"){|v| options[:filename]=v} | |
opts.on("-t", "--testname TESTNAME", "test to test"){|v| options[:testname]=v} | |
opts.on("-s", "--seed SEED", "seed value"){|v| options[:seed]=v} | |
opts.parse(ARGV.drop(2)) |