Skip to content

Instantly share code, notes, and snippets.

View risicle's full-sized avatar

Robert Scott risicle

View GitHub Profile
@risicle
risicle / default.nix
Created July 29, 2018 18:32
default.nix for josm development (retarget as needed for different java versions)
{
pkgs ? import <nixpkgs> {}
}:
let
oraclejdk11 = pkgs.oraclejdk10.overrideAttrs (oldAttrs: {
src = pkgs.requireFile {
name = "jdk-11-ea+24_linux-x64_bin.tar.gz";
url = "http://jdk.java.net/11/";
sha256 = "51430792cd9955c7e41792964bede9fe7e4b2aae084986b8575467db75203a3a";
};
import png
from PIL import Image, ImageMath
import array
import math
def _planes_from_png(filename):
with open(filename, "rb") as png_file:
reader = png.Reader(filename)

Keybase proof

I hereby claim:

  • I am risicle on github.
  • I am r_i_s (https://keybase.io/r_i_s) on keybase.
  • I have a public key whose fingerprint is 8868 8AE4 8AE6 3195 BCF5 F732 3A7B 7B7A 2611 CE25

To claim this, I am signing this object:

@risicle
risicle / nix-daemon.service
Created January 15, 2017 12:52
Nix daemon systemd service (from various sources)
[Unit]
Description=Nix daemon
[Service]
ExecStart=/nix/var/nix/profiles/default/bin/nix-daemon
Nice=15
IOSchedulingClass=3
Environment="CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt"
[Install]
@risicle
risicle / retry_transaction_decorator.py
Created March 17, 2016 18:14
Django @retry_transaction decorator
from django.db import transaction, IntegrityError, DatabaseError
from functools import wraps
import logging
_transaction_logger = logging.getLogger("db.transactions")
def retry_transaction(attempts=2, on_failure=None, logger=_transaction_logger):
"""
Decorator for catching db errors and retrying the operation.
import datetime
def apply_calendar_month_delta(datetime_in, month_delta):
"""
Applies an (integer) @month_delta to @datetime_in. Cheats on days, clamping them to (0,28] to avoid complexities.
>>> from datetime import date
>>> apply_calendar_month_delta(date(2014, 1, 3), -1)
datetime.date(2013, 12, 3)
>>> apply_calendar_month_delta(date(2014, 9, 3), 6)
@risicle
risicle / cache_chained_calculation.py
Created March 17, 2016 16:54
Django cache work-sharing using PostgreSQL advisory locks
from django.core.cache import cache
from django.core.cache.backends.base import DEFAULT_TIMEOUT
from django.db import connection , transaction
from hashlib import md5
def cache_chained_calculation(characteristic_str, calculate_function, timeout=DEFAULT_TIMEOUT, force_update=False):
"""
Attempt to obtain result of @calculate_function, represented by @characteristic_str, through cache or calling the
function. Should only allow one caller to be calculating the value at once (enforced using postgres advisory locks),