Skip to content

Instantly share code, notes, and snippets.

docker run --rm -P -p 127.0.0.1:5432:5432 -e POSTGRES_PASSWORD="1234" --name pgs postgres

pgcli "postgresql://postgres:1234@localhost:5432"
def find_duplicate(folder):
list_of_files = list(os.walk(folder))[0][-1]
duplicate_dict = dict()
hash_mapping = dict()
for file_name in list_of_files:
with open(file_name, 'r') as file:
file_hash = hash(file.read())
file_path = get_file_path(file_name)
hash_mapping[file_path] = file_hash
@iamneha
iamneha / description.md
Last active March 3, 2020 22:03
Word Count Coding Challenge
def count_words(input_file="data.txt", output_file="result.txt"):
    word_occurrences = dict()
    with open(input_file) as file:
        for word in file.read().lower().split():
            if word.isalpha():
                tmp_word = word
            else:
 tmp_word = ''.join(
from kubernetes import client, config
config.load_kube_config()
api=client.CoreV1Api()
pods = api.list_pod_for_all_namespaces()

for i in pods.items:
    print("%s: %s", i.metadata.namespace, i.metadata.name)
    
default: hello-minikube-7c77b68cff-vp9qn
@iamneha
iamneha / q.md
Created May 29, 2018 05:29
SQL command to run on CSV files
q "select distinct(Treenode) from tree.csv" -d ',' -H
sed -i "" 's/BLANKET/blanket/' tree.csv
q "select count(distinct(Treenode)) from tree.csv" -d ',' -H
q "select Treenode, count(*) from tree.csv group by Treenode order by count(*)" -d ',' -H
q "select Treenode, count(*) from tree.csv group by Treenode" -d ',' -H
q "select * from first.csv INNER JOIN second.csv on column1 = column2" -d ',' -H > update.csv
q "select * from first.csv order by column1 ASC" -d ',' -H > result.csv

Dimond problem

     A
   /   \
  B     C
   \   /
     D

Multiple inheritance without super

In [1]: class Person:
   ...:     def __init__(self, name, age):
   ...:         self.name = name
   ...:         self.age = age
   ...:
   ...:     # a class method to create a Person object by birth year.
   ...:     @classmethod
   ...:     def fromBirthYear(cls, name, year):
 ...: return cls(name, date.today().year - year)

Lambdas

In [1]: list1 = [6, 3, 7, 19, 34, 67, 10]

In [1]: list2 = [98, 45, 67, 2, 100, 34]

In [2]: data = zip(list1, list2)

In [2]: data.sort()
In [1]: def square(n):
   ...:     for i in range(n):
   ...:         return i*i
   ...:

In [2]: square(5)
Out[2]: 0

In [3]: def square(n):
In [1]: key = 'Pyladies'

In [2]: type(key)
Out[2]: str

In [3]: _iter = iter(key)

In [4]: type(_iter)
Out[4]: iterator