h = [
lambda a, b, c, d: 0,
lambda a: 0,
lambda a, b, c, d, e, f, g, h: 0,
lambda a, b, c, d, e, f, g, h: 0,
lambda a, b, c, d, e, f, g, h, i, j, k: 0,
None,
lambda a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, x, t: 0,
lambda a, b, c, d, e, f, g, h, i, j, k, l: 0,
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 pymongo import MongoClient | |
| from decimal import localcontext | |
| from math import sqrt, log2 | |
| from bson import Decimal128 | |
| from bson.decimal128 import create_decimal128_context | |
| coll = MongoClient().db.coll | |
| coll.drop() | |
| def Dec(x): | |
| with localcontext(create_decimal128_context()) as ctx: | |
| return Decimal128(ctx.create_decimal(x)) |
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
| import os,select,tty,sys | |
| from time import time | |
| from functools import partial | |
| # Need this because Unix-esque OSes are different from Windows. | |
| try: | |
| from msvcrt import getch as cf | |
| except ImportError: | |
| tty.setcbreak(sys.stdin.fileno()) | |
| cf=partial(sys.stdin.read,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
| from multiprocessing import Process | |
| import psutil | |
| from time import sleep | |
| def ascii_bomb(): | |
| return [ | |
| """ | |
| .,-:-,,. |
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
| import os | |
| timestep=1./60 | |
| gravity=-9.81 | |
| tg=timestep*gravity | |
| s_x,s_y=10,20 | |
| u=v=[[.0 for A in range(s_y)]for A in range(s_x)] | |
| pr=[[.0 for A in range(s_y)]for A in range(s_x)] | |
| st=[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[0,1,1,1,1,0,.1,0,0,.1,.1,.1,.1,.1,.1,.1,0,0,0,0],[0,1,1,1,1,1,.1,.1,.1,.1,.1,.1,.1,.1,.1,0,0,0,0,0],[0,1,1,1,1,1,.1,.1,.1,.1,.1,.1,.1,.1,.1,0,0,0,0,0],[0,.1,0,1,1,1,.1,.1,.1,.1,.1,.1,.1,.1,.1,0,0,0,0,0],[0,.1,0,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,.1,0,0,0,0,0,0],[0,.1,0,.2,.1,.1,.1,0,.1,.1,.1,.1,0,0,0,0,0,0,0,0],[0,.1,0,0,.2,.1,.1,0,.1,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]] | |
| C=1e3/timestep | |
| loop=[(A,B)for A in range(1,len(u)-1)for B in range(1,len(u[0])-1)] |
zlib underlies most zip file decompressors, and DEFLATE is one the binary formats used to store compressed data in a bitstream.
The goal of this article is to walk through how my Python DEFLATE compressor implementation works. There are many
guides on the internet that describe how to implement each step of DEFLATE, but very few end up producing a bitstream
that can actually be parsed by a library like zlib. This article assumes that you roughly know how each step of the DEFLATE algorithm
is implemented, but are having trouble with some of the finer points that are often glossed over.
The code can be found in "deflate.py".
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
| import sys;itls,colls,binasc,struct,time=[\ | |
| __import__(i) for i in("itertools",\ | |
| "collections","binascii","struct","time")];\ | |
| s=sys.stdin.read();(MOFFSET,MLENGTH,\ | |
| FILE_NAME,ZIP_NAME, | |
| idx)=(2047,31,"a.txt" | |
| , "a.zip", 0); \ | |
| compressed=[((*\ | |
| lo,s[idx]),idx:=\ | |
| idx+lo[1])[0] for\ |
OlderNewer