Skip to content

Instantly share code, notes, and snippets.

View codeprimate's full-sized avatar

Patrick Morgan codeprimate

  • Bellingham, WA
  • 04:18 (UTC -07:00)
View GitHub Profile
@codeprimate
codeprimate / deploy.rb
Created May 10, 2012 22:21 — forked from bkutil/deploy.rb
Start and Stop tasks for resque workers and resque scheduler with capistrano deploy hook (without God)
after "deploy:symlink", "deploy:restart_workers"
after "deploy:restart_workers", "deploy:restart_scheduler"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
@codeprimate
codeprimate / resque_workers.rake
Created May 10, 2012 22:22 — forked from karmi/resque_workers.rake
Our Rake task for running multiple Resque workers in production
namespace :queues do
desc "Run Resque workers with options and job classes loaded"
# Run with & appended to daemonize
task :workers => :environment do
def pid_directory
Rails.root.join('tmp', 'pids')
end
@codeprimate
codeprimate / gist:3054582
Created July 5, 2012 16:11
OpenSSL Commands
The following assume that you are in the homedir of your private CA userdir (/home/myca). I would suggest creating a limited system account used solely for key creation and signing. Use homedir encryption to protect your CA keys from root compromise.
Create CA Certificate
openssl genrsa -des3 -out private/cacert.key 4096 -config conf/caconfig.cnf
openssl req -new -x509 -days 365 -key private/cacert.key -out certs/cacert.crt -config conf/caconfig.cnf
Create Server Certificate
openssl genrsa -des3 -out private/nullbacon.patrick-morgan.net.key 4096 -config conf/caconfig.cnf
openssl req -new -key private/nullbacon.patrick-morgan.net.key -out nullbacon.patrick-morgan.net.csr -config conf/caconfig.cnf
@codeprimate
codeprimate / resque_web.sh
Created July 11, 2012 15:43
Start resque-web
RAILS_ROOT=`pwd` bundle exec resque-web config/initializers/resque.rb
var CategoryPicker = function(category_picker_path, subcategory_picker_path) {
this.init = function(){
var obj = this;
var category_picker = $(category_picker_path);
var subcategory_picker = $(subcategory_picker_path);
category_picker.change(function(){
if (this.value != '') {
var target_url = "/category_groups/" + this.value + "/subcategories.json";
$.ajax( target_url, {
@codeprimate
codeprimate / cooks.rb
Created August 7, 2012 07:03 — forked from shime/cooks.rb
overriding instance method with module, ultimate solution
module Prepending
def append_features(base)
prepend = self
base.extend Module.new { define_method(:new) { |*args,&block| super(*args,&block).extend(prepend) }}
end
end
module CanCook
extend Prepending
@codeprimate
codeprimate / table_subquery_update.sql
Created August 31, 2012 16:45
MySQL Update using a subquery on the updated table
-- MySQL creates a lock on tables during updates, so a temporary table must be used by the inner query within the selection criteria.
-- Update Workorder Steps to 'failure_int' datareading_type
UPDATE workorder_steps
SET datareading_type_id = (SELECT id
FROM datareading_types
WHERE code = 'failure_int')
WHERE id IN (SELECT id
FROM (SELECT workorder_steps.id
FROM workorders
@codeprimate
codeprimate / fulltext_keys.sql
Created September 19, 2012 18:34
List all FULLTEXT keys used in the Current MySQL Database
SELECT DISTINCT TABLE_NAME AS `table`, COLUMN_NAME AS `key`, index_type AS `index_type` FROM information_schema.statistics WHERE table_schema=DATABASE() AND index_type='FULLTEXT';
git diff $1 | grep "^\+[^+]\{3\}" | grep -v "^\+[\t ]*$" | wc -l
@codeprimate
codeprimate / gist:4356031
Last active December 10, 2015 01:08
Fix "boxes" command installed by Brew
# This will correct the error: "boxes: can't find config file"
sudo ln -s /usr/local/Cellar/boxes/1.1/share/boxes-config /usr/share/boxes