Skip to content

Instantly share code, notes, and snippets.

View milosdakic's full-sized avatar

Milos Dakic milosdakic

View GitHub Profile
@milosdakic
milosdakic / namespace.js
Created December 12, 2011 03:54
JavaScript namespacing with Underscore
function namespace(string, obj) {
var current = window,
names = string.split('.'),
name;
while(name = names.shift()) {
current[name] = current[name] || {};
current = current[name];
}
@milosdakic
milosdakic / backbone.snippets
Created January 26, 2012 23:21
Backbone.js Vim Snippets
# Class
snippet bc
var ${1:Thing} = Class.extend({
initialize: function(${2:Attributes}) {
}
});
# Model
snippet bbm
var ${1:Thing} = Backbone.Model.extend({
@milosdakic
milosdakic / server.coffee
Created August 8, 2012 01:33
Node + Express + CoffeeScript = static file server
# use express for server/middleware
express = require 'express'
# create new instance of express
app = express()
# set static directory to root directory of this file
app.use express.static __dirname
# run the application on port 9000
app.listen 9000
@milosdakic
milosdakic / stream.js
Created August 13, 2012 03:27
Backbone.js Collection/Model Stream mixin
/**
* Stream collection/model data.
* @exports mixins/Stream
* @module Stream
*/
var Stream = {
/**
* Is the collection steaming?
*
* @property streaming
@milosdakic
milosdakic / cluster.coffee
Created September 7, 2012 06:34
Node + Express + Cluster in CoffeeScript
cluster = require 'cluster'
express = require 'express'
workers = require('os').cpus().length
app = express()
app.get '/', (req, res) ->
res.send('Working!')
@milosdakic
milosdakic / sequelize-mixins.js
Created September 5, 2013 08:34
Sequelize model mixins
var User = sequelize.define('User', {
name: Sequelize.STRING
}, {
// define the mixins you want to include
// could be similar to sequelize.import()
mixins: [
'CreatedAt',
...
]
] });
@milosdakic
milosdakic / gist:6809627
Created October 3, 2013 13:14
sequelize associations issue
module.exports = function(State, Country) {
var data = require('../db/au.json');
// Create states
State.bulkCreate(data).done(function() {
// Find all newly added states where country associations is not set.
State.findAll({ where: { countryId: null }}).done(function(states) {
// Find the country we want to associate this with
Country.find({ where: { name: 'Australia' }}).success(function(australia) {
@milosdakic
milosdakic / mutliview.js
Created January 19, 2014 03:01
Express.js multi folder views
var path = require('path')
, fs = require('fs')
, utils = require('./utils')
, dirname = path.dirname
, basename = path.basename
, extname = path.extname
, exists = fs.existsSync || path.existsSync
, join = path.join;
module.exports = function(app) {
@milosdakic
milosdakic / skeleton.js
Created June 4, 2015 07:20
React Component Skeleton
var Component = React.createClass({
displayName: 'ComponentName',
propTypes: {},
getDefaultProps: function() {},
getInitialState: function() {},
componentWillReceiveProps: function(nextProps) {}
componentWillMount: function() {},
@milosdakic
milosdakic / component.js
Created July 7, 2015 04:44
React ES6 Component Skeleton
import React, { Component, PropTypes } from 'react';
export default class Awesome extends Component {
render() {}
}