Skip to content

Instantly share code, notes, and snippets.

@boazsender
boazsender / keyboard-event-trigger.js
Created October 17, 2011 03:25
Dispatch a keyboard
/*
Chrome does not let you modify the keyCode prop when you trigger it, so it defaults to 0.
You can use this code to trigger a keydown with a char code of 0 in chrome.
If you use initKeyEvent instead of initKeyboardEvent, it will work in FF
(the bellow example would trigger keydown with a char code of 65 in FF).
*/
document.addEventListener( 'keydown', function( event ){
console.log( event.keyCode )
@boazsender
boazsender / abacus-api-notes.js
Created October 16, 2011 16:49
Abacus API Notes
var mainLoop = Abacus.timer({
callback: function( data ) {
data.delta // time since the last tick
data.ticks // zero indexed number of ticks
}
});
// Start the timer with an optional kill time in miliseconds
// if no miliseconds are passed in, it wil run FOR EV AR, until you pause it
mainLoop.start( 10000 )
@boazsender
boazsender / google-contacts-authsub.html
Created June 8, 2011 17:54
Boilerplate for authsubbing a user to grant permissions to their contacts, and loading in an arbitrary number of their contacts into the page.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://google.com/jsapi"></script>
<script src="google-contacts-authsub.js"></script>
</head>
<body>
<!-- Google requires an image to be on the page -->
<img src="https://localhost/img/1px.png">
@boazsender
boazsender / jquery.pubsub.js
Created May 8, 2011 02:55
Implementing what a static jQuery pubsub might look like even though everyone hates the idea.
/*
usage:
$.bind('customEvt', function( event ){
console.log( event );
});
$.trigger('customEvt');
*/
@boazsender
boazsender / carousel.js
Created April 24, 2011 04:31
A fade in/out carousel snippet.
<script src="http://code.jquery.org/jquery.js"></script>
<script src="https://github.com/cowboy/jquery-throttle-debounce/raw/master/jquery.ba-throttle-debounce.min.js"></script>
<script src="http://butterapp.org/butter/popcorn-js/popcorn.js"></script>
<script>
// Pause the video when the user hovers over one of the plugins
// for more than 500 milliseconds
$('.butter-plugin').hover(
@boazsender
boazsender / couchdb-database-maker.js
Created February 13, 2011 21:34
Quick script for creating many databases in couchdb.
var databases = ['list', 'of', 'databases'];
$.each( databases, function(iterator, database) {
$.ajax({
url: 'http://127.0.0.1:5984/' + database,
type: 'PUT',
success: function(response){
console.log(response);
}
});
@boazsender
boazsender / open-civic-data.json
Created February 5, 2011 23:29
Concept for open civic data scheme for describing geospacial and temporal civic data (crime, weather, protests, public spaces, public housing projects, public transportation paths, public transportation schedules, etc).
{
category : "", // Required Single category from (http://opencivicdata.com/#categories-wg)
properties : {} // Required Common bin for domain specific properties from from (http://opencivicdata.com/#properties-wg)
start : "", // Optional RFC3339DateTime optional start date
end : "", // Optional RFC3339DateTime optional end date
geometry : {} // Optional Geojson location feature (http://geojson.org/geojson-spec.html)
}
// Originally solved by Tim Branyen in his drop file plugin
// http://dev.aboutnerd.com/jQuery.dropFile/jquery.dropFile.js
jQuery.event.props.push('dataTransfer');
Popcorn('#video')
.play()
.currentTime(30)
.pause()
.listen('timeupdate', function(event){
console.log( this ) // the current popcorn object
this.currentTime() // the currentTime
})
.play()
.currentTime(20)