Skip to content

Instantly share code, notes, and snippets.

@yuchi
yuchi / test.js
Created October 20, 2011 12:23
Uniqueness by id in Backbone.Collection
var _oldPrepareModel = Backbone.Collection.prototype._prepareModel;
Backbone.Collection.prototype._prepareModel = function (model, options) {
var _id = model.id;
if (!(model instanceof Backbone.Model)) _id = model[this.model.prototype.idAttribute];
if (this._byId[_id]) return this.get(_id);
return _oldPrepareModel.call(this, model, options);
}
@yuchi
yuchi / stream-to-string.js
Last active December 16, 2015 20:09
Titanium SDK: a snippet to read a Stream into a string preserving UTF-8 characters
/**
* Titanium SDK - Stream UTF-8 reader
* ==================================
*
* a snippet to read a Stream into a string preserving UTF-8 characters
*
* Author: Pier Paolo Ramon
* Copyright 2013 SMC Treviso <http://www.smc.it>
*
*/
AUI.add(
'animated-scroll',
function(A) {
// Yes, user agent sniffing.
var scrollTarget = /webkit/i.test(navigator.userAgent) || document.compatMode == 'BackCompat' ?
document.body :
document.documentElement;;
@yuchi
yuchi / result.js
Created October 15, 2013 08:05
using CoffeeScript with Appcelerator Hyperloop
@import('Foundation/NSDictionary');
@import('Foundation/NSMutableDictionary');
@import('Foundation/NSNumber');
@import('Foundation/NSBundle');
@import('Foundation/NSString');
@import('Foundation/NSUTF8StringEncoding');
@import('Foundation/NSObject');
@import('Foundation/UILabel');
@import("Foundation/NSLog");
;

Keybase proof

I hereby claim:

  • I am yuchi on github.
  • I am yuchi (https://keybase.io/yuchi) on keybase.
  • I have a public key whose fingerprint is 6E1F FB29 BE6A AB78 08E5 5167 EB60 4195 15F7 654B

To claim this, I am signing this object:

@yuchi
yuchi / gist:9828475
Last active August 29, 2015 13:57 — forked from baxtheman/gist:9828154
<aui:script use="aui-base,anim-base,anim-node-plugin,anim-scroll">
var step = 25;
var scrolling = false;
var list = A.one('.oneshop-portlet-item-browser .list');
var a = new A.Anim({
node: '.oneshop-portlet-item-browser .list',
duration: 0.5
});
@yuchi
yuchi / dictionary_map.swift
Last active September 13, 2018 15:39
Swift extension that gives Dictionaries support for .map
extension Dictionary /* <KeyType, ValueType> */ {
func mapKeys<U> (transform: KeyType -> U) -> Array<U> {
var results: Array<U> = []
for k in self.keys {
results.append(transform(k))
}
return results
}
@yuchi
yuchi / camelcase.js
Created July 24, 2014 21:39
CamelCaseUtil.normalizeCamelCase in JS
function isUpperCase(c) {
return (c !== c.toLowerCase());
}
function normalize(s) {
var buffer = '';
var upperCase = false;
var l = s.length;
var c, nextUpperCase;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yuchi
yuchi / dynamic_templates.js
Created February 4, 2015 23:06
Multiple dynamic template children
// views
var templates = {};
// Up to 5 dynamic elements
var maxDynamicImages = 5;
// get an array in the form [ 0, 1, 2, ... n ]
range(maxDynamicImages)
// number -> template