Skip to content

Instantly share code, notes, and snippets.

View JackDanger's full-sized avatar

Jack Danger JackDanger

View GitHub Profile
@JackDanger
JackDanger / descriptive_sql_load_log.rb
Created July 19, 2011 20:24
Let Rails display file names and line numbers for log activity.
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
protected
# Turn:
# User Load (6.3ms) SELECT * FROM "users"
# Into:
# User Load /app/views/_partial.erb:27 (6.3ms) in `_app_views_partial_erb` SELECT * FROM "users"
@JackDanger
JackDanger / gist:828885
Created February 16, 2011 04:46
gotcha.js
/* Arrays implicitly turn numbers to strings */
var total = 4
total += 5
// total: 9
total += [5]
// total: "95"
/* Arrays are numerically comparable */
1 > 0
// true
@JackDanger
JackDanger / t.rb
Created January 21, 2011 00:17 — forked from joevandyk/t.rb
class C
attr_accessor :b
def foo
b ? b.foo : raise(NoMethodError.new)
end
alias gob foo
@JackDanger
JackDanger / s3_bucket_clone.rb
Created October 26, 2010 04:10
Copy an entire S3 bucket to another
#!/usr/bin/env ruby
## Taken from: http://snippets.dzone.com/posts/show/4935
#
# Usage:
# a = AmazonS3Asset.new
# a.copy_over_bucket("myapp_production", "myapp_production")
require 'aws/s3'
require 'mechanize'
require 'logger'
(function(){
var cloops = $(".rotating_cloop")
var shown = 0
var length = cloops.length
setInterval(function(){
shown++
if(shown >= length) shown = 0
$(cloops[shown-0]).hide();
$(cloops[shown]).show()
}, 2000)
@JackDanger
JackDanger / git-remove-history.sh
Created August 19, 2010 22:06
remove large binary files from git history
#!/bin/bash
set -o errexit
# Author: David Underhill
# Script to permanently delete files/folders from your git repository. To use
# it, cd to your repository's root and then run the script with a list of paths
# you want to delete, e.g., git-delete-history path1 path2
#
# retrieved from: http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
#
@JackDanger
JackDanger / forgetful.js
Created June 22, 2010 00:28
forgetful.js
// Forgetful.js is what I use on SSDs to prevent disk wear.
// Because each SSD sector can only be written a set # of times
// it's important not to write huge log files for no reason.
// So my test logs (and some others) are all outputted to this
// node.js instance which keeps track of the throughput
// in simply-named channels.
//
// To use this in, e.g., Rails, put this in environments/test.rb:
//
// class NamedChannelSocket < TCPSocket
@JackDanger
JackDanger / solr_1.4_on_EC2.bash
Created April 9, 2010 22:42
solr 1.4 on EC2
# My record of provisioning a Solr server on EC2 (mostly mistakes):
# Take 2:
## AMI: ami-1515f67c (bare ubuntu)
sudo apt-get update
sudo apt-get install rubygems1.8
sudo apt-get install git-core
git clone git://github.com/JackDanger/jackbash.git ./.bash
source ~/.bash/rc
@JackDanger
JackDanger / prune_vendor.rake
Created March 24, 2010 20:24
crazy-compress your ./vendor dir
namespace :prune do
desc "Delete all unnecessary files from vendored Rails"
task :rails do
require 'fileutils'
list = Dir.glob("vendor/rails/*/test")
FileUtils.rm_rf list, :verbose => true unless list.empty?
end
@JackDanger
JackDanger / setup_ubuntu.sh
Created February 10, 2010 05:57
install Rails essentials on ubuntu
#/bin/bash
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install build-essential
sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.1 mysql-common mysql-server-5.1 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libhtml-template-perl mysql-server-core-5.1 libmysqlclient16 libreadline5 psmisc
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar xvzf rubygems-1.3.5.tgz