Skip to content

Instantly share code, notes, and snippets.

View JoshMcKin's full-sized avatar

Joshua T. Mckinney JoshMcKin

  • New Braunfels, TX
View GitHub Profile
@JoshMcKin
JoshMcKin / gist:801081
Created January 28, 2011 21:59
Deploy with Thin Rails 3
require "bundler/capistrano"
default_run_options[:pty] = true
set :user, 'user'
set :domain, 'SOMEDOMAIN.OR.IP'
set :application, "applcation_name"
set :repository, "/home/#{user}/git/#{application}.git/"
set :local_repository, "."
set :deploy_to, "/home/#{user}/#{application}"
@JoshMcKin
JoshMcKin / gist:801101
Created January 28, 2011 22:09
Nginx conf for thin clusters with shared ssl and redirect to ssl
user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@JoshMcKin
JoshMcKin / gist:809746
Created February 3, 2011 16:42
Early EventMachine Zendesk example
module EmZendesk
require 'em-http'
class Base < SimpleModel::Base
has_attributes :zen_resource, :params, :username, :password, :response, :company_url
has_attributes :format, :default => 'json'
has_attributes :http_method, :default => :post
validate :validates_post_response
in the layout file
<% cache("header_cache_#{session_user.id}") do %>
some dynamic navigation and large select box
<%end%>
in the controller
expire_fragment("header_cache_#{session_user.id}")
@JoshMcKin
JoshMcKin / gist:981561
Created May 19, 2011 19:43
Guess the number of each of the supplied values necessary to get the desired total
def self.guessing_game(values=[2.5,10.95,55.25],multi_sum=4,total_goal=79.65)
results = nil
total_amount = 0.0
length = values.length
((multi_sum ** length) / (multi_sum)).times do |i|
total = 0
possible = []
total_amount = 0.0.to_d # use decimal for accuracy
@JoshMcKin
JoshMcKin / gist:983763
Created May 20, 2011 20:47
Rake 0.9.0 Gem build fail
rake aborted!
undefined method `desc' for #<Bundler::GemHelper:0x00000101d83ab8>
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.10/lib/bundler/gem_helper.rb:24:in `install'
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/bundler-1.0.10/lib/bundler/gem_helper.rb:9:in `install_tasks'
/Users/joshmckin/Ventanex/vtx_operations/Rakefile:21:in `<top (required)>'
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load'
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:495:in `raw_load_rakefile'
/Users/joshmckin/.rvm/gems/ruby-1.9.2-p0/gems/rake-0.9.0/lib/rake/application.rb:78:in `block in load_rakefile'
@JoshMcKin
JoshMcKin / gist:1012605
Created June 7, 2011 16:30
Queued AWS Queue writes
class QueuedMessage < Aws::Sqs
def queued_messages
@queued_messages ||= []
@queued_messages
end
def initialize(aws_access_key_id = AWS_ACCESS_KEY_ID, aws_secret_access_key = AWS_SECRET_ACCESS_KEY, params = {})
super(aws_access_key_id, aws_secret_access_key,params)
end
@JoshMcKin
JoshMcKin / gist:1058768
Created July 1, 2011 15:24
EM-mysql2 dead fiber from Rails exception patch
module Mysql2
module Fibered
class Client < ::Mysql2::Client
def query(sql, opts={})
if ::EM.reactor_running?
super(sql, opts.merge(:async => true))
deferrable = ::EM::DefaultDeferrable.new
::EM.watch(self.socket, Watcher, self, deferrable).notify_readable = true
fiber = Fiber.current
deferrable.callback do |result|
@JoshMcKin
JoshMcKin / gist:1058782
Created July 1, 2011 15:32
EM-mysql2 dead fiber from Rails exception
/Users/joshmckin/test_mysq_gem/config/initializers/em_mysql2_adapter.rb:16:in `resume': dead fiber called (FiberError)
from /Users/joshmckin/test_mysq_gem/config/initializers/em_mysql2_adapter.rb:16:in `block in query'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `call'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/eventmachine-0.12.10/lib/em/deferrable.rb:141:in `set_deferred_status'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/eventmachine-0.12.10/lib/em/deferrable.rb:180:in `fail'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.11/lib/active_record/connection_adapters/em_mysql2_adapter.rb:38:in `rescue in notify_readable'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.11/lib/active_record/connection_adapters/em_mysql2_adapter.rb:33:in `notify_readable'
from /Users/joshmckin/.rvm/gems/ruby-1.9.2-p180/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /Users/joshmckin/.rvm/gem
@JoshMcKin
JoshMcKin / gist:1058838
Created July 1, 2011 16:05
NoMethodError on class
class FoosController < ApplicationController
# GET /foos
# GET /foos.xml
def index
@foos = Foo.all
Foo.bad_method #should raise NoMethodError
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @foos }
end