Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Working from Earth...

Mindey mindey

🚀
Working from Earth...
View GitHub Profile
View KEO-message.txt
# 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.
View mirror-mouse.py
# 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
View notebook_finder.py
# according to http://jdfreder-notebook.readthedocs.org/en/docs/examples/Notebook/Importing%20Notebooks.html
import io, os, sys, types
from IPython import get_ipython
from IPython.nbformat import current
from IPython.core.interactiveshell import InteractiveShell
def find_notebook(fullname, path=None):
"""find a notebook, given its fully qualified name and an optional path
This turns "foo.bar" into "foo/bar.ipynb"
View schematize.py
### 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]
View schematize.py
### 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]
View md_language_splitter_autodetect.py
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)
View xarray_fundamentals.py
import pandas
import xarray
ds = xarray.Dataset(
{'x': ([None], [1,2,3] ),
'y': ([None], [4,5,6] )},
)
# *is equivalent to*
View grouped_apply.py
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)
View parallelize_df.py
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)
View complex_frames.py
# 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'],