Skip to content

Instantly share code, notes, and snippets.

View shawnbutts's full-sized avatar

Shawn Butts shawnbutts

View GitHub Profile
@shawnbutts
shawnbutts / gist:3342599
Created August 13, 2012 17:24
find files larger than 2GB in and below current directory
find . -type f -size +2000000k -exec ls -lh {} \; | awk '{ {for (i = 9; i <= NF; i++)printf("%s ", $i);} print ": " $5 }'
@shawnbutts
shawnbutts / gist:3675700
Created September 8, 2012 14:58
dedupe mbox file
cat mail.mbox | formail -D 100000000 idcache -s >> dedupe.mbox
@shawnbutts
shawnbutts / bytesto.py
Created October 17, 2012 17:33
bytes to to mb, gb, etc in python
def bytesto(bytes, to, bsize=1024):
"""convert bytes to megabytes, etc.
sample code:
print('mb= ' + str(bytesto(314575262000000, 'm')))
sample output:
mb= 300002347.946
"""
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 }
@shawnbutts
shawnbutts / authenticator.py
Last active December 20, 2015 09:19
Goal: Securely authenticate a user without storing their username and password in the database. Also, the authentication records and user records must be separated and unconnect-able without a successful authentication. This would permit a layer of obfuscation between authentication and account details in the database. i.e. The connection betwee…
#!/usr/bin/env python
# encoding: utf-8
"""
Copyright (c) 2013, Shawn Butts. All rights reserved.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
@shawnbutts
shawnbutts / gist:8221960
Created January 2, 2014 16:35
python: generate a password hash for /etc/shadow
import crypt
plaintext_password = 'txetnialp'
salt = crypt.mksalt()
shaadow_password = crypt.crypt(plaintext_password, '$6${0}'.format(salt))
@shawnbutts
shawnbutts / gist:8339027
Last active January 2, 2016 17:49
flush cache and swap on linux
time sync; echo 3 > /proc/sys/vm/drop_caches
time swapoff -a
swapon -a
@shawnbutts
shawnbutts / gist:c75b3fa8839274c948d1
Last active August 29, 2015 14:01
EC2_INSTANCE_TYPES
EC2_INSTANCE_TYPES = {
'c3.2xlarge': {'ebs': {'optimized': True},
'ephemeral': {'number': '2',
'size': '80',
'type': 'SSD'},
'network': {'enhanced': True,
'performance': 'High'},
'processor': {'aes-ni': True,
'avx': True,
'speed': '2.8',
def get_aws_account_id():
conn_iam = boto.connect_iam()
ret = conn_iam.get_all_users()['list_users_response']['list_users_result']['users'][0]['arn'].split(':')[4]
return(ret)
@shawnbutts
shawnbutts / gist:9451a2b6293d6ed7d626
Created May 30, 2014 13:29
ssh connection test
time ssh <SERVER> 'a=1; while true; do echo $a `date` ; let a=a+1; sleep 1; done'
@shawnbutts
shawnbutts / testserver.py
Created October 9, 2015 14:25
@rochacbruno test webserver (damn handy)
#!/usr/bin/python
"""
Save this file as server.py
>>> python server.py 0.0.0.0 8001
serving on 0.0.0.0:8001
or simply
>>> python server.py