Skip to content

Instantly share code, notes, and snippets.

View iLoveTux's full-sized avatar

Clifford Bressette iLoveTux

View GitHub Profile
@iLoveTux
iLoveTux / fizzbuzz.py
Created August 29, 2016 21:29
fizz buzz implementation in Python 3
from functools import partial
# Algorithm needs to avoid newlines being appended to output
pr = partial(print, end="")
for n in range(1, 101):
if n%3 == 0:
pr("Fizz")
if n%5 == 0:
pr("Buzz")
@iLoveTux
iLoveTux / setup.py
Created February 9, 2016 22:16
setuptools setup.py minimal example
"""
Minimal setuptools setup.py example
Useful links:
https://pythonhosted.org/setuptools/setuptools.html#command-reference
https://pythonhosted.org/setuptools/setuptools.html#basic-use
https://pythonhosted.org/setuptools/setuptools.html#new-and-changed-setup-keywords
https://pypi.python.org/pypi?%3Aaction=list_classifiers
"""
@iLoveTux
iLoveTux / files-by-commits.sh
Created February 2, 2016 19:13
list files by number of commits in repository
git log --name-only --decorate=short --sparse --format=oneline | grep "/" | grep -v " " > /tmp/files-changed.txt
cat /tmp/files-changed.txt | sort | uniq -c > /tmp/changes-by-file.txt
cat /tmp/changes-by-file.txt | sort -r
@iLoveTux
iLoveTux / template.py
Created September 23, 2015 17:59
Extremely simple Python Templating Engine
"""
# template.py
Extremely simple Python Templating Engine
This is a no-frills templating engine written in Python. I chose to
write this when I decided that I wanted something that was extremely
simple templating system and even str.format seemed like overkill.
You can use either a string as a template, or a file. NOTE, however,
@iLoveTux
iLoveTux / gist:ad9e82fee079a356621f
Created June 15, 2015 20:24
remove all docker images
$ sudo docker images | awk '{ print $3 }' | grep -v IMAGE | xargs -L 1 sudo docker rmi
@iLoveTux
iLoveTux / gist:7ff9e625d439a32da4d1
Last active August 29, 2015 14:22
Docker - One liner to remove all non-running containers
# The following command will cycle through all containers and attempt to remove it.
# NOTE: This will fail on running containers (you will get an error message, but it
# will just move on to the next one)
$ sudo docker ps -a | grep -v CONTAINER | awk '{ print $1 }' | xargs -L 1 sudo docker rm
@iLoveTux
iLoveTux / gist:c0c6216dca943876da6d
Created May 18, 2015 22:53
permit insecure connections with urllib2.urlopen in python 2.7.x >= 2.7.9
# Because migrating to python 2.7.9 requires me to update my code (or ask my clients to add cafiles to their trust store
# [which some people don't know how to do]), I found a way to explicitly allow insecure connections (ie. without hostname
# verification) using urllib2.urlopen()
#
# This gist basically involves creating an ssl.SSLContext() with some options which disable hostname verification
# This allows you to, for instance, add a parameter to a function which disables hostname verification.
import ssl
import urllib2
import logging
@iLoveTux
iLoveTux / gist:290457feb385b5788f48
Created May 17, 2015 12:46
(Linux) Where is my disk space being used
sudo du -h / | cut --delimiter $'\t' -f 1,2 | grep G$'\t'