Skip to content

Instantly share code, notes, and snippets.

Thank you for contacting me about the disclosure of the National
Security Agency's (NSA) intelligence gathering programs. It is good to
hear from you on this critical issue.
On June 6, 2013, news outlets reported on a large leak of classified
information by a contractor named Edward Snowden. In the following days
and weeks, more revelations have come to light, including troubling
surveillance practices by the NSA. I believe we now have an important
opportunity for a renewed debate around intelligence gathering
activities and their relationship to Americans' civil liberties,
@abevoelker
abevoelker / pry_session.rb
Created July 9, 2013 17:02
In a Rails controller (in development mode), I somehow got an object that had an invalid or orphaned reference to its class. I'm guessing the class was reloaded at some point by Rails and the Foo constant was changed, but it's weird because I never changed app/models/foo.rb. After I restarted the Rails server the problem was gone. Rails 3.2.13
@foo # => #<Foo @id=1>
Foo.get(1) # => #<Foo @id=1>
Foo.get(1) == @foo # => false
@foo.as_json == Foo.get(1).as_json # => true
Foo.get(1) === @foo # => false
@foo.class # => Foo
Foo.get(1).class # => Foo
@foo.class == Foo.get(1).class # => false
@foo.class == Foo # => false
@abevoelker
abevoelker / deadfish.rb
Created July 1, 2013 15:25
Deadfish interpreter written in Ruby (http://esolangs.org/wiki/Deadfish)
#!/usr/bin/env ruby
n = 0
while true
print '>> '
gets.chomp.each_char do |c|
n = 0 if [-1, 256].include?(n)
case c
when 'd' then n -= 1
when 'i' then n += 1
@abevoelker
abevoelker / Gemfile.lock.diff
Last active December 18, 2015 07:59
Strange bug encountered with `ActionDispatch::Http::UploadedFile#read` returning empty string; see http://stackoverflow.com/questions/16840613/actiondispatchhttpuploadedfileread-returns-empty-string
diff --git a/Gemfile.lock b/Gemfile.lock
index 267c383..6b33c37 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -119,16 +119,16 @@ GEM
remote: http://rubygems.org/
specs:
- actionmailer (3.2.13)
- actionpack (= 3.2.13)
- mail (~> 2.5.3)
@abevoelker
abevoelker / rate_limiter.rb
Last active December 17, 2015 13:19
Basic rate limiter using Celluloid
class RateLimiter
include Celluloid
def initialize(actions_per, seconds)
@bucket, @nice = actions_per, seconds
end
def request
wait :bucket_increment unless @bucket > 0
@bucket -= 1
$ rvm info
jruby-1.6.7.2@temp:
system:
uname: "Linux STAGING1 2.6.32-25-server #45-Ubuntu SMP Sat Oct 16 20:06:58 UTC 2010 x86_64 GNU/Linux"
system: "ubuntu/10.04/x86_64"
bash: "/bin/bash => GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)"
zsh: "/usr/bin/zsh => zsh 4.3.10 (x86_64-unknown-linux-gnu)"
@abevoelker
abevoelker / inlinenestedmodel.js
Created October 15, 2012 21:21 — forked from philfreo/inlinenestedmodel.js
Backbone-Forms InlineNestedModel
;(function() {
var Form = Backbone.Form,
editors = Form.editors;
// we don't want our nested form to have a (nested) <form> tag
// (currently bbf includes form tags: https://github.com/powmedia/backbone-forms/issues/8)
// aside from being strange html to have nested form tags, it causes submission-upon-enter
Form.setTemplates({
nestedForm: '<div class="bbf-nested-form">{{fieldsets}}</div>'
@abevoelker
abevoelker / dsl.rb
Created August 9, 2012 19:09
Goal DSL for XFA manipulation
data = {:name => 'Bob', :gender => 'm', :relation => 'Uncle' }
pdfs = capture_pdfs do
pdf :basic_info do
text 'name', data[:name]
radio_group 'sex' do
fill 'male', :when => data[:gender] == 'm'
fill 'female', :when => data[:gender] == 'f'
end
checkbox_group 'relation' do
@abevoelker
abevoelker / hflatten.rb
Created July 31, 2012 19:58
Convert Ruby hash keys to dotted form like backbone-deep-model
class Hash
def hflatten(path=[])
self.inject({}) do |a,(k,v)|
if v.is_a? Hash
# Recurse
a.merge(v.hflatten(path.dup << k))
else
# Base case
a[(path.dup << k).join('.')] = v; a
end
require 'sinatra'
require './models'
get '/customers' do
Customer.all.to_json
end
get '/customer/:cust_num' do |cust_num|
@customer = Customer.get(cust_num)
if @customer