Skip to content

Instantly share code, notes, and snippets.

View pranavgarg's full-sized avatar

Pranav Garg pranavgarg

View GitHub Profile

-- Information related to index, table size with the scans SELECT t.tablename, indexname, c.reltuples AS num_rows, pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size, pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size, CASE WHEN indisunique THEN 'Y' ELSE 'N' END AS UNIQUE,

@pranavgarg
pranavgarg / runtime plotting for different big o-complexity
Created January 2, 2018 19:58
plot runtimes for different big oh notation
import matplotlib.pyplot as plt
import numpy as np
import math
n = range(1,9) # input range
lgn = [math.log(x,2) for x in n] #logn
l = [x for x in n] # linear
nlgn = [x*math.log(x,2) for x in n] # nlogn
q = [x**2 for x in n] # quadratic
p = [2**i for i in n] # polynomial
<?php
$loops = 100000;
$str = "ana are mere";
echo "<pre>";
$tss = microtime(true);
for($i=0; $i<$loops; $i++){
$x = crc32($str);
}
@pranavgarg
pranavgarg / keybase.md
Created February 13, 2017 17:43
keybase pranav

Keybase proof

I hereby claim:

  • I am pranavgarg on github.
  • I am pgarg (https://keybase.io/pgarg) on keybase.
  • I have a public key whose fingerprint is 70F8 1545 7515 F45C 3441 2FA6 BEFA 817E EB70 BEBE

To claim this, I am signing this object:

@pranavgarg
pranavgarg / flatten.py
Created October 28, 2016 18:34
flatten a list
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
assert [i for i in flatten([1,2,[3,4]])] == [1,2,3,4]
@pranavgarg
pranavgarg / skip_every_3rd_element.py
Last active October 14, 2016 20:29
josepheus problem - delete every 3rd element until the list goes empty
a = ['1','2','3','4','5','6','7','8','9']
def josepheus(int_list, skip):
skip = skip - 1 #list starts with 0 index
idx = 0
output = []
while len(int_list)>0:
idx = (skip+idx)%len(int_list)
k = int_list.pop(idx)
output.append(k)
@pranavgarg
pranavgarg / linklist.py
Created October 14, 2016 16:10
Python Reverse Link List
@pranavgarg
pranavgarg / docker_cheatsheet
Last active October 15, 2015 14:40
Docker CheatSheet
##INTRO
Docker is based on lxc (Linux Containers) which helps provide virtualization on the host OS.
Its lightweight and ease of use allows it to succeed over VMware virtualization.
##Useful commands
1. **docker ps** - Lists containers.
2. **docker logs** - Shows us the standard output of a container.
3. **docker stop** - Stops running containers.
4. **docker images** - Lists all the docker images
@pranavgarg
pranavgarg / mount a new volume
Last active August 29, 2015 14:24
Attach a new volume to ec2, ensuring a service runs on server restart and access instance metadata
# lists the volumes
$> lsblk
# this lists all the volumes
xvda1 202:1 0 8G 0 disk /
xvdb 202:16 0 400G 0 disk /mnt
$> free -s /dev/xvdb
#would return data is its not yet formatted and doesn't have any data
#otherwise would return the block and storage type ext4
@pranavgarg
pranavgarg / meteor_best_practices
Created June 23, 2015 15:40
Meteor Best Practices
###
Install: meteor add audit-argument-checks
Description: This package will do type checking for the arguments.
E.g. Publish function sending data back based on the username
###
Meteor.publish({
"posts": (currentUserName) ->
check currentUserName, String #this line does the typechecking. If missed following error thrown Exception from sub posts id .. Did not check() all arguments during publisher
Posts.find({author: currentUserName}).fields({})
})