Skip to content

Instantly share code, notes, and snippets.

View lachie's full-sized avatar

Lachie Cox lachie

View GitHub Profile
#Ruby assignment option to assign unless nil
replacement_content = page_contents.content_label_find(item)
element.inner_html = replacement_content if replacement_content
# or
if pc = page_contents.content_label_find(item)
element.inner_html = pc
end
helpers do
def cycle
%w{even odd}[@_cycle = ((@_cycle || -1) + 1) % 2]
end
CYCLE = %w{even odd}
def cycle_fully_sick
CYCLE[@_cycle = ((@_cycle || -1) + 1) % 2]
end
end
var table = $('<table>').attr('id', 'host-' + host.host)
$('<thead>')
.append('<tr><th class="name">File name</th><th class="size">Size</th></tr>')
.appendTo(table);
table.append('<tfoot>')
.append('<tbody>')
.appendTo('#wrap')
@lachie
lachie / gist:34640
Created December 11, 2008 07:20 — forked from benaskins/gist:34631
class Foo
attr_accessor :some_attr
def initialize(val)
self.some_attr = val
end
def ==(other)
self.some_attr == other.some_attr
end
end
@lachie
lachie / gist:34629
Created December 11, 2008 07:09 — forked from benaskins/gist:34628
static VALUE
rb_ary_uniq_bang(ary)
VALUE ary;
{
VALUE hash, v, vv;
long i, j;
hash = ary_make_hash(ary, 0);
if (RARRAY(ary)->len == RHASH(hash)->tbl->num_entries) {
class Date
def to_words
today = Date.today
case self
when today
"Today"
when today - 1
"Yesterday"
when today + 1
require File.dirname(__FILE__) + '/../spec_helper'
require File.dirname(__FILE__) + '/../../app/models/notifications'
class Notifications
def self.spec_new(method_name,*parameters)
n = self.allocate
n.__send__ :initialize_defaults, method_name
yield(n) if block_given?
n.__send__(method_name, *parameters)
return n