Skip to content

Instantly share code, notes, and snippets.

View brandonhilkert's full-sized avatar

Brandon Hilkert brandonhilkert

View GitHub Profile
@brandonhilkert
brandonhilkert / Textareasubmit.js
Created June 22, 2011 02:16
Submit text in textarea with "Enter"
// Function that allows a textarea to use the enter
// key to submit the associated form
$.fn.submitTextArea = function() {
return this.each(function() {
$(this).keypress(function(e){
if (e.keyCode == 13 && !e.shiftKey) {
e.preventDefault();
$(this).closest('form').submit();
}
});
@brandonhilkert
brandonhilkert / unicorn
Created July 1, 2011 12:52
Unicorn startup script
#! /bin/sh
# File: /etc/init.d/unicorn
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
@brandonhilkert
brandonhilkert / meeteor
Created July 1, 2011 12:58
Nginx config for Unicorn
upstream unicorn {
server unix:/tmp/unicorn.sock fail_timeout=0;
}
server {
listen 80;
server_name staging.meeteor.com;
root /vol/data/rails/meeteor_production/current/public/;
location / {
@brandonhilkert
brandonhilkert / nginx
Created July 11, 2011 19:37
/etc/init.d/nginx for Passenger install
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
module Retryable
def self.included(base)
base.extend(self)
end
# Options:
# * :tries - Number of tries to perform in total, not number of retries. Defaults to 2.
# * :on - The Exception on which a retry will be performed. Defaults to Exception, which retries on any Exception.
# * :hoptoad - a hash of options that will be sent to Hoptoad along w/ the exception on errors
# * :final - Return when the code fails the max number of times
require "spec_helper"
describe UsersController do
describe "authentication" do
let(:user) { FactoryGirl.create(:user) }
it "should properly log a user out" do
session[:user_id] == user.id
AnalyticLog.should_receive(:logout) <----- (<AnalyticLog (class)>).logout(any args) expected: 1 time received: 0 times
get :logout
@brandonhilkert
brandonhilkert / gist:1866505
Created February 19, 2012 23:36
Random emails
def get_random_emails(emails = [], number_of_random_emails = 1)
random_emails = []
total_emails = emails.length
return false if number_of_random_emails > total_emails
while number_of_random_emails < random_emails.length
random_emails << emails.shuffle.pop
end
@brandonhilkert
brandonhilkert / memoizable.rb
Created February 22, 2012 15:08
Memoizable
@objects ||= long_running_query
@brandonhilkert
brandonhilkert / elasticsearch-ubuntu.sh
Created February 29, 2012 15:53
Installation script for Elasticsearch on Ubuntu
sudo apt-get update
sudo apt-get install openjdk-6-jre-headless -f
sudo wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.18.7.tar.gz -O elasticsearch.tar.gz
sudo tar -xf elasticsearch.tar.gz
sudo rm elasticsearch.tar.gz
sudo mv elasticsearch-0.18.7 elasticsearch
sudo mv elasticsearch /usr/local/share
sudo wget http://github.com/elasticsearch/elasticsearch-servicewrapper/tarball/master -O - | tar xz
sudo mv elasticsearch-elasticsearch-servicewrapper-3e0b23d/service /usr/local/share/elasticsearch/bin/
sudo rm -rv elasticsearch-elasticsearch-servicewrapper-3e0b23d/
@brandonhilkert
brandonhilkert / elasticsearch-1.9-ubuntu.sh
Created March 2, 2012 16:21
Installation script with .deb for ElasticSearch
sudo apt-get update
sudo apt-get -fy install openjdk-6-jre-headless
sudo wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.4.deb
sudo dpkg -i elasticsearch-0.19.4.deb