View now.rb
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
PIPELINE = %w[booked collected ironed delivered] | |
def state | |
PIPELINE[@pipeline_position] | |
end | |
def advance | |
@pipeline_position += 1 | |
end |
View flatten.rb
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
module Fluent | |
class TextParser | |
class StringifiedValuesJSONParser < JSONParser | |
Plugin.register_parser("stringified_values_json", self) | |
def parse(text) | |
time, record = super(text) | |
# replace all Hash (like a dict) values with stringified JSON | |
record = record.inject({}) { | new_hash, (key, value) | |
View gist:1922637
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 Contract < ActiveRecord::Base | |
has_paper_trail | |
acts_as_restful_list | |
CHANGE_FIELDS_MAP = { | |
'contract_status_id' => { | |
:association => 'contract_status' | |
:field => 'name' | |
} |
View explicit.rb
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 PullSource | |
def self.implementations | |
@implementations ||= {} | |
end | |
def self.register(name) | |
implementations[name] << self | |
end |
View get_data.rb
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 GetData | |
@@logger = Logger.new('log.log') | |
def initialize | |
@yesterday = Date.today.prev_day | |
@token = xxx | |
end | |
def save_actions | |
with_database do |db| |
View act.rb
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
w_r, w_w = IO.pipe | |
t_r, t_w = IO.pipe | |
work = Thread.new { block.call; w_w.write('.') } | |
timeout = Thread.new{ sleep 10; t_w.write('.') } | |
io = IO.select [w_r, t_r] | |
if io == t_r | |
#Timeout |
View get_transactions.rb
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
# /^(\d{2}\/\d{2}) (.*) (\-?\d+\.\d+)/ | |
File.open ARGV[0], 'r' do |file| | |
file.each_line do |line| | |
if m = line.match(/^(\d{2}\/\d{2}) (.*) (\-?\d+\.\d+)/) | |
puts [m[1], m[2], m[3]].join(', ') | |
end | |
end |
View library.rb
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 Library | |
attr_accessor :games | |
def each | |
games.each do |game| | |
yield game | |
end | |
end | |
end |
View gist:38eaeed4884283e9c2ed
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 | |
require 'socket' | |
require 'thread' | |
threads = Array.new | |
ports = [*(1..1024)] | |
mutex = Mutex.new | |
20.times do |
View mtool.rb
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 'api/pools.rb' | |
module Mtool | |
extend Blather::DSL | |
#Blather.logger.level = Logger::DEBUG | |
Blather.logger.level = Logger::INFO | |
@@faye = nil |
NewerOlder