Skip to content

Instantly share code, notes, and snippets.

@ratpik
ratpik / countUniqueInColumn2ofCSVFiles.sh
Created May 12, 2018 17:02
Split lines with Regex provided to awk
cat *.csv| awk -F "\"*,\"*" '{print $2}'|uniq|wc -l
@ratpik
ratpik / clear-redis.sh
Created May 1, 2018 07:47
Redis Delete all keys
./redis-cli -p 7777--raw keys "*" | xargs ./redis-cli -p 7777 del
@ratpik
ratpik / users.js
Created May 1, 2018 07:46
User in Postman App
pm.models.user.find({}, (err, users) => {
users.forEach((user) => {
console.log(`User ID: ${user.id} \n Access Token: ${user.auth.access_token} \n Email: ${user.email}`);
});
});
@ratpik
ratpik / parsePostmanCollection.js
Created October 11, 2017 06:46
Postman Collection SDK Example
var fs = require('fs'), // needed to read JSON file from disk
sdk = require('postman-collection'),
Collection = sdk.Collection,
Request = sdk.Request,
Item = sdk.Item,
ItemGroup = sdk.ItemGroup,
_ = require('lodash'),
myCollection,
requests = [],
dfs = function (item, requests) { // fn -> Depth first search
@ratpik
ratpik / NodeHTTPStatusCodes.js
Last active October 9, 2017 10:30
List of Valid HTTP Response Codes in Node (as of node v6.11.4)
console.log(require('http').STATUS_CODES);
@ratpik
ratpik / isUUID.js
Last active May 4, 2017 09:55
Checks if input is a valid UUID (any version, includes nil and GUID) as per RFC 4122 - https://tools.ietf.org/html/rfc4122
// Fiddle - https://jsfiddle.net/ratpik/azf5a9bv/3/
var UUIDIndex = {0:8, 1:4, 2:4, 3:4, 4:12};
function isHex(h, index) {
if (UUIDIndex[index] !== _.size(h)) return false;
var a = parseInt(h, 16);
return !isNaN(a) &&
a.toString(16) === _.toLower(h) ||
_.join(_.times(_.size(h), _.constant(0)), '') === _.toLower(h);
@ratpik
ratpik / async_recursion_sample.js
Created March 27, 2017 17:01
Async With Recursion
it.only('Async should work with Recursion', function (done) {
var n = 10;
var f = function(callback) {
async.waterfall([
function (cb) {
n--;
cb(null, n);
},
function (b, cb) {
@ratpik
ratpik / custom_string.js
Last active March 5, 2017 12:17
JS BinRepresentation of a custom String Object// source https://jsbin.com/jibuso
var MyString = function(source){
var arr = [];
for(var index in source){
arr.push(source[index]);
//Public property
this[index] = source[index];
}
//Public property
@ratpik
ratpik / BST_traversal.py
Created October 22, 2016 07:06
Spiral Traversal of a Binary Search Tree
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
class BST:
def __init__(self, root=None):
@ratpik
ratpik / trie.py
Last active October 13, 2016 13:54
Trie Implementation - A way to search for strings and prefixes given a list of strings
class Node:
def __init__(self, key=None, word_count=0):
self.key = key
self.word_count = word_count #Since word and prefix counts are same
self.edges = [] #List of Nodes
class Trie:
def __init__(self, root=None):
self.root = root