Skip to content

Instantly share code, notes, and snippets.

import ctypes
# Create a function prototype for a 3-arg function
ternaryfunc = ctypes.CFUNCTYPE(ctypes.py_object, ctypes.py_object,
ctypes.py_object, ctypes.c_void_p)
# Define a new python type that's callable, via a ternaryfunc
class PyTypeObject(ctypes.Structure):
Ivoz /
Created Jul 20, 2020
If you are able to run python code, use this to add python to your path on windows
import sys
from pathlib import Path
# Get the path to the Scripts directory
scripts_path = Path(sys.base_prefix) / "Tools" / "Scripts"
# Append it to python's import path so we can grab it
# Import the main function from the win_add2path script
from win_add2path import main
# run the main function to add python to out path
* $RCSfile$
* $Revision: 3657 $
* $Date: 2002-09-09 08:31:31 -0700 (Mon, 09 Sep 2002) $
* Adapted from Markus Hahn's Blowfish package so that all functionality is
* in a single source file. Please visit the following URL for his excellent
* package:
* Copyright (c) 1997-2002 Markus Hahn <>
Ivoz /
Last active Dec 25, 2017
Naive way to solve the Discrete Logarithm Problem
#!/usr/bin/env python
from __future__ import print_function
def find_discrete_log(h, g, p):
H = {}
print('Generating table...')
for x1 in range(0, B):
gx1inv = mod_mul_inv(pow(g, x1, p), p)
H[(h * gx1inv) % p] = x1
Ivoz /
Last active Jan 31, 2016
A self-checking python quine, of sorts
#!/usr/bin/env python3
A "self-verifying" quine - `<quine> <source_file>` will only print itself
if `<quine>` has the same output as `cat <source_file>`
source = r'''{foreword}
import sys, subprocess
if len(sys.argv) > 1:
Ivoz /
Last active Jan 3, 2016
How to replicate labelled linking with rst?
View gist:7035239
from __future__ import absolute_import, division, print_function
from cryptography.bindings import _default_api
class BlockCipher(object):
def __init__(self, cipher, mode, api=None):
super(BlockCipher, self).__init__()
if api is None:
View .gitignore
import os
import sys
from os.path import join
from fabric.api import local
BASE_DIR = os.path.realpath(os.path.dirname(__file__))
BUILD_DIR = join(BASE_DIR, '_build')
SOURCE_DIR = join(BASE_DIR, 'source')
LOCALE_DIR = join(SOURCE_DIR, 'locale',
View copyright.pot