Skip to content

Instantly share code, notes, and snippets.

from collections import defaultdict
import csv
from functools import reduce
from itertools import groupby
import json
import sqlite3
from disjoint_set import DisjointSet
# Diese AGS werden ignoriert, weil wir zurzeit für gemeindefreie Gebiete keine Daten aufbereiten.
IGNORE = {
@curiousleo
curiousleo / localzero.sql
Last active March 25, 2022 17:31
Generate renewable summary statistics in the format used by GermanZero-de/localzero-data-public
with Stichtag as (select "2018-12-31" as Stichtag),
ags as (
select Gemeindeschluessel as ags from EinheitSolar
union select Gemeindeschluessel as ags from EinheitWind
union select Gemeindeschluessel as ags from EinheitBiomasse
union select Gemeindeschluessel as ags from EinheitGeoSolarthermieGrubenKlaerschlammDruckentspannung
union select Gemeindeschluessel as ags from EinheitWasser
),
pv as (
select
@curiousleo
curiousleo / index.html
Last active February 1, 2022 22:23
Marktstammdatenregister Gesamtexport Validierungsergebnis: Test 1
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/@picocss/[email protected]/css/pico.min.css">
<style>
/* Show <tr>s in the overview table not marked with class="failure" iff #all-files is checked. */
table.overview tbody tr { display: none; }
@curiousleo
curiousleo / day06.py
Last active December 10, 2021 08:35
Advent of Code 2021 Day 6 in Python
from collections import deque
import itertools
def init(fish):
"""
>>> init([3, 4, 3, 1, 2])
[0, 1, 1, 2, 1, 0, 0, 0, 0]
"""
result = [0] * 9
for day, fish in itertools.groupby(sorted(fish)):
@curiousleo
curiousleo / Enumerate.hs
Last active April 29, 2020 09:54
Check how many floats in the unit interval are hit by various Word32 -> Float conversion functions
module Main (main) where
import Data.Bit
import Data.Bits
import Data.Vector.Unboxed as V
import Data.Vector.Unboxed.Mutable as MV
import GHC.Float (castFloatToWord32, castWord32ToFloat)
import Data.Word (Word32, Word64)
import Data.Int (Int32)
@curiousleo
curiousleo / laptop-nixos-setup.md
Last active March 20, 2020 16:21
How to set up a new laptop with NixOS

How to set up a new laptop with NixOS

Set up installation medium

$ sudo dd bs=4M if=${image.iso} of=${/dev/sdx} status=progress oflag=sync

@curiousleo
curiousleo / goodriddance.py
Last active March 4, 2019 23:33
Convert Goodreads CSV export to CSV with only relevant fields
import pandas as pd
INPUT_FIELDS = [
"Book Id",
"Title",
"Author",
"Author l-f",
"Binding",
"Original Publication Year",
"Bookshelves",
@curiousleo
curiousleo / denkrate.nix
Last active January 5, 2019 14:26
NixOS server experiment
{ config, lib, pkgs, ... }:
with lib;
let
kibanaPort = 5601;
netdataPort = 19999;
oauthProxyPort = 4180;
innerNginxPort = 8080;
in
@curiousleo
curiousleo / convert.py
Created April 8, 2018 14:33
Convert IUPAC to SMILES and vice versa
import urllib.error
import urllib.parse
import urllib.request
SMILES_URL_TEMPLATE = 'http://cactus.nci.nih.gov/chemical/structure/{}/smiles'
IUPAC_URL_TEMPLATE = 'http://cactus.nci.nih.gov/chemical/structure/{}/iupac_name'
def retrieve(url):
with urllib.request.urlopen(url) as f:
return f.read()
@curiousleo
curiousleo / muhttp.cpp
Last active April 24, 2018 19:57
Oversimplified HTTP server in C++
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
#include <algorithm>
#include <cerrno>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>