Skip to content

Instantly share code, notes, and snippets.

View Proteusiq's full-sized avatar

Prayson Wilfred Daniel Proteusiq

View GitHub Profile
@Proteusiq
Proteusiq / emojipy.py
Created July 11, 2018 12:55
emojipy.py
import re
from collections import Counter
# eyes [nose] mouth | mouth [nose] eyes pattern
emoticons = r"(?:[<>]?[:;=8][\-o\*\']?[\)\]\(\[dDpP/\:\}\{@\|\\]|[\)\]\(\[dDpP/\:\}\{@\|\\][\-o\*\']?[:;=8][<>]?)"
emoticon_re = re.compile(emoticons, re.VERBOSE | re.I | re.UNICODE)
@Proteusiq
Proteusiq / caesarcipher.py
Created July 11, 2018 20:32
caesarcipher.py
import string
from collections import deque
letters = string.ascii_lowercase
def pass_creator(string='',rotation=0):
'''
Takes in the string and rotate words
n steps +n, to get back to original
use -n
@Proteusiq
Proteusiq / get_imports.py
Last active July 13, 2018 08:33
get_imports.py
def get_imports():
import types
'''
returns a generator of packages and version numbers used in the script
use. print(set(get_imports())) to show the packages. packages that are
import directly e.g. from nltk.stem import SnowballStemmer won't be found
'''
for name, val in globals().items():
if isinstance(val, types.ModuleType):
if hasattr(val, '__version__'):
@Proteusiq
Proteusiq / ptimer.py
Created September 17, 2018 10:16
ptimer
from datetime import datetime
class MyImportError(Exception):
'''Error when humanfriendly module not installed'''
def __init__(self,original_exception,msg):
super(MyImportError, self).__init__(f'\n\n{original_exception} {msg}')
self.original_exception = original_exception
msg = ('\nInstall using conda or pip:'
'\n>pip install humanfriendly'
@Proteusiq
Proteusiq / dk_postal.py
Last active October 4, 2018 11:36
Get Denmark Postal Codes from Dawa as a Pandas’ DataFrame
from collections import defaultdict
import requests
import pandas as pd
def get_postal(only_postal=True):
'''
Simple function that returns DK postal codes from DAWA. If only_post is false,
postal code name, kommune, latitude and longitude are returned
how to use:
@Proteusiq
Proteusiq / thread_quoters.py
Created October 19, 2018 16:56
thread_quoters.py
from concurrent.futures import ThreadPoolExecutor
import random,time
from bs4 import BeautifulSoup as bs
import requests
URL = 'http://quotesondesign.com/wp-json/posts'
def quote_stream(sleep=5):
'''
Quoter streamer
@Proteusiq
Proteusiq / useful_pandas_snippets.py
Created November 8, 2018 07:22 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
# List unique values in a DataFrame column
# h/t @makmanalp for the updated syntax!
df['Column Name'].unique()
# For each unique value in a DataFrame column, get a frequency count
df['Column Name'].value_counts()
# Convert Series datatype to numeric (will error if column has non-numeric values)
# h/t @makmanalp
pd.to_numeric(df['Column Name'])
@Proteusiq
Proteusiq / hangman2.py
Created December 7, 2018 15:50
hangman2.py
import cmd
import random
import re
from hangword import words
class Hang(cmd.Cmd):
'''Command Line Hangman
@Proteusiq
Proteusiq / hangword.py
Created December 7, 2018 15:51
hangword.py
hangwords = \
'''abruptly
absurd
abyss
affix
askew
avenue
awkward
axiom
azure
@Proteusiq
Proteusiq / speedcontrol.py
Created January 2, 2019 13:47
speedcontrol.py
from datetime import datetime
import requests
url = 'https://www.fartkontrol.nu/ajax.php'
dawa_url = 'https://dawa.aws.dk/postnumre/reverse'
data = {'json':'''{"action":"controls_fetch","uid":null,"app":0,"my_coords":{"Ya":0,"Za":0,"a c":0},"types":["1","-1","-1",null,"1"]}'''}