Skip to content

Instantly share code, notes, and snippets.

View whiledoing's full-sized avatar

whiledoing whiledoing

View GitHub Profile
@whiledoing
whiledoing / cVimrc
Last active May 1, 2024 20:52
[chrome-extension-cVimrc] #chrome
set nohud
map h J
map l K
map c x
map C X
set cncpcompletion
let barposition = "bottom"
set typelinkhints
set noautofocus
@whiledoing
whiledoing / markdown-table-example.md
Last active October 7, 2023 09:34
[markdown-example] markdown example demo #markdown
Left-Aligned Center Aligned Right Aligned
col 3 is some wordy text $1600
col 2 is centered $12
zebra stripes are neat $1
@whiledoing
whiledoing / log.py
Created December 9, 2019 07:13
[python-logging] python logging example #python
# logging_example.py
import logging
# Create a custom logger
logger = logging.getLogger(__name__)
# Create handlers
c_handler = logging.StreamHandler()
f_handler = logging.FileHandler('file.log')
@whiledoing
whiledoing / priority_dict.py
Created June 13, 2018 01:27
[python-heap-with-updated-dict] python heap dict which can update heap in O(1), use redundant element for laze evaluation #python #datastructure
# copyed from http://code.activestate.com/recipes/522995-priority-dict-a-priority-queue-with-updatable-prio/
from heapq import heapify, heappush, heappop
class priority_dict(dict):
"""Dictionary that can be used as a priority queue.
Keys of the dictionary are items to be put into the queue, and values
are their respective priorities. All dictionary methods work as expected.
The advantage over a standard heapq-based priority queue is
that priorities of items can be efficiently updated (amortized O(1))
// from: https://stackoverflow.com/questions/12753805/type-converting-slices-of-interfaces
// make any slice to interface{} slice
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
}
ret := make([]interface{}, s.Len())
class Pipe(object):
def __init__(self, func):
self.func = func
def __ror__(self, other):
def generator():
for obj in other:
if obj is not None:
yield self.func(obj)
return generator()
@whiledoing
whiledoing / exponential-probability-demo.py
Last active February 1, 2020 08:27
[scipy-snippets] scipy snippets #python #scipy
# from: https://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb
import scipy.stats as stats
from matplotlib import pyplot as plt
import numpy as np
a = np.linspace(0, 4, 100)
expo = stats.expon
lambda_ = [0.5, 1]
for l, c in zip(lambda_, colours):
@whiledoing
whiledoing / svm-demo.py
Last active February 1, 2020 08:24
[sklearn-snippets] skl-learn snippets #python #sklearn
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widget
from sklearn.datasets import make_blobs
from sklearn.svm import SVC
def plot_svc_decision_function(model, ax=None, plot_support=True):
"""Plot the decision function for a 2D SVC"""
ax = ax or plt.gca()
@whiledoing
whiledoing / contour-example.py
Last active January 22, 2020 09:34
[matplotlib-snippets] matplotlib snippets #matplotlib #python #visualization
def f(x, y):
return np.sin(x) ** 10 + np.cos(10+x*y) + np.cos(x)
x = np.linspace(0, 5, 50)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
# draw contour
contour = plt.contour(X, Y, Z, 3, colors='black')
@whiledoing
whiledoing / ipython-clip-magic.py
Last active January 22, 2020 09:28
[ipython-notebook] ipython related #python
"""
Add copy to clipboard from IPython!
To install, just copy it to your profile/startup directory, typically:
~/.ipython/profile_default/startup/
Example usage:
%clip hello world
# will store "hello world"