Skip to content

Instantly share code, notes, and snippets.

View snsinfu's full-sized avatar
🕺
📆🍩🍩🍩📲

snsinfu snsinfu

🕺
📆🍩🍩🍩📲
View GitHub Profile
@snsinfu
snsinfu / .py
Created September 27, 2021 08:49
Short colorbar
import matplotlib.pyplot as plt
import mpl_toolkits.axes_grid1.inset_locator
fig, ax = plt.subplots()
matrix = np.random.normal(size=(100, 100))
sm = ax.matshow(matrix)
# Attach a small axes to the lower right of the main axes. It's an "inset"
# placed outside of the plot. The size is 0.02 width x 0.5 height of the
hi def link cppSTLfunction Function
hi def link cppSTLfunctional NONE
hi def link cppSTLconstant NONE
hi def link cppSTLnamespace cppNamespaceStd
hi def link cppSTLexception NONE
hi def link cppSTLiterator NONE
hi def link cppSTLiterator_tag NONE
hi def link cppSTLenum NONE
hi def link cppSTLios NONE
hi def link cppSTLcast NONE
@snsinfu
snsinfu / .py
Created April 8, 2021 09:13
[matplotlib] Add named colors (from prop cycle)
plt.style.use("paper")
# Name prop colors. You may need to change it to match your matplotlib style to use.
names = ["nb:blue", "nb:red", "nb:green", "nb:yellow", "nb:cyan", "nb:purple", "nb:magenta", "nb:gray"]
props = plt.rcParams["axes.prop_cycle"]
assert len(names) == len(props)
cc = plt.cm.colors.colorConverter
for name, prop in zip(names, props):
cc.colors[name] = prop["color"]
@snsinfu
snsinfu / rainbow.zsh
Created March 30, 2021 05:07
Rainbow zsh prompt
zshrc::rainbow() {
local i=$1
#local palette=( 197 220 82 49 33 129 )
#local size=${#palette}
local palette=
set -A palette 197 220 82 49 33 129
local size=${#palette}
# Normalize index to a non-negative value by cycling.
@snsinfu
snsinfu / .sh
Created March 29, 2021 14:46
Sync forked git repository to upstream
# git clone git@github.com:example/fork.git
# git remote add upstream https://github.com/example/upstream.git
git pull upstream master
git push origin master
@snsinfu
snsinfu / mockserver.ts
Created March 27, 2021 05:43
Deno HTTP mock server for testing HTTP requests
import * as http from "https://deno.land/std@0.91.0/http/mod.ts";
interface RequestData {
method: string;
path: string;
headers: Headers;
body: ArrayBuffer;
}
interface MockData {
@snsinfu
snsinfu / asleep.ts
Created March 10, 2021 05:26
Typescript async sleep
function asleep(delay: number): Promise<void> {
return new Promise<void>((resolve, reject) => setTimeout(resolve, delay));
}
console.log(Date.now());
await asleep(100);
console.log(Date.now());
@snsinfu
snsinfu / additive_animation.py
Created February 9, 2021 08:11
FuncAnimation that adds lines on each frame. No removal.
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation
from IPython.display import Video
# Make a spiral
step_count = 10000
random = np.random.RandomState(0)
@snsinfu
snsinfu / clearpaper.mplstyle
Last active January 19, 2021 07:45
A clean-looking matplotlib style
# Figure
figure.figsize: 3.6, 2.0
figure.dpi: 150
figure.frameon: True
figure.edgecolor: none
figure.facecolor: white
figure.autolayout: False
figure.constrained_layout.use: True
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.