Skip to content

Instantly share code, notes, and snippets.

View rthbound's full-sized avatar

Ryan T. Hosford rthbound

View GitHub Profile
@rthbound
rthbound / crop_and_transform.sh
Last active January 7, 2016 06:32
Taking fft of the squares in https://imgh.us/eca.png
convert eca.png -crop 400x400 +repage tiles_%03d.png
convert -dispose previous -loop 0 tiles_*.png eca.gif
for i in $(ls tiles*); do convert $i -fft +depth +adjoin fft_%d_$i; done
convert -dispose previous -loop 0 fft_1_tiles_*.png eca-fft-phase.gif
convert -dispose previous -loop 0 fft_0_tiles_*.png eca-fft-mag.gif
@rthbound
rthbound / advent_of_code.day6.rb
Last active January 5, 2016 06:34
http://adventofcode.com/day/6 solution in ruby... roughly 10 seconds to finish running (per part)
def run_commands(commands)
commands.each { |command|
command_set = command.match(/(\w*)\s(\d*,\d*)\s\w*\s(\d*,\d*)/).to_a[1..-1]
s = command_set[1].split(",").map(&:to_i)
e = command_set[-1].split(",").map(&:to_i)
s[0].upto(e[0]) do |x|
s[1].upto(e[1]) do |y|
@lights[x * 1000 + y] = @instructions[command_set[0].to_sym].call(@lights[x * 1000 + y])
end
end
@rthbound
rthbound / hangman_cheat_sheet.txt
Last active November 30, 2015 03:44
Cheat sheet for DeBot's hangman game :P
pokemon: 720
513 a
472 e
440 o
414 r
395 i
348 l
327 n
290 t
276 s
@rthbound
rthbound / html_flip_flop.rb
Created September 3, 2015 21:18 — forked from baweaver/html_flip_flop.rb
Abusing flip flops for HTML parsing after watching a ruby tapa ala Avdi.
IO.readlines('test.html')
.flat_map(&:split)
.select { |word|
true if word =~ %r{<strong>} .. word =~ %r{</strong>}
}
# => ["<strong>multiple</strong>","<strong>strong</strong>"]
# test.html
#
@rthbound
rthbound / dynamic_stylesheet.rb
Last active August 29, 2015 09:03 — forked from mattsmith/dynamic_stylesheet.rb
Renders a scss stylesheet with erb using Tilt templates.
class DynamicStylesheet
# logical_path = 'app/assets/stylesheets/custom.css.scss.erb'
def render(logical_path, data={})
path = Rails.root.join(logical_path)
context = env.context_class.new(env, logical_path, Pathname.new(path))
# TODO Change to Tilt.templates_for(file) in Tilt 2.x
templates = [Tilt::ERBTemplate, Sass::Rails::ScssTemplate]
def lookup(x); { a: 1, b: 2, c: 3 }[x]; end
def promos; { x: :a, y: :b, z: :c }; end
@promo_counts = Concurrent::Promise.fulfill(@promos = promos).then { |val| Concurrent::Promise.zip(*val.map { |x,v| Concurrent::Promise.new { { x => lookup(v) } } }).value }.value
#=> [{:x=>1}, {:y=>2}, {:z=>3}]
@promos
#=> {:x=>:a, :y=>:b, :z=>:c}
<!DOCTYPE html>
<html>
<div class='colors' data-label='PRIMARY' data-color='blue'></div>
<div class='colors' data-label='FOOBAR' data-color='green'></div>
<select>
<option value='PRIMARY'>PRIMARY</option>
<option value='FOOBAR'>FOOBAR</option>
</select>
<script type='text/javascript' src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
@rthbound
rthbound / seeding_from_csv_with_psql.rb
Created August 13, 2015 19:10
Procedure for seeding using psql's `copy`
models = %w{
skins
themes
options
site_settings
links
faq_categories
faq_questions
faq_answers
completion_indicators
@rthbound
rthbound / skip.rb
Last active August 29, 2015 14:24 — forked from adampats/skip.rb
@panels = @servicelist.map do |service|
if service[:hidden] == "true"
nil
else
{
title: service[:title],
panel_name: __method__.to_s,
icon: service[:logo],
query_string: {},
id: service[:id]
@rthbound
rthbound / comparison.md
Created June 25, 2015 19:40
comparing concurrent-ruby to browser concurrency

All requests made to same resource: http://httpbin.org/delay/1 The minimum possible response time for a single request: 1 second

Scenario 1: Use concurrent-ruby to make 64 requests as concurrently as possible On my machine (8 processors), performing 64 requests as concurrently as possible took 46.2 seconds total. The average response time was 1.18s.

Scenario 2: Use javascript/browser to make 64 requests as concurrently as possible Using google chrome, performing 64 requests as concurrently as possible took 3.09 seconds total. The average response time was also ~1s.