This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__'): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cmd | |
import random | |
import re | |
from hangword import words | |
class Hang(cmd.Cmd): | |
'''Command Line Hangman |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hangwords = \ | |
'''abruptly | |
absurd | |
abyss | |
affix | |
askew | |
avenue | |
awkward | |
axiom | |
azure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]}'''} |
OlderNewer