Skip to content

Instantly share code, notes, and snippets.

View chris's full-sized avatar
🏠
Working from home

Chris Bailey chris

🏠
Working from home
View GitHub Profile
@chris
chris / Bassistance jQuery autocomplete notes.textile
Created May 8, 2010 00:39
Bassistance Autocomplete jQuery plugin notes

Notes on the Bassistance jQuery Autocomplete plugin

This plugin has some key features we employ, that I’ve yet to find in others, so we’ve stuck with it. But, it also has some bugs or idiosyncrasies that have made it quite frustrating at times. These notes are now my catalog of these issues.

Reasons we’re using it

Some of the reasons we’re using this plugin vs. others:

  • returned results can contain HTML to affect a style
  • returned results can include data, not just the matching text to put in the field. This allows us to match an item, and then inject other data that we need into the DOM. For example, matching a city, it lets us store the city’s ID, its state, and country, in hidden form fields, so that we can send that data to a third party site if needed (e.g. metasearch). This reason alone prevents using any other plugin I’ve seen (including the new autocomplete in jQuery UI 1.8).
@chris
chris / gist:383815
Created April 29, 2010 15:56
Cucumber 0.7.0 prerelease problem
# Cucumber 0.7.0 prerelease issue, contact chris at cobaltedge dot com
# The following error was due to having a feature file that was entirely commented out, with except to the tag,
# so the feature file looked like:
# @hotels
# # Feature:
# # ...
# This problem was fixed simply by also commenting out the tag :)
Using the default profile...
Parse error on line 2. Found comment when expecting one of: examples, feature, scenario, scenario_outline, tag. (Current state: tag). (Gherkin::Parser::ParseError)
@chris
chris / get_database_size.sql
Created November 11, 2009 00:30
SQL to get the size of your database (data, indexes, totals)
-- SQL to calculate the size of your database (data, indexes, total).
-- Replace the "DATABASE_NAME in the 2nd to last line with the name of your DB
SELECT concat( table_schema, '.', table_name ) table_name,
concat( round( data_length / ( 1024 *1024 ) , 2 ) , 'M' ) data_length,
concat( round( index_length / ( 1024 *1024 ) , 2 ) , 'M' ) index_length,
concat( round( round( data_length + index_length ) / ( 1024 *1024 ) , 2 ) , 'M' ) total_size
FROM information_schema.TABLES
WHERE table_schema = 'DATABASE_NAME'
ORDER BY data_length DESC;
@chris
chris / com.danga.memcached.plist
Created September 16, 2009 05:17
memcached LaunchDaemon for /usr/local/ memcached install (via homebrew)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.danga.memcached</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/memcached</string>
<string>-d</string>
#! /bin/sh
### BEGIN INIT INFO
# Provides: tracker_github_hook
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Pivotal Tracker-GitHub post-receive hook service
# Description: GitHub post-receive hook. This runs the service (via Sinatra app).
### END INIT INFO
@chris
chris / nginx_pagination_fix.conf
Created May 5, 2009 02:16
Nginx rewrite rule to change ?page pagination URL's to /p style
if ($request_uri ~* ^(.+)\?page=1$) {
set $dom_prefix $1;
set $args '';
rewrite ^(.*)$ $scheme://$host$dom_prefix permanent;
break;
}
if ($request_uri ~* ^(.+)\?page=(\d+)$) {
set $dom_prefix $1;
set $page $2;
set $args '';
@chris
chris / update_active_deals.rb
Created May 1, 2009 16:55
Script to simply go through and save all active deals, so we update their Affiliate association
#!script/runner
# Script to simply go through and save all active deals, so we update their Affiliate association
page = 1
loop do
deals = Deal.active.paginate(:per_page => 100, :page => page)
deals.each do |deal|
Deal.without_revision {
begin
deal.save
@chris
chris / ruby_benchmark_example.rb
Created December 3, 2008 07:32
Ruby benchmarking example
# Ruby benchmarking example
Benchmark.bm(5) do |timer|
date_range = [1.month.ago.to_date, 6.months.from_now.to_date]
timer.report('old way') do
10.times do
# do the old way of code here
end
end
timer.report('new way') do
@chris
chris / gist:26822
Created November 19, 2008 23:38
Use script/runner to execute a route/controller action
#!script/runner
# Use script/runner to execute a route/controller action - delete this line in real life, it's just here to help me know which gist this is.
require 'action_controller/integration'
session = ActionController::Integration::Session.new
session.host = 'www.yourdomain.com'
session.get_via_redirect '/controller/action'
require 'autotest/redgreen'
module Autotest::Growl
def self.growl(title, msg, img, pri=0, stick="")
system "/usr/local/bin/growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
Autotest.add_hook :ran_command do |at|
results = at.results.last