Skip to content

Instantly share code, notes, and snippets.

View kissgyorgy's full-sized avatar

György Kiss kissgyorgy

View GitHub Profile
@vlaci
vlaci / generate_x25519.py
Created August 2, 2022 17:26
Generate x25519 certificate
#!/usr/bin/env python
import datetime as dt
from cryptography import x509
from cryptography.hazmat.backends.openssl import backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import ed25519, x25519
from cryptography.x509.oid import NameOID
issuer_private_key = ed25519.Ed25519PrivateKey.generate()
@jart
jart / .init.lua
Last active September 1, 2023 07:14
redbean sqlite tutorial
re = require "re"
sqlite3 = require "lsqlite3"
reNumberPath = re.compile[[^/([0-9][0-9]*)$]]
function SetupSql()
if not db then
db = sqlite3.open('redbean.sqlite3')
db:busy_timeout(1000)
db:exec[[PRAGMA journal_mode=WAL]]
@ityonemo
ityonemo / test.md
Last active April 7, 2024 14:48
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

@atoponce
atoponce / instructions.md
Last active March 8, 2022 08:04
Convert any binary to an image

Convert any binary to PNG

This walk through comes from @GalacticFurball who tweeted two images representing the youtube_dl source code as of 2020-09-20. They mentioned later in the thread that they struggled converting the gzip-compressed tarball of the source code with Imagemagick to a PNG, so they ended up using a 3rd party website to do the work. This Gist will show you how to do it cleanly and exactly.

Instructions

If you would like to convert any non-image binary into PNG, Imagemagick makes this trivial. I will be executing the commands on a Debian Linux system, so you may need to adjust the commands for BSD, macOS, or Windows as necessary.

#!/usr/bin/python3
import sys
import asyncio
import greenlet
class AsyncIoGreenlet(greenlet.greenlet):
def __init__(self, driver, fn):
greenlet.greenlet.__init__(self, fn, driver)
self.driver = driver
@zzzeek
zzzeek / simpler_asyncio.py
Last active October 12, 2023 13:53
a simpler version of async->greenlet->async written by @CaselIT
"""This is a simpler version of the greenlet
example at https://gist.github.com/zzzeek/4e89ce6226826e7a8df13e1b573ad354
Instead of the "await" keyword, we use the "await_()" function to interact with
the greenlet context. the greenlet context itself is 23 lines of code right
here.
"""
import asyncio
@zzzeek
zzzeek / msg373145.rst
Last active October 22, 2022 12:36
asyncio support for SQLAlchemy (and Flask, and any other blocking-IO library)

This is a cross post of something I just posted on the Python bug tracker at https://bugs.python.org/msg373145.

I seem to have two cents to offer so here it is. An obscure issue in the Python bug tracker is probably not the right place for this so consider this as an early draft of something that maybe I'll talk about more elsewhere.

> This basically divides code into two islands - async and non-async

@zzzeek
zzzeek / asyncio_plus_greenlet.py
Last active July 5, 2023 16:32
An asyncio program that runs rows into a Postgresql database, using blocking style code to actually run the database commands
"""This program is exactly the same as that of
https://gist.github.com/zzzeek/33943060f7a08cf9e82bf8df1f0f75de ,
with the exception that the add_and_select_data function is written in
synchronous style.
UPDATED!! now includes refinements by @snaury and @Caselit . SIMPLER
AND FASTER!!
@zzzeek
zzzeek / plain_asyncio.py
Last active November 13, 2021 00:01
An asyncio program that runs rows into a Postgresql database
"""A plain asyncio program that uses asyncpg to run some rows into a table and
select them.
This is a "control" program which we will compare to the one which uses calls
from an implicit IO greenlet at
https://gist.github.com/zzzeek/4e89ce6226826e7a8df13e1b573ad354.
Performance against a PG database over a wired network
Ran 40000 records in 40 concurrent requests, Total time 5.560306
@zzzeek
zzzeek / async_to_greenlet_to_async.py
Last active January 22, 2024 15:35
Write a program in asyncio, that calls into a library that knows nothing about asyncio, which then calls out to a database adapter that is only asyncio
"""Proof of concept of an adapter that will wrap a blocking IO library in
greenlets, so that it can be invoked by asyncio code and itself make calls out
to an asyncio database library.
hint: any Python ORM or database abstraction tool written against the DBAPI
could in theory allow asyncio round trips to a pure async DB driver like
asyncpg.
The approach here seems too simple to be true and I did not expect it to
collapse down to something this minimal, so it is very possible I am totally