Skip to content

Instantly share code, notes, and snippets.

@gvx
gvx / PollCache.py
Last active March 17, 2020 17:37 — forked from dotchetter/PollCache.py
Call functions through the PollCache object for only receiving output from the function if new output is detected.
# disclaimer: untested code ahead! see https://www.reddit.com/r/Python/comments/fk4wal/i_needed_an_object_that_can_with_one_instance/fkrbodb/
from dataclasses import dataclass
from enum import Enum, auto
from typing import Any, Callable, Tuple
@dataclass
class CacheValue:
result: Any
times_changed: int = 1
@gvx
gvx / py2md.py
Last active February 1, 2017 20:12 — forked from AtHeartEngineer/py2md.py
#!/usr/bin/env python
# coding=utf-8
# <a class="btn btn-default pull-right" href="https://gist.github.com/TylerShaw/48ead56c19ce905ac513"><i class="fa fa-git"></i> Download the gist here!</a>
# Py2Md started as a little project to do the magical "self documenting code". After thinking about it, I realized self documenting code is great, but it's really not the point.
# Commenting code properly, if only better, is the point.
# This script evolved from me wanting to code better. I often look at other peoples code, or even old code I've written, and it takes me a few minutes to even figure out what each section is doing.
# This will hopefully solve that, not only by forcing me to comment code better, but to publish my code with decent comments.
# This script reads in a python file (either itself, or anything it's
# imported into) and converts the python file into a markdown file. It
class LinkedList:
next = None
val = None
def __init__(self, val):
self.val = val
def add(self, val):
if self.next is None:
self.next = LinkedList(val)
@gvx
gvx / bf2c.py
Created May 25, 2012 07:39 — forked from jdp/bf2c.py
Naive brainfuck-to-C transpiler
#!/usr/bin/env python
import argparse
import sys
def tokenize(source):
return list(source)
def parse(tokens):