Skip to content

Instantly share code, notes, and snippets.

View Yourun-proger's full-sized avatar
🥛
kefir

Yourun Yourun-proger

🥛
kefir
View GitHub Profile
@egonSchiele
egonSchiele / Main.hs
Created April 17, 2013 00:03
Read and write from a database using persistent and Scotty
{-# LANGUAGE EmptyDataDecls #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
from typing import Any
from dataclasses import dataclass
class FunctionType:
const = 'const'
call = 'call'
@dataclass
from typing import Any, Dict, Union
from types import FunctionType
from inspect import getargs, getfullargspec
import functools
import warnings
class TypesCompilationWarning(Warning):
pass
@Tishka17
Tishka17 / depends.py
Last active December 21, 2022 16:41
Simple IoC framework
import contextlib
from contextlib import AbstractContextManager, ExitStack
from functools import wraps
from inspect import getfullargspec
from typing import Any, Callable, Dict, get_type_hints, Type
class Depends: # todo mypy
def __init__(self, dependency: Any = None):
self.dependency = dependency
@decorator-factory
decorator-factory / sum_type.py
Last active December 27, 2022 16:11
Sum type in Python
class _EmbellishedBase:
_constructor_name: str
def embellished(name, definition):
class EmbellishedMeta(type):
def __repr__(self):
return f"embellished({self._constructor_name!r}, {definition!r})"
class Embellished(_EmbellishedBase, metaclass=EmbellishedMeta):
from timeit import timeit
import plotly.express as px
import pandas as pd
EXPRESSIONS = [
"{v: k for k, v in data.items()}",
"dict(zip(data.values(), data.keys()))",
"new = {}\nfor k, v in data.items(): new[k] = v",
]
@dabeaz
dabeaz / aecho.py
Last active October 17, 2023 03:26
Live-coded examples from my PyCon Brasil 2015 Keynote
# aecho.py
from socket import *
import asyncio
loop = asyncio.get_event_loop()
async def echo_server(address):
sock = socket(AF_INET, SOCK_STREAM)
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
@coolreader18
coolreader18 / segfault.py
Last active March 30, 2024 08:05
CPython segfault in 5 lines of code
class E(BaseException):
def __new__(cls, *args, **kwargs):
return cls
def a(): yield
a().throw(E)
@patik
patik / how-to-squash-commits-in-git.md
Last active May 30, 2024 07:59
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@Integralist
Integralist / Python Async Decorator.py
Last active June 30, 2024 09:22
[Python Async Decorator] #python #asyncio #decorator
import asyncio
from functools import wraps
def dec(fn):
@wraps(fn)
async def wrapper(*args, **kwargs):
print(fn, args, kwargs) # <function foo at 0x10952d598> () {}
await asyncio.sleep(5)