Skip to content

Instantly share code, notes, and snippets.

View perplexes's full-sized avatar

Colin Curtin perplexes

View GitHub Profile
@perplexes
perplexes / Rakefile.rb
Created June 4, 2012 16:00
How to have multithreaded workers in delayed_job 3.0.3 and Ruby 1.9.3 and Rails 3.2.2
task :workers => :environment do
module Delayed
class Worker
def name_with_thread_id(*a, &b)
name_without_thread_id(*a, &b) + " thread:#{Thread.current.object_id}"
end
alias_method_chain :name, :thread_id
end
end
Rails.logger.info "Running threaded worker env."
@perplexes
perplexes / instructions.txt
Created June 6, 2012 20:42
Move messages from iPhone to Android
# Migrate SMS from iPhone to Android in OSX #
Parts of this taken from http://pastebin.com/d4hNUmTK
1. Make an unencrypted backup of your iPhone to iTunes, not using iCloud.
2. cd /tmp
3. put iphone_sms_* here (found below)
4. Find your ~/Library/Application Support/MobileSync/Backup/*/3d0d7e5fb2ce288813306e4d4636395e047a3d28(.mddata)
5.
> sqlite3 ~/Library/Application Support/MobileSync/Backup/(id)/3d0d7e5fb2ce288813306e4d4636395e047a3d28(.mddata)
@perplexes
perplexes / readme.txt
Created June 13, 2012 10:18
Bandwidth monitor with tcpdump and ruby
EDIT: What you're looking for is iptraf (linux) or iftop (osx/brew) :P Yay @stormbrew
Here's a thing. The display is crap, but it mimics something that Windows 7 does pretty awesomely (??? did I just say that??).
> tcpdump -i en2 | ruby stream.rb
10.0.1.15.49257: 59.0617085357773 B/S
10.0.1.15.49302: 79.8090170222657 B/S
10.0.1.15.50671: 43.88880366791089 B/S
10.0.1.15.50684: 0.0 B/S
10.0.1.15.50685: 0.0 B/S
commit f65a43c9027d8fc82de44f82737a744dcac0556f
Author: Colin Curtin <[email protected]>
Date: Wed Nov 7 12:21:46 2012 -0800
Fix documentation for .initial backend parameter to match the source.
diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst
index 60daaa3..31c79a5 100644
--- a/doc/sphinx/reference/vcl.rst
+++ b/doc/sphinx/reference/vcl.rst
@perplexes
perplexes / gist:4343520
Created December 20, 2012 07:20
brew install go fails (HB 0.9.3, go 1.0.3)
Colins-MacBook-Pro:local colin$ ls -lah /usr/local/opt/go
ls: /usr/local/opt/go: No such file or directory
Colins-MacBook-Pro:local colin$ brew -v install go
Homebrew 0.9.3
==> Downloading http://go.googlecode.com/files/go1.0.3.src.tar.gz
Already downloaded: /Users/colin/Library/Caches/Homebrew/go-1.0.3.tar.gz
/usr/bin/tar xf /Users/colin/Library/Caches/Homebrew/go-1.0.3.tar.gz
==> ./make.bash --no-clean
./make.bash --no-clean
# Building C bootstrap tool.
@perplexes
perplexes / tumblr2wordpress.rb
Last active December 14, 2015 02:49
A small script for moving from tumblr to wordpress
require 'xmlrpc/client'
wordpress = XMLRPC::Client.new('academiaedu.wordpress.com', '/xmlrpc.php')
require 'tumblr_client'
# To get these:
# Go to http://tumblr-rb.herokuapp.com/ (a service for the below)
# --OR--
# `gem install tumblr-rb` somewhere with a public ip address
@perplexes
perplexes / gist:5118700
Created March 8, 2013 18:34
Post csv to gist with net/http
require 'csv'
csv_string = CSV.generate do |csv|
csv << titles
data.sample(1000).each do |row|
csv << row
end
end; csv_string.size
require 'net/http'
require 'uri'
@perplexes
perplexes / buildpacks.md
Last active November 25, 2021 02:29
Heroku custom compiled library .bundle/config

Buildpacks

Heroku uses buildpacks to compile your application into a slug that is used across dynos for scaling horizontally quickly. A slug is a tar.gz archive of your app’s repository with certain pre-deploy features baked into the filesystem. Since everything to run your application is included in the archive, scaling becomes a simple matter of transferring it to a dyno, unpacking, and running the appropriate process. This is how Heroku achieves scaling-by-moving-a-slider.

For example, the Ruby buildpack will:

  • install ruby locally
  • install the jvm/jruby (if you’re using it)
  • install/run bundler and install your gems to Rails.root/vendor
  • create your database.yml (which ends up reading from your app’s environment variables)
@perplexes
perplexes / node.rb
Created June 5, 2013 22:14
Hash/Array Tree searcher
# > n = Node.find_where(terms2){|v| !v["Section"].empty?}
# => #<Node key="Sections" value=Hash children=1>
# > puts n.path
# => [0]["Departments"]["Department"][3]["Courses"]["Course"][1]["Sections"]
class Node
attr_reader :parent, :key, :value, :children
def initialize(parent, key, value)
@parent = parent
@key = key
@value = value
@perplexes
perplexes / sidekiq_middleware.rb
Created February 27, 2014 20:52
Sidekiq Middleware inspector
# Script to dump your current Sidekiq server middleware like `rake middleware`
# Drop this in script/sidekiq_middleware.rb and run:
# RAILS_ENV=production bundle exec sidekiq -r ./script/sidekiq_middleware.rb
puts "Eager loding Rails..."
require 'rails'
require 'sidekiq/rails'
require File.expand_path('./config/environment.rb')
::Rails.application.eager_load!
puts Sidekiq.server_middleware.entries.map(&:klass).join("\n")