This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operators = ['sentinel', '=', ')', '(', '+', '*', '.'] | |
| precedence = dict((b, a) for a, b in enumerate(operators)) | |
| assoc_right = {'='} | |
| def has_higher_prec(a, b): | |
| prec = precedence[a] | |
| if a in assoc_right: | |
| prec += 1 | |
| return prec > precedence[b] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| global _start | |
| extern getchar | |
| extern putchar | |
| extern fflush | |
| section .data | |
| sys_read equ 0 | |
| sys_write equ 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| tape=(0) | |
| tape_index=0 | |
| tape_get() { | |
| echo ${tape[$tape_index]} | |
| } | |
| tape_inc() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Benchmark brainf*ck program | |
| >++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ | |
| [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ | |
| ++++++++[>++++++++++[>++++++++++[>++++++++++[>+ | |
| +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Any, Dict, Optional | |
| from dataclasses import dataclass | |
| MISSING = 'missing' | |
| def mro(o): | |
| yield o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Type: | |
| def __init__(self, name, *, method_table=None, parent=None): | |
| self.name = name | |
| self.method_table = method_table or {} | |
| self.parent = parent | |
| def resolve_method(self, name, /): | |
| if name in self.method_table: | |
| return self.method_table[name] | |
| elif self.parent is not None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from collections import defaultdict | |
| from secrets import token_bytes | |
| def roll(num_sides: int) -> int: | |
| assert num_sides > 0, 'cannot have no sides' | |
| return int.from_bytes(token_bytes(48), 'little') % num_sides + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FNV_PRIME_64 = 1099511628211 | |
| FNV_OFFSET_BASIS_64 = 14695981039346656037 | |
| def hash(s: str) -> int: | |
| val = FNV_OFFSET_BASIS_64 | |
| for c in s: | |
| val ^= ord(c) | |
| val *= FNV_PRIME_64 | |
| return val |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| nnoremap <leader>z :%s/ -> [^:]\+:/:/gc<CR> | |
| nnoremap <leader>T :%s/\([^']\): [^,)]\+\([,)]\)/\1\2/gc<CR> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| template <int N> | |
| struct Fib { | |
| enum { | |
| value = Fib<N - 2>::value + Fib<N - 1>::value, | |
| }; | |
| }; | |
| template <> | |
| struct Fib<1> { | |
| enum { |