Skip to content

Instantly share code, notes, and snippets.

Object.prototype.extends = function(thing) {
var self = this;
for( var prop in thing ) {
if (thing.hasOwnProperty(prop)) {
self[prop] = thing[prop];
}
}
};
var Foo = {
@garrow
garrow / drop_tables.rake
Created February 2, 2012 03:26
Drop every table in the database without requiring the DROP DATABASE permission.
namespace :db do
namespace :drop do
desc "Drop every table in the database. (Does not require DROP DATABASE permission.)"
task :tables => :load_config do
config = ActiveRecord::Base.configurations[Rails.env || 'development']
begin
ActiveRecord::Base.establish_connection(config)
puts "Dropping #{ActiveRecord::Base.connection.tables.count} tables."
ActiveRecord::Base.connection.tables.each do |table|
@garrow
garrow / spec_helper.rb
Created February 27, 2012 09:01
make capybara specs open save the page on failing specs
RSpec.configure do |config|
# ...
# Open output of failing specs.
config.after(:each) do
if example.exception and example.metadata[:type] == :request
save_and_open_page
end
end
@garrow
garrow / watwat.rb
Created March 20, 2012 05:20
URI::parse
[65] pry(main)> ftp_abc = 'ftp://www.abc.net.au/hifive/'
=> "ftp://www.abc.net.au/hifive/"
[66] pry(main)> http_abc = 'http://www.abc.net.au/hifive/'
=> "http://www.abc.net.au/hifive/"
[67] pry(main)> f = URI::parse ftp_abc
=> #<URI::FTP:0x7ffe21b416b8 URL:ftp://www.abc.net.au/hifive/>
[68] pry(main)> h = URI::parse http_abc
=> #<URI::HTTP:0x7ffe21b37c58 URL:http://www.abc.net.au/hifive/>
[69] pry(main)> f.path
=> "hifive/"
@garrow
garrow / prompt_char.sh
Created April 17, 2012 07:09
Nice changing prompt character, based on the current repository type.
function prompt_char {
if [[ -d './.svn/' ]]; then echo '§' && return; fi
# it's faster to test for a `./.svn` directory than
# to exec `svn` & check return codes
git branch >/dev/null 2>&1 && echo '±' && return
hg root >/dev/null 2>&1 && echo '☿' && return
# redirect output of commands to /dev/null &
# echo custom char based on successful execution
echo '○'
ActiveAdmin::Register Package do
# A custom action we want treated like the :show or :edit actions.
member_action :overview, :method => :get do
@package = Package.find params[:id]
end
# Add the actions for the :overview action.
template_actions_for :overview, :show
end
@garrow
garrow / colourise_svn_status.rb
Created May 28, 2012 02:05
Quick and terrible svn output colouriser, might be ugly in non custom terminal colour schemes. Mine is based on monokai.
#!/usr/bin/ruby
colours = { :white => "\033[1;37m" \
, :yellow => "\033[1;33m" \
, :green => "\033[1;32m" \
, :blue => "\033[1;34m" \
, :cyan => "\033[1;36m" \
, :red => "\033[1;31m" \
, :magenta => "\033[1;35m" \
, :black => "\033[1;30m" \
@garrow
garrow / snapshot_restore.sql
Created October 8, 2012 06:15
Restore tables from a snapshot into public.
DO
$$
DECLARE
hidden_table record;
BEGIN
FOR hidden_table IN
SELECT schemaname, tablename FROM pg_tables
WHERE schemaname = (SELECT MAX(schemaname) FROM pg_tables WHERE schemaname LIKE 'snapshot_%')
LOOP
EXECUTE 'DROP TABLE IF EXISTS public.' || quote_ident(hidden_table.tablename) || ';';
@garrow
garrow / spoiler-css-only.css
Created February 23, 2013 13:10
spoiler-alert, css only version. Still doesn't work on firefox. https://github.com/joshbuddy/spoiler-alert
spoiler, .spoiler {
-webkit-transition: all 125ms linear;
-moz-transition: all 125ms linear;
-o-transition: all 125ms linear;
transition: all 125ms linear;
filter: blur(10px);
-webkit-filter:blur(10px);
-moz-filter: blur(10px);
-o-filter: blur(10px);
@garrow
garrow / output
Created February 26, 2013 03:14
A very simple git pre-commit hook to add/set a VERSION file with each commit. It will automatically insert the version and add that to the pending commit. Note that git hooks are not distributed with the repo, though adding to a fresh repo via the dev environment bootstrap script for our project works fine.
~/work/tmp/version_file <master +>± git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: foo
#
~/work/tmp/version_file <master +>± git diff --staged
diff --git a/foo b/foo
new file mode 100644