Skip to content

Instantly share code, notes, and snippets.

View basnijholt's full-sized avatar

Bas Nijholt basnijholt

View GitHub Profile
@basnijholt
basnijholt / clean_notebook.sh
Created November 26, 2021 16:09
Clean up and lint a notebook with black, isort, autoflake, pyupgrade
NB=FNAME.ipynb
pip install nbqa autoflake pyupgrade black isort nbconvert jupyter_contrib_nbextensions
nbqa isort $NB
nbqa black $NB
nbqa autoflake -i --remove-all-unused-imports $NB
nbqa pyupgrade $NB --py38-plus
jupyter nbconvert --clear-output --inplace $NB
@basnijholt
basnijholt / cto_line.pine
Created September 18, 2021 08:23
CTO Line indicator for TradingView
//@version=4
study(title="CTO Line", shorttitle="CTO", overlay=true, resolution="")
smma(src, length) =>
smma = 0.0
smma := na(smma[1]) ? sma(src, length) : (smma[1] * (length - 1) + src) / length
smma
v1 = smma(hl2, 15)
m1 = smma(hl2, 19)
m2 = smma(hl2, 25)
v2 = smma(hl2, 29)
sudo su
dd if=/dev/sda1 of=./sda1.image
dd if=/dev/sda2 of=./sda2.image
dd if=/dev/sda3 of=./sda3.image
dd if=/dev/sda4 of=./sda4.image
dd if=/dev/sda5 of=./sda5.image
dd if=/dev/sda6 of=./sda6.image
dd if=/dev/sda7 of=./sda7.image
zip test.zip sda*
import matplotlib.tri as mtri
from matplotlib import pyplot as plt
def plot_loss(learner, cmap="viridis", xy_size=(10, 10)):
fig, ax = plt.subplots(figsize=xy_size)
x_size, y_size = xy_size
ip = learner.ip()
zs = learner.loss_per_triangle(ip)
tri = ip.tri
@basnijholt
basnijholt / pymc3-Hello-World.ipynb
Created December 17, 2020 12:00
pymc3-Hello-World.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import ipywidgets as widgets
class SelectMultipleInteract(widgets.HBox):
def __init__(self, combos, **plot_kwargs):
self.W1 = widgets.SelectMultiple(
options={str(x): x for x in combos},
description="Combinations",
disabled=False,
)
@basnijholt
basnijholt / cache_method_once_dynamically_add.py
Created May 27, 2020 11:07
Dynamically cache a method of an object once
import functools
import random
import time
import types
class A:
def f(self):
time.sleep(1)
return random.random()
@basnijholt
basnijholt / asyncio_zmq_proxy.py
Created May 26, 2020 14:44
zmq.proxy and asyncio
# moddified from https://github.com/booksbyus/zguide/blob/master/examples/Python/asyncio_ioloop/asyncsrv.py
import asyncio
import sys
import zmq
from zmq.asyncio import Context, Poller
# FRONTEND_ADDR = 'tcp://*:5570'
FRONTEND_ADDR = "inproc://frontend"
#!/usr/bin/env python
from collections import Counter
import subprocess
x = subprocess.check_output('qstat -ea'.split())
out = x.decode('utf-8').split('\n')
cols = ['Job ID', 'Username', 'Queue', 'Jobname', 'SessID', 'NDS', 'TSK',
'Required Memory', 'Required Time', 'S', 'Elapsed Time']
@basnijholt
basnijholt / corona-covid19-analysis.ipynb
Created March 29, 2020 14:43
corona-covid19-analysis.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.