Skip to content

Instantly share code, notes, and snippets.

@chetandhembre
chetandhembre / index.html
Created October 26, 2013 14:16
A Pen by Chetan.
<div class = "parent">
<div class="child">
<div class="child1">
<div class="child2">
<div class="child3">
</div>
</div>
</div>
</div>
</div>

img2boxshadow.rb

a ruby script to convert images to CSS (box-shadows)

Installation

gem install rmagick    # you'll need ImageMagick & Ruby first
gem install colormath
gem install micro-optparse
@chetandhembre
chetandhembre / httpsProxy.js
Last active August 29, 2015 13:56
Create https proxy
var fs = require('fs'),
http = require('http'),
https = require('https'),
httpProxy = require('http-proxy');
var hskey = fs.readFileSync('./***-key.pem' , 'utf8');
var hscert = fs.readFileSync('./***-cert.pem' , 'utf8')
var options = {
https: {
@chetandhembre
chetandhembre / s3Uploader.js
Created April 14, 2014 13:25
Upload file to s3 using intimidate
var Intimidate = require('intimidate');
var s3Uploader = function(options) {
try {
this.client = new Intimidate(options);
} catch (e) {
return null;
}
};
@chetandhembre
chetandhembre / mongo error
Last active August 29, 2015 14:01
mongo error
> node index.js
ec2-54-234-201-7.compute-1.amazonaws.com :27017
Error: No valid replicaset instance servers found
at /var/app/current/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/repl_set/repl_set.js:446:45
at null.<anonymous> (/var/app/current/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:499:7)
at EventEmitter.emit (events.js:95:17)
at null.<anonymous> (/var/app/current/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:178:15)
at EventEmitter.emit (events.js:98:17)
at Socket.<anonymous> (/var/app/current/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:501:10)
@chetandhembre
chetandhembre / afterShutdown.json
Created May 22, 2014 13:20
Bug in Kue while shutdowning worker for particular type of job
[ { queue:
{ client: [Object],
promoter: null,
workers: [Circular],
_events: {} },
type: 'abc',
client:
{ stream: [Object],
options: [Object],
connection_id: 1,
# mongo.conf
#where to log
logpath=/log/mongod.log
logappend=true
# fork and run in background
fork = true
@chetandhembre
chetandhembre / gist:cdeff7f870401eabce66
Last active August 29, 2015 14:06
useful Linux commnad
# find process holding port
sudo netstat -lpn |grep :80
# run nginx command
sudo LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx
#reload nginx
sudo LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx -s reload
#get all nginx process
@chetandhembre
chetandhembre / named.js
Last active August 29, 2015 14:06
Performace of node.js and GC working
var globalTime = new Date().getTime();
var obj;
var a = function(){
var i;
for(i=0;i<=12000;i++){
obj = {};
obj = null;
}
}
@chetandhembre
chetandhembre / best.txt
Last active August 29, 2015 14:07
best practicess while writing javascript
1. No anonymous function give function name even in callback..V8 optimized hot function if your function do not have name then each time it get calls V8 think it is new function and tend optimize it or may not consider as hot function
2. Declare your object (initialized it). Adding and removing attribute on the fly is not optimized way to do things. See how V8's hidden call concept. And always initialize variable in same sequence.
3. use prototype to bind function to your object.
4. use buffer more often. Converting to 'utf8' string is costly
5. use 'dezalgo' module, You can find more reason behind it in link to blog post from readme of module
6. do not string concatenate using '+' operator create array of all string an use join method.
7. do not create function inside closure .. write atomic function (named function )
8. assign static constant value to varible in class using prototype
9. Do not use delete reason hidden class optimization assign null or let GC to it's job
10. try to avoid number more than 31