Skip to content

Instantly share code, notes, and snippets.

View rymai's full-sized avatar
🙌
Working from home

Rémy Coutable rymai

🙌
Working from home
View GitHub Profile
@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)

@jeffkreeftmeijer
jeffkreeftmeijer / application.rb
Created February 14, 2011 13:08
Lighthouse Keeper: turns Lighthouse API XML into RSS - http://keeper.jeffkreeftmeijer.com
class Application < Sinatra::Base
get '/:domain/:project' do
tickets = HTTParty.get(
"https://#{params[:domain]}.lighthouseapp.com/projects/#{params[:project]}/tickets.xml?q=#{params[:q]}"
)['tickets']
builder do |xml|
xml.instruct! :xml, :version => '1.0'
xml.rss :version => "2.0" do
xml.channel do
@stefanfoulis
stefanfoulis / osx_developer_installation.rst
Last active November 12, 2024 22:34
Instructions on how to setup an OSX developer machine for (python/django) development

OSX Developer System installation

This guide assumes a fresh install of Mac OSX 10.7 Lion.

Brew User

@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
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)
:+1:
:-1:
:airplane:
:art:
:bear:
:beer:
:bike:
:bomb:
:book:
:bulb:
@igrigorik
igrigorik / TweetEvent.java
Created May 27, 2011 06:19
wrapping esper with JRuby embrace
// A simple Tweet POJO:
// $> javac TweetEvent.java
public class TweetEvent {
private String user;
private String text;
private String timezone;
private int retweets;
public TweetEvent(String user, String text, String timezone, int retweets) {
@pcreux
pcreux / awesomer.rb
Created June 2, 2011 00:12
Convert markdown inline links to link definitions
# For https://github.com/guard/guard/blob/master/CHANGELOG.md
str = File.read('CHANGELOG.md')
people = []
str.each_line do |l|
found = l.match(/\[@(\w+)\]\(([\w:\/.]+)\)/)
if found
user = found[1]

Sprockets Railtie Setup

This file at actionpack/lib/sprockets/railtie.rb defines the Sprockets::Railtie, defining another Railtie for Rails. This Railtie is responsible for detecting if the application at-hand is using CoffeeScript, and if so will set config.app_generators.javascript_engine on the application to be :coffee.

Next, this defines an initializer called sprockets.set_configs which sets up ActionController::Base to either use or not use sprockets depending on the configuration option config.assets.enabled.

Finally, this file defines an after_initialize hook for the application which is the real meat of this Railtie. If assets are disabled (with the config.assets.enabled config option set to false) then this after_initialize hook will do nothing.

If assets are enabled then, this initializer first makes a call to an asset_environment protected method near the bottom of this file which requires the sprockets gem, creates a new Sprockets::Environment object, and then co

@rsanheim
rsanheim / gist:1054078
Created June 29, 2011 15:23
Devise + Spork + Rails 3.1 RC4 hacks to keep User model from loading prefork
Spork.prefork do
require "rails/application"
# Prevent Devise from loading the User model super early with it's route hacks for Rails 3.1 rc4
# see also: https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
# rest of your prefork here...
end