Skip to content

Instantly share code, notes, and snippets.

View clarle's full-sized avatar

Clarence Leung clarle

  • Netflix
  • Los Gatos, CA
  • 10:27 (UTC -07:00)
  • X @clarler
View GitHub Profile
@clarle
clarle / closest_mersenne.py
Last active June 7, 2016 16:20
Closest Mersenne function - optimized for readability, not performance
from math import log
def round_base_2(n):
return 2**round(log(n)/log(2))
def closest_mersenne(n):
rb2 = round_base_2(n)
# We got the closest power of 2, so you can just drop the first digit and replace all others with 1
result = bin(rb2)[3:].replace('0', '1')
return int(result, 2)
@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
@clarle
clarle / Standa.cpp
Created May 9, 2013 14:39
Standa device adapter for Micro-Manager
///////////////////////////////////////////////////////////////////////////////
// FILE: Standa.cpp
// PROJECT: Micro-Manager
// SUBSYSTEM: DeviceAdapters
//-----------------------------------------------------------------------------
// DESCRIPTION: Standa device adapters: 8SMC1-USBhF Microstep Driver
//
// COPYRIGHT: Leslie Lab, McGill University, Montreal, 2013
//
// LICENSE: This file is distributed under the BSD license.