Skip to content

Instantly share code, notes, and snippets.

@flying-sheep
flying-sheep / makepkg-wrap.sh
Created January 14, 2018 11:55
makepkg wrapper to exit python virtual envs
makepkg() {
if [[ "$(type -w deactivate || true)" == 'decativate: function' ]]; then
deactivate
fi
/usr/bin/makepkg "$@"
}
import sys
import hashlib
import pathlib
BUF_SIZE = 65536
def get_hash(fp):
sha1 = hashlib.sha1()
with open(fp, 'rb') as f:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@flying-sheep
flying-sheep / .block
Last active October 18, 2017 11:48
script insertion and stack traces. jQuery’s magic is bad for debugging
license: mit
@flying-sheep
flying-sheep / unpack.py
Last active September 7, 2017 19:40
A context manager that can skip its body.
import sys
import inspect
class _UnpackMarker(Exception): pass
class unpack:
def __init__(self, pred):
self.pred = pred
def __enter__(self):
@flying-sheep
flying-sheep / _templates⁄autosummary⁄base.rst
Last active August 29, 2017 13:31
Sphinx configuration for GitHub code links. Every autosummary page will link to the python code, other pages to the .rst documents.
github_url:{{ fullname | modurl }}

{% extends "!autosummary/base.rst" %}

@flying-sheep
flying-sheep / cache-file.py
Created August 10, 2017 11:44
Download and cache file
#!/usr/bin/env python3
import sys
from pathlib import Path
from urllib.request import urlretrieve
import requests
from appdirs import user_cache_dir
from tqdm import tqdm
cache_dir = Path(user_cache_dir('programm-name', 'dein-name'))
@flying-sheep
flying-sheep / bisect.sh
Created August 8, 2017 16:08
IRkernel bisecting
#!/bin/bash
git bisect start
git bisect good 0.8.6
git bisect bad master
git bisect run bash test.sh
git bisect log
#include <iostream>
#include <vector>
#include <cstdlib>
namespace 🔩 = std;
using 🔢 = int;
using 💀 = void;
using 🕒 = time_t;
using 👌 = bool;
import random
with path.open('r', encoding='latin-1') as f:
f.readline() # header
lines = list(csv.reader(f, delimiter='\t'))
random.sample(lines, 20)