Skip to content

Instantly share code, notes, and snippets.

View thirdreplicator's full-sized avatar

David B thirdreplicator

View GitHub Profile
# A trivial-case processor. This is a custom paperclip processor that doesn't do anything but generate thumbnails like it normally would.
# RAILS_ROOT/lib/paperclip_processors/general_processor.rb
module Paperclip
class General < Processor
def make
Thumbnail.make( @file, @options, @attachment )
end
end # class
@thirdreplicator
thirdreplicator / how to configure Paperclip plugin to handle general file uploading
Created October 25, 2009 10:46
how to configure the Paperclip plugin to handle general file uploading and image thumbnail generation
class Clip < ActiveRecord::Base
belongs_to :clippable, :polymorphic => true
has_attached_file :document,
:styles => { :thumbnail => "50x50#",
:medium => "200x200",
:large => "450x450>",
:jumbo => "1024x1024>"
},
:processors => [:general],
@thirdreplicator
thirdreplicator / watch.rb
Created April 18, 2011 07:17
Handy directory watcher for running tests in the background.
require 'directory_watcher'
# gem 'directory_watcher.rb'
# gem 'rev'
#command = 'rspec --drb --color spec'
command = "cucumber --drb -f html -o tmp/cuke.html -f progress -o tmp/progress.txt features"
dw = DirectoryWatcher.new '.', :pre_load => true, :scanner => :rev
dw.glob = '**/*.{rb,feature,haml,erb}'
@thirdreplicator
thirdreplicator / crontab
Created May 10, 2011 17:20
How to idempotently start your server (after a server reboot for example)
# crontab -e
* * * * * /bin/bash -l -c 'cd /var/www/whatsyourfavoritewebsite.com/production ; script/rails server -p 3001 -e production -d' > /tmp/start_whatsyourfavoritewebsite 2>&1
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source .bashrc
rvm package install zlib
rvm package install openssl
rvm package install readline
rvm install 1.9.2 -C --with-zlib-dir=$rvm_path/usr --with-openssl-dir=$HOME/.rvm/usr --with-readline-dir=$rvm_path/usr
rvm install 1.9.2
rvm --default 1.9.2
@thirdreplicator
thirdreplicator / index.html
Created May 22, 2011 18:56
javascript html5 hexagons canvas
<!DOCTYPE html>
<html>
<body>
<canvas id="a" width="500" height="500">
</canvas>
<div id='debug' style="background-color: #eee"></div>
<script>
var can = document.getElementById("a");
var ctx = can.getContext("2d");
var x0=100,
@thirdreplicator
thirdreplicator / screen_cheat_sheet.txt
Created June 5, 2011 06:18
Notes on command-line utility "screen"
# Put this in ~/.screenrc:
# This will remap CTRL-A (the normal screen command-mode toggle key combo) to CTRL-Z,
# because I like to preserve CTRL-A to go to the beginning of the command line.
defscrollback 5000
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'
# .screenrc
# EOF
@thirdreplicator
thirdreplicator / walk.js
Created June 19, 2011 02:46
Walking a graph in Javascript.
<script>
var H = function(){
var g=function(){};
g.prototype.children = [];
g.prototype.values = {};
g.prototype.walk = function(f){
for(var i in H.all){
@thirdreplicator
thirdreplicator / tcpdump example
Created August 7, 2011 19:54
view raw traffic
sudo tcpdump -i en1 -s0 -A tcp port 80
@thirdreplicator
thirdreplicator / git branch --set-upstream
Created October 11, 2011 14:32
set upstream branch
# Set your current branch to be the one your push and pull from remotely, so that you can just say "git pull" and "git push" without having to say "git pull origin mybranch" or "git push origin mybranch"
git branch --set-upstream
git push --set-upstream