Skip to content

Instantly share code, notes, and snippets.

@xtream1101
xtream1101 / multi_try_except_flat.py
Last active June 20, 2017 20:56
Python multiple Try/except flat design
# I know dict's have `.get()`, this example was made to break if the key is not
# there to show the use of multiple try/except's
# Yes I know that having the except and else on 1 line each does not fit with PEP8 standards.
# But when you have many of them it helps reduce the size of the file and is no harder to read
data = {'some_key': 'key value'}
key_data = None
for _ in range(1):
try:
key_data = data['someKey']
@xtream1101
xtream1101 / keybase.md
Created September 1, 2016 21:59
keybase.md

Keybase proof

I hereby claim:

  • I am xtream1101 on github.
  • I am xtream1101 (https://keybase.io/xtream1101) on keybase.
  • I have a public key whose fingerprint is 061A BAAC 9D1B E6EB 89F5 26AF 1498 1397 2F25 7A6D

To claim this, I am signing this object:

@xtream1101
xtream1101 / aliases.sh
Last active June 30, 2016 18:53
Python virtual envs bash commands
# Add this to your .bashrc or .bash_profile file to use
#
# This gives you access to create and switch between different python envs
# To create a venv called 'foo' just type:
# `pyve foo`
# This will create a python 3 venv and activate it as well
# If you are in a different venv and want to switch to foo, enter the same thing
pyve(){
env_name=$1
activate_file=~/Virtualenvs/py3/$env_name/bin/activate
@xtream1101
xtream1101 / csv_to_dict_with_unicode.py
Created May 6, 2016 14:25
csv to dict with unicode chars
import sys
import csv
from pprint import pprint
row_list = []
with open(sys.argv[1], 'r', encoding='ISO-8859-1') as f:
reader = csv.DictReader(f)
for row in reader:
# Make all keys lower case since we do not know the case used
row = dict((k.lower(), v) for k, v in row.items())
@xtream1101
xtream1101 / url_regex.py
Last active May 6, 2016 14:08
URL Regex
import re
from pprint import pprint
"""
TODO:
Support PORT numbers in the url
Support IP's as domains. If IP, it cannot have a subdomain or a tld
"""
"""