Skip to content

Instantly share code, notes, and snippets.

View zoni's full-sized avatar

Nick Groenen zoni

View GitHub Profile
#!/usr/bin/env python3
import os
import subprocess
from datetime import datetime
from pathlib import Path
from zoneinfo import ZoneInfo
import frontmatter
@zoni
zoni / app.py
Last active March 22, 2023 17:43
from pathlib import Path
from starlite import Response, Starlite, TemplateConfig, get
from starlite.contrib.jinja import JinjaTemplateEngine
from starlite.status_codes import HTTP_307_TEMPORARY_REDIRECT
@get("/{name:str}", include_in_schema=False)
def hello(name: str = "world") -> Response:
if name == "foo":
import asyncio
import os
from pprint import pprint
async def do_work():
"""Schedule and run a bunch of tasks that do nothing but sleep"""
tasks = [asyncio.create_task(asyncio.sleep(duration)) for duration in [0, 1, 3, 5]]
results, _ = await asyncio.wait(tasks)
return results
#!/bin/bash
: ${TEXT_COLLECTOR_DIR:="/var/tmp/node_exporter"}
OUTPUT_FILE=${TEXT_COLLECTOR_DIR}/apt.prom
TEMP_OUTPUT_FILE=${OUTPUT_FILE}.tmp
upgrades=$(/usr/lib/update-notifier/apt-check 2>&1)
# output format for apt-check is $upgrades;$security_upgrades
(
@zoni
zoni / benchmark.rs
Created May 14, 2020 12:23
Performance benchmark of context() vs with_context()
use anyhow::{Context, Result};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::error::Error;
use std::fmt;
#[derive(Debug)]
struct FooError {}
fn foo() -> Result<(), FooError> {
Err(FooError {})
@zoni
zoni / errbot.conf
Created May 16, 2016 21:49
Errbot supervisord config
[program:errbot]
command = /srv/errbot/virtualenv/bin/errbot --config /srv/errbot/config.py
user = errbot
stdout_logfile = /var/log/supervisor/errbot.log
stderr_logfile = NONE
redirect_stderr = true
directory = /srv/errbot/
startsecs = 3
stopsignal = INT
environment = LC_ALL="en_US.UTF-8"
@zoni
zoni / keybase.md
Created October 27, 2014 12:51
keybase.md

Keybase proof

I hereby claim:

  • I am zoni on github.
  • I am nickgroenen (https://keybase.io/nickgroenen) on keybase.
  • I have a public key whose fingerprint is B19D EB40 69BC 0FF8 EE16 BA64 4F0A D019 928A E098

To claim this, I am signing this object:

@zoni
zoni / sendhello.plug
Created July 17, 2014 01:02
self.send() example for Err
[Core]
Name = SendHello
Module = sendhello
[Python]
Version = 2+
[Documentation]
Description = Demonstrating self.send()
@zoni
zoni / README
Last active December 30, 2015 14:09
Invoke script to ease dealing with (StartSSL) TLS certificate generation.
Certificates may be created with the help of invoke. This is geared towards
use of StartSSL certificates, but does not enforce this (--no-startssl).
See `invoke --help` for general help on invoke, including useage of how
to list all tasks and their corresponding help and option flags.
To create a new key:
invoke createkey foo.domain.tld.key
@zoni
zoni / iptables
Created November 26, 2013 09:20
Ansible module to manage iptables rules
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Ansible module to manage iptables rules
Written by Nick Groenen <zoni@zoni.nl>. If you get your hands on a
copy of this code, please feel free to do with it whatever you like.
"""