Skip to content

Instantly share code, notes, and snippets.

Avatar
🍔
Building Pingboard. Accepting JavaScript. Still loving Rails. Telling jokes.

Adam Keys therealadam

🍔
Building Pingboard. Accepting JavaScript. Still loving Rails. Telling jokes.
View GitHub Profile
@therealadam
therealadam / SketchSystems.spec
Last active Sep 2, 2018
A Markdown and Unfurling Saavy Text Cell
View SketchSystems.spec
A Markdown and Unfurling Saavy Text Cell
Empty Cell*
click inside -> Edit Cell
Edit Cell
type markdown -> Edit Cell
type URL -> Edit Cell with unfurl
Edit Cell with unfurl
click save -> Populated Cell
click outside -> Populated Cell
Populated Cell
@therealadam
therealadam / maps.rb
Created Mar 25, 2016
Can you chain maps and eat cake too?
View maps.rb
Allocations -------------------------------------
null 0/0 alloc/ret 0/0 strings/ret
mega no work 1/0 alloc/ret 0/0 strings/ret
mega w/ locals 1446/114 alloc/ret 50/50 strings/ret
chained 1334/0 alloc/ret 50/0 strings/ret
lazy chained 2102/0 alloc/ret 50/0 strings/ret
Warming up --------------------------------------
null 151.895k i/100ms
mega no work 6.384k i/100ms
mega w/ locals 135.000 i/100ms
@therealadam
therealadam / lol.rb
Last active Dec 12, 2015
I took producer.rb, added threads and made it two orders of magnitude slower. Thus was born, lol.rb. (NOW LOLFAST)
View lol.rb
require 'thread'
require 'ffaker'
require 'json'
def new_message
text = Faker::HipsterIpsum.sentences(3)
metrics = {
temp: rand(110), # degrees F
mass: rand(100), # kilograms
speed: rand(70) # miles per hour
View simplequeue.rb
# Simple Queue
# ------------
#
# A riff on bitly's HTTP-based simple queue[1]
#
# [1] https://github.com/bitly/simplehttp/blob/master/simplequeue/simplequeue.c
#
# Is it any good?
# ===============
#
@therealadam
therealadam / gist:2953970
Created Jun 19, 2012
Baby's first concurrent program
View gist:2953970
# http://weblog.therealadam.com/2012/06/19/getting-started-with-ruby-concurrency-using-two-simple-classes/
require 'thread'
require 'timeout'
module Work
@queue = Queue.new
@n_threads = 2
@workers = []
@running = true
View postbin.rb
# Postbin
# -------
# A postbin for your localhost.
#
# Usage
# =====
#
# It's a Unix program. You run it from a shell.
#
# $ ./postbin [-p PORT]
@therealadam
therealadam / README.md
Created Feb 22, 2012
Run focused unit tests in Vim, with a little help from Ruby.
View README.md
  • Move focus to somewhere on your PATH
  • Drop focus.vim in ~/.vim/plugins
  • Put focus on a key. I went with nnoremap <leader>tf :call Focus().
  • Open a test/unit file, put your cursor inside a test method and run focus.
  • Profit
@therealadam
therealadam / gist:1862005
Created Feb 19, 2012
A lenient cane script for a Rails project
View gist:1862005
#!/bin/sh
max_violations=0 # We run a tight ship...
complexity_max=60 # ...but we've got stuff to clean up
cane \
--max-violations $max_violations \
--abc-glob '{app,lib}/**/*.rb' \
--abc-max=$complexity_max \
--no-style \
@therealadam
therealadam / gist:1627058
Created Jan 17, 2012
Sugar for swallowing exceptions
View gist:1627058
# Suppose we're going to have a bunch of code like the following
# boilerplate (ignore the unfortunate nil propagation)
@city = begin
GizmoStore::Thingy.get(123)
rescue GizmoStore::NotFound
nil
end
# I can't decide if this is useful boilerplate elimination or
# saccharine ivory tower abstraction.
View test.sh
#!/bin/sh
message=$0 || "this just happened #boom"
echo "this just happened #boom" | nc -c localhost 4321
echo '....'
sleep 1
psql wcld -c 'select * from events order by time DESC;'