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
# Author: Mindey | |
# Basic Baserow.io API Wrapper. | |
import os, requests, getpass | |
import urllib.parse | |
import tqdm | |
# Auth: | |
try: | |
from envars import API_BASE, API_TOKEN |
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
# Message to the future, that I wrote to the sattelite KEO ( https://en.wikipedia.org/wiki/KEO ) | |
# I sent it before 2006-06-15). Perhaps it has a few mistakes, but anyway, here is what I wrote: | |
Hello, the intelligent entities of the future. | |
This is Inyuki from Japan, from the past. | |
How were you doing all the time from the year 2006 up to now? How are | |
you doing now? What problems you are having? It is interesting to | |
know. |
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
# inspired by: | |
# https://www.halfbakery.com/idea/Mirrored_20Mouse | |
import pyautogui | |
width, height = pyautogui.size() | |
def mirror(duration=0.0): | |
current = pyautogui.position() | |
new_x = width - current.x |
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
### For finding schema | |
def schematize(obj): | |
''' | |
Get schema of nested JSON, assuming first item in lists. | |
''' | |
if isinstance(obj, dict): | |
return {k: schematize(v) for k, v in obj.items()} | |
elif isinstance(obj, list): | |
return [schematize(elem) for elem in obj][:1] |
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
### For finding schema | |
def schematize(obj): | |
''' | |
Get schema of nested JSON, assuming first item in lists. | |
''' | |
if isinstance(obj, dict): | |
return {k: schematize(v) for k, v in obj.items()} | |
elif isinstance(obj, list): | |
return [schematize(elem) for elem in obj][:1] |
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 os | |
import collections | |
import langdetect | |
LANGUAGE_CODES = os.listdir(langdetect.PROFILES_DIRECTORY) | |
def detect_language(text, max_length=2): | |
""" Make sure we return N-letter keys for languages""" | |
shorter = {'zh-cn': 'cn', 'zh-tw': 'zh'} | |
code = langdetect.detect(text) |
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 pandas | |
import xarray | |
ds = xarray.Dataset( | |
{'x': ([None], [1,2,3] ), | |
'y': ([None], [4,5,6] )}, | |
) | |
# *is equivalent to* |
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 pandas | |
from dask import dataframe | |
from dask.diagnostics import ProgressBar | |
def parallel_apply(df, func, progress=True, chunkrows=100, scheduler_address=None, *args, **kwargs): | |
if scheduler_address: | |
from dask.distributed import Client | |
client = Client(scheduler_address) | |
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
# Practically, it's useful if we have complex observations (rows) and variables (columns): | |
df = pandas.DataFrame( | |
data=pandas.np.array( | |
[[1,2,3,4,5], | |
[6,7,8,9,10], | |
[11,12,13,14,15]]).T, | |
index=pandas.MultiIndex.from_arrays( | |
[['x','x','x','y','z'], | |
['a','a','b','b','c'], |
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 pandas | |
import multiprocessing | |
def apply_parallel(grouped_df, func): | |
with multiprocessing.Pool(multiprocessing.cpu_count()) as p: | |
ret_list = p.map(func, [group for name, group in grouped_df]) | |
return pandas.concat(ret_list) |
NewerOlder