Skip to content

Instantly share code, notes, and snippets.

@dustMason
dustMason / ajaxOverride.js
Created September 13, 2010 17:50
Custom error handling with jQuery.ajax()
// CUSTOM AJAX FUNCTION FOR STRUCTURED ERROR HANDLING
(function(){
// Store a reference to the original ajax method.
var originalAjaxMethod = jQuery.ajax;
var EF = function(){};
// override the default $.ajax to include special handlers for error and success
// to utilize new custom error box. existing success and error callbacks are
// left intact and given the expected params.
jQuery.ajax = function(options) {
var thisSuccess = (typeof options.success == 'function') ? options.success : EF;
@dustMason
dustMason / Validate.cfc
Created September 20, 2010 19:48
Measurement Parsing and Display in cfscript
<cfcomponent extends="Controller" output="false" hint="A set of functions to interface with the jQuery validator plugin">
<cfscript>
function measurement() {
// gets either params.w, params.d or params.h
// m = params.w OR params.d OR params.h;
if (isDefined("params.w")) { m = params.w; }
if (isDefined("params.d")) { m = params.d; }
if (isDefined("params.h")) { m = params.h; }
@dustMason
dustMason / SpecifyAPI.rb
Created February 25, 2011 22:35
Simple API wrapper for Specify using HTTParty and HTTMultiParty
require 'rubygems'
require 'httparty'
require 'HTTMultiParty'
require 'base64'
# This is a quick example to demonstrate the use of ruby to interact with the Specify API.
# I am a beginner rubyist, so please excuse my rudimentary code!
# Depends on httparty for clean and simple API wrapper code https://github.com/jnunemaker/httparty
# Depends on httpmultiparty to allow image and file uploads https://github.com/jwagener/httmultiparty
var dmp = new diff_match_patch();
var text1 = "your input text source";
var text2 = "your input text destination";
var current_unicode = parseInt('2000',16);
var charmap = {};
var replaceFirstTag = function(str,code) {
var nu = code+1;
@dustMason
dustMason / gist:1252515
Created September 30, 2011 02:34
Fix precompilation DB dependency
namespace :assets do
# Prepend the assets:precompile_prepare task to assets:precompile.
task :precompile => :precompile_prepare
# This task will be called before assets:precompile to optimize the
# compilation, i.e. to prevent any DB calls.
task 'precompile_prepare' do
# Without this assets:precompile will call itself again with this var set.
# This basically speeds things up.
# ENV['RAILS_GROUPS'] = 'assets'
ruby-1.9.2-p180 :061 > Signup.last
Signup Load (0.4ms) SELECT "signups".* FROM "signups" ORDER BY "signups"."token" DESC LIMIT 1
#<Signup:0x0000010a51f5a8> {
:token => "ab377c84",
:email => "[email protected]",
:referred_by => nil,
:notified => nil,
:user_id => nil,
:created_at => Tue, 01 Nov 2011 13:25:06 PDT -07:00,
:updated_at => Tue, 01 Nov 2011 13:25:06 PDT -07:00,
@dustMason
dustMason / scorekeeper.rb
Created November 22, 2011 12:51
ScoreKeeper.rb : A quick command-line app written in Ruby for keeping score during Gin Rummy games. Run `ruby scorekeeper.rb` to start the game.
module ScoreKeeper
class Player
attr_accessor :name, :scores
def initialize(name)
@name = name
@scores = []
end
def <<(points)
@scores << points
@dustMason
dustMason / index.js.erb
Created December 17, 2011 04:16 — forked from ryanb/index.js.erb
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
@dustMason
dustMason / cached_finder.rb
Created February 24, 2012 17:45
CachedFinder Extension for ActiveRecord
require 'digest/sha1'
module Extensions
module CachedFinder
extend ActiveSupport::Concern
module ClassMethods
def cached(options = {})
options_hash = Digest::SHA1.hexdigest(options.to_s)
Rails.cache.fetch [self.class.to_s.underscore, options_hash].join('/'), :expires_in => 1.hour, :race_condition_ttl => 10 do
all options
@dustMason
dustMason / geocoder.coffee
Created August 14, 2012 00:34
The simplest geocoder ever. CLI thingy using node.js and the Google Maps API. Enter a place, get lat + lng
prompt = require 'prompt'
gm = require 'googlemaps'
red = '\u001b[31m'
blue = '\u001b[34m'
reset = '\u001b[0m'
l = (content) ->
console.log content