Skip to content

Instantly share code, notes, and snippets.

View manojVivek's full-sized avatar

Manoj Vivek manojVivek

View GitHub Profile
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
@manojVivek
manojVivek / flattenArray.js
Last active August 9, 2018 10:17
Code snippet to flatten a nested array
//A recurse function to flatten a nested array
function flatten(input, output = []) {
input && input.forEach(element => {
if (element instanceof Array) {
//if found a array flatten it recursively
return flatten(element, output);
}
//if non-array element add it the output
output.push(element);
});
@manojVivek
manojVivek / listUnusedIndex-MongoDBv3-2.js
Last active December 26, 2016 12:05
Lists the indexes that are not used(according to $indexstats) across all the databases.
var dbData = {}
db.adminCommand('listDatabases').databases.forEach(function(dBase){
if( "admin" == dBase.name || "local" == dBase.name){
return;
}
var currentDb = db.getSiblingDB(dBase.name)
var collData = {}
currentDb.getCollectionNames().forEach(function(collName){
unusedIndexes = currentDb.getCollection(collName).aggregate([{"$indexStats":{}},{"$match":{"accesses.ops" : 0,"name" : {"$ne" : "_id_"}}}]).toArray()
if(unusedIndexes.length > 0){
@manojVivek
manojVivek / haproxy-request-rate-monitor.sh
Created October 21, 2016 14:47
A simple elementary script to monitor the request count for each source ips at seconds granularity by grepping the haproxy-info log
#!/bin/bash
COLUMNS=300
export COLUMNS
source_ips=( "10.0.0.1" "10.0.0.2" "10.0.0.3")
header=("Time" ${source_ips[@]})
for value in "${header[@]}"; do
printf "%-8s\n" "${value}"
done | column -x
for i in $(seq -w 1 60);
do