Skip to content

Instantly share code, notes, and snippets.

@jgwhite
jgwhite / .htaccess
Created May 28, 2012 09:36
Broadbean RewriteRule
RewriteRule ^broadbean-inbox$ /wp-content/plugins/broadbean/inbox.php [QSA,L]
/* This function extracts user input from the Loan Calculator input form and uses it to set the variables of loanAmount, repayPeriod and protection*/
function getInput()
{
document.getElementById('error').style.display = 'none';
var loanAmount = document.getElementById('loan_amount').value;
/*Check whether user input for loan amount is valid*/
if (isNaN(loanAmount) == true || loanAmount<1000 || loanAmount>500000)
{
files = Dir['*/*']
files.each do |old_path|
old_dir = old_path.split('/').first
next if old_dir.length < 12
new_path = old_path.sub(%r[(.{3})(.{9})/(.{12})], '\1/\2\3')
`mkdir -p #{$1}`
`mv #{old_path} #{new_path}`
if Dir[old_dir + '/*'].empty?
`rm -r #{old_dir}`
end
@jgwhite
jgwhite / app.js
Created August 19, 2012 20:28
Ember.js Routing With Authentication Example
var App = Em.Application.create();
App.ApplicationController = Em.Controller.extend();
App.ApplicationView = Em.View.extend({ templateName: 'application' });
App.HomeController = Em.Controller.extend();
App.HomeView = Em.View.extend({ templateName: 'home' });
App.AuthController = Em.Controller.extend({
@jgwhite
jgwhite / app.js
Created August 21, 2012 16:51
Ember Router Example
// The app's namespace.
var App = Em.Application.create();
// The app's top-level controller.
App.ApplicationController = Em.Controller.extend();
// The app's top-level view.
App.ApplicationView = Em.View.extend({ templateName: 'application' });
// Displays the home template.
@jgwhite
jgwhite / oregon.md
Created August 22, 2012 18:21
Deberes

¿Qué Vamos a Hacer en Oregon?

En Octubre vamos a ir a la costa oeste de los Estados Unidos a visitar nuestros amigos Heylen y Seth. ¡No puedo esperar!

Aquí estan algunas de las cosas que vamos a hacer…

Saldremos de Londres el Sábado 29 de Septiembre a las 10:35 de la mañana, y llegaremos a Redmond a las 5:35 de la tarde. Heylen y Seth viven en Bend, que esta bastante cerca de Redmond.

@jgwhite
jgwhite / slice.rb
Created October 17, 2012 14:31
Slices Documentation
class Slice
...
# Specifies that the slice can only be added/removed by super admins.
def self.restricted_slice
self.restricted = true
end
...
@jgwhite
jgwhite / Gemfile
Created November 9, 2012 16:05
Testing Static HTML with RSpec & Capybara
source :rubygems
gem 'capybara'
gem 'rack'
gem 'rspec'
{{#composer field="items"}}
<input type="text" name="title" value="{{title}}" placeholder="Title…">
<input type="text" name="definition" value="{{definition}}" placeholder="Definition…">
{{/composer}}
@jgwhite
jgwhite / delight.rb
Last active December 10, 2015 13:58
Why Ruby is Delightful
my_array = %w[a b c d e f] #=> ["a", "b", "c", "d", "e", "f"]
my_array[0..3].map &:upcase #=> ["A", "B", "C", "D"]
my_array[0...3].map &:upcase #=> ["A", "B", "C"]
my_array.first(3).map &:upcase #=> ["A", "B", "C"]
Time.new(2013, 1, 3).thursday? #=> true
(1..10).to_a.group_by &:odd? #=> {true=>[1, 3, 5, 7, 9], false=>[2, 4, 6, 8, 10]}