Skip to content

Instantly share code, notes, and snippets.

View buxx's full-sized avatar
🦀

Bastien Sevajol buxx

🦀
View GitHub Profile
@buxx
buxx / builder.py
Last active February 9, 2024 14:21
Examples of Builder in Rust, Python and TypeScript
import dataclasses
import abc
import typing
@dataclasses.dataclass
class Person:
name: str
class RuleSet(abc.ABC):
@buxx
buxx / async.py
Created September 2, 2021 10:22
Quelques concepts python
import asyncio
"""
asyncio: résoudre les problèmes d'attente
"""
class Progress:
def __init__(self, start: float):
self.value = start
src = create_engine('mysql+oursql://username:password@127.0.0.1:3306/dbname')
dst = create_engine('postgresql://username:password@localhost:5432/dbname')
tables = Base.metadata.tables;
for tbl in tables:
data = src.execute(tables[tbl].select()).fetchall()
for a in data: print(a)
if data:
print (tables[tbl].insert())
dst.execute( tables[tbl].insert(), data)
@buxx
buxx / keybase.md
Created September 16, 2019 07:05
For keybase auth

Keybase proof

I hereby claim:

  • I am buxx on github.
  • I am buxx (https://keybase.io/buxx) on keybase.
  • I have a public key ASBiqrMvEzxYFEjTpnHrAOeKpNL3Yt3VYArT-iJ2sFbZ8go

To claim this, I am signing this object:

@buxx
buxx / aiopoc.py
Created July 24, 2018 12:44
aiohttp stream response example
from aiohttp import web
async def handle(request):
response = web.StreamResponse(
status=200,
reason='OK',
headers={'Content-Type': 'text/plain'},
)
await response.prepare(request)
@buxx
buxx / testing_transparency.py
Created December 11, 2017 11:49
testing_transparency
from pyglet.gl import *
# glEnable(GL_TEXTURE_2D)
# glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
desert_img = pyglet.image.load('assets/desert.png')
data = desert_img.data
data = b'\x00' * 200000 + data[200000:]
desert_img.data = data
@buxx
buxx / .sh
Last active July 4, 2017 14:42
bash aliases
alias uuid="python -c 'import uuid; print(uuid.uuid4())'"
alias gen="python -c 'import uuid; print(str(uuid.uuid4()).replace(\"-\", \"\"))'"
alias freezelist="python -c \"import pip; print(list(sorted(['{}{}'.format(d.project_name, '=={}'.format(getattr(d, 'version')) if getattr(d, 'version') else '') for d in pip.get_installed_distributions(local_only=True)], key=lambda s: s.lower())))\""
alias prettyjson='python -m json.tool'
@buxx
buxx / gist:b85420dd10c67f0cb3ca8b939b5feb8c
Created March 2, 2017 21:09
Add utf8 info usage at beginning of python file given as 1rst arg
#!/bin/bash
line=$(head -n 1 $1)
# need to be fixed below
if ! [ $line="# coding: utf-8" ]; then
printf '%s\n' "# coding: utf-8" | cat - $1 > $1.n && mv $1.n $1
fi;
# use like:
# find -iname '*.py' ! -path "./venv3.5/*" -exec ./u.sh {} \;
@buxx
buxx / ModelTestCase.php
Created June 11, 2012 17:25 — forked from wowo/ModelTestCase.php
Model Test Case, which loads fixtures and builds database before each test
<?php
/*
* Adapt to your AppKernel.php path
*/
require_once(__DIR__ . "../../../../../../app/AppKernel.php");
/**
* @see http://haulynjason.net/weblog/2012/01/fully-isolated-tests-in-symfony2/
*/