Skip to content

Instantly share code, notes, and snippets.

View clarle's full-sized avatar

Clarence Leung clarle

  • Netflix
  • Los Gatos, CA
  • 19:58 (UTC -07:00)
  • X @clarler
View GitHub Profile
@clarle
clarle / array_promises_in_sequence.js
Last active August 29, 2015 14:08
Promise-based operations in sequence, with Bluebird
var Promise = require('bluebird'),
data = ['a', 'b', 'c', 'd', null, 'e'];
/**
* A long running task to run for each element of the array.
* It must return a promise
*/
function doThing(arg) {
return new Promise(
function (resolve, reject) {
@clarle
clarle / manage.py
Created April 7, 2014 22:40
Client/Server management script for COMP 512
import os
from time import sleep
from optparse import OptionParser
# Remember to add the trailing slash!
SERVER_FOLDER = "/home/2010/cleung24/comp512/a3/servercode/"
CLIENT_FOLDER = "/home/2010/cleung24/comp512/a3/clientsrc/"
MIDDLEWARE_PORT = 5678
@clarle
clarle / index.html
Created November 10, 2013 17:50
Reproduction for issue #1371
<html>
<head>
<title>Hello DataSource!</title>
<script src="/yui/yui.js"></script>
</head>
<body>
<p>Hello XML!</p>
<script>
YUI({
filter: 'raw'
@clarle
clarle / person.js
Created September 20, 2013 21:38
Simple computed Attribute
YUI().use("attribute", "attribute-computable", function (Y) {
function Person(options) {
var defaultAttrs = {
firstName : {
value: "John"
},
lastName : {
value: "Doe"
@clarle
clarle / README.md
Created September 20, 2013 21:22
AttributeComputable and BaseComputable

AttributeComputable and BaseComputable

Currently, Attribute and Base have the idea of observable properties, through AttributeObservable and BaseObservable. The next step from this is the idea of computable properties, where one Attribute may be dependent on the value of one or more other Attributes.

There's an example of how this is currently done in YUI with our current system in Attribute Getters, Setters, and Validators, which gets unwieldy when a large number of Attributes become dependent on each other.

Use Cases
  • The simple case of re-evaluating a synchronous computed attribute when one of the attributes it depends on changes. (Example: fullName should change when either firstName or lastName changes)
@clarle
clarle / deep-copy.js
Created August 23, 2013 16:51
Deep copy performance tests with Benchmark.js
var Benchmark = require('benchmark'),
suite = new Benchmark.Suite;
Benchmark.prototype.setup = function() {
function recursiveDeepCopy(o) {
var newO,
i;
if (typeof o !== 'object') {
return o;
@clarle
clarle / flip.py
Created August 20, 2013 02:05
Flippin'
import random
import collections
COIN = ["H", "T"]
def average(array):
return sum(array) / float(len(array))
def flip_coins(result):
flips = collections.deque(maxlen=3)
@clarle
clarle / index.html
Created August 19, 2013 19:47
Rendering Django data as a YUI DataTable - Remember to escape and validate user input before displaying it though!
<html>
<head>
<script src="http://yui.yahooapis.com/3.11.0/build/yui/yui-min.js"></script>
</head>
<body>
<div class="example yui3-skin-sam">
<div id="simple"></div>
</div>
<script>
YUI().use("datatable", function (Y) {
@clarle
clarle / README.md
Last active December 20, 2015 13:59
Architecture of "smart" ModelLists

ModelList Re-write

Goals and Current Usage

The goal in re-writing ModelList is to take advantage of the features in LazyModelList which improve performance, which is mainly to not immediately regenerate plain JavaScript objects that are added to the ModelList.

Right now, a ModelList is sometimes used like this inside a View:

template: function(data, options) {
 /* Interpolates data into a string of HTML */
@clarle
clarle / luke.js
Last active December 19, 2015 15:38
Comparison of different data-binding frameworks for YUI
var BoundView = Y.Base.create('bound', Y.View, [Y.DataBind], {
render: function () {
var container = this.get('container');
container.append(
'<form><p><label>Field 1: <input name="f1" data-bind-attr="field1" value="field 1 value"></label></p> <p>Field 2: <label><input name="f2" data-bind-attr="field2" type="radio" value="a" checked> 2a</label> <label><input name="f2" data-bind-attr="field2" type="radio" value="b"> 2b</label> <label><input name="f2" data-bind-attr="field2" type="radio" value="c"> 2c</label> </p> <p><label>Field 3: <input name="f3" data-bind-attr="field3" type="checkbox" value="field 3 value"></label></p> <p><label>Field 4: <input name="f4" data-bind-attr="field4" type="hidden" value="field 4 value"></label></p> <p><label>Field 5: <textarea name="f5" data-bind-attr="field5">field 5 value</textarea></label></p> <p><label>Field 6: <select name="f6" data-bind-attr="field6"> <option value="a" selected>6a</option> <option value="b">6b</option> <option va