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 / 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 (
@detj
detj / async-template.js
Last active August 29, 2015 14:06
async template loading with requests caching
/**
* Asynchronously fetches a template & caches it internally
*
* If a request for a template hasn't completed yet and another
* request arrives, then instead of queuing the request resolve
* the deffered with the previously cached request
*/
function fetchTemplate(path) {
/**
@detj
detj / pushout.sh
Last active August 29, 2015 14:04
Push code to an outside repo, without revealing commits
#!/bin/sh
# The MIT License (MIT)
# Copyright (c) 2014 Debjeet Biswas
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@detj
detj / echoback.sh
Last active August 29, 2015 14:04
How to parse arguments using getopts
#!/bin/sh
# Uses getopts to parse passed arguments
# Show usage
show_help() {
cat << EOF
Usage: echoback -m message
@detj
detj / cookies.js
Last active August 29, 2015 14:02
Client side cookie manipulation
/**
* Get a cookie by key
*/
function getCookieItem(sKey) {
if (!sKey || !this.hasCookieItem(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
}
/**
* Set a cookie
@detj
detj / <-- -->.js
Last active August 29, 2015 14:02
--> Arrow operators <--
function foo() {
var s = 4;
var t = 1;
while(s --> t) { console.log(s) }
}
// Output
// 3
// 2
// 1
@detj
detj / in-arr-object.js
Created March 27, 2014 11:49
Search an object inside an Array of objects using a key
/**
* Searches object in Array by key
*
* Usage:
*
* List should be an Array like this
* var foo = {};
* var list = [
* { name: {} }, { name: foo }, { name: {} }
* ];