Skip to content

Instantly share code, notes, and snippets.

@alexferl
alexferl / main.py
Created December 5, 2024 22:53
Compare JSON/CBOR/MessagePack with Brotli/GZIP/LZ4/LZMA/ZSTD compression
import argparse
import gzip
import json
import lzma
import sys
import timeit
import brotli
import cbor2
import lz4.block
@alexferl
alexferl / url_safe_uuid.py
Created June 30, 2014 23:33
Generate URL-safe UUIDs in Python
import uuid
def gen_uuid(length=32):
u = uuid.uuid4()
return u.hex[:length]
# >>> gen_uuid()
# '582d1f35d75c4536a26235231fa8ec90'
@alexferl
alexferl / formhelpers.py
Last active January 1, 2016 17:09
Jinja2 macro for Twitter Bootstrap 3 alerts.
{% macro render_alert(category=None, dismissable=False, error=False,
message=None, link=None) -%}
{% if not category and not error %}
{% set category = 'success' %}
{% elif error %}
{% set category = 'danger' %}
{% endif %}
<div class="alert alert-{{ category }}
{% if dismissable %} alert-dismissable{% endif %}">
{% if dismissable %}