Skip to content

Instantly share code, notes, and snippets.

View adamloving's full-sized avatar
💭
10x Ninja Rockstar

Adam Loving adamloving

💭
10x Ninja Rockstar
View GitHub Profile
@adamloving
adamloving / inheritance.js
Created April 18, 2011 23:47
More examples of javascript inheritance patterns
// There does not appear to be a clear winner here. #3 is ideal but too verbose.
// So, I think it is convenient to use a combination of all of these.
// establish a namespace
Ext.ns('MYCO.controls'); // for class definitions
Ext.ns('MYCO.mypage'); // for instances
// [1] Singleton object with functions (when only 1 object is necesary)
MYCO.mypage.mySimpleCar = {
doors : 4,
@adamloving
adamloving / bigdoor-simple-sample.sh
Created April 27, 2011 16:51
Use BigDoor API to award points via a shell script
# the simplest possible way to award points
# note that this uses the JSONP proxy and is insecure (subject to frequency caps, you can give yourself or anybody else as many points as you want)
# check that user exists
curl -v "http://api.bigdoor.com/api/publisher/f284d42515214498baf2f601845f5c2c/proxy/end_user/adamloving?method=GET&callback=callback"
# execute XP transaction
curl -v "http://api.bigdoor.com/api/publisher/f284d42515214498baf2f601845f5c2c/proxy/named_transaction_group/618557/execute/adamloving?method=POST&callback=callback&non_secure=1"
@adamloving
adamloving / google-js-lint.sh
Created April 28, 2011 16:48
google js lint
# install it on mac
sudo easy_install http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz
# run
gjslint myfile.js
# fix it automatically
fixjsstyle myfile.js
@adamloving
adamloving / twitter-user-timeline.js
Created May 15, 2011 21:37
The simplest way to get a user's Twitter timeline using Javascript and jQuery
var url = "http://twitter.com/status/user_timeline/adamloving.json?count=10&callback=?";
$.getJSON( url, function( data ){ console.log(data) });
@adamloving
adamloving / viral_gate.html
Created September 5, 2011 05:00
Viral Gate - how to require liking, sharing, or tweeting to reveal content.
<html>
<body>
<!--
This page demonstrates how to hide some content on the page until the
viewer clicks one of the social sharing buttons.
You can see a live demonstration of this technique on this blog post:
http://adamloving.com/internet-programming/gamify
@adamloving
adamloving / watch-sample.js
Created September 14, 2011 21:47
Example of using node.js watch
// npm install watch
// see: https://github.com/mikeal/watch
watch = require('watch');
watch.createMonitor('/Users/adam', function (monitor) {
monitor.on("created", function (f, stat) {
console.log('created', f);
})
@adamloving
adamloving / watcher.js
Created October 13, 2011 20:43
Node.js CoffeeScript, Jade, and Stylus compiler (watches filesystem for changes)
var OUTPUT_JS_FILENAME = '../media/partner/js/widgets.js'
var OUTPUT_CSS_FILENAME = '../media/partner/css/widgets.css'
var OUTPUT_HTML_PATH = 'templates'
var fs = require('fs')
var jade = require('jade')
var stylus = require('stylus');
var cs = require('coffee-script');
var watch = require('watch');
@adamloving
adamloving / copy.py
Created October 30, 2011 23:47
Moving some mp3 files around
import shutil, os, os.path
root = '/Volumes/Blackmagic/Music/'
dest = '/Volumes/Blackmagic/90bpm/'
f = open('working.m3u')
s = f.read()
files = s.split('\n')
i = 0
@adamloving
adamloving / fade_binding_handler.coffee
Created December 23, 2011 17:53
Knockout binding handler using jQuery fadeIn and fadeOut
ko.bindingHandlers.fade =
init: (element, valueAccessor) ->
element = jQuery(element)
value = valueAccessor()
value = ko.utils.unwrapObservable()
element.toggle(value)
update: (element, valueAccessor) ->
element = jQuery(element)
@adamloving
adamloving / swipe-listener.coffee
Created January 29, 2012 19:45
Webkit (iPhone Safari) swipe event handler
# This is a translation of http://rabblerule.blogspot.com/2009/08/detecting-swipe-in-webkit.html
class SwipeListener
constructor: (@el, @handler) ->
@el.addEventListener('touchstart', @onTouchStart, false);
@startX = @startY = @direction = null
cancelTouch: () ->
@el.removeEventListener('touchmove', @onTouchMove)
@el.removeEventListener('touchend', @onTouchEnd)
@startX = null