Skip to content

Instantly share code, notes, and snippets.

@manjeettahkur
manjeettahkur / leapyear.js
Created October 8, 2015 11:32
In this kata you should simply determine, whether a given year is a leap year or not
Description:
In this kata you should simply determine, whether a given year is a leap year or not. In case you don't know the rules, here they are:
years divisible by 4 are leap years
but years divisible by 100 are no leap years
but years divisible by 400 are leap years
Additional Notes:
Only valid years (positive integers) will be tested, so you don't have to validate them
@manjeettahkur
manjeettahkur / modules.md
Created October 20, 2015 05:43 — forked from mattdesl/modules.md
my favourite modules.
/* Object.create() vs new Speed Test
* @author Eric Hamilton
*
* Result: For a few thousand objects, it
* doesn't matter which way you go.
* For hundreds of thousands of objects,
* you might want to use new instead of
* Object.create().
*
* Tested on node v0.2.0
@manjeettahkur
manjeettahkur / test.js
Created October 21, 2015 05:27 — forked from juanpaco/test.js
Sparse indexes in Mongo with Mongoose
// Assumes you've already somehow configured your db access. I left that part out
var mongoose = require("mongoose")
var es = new mongoose.Schema({
'firstname': { type: String, required: true },
'lastname': { type: String, required: true },
'email': { type: String, required: true, index: { unique: true, sparse: true }, validate: /\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/ },
'departmentId': { type: mongoose.Schema.ObjectId, required: true },
'enddate': String,
var mongoose = require('mongoose');
mongoose.connect('localhost', 'testing_invalidate');
var schema = new mongoose.Schema({
name: { type: String, required: true },
pass: { type: String, required: true },
});
schema.methods.setPassword = function setPassword (pwd, confirm) {
if (pwd === confirm) {
@manjeettahkur
manjeettahkur / customer.js
Created October 22, 2015 12:01 — forked from geek0x23/customer.js
A mongoose model that takes advantage of the handy invalidate method to run multiple validations
var mongoose = require('./db-connect'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
uuid = require('node-uuid'),
Validator = require('validator').Validator,
val = new Validator(),
bcrypt = require('bcrypt');
Validator.prototype.error = function(msg) { return false; };
@manjeettahkur
manjeettahkur / node_debian_init.sh
Created October 30, 2015 05:11 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#!/bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@manjeettahkur
manjeettahkur / why.js
Created November 21, 2015 10:46 — forked from cowboy/why.js
JavaScript: why do we write async code the way we do?
// This is an UBER simplified example, but I hope you get the idea...
function thisIsHowWeWriteSyncCode(arg) {
var foo = doSomething(arg);
var bar = doSomethingElse(foo);
var baz = doSomethingWith("test", bar, 123);
return doLastThing(baz);
}
function soThisSeemsSensibleForAsyncCode(arg) {
@manjeettahkur
manjeettahkur / shipitfile.js
Created December 29, 2015 11:35 — forked from jbraithwaite/shipitfile.js
Shipit deploy with Slack integration
var pack = require('./package.json');
var request = require('request');
var name = pack.name;
module.exports = function (shipit) {
require('shipit-deploy')(shipit);
var deployTo = '/var/www/FOLDER_TO_DEPLOY_TO';
var deployToCurrent = deployTo + '/current';
var slackWebhookURL = 'SLACK_HOOK_URL';
// http://www.therightcode.net/deploy-nodejs-application-using-shipit/
// sudo npm i shipit-cli -g
// npm i shipit-deploy --save-dev
// npm i shipit-npm --save-dev
module.exports = function (shipit) {
require('shipit-deploy')(shipit); // remote deploy
require('shipit-npm')(shipit); // remote auto install npm packages
var config = {