Skip to content

Instantly share code, notes, and snippets.

View denmarkin's full-sized avatar

Den Markin denmarkin

  • Rev.com, Inc
  • Carlsbad, CA
View GitHub Profile
# ~/.irbrc
# Requires the following gems: wirble, hirb
#
# Hirb: http://tagaholic.me/hirb/doc/index.html
# Wirble: http://pablotron.org/software/wirble/
require 'irb/completion'
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 100
@denmarkin
denmarkin / development.rb
Created April 11, 2011 08:38
Example of rails console SQL dumping and result formatting
# dump SQL into console
require 'logger'
if ENV.include?('RAILS_ENV') && !Object.const_defined?('RAILS_DEFAULT_LOGGER') # rails 2
Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))
else # rails 3
ActiveRecord::Base.logger = Logger.new(STDOUT) if defined? Rails::Console
end
# enable result formatting - install gem 'hirb'
require 'hirb'
@denmarkin
denmarkin / .irbrc.rb
Created April 23, 2011 16:10 — forked from dekart/.irbrc.rb
console luxe - gems for IRb
# Put this content to ~/.irbrc file (no extension)
require "rubygems"
begin
require "ap"
rescue LoadError => err
puts "Cannot find awesome_print gem. Please run 'gem install awesome_print' to install it."
end
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
@denmarkin
denmarkin / nginx-init-script.sh
Created April 26, 2011 17:18
ini.d script for nginx, installed by passenger gem
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@denmarkin
denmarkin / sql_logger.rb
Created May 15, 2011 17:20
Log all SQL statements in RoR 3 app. config/initializers/sql_logger.rb
# config/initializers/sql_logger.rb
connection = ActiveRecord::Base.connection
class << connection
alias :original_exec :execute
def execute(sql, *name)
# try to log sql command but ignore any errors that occur in this block
# we log before executing, in case the execution raises an error
begin
rails_env = ENV['RAILS_ENV'] || 'development'
file = File.open(Rails.root.to_s + "/log/sql_#{rails_env}.log",'a'){|f| f.puts Time.now.to_s+": "+sql} if (%w(staging development).include? rails_env)
@denmarkin
denmarkin / payments_controller.rb
Created May 29, 2011 11:00
Example of ActiveMerchant Express Checkout request construction
amount = thing.build_payment.price_in_cents
response = EXPRESS_GATEWAY.setup_authorization(amount,
:ip => request.remote_ip,
:return_url => new_payment_url,
:cancel_return_url => new_order_url,
:no_shipping => true,
:items => [{:name => "#{thing.title}", :amount => amount}]
)
@denmarkin
denmarkin / monit_rake.sh
Created June 22, 2011 15:48
monit + resque management (from @Mindwork)
#!/bin/sh
# wrapper to daemonize rake tasks: see also http://mmonit.com/wiki/Monit/FAQ#pidfile
usage() {
echo "usage: ${0} [start|stop] name target [arguments]"
echo "\tname is used to create or read the log and pid file names"
echo "\tfor start: target and arguments are passed to rake"
echo "\tfor stop: target and arguments are passed to kill (e.g.: -n 3)"
exit 1
}
[ $# -lt 2 ] && usage
@denmarkin
denmarkin / config_initializers_sass.rb
Created October 6, 2011 08:03 — forked from grk/config_initializers_sass.rb
Sass load paths Rails 3.1
Sass::Engine::DEFAULT_OPTIONS[:load_paths].tap do |load_paths|
load_paths << "#{Rails.root}/app/assets/stylesheets"
load_paths << "#{Gem.loaded_specs['compass'].full_gem_path}/frameworks/compass/stylesheets"
load_paths << "#{Gem.loaded_specs['html5-boilerplate'].full_gem_path}/stylesheets"
load_paths << "#{Gem.loaded_specs['fancy-buttons'].full_gem_path}/lib/stylesheets"
end
@denmarkin
denmarkin / nginx
Created October 6, 2011 13:29 — forked from mdominiak/nginx
nginx start up script for ubuntu
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon