Skip to content

Instantly share code, notes, and snippets.

class User
has_many :methods
has_many :options, :through => :methods
def points
connection.execute("SELECT SUM(points) as points FROM options o INNER JOIN methods m ON m.option_id = o.id WHERE m.user_id = '#{user_id}'").first['points']
end
end
<div typeof="product:Product"
xmlns:product="http://search.yahoo.com/searchmonkey/product/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<span rel="rdfs:seeAlso media:image">
<img src="http://www.sytore.com/product.jpg"/>
</span>
</div>
<div>
<span property="product:listPrice">49.99</span>
<span property="product:salePrice">39.99</span>
#!/bin/sh
echo 'This script adds a slave to bind9'
echo ''
echo -n 'What is the TLD?: '
read tld
echo -n 'What is the IP of the master server?: '
read masterip
echo "zone \"$tld\" {
type slave;
file \"zones/slave/slave.$tld\";
source :rubygems
gem 'rails', '3.0.1'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'authlogic', :git => 'git://github.com/odorcicd/authlogic.git', :branch => 'rails3'
gem 'acts_as_commentable'
gem 'activemerchant'
@jhubert
jhubert / application_controller.rb
Created January 11, 2011 08:02
This code would be placed somewhere in the file
before_filter :strip_www
def strip_www
if request.env["HTTP_HOST"] == "www.myapp.com"
redirect_to "http://myapp.com/"
end
end
@jhubert
jhubert / refraction_rules.rb
Created January 11, 2011 08:14
The configuration file for the Refraction Gem to add www. to a domain
Refraction.configure do |req|
req.permanent! :host => "www.mydomain.com" if req.host !~ /^www./
end
function updateCount() {
num--;
$('#status-count').html(num);
if (units == (1000 - num)) {
clearTimeout(countdown);
}
}
$(document).ready(function() {
$.getJSON('http://www.tweetfolk.com/markers/stats.js?callback=?', function(d) {
@jhubert
jhubert / Drinking Tonight
Created March 10, 2011 20:58
A limerick about drinking
We went out on the town last night
And drank to my friend's delight
i remember a shot
the rest i forgot
Lets do it again tonight!
(function () {
function deleteAll() {
var list = $('ul#list'),
list_id = parseInt($(list[0]).attr('rel'), 10),
list_name = $('#list' + list_id + ' b').html();
if (list_id > 0) {
if (confirm('Are you sure you want to delete all the items in ' + list_name)) {
list.find('li').each(function () {
<script type="text/javascript">
/*
Copyright (c) 2012 Jeremy Hubert (http://github.com/jhubert)
Released under the MIT License. See LICENSE for details.
*/
(function(a){a.fn.GoogleizeForm=function(c){var f,e,d,b;d=a.extend({},a.fn.GoogleizeForm.defaults,c);b=function(g){var h;if(g===""){return false}h=d.emailRegex;return h.test(g)};f=function(h,i,g){return d.success()};e=function(i){var g,h;i.preventDefault();h=a(this);g=h.find(d.emailFieldSelector);if(!b(g.val())){d.invalidEmail(g);return false}c={};c.type="POST";c.dataType="jsonp";c.url=h.attr("action");c.data=h.serialize();c.error=f;a.ajax(c)};return this.each(function(){return a(this).on("submit",e)})};a.fn.GoogleizeForm.defaults={emailRegex:/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/,emailFieldSelector:"#entry_0",success:function(){},invalidEmail:function(b){}}})(jQuery);
$(document).ready(function () {
$('form').GoogleizeForm({
success: function () {