Skip to content

Instantly share code, notes, and snippets.

@itayw
itayw / node.js
Created November 28, 2013 05:58
function wrapper
https://github.com/joyent/node/blob/master/src/node.js#L1007-L1014
var util = require('util')
function hook_stdout(callback) {
var old_write = process.stdout.write
process.stdout.write = (function(write) {
return function(string, encoding, fd) {
write.apply(process.stdout, arguments)
callback(string, encoding, fd)
}
@itayw
itayw / gist:7671593
Last active December 29, 2015 12:39
nodejs express csrf
Dynamic helpers has been removed from Express since 3.x.
The new usage would be app.use(express.csrf());, which comes from Connect.
Connect details about csrf:
http://www.senchalabs.org/connect/csrf.html
Full example:
http://sporcic.org/2012/06/csrf-with-nodejs-and-express/
@itayw
itayw / gist:7657175
Created November 26, 2013 11:53
increase fs watcher limit for webstorm
For an intelligent IDE it is essential to be in the know about any external changes in files it working with - e.g. changes made by VCS, or build tools, or code generators etc. For that reason, IntelliJ platform spins background process to monitor such changes. The method it uses is platform-specific; and on Linux it is Inotify facility.
Inotify requires a "watch handle" to be set for each directory in the project. Unfortunately, the default limit of watch handles may not be enough for reasonably sized projects, and reaching the limit will force IntelliJ platform to fall back to recursive scans of directory trees.
To prevent this situation it is recommended to increase the watches limit (to, say, 512K). You can do it by adding following line to the /etc/sysctl.conf file:
fs.inotify.max_user_watches = 524288
Then run this command to apply the change:
sudo sysctl -p
var net = require('net')
var sock = net.connect(1337)
process.stdin.pipe(sock)
sock.pipe(process.stdout)
sock.on('connect', function () {
process.stdin.resume();
process.stdin.setRawMode(true)
@itayw
itayw / gist:7566317
Created November 20, 2013 16:35
nconf-redis issue with null JSON values
var
nconf = require('nconf');
require('nconf-redis');
var options = {
host:'localhost',
port:80,
method:'GET'
}
@itayw
itayw / head.html
Created November 20, 2013 13:35 — forked from juliangruber/head.html
requirebin sketch
<style type='text/css'> html, body { margin: 0; padding: 0; border: 0; } </style>
@itayw
itayw / license
Created November 19, 2013 12:01
Default licensing on new JS files
/**
* joola.io
*
* Copyright Joola Smart Solutions, Ltd. <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
* Some rights reserved. See LICENSE, AUTHORS.
*
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
*/
@itayw
itayw / test.js
Created November 13, 2013 10:22
Check relative paths
var path = require('path');
var x = 'c:\\';
var y = 'C:\\joola.io\\joola.io.config\\config'
console.log(x, y);
console.log(path.resolve(x));
if (path.resolve(x) == path.join(__dirname, x))
@itayw
itayw / hook.js
Last active December 27, 2015 09:19
hook object functions and measure times
//Simple prototype modifier to add console.time measure
// whenever a function is called.
//The hook will ignore any function starting with _ as treat
// as private.
Object.prototype.hookEvents = function (modifier) {
var obj = this;
var name, fn;
for (name in obj) {