Skip to content

Instantly share code, notes, and snippets.

View syrte's full-sized avatar

Zhaozhou Li syrte

View GitHub Profile
from __future__ import division
from scipy.stats import rv_continuous
from numpy import log, exp, nan
from numba import vectorize
import numpy as np
from matplotlib import pyplot as plt
class rv_custom(rv_continuous):
@syrte
syrte / Marked.md
Created May 1, 2017 14:59
Use Marked for TiddlyWiki. Originally fork from http://bjtools.tiddlyspot.com/

Use marked instead of markdown-js for Markdown parser of TiddlyWiki 5. Originally fork from http://bjtools.tiddlyspot.com/

Main New Features

  • support fenced code block
  • support code highlighting

Install

  1. Install the official Markdown and Hightlight.js plugin.
@syrte
syrte / custom_oscillator_potential.py
Last active May 10, 2017 13:17
template for user defined cython potential of gala
code = r'''
from __future__ import division, print_function
import numpy as np
from collections import OrderedDict
from gala.potential.potential.cpotential import CPotentialBase
from gala.potential.potential.cpotential cimport CPotentialWrapper
from gala.potential.potential.cpotential cimport densityfunc, energyfunc, gradientfunc, hessianfunc
@syrte
syrte / export_meizu_note.py
Created May 14, 2017 14:24
Export Meizu note from cloud.flyme.cn
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
class IfReady:
key = None
if pyx_file is not None:
pyx_mtime = os.path.getmtime(pyx_file)
else:
pyx_mtime = 0. # so ext_file always newer than pyx_file
# need build:
# force is True, ext_file non exists, or older than pyx_file
# user should take care of deps by himself
if (force or not os.path.isfile(ext_file) or
os.path.getmtime(ext_file) < pyx_mtime):
if pyx_file is not None:
pyx_mtime = os.path.getmtime(pyx_file)
else:
pyx_mtime = 0. # so ext_file always newer than pyx_file
# need build:
# force is True, ext_file non exists, or older than pyx_file
# user should take care of deps by himself
if (force or not os.path.isfile(ext_file) or
os.path.getmtime(ext_file) < pyx_mtime):
@syrte
syrte / histogram_patch.py
Created June 12, 2017 12:44
vi ~/local/anaconda2/lib/python2.7/site-packages/numpy/lib/function_base.py
# Do not modify the original value of range so we can check for `None`
if range is None:
if a.size == 0:
# handle empty arrays. Can't determine range, so use 0-1.
mn, mx = 0.0, 1.0
else:
mn, mx = a.min() + 0.0, a.max() + 0.0
# add below
if not np.all(np.isfinite([mn, mx])):
b = a[np.isfinite(a)]
def compare_violin(x, y, bins, **kwargs):
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
nmax = int(kwargs.pop('nmax', 1e4))
nmin = int(kwargs.pop('nmax', 1))
kwargs.setdefault('showmedians', True)
bins_mid = (bins[:-1] + bins[1:]) * 0.5
def tripcolorshow(x, y, z=None, **kwargs):
"""
tripcolorshow(x, y, z)
tri = Triangulation(x, y)
tripcolorshow(tri, z)
"""
import matplotlib.tri as tri
import matplotlib.pyplot as plt
@syrte
syrte / periodic_tree.py
Last active September 21, 2017 06:16
sklearn-based KDTree with periodic boundary conditions.
import numpy as np
from collections import namedtuple
__all__ = ['query_radius_periodic']
def repeat_periodic(points, boxsize):
"""Repeat data to mock periodic boundaries.
points (m, n) -> repeated_points (m, 3**n, n)