Skip to content

Instantly share code, notes, and snippets.

View kaidokert's full-sized avatar

Kaido Kert kaidokert

View GitHub Profile
@kaidokert
kaidokert / wall_of_fame.py
Created August 2, 2015 16:45
Simple page scraping with html5lib
import html5lib
import requests
def get_packages():
page = 'https://python3wos.appspot.com/'
doc = html5lib.parse(requests.get(page).content,
namespaceHTMLElements=False)
table = doc.find('body/div/div/table/tbody')
if not table:
@kaidokert
kaidokert / pippi.py
Last active August 29, 2015 14:26
Use pip to find all available and matching versions of a package
import logging
import pip
log = logging.getLogger(__name__)
def check_package(package):
requirement = pip.req.InstallRequirement.from_line(package)
@kaidokert
kaidokert / configs.py
Last active August 29, 2015 14:25
Everyones favorite config formats
# pip install pytoml pyaml
import pytoml
import yaml
import json
# no ConfigParser here
testdict={'copterz': 'lol',
'nest': {'this': 'that'},
'nestnest': {'hive': { 'bees' : 3, 'ants' : -1} , 'house' : 'frogs' },
'mah' : ['dogs','catz'],
@kaidokert
kaidokert / pint_args_decorator.py
Last active August 29, 2015 14:24
Force pint args to be of particular dimensionality
import pint
import functools
import itertools
ureg = pint.UnitRegistry()
def require_args(*args):
units = args
@kaidokert
kaidokert / cloud.providers
Created May 8, 2015 19:07
Minimal salt cloud.providers file to configure ec2 access
my-ec2-config:
id: GKTADJGHEIQSXMKKRBJ08H
key: askdjghsdfjkghWupUjasdflkdfklgjsdfjajkghs
keyname: default
private_key: /root/default.pem
provider: ec2
# full file here : http://docs.saltstack.com/en/latest/ref/clouds/all/salt.cloud.clouds.ec2.html
# if any of the vars is missing, you'll get
# [WARNING ] The cloud driver, 'ec2', configured under the 'my-ec2-config' cloud provider alias was not loaded since 'ec2.get_configured_provider()' could not be found. Removing it from the available providers list
@kaidokert
kaidokert / django-min.py
Created May 3, 2015 19:20
Minimal django to serve a html page
import sys
from django.conf.urls import url
from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse
from django.conf import settings
settings.configure(
DEBUG='on',
ROOT_URLCONF=__name__,
)