Skip to content

Instantly share code, notes, and snippets.


Jeremy Lu coodoo

View GitHub Profile
View gist:615368
var input = "@ch: THIS IS A BOOK @c:professional-quality display and classified ads using a web interface. You can control the quality of these ads — and accept them later in the production cycle — while still giving your customers a wide range of creative options. At the same time, the process provides an opportunity to cross-sell and upsell your customers to higher value placements by showing them additional options during the creation process. You can even add new categories of advertisements without expending additional resources.";
var r = /(@.*?:)/g;
var k = r.exec( input );
coodoo /
Created Nov 29, 2012 — forked from dideler/
coodoo / Backbone-Collection-View
Created Dec 1, 2012
Backbone Collection View
View Backbone-Collection-View
* Backbone Collection View
* A light-weight approach to display filetered data from collection by assigning rules, without changing original models,
* which works just like CollectionView in other languages (ie: Java, WPF and AS3).
* Usage:
* 1. Filter by single field:
* this.wineList.filterView( {Country:'France'}} );
View gist:4188218
module.exports = function(grunt) {
requirejs: {
std: {
options: {
almond: true,
baseUrl: "lib",
coodoo / b
Last active Dec 10, 2015
What if we can assign an action (callback) for each of the 'eat' event ? this way switch/case would be eliminated.
View b
var fsm = StateMachine.create({
initial: 'hungry',
events: [
{ name: 'eat', from: 'hungry', to: 'satisfied', action: 'foo' },
{ name: 'eat', from: 'satisfied', to: 'full', action: 'bar' },
{ name: 'eat', from: 'full', to: 'sick', action: 'coo' },
{ name: 'rest', from: ['hungry', 'satisfied', 'full', 'sick'], to: 'hungry', action: 'doo' },
coodoo / State_Machine.js
Created Jan 5, 2013
Implemented in a way that resembles SMC (, primarily adding two callbacks a. action() b. guard() Changes I made are marked with "jx" in the comment.
View State_Machine.js
(function (window) {
var StateMachine = {
VERSION: "2.2.0",
coodoo / randomColor.js
Created Mar 2, 2013
get random color in hex or rgba format.
View randomColor.js
* @param useRGB Boolean, true for rgba format, false will return color in hex format
* @param randomAlpha Boolean, when using rgba format, decide whether to randomnize alpha value too
function getRandomColor( useRGB, randomAlpha ){
if( useRGB ){
return "rgba("+
coodoo / gist:5251585
Created Mar 27, 2013
Weird behavior in chrome's dev tool console
View gist:5251585
I tried to pause the script, then enter following command in the console:
The weird part is, sometimes it will show the object state, but some times it will just show the <div> tag, seems it's the result of toString() ?
Is there a way to always get object state in the console ?
Screen cap here:
coodoo / starling.js
Created May 6, 2013
Starling.js source code, slightly annotated. Starling.js is a canvas based drawing framework, ported from iOS to AS3 to Javascript. Demo:
View starling.js
RequireJS 2.1.4 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
Available via the MIT or new BSD license.
see: for details
/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. |
coodoo / getQueryString.js
Created May 25, 2013
input: "$filter=&$top=3&$skip=3&$orderby=firstName&$format=json&$inlinecount=allpages output: Object {$filter: "", $top: "3", $skip: "3", $orderby: "firstName", $format: "json"…} $callback: "callback" $filter: "" $format: "json" $inlinecount: "allpages" optional: enter key name as 2nd parameter to just get that value
View getQueryString.js
getQueryString: function ( urlString, key) {
function parseParams() {
var params = {},
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
q = urlString;