Skip to content

Instantly share code, notes, and snippets.

View khaeru's full-sized avatar

Paul Natsuo Kishimoto khaeru

View GitHub Profile
@khaeru
khaeru / pandas_parquet_in_blob.py
Last active March 13, 2024 15:36
Store pandas data in an SQL(ite) BLOB field using the Parquet format
"""Store pandas data in an SQL(ite) BLOB field using the Parquet format.
© 2024 Paul Natsuo Kishimoto <mail@paul.kishimoto.name>.
Licensed under the GNU GPL v3 https://www.gnu.org/licenses/gpl-3.0.en.html.
"""
import sqlite3
from dataclasses import dataclass
from io import BytesIO
@khaeru
khaeru / variables-AR6.txt
Created May 13, 2020 12:49
Transport-related variables in the IPCC AR5 WGIII data template
Capacity|Transportation|Aviation|Freight
Capacity|Transportation|Aviation|Passenger
Capacity|Transportation|Maritime|Freight
Capacity|Transportation|Maritime|Passenger
Capacity|Transportation|Rail|Freight
Capacity|Transportation|Rail|Passenger
Capacity|Transportation|Road|Freight
Capacity|Transportation|Road|Passenger
Discount rate|Economy
Discount rate|Electricity
@khaeru
khaeru / inline.py
Last active October 14, 2019 18:36
Copy inline documentation to Sphinx source tree
"""Crude Sphinx extension for inline documentation.
© 2019 Paul Natsuo Kishimoto <mail@paul.kishimoto.name>
Licensed under the GNU GPLv3: https://www.gnu.org/licenses/gpl-3.0.html
Star: https://gist.github.com/khaeru/3185679f4dd83b16a0648f6036fb000e
Enable by adding to conf.py::
sys.path.append('path/to/this/file')
extensions.append('inline')
@khaeru
khaeru / dag_reporting.py
Last active February 20, 2019 15:36
Reporting using a directed acyclic graph (DAG)
"""Reporting using a directed acyclic graph (DAG).
2019-01-24 Paul Natsuo Kishimoto <mail@paul.kishimoto.name>
This is a demo of one possible pattern for a reporting architecture for ixmp
/MESSAGE. It uses a directed acyclic graph (DAG) where the nodes are operations
and edges are data. Calling get(…) on the graph causes a node's output, and all
its dependencies, to be retrieved.
This is implemented using dask:
@khaeru
khaeru / geom_partial.py
Created June 26, 2018 16:18
Like partial(), for plotnine geoms
def geom_partial(name, aes, **geom_kwargs):
"""Like partial(), for plotnine geoms.
*name* refers to a geom, e.g. 'point' for p9.geom_point. *geom_kwargs* are
optional keyword arguments for the geom. *aes* is a dict() with keys that
match the geom's aesthetics, and values that are format strings.
Returns a callable object. When called, the arguments are passed to
str.format() for each entry in *aes*, and a plotnine geom is returned with
the resulting aesthetics and kwargs.
"""Vehicle Acronyms
Usage:
1. Clone https://github.com/tabatkins/railroad-diagrams
2. Drop this file in.
3. $ python3 acronyms.py
Some sources:
- https://en.wikipedia.org/wiki/Automotive_acronyms_and_abbreviations
- http://www.chicagotribune.com/classified/automotive/
@khaeru
khaeru / toggl_import.py
Last active October 4, 2021 20:50
Toggl → Timewarrior import extension
#!/usr/bin/env python3
"""Toggl → Timewarrior import extension
© 2016 Paul Natsuo Kishimoto <mail@paul.kishimoto.name>
Licensed under the GNU GPL v3 or later.
Implements a Timewarrior extension (see
https://taskwarrior.org/docs/timewarrior/index.html) to import data from Toggl
(http://toggl.com).

Keybase proof

I hereby claim:

  • I am khaeru on github.
  • I am paulnatsuo (https://keybase.io/paulnatsuo) on keybase.
  • I have a public key whose fingerprint is EB2C 9E86 96D5 EB2C 9C66 428B 61A1 338E 4CE1 9468

To claim this, I am signing this object:

@khaeru
khaeru / fair.py
Last active December 23, 2015 18:59
Team-case matching for ESD.801 Fall 2013
from numpy import *
T = 8 # number of teams
C = 3 # cases per team
# preferences of the teams
# p = array([random.permutation(range(T)) for i in range(T)]) # for testing
p = array([
[4, 5, 6, 1, 2, 7, 8, 3], # abdulla
[8, 4, 2, 1, 6, 7, 5, 3], # accuardi