Skip to content

Instantly share code, notes, and snippets.

View detj's full-sized avatar
🖥️
deep into work

Debjeet Biswas detj

🖥️
deep into work
View GitHub Profile
@detj
detj / grep-up-down.sh
Created August 27, 2016 13:23
Grab bunch of lines before & after certain keyword
# grab 10 lines before & after the pattern
# make sure escape sequences are reained so it looks pretty (that's what the -r flag is for in less)
grep -B 10 -A 10 "error" file.log | less -r
@detj
detj / app.js
Created August 18, 2016 11:43 — forked from Ajido/app.js
nodejs express4 cluster graceful restart / shutdown
...
app.use(function(req, res, next){
if (app.get('graceful_shutdown') === true) {
res.set('Connection', 'close');
}
next();
});
app.set('graceful_shutdown_start', function() {
@detj
detj / robots.txt
Last active August 17, 2016 10:50
robots.txt nginx config in one line
#Allow access to all User-agents:
location /robots.txt {return 200 "User-agent: *\nDisallow:\n";}
#Disallow access to every User-agent:
location /robots.txt {return 200 "User-agent: *\nDisallow: /\n";}
@detj
detj / diffie-hellman
Created July 8, 2016 11:09
Generate Diffie Hellman Keys
openssl dhparam -out dhparam.pem 4096
@detj
detj / run-gitlab-docker.sh
Created June 5, 2016 13:46
Run Gitlab Docker Container
#!/bin/bash
# Replace hostname
HOSTNAME=[HOSTNAME HERE]
docker run --detach \
--hostname $HOSTNAME \
--publish 443:443 --publish 80:80 --publish 22:22 --publish 9418:9418 \
--name gitlab \
--restart always \
@detj
detj / run-gitlab-runner-docker.sh
Created June 5, 2016 13:43
Run Gitlab Runner Docker container
#!/bin/bash
docker run -d --name gitlab-runner --restart always \
-v /data/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:lates
@detj
detj / elasticsearch.conf
Last active May 31, 2016 19:56
Elasticsearch Upstart Configuration
# Elasticsearch Upstart Script
description "Elasticsearch upstart script"
start on (net-device-up
and local-filesystems
and runlevel [2345]
and startup)
stop on runlevel [016]
@detj
detj / crt-to-p12.sh
Created October 14, 2015 13:48
Create a PKCS#12 or .p12 file which can be readily imported into Keychain Access
openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt -certfile CACert.crt
@detj
detj / object-factory.js
Last active December 18, 2016 20:58
Creates an object by taking an array of keys, type of the key's value and key's default value. Contains an in-house deeply recursive object cloner
var keys = ['apple', 'orange', 'grape', 'banana'];
function gen(keys, type, def) {
var constructor = type.constructor;
var obj = {};
keys.forEach(function(key) {
obj[key] = typeof constructor === 'function' ? constructor(clone(def)) : undefined;
});
return obj;
@detj
detj / inViewport.js
Created November 7, 2014 02:49
Check if a DOM element is within the viewport
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (