Skip to content

Instantly share code, notes, and snippets.

View imalberto's full-sized avatar

alberto chan imalberto

  • Yahoo!
  • San Francisco
View GitHub Profile
/** @jsx React.DOM */
var MyComponent = React.createClass({
render: function() {
// Defaults in case the props are undefined. We'll have a solution for this
// soon that is less awkward.
var perMinute = this.props.perMinute || '-';
var perDay = this.props.perDay || '-';
return (
<div>
<h3>Clickouts</h3>
@imalberto
imalberto / res.js
Created December 10, 2013 22:55
res.render hack
function _render(name, data) {
var ViewClass = Y.Views[Y.PNUtil.classify(name + '-view')] || Y.BaseView,
foo = new ViewClass({
locals: data
});
foo.render();
_expressRender(req.app.set('hack-layout'), {
viewName: name,
// TODO this belong to the render engine
viewOutlet: function () {
<!DOCTYPE html>
<html>
<head>
<script src="http://documentcloud.github.io/underscore/underscore-min.js"></script>
<script src="http://documentcloud.github.io/backbone/backbone-min.js"></script>
<meta name="description" content="Test driving jQuery" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/smoothness/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"></script>
<meta charset=utf-8 />
@imalberto
imalberto / amd.js
Last active December 28, 2015 01:49
Modules Definitions Examples
// Definition
define('newsModel', [ 'Y.Model', 'Y.Models.DefaultModel'], function (newsModel) {
// create the newsModel object
var factory = function () {
return {
newsModel = Y.Base.create(xxx),
init: function () { }
};
};
@imalberto
imalberto / controller.server.js
Last active December 27, 2015 19:59
Exporting CSV formatted data from Mojito
exportcsv: function (ac) {
ac.model.get('mydb').fetch(function (err, data) {
var csv = convert2csv(data); // csv is of type string
ac.http.addHeader('content-type', 'application/vnd.ms-excel');
ac.http.addHeader("content-disposition", "attachment; filename=export");
ac.done(csv);
});
@imalberto
imalberto / plugin.js
Created October 18, 2013 00:27
locator-yui/lib/plugin.js
/*
* Copyright (c) 2013, Yahoo! Inc. All rights reserved.
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
/*jslint node: true, nomen: true */
"use strict";
@imalberto
imalberto / routes.json
Last active December 22, 2015 16:49
how to deal with this routes.json config with the updated scheme
{
// foo, get#foo-index
"foo": {
"path": "/foo",
"verbs": [ "get" ],
"call": "foo.index",
"params": { src: "/foo" }
},
// bar, get#foo-index
"bar": {
@imalberto
imalberto / routes.json
Last active December 21, 2015 14:49
routes.json
{
foo: {
call: "foo.index",
path: "/foo",
verbs: [ "get" ]
},
bar: {
call: "foo.index",
path: "/bar",
verbs: [ "post" ]
@imalberto
imalberto / config.js
Last active December 21, 2015 13:38
route config format
"routes": {
"homepage": {
"path": "/",
"method": "get",
"keys": [],
"regexp": {},
"annotations": {
"name": "homepage",
"dispatch": {
"call": "home.index",
@imalberto
imalberto / util.js
Last active December 19, 2015 21:58
util.common.js#copy
copy: function(oldObj) {
var newObj,
key,
len,
type,
copy = Y.mojito.util.copy;
if (!oldObj) {
return oldObj;
}