Skip to content

Instantly share code, notes, and snippets.

@developish
developish / secrets.sh
Created August 5, 2019 18:04
A script for managing an encrypted volume at ~/Secrets (Mac OS X)
#!/usr/bin/env sh
program=$(basename $0)
command=$1
help() {
echo "Usage: $program <subcommand>"
echo ""
echo "Subcommands:"
echo " create Create an encrypted volume"
Bundler 1.3.5
Ruby 1.9.3 (2013-02-22 patchlevel 392) [x86_64-linux]
Rubygems 1.8.23
GEM_HOME
Bundler settings
frozen
Set for your local app (/var/www/app/releases/20130420233758/.bundle/config): "1"
path
Set for your local app (/var/www/app/releases/20130420233758/.bundle/config): "vendor/bundle"
@developish
developish / taps-transfer.sh
Created January 12, 2013 00:02
Convert mysql database to postgres locally with taps
# Start taps server in one tab
taps server mysql://mysqluser@localhost/sourcedb tmpuser tmppass
# Create destination postgres database
createdb destinationdb
# Import into postgres database in another tab
taps pull postgres://postgresuser@localhost/destinationdb http://tmpuser:tmppass@localhost:500
@developish
developish / dig.sh
Last active December 10, 2015 23:19
What are the name servers for example.com set to?
dig +short ns example.com
@developish
developish / format-disk3.sh
Created January 9, 2013 22:47
How to destructively remove unnecessary "Boot OS X" record from a drive by completely reformatting
# where /dev/disk3 is the disk you want to reset
# GPT is the GUID partition table
# HFS+ is the Apple HFS format
diskutil partitionDisk /dev/disk3 GPT HFS+ newDiskName 100%
@developish
developish / duration_spec.rb
Created October 15, 2011 02:55
How to create an isolated ActiveRecord connection for testing without breaking the rest of the suite.
require "active_record"
require "lib/duration"
class Event < ActiveRecord::Base
include Duration
end
describe Duration do
before do
ActiveRecord::Base.establish_connection(
@developish
developish / post.rb
Created October 14, 2011 07:25
Test ActiveRecord #delete vs #destroy
class Post < ActiveRecord::Base
before_destroy :protect_from_destruction
def protect_from_destruction
if protected?
errors.add(:base, "Whoa this one is important")
false
end
end
@developish
developish / gist:1059914
Created July 2, 2011 10:09
I thought the problem was Rails safe buffers
# Assuming that :something is trusted
Mustache.render("<h1>template</h1> {{ something }}", {:something => "<h2>Testing</h2>" })
# => <h1>template</h1> &lt;h2&gt;Testing&lt;/h2&gt;
# Desired out is "<h1>template</h1> <h2>Testing</h2>"
# Solution, use the triple mustache - {{{ }}} - for content that shouldn't be escapes
@developish
developish / jquery.appendfromtemplate.js
Created April 13, 2011 03:18
For adding nested form objects with Rails
// Works in conjunction with the generate_template helper to insert new
// objects into a form that has a collection of items.
$.fn.appendFromTemplate = function(template) {
return this.each(function () {
var newId = new Date().getTime();
$(this).append(template.replace(/NEW_RECORD/g, newId));
});
};
@developish
developish / jquery.bindcheckbox.js
Created April 11, 2011 21:48
Simple way to bind the state of a checkbox to an associated function.
// Bind a checkbox to a with checked and unchecked callback functions
// and run the appropriate action on page load:
//
// Examples
//
// $("input[type=checkbox][name=thecheckbox]").bindCheckbox({
// checked: function() {
// alert("the checkbox is checked!")
// },
// unchecked: function() {