Skip to content

Instantly share code, notes, and snippets.

def self.auto_link_content(content)
# Splits all HTML tags, except <a></a> tags. Keeps <a></a> tags as whole
# so that we don't accidentally link already linked Keywords
word_groups = content.split(/(<a[^>]*>.+?<\/a>|<\/?[^>]*>|[.]|,|['"]+)/i)
word_groups.collect! do |words|
(!words.match(/<\/?[^>]*>|[.]+|,+/) && words.match(/([a-zA-Z]+)/)) ? link_it(words) : words
end
word_groups.join
end
10.3 - 10
# 0.300000000000001
a = 10.3 - 10
# 0.300000000000001
b = 0.300000000000000
# 0.300000000000000
a == b
# false
(a + 10) == (b + 10)
# true
module FooModule
def say_hello
"Hello!"
end
end
class FooClass
include FooModule
end
# Create a file my_modeule.rb
# Include it in your application load path (Standard: app/lib )
# FILE CONTENTS BEGIN HERE
module MyModule
def self.included(base)
base.extend ClassMethods
class << base
attr_accessor :class_variable
end
class Array
def to_sentence(options = {})
# en-US: "One, Two, and Three" en-UK: "One, Two and Three"
options[:last_word_connector] ||= " and "
super
end
end
@spp
spp / bitly.rb
Created November 11, 2009 11:55
# To change this template, choose Tools | Templates
# and open the template in the editor.
class Bitly < ActiveResource::Base
self.site = 'http://api.bit.ly'
self.user = 'USERNAME'
self.password = 'PASSWORD'
cattr_accessor :login, :return_format, :api_key, :bitly_version
>> Bitly.shorten "http://www.facebook.com/home.php"
=> "http://bit.ly/3B2w14"
>> Bitly.shorten "http://bit.ly/"
=> "http://bit.ly/"
>> wall "Changing the mysql root password, please bear. -Swanand"
Broadcast message from root (pts/3) (Sat Nov 21 12:53:50 2009):
Changing the mysql root password, please bear. Thanks, Swanand
>> wall "Done. Thanks for the patience. -Swanand"
Broadcast message from root (pts/3) (Sat Nov 21 12:54:44 2009):
Done. Thanks for the patience. -Swanand
<?php
/*
Credit Card Validator
Date - Sep 04, 2009
Author - Brent Shaffer
ABOUT
@spp
spp / symfony_test.php
Created January 29, 2010 13:47
How to test your code snippets in Symfony
<?php
// These following lines load the project context
require_once(dirname(__FILE__).'/config/ProjectConfiguration.class.php');
// I use 'prod' all the time, and 'dev' only when something goes wrong
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', false);
// Generally keep 'dev', I use 'prod' all the time, 'dev' only when something goes wrong
// If you want to test just the models and business logic:
// sfContext::createInstance($configuration);
// If you want to test URL helpers and other helpers that require controller context
sfContext::createInstance($configuration)->dispatch();