Skip to content

Instantly share code, notes, and snippets.

View imalberto's full-sized avatar

alberto chan imalberto

  • Yahoo!
  • San Francisco
View GitHub Profile
@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 / 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 / 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 / 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 () { }
};
};
<!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 / 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 () {
/** @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 / photo-view.js
Last active September 15, 2016 09:06
YAF and React.js Discussion context is getting YAF to use React.js effectively.
// YAF view
var PhotoView = Y.Base.create('photoView', Y.View, [], {
photoTemplate: Template.get('photonews/photo'),
render: function () {
var container = this.get('container'),
locals = this.get('locals'),
html;
html = this.photoTemplate({
@imalberto
imalberto / routes.yml
Created January 29, 2014 21:58
routes.yaml example
-
settings:
- master
home:
path: /home
verbs:
- get
call: home.index
@imalberto
imalberto / app.js
Last active August 29, 2015 13:56
sample app.js
'use strict';
var debug = require('debug')('app'),
express = require('express'),
libmojito = require('../../../'),
app,
mojito;
app = express();
app.set('port', process.env.PORT || 8666);