Skip to content

Instantly share code, notes, and snippets.

@bcalloway
bcalloway / jQuery-ajax-load.js
Created January 19, 2010 22:03
Ajax sorting of page results using jQuery
$('img#spinner').hide();
// Sort products by size selected from dropdown
$('form select#size').change(function() {
$('img#spinner').show();
var size = $("select#size").val();
if ($.getUrlVar('keywords')) {
var keywords = $.getUrlVar('keywords');
var url = "/products?size=" + size + "&keywords=" + keywords + " ul.product-listing";
@bcalloway
bcalloway / .bash_profile
Created February 17, 2010 16:11
My custom bash profile
source ~/.git-completion.bash
#Prompt shows user, working directory, and branch if its a git repo
PS1='\h:\w$(__git_ps1 "(%s)") $ '
# maintains a jump-list of the directories you actually use
export JPY=/Users/bcalloway/scripts/j.py # tells j.sh where the python script is
. /Users/bcalloway/scripts/j.sh # provides the j() function
alias jl='j -l'
alias jt='j -t recent'
@bcalloway
bcalloway / application_controller.rb
Created March 2, 2010 19:40
Super Simple Role-Based Authorization
class ApplicationController < ActionController::Base
helper :all
protect_from_forgery
filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user, :role_call
before_filter :start_session
@bcalloway
bcalloway / create_imports.rb
Created March 10, 2010 15:46
Importing a csv file using FasterCSV
class CreateImports < ActiveRecord::Migration
def self.up
create_table :imports do |t|
t.string :datatype
t.integer :processed, :default => 0
t.string :csv_file_name
t.string :csv_content_type
t.integer :csv_file_size
t.timestamps
end
@bcalloway
bcalloway / mysql_backup.sh
Created April 22, 2010 13:31
MySQL backup shell script
We couldn’t find that file to show.
@bcalloway
bcalloway / daily.sh
Created April 22, 2010 13:42
s3sync backups
#!/bin/sh
#
# Sync's the following dirs to S3 using s3sync.rb
# /public/uploads
# /etc
# /usr/local/ec2onrails
#
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
@bcalloway
bcalloway / reset_pass.sh
Created May 10, 2010 14:49
Reset MySQL root password
mysql> update user set password=PASSWORD('') where user='root';
Query OK, 2 rows affected (0.03 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> exit
Bye
@bcalloway
bcalloway / paperclip_orientation.rb
Created June 11, 2010 15:32
Method to determine the orientation of an image using Paperclip
# via http://jimneath.org/2010/06/10/calculating-an-images-orientation-using-paperclip/
class Image < ActiveRecord::Base
# Paperclip
has_attached_file :file
# Callbacks
before_create :set_orientation
protected
@bcalloway
bcalloway / test_db_connection.php
Created August 4, 2010 18:47
Basic test for db connection
<?php
//test database connection
// Address error handling.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);
// Attempt to connect to MySQL
if ($dbc = mysql_connect ($host, $user, $pass)) {
@bcalloway
bcalloway / mysql_dupes.sql
Created September 22, 2010 22:08
SQL query to find duplicate records
SELECT t1.*
FROM table1 AS t1
JOIN (SELECT col1
FROM table1
GROUP BY col1
HAVING count(col1) > 1) AS t2 ON t1.col1 = t2.col1
(where col1 is the column containing the duplication)