Skip to content

Instantly share code, notes, and snippets.

Cody Caughlan ruckus

Block or report user

Report or block ruckus

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ruckus
ruckus / statistics.sql
Created Jun 5, 2013
Postgres statistics queries
View statistics.sql
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
@ruckus
ruckus / gist:2293434
Created Apr 3, 2012
Basic setup of WAL-E for continuous archiving and recovery
View gist:2293434

WAL-E needs to be installed on all machines, masters and slaves.

How to install WAL-E

Only one machine, the master, writes WAL segments via continuous archiving. The configuration for the master postgresql.conf is:

archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env wal-e wal-push %p'
archive_timeout = 60
@ruckus
ruckus / gist:3124445
Created Jul 16, 2012
Rails Single Table Inheritance example
View gist:3124445
create_table :media_items do |t|
t.string :type, :null => false, :limit => 32
t.string :name
t.timestamps
end
class MediaItem < ActiveRecord::Base
validates_presence_of :kind
end
View archive-rds-logs-to-s3.sh
#!/bin/bash
MONTH=`date +"%Y-%m"`
DAY=`date +"%d"`
THISHOUR=`date +"%H"`
LASTHOUR=`expr $THISHOUR - 1`
TIMESTAMP=`date +"%Y-%m-%d"`
TIMESTAMP="${TIMESTAMP}-${LASTHOUR}"
echo "Start: postgresql.log.${TIMESTAMP}"
@ruckus
ruckus / rds_download_logfiles.rb
Created Jan 9, 2015
Ruby script to download log files from RDS and archive to S3.
View rds_download_logfiles.rb
=begin
This script uses the AWS v2 API
Gemfile:
source "https://rubygems.org"
gem "aws-sdk", "2.0.17.pre"
@ruckus
ruckus / AppController.php
Created Oct 25, 2012
CakePHP Request logging ala Rails
View AppController.php
class AppController extends Controller {
function beforeFilter() {
$this->capture_request_head_for_log();
}
/*
Log some basic basic details of the HTTP Request:
Started GET "/users/lost" for 127.0.0.1 at 2012-10-24 19:18:25 -0700
@ruckus
ruckus / gist:3989311
Created Oct 31, 2012
tumblr theme with fixed footer
View gist:3989311
<!DOCTYPE html>
<!--
High Res Theme 1.1.9 -- 26 September 2012
(c) 2011-2012 Justin Ouellette, all rights reserved
http://highrestheme.tumblr.com/
-->
<html>
<head>
<title>{Title}{block:PostSummary} - {PostSummary}{/block:PostSummary}</title>
<meta name="tumblr-theme" content="30257" />
@ruckus
ruckus / Gemfile
Last active Dec 22, 2016
Example controller for a SOAP Endpoint for Quickbooks Web Connector (QWC)
View Gemfile
# QBD Integration
gem "wash_out", "0.9.0"
gem 'qbxml', '~> 0.1.5'
@ruckus
ruckus / mailer_recipient_override.rb
Created Sep 9, 2016
Place in `config/initializers/mailer_recipient_override.rb` and be sure to define an environment variable for `EMAIL_RECIPIENT_OVERRIDE`
View mailer_recipient_override.rb
class OverrideMailReciptient
def self.delivering_email(mail)
if Rails.env.development?
original_to = mail.to
mail.to = ENV['EMAIL_RECIPIENT_OVERRIDE']
mail.subject = "[DEVELOPMENT] #{mail.subject} - Recipient: #{original_to}"
if mail.cc && mail.cc.any?
new_body = "#{mail.body}\n\nRemoved CC: recipients: #{mail.cc.join(", ")}"
mail.body = new_body
mail.cc = []
View Summary.md

Summary: if you're posting a form via Content-Type: application/x-www-form-urlencoded then the data attribute itself must be a valid URL-encoded string - it CANNOT be a hash. Angular $http will not convert it to a URL-encoded format (like jQuery does).

When you run this code your cake log will have a line like:

2013-11-12 20:08:50 Error: POST: Array
(
    [name] => scott
    [flavor] => vanilla
)
You can’t perform that action at this time.