Skip to content

Instantly share code, notes, and snippets.

View joshnesbitt's full-sized avatar

Josh Nesbitt joshnesbitt

View GitHub Profile
@joshnesbitt
joshnesbitt / migrate.sh
Created November 6, 2012 16:23
A handy script to stream a MySQL dump into another database.
#!/bin/bash
SOURCE_USER=user
SOURCE_HOST=localhost
SOURCE_PASSWORD='password'
SOURCE_DATABASE=database
TARGET_USER=user
TARGET_HOST=localhost
TARGET_PASSWORD='password'

It's a little known fact that you can easily substitute the default Rails HTML error pages with something more pleasant. You may have noticed the 404.html, 422.html and 500.html files that are generated with every new Rails project and wondered if there's a clean way to style them like the rest of your application. There is, and it's surprisingly simple.

Basic Implementation

The default status code templates are served by a Rack exception application. You can override this to be any Rack compatible app, including your applications router:

# config/application.rb
config.exceptions_app = self.routes
@joshnesbitt
joshnesbitt / readme.md
Last active May 16, 2016 10:28
A simple script to get you on the Mondo beta.

Mondo Referral Bump

Thanks to @cbarratt for writing this. Tested on Ruby 2.2.2.

Installation

Install the dependencies:

gem install capybara ffaker poltergeist selenium-webdriver chromedriver-helper
@joshnesbitt
joshnesbitt / watch.rb
Created November 30, 2012 15:05 — forked from JamieMason/watch.rb
Watch a folder for changes to files, then reload Chrome
#!/usr/bin/env ruby
require 'tempfile'
require 'fileutils'
# Signals
trap("SIGINT") { exit }
# Setup
TARGET_FOLDER = ARGV[0]
TARGET_URL = ARGV[1]
# Libs
brew uninstall libxml2 libxslt
brew install libxml2 libxslt
brew link libxml2 libxslt
# Iconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz

If you've used Rails for a while you'll be well familiar with flash messages. Flash objects provide a way to temporarily store information to recall later (usually on the next page render). This can be really useful for performing an action in a controller and then setting a feedback message to show the user during the next action.

We've done a lot of work with EmberJS lately, and we needed this functionality to feedback model saves to the user. There are already a wide variety of solutions out there, including the awesome Growl-esque notifications by Aaron Haurwitz, but for one of our smaller projects we wanted something simpler.

We're already using Foundation for it's excellent grid system, so we wanted to re-purpose the alert component into Ember JS flash object.

You can view the complete demo here, what follows is a break down of each area. Please note that this demo

@joshnesbitt
joshnesbitt / recipe.md
Last active December 25, 2015 14:19
The only pulled pork recipe you will ever need.

Slow Cooker Pulled Pork

Ingredients

For The Pork

  • Large, boned pork shoulder
  • Brown sugar
  • Salt flakes
  • Pepper
RoutingTest::Application.routes.draw do
get "404", :to => "errors#show", :code => 404, :as => :not_found
get "422", :to => "errors#show", :code => 422, :as => :unprocessible_entity
get "500", :to => "errors#show", :code => 500, :as => :server_error
end
@joshnesbitt
joshnesbitt / gem-open.sh
Created April 24, 2013 15:55
Open any gem within the current bundle in Sublime Text 2.
function gemo(){
subl `bundle show $1`
}
@joshnesbitt
joshnesbitt / rbenv-ruby-2.0.0-p0.sh
Created April 17, 2013 16:01
How to install Ruby 2.0.0-p0 on OSX Mountain Lion.
export CFLAGS=-Wno-error=shorten-64-to-32
export CONFIGURE_OPTS=--with-readline-dir=`brew --prefix readline`
export RUBY_CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`
rbenv install 2.0.0-p0