misc_python

Sean's miscellaneous Python code that's not big enough for its own repo.
Log | Files | Refs | README | LICENSE

commit 9ba936b52808716f0e67072e8549fad8d1945954
parent 45590ff9bb50c223f92d3f27e44b14c36ae30354
Author: Sean Lynch <seanl@literati.org>
Date:   Thu, 21 Feb 2019 20:46:38 -0800

Remove useless scripts

Some of the scripts didn't really have enough in them to be worth keeping.

Diffstat:
Dbwt.py | 14--------------
Dotr.py | 25-------------------------
Drabin.py | 54------------------------------------------------------
Drocket.py | 60------------------------------------------------------------
Dtest.py | 12------------
5 files changed, 0 insertions(+), 165 deletions(-)

diff --git a/bwt.py b/bwt.py @@ -1,14 +0,0 @@ -#!/usr/bin/python -import sys - -def main(): - data = sys.stdin.read() - def bwt_cmp(a, b): - return cmp(data[a+1:], data[b+1:]) - indexes = range(len(data) + 1) - indexes.sort(cmp=bwt_cmp) - print ''.join([data[i] if i < len(data) else '' for i in indexes]) - - -if __name__ == '__main__': - main() diff --git a/otr.py b/otr.py @@ -1,25 +0,0 @@ -#!/usr/bin/python - -from ctypes import * - -_o = cdll.LoadLibrary('/usr/lib/libotr.so.2') -_o.otrl_init(3, 0, 0) - -class UserState(object): - def __init__(self): - self._p = _o.otrl_userstate_create() - - def __del__(self): - _o.otrl_userstate_free(self._p) - - def privkey_read(self, filename): - _o.otrl_privkey_read(filename) - - def privkey_read_fingerprints(self, filename): - _o.otrl_privkey_read_fingerprints(self._p, filename, None, None) - - def :wq - - - - diff --git a/rabin.py b/rabin.py @@ -1,54 +0,0 @@ -#!/usr/bin/python - -def bin(x, n=32): - s = '' - for i in xrange(32): - s = str(x & 0x1) + s - x >>= 1 - - return s - - -class Rabin(object): - def __init__(self, p=0xab59b4d1): - self.p = p - self.table = self.calculate_t8_table() - #self.window_table = self.calculate_window_table(16) - - def calculate_t8_table(self): - # This table is the result of multiplying by t**8 given the high-order 8 bits - return [ self.table_entry(i) for i in xrange(256) ] - - def calculate_window_table(self, window_size): - return [ self.multiply_repeatedly_by_t8(i, window_size) for i in xrange(256) ] - - def multiply_repeatedly_by_t8(self, x, n): - for i in xrange(n): - x = self.multiply_by_t8(x) - - return x - - def table_entry(self, i): - x = i << 24 - for j in xrange(8): - x = self.multiply_by_t(x) - print '%d\t%d\t%08x\t%s' % (i, j, x, bin(x)) - - return x - - def multiply_by_t8(self, x): - return ((x & 0xffffff) << 8) ^ self.table[x >> 24] - - def multiply_by_t(self, x): - if x & 0x80000000: - return ((x & 0x7fffffff) << 1) ^ self.p - else: - return x << 1 - - def fingerprint(self, fingerprint, s): - for c in s: - fingerprint = self.multiply_by_t8(fingerprint) ^ ord(c) - - return fingerprint - - diff --git a/rocket.py b/rocket.py @@ -1,60 +0,0 @@ -#!/usr/bin/python - -k1 = 0.190263 -k2 = 8.417286e-5 -E = 6369000L -L = 6.5 -g = 9.80665 -P0 = 101325 -T0 = 288.15 -R = 8.31432 -M = 28.9644 -Rd = 287.04 -Rv = 461.495 - -def actualPressure(AS, H): - """Actual pressure in mb from altimeter setting and geopotential elevation""" - return (AS**k1 - k2*H)**(1.0/k1) - -def vaporPressure(T): - """Vapor pressure in mb from dew point in K""" - eso=6.1078 - c0=0.99999683 - c1=-0.90826951e-2 - c2=0.78736169e-4 - c3=-0.61117958e-6 - c4=0.43884187*10-8 - c5=-0.29883885*10-10 - c6=0.21874425*10-12 - c7=-0.17892321*10-14 - c8=0.11112018*10-16 - c9=-0.30994571*10-19 - return eso*(c0+T*(c1+T*(c2+T*(c3+T*(c4+T*(c5+T*(c6+T*(c7+T*(c8+T*(c9))))))))))**(-8) - -def geometricAltitude(H): - """Geometric altitude from geopotential altitude""" - return (E*H)/(E-H) - -def geopotentialAltitude(Z): - return (E*Z)/(E+Z) - -#def densityAltitude(D): -# """Density altitude from density in kg/km^3""" -# return 44.3308 - 8.33851 * (D**0.324969) - -#def pressureAltitude(P): -# """Pressure altitude from actual pressure in pascals""" -# return 44.3308 - 4.94654 * (P**0.190263) - -def density(Pd, Pv, T): - """Density from dry air pressure in Pascals, vapor pressure in Pascals, and temperature in K""" - return (Pd / Rd * T) + (Pv + Rv * T) - -def airDensity(Z, AS, T, DP): - """Density from geometric altitude in meters, altimeter setting in millibars, temperature in K, and dew point in K""" - H = geopotentialAltitude(Z) - P = actualPressure(AS, H) - Pv = vaporPressure(DP) - Pd = P - Pv - return density(Pd, Pv, T) - diff --git a/test.py b/test.py @@ -1,12 +0,0 @@ -h1 = rolling_hash('hello')[-1] -h1 -h2 = rolling_hash(' world', start=h1)[-1] -h2 -h3 = rolling_hash('hello world')[-1] -h3 -h4 = rolling_hash(' world')[-1] -h4 -h5 = combine_hashes(h1, h4, 6) -h5 - -