Skip to content

Instantly share code, notes, and snippets.

@hmml
hmml / lxml.sh
Last active December 10, 2020 05:39
Install lxml on Mac OS X 10.7 (Python 2.7.1)
#!/bin/bash
#
# Install lxml on Mac OS X 10.7. It might work for 10.8 as well.
#
LXML_LIB=libxml2-2.9.0
LXML_ARCHIVE=libxml2-2.9.0.tar.gz
# Start install, it's going to fail...
STATIC_DEPS=true pip install lxml
@hmml
hmml / joyohjoy.py
Last active August 21, 2016 19:01
Download meta information about all posts from http://thejoysofcode.com and http://devopsreactions.tumblr.com to JSON files.
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Download meta information from:
# - http://thejoysofcode.com
# - http://devopsreactions.tumblr.com
#
# Script downloads title, link and image url for each post. First run will
# extract all posts. Following executions just update db. Posts are stored
# in JSON format in 'posts-joys.json' and 'posts-devops.json'.
@hmml
hmml / benford.py
Last active January 1, 2016 13:29
Beford's law in action.
import os, sys, time
def print_stats(buckets):
# source: http://mathworld.wolfram.com/BenfordsLaw.html
benford = (0.30103, 0.176091, 0.124939, 0.09691, 0.0791812, 0.0669468, 0.0579919, 0.0511525, 0.0457575)
try:
vals = [float(buckets[x])/sum(buckets) for x in range(len(buckets))]
print 'Digit\tResult\tBenford\tDifference'
for i, val in enumerate(vals):
error = (benford[i] - vals[i])
@hmml
hmml / cleanpath.py
Created January 15, 2014 09:28
Inspect $PATH environment variable for duplicates and invalid paths. Prints cleaned version afterwards.
#!/usr/bin/env python
import os
paths = os.getenv('PATH').split(os.pathsep)
cleaned_paths = []
for path in paths:
if path in cleaned_paths:
print 'Duplicated:', path
continue
if not os.path.exists(path):
print 'Doesn\'t exist: ', path
@hmml
hmml / storefronts.py
Created February 11, 2014 20:00
List of Storefront IDs (http://www.apple.com/itunes/affiliates/resources/documentation/linking-to-the-itunes-music-store.html#appendix) is not complete. Here's the full list of all 155 countries (2014-02-11) along with ids. Everything wrapped in tasty python dictionary. List produced with API from https://appfigures.com.
appStores = {
"Albania": 143575,
"Algeria": 143563,
"Angola": 143564,
"Anguilla": 143538,
"Antigua And Barbuda": 143540,
"Argentina": 143505,
"Armenia": 143524,
"Australia": 143460,
"Austria": 143445,