Skip to content

Instantly share code, notes, and snippets.

Swateek Jena swateek

Block or report user

Report or block swateek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@swateek
swateek / convert_to_timezone.py
Last active Jul 31, 2019
Converting a Timezone's Local Time to UTC
View convert_to_timezone.py
#!/usr/bin/python
import moment
# New York's
ny_now_local = moment.utcnow().timezone("America/New_York")
ny_midnight_local = ny_now_local.clone().replace(hours=0, minutes=0, seconds=0, microseconds=0)
ny_prev_midnight_local = ny_midnight_local.clone().subtract(days=1)
ny_prev_lasthour_local = ny_prev_midnight_local.clone().replace(hours=23, minutes=59, seconds=59, microseconds=999999)
@swateek
swateek / cleanOldDockers.sh
Created Jul 26, 2018
clean Docker Images with <none> and stopped containers
View cleanOldDockers.sh
sudo docker rmi -f `sudo docker images | grep none | awk '{ print $3 }'`
sudo docker rm `sudo docker ps -a | awk '{ print $1 }'`
@swateek
swateek / nginx.conf
Created Jul 6, 2018 — forked from anjia0532/nginx.conf
nginx proxy_pass add a static parameter
View nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
@swateek
swateek / difference.js
Created Jun 8, 2018 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
View difference.js
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@swateek
swateek / fresh-chrome-with-custom-tz.sh
Created Feb 15, 2018 — forked from prasadsilva/fresh-chrome-with-custom-tz.sh
Launch new instances of Google Chrome on OS X with isolated cache, cookies, user config and custom Timezone
View fresh-chrome-with-custom-tz.sh
#!/usr/bin/env bash
# fresh-chrome
#
# Use this script on OS X to launch a new instance of Google Chrome
# with its own empty cache, cookies, and user configuration.
#
# The first time you run this script, it will launch a new Google
# Chrome instance with a permanent user-data directory, which you can
# customize below. Perform any initial setup you want to keep on every
@swateek
swateek / nodejs_clusters.js
Last active Oct 11, 2017
NodeJS Clusters
View nodejs_clusters.js
'use strict';
const cluster = require('cluster');
const http = require('http');
const numCores = 3;
var workerIds = [];
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
View Exporting collection size to csv.
use <dbname>;
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function(n){
stats.push(db[n].stats());
});
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
@swateek
swateek / mongodb_collection_sizes.js
Created Sep 25, 2017
Use to calculate sizes of MongoDB collections.
View mongodb_collection_sizes.js
use <dbname>;
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function(n){
stats.push(db[n].stats());
});
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
@swateek
swateek / multiple_filter_criterias.js
Created Sep 14, 2017
Using multiple filter fields and filter data with REST
View multiple_filter_criterias.js
var params = {};
var filter = {};
params['filterField'] = "field1,field2";
params['filterData'] = "2,3;abc,cde";
if(params.hasOwnProperty('filterField') && params.hasOwnProperty('filterData')){
var filterFieldArr = params.filterField.split(',');
var filterDataArr = params.filterData.split(';');
@swateek
swateek / interval_timer.py
Last active Sep 12, 2017
A python piece that can run some function at regular 'x' seconds interval
View interval_timer.py
from datetime import datetime
import time
def task():
print "This is my task at - " + str(datetime.now())
while True:
task()
time.sleep(5)
You can’t perform that action at this time.