Skip to content

Instantly share code, notes, and snippets.

View jimjeffers's full-sized avatar

Jim Jeffers jimjeffers

View GitHub Profile
@jimjeffers
jimjeffers / jquery.plugin.calendar_input.coffee
Created March 29, 2010 06:13
A simple calendar input that only has essential functionality.
jQuery.fn.calendarInput: (options) ->
defaults: {
active_class: "active"
calendar_id: "calendar_table"
calendar_class: "calendar_object"
calendar_container_id: "calendar_container"
controls_class: "calendar_controls"
custom_class: false
default_class: "calendar_input"
dont_allow_dates_from_the_past: true
# Pre-reqs
sudo apt-get -y install libc6-dev libssl-dev libmysql++-dev libsqlite3-dev make build-essential libssl-dev libreadline5-dev zlib1g-dev
# Install ruby 1.9.2 -p290
sudo mkdir /usr/local/src
cd /usr/local/src
sudo curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz
sudo tar xzvf ruby-1.9.2-p290.tar.gz
cd ruby-1.9.2-p290
sudo ./configure --prefix=/usr/local
@jimjeffers
jimjeffers / jquery.plugin.databinder.coffee
Created December 5, 2010 16:12
A simple data binder plugin for jQuery.
# DataBinder is an object attached to the window. You can pass a JSON object
# and HTML node to the bind method to bind the JSON object data to the
# attributes mapped in the HTML node's data-bindings attribute. Providing
# an attribute data-template will cause the function to run recursively on child
# nodes. To prevent child nodes from being overwritten you can also set a
# data-preserve attribute on a given node. This will re-append a given elements
# children after updating it's content.
#
# Here's an example of a template in HTML:
# --------------------------------------------------------------------------------
@jimjeffers
jimjeffers / button.html
Created February 9, 2011 16:09
Nice shiny button all in CSS3.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Nice CSS3 Button</title>
<style type="text/css" media="screen">
body {
font: normal normal normal 1em/1.5em "Helvetica Neue", Arial, sans-serif;
}
@jimjeffers
jimjeffers / cssbeautify.rb
Created March 5, 2011 20:22
Formats a CSS file so the rules and selectors are printed clearly. Rules are sorted alphabetically, selectors are sorted by length.
nodes = File.open("path/to/stylesheet.css").readlines.join("").gsub(/\n/,"").split("}").map do |chunk|
selectors = chunk.split("{")[0]
rules = chunk.split("{")[1]
chunk = { :selectors => selectors.split(','), :rules => rules.split(';').map{|r| [r.split(':')[0],r.split(':')[1]]} } unless rules.nil? or selectors.nil?
end
output = ""
nodes.each do |node|
unless node.nil?
output += node[:selectors].sort {|x,y| x.length <=> y.length }.join(",\n") + " {\n"
output += node[:rules].sort {|x,y| x[0] <=> y[0] }.map{|rule| " #{rule.join(": ")}"}.join(";\n") + "\n}\n\n"
@jimjeffers
jimjeffers / gist:984897
Created May 21, 2011 21:04
Date Sorting Comparators
# item.getDate() assumes you are returning a Date object from your model.
dateComparator: (item) ->
item.getDate().getTime()
reverseDateComparator: (item) ->
-item.getDate().getTime()
@jimjeffers
jimjeffers / noise.coffee
Created May 22, 2011 18:11
Generate noise with Canvas.
# Inspired and largely borrowed from Pixstatic
# http://www.pixastic.com/lib/git/pixastic/actions/noise.js
# https://github.com/jseidelin/pixastic
# And NetTuts tutorial:
# http://blip.tv/nettuts/how-to-generate-image-noise-with-canvas-4439977#EpisodeDescription
# http://net.tutsplus.com/tutorials/javascript-ajax/how-to-generate-noise-with-canvas/
window.Noise = class Noise
constructor: ->
@jimjeffers
jimjeffers / gist:1043333
Created June 23, 2011 19:05
Apple's Elastic CSS Animations
<!DOCTYPE html>
<html>
<head>
<!-- Apple nicely commented all of these transitions on their source file:
http://images.apple.com/global/styles/productbrowser.css -->
<style type="text/css" media="screen">
/* Just some basic presentational CSS for the example */
a {
background: #000; display: block; color: #fff;
font: 1.5em "Lucida Grande", "Trebuchet MS", Verdana, sans-serif;
var hotSauce = new Sauce();
hotSauce.addFlavor("chili",{
equation: Easie.elasticOut,
from: -400,
to: 0,
period: 15
}).addFlavor("pepper",{
equation: Easie.circOut,
from: 0.5,
to: 1,
@jimjeffers
jimjeffers / merge_objects.coffee
Created July 10, 2011 22:32
Merge one or more objects.
# Usage: mergeObjects(obj1,obj2,obj3,etc)
mergeObjects = (objects...) ->
combinedObject = {}
for object in objects
combinedObject[key] = value for key,value of object
combinedObject