Skip to content

Instantly share code, notes, and snippets.

@brianmario
brianmario / config.ru.rb
Created April 21, 2011 06:11
minimal rails3 app
# minimal rails3 app
require 'action_controller'
Router = ActionDispatch::Routing::RouteSet.new
Router.draw do
root :to => 'site#index'
end
class SiteController < ActionController::Metal
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
class Numeric
def commify
to_s.reverse.gsub(/(\d\d\d)(?=\d)(?!\d*\.)/,'\1,').reverse
end
end
require 'rubygems'
require 'yajl'
tests = []
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@dkubb
dkubb / gist:556033
Created August 29, 2010 06:26
DO API ideas
connection = DataObjects::Connection.new(uri)
connection.close
# immediately executed statements
reader = connection.query('SELECT * FROM table WHERE id = ?', 1)
reader.set_types(Integer) # returns self for chaining
reader.each { |row| ... }
@tobitailor
tobitailor / def.js
Created July 13, 2010 23:32
Simple Ruby-style inheritance for JavaScript
/*
* def.js: Simple Ruby-style inheritance for JavaScript
*
* Copyright (c) 2010 Tobias Schneider
* This script is freely distributable under the terms of the MIT license.
*
*
* Example:
*
* def ("Person") ({
@thibaudgg
thibaudgg / truncate_middle.rb
Created May 19, 2010 10:09
truncate in the middle like Finder
# If text is longer than +options[:length]+ (defaults to 30), text will be middle-truncated
# and the last characters will be replaced with the +options[:omission]+ (defaults to "...").
def truncate_middle(text, *args)
options = args.extract_options!
options.reverse_merge!(:length => 30, :omission => "...")
if text
if text.mb_chars.length <= options[:length]
text
else
@endolith
endolith / Has weird right-to-left characters.txt
Last active April 30, 2024 12:48
Unicode kaomoji smileys emoticons emoji
ּ_בּ
בּ_בּ
טּ_טּ
כּ‗כּ
לּ_לּ
מּ_מּ
סּ_סּ
תּ_תּ
٩(×̯×)۶
٩(̾●̮̮̃̾•̃̾)۶