Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
@dhilst
dhilst / diskindex.py
Last active August 29, 2017 15:22
Print the top 20 folder that are using more space.
#!/usr/bin/env python3
# Copyright 2017 Daniel Hilst Selli
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@dhilst
dhilst / injector.py
Created September 28, 2017 17:30
Monkey patching injector decorators.
# Copyright 2017 Daniel Hilst Selli, <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@dhilst
dhilst / mokeyproxy.py
Last active September 29, 2017 14:41
Monkey patch functions and methods proxy.
from functools import wraps
from operator import attrgetter
from importlib import import_module
from collections import Counter
import re
def packages(pfqn):
dots_n = len(pfqn.split('.'))
for i in range(dots_n):
yield pfqn.rsplit('.', i)[0]
http://www.detran.sp.gov.br/wps/portal/portaldetran/cidadao/veiculos/fichaservico/transferenciaPropriedadeMesmoMunicipio
@dhilst
dhilst / getmetadata.py
Created November 3, 2017 19:08
Xen grab vm metadata
#!/usr/bin/env python
import XenAPI
from getpass import getpass
host = 'https://localhost'
user = 'root'
password = getpass('Password: ')
session = XenAPI.Session(host)
py3 pass
syntax on
set background=dark
set laststatus=2
set smartindent
set autoindent
set modeline
set nocompatible
" execute pathogen#infect()
py3 pass
syntax on
set background=dark
set laststatus=2
set smartindent
set autoindent
set modeline
set nocompatible
" execute pathogen#infect()
@dhilst
dhilst / foo.py
Last active December 6, 2017 03:12
Python worker pool that doesn't waste memory.
#!/usr/bin/env python3
import sys
import multiprocessing as mp
import subprocess as sp
import shlex as sh
from itertools import cycle
def sh(cmd):
return sp.Popen(cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr).wait()
py3 pass
syntax on
set background=dark
set laststatus=2
set smartindent
set autoindent
set modeline
set nocompatible
" execute pathogen#infect()
@dhilst
dhilst / foo.py
Last active February 4, 2018 05:12
playing with lazy class properties using jinja recursive templates
from jinja2 import Template
from jinja2.runtime import Context
def merge_vars(obj):
d = {}
for o in reversed(obj.mro()):
d.update(vars(o))
return d