Skip to content

Instantly share code, notes, and snippets.

View roidrage's full-sized avatar
🌱
Planting seeds

Mathias Meyer roidrage

🌱
Planting seeds
View GitHub Profile
@roidrage
roidrage / doesnt.rb
Created September 17, 2008 14:59
LOLstring
require 'rubygems'
require 'activesupport'
class StringProxy
def initialize(string, negate)
@string = string
@negate = negate
end
def method_missing(name, *args)
class Bar
def self.foo
puts "foo.bar"
end
end
Bar.foo # => outputs foo.bar
class << Bar
remove_method :foo
@roidrage
roidrage / gist:13203
Created September 26, 2008 21:00
Code of the day
def test_permalinks
# note that this test assumes you haven't changed the `extra_word` argument of Post.to_permalink
# from the default 'again'... if you have, change the equality assertions below appropriately
p = Post.new
p.title = 'test post'
p.body_raw = "this is my post content and it's a test"
assert p.save
assert_equal (Preference.get_setting('SIMPLE_TITLES') == 'yes' ? 'this_is_my_post_content' : 'test_post'), p.permalink
# cleaning HTML...
def test_pref_speed
total = 0
total2 = 0
10.times do
start = Time.now
Preference.get_setting('domain')
Preference.get_setting('site_name')
Preference.get_setting('slogan')
Preference.get_setting('site_description')
class AccountController < ApplicationController
def signup
@user = User.new(params[:user])
if @user.save
run_later do
AccountMailer.deliver_signup(@user)
end
end
end
end
@roidrage
roidrage / Ouch
Created October 5, 2008 13:44
Ouch
if @params[:highlighting]
hash[:hl] = true
hash["hl.fl"] = @params[:highlighting][:field_list].join(',') if @params[:highlighting][:field_list]
snippets = @params[:highlighting][:max_snippets]
if snippets
if snippets.kind_of? Hash
if snippets[:default]
hash["hl.snippets"] = snippets[:default]
end
module Kernel
def new(clazz)
clazz.new
end
end
obj = new Object
module Persistence
def self.included(base)
base.extend(ClassMethods)
end
def start_transaction
puts "Starting transaction"
end
def commit
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'
gem 'mattmatt-cap-ext-webistrano'
require 'cap-ext-webistrano'
class Project < ActiveResource::Base
self.site = "http://localhost:3000"
end
@projects = Project.find(:all)