Skip to content

Instantly share code, notes, and snippets.

View graipher's full-sized avatar

Andreas Weiden graipher

View GitHub Profile
from string import ascii_letters
from itertools import cycle
import random
from copy import deepcopy
from functools import reduce
import numpy as np
from functools import partial
import timeit
import matplotlib.pyplot as plt
import pandas as pd
#!/usr/bin/env python3
from functools import partial
import timeit
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from itertools import starmap, count
from string import digits
from random import choices
@graipher
graipher / gen_expression.py
Last active April 18, 2018 13:07
Generator expression
sum(num % i == 0 for i in range(1, int(sqrt(num)) + 1))
# Equivalent to:
sum_ = 0
for i in range(1, int(sqrt(num)) + 1):
if num % i == 0:
sum_ += 1
# Inner expression:
This file has been truncated, but you can view the full file.
100000 100000
1 31789 82245
0 48604 88346
1 16301 94014
1 67473 79175
1 5046 68407
1 15554 31743
0 27007 58353
1 8603 83722
1 5326 70222
@graipher
graipher / TChain_contextmanager.py
Last active March 19, 2017 12:20
TChain context manager
import ROOT
class TChain(ROOT.TChain):
"""
A contextmanager for TChain, which loads from a file directly.
Can disable all branches except the needed branches (default: all enabled).
"""
def __init__(self, tree_name, file_names=None, active_branches=None):
super(TChain, self).__init__(tree_name)
@graipher
graipher / TTree_contextmanagers.py
Last active March 29, 2017 14:36
Contextmanagers for ROOT.TTree
import ROOT
import contextlib2
class TTree:
"""
A contextmanager for TTree, which loads from a file directly.
Can disable all branches except the needed branches (default: all enabled).
"""
def __init__(self, tree_name, file_name, active_branches=None):
@graipher
graipher / argparser_comp.py
Last active December 6, 2016 09:14
Argparse vs docopt
"""SMTP user checker.
Usage:
argparser_comp.py SERVER USERNAMES [(-p <p>| --port=<p>)]
argparser_comp.py (-h | --help)
Options:
-h --help Show this screen.
-p <p> --port=<p> SMTP port of server [default: 25].