Skip to content

Instantly share code, notes, and snippets.

@tavakyan
tavakyan / hr-python-xml-xml2.py
Created November 5, 2016 06:54
hr-python-xml-xml2
from xml.etree import ElementTree
def max_tree_depth(root):
if root is None or len(root) == 0:
return 0
return max([1 + max_tree_depth(child) for child in root])
@tavakyan
tavakyan / py-hr-iter-combo.py
Created November 5, 2016 08:15
py-hr-iter-combo.py
from itertools import combinations
S, N = input('').split(' ')
N = int(N)
def words_from_combos(s, n):
# Get list of n dimensional combos
combos = list(combinations(s, n))
from itertools import groupby
# Get input and convert it to list of integers
list_ints = [int(i) for i in input('')]
# Group ints into seperate arrays, create tuple of length, value
len_val_tuples = [((len(list(g))), k) for k, g in groupby(list_ints)]
for tup in len_val_tuples:
from itertools import combinations
# Create ranges from X Y Z inputs
X = range(int(input(''))+1)
Y = range(int(input(''))+1)
Z = range(int(input(''))+1)
N = int(input(''))
# Get length of list
N = int(input(''))
# Convert string to list of letters & casted as integers
INTS = (int(letter) for letter in input('').split(' '))
# Remove doubles by converting list of integers to set
SET_INTS = set(INTS)
# Convert back to list and sort
#!/usr/local/bin/python3
import wikipedia
if __name__ == '__main__':
# Python Wikipedia article name
article_name = "Python (Programming Language)"
# Print first sentence from summary
summary = wikipedia.summary(article_name)
summary_first_sent = summary.split('.')[0]
from os import path
from wordcloud import WordCloud
d = path.dirname(__file__)
# Read the whole text.
text = open(path.join(d, 'python.txt')).read()
# Generate a word cloud image
wordcloud = WordCloud().generate(text)
import sys
import crypt
DICT_FILE = '/usr/share/dict/words'
def main(arg):
salt = '$6$Mqe5XrQt$'
hashed_pass = arg
with open(DICT_FILE) as f:
for line in reversed(f.readlines()):
if crypt.crypt(hashed_pass, salt) == line:
#! /usr/bin/env python3
import sys
MEM_INFO_FILE = '/proc/meminfo'
MEM_INFO_DELIM = ':'
def main(args):
mem_dict = dict()
# Build mem_dict from file
@tavakyan
tavakyan / git-cheat-list.md
Created February 17, 2017 20:14
Git cheat list

Git cheat list

  • name of the current banch and nothing else (for automation)

    git rev-parse --abbrev-ref HEAD
    
  • all commits that your branch have that are not yet in master

    git log master..<HERE_COMES_YOUR_BRANCH_NAME>