Skip to content

Instantly share code, notes, and snippets.

View jonahbron's full-sized avatar

Jonah Bron jonahbron

View GitHub Profile
@jonahbron
jonahbron / have_friendly_id.rb
Last active December 28, 2015 09:19
Friendly_Id Shoulda Matcher.
# Copyright 2013 Jonah Dahlquist
# Creative Commons Attribution 3.0
#
# Installation:
# Add to your spec_helper.rb file:
# Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
# Add this file to spec/support/matchers/
#
# Usage:
# it { should have_friendly_id :title }
@jonahbron
jonahbron / fix_vagrant_boxes.sh
Created October 18, 2013 19:11
Upgrade Vagrant Boxes to 1.1
#!/bin/bash
provider=virtualbox
# Loop over boxes
for box in ~/.vagrant.d/boxes/*; do
# Create provider directory to contain files
mkdir $box/$provider/
@jonahbron
jonahbron / parchive.sh
Created May 24, 2013 22:47
Compress and archive project directory, with tab completion.
# Compress and archive project directory. Only deletes project directory if compression is successful.
#
# author Jonah Dahlquist
# license CC0
export PROJECTS_PATH=~/Projects
parchive() {
local project=$1
local year=`date +%Y`
@jonahbron
jonahbron / genpass.sh
Created May 24, 2013 22:42
Quickly generate a safe password. Allows you to (optionally) pass a length.
# Easily generate a safe password. Defaults to 16 characters
#
# author Jonah Dahlquist
# license CC0
genpass() {
local l=$1
[ "$l" == "" ] && l=16
tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs
}
@jonahbron
jonahbron / p.sh
Last active December 17, 2015 17:38
Script to `cd` relative to a specific directory, with autocomplete. Useful for jumping to a project directory, for example. Automatically activates `virtualenvwrapper` if detected.
# Quickly `cd` relative to a specific directory
#
# author Jonah Dahlquist
# license CC0
# Path to projects directory
export JUMP_PATH=$HOME/Projects
# Change to directory relative to JUMP_PATH
p() {
@jonahbron
jonahbron / sshs.sh
Last active January 18, 2023 19:48
Wrapper for ssh that allows you to automatically source your own .bashrc when logging-in to another computer. Place in your .bashrc file to use.
# Wrapper for ssh to automatically source bash config file on remote machine.
# Sources ~/.bashrc_remote
#
# author Jonah Dahlquist
# license CC0
sshs() {
ssh ${*:1} "cat > /tmp/.bashrc_temp" < ~/.bashrc_remote
ssh -t ${*:1} "bash --rcfile /tmp/.bashrc_temp ; rm /tmp/.bashrc_temp"
}
@jonahbron
jonahbron / explode.sh
Created April 2, 2013 18:54
A very small BASH script to "explode" a directory. That is, move it's contents to it's parent directory, and remove the old (now empty) directory. Very handy after unzipping archives, and things of that nature. Be sure to add it to your PATH for easy use.
#!/bin/bash
# Example usage
#
# $ explode dir/
find "$*" -maxdepth 1 -mindepth 1 -exec mv -f {} "$*/../" \;
rmdir "$*"
@jonahbron
jonahbron / htmltidy-kodomo-macro.js
Created August 18, 2011 18:08
An HTMLTidy Macro for Komodo Edit
/*
HTML Tidy Macro for Komodo Edit
Pipes tidy output through sed to convert space indentation to tabs (tidy doesn't support tab indentation).
Requires that tidy and sed be installed.
BSD License
*/
komodo.assertMacroVersion(3);
if (komodo.view) { komodo.view.setFocus(); }