Skip to content

Instantly share code, notes, and snippets.

View oroce's full-sized avatar

Róbert Oroszi oroce

  • Budapest, Hungary
View GitHub Profile
@oroce
oroce / gist:1555774
Created January 3, 2012 16:56
toJSON method for nested Backbonejs objects
var YourModel = Backbone.Model.extend({
toJSON: function(){
var obj = {};
_( this.attributes ).each( function( val, key ){
obj[ key ] = val && typeof val === "object" && "toJSON" in val ? val.toJSON() : val;
});
return obj;
}
});
@oroce
oroce / twipsy-view.js
Created January 12, 2012 08:10
Twitter Bootstrap Backbone.View
var TwipsyView = Backbone.View.extend({
tagName: "div",
className: "twipsy fade",
events: {
"mouseenter": "show",
"mouseleave": "hide"
},
options: {
enabled: true,
title: "twipsyView",
@oroce
oroce / Controller.coffee
Created January 13, 2012 07:41
Controller.coffee
class Controller
constructor: ( @app ) ->
@initialize()
routes: {}
delegateRoutes: () ->
that = this
@oroce
oroce / router.js
Created January 24, 2012 19:39
Backbone.Router and pushState
define( [
"jquery",
"underscore",
"backbone",
"models/home",
"views/home",
"models/item",
"views/item"
], function( $, _, Backbone, HomeModel, HomeView, ItemModel, ItemView ){
@oroce
oroce / jade-to-amd.coffee
Created January 30, 2012 22:32
.jade template into AMD Compatible client side modules
fs = require "fs"
jade = require "jade"
path = require "path"
walk = ( start, callback ) ->
fs.lstat start, (err, stat) ->
return callback err if err?
if stat.isDirectory()
fs.readdir(
start,
(err, files) ->
@oroce
oroce / uncaughtexception.js
Created February 21, 2012 00:12
inception in uncaughtException handler
process.on( "uncaughtException", function( err ){
console.log( "this is a ReferenceError for 'foo', but no exception for 'bar'",err );
bar;
});
foo;
@oroce
oroce / dabblet.css
Created February 25, 2012 18:35
Untitled
body{
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height:100%;
}
.w-left-f,.w-left-s,.w-right-f,.w-right-s{
width:1px;
height: 100px;
background-color:black !important;
float:left;
@oroce
oroce / custom-model-with-view.js
Created June 24, 2012 17:52
backbone.js CustomModel with View
var customModel = new CustomModel();
var sampleView = new Backbone.View({
model: customModel
});
@oroce
oroce / node-restify-version-qs.js
Created November 10, 2012 14:47
node-restify before hook to serve different version of routes based on query string
var qs = require( "querystring" );
server.pre(function( req, res, next ){
var query = qs.parse( req.query() );
req._version = query.version||undefined; //if `version` isn't defined, let node-restify to decide which is the best version
next();
});
@oroce
oroce / bunyan-pipe-to-mongodb.js
Created November 10, 2012 21:29
pipe bunyan logger into mongodb (even with node-restify)
var mongoCol = require( "mongo-col" ),
mongoStream = require( "mongo-stream" ),
mongoInsertStream = mongoStream( mongoCol( "piped-collection", null, {
dbOptions:{
safe: true
}
})),
Logger = require( "bunyan" );
new Logger({