Skip to content

Instantly share code, notes, and snippets.

View levi's full-sized avatar

Levi McCallum levi

View GitHub Profile
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@pelf
pelf / snow.html
Created November 26, 2010 02:51
html5 canvas snow flakes (as seen on http://goplanapp.com/home/blackfriday)
<!DOCTYPE html>
<head>
<title>Snow</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="snow.js" type="text/javascript"/></script>
</head>
<body onload="init();">
<canvas id="bgcanvas" width="410" height="316" style="position:absolute;z-index:2"></canvas>
<img src="globe_layers_2.png" style="position:absolute;z-index:3">
<canvas id="fgcanvas" width="410" height="316" style="position:absolute;z-index:4"></canvas>
@aroder
aroder / CacheProvider.js
Created March 15, 2011 18:58
An implementation of Dustin Diaz's CacheProvider with a simplified interface
/**
* {Boolean} useLocalStorageIfAvailable - optional, defaults to true. The CacheProvider object will
* use the HTML5 localStorage object, if available
*/
function CacheProvider(useLocalStorageIfAvailable) {
// values will be stored here
this._cache = {};
this._useLocalStorage = 'undefined' == typeof(useLocalStorageIfAvailable) ? true : useLocalStorageIfAvailable;
}
@milani
milani / advanced_collision_detection.js
Created March 16, 2011 21:15
Collision detection with javascript using interval tree
// Collision detection with javascript using semi-interval tree.
// Add elements using insert function, then check collision using hasCollision.
var collisionTree = {
LEFT: 1,
RIGHT: 0,
INTERSECT: 2,
nodes:null,
margin: 1,
init: function(margin){
this.nodes = new Array();
@jimeh
jimeh / jquery.myplugin.coffee
Created April 7, 2011 23:44
Example jQuery plugin written in CoffeeScript, and the resulting compiled JavaScript file.
$.fn.extend
myplugin: (options) ->
self = $.fn.myplugin
opts = $.extend {}, self.default_options, options
$(this).each (i, el) ->
self.init el, opts
self.log el if opts.log
$.extend $.fn.myplugin,
default_options:
@jeresig
jeresig / .vimrc
Created May 4, 2011 16:46
VIM Config
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
set nocompatible
set autoindent
set tabstop=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
syntax on
@clintongormley
clintongormley / gist:1088986
Created July 18, 2011 09:19
Create index for partial matching of names in ElasticSearch
# First, create the synonyms file /opt/elasticsearch/name_synonyms.txt
# with the contents:
#
# rob,bob => robert
#
## CREATE THE INDEX WITH ANALYZERS AND MAPPINGS
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
@ryangreenberg
ryangreenberg / todo.rb
Created March 26, 2012 23:03
todo_for_real
require 'date'
class ExpiredTodoError < StandardError; end
# Implementation #
def todo(what, by_date)
if production? || (Date.parse(by_date) >= Date.today)
yield
else
raise ExpiredTodoError, "TODO: #{what}"
@kmiyashiro
kmiyashiro / admin.html
Created May 10, 2012 21:02
Mocha HTML spec
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="../libs/mocha.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
<body>
<div id="mocha"></div>
<script src="../libs/mocha.js" type="text/javascript" charset="utf-8"></script>