This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Written by Kieran P | |
| # http://github.com/KieranP | |
| # http://twitter.com/k776 | |
| # http://k776.tumblr.com | |
| # | |
| # Feel free to fork and modify. | |
| # If you do, send me a message on | |
| # Github details changes and I'll |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # app/controllers/posts_controller.rb | |
| class PostsController < ApplicationController | |
| def index | |
| @posts.all_cached # Retrive only at once by every 5 minutes | |
| expires_in 5.minutes, :private => false, :public => true | |
| end | |
| end | |
| # app/models/post.rb | |
| Class Post |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'geoip' | |
| module Rack | |
| # Rack::GeoIPCountry uses the geoip gem and the GeoIP database to lookup the country of a request by its IP address | |
| # The database can be downloaded from: | |
| # http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz | |
| # | |
| # Usage: | |
| # use Rack::GeoIPCountry, :db => "path/to/GeoIP.dat" | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| env_vars = "RAILS_ENV=production PATH=/sb/thehierarchy/ruby/bin:/sb/thehierarchye/nginx/sbin:$PATH RUBY_HEAP_MIN_SLOTS=500000 RUBY_HEAP_SLOTS_INCREMENT=250000 RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 RUBY_GC_MALLOC_LIMIT=50000000" | |
| RAILS_ROOT = "/var/www/apps/thehierarchy/current/" | |
| Bluepill.application("thehierarchy") do |app| | |
| app.process("scheduled_notifications") do |process| | |
| process.group = "thehierarchy" | |
| process.pid_file = File.join(RAILS_ROOT, "tmp", "pids", "scheduled_notifications") | |
| process.daemonize = true | |
| process.start_command = "/usr/bin/env #{env_vars} rake --rakefile=#{RAILS_ROOT}/Rakefile app_name:scheduled_notifications" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'sinatra' | |
| require 'datamapper' | |
| require 'dm-paperclip' | |
| require 'haml' | |
| require 'fileutils' | |
| APP_ROOT = File.expand_path(File.dirname(__FILE__)) | |
| DataMapper::setup(:default, "sqlite3://#{APP_ROOT}/db.sqlite3") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb | |
| # and made a lot more robust by me | |
| # this implementation uses erb by default. if you want to use any other template mechanism | |
| # then replace `erb` on line 13 and line 17 with `haml` or whatever | |
| module Sinatra::Partials | |
| def partial(template, *args) | |
| template_array = template.to_s.split('/') | |
| template = template_array[0..-2].join('/') + "/_#{template_array[-1]}" | |
| options = args.last.is_a?(Hash) ? args.pop : {} | |
| options.merge!(:layout => false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # If your workers are inactive for a long period of time, they'll lose | |
| # their MySQL connection. | |
| # | |
| # This hack ensures we re-connect whenever a connection is | |
| # lost. Because, really. why not? | |
| # | |
| # Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
| # | |
| # From: | |
| # http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/ruby | |
| # | |
| # Download and execute this script in one-line with no temporary files: | |
| # | |
| # ruby -e "$(curl http://gist.github.com/raw/323731/install_homebrew.rb)" | |
| # | |
| # | |
| # I deliberately didn't DRY /usr/local references into a variable as this | |
| # script will not "just work" if you change the destination directory. However | |
| # please feel free to fork it and make that possible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Author: Pieter Noordhuis | |
| # Description: Simple demo to showcase Redis PubSub with EventMachine | |
| # | |
| # Requirements: | |
| # - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby | |
| # - a browser with WebSocket support | |
| # | |
| # Usage: | |
| # ruby redis_pubsub_demo.rb | |
| # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Demo < Prawn::Document | |
| def flower | |
| 0.step(270, 90) do |angle| | |
| rotate(angle, :origin => [100, 100]) do | |
| fill_color(random_color) | |
| polygon [100, 100], [150, 150], [200, 100] | |
| fill_and_stroke | |
| end | |
| end | |
| end |