Skip to content

Instantly share code, notes, and snippets.

View lachie's full-sized avatar

Lachie Cox lachie

View GitHub Profile
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
class Date
def to_words
today = Date.today
case self
when today
"Today"
when today - 1
"Yesterday"
when today + 1
@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) {
@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
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')
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
#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
@lachie
lachie / string.rb
Created February 26, 2009 02:20 — forked from slowjud/string.rb
class String
class TextHelperSingleton
def self.instance; @instance ||= new end
include ActionView::Helpers::TextHelper
end
def method_missing(method, *args, &block)
if TextHelperSingleton.instance.respond_to?(method)
self.class.send(:define_method, method, &block) do
TextHelperSingleton.instance.send(method, self, *args, &block)
def f(ra,n)
ra.select {|x| x.include? n}.size
end
- if @items
- @items.each do |item|
- name = item.gsub(/views\/.+\/(.+).haml/, '\1')
- unless name == "index" || name[/^hide-/]
%p do some stuff