Skip to content

Instantly share code, notes, and snippets.

@handerson
handerson / jquery.scroll_to.js
Created June 14, 2010 14:45
jQuery plugin for a simple scroll to animation
// scroll to animation
// example usage: $('.scroll_to_here').scrollTo();
jQuery.fn.scrollTo = function(speed) {
if(speed === undefined ){
speed = 'slow';
}
$('html,body').animate({scrollTop: this.offset().top},speed);
};
@handerson
handerson / jquery.has_default_value.js
Created June 14, 2010 14:45
jQuery plugin that clears and restores a field's default value
// clears and restores a field's default value
// example usage (js): $('input.has_default').hasDefaultValue();
// example usage (html): <input class="has_default" default="This is displayed by default" type="text"/>
jQuery.fn.hasDefaultValue = function() {
function supports_input_placeholder() {
var i = document.createElement('input');
return 'placeholder' in i;
}
if(!supports_input_placeholder()){
@handerson
handerson / getUrlVars.js
Created July 7, 2010 23:53
Get URL Parameters values with jQuery
// from http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
$.extend({
getUrlVars: function(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
@handerson
handerson / simplepolling.js
Created July 27, 2010 16:28
Simple AJAX Polling jQuery Plugin
//Simple AJAX Polling jQuery Plugin
// example usage:
/* $.ajaxPoll({
url: "/path",
type: "GET",
interval: 250,
maxAttempts: 25,
successCondition: function(result) {
return result != "processing";
},
@handerson
handerson / monkey_patch_sql2005_limit.rb
Created August 2, 2011 00:32
monkey-patch for SQLServerAdapter to support SQL Server 2005-style pagination
# monkey-patching SQLServerAdapter to support SQL Server 2005-style pagination
# inspired by
# - http://alexle.net/archives/tag/mislav-will_paginate-sqlserver-2005
# - http://www.sqlservercentral.com/articles/T-SQL/66030/
# - http://stackoverflow.com/questions/4871523/sql-server-2008-r2-pagination/4871591#4871591
# - https://gist.github.com/335683
# place the following at the bottom of environment.rb:
# require "#{RAILS_ROOT}/lib/monkey_patch_sql2005_limit.rb"
@handerson
handerson / Base File.sublime-settings
Created August 15, 2011 19:17
My Sublime Text 2 settings file
{
"color_scheme": "Packages/Color Scheme - Default/Novel.tmTheme",
"font_size": 12,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"rulers": [80],
"font_face": "Inconsolata",
"word_wrap": true,
"wrap_width":80
}
@handerson
handerson / .gitignore
Created September 2, 2011 14:37
My standard git ignore file for Ruby on Rails or Phonegap (or pretty much all projects)
# RoR/Padrino
log/**/*
api/log/**/*
tmp/**/*
api/tmp/**/*
bin/*
vendor/gems/*
!vendor/gems/cache/
.sass-cache/*
*.sqlite3
body {
background-color: #C5CCD6; /* Background color */
color: #222; /* Foreground color used for text */
font-family: Helvetica;
font-size: 14px;
margin: 0; /* Amount of negative space around the outside of the body */
padding: 0; /* Amount of negative space around the inside of the body */
-webkit-user-select: none;
overflow-x: hidden;
}
@handerson
handerson / mysql_backup_to_cloudfiles.rb
Created February 17, 2012 00:24
Creates a MySQL dump and backs it up to Rackspace Cloudfiles and maintains 14 days worth of backups
require 'rubygems'
require 'cloudfiles'
cf = CloudFiles::Connection.new(:username => "", :api_key => "")
`mysqldump -u root --password=password --all-databases > /home/deploy/backup.sql`
file = File.new("/home/deploy/backup.sql")
if file
@handerson
handerson / sqlite_backup_to_cloudfiles.rb
Created February 17, 2012 00:39
Creates a backup SQLite DB and backs it up to Rackspace Cloudfiles and maintains 14 days worth of backups
require 'rubygems'
require 'cloudfiles'
require 'sqlite3'
cf = CloudFiles::Connection.new(:username => "", :api_key => "")
original = = SQLite3::Database.new('/var/www/project/current/db/original.db')
backup = SQLite3::Database.new('/home/deploy/backup.sqlite3')
backup_process = SQLite3::Backup.new(backup, 'main', original, 'main')