Skip to content

Instantly share code, notes, and snippets.

@amundo
amundo / gist:288282
Created January 27, 2010 23:40
Super short intro to using cosine similarity in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# see http://www.fileslip.net/news/2010/02/04/language-id-project-the-basic-algorithm/
from math import sqrt
you = {'pennies': 1, 'nickels': 2, 'dimes': 3, 'quarters': 4 }
me = {'pennies': 0, 'nickels': 3, 'dimes': 1, 'quarters': 1 }
abby = {'pennies': 2, 'nickels': 1, 'dimes': 0, 'quarters': 3 }
@remy
remy / gist:350433
Created March 31, 2010 14:58
Storage polyfill
if (typeof window.localStorage == 'undefined' || typeof window.sessionStorage == 'undefined') (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@dmolsen
dmolsen / Google Analytics Outbound Tracking with Events
Created August 12, 2010 02:02
This is so you can use the latest Google Analytics set-up code to track outbound links from your site. Requires jQuery.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
@cowboy
cowboy / HEY-YOU.md
Last active July 1, 2024 08:37
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@paulirish
paulirish / gist:704386
Created November 17, 2010 23:55
10 or 11 or 12 things i learned from the jquery source
/*
.d dP"Yb dP"Yb 88""Yb .d .d dP"Yb 88""Yb .d oP"Yb. 888888 88 88 88 88b 88 dP""b8 .dP"Y8
.d88 dP Yb dP Yb 88__dP .d88 .d88 dP Yb 88__dP .d88 "' dP' 88 88 88 88 88Yb88 dP `" `Ybo."
88 Yb dP Yb dP 88"Yb 88 88 Yb dP 88"Yb 88 dP' 88 888888 88 88 Y88 Yb "88 o.`Y8b
88 YbodP YbodP 88 Yb 88 88 YbodP 88 Yb 88 .d8888 88 88 88 88 88 Y8 YboodP 8bodP'
88 88 888888 db 88""Yb 88b 88 888888 8888b. 888888 88""Yb dP"Yb 8b d8
@drewwells
drewwells / core.test.js
Created April 14, 2011 20:21
RequireJS and QUnit sitting in a tree
//Wait for relevant code bits to load before starting any tests
define(['core.js'], function( core ) {
module("Core Tests");
test("Test core methods", function(){
expect(2);
equals( 1, 1, "A trivial test");
ok( true, "Another trivial test");
});
@jeremyckahn
jeremyckahn / touchify.js
Created August 11, 2011 21:52
A function to make Backbone Views touch-ready
/**
* Asesses all of the events handlers bound on an View and makes touch event equivalents.
*
* Dependencies: Backbone, jQuery, Ben Alman's Outside Events jQuery plugin updated to support "touchstart"
*
* @param {Backbone.View} view
*/
function touchify (view) {
_.each(view.events, function (value, key) {
_.each({'mouseleave': 'touchstartoutside', 'mouseenter': 'touchstart'}, function (eventValue, eventKey) {
@rajraj
rajraj / gist:1388849
Created November 23, 2011 14:46
Capybara Reference
# Credit: http://richardconroy.blogspot.com/2010/08/capybara-reference.html
#Navigating
visit('/projects')
visit(post_comments_path(post))
#Clicking links and buttons
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
@dmolsen
dmolsen / gist:1495085
Created December 19, 2011 01:46
Holiday card timed events code
// don't change these variables
var p = false; // currently playing
var e = false; // ended
var j = true; // first play
var videoTimeRaw = 0;
var currentTime = 0;
var defaultInterval = 100;
// configure these variables
var vidId = 'videoEmbed'; // the ID of the div holding the video
@kaiohken1982
kaiohken1982 / Multicheckboxes.php
Created December 22, 2011 14:36
Zend Form Element Multicheckboxes unordered list tag ul
<?php
class My_Form_Template extends My_Form
{
public function init()
{
parent::init();
$this->addElements(array(
$this->createElement(self::TYPE_MULTICHECKBOX, 'checks', array(