Skip to content

Instantly share code, notes, and snippets.

class Entry < ActiveRecord::Base
ITEMS_PER_PAGE = 50
belongs_to :subreddit
def self.page_for(subreddit, page)
if subreddit
entries = subreddit.entries
else
@xenda
xenda / gist:1015005
Created June 8, 2011 18:26 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
# gem install ruby-mp3info
require 'mp3info'
# Formato: # Pista [espacio] Nombre
# Ejemplo de filtros:
# Antes: 05 - Run Run Run - The Velvet Underground.mp3
# filters = ["- ", " - The Velvet Underground"]
# Después: 05 Run Run Run.mp3
def prepare(name)
# config/initializers/encodings.rb
Encoding.default_internal, Encoding.default_external = ['utf-8'] * 2
#!/usr/local/bin/ruby
require 'rubygems'
require 'iterm_window'
PROJECTS = [] # array of project names
project_name = ARGV.first
raise "unknow project" if !PROJECTS.include?(project_name)
project_path = "~/Programmation/Projets/#{project_name}"
@xenda
xenda / gist:255571
Created December 13, 2009 19:30 — forked from jsierles/gist:29838
#!/usr/bin/env ruby
#
# Find bloating passengers and kill them gracefully. Run from cron every minute.
#
# required for passenger since cron has no environment
ENV['HTTPD'] = 'httpd'
MEM_LIMIT = ARGV[0] || 500
@xenda
xenda / development.rb
Created November 19, 2009 14:26 — forked from adzap/development.rb
Restart Task and Debug with ruby-debug
# ... bottom of your development.rb
if File.exists?(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
require 'ruby-debug'
Debugger.wait_connection = true
Debugger.start_remote
File.delete(File.join(RAILS_ROOT,'tmp', 'debug.txt'))
end