Skip to content

Instantly share code, notes, and snippets.

View ncherro's full-sized avatar
🎯
Focusing

Nick Herro ncherro

🎯
Focusing
View GitHub Profile
@ncherro
ncherro / nested_form.rb
Created March 4, 2012 18:32
monkeypatch to Twitter Bootstrapify the Nested Form add / remove buttons
# put this in in config/initializers
require 'nested_form/builder_mixin'
module NestedForm
module BuilderMixin
alias_method :link_to_add_original, :link_to_add
alias_method :link_to_remove_original, :link_to_remove
def link_to_add(*args, &block)
options = args.extract_options!.symbolize_keys
options[:class] = [options[:class], 'btn'].compact.join(' ')
link_to_add_original *args, options, &block
@ncherro
ncherro / example_model.rb
Created April 23, 2012 00:44
Rails extension to add Permalink functionality to any model. To use, place in /app/models/extensions/permalink.rb
class ExampleModel < ActiveRecord::Base
# include the module
include Extensions::Permalink
# make sure there's a method named "unicode" that
# returns the string you'd like to sluggify
def unicode
self.name
end
@ncherro
ncherro / nested_form_bootstrap.rb
Created April 30, 2012 03:21
Nested Form monkeypatch - add / remove buttons with twitter bootstrap classes
require 'nested_form/builder_mixin'
module NestedForm
module BuilderMixin
alias_method :link_to_add_original, :link_to_add
alias_method :link_to_remove_original, :link_to_remove
def link_to_add(*args, &block)
options = args.extract_options!.symbolize_keys
options[:class] = [options[:class], 'btn btn-inverse'].compact.join(' ') unless options[:plain]
link_to_add_original *args, options, &block
end
@ncherro
ncherro / deploy.rb
Created May 2, 2012 18:57
Capistrano deploy overrides for Passenger Standalone - config/deploy.rb
set :standalone_port, 3000
namespace :deploy do
task :start do
run "cd #{latest_release} && RAILS_ENV=#{rails_env} passenger start -p #{standalone_port} -d"
end
task :stop do
run "cd #{latest_release} && RAILS_ENV=#{rails_env} passenger stop"
end
task :restart, :roles => :app, :except => { :no_release => true } do
@ncherro
ncherro / settings.php
Created October 2, 2012 15:36
Drupal branch-specific database settings
<?php
// full path to project root (you'll need to edit this)
$root = dirname(dirname(dirname(__DIR__)));
// project name here (full db name will be my_project_[current git branch])
$project_name = 'my_project';
// base connection info
$base_conn = array(
'driver' => 'mysql',
@ncherro
ncherro / prettyloader.js
Created October 3, 2012 22:55
Simple jquery plugin fades image in on load
(function($) {
var PrettyLoader = function(el, opts) {
var settings = $.extend({}, $.fn.prettyloader.defaults, opts)
$el = $(el);
function init() {
$el.hide().one('load', loaded).each(function() {
// manually call load() if the image has been cached
if (this.complete) $el.load();
});
}
@ncherro
ncherro / .bashrc
Created October 4, 2012 15:40
Bash function to cd to the project root
# cd to the git root
cd.() {
cd $(git rev-parse --show-toplevel)
}
@ncherro
ncherro / jquery.select_or_other.js
Created November 20, 2012 16:58
Rails SimpleForm Select or Other input, with jQuery plugin
/**
* SelectOrOther plugin
*
* works with our custom simple_form select_or_other input
*/
(function($) {
var SelectOrOther = function(el, opts) {
var settings = $.extend({}, $.fn.selectorother.defaults, opts), $el,
$select, $other;
@ncherro
ncherro / killport.sh
Created January 15, 2013 15:53
Kill a process on a port. Defaults to 3000 (Rails)
killport() {
if [ -n "${1}" ]; then
port=$1
else
# default (Rails-centric)
port="3000"
fi
pid=`lsof -wni tcp:$port | awk 'NR==2 { print $2 }'`
if [ -n "${pid}" ]; then
kill -9 $pid
@ncherro
ncherro / mopidy settings.py
Created February 5, 2013 18:15
settings.py file for mopidy with a HTTP front end
MPD_SERVER_HOSTNAME = u'::'
SPOTIFY_USERNAME = u'YOUR-USERNAME'
SPOTIFY_PASSWORD = u'YOUR-PASSWORD'
HTTP_SERVER_HOSTNAME = u'::'
HTTP_SERVER_PORT = 6680
HTTP_SERVER_STATIC_DIR = u'/var/www/mopidy/current/public'
LOCAL_MUSIC_PATH = u'/home/bbox/music'
LOCAL_TAG_CACHE_FILE = u'/home/bbox/tag_cache'
FRONTENDS = (
u'mopidy.frontends.mpd.MpdFrontend',