Skip to content

Instantly share code, notes, and snippets.

View spiegela's full-sized avatar

Aaron Spiegel spiegela

View GitHub Profile
@spiegela
spiegela / mailing_list.rb
Created October 15, 2010 01:55
So I wanted to create some default options in my parser. I'm not sure if this is how you would do it, but this is what I figured out...
module Burst
class MailingList
include Typhoeus
DEFAULT_KEY = 'SECRET'
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORT = 3000
remote_defaults :on_success => lambda {|response| Yajl::Parser.parse(response.body)},
:on_failure => lambda {|response| raise "Error code: #{response.code}"},
:base_uri => "http://"
@spiegela
spiegela / gist:777939
Created January 13, 2011 14:32
Mail Enhancement Examples
smtp = Net::SMTP.start('127.0.0.1', 25)
Mail.defaults do
delivery_method :smtp_connection, :connection => smtp
end
mail1 = Mail.deliver do
from '[email protected]'
to '[email protected], [email protected]'
subject 'invalid RFC2822'
@spiegela
spiegela / minion_excerpt.rb
Created March 13, 2011 06:16
Class to check # of requests per window
# From: https://github.com/orionz/minion/blob/master/lib/minion.rb
...
def run
log "Starting minion"
Signal.trap('INT') { AMQP.stop{ EM.stop } }
Signal.trap('TERM'){ AMQP.stop{ EM.stop } }
#!/usr/bin/env ruby
# ^^ Replace with an RVM wrapper if RVM is to be used.
require "bundler/setup"
require 'methadone'
require "etc"
# Lambda for init script to fork into new daemon
STARTUP = labmda{ Verify::Pool.new(:environment => env).start }
@spiegela
spiegela / csv.rb
Created August 10, 2012 04:07
Command line script to Parse CSV files
#!/usr/bin/env ruby
# How about an awesome command-line script
# that replaces your usage of "awk -F, ..."
# for like 99% of cases.
#
# Also, importantly, it supports CSV features
# like escaping commas when quoted
#
# Usage: csv.rb [options] <filename>
@spiegela
spiegela / gist:3383151
Created August 17, 2012 22:07
Thread dump showing celluloid deadlock
Full thread dump OpenJDK 64-Bit Server VM (19.0-b09 mixed mode):
"Thread-2" daemon prio=10 tid=0x00007fa6f4242000 nid=0x16fe in Object.wait() [0x00007fa6f8c09000]
java.lang.Thread.State: TIMED_WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000000f7511728> (a java.lang.Object)
at org.jruby.util.ShellLauncher$StreamPumper.run(ShellLauncher.java:1329)
- locked <0x00000000f7511728> (a java.lang.Object)
"Thread-1" daemon prio=10 tid=0x00007fa6f4240000 nid=0x16fd runnable [0x00007fa6f8e0a000]
Linux version 2.6.31.7 (mitch@home) (gcc version 4.1.2) #1 Sat Dec 19 13:00:37 GST 2009
KERNEL supported cpus:
Intel GenuineIntel
AMD AuthenticAMD
NSC Geode by NSC
Cyrix CyrixInstead
Centaur CentaurHauls
Transmeta GenuineTMx86
Transmeta TransmetaCPU
UMC UMC UMC UMC
@spiegela
spiegela / gist:4009607
Created November 4, 2012 00:41
aa_associations full trace
aa_associations (0.1.1) lib/active_admin_associations/active_admin_extensions.rb:10:in `map'
aa_associations (0.1.1) lib/active_admin_associations/active_admin_extensions.rb:10:in `resources'
aa_associations (0.1.1) app/helpers/active_admin_associations_helper.rb:41:in `resource_administrated?'
aa_associations (0.1.1) app/views/admin/shared/_add_to_association.html.erb:1:in `___olumes__torage__sers_spiegela__rvm_gems_ruby_______p____gems_aa_associations_______app_views_admin_shared__add_to_association_html_erb___1430324781899361445_70241541638800'
actionpack (3.2.8) lib/action_view/template.rb:145:in `block in render'
activesupport (3.2.8) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.8) lib/action_view/template.rb:143:in `render'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:265:in `render_partial'
actionpack (3.2.8) lib/action_view/renderer/partial_renderer.rb:238:in `block in render'
actionpack (3.2.8) lib/action_view/renderer/abstract_renderer.rb:38:in `block in
@spiegela
spiegela / gist:4712000
Last active February 7, 2016 07:33
JRuby & Akka Example
#!/usr/bin/env ruby
require 'java'
require 'scala-library.jar'
require 'config-1.0.0.jar'
require 'akka-actor_2.10-2.1.0.jar'
java_import 'java.io.Serializable'
java_import 'akka.actor.UntypedActor'
java_import 'akka.actor.ActorRef'
@spiegela
spiegela / gzip.rb
Created March 8, 2013 04:00 — forked from romanbsd/gzip.rb
require 'faraday'
require 'zlib'
module FaradayMiddleware
class Gzip < Faraday::Response::Middleware
def on_complete(env)
return unless env[:body].is_a? String
encoding = env[:response_headers]['content-encoding'].to_s.downcase
case encoding