Skip to content

Instantly share code, notes, and snippets.

@antoncohen
antoncohen / fhash.py
Created October 24, 2016 00:52
fhash.py
#!/usr/bin/env python
"""Hash files, like md5sum or shasum, only faster. Works with all
hash functions Python's hashlib supports."""
from __future__ import print_function
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from hashlib import algorithms_available
from hashlib import new as new_hash
from io import open
@antoncohen
antoncohen / sleep_lots_max.py
Created October 24, 2016 00:51
sleep_lots_max.py
from multiprocessing import Pool, cpu_count
from random import randint
from time import sleep
class RandSleep(object):
"""multiprocessing.Pool.imap* needs to pickle the function it send to the
processes. It can't pickle functions or instance methods. But oddly it
can pickle instances of custom classes. So write the function as a
callable class."""
@antoncohen
antoncohen / sleep_lots.py
Created October 24, 2016 00:51
sleep_lots.py
from multiprocessing.dummy import Pool as ThreadPool
from random import randint
from time import sleep
def increasing_sleeps():
"""Pointless function to show using your own generator"""
for i in xrange(10):
yield i
@antoncohen
antoncohen / keybase.md
Created March 3, 2015 04:29
keybase.md

Keybase proof

I hereby claim:

  • I am antoncohen on github.
  • I am antoncohen (https://keybase.io/antoncohen) on keybase.
  • I have a public key whose fingerprint is 5FE2 8B02 08DD 85F8 18C8 E6C9 51D1 1262 B610 78BE

To claim this, I am signing this object:

@antoncohen
antoncohen / lb.pp
Created June 4, 2013 06:36
Roles example for load balancer
class role::lb {
class { 'nginx': }
class { 'memcached':
max_connections => 4096
}
}
@antoncohen
antoncohen / roles.yaml
Created June 4, 2013 06:30
Example of roles in Hiera
---
roles:
- 'role::base'
- 'role::lb'
memcached::max_memory: 64
nginx::worker_processes: %{::processorcount}
@antoncohen
antoncohen / init.pp
Created June 4, 2013 06:25
init.pp for the role class
class role {
include stdlib
$roles = hiera_array('roles')
# Require base first in case it is needed by other classes
if member($roles, 'role::base') {
require role::base
}
node default {
include role
}
@antoncohen
antoncohen / 99bottles.coffee
Created September 6, 2011 01:48
99 Bottles of Beer in CoffeeScript
#!/usr/bin/env coffee
print = (line) -> process.stdout.write line + '\n'
for num in [99..1]
if num > 1
print "#{num} bottles of beer on the wall, #{num} bottles of beer."
if num-1 > 1
print "Take one down and pass it around, #{num-1} bottles of beer on the wall.\n"
else