Skip to content

Instantly share code, notes, and snippets.

View subchild's full-sized avatar

Alex Kolundzija subchild

View GitHub Profile
@subchild
subchild / gist:6556632
Created September 13, 2013 21:58
Catch-all expressjs route gets executed even after first matching res.send() is handled. Discussed here: https://groups.google.com/forum/#!topic/express-js/QVxp1YXkgqE
var express = require('express');
var app = express();
app.get('/', function(req, res){
console.log('/');
res.send('first');
});
app.get('/about', function(req, res){
console.log('/about');
@subchild
subchild / gist:4089929
Created November 16, 2012 19:03
session mongoose bug
app.post('/login', function(req, res){
User.findOne({email:req.body.email}, function(err, user){
if (err) throw err;
if (user && user.isValidPassword(req.body.password)){
user.last_login = Date.now();
user.save(function(err){
if (err) throw err;
req.session.user = user;
// console.log(req.session.user) // THIS WORKS!
@subchild
subchild / font.styl
Created March 28, 2012 22:46
Stylus function for cross browser font assignments.
font(name, path, prefix)
font-family name
font-weight normal
font-style normal
src: url(path + prefix + '.eot')
src: url(path + prefix + '.eot?#iefix') format(embedded-opentype)
src: url(path + prefix + '.woff') format(woff)
src: url(path + prefix + '.ttf') format(truetype)
src: url(path + prefix + '.svg#' + name) format(svg)
@subchild
subchild / Loader
Created October 13, 2010 14:31
Loader
/**
* Loader instances support evented ajax calls, with caching
* @requires $.bindable()
*/
var Loader = function(){
this._cache = {};
};
Loader.prototype.load = function(cfg){
var _self = this,
_cfg = {},
@subchild
subchild / gist:547926
Created August 24, 2010 17:28
loggable()
/**
* Loggable adds a log method to the passed object.
* @param obj {Object} Object which will get a new log() method
* @param objName {String} Optional parameter for displaying a string before each log output
* @param debugMode {boolean} Optional switch for disabling logging
*/
var loggable = function(obj /* , objName, debugMode */){
var objName = arguments[1] || "",
debugMode = (typeof arguments[2]!=="undefined") ? arguments[2] : true;
prefix = objName ? objName + ": " : "";
@subchild
subchild / $.resizeEnd.js
Created April 18, 2010 18:21
$.resizeEnd()
jQuery.fn.extend({
/**
* Binds new resize handler to window object. For IE and Safari handler is executed on resize completion.
* @param newHandler function object
*/
resizeEnd: function(newHandler){
$(this).resize(function(){
var handlerCode = newHandler.toString(); // for hash reference
if ($.browser.msie || $.browser.safari){ // handle after resize operation is complete (once)
@subchild
subchild / sortJsonArrayByProp.js
Created April 13, 2010 02:30
sortJsonArrayByProp()
/**
* Sorts an array of json objects by some common property, or sub-property.
* @param {array} objArray
* @param {array|string} prop Dot-delimited string or array of (sub)properties
*/
function sortJsonArrayByProp(objArray, prop){
if (arguments.length<2){
throw new Error("sortJsonArrayByProp requires 2 arguments");
}
if (objArray && objArray.constructor===Array){