Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Kolundzija subchild

View GitHub Profile
@subchild
subchild / gist:6556632
Created Sep 13, 2013
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
View gist:6556632
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 Nov 16, 2012
session mongoose bug
View gist:4089929
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 Mar 28, 2012
Stylus function for cross browser font assignments.
View font.styl
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)
View 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 = {},
View gist:547926
/**
* 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 + ": " : "";
View $.resizeEnd.js
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)
View sortJsonArrayByProp.js
/**
* 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){