Skip to content

Instantly share code, notes, and snippets.

View somebox's full-sized avatar
⌨️
coding nights

Jeremy Seitz somebox

⌨️
coding nights
View GitHub Profile
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@somebox
somebox / unicorn-graphite.rb
Created November 12, 2013 13:03
Graphing unicorn active/queued processes (via sockets)
#!/usr/bin/env ruby
require 'rubygems'
require 'raindrops'
require 'statsd'
#
# This script monitors the active and queued unicorn processes.
# It uses the raindrops gem to look at the unix domain socket.
# Stats are polled every second (for one minute) and pushed to
# statsd as a counter. This script runs once a minute.
@somebox
somebox / redis-graphite.sh
Last active July 18, 2016 00:37
graphite-redis : monitor redis statistics with graphite across several hosts
#!/usr/bin/env ruby
require 'socket'
# This script runs every minute, captures stats about redis
# and forwards them to graphite as counter values.
# Graphite/carbon settings
GRAPHITE_HOST="graphite.intra.local.ch"
GRAPHITE_PORT=8125
>> h={a:true,b:false,c:1}
=> {:a=>true, :b=>false, :c=>1}
>> h[:a].present?
=> true
>> h[:a].presence
=> true
>> h[:b].present?
=> false
>> h[:b].presence
=> nil
@somebox
somebox / i18ndocs.diff
Created May 9, 2012 06:32
i18ndocs changes
diff --git a/Gemfile b/Gemfile
index 34fced8..7edff29 100644
--- a/Gemfile
+++ b/Gemfile
@@ -16,6 +16,8 @@ group :development do
gem "bundler", ">= 1.0.0"
gem "jeweler", ">= 1.8.3"
gem "simplecov",">= 0.5"
+ gem "fastercsv"
+ gem "i18n"
@somebox
somebox / application_controller.rb
Created May 3, 2012 11:51
rescue from routing errors
rescue_from ActionController::RoutingError do |exception|
render :file => Rails.root.join('public', '404.html'), :status => "404", :layout=>false
end
@somebox
somebox / nginx.conf
Created March 13, 2012 16:19
Nginx error page handling
# The following recipe works with upstream rails proxy for custom 404s and 500s.
# Errors are usually handled via rails except if proxy is really down, in which case
# nginx needs a bit more configration.
server {
# ...
location / {
error_page 404 = @rails; # let rails show a page with suggestions
try_files maintenance.html @rails;
@somebox
somebox / unicorn.rb
Created March 7, 2012 08:19
unicorn.rb file to deal with dead processes/stale pid and knows about RVM
APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! APP_ROOT
rescue LoadError
@somebox
somebox / nicer_ps1.sh
Created December 19, 2011 00:02
A nicer PS1
# A More Awesome PS1
# - only show username if its not the usual one
# - only show hostname if its not my local box (checks SSH_CONNECTION)
# - show root username in red
# - show current path, and smart truncate longer ones (>35 chars)
# - show git branch in brackets
# - show a red star for uncommitted git changes
# - show local hostname in green (192.*,10.*,::1)
# - show other hostnames in white
@somebox
somebox / readme.md
Created September 26, 2011 06:05 — forked from metaskills/gist:756111
Rails 3 Models To Export Mephisto To Octopress & Disqus
require 'builder'
require 'digest/md5'
class Content < ActiveRecord::Base
belongs_to :user
end
class Section < ActiveRecord::Base
has_many :assigned_sections
has_many :articles, :order => 'position', :through => :assigned_sections