Skip to content

Instantly share code, notes, and snippets.

rec {
pkgs = import <nixpkgs> {};
python3 = pkgs.python39.withPackages (ps: with ps; [ setuptools wheel twine ]);
v502 = pkgs.fetchzip {
url = "https://github.com/hsluv/hsluv-python/archive/refs/tags/v5.0.2.zip";
sha256 = "sha256-8uzDL8VWJmoH5Hnj+PZ3I1U1KdD5wyd/veM5LplHHGQ=";
};
v501 = pkgs.fetchzip {
@boronine
boronine / fetch_email.py
Created January 20, 2022 09:01
Fetch email from S3 bucket written to by SES "receive email" feature
#!/usr/bin/env python3
import os
import subprocess
import json
import glob
from pathlib import Path
RCLONE_REMOTE = 'my-s3-remote'
S3_BUCKET = 'my-ses-email-bucket'
RCLONE_REMOTE_S3 = f'{RCLONE_REMOTE}:{S3_BUCKET}'
@boronine
boronine / sentry2csvUA.py
Created June 17, 2020 03:09
Original: https://github.com/sparkmeter/sentry2csv (modified for User-Agent extraction)
#!/usr/bin/env python3
"""Export a Sentry project's issues to CSV."""
import argparse
import asyncio
import csv
import logging
import sys
from typing import Any, Dict, List, Optional, Tuple, Union
@boronine
boronine / shebang.py
Last active February 22, 2018 15:42
Test maximum shebang length
import os
import stat
import tempfile
import subprocess
shebang_prefix = '#!/usr/bin/env DUMMY=x'
shebang_suffix = ' python\n'
shebang_length_min = len(shebang_prefix) + len(shebang_suffix)
TEST_FILE_HANDLE, TEST_FILE = tempfile.mkstemp('.py')
@boronine
boronine / edn-vs-json.cljs
Created May 15, 2015 08:23
EDN vs JSON parsing speed
; lein new mies-node edn-vs-json
; vim edn-vs-json/src/edn_vs_json/core.cljs
; lein cljs build once
; node run.js
(ns edn-vs-json.core
(:require
[cljs.nodejs :as nodejs]
[cljs.reader :as reader]
[clojure.string :as string]))
@boronine
boronine / generate-avatar.py
Created August 17, 2014 12:46
Colorful display pic with HUSL
import math
import png
from husl import *
def mix(h1, h2, t):
return h1 * t + h2 * (1 - t)
def spiral(radius, degree, number):
n = 1.0 / number
// Asynchronous coding takes a bit of time to wrap your head around.
// I can't know for sure, but I think you misunderstand the general
// nature of a callback function. 'ajax.post' doesn't wait for the
// request to complete before returning, if it did so, there wouldn't
// be any need for a callback. **If you want something to happen AFTER
// the request completes, you have to put it in the callback function.**
// Don't think of a callback as some kind of icing on the cake, it is
// literally the continuation of your program's logic.
app.post '/api/verify', (req, res) ->
fail = ->
res.json status: 'failure'
if not req.body?
fail()
opts = {
host: "https://verifier.login.persona.org"
path: "/verify"
method: 'POST'
regectUnauthorized: true
class MyResource(ModelResource):
# Workaround for this issue:
# https://github.com/toastdriven/django-tastypie/issues/518
def hydrate(self, bundle):
for field_name, field_obj in self.fields.items():
if field_name == 'resource_uri':
continue
if not field_obj.blank and not bundle.data.has_key(field_name):
raise ApiFieldError("The '%s' field has no data and doesn't allow a default or null value." % field_name)
return bundle
class CompanyResource(ModelResource):
class Meta:
resource_name = 'companies'
api_name = 'v1'
detail_uri_name = 'domain'
queryset = Company.objects.all()
def prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<domain>[\w\d_.-]+)/$" %
self._meta.resource_name,