Skip to content

Instantly share code, notes, and snippets.

View darkhelmet's full-sized avatar
🏠
Working from home

Daniel Huckstep darkhelmet

🏠
Working from home
View GitHub Profile
@darkhelmet
darkhelmet / wale_postgres_recovery.md
Created February 15, 2014 04:09 — forked from elithrar/wale_postgres_recovery.md
WAL-E + Postgres 9.x (single server + DB) Setup and Recovery

A quick "how to" on what you need to do to both setup AND recover a single-server PostgreSQL database using WAL-E

  • WAL-E: https://github.com/wal-e/wal-e
  • Assuming Ubuntu 12.04 LTS ("Precise")
  • We'll be using S3. Make sure you have an IAM in a group with GetObject, ListBucket and PutObject on the bucket you want to use (and that it's not public).

Setup:

  1. These packages:
@darkhelmet
darkhelmet / docker-ruby-fpm.sh
Created March 4, 2014 04:40 — forked from dysinger/docker-ruby-fpm.sh
Using docker to build deb of ruby so you don't need to use rvm or something on the server
cat > Dockerfile <<\EOF
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get install -y ruby1.9.3 build-essential \
libc6-dev libffi-dev libgdbm-dev libncurses5-dev \
libreadline-dev libssl-dev libyaml-dev zlib1g-dev
RUN gem install fpm --bindir=/usr/bin --no-rdoc --no-ri
RUN apt-get install -y curl
RUN curl ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p484.tar.gz|tar oxzC /tmp
WORKDIR /tmp/ruby-1.9.3-p484
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
@darkhelmet
darkhelmet / iterator.rb
Created November 16, 2009 04:46 — forked from tmm1/iterator.rb
module EventMachine
# A simple iterator for concurrent asynchronous work.
#
# Unlike ruby's built-in iterators, the end of the current iteration cycle is signaled manually,
# instead of happening automatically after the yielded block finishes executing. For example:
#
# (0..10).each{ |num| }
#
# becomes:
#
module HTML
class StathamSanitizer < WhiteListSanitizer
protected
def tokenize(text, options)
super.map do |token|
if token.is_a?(HTML::Tag) && options[:parent].include?(token.name)
token.to_s.gsub(/</, "&lt;")
else
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
require 'snip_snap'
require 'hpricot'
module Rack
# = Rack::Snapshot
#
# Takes the image tags in your page and expands them using some of the popular
# image sharing services. Currently supports these services:
#
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
import re
# http://atomboy.isa-geek.com/plone/Members/acoil/programing/double-metaphone
from metaphone import dm as double_metaphone
# get the Redis connection
from jellybean.core import redis
import models
# Words which should not be indexed