Skip to content

Instantly share code, notes, and snippets.

View decorator-factory's full-sized avatar
🦆
duck

decorator-factory

🦆
duck
View GitHub Profile
@decorator-factory
decorator-factory / adts.hs
Created March 14, 2023 21:20
Lambda calculus interlude
-- Lazy System F (lazy as in -- I am too lazy to specify all the boring bits)
--- boolean (this is a popular implementation in lambda calculus)
Bool = ∀x. x -> x -> x
true : Bool
true = λt f. t
false : Bool
@decorator-factory
decorator-factory / silly-interview-questions-and-answers.md
Last active January 16, 2023 13:27
Silly interview questions and answers

When I was looking forward to my first job interview, I was (naturally) anxious, so I wanted to prepare well. I opened up a search engine and typed in: "Python interview questions".

To my surprise, I found dozens of articles with outdated, plain wrong and supernaturally hilarious "interview questions" and even worse "answers" to them. In this post, I've compiled some of them with my own commentary. I've sprinlked in some related guides of poor quality.

I tried ordering the sections as they lose the connection to reality.

Dynamic typing

Source

Python is dynamically typed, this means that you don’t need to state the types of variables when you declare them or anything like that. You can do things like x=111 and then x="I'm a string" without error

@decorator-factory
decorator-factory / gls.py
Created February 22, 2022 18:35
Cursed Python - inspired by `jtolio/gls`
import inspect
from collections.abc import Iterator
from asyncio import run, sleep, create_task
from types import FrameType
from typing import Optional
async def _setup_(f):
return await f
@decorator-factory
decorator-factory / madness.ts
Created December 18, 2021 13:36
TypeScript Higher Kinded Types using generic representation
declare class Fail<Message extends string, Detail> { #_: Fail<Message, Detail> }
///
enum $A {}; enum $B {}; enum $C {}; enum $D {}; enum $E {}; enum $F {}; enum $G {}; enum $H {};
///
declare class Barrier<T, Tag> { #body: T; #tag: Tag }
@decorator-factory
decorator-factory / example.py
Created December 7, 2021 00:20
Pyright example gist
from typing import TypeVar
T = TypeVar("T")
def f(t: T, x: int) -> str:
return x
#!/bin/bash
#
# Create a throwaway Python project
# Usage:
#
# 1. Put the script as `pysandbox` somewhere on your PATH
# 2.
# if (you want a predefined project name):
# source pysandbox play-around-with-aioredis
# elif (you want a random one):

Keybase proof

I hereby claim:

  • I am decorator-factory on github.
  • I am decoratorfactor (https://keybase.io/decoratorfactor) on keybase.
  • I have a public key whose fingerprint is 1687 6415 3517 BC3F 6506 1777 02DF 0785 30A3 C3CB

To claim this, I am signing this object:

@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):