Skip to content

Instantly share code, notes, and snippets.

View msakai's full-sized avatar

Masahiro Sakai msakai

View GitHub Profile
#!/usr/bin/env python
import argparse
import chainer
import chainer.functions as F
import chainer.links as L
from chainer import training
from chainer.training import extensions
import chainerx
# Attempt to mimick following GADT (Generalized algebraic data type) in Python:
#
# data Expr a where
# Const :: a -> Expr a
# Add :: Expr Int -> Expr Int -> Expr Int
# Eq :: Expr Int -> Expr Int -> Expr Bool
# IfThenElse :: Expr Bool -> Expr a -> Expr a -> Expr a
import abc
from typing import Generic, TypeVar
# Encoding existential types in Python using ∃X. F(X) ≅ ∀R. (∀X. F(X) → R) → R.
import abc
from typing import Generic, TypeVar
S = TypeVar('S')
R = TypeVar('R')
class Automata(Generic[S], metaclass=abc.ABCMeta):
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@msakai
msakai / .block
Created November 7, 2019 03:10 — forked from fancellu/.block
Force directed graph for D3.js v4 with labelled edges and arrows
license: gpl-3.0
height: 600
print(0x10000000000000000 is 0x10000000000000000)
#=> True
import dis
b = dis.Bytecode(lambda: 0x10000000000000000 is 0x10000000000000000)
print(b.dis())
#=>
# 4 0 LOAD_CONST 1 (18446744073709551616)
# 2 LOAD_CONST 1 (18446744073709551616)
# 4 COMPARE_OP 8 (is)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
year month day wday
2158 4 19 3
2020 8 11 2
2010 5 15 6
2088 11 30 2
2181 5 28 1
2162 5 16 0
2175 11 17 5
2018 4 5 4
2287 1 24 1
@msakai
msakai / citeusync.py
Last active April 7, 2019 01:50 — forked from willwade/citeusync.py
inspired by the perl version - but not quite the same. Simply use to download your bibtex file and attachments on a regular basis. NB: Only downloads the PDF if not already present so technically only 2 calls at a minimum to CUL (Login and download of bibtex. Obviously a lot more if downloading the PDFs). If more than one attachment - will only …
#!/usr/bin/env python
# Contact: Will Wade willwa.de
# Date: April 2013
# Needs mechanize and pybtex
#
# NB: Little error checking going on in this script
# TO-DO: Check last-download-date of bibtex file later than last-modified date on CUL. ? possible
#
# With thanks to https://pypi.python.org/pypi/citeulike_api/0.1.3dev for the login part
import mechanize
from abc import ABCMeta, abstractmethod
import numpy as np
import scipy.linalg
import pivots
def beye(nBatch, n, dtype):
return np.broadcast_to(np.expand_dims(np.eye(n, dtype=dtype), 0), (nBatch, n, n))