Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
joshmcarthur / setup_load_paths.rb
Created March 14, 2011 00:50
The required preinitializer for Rails when using RVM in a system-wide installation
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
@joshmcarthur
joshmcarthur / gist:1011639
Created June 7, 2011 03:39
A snippet of deploy script to automatically exclude sensitive files
default_run_options[:pty] = true
set :deploy_via, :copy
set :copy_cache, true
set :copy_exclude, [".git", "config/database.yml", "config/deploy.rb", ".rvmrc"]
@joshmcarthur
joshmcarthur / gist:1055377
Created June 30, 2011 00:43
Spree Hosted Gateway - Process Gateway Return Method
def process_gateway_return
#Find the gateway payment method from the parameters we have received back from the gateway provider
gateway = PaymentMethod.find_by_id_and_type(ExternalGateway.parse_custom_data(params)["payment_method_id"], "ExternalGateway")
# Populate the @order variable and the payment_made variable with the variables returned from the process_response method on the gateway method
# This method returns an array, which is how these two variables get populated.
@order, payment_made = gateway.process_response(params)
# Only do the next bit if the order has been found, and the gateway tells us that the payment has been made successfully
@joshmcarthur
joshmcarthur / ubuntu-rvm.sh
Created July 7, 2011 03:23 — forked from mystix/passenger-nginx-setup.sh
Ubuntu 11.04 (Natty) -- RVM + PostgreSQL + Passenger setup script
# run this script on a fresh Ubuntu server installation as root
# copy public ssh key to server's authorized_keys keychain for simple ssh logins
mkdir -p ~/.ssh
echo -e '<your ssh public key here>' > ~/.ssh/authorized_keys
# setup .gemrc
echo -e '---
:verbose: true
@joshmcarthur
joshmcarthur / spec_helper.rb
Created July 19, 2011 23:23
Omniauth: stub out providers
## Note: This goes inside your spec_helper.rb file - if using Spork, inside the Spork.prefork block
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:twitter, {
:uid => '123456789'
})
OmniAuth.config.add_mock(:facebook, {
:uid => '123456789'
})
@joshmcarthur
joshmcarthur / gist:1135392
Created August 9, 2011 22:39
A method to calculate BMI in C#
#region Calculations
/** <summary>A method to calculate Body-Mass Index (BMI) from a given weight and height</summary>
* <param name="weight">The person's weight in kilograms</param>
* <param name="height">The person's height in kilograms</param>
*/
public decimal CalculateBMI(decimal weight, decimal height) {
bmi = Math.pow(weight / height, 2)
return Math.round(bmi, 2)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Alexander_Sean_McArthur_300229975
@joshmcarthur
joshmcarthur / gist:1300106
Created October 20, 2011 00:38
Look Busy Bookmarklet
// Create a new div tag to contain our image
var busy = document.createElement('div');
var body = document.getElementsByTagName('body')[0];
var max_width_cache = body.style.maxWidth;
body.style.maxWidth = '100%';
busy.setAttribute('id', 'lookbusy');
// Add a background image, and position the div tag above all other content and make it fill the screen
busy.setAttribute('style', 'position: absolute; z-index: 1000; width: 100%; height: 100%; top: 0px; left: 0px; right: 0px; bottom: 0px; background: #FFF url(http://www.1-day.co.nz/images/2010_mission_critical_development_strategy.png) no-repeat 0 0;');
@joshmcarthur
joshmcarthur / gem_to_command.rb
Created November 3, 2011 03:43
A simple Ruby script to make a shell command that can be executed to install the gems *you* have installed in *their* environment
#!/usr/bin/env ruby
### gem_to_command.rb ###############################################################
# Produce a command to install the gems you currently have installed (using gem list)
# Makes a simple Shell script that can be run on Linux or Mac OS X
#
# Author: @sudojosh
######################################################################################
@joshmcarthur
joshmcarthur / .vimrc.local
Created December 12, 2011 22:14
Add JBuiler syntax highlighting to VIM
" add jbuilder syntax highlighting
au BufNewFile,BufRead *.json.jbuilder set ft=ruby