Skip to content

Instantly share code, notes, and snippets.

@watsonbox
watsonbox / xmp_scan.rb
Created December 15, 2014 16:23
Scans a folder of photos looking for save timestamps in XMP header
#! /usr/bin/env ruby
#
# Scans a folder of photos looking for save timestamps in XMP header
#
require 'nokogiri'
dir = ARGV[0]
Dir.foreach(dir) do |file|
@watsonbox
watsonbox / gist:6534827
Created September 12, 2013 09:12
Ruby backtrace produced by nrdebug for stuck resque worker
Ruby Backtrace:
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:121:in `block in start'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:121:in `loop'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:132:in `block (2 levels) in start'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:132:in `each'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:133:in `block (3 levels) in start'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:191:in `merge_data_from_pipe'
from /srv/jobzy/shared/bundle/ruby/1.9.1/gems/newrelic_rpm-3.6.7.152/lib/new_relic/agent/pipe_channel_manager.rb:80:in `eof?'
from /srv/jobzy/shared/bundle/ruby/1.9.1/ge
# User class with #is_member_of? method
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, :through => :memberships
def is_member_of?(group)
memberships.exists?(:membership_group_id => group.id)
end
end
@watsonbox
watsonbox / php_dalli_store.rb
Created July 24, 2012 14:51
PHP Memcache Session Store Using Dalli
require 'action_dispatch/middleware/session/dalli_store'
# - PHP side is 5.3.6 configured with session.save_handler = memcache
# - Requires php-serialize gem for serialization: https://github.com/jqr/php-serialize
module ActionDispatch
module Session
class PhpDalliStore < ActionDispatch::Session::DalliStore
require 'php_serialize'
class PhpSerializingPoolDecorator < SimpleDelegator
@watsonbox
watsonbox / gist:2376668
Created April 13, 2012 12:43
Output of jstack [pid] for locked Torquebox process
2012-04-13 14:41:16
Full thread dump Java HotSpot(TM) Client VM (20.4-b02-402 mixed mode):
"Attach Listener" daemon prio=9 tid=0000000002462800 nid=0xb70f5000 waiting on condition [0000000000000000]
java.lang.Thread.State: RUNNABLE
"http-localhost-127.0.0.1-8080-7" daemon prio=5 tid=0000000001bc5000 nid=0xb6ef3000 in Object.wait() [00000000b6ee3000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <000000000b8efb30> (a org.jruby.libraries.ThreadLibrary$Mutex)
@watsonbox
watsonbox / gist:2376477
Created April 13, 2012 12:07
Ran ab -n 4 -c 4 http://app-dev.fanrank.me:8080/v2, server locks up, then ctrl-c server
13:58:23,720 INFO [org.torquebox.core.runtime] (Thread-109) Created ruby runtime (ruby_version: RUBY1_9, compile_mode: JIT, app: fanzy_spike, context: web) in 13.48s
^Ccaught SIGINT, shutting down
13:58:53,511 INFO [org.jboss.as.logging] JBAS011503: Restored bootstrap log handlers
13:58:53,520 INFO [org.jboss.as.messaging] JBAS011605: Unbound messaging object to jndi name java:/queues/torquebox/fanzy_spike/tasks/torquebox_backgroundable
13:58:53,525 ERROR [stderr] cache: [GET /v2/] miss
13:58:53,544 INFO [jacorb.poa] POA Naming destroyed
13:58:53,545 INFO [jacorb.poa] POA IRPOA destroyed
13:58:53,546 INFO [jacorb.poa] POA RootPOA destroyed
13:58:53,558 INFO [jacorb.orb] prepare ORB for shutdown...
13:58:53,558 INFO [jacorb.orb] ORB going down...
@watsonbox
watsonbox / php_session_store.rb
Created April 12, 2012 15:02
PhpSessionStore middleware to allow sharing session with legacy PHP app
# Overrides functionality in Rack::Session::Memcache from Rack 1.4.1 to support sharing PHP sessions
# - PHP side is 5.3.6 configured with session.save_handler = memcache
# - Requires php-serialize gem for serialization: https://github.com/jqr/php-serialize
module ActionDispatch
module Session
class PhpSessionStore < ActionDispatch::Session::MemCacheStore
require 'php_serialize'
def initialize(app, options = {})
@watsonbox
watsonbox / gist:1780596
Created February 9, 2012 15:11
Example of how email templates are parameterised
<!-- // Begin Module: Standard Content \\ -->
<table border="0" cellpadding="20" cellspacing="0" width="100%">
<tr>
<td valign="top">
<div mc:edit="std_content00">
<h1 class="h1">{{ subject }}</h1>
<p>Hi {{ email.user['user_fb_name'] }},</p>
{% if email.reward['reward_image'] %}
<p>Image: <img src="{{ email.reward['reward_image'] | fanzy_image_url }}"></p>
{% endif %}