Skip to content

Instantly share code, notes, and snippets.

View reimundklain's full-sized avatar

Reimund Klain reimundklain

  • ConDevTec GmbH
  • Munich
View GitHub Profile
@kjmph
kjmph / A_UUID_v7_for_Postgres.sql
Last active November 6, 2024 19:57
Postgres PL/pgSQL function for UUID v7 and a bonus custom UUID v8 to support microsecond precision as well. Read more here: https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
-- Based off IETF draft, https://datatracker.ietf.org/doc/draft-peabody-dispatch-new-uuid-format/
create or replace function uuid_generate_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(
@stettix
stettix / things-i-believe.md
Last active November 15, 2024 20:06
Things I believe

Things I believe

This is a collection of the things I believe about software development. I have worked for years building backend and data processing systems, so read the below within that context.

Agree? Disagree? Feel free to let me know at @JanStette.

Fundamentals

Keep it simple, stupid. You ain't gonna need it.

@mattst
mattst / TestClipTwoMinData.csv
Created November 9, 2018 17:15
FFMPEG libx264 encodes 2 min video, CRFs 18 to 27, all presets except placebo, encode times and file sizes
CRF Preset Time (Secs) Size (MB)
18 ultrafast 13.91 175.13
18 superfast 24.39 149.13
18 veryfast 36.39 87.97
18 faster 55.89 94.50
18 fast 79.71 97.76
18 medium 97.80 94.15
18 slow 145.07 91.47
18 slower 262.72 91.55
18 veryslow 503.44 84.07
@obskyr
obskyr / stream_response.py
Last active October 18, 2024 13:18
How to stream a requests response as a file-like object.
# -*- coding: utf-8 -*-
import requests
from io import BytesIO, SEEK_SET, SEEK_END
class ResponseStream(object):
def __init__(self, request_iterator):
self._bytes = BytesIO()
self._iterator = request_iterator
@cairabbit
cairabbit / cte.sqlalchemy.py
Last active September 16, 2024 21:49
SqlAlchemy CTE recursive sample
from sqlalchemy.orm import sessionmaker, relationship, aliased
from sqlalchemy import cast, Integer, Text, Column, ForeignKey, literal, null
from sqlalchemy.sql import column, label
class Catalog(Base):
__tablename__ = 'catalog'
id = Column(String, primary_key=True)
parentid = Column(String, ForeignKey('catalog.id'))
name = Column(String)
parent = relationship("Catalog", remote_side=[id])
@olgakogan
olgakogan / sql_alchemy_samples.py
Last active February 7, 2023 22:49
SQL Alchemy Samples
########## CASE IN UPDATE STATEMENT ############
from sqlalchemy import case
# single value modification (the 'else' is not mandatory)
session.query(User).update({User.status : case([(User.status == "pending", "approved")], else_=User.status)}, False)
# multiple values modification
session.query(User).update({User.status : case([(User.status == "pending", "approved"),
(User.status == "waiting", "deprecated_status")])}, False)