Skip to content

Instantly share code, notes, and snippets.

#in global_helpers.rb:
def list(collection, &block)
throw_content(:list_items) { collection.each { |item| partial("shared/list_item", block.call(item)) } }
partial("shared/list")
end
#in shared/_list.html.haml
%ul.list=catch_content(:list_items)
passnger.load:
#include Phusion Passenger mod_rack module
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6/ext/apache2/mod_passenger.so
passenger.conf:
<IfModule mod_passenger.so>
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.6
PassengerRuby /usr/bin/ruby1.8
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}/$1 [R=301, L]
factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
perm :: (Integral a) => a -> a -> Double
perm n r = factorial n / factorial r
comb :: (Integral a) => a -> a -> Double
comb n r = factorial n / (factorial r * factorial(n - r))
module Enumerable
def group(&block)
groups = {}
self.each do |elem|
the_key = block ? block.call(elem) : elem
if groups[the_key]
groups[the_key].push(elem)
else
groups[the_key] = [elem]
end
def array_to_list(data, opts={})
if data.is_a?(Array)
content_tag(:ul, data.map{ |e| content_tag(:li, array_to_list(e)) }.join , opts)
else
data
end
end
<p class="check t_and_cs">
<%= form.check_box :terms_and_conditions %> <strong>Please tick here to confirm that you agree with these Terms and
Conditions.</strong>
<%# This is a rather nasty hack - we don't need the
hidden form as the ts and cs have to be accepted, and
having two form elements with the same name buggers the
jquery validation code. However, Rails yet-again fucks
anyone who tries to do anything that DHH hasn't, as
'opinionated software' is basically a euphemism for
'lazy programmers', so we can't do this server side. %>
messages: {
"profile[terms_and_conditions]": function() {
alert("Callback");
//We want to make sure there's a line break after the message for this one.
if($("p.t_and_cs br").length == 0) {
$("p.t_and_cs strong").before("<br />");
}
return("Please agree to the terms and conditions");
}, //etc...
SLOT_ID_REGEXP = /^\|.+\|.+\|.+\|.+\|.+\|(.+)\|.+\|/
def winner_id_regexp(slot_id)
/INSERT\ INTO\ \`winners\`\ \(\`updated_at\`\,\ \`competitor_id\`\,\ \`activation_code\`\,\ \`slot_id\`\,\ \`created_at\`\)\ VALUES\(\'.+\'\,(.+)\,\ \'.+\'\,\ #{slot_id}\,\ \'.+\'\)/
end
File.open("/Users/tim/winners-pick.log") do |log|
@log = log.read.split("\n")
end
RAILS_ENV='production'
require '/srv/rails/oneandother/current/config/environment.rb'
@pairs = [[160,34841],[542,37225],[411,32931],[290,35770],[396,28013],[344,35363],[390,35806],[569,29046],[132,29077],[76,34435],[170,31940],[430,33192],[223,30408],[385,26738],[372,28237],[505,28830],[205,35745],[31,26037],[17,33674],[474,35652],[46,25034],[316,31369],[426,29798],[350,30811],[581,34305],[612,34341],[359,36284],[230,24812],[456,30900],[600,32600],[410,29414],[424,30743],[552,34245],[334,35572],[228,24449],[333,32759],[391,31950],[336,27947],[171,24509],[87,30719],[186,27931],[138,32987],[139,24480],[404,32402],[568,32217],[468,26783],[297,34307],[571,35473],[164,37063],[185,25608],[249,33795],[392,32373],[193,32247],[398,28113],[155,25517],[557,27867],[245,29562],[418,26860],[70,27662],[88,34106],[531,34023],[394,34232],[236,33332],[49,29108],[416,29254],[379,28057],[495,34064],[159,28875],[97,36038],[312,29969],[281,31443],[48,33488],[473,35766],[226,33836],[44,33665],[402,30904],[45,35183],[326,31051],[29