Skip to content

Instantly share code, notes, and snippets.

@lrq3000
lrq3000 / pylistmodules.py
Last active September 17, 2023 19:27
List recursively all imports of modules along with versions done from your Python application. Tested on Python 2.7. No dependencies except standard Python libs.
#!/usr/bin/env python
# encoding: utf-8
# Copyright (C) 2001-2007 Martin Blais. All Rights Reserved
# Copyright (C) 2010 Bear http://code-bear.com/bearlog/
# Copyright (C) 2013 lrq3000
# Excerpt from SnakeFood to recursively list all imports of modules using AST parsing
# Additions to print the versions of each module if available
@tmr232
tmr232 / loop_label.py
Created March 4, 2014 19:42
Loop Labels - Python hack for breaking out of nested loops.
class LoopLabel(object):
def __init__(self):
super(LoopLabel, self).__init__()
class MyLoopLabel(Exception): pass
self._label_exception = MyLoopLabel
def __enter__(self):
return self._label_exception
@tylerneylon
tylerneylon / copy.lua
Last active August 11, 2024 21:49
How to deep copy Lua values.
-- copy.lua
--
-- Lua functions of varying complexity to deep copy tables.
--
-- 1. The Problem.
--
-- Here's an example to see why deep copies are useful. Let's
-- say function f receives a table parameter t, and it wants to
@adamnew123456
adamnew123456 / pyc.py
Last active June 10, 2024 07:12
Using Inline C Code In Python Programs
"""
Inserts C code directly into Python files, which can then be dynamically linked
in and called via ctypes.
"""
import atexit
import ctypes
import os
import shlex
import sys
import tempfile
@divergentdave
divergentdave / .gitignore
Last active May 26, 2020 13:30
Inheritance with PLY (Python Lex-Yacc)
*.pyc
@edmundsmith
edmundsmith / writeup.md
Created July 7, 2019 20:47
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

@EkremDincel
EkremDincel / microstream.py
Last active July 15, 2020 00:45
A little TCP socket interface for Python.
import json
import socket
from struct import Struct, calcsize
from select import select
__all__ = ("Server", "Client", "localhostname", "localhost", "LAN", "WAN")
_int = "H" # 0 <= number <= 65535 == 2 ** 16 -1
_size = calcsize(_int)
_struct = Struct("!" + _int)

Redesigning coca's Storage Abstraction

This post was written primarily to organize my thoughts during the design process. I'll explain the thought process that led me to each point in the design space we visit, then point out any issues, which will lead into the next iteration. Along the way, I made a few errors, which I'll try to rectify in the (Side Notes).

Here we go!

Introduction: The Status Quo