Skip to content

Instantly share code, notes, and snippets.

View mindey's full-sized avatar
🚀
Working from Earth...

Mindey mindey

🚀
Working from Earth...
View GitHub Profile
@mindey
mindey / baserow.py
Last active February 23, 2023 18:59
# 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
# 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.
# 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
### 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]
### 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]
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)
import pandas
import xarray
ds = xarray.Dataset(
{'x': ([None], [1,2,3] ),
'y': ([None], [4,5,6] )},
)
# *is equivalent to*
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)
# 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'],
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)