Skip to content

Instantly share code, notes, and snippets.

@mutsune
mutsune / INSTALLATION
Last active October 16, 2022 14:59
Setup SwitchBot python-host (https://github.com/OpenWonderLabs/python-host switchbot_py3.py) on Docker image python:3.9-bullseye
apt update
apt install python3-bluez -y
git clone https://github.com/OpenWonderLabs/python-host.git
cd python-host
pip3 install setuptools==58
pip3 install pybluez
apt install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev python3-dev -y
@mutsune
mutsune / random-wallpaper.sh
Last active November 6, 2021 15:56
Get photo URLs from unsplash collections
#! /usr/bin/env bash
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
function exec_uncollections() {
ACCESS_KEY="$(security find-generic-password -a "${USER}" -s unsplash-uncollections-access-key -w)"
export ACCESS_KEY
python3 ./uncollections.py
}
@mutsune
mutsune / memo.sh
Created October 17, 2021 09:18
nerdctl with k3s (armv7)
mkdir nerdctl
cd nerdctl
wget 'https://github.com/containerd/nerdctl/releases/download/v0.12.1/nerdctl-0.12.1-linux-arm-v7.tar.gz'
tar xzf nerdctl-0.12.1-linux-arm-v7.tar.gz
alias k3sctl="/root/nerdctl/nerdctl --address /run/k3s/containerd/containerd.sock --namespace k8s.io"
wget 'https://github.com/containernetworking/plugins/releases/download/v1.0.1/cni-plugins-linux-arm-v1.0.1.tgz'
mkdir -p /opt/cni/bin
from deco import concurrent
from deco import synchronized
import time
@concurrent
def process(data):
time.sleep(1)
return data
@mutsune
mutsune / 0.pipe_and_redirect
Last active October 17, 2021 12:22
pipe and redirect implement
.
@mutsune
mutsune / mpt.py
Created October 3, 2021 00:42
multiprocess termination
from multiprocessing import Process
import time
import sys
def f(x):
if x == 3:
sys.exit(1)
time.sleep(2)
print('hello', x)
@mutsune
mutsune / fav_albums.py
Last active May 15, 2021 07:10
Extract albums containing songs that have been played more than 5 times
from itertools import groupby
f = open("music.utf8.tsv")
lines = [l[:-1] for l in f]
data = [l.split("\t") for l in lines[1:]]
data = filter(lambda d: "Apple Music" in d[1], data)
data = filter(lambda d: d[2] != "", data)
for k, v in groupby(data, lambda c: c[0]):
album = list(v)
{
viewer {
gists(first: 100, orderBy: {field: CREATED_AT, direction: DESC}, privacy: SECRET) {
edges {
node {
name
url
isPublic
}
}
#[derive(PartialEq)]
pub enum Class {
Var,
Function,
List,
Str,
Int,
Double,
}
@mutsune
mutsune / notebook.json
Created September 20, 2020 14:00
Jupyter Nbextensions config: .jupyter/nbconfig/notebook.json
{
"load_extensions": {
"nbextensions_configurator/config_menu/main": true,
"hinterland/hinterland": true,
"code_prettify/code_prettify": true,
"select_keymap/main": true,
"toc2/main": true,
"addbefore/main": true,
"autosavetime/main": true,
"comment-uncomment/main": true,