Skip to content

Instantly share code, notes, and snippets.

fbparis fbparis

Block or report user

Report or block fbparis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fbparis
fbparis / kik.py
Last active Mar 18, 2019
A replacement for the indexed trie data-structure with a very low memory footprint!
View kik.py
"""
kik (key to index to key) is a new implentation of indexed trie (https://gist.github.com/fbparis/e114958a4a9be84146a1a579cf677e8d) reducing memory footprint by a factor 7 or more!
The main differences with indexed tries are:
* Trie nodes are no longer stored in Node objects but in a python list. An internal mechanism use the list to simulate a tree behaviour, without any recursive function.
* Nodes and values stored in the kik can be compressed with several compression levels:
* None: no compression at all
* 0: data are stored as pickle.dumps (memory use divided by 3-4)
* -1, 1 to 9: pickle.dumps are compressed with zlib
* Some internal methods can be cached with a custom implentation of a LRU cache.
@fbparis
fbparis / indexedtrie.py
Last active Mar 12, 2019
A very powerful and memory safe data-structure to replace python's dict: Indexed Radix Trie
View indexedtrie.py
"""
A Python3 indexed trie class.
An indexed trie's key can be any subscriptable object.
Keys of the indexed trie are stored using a "radix trie", a space-optimized data-structure which has many advantages (see https://en.wikipedia.org/wiki/Radix_tree).
Also, each key in the indexed trie is associated to a unique index which is build dynamically.
Indexed trie is used like a python dictionary (and even a collections.defaultdict if you want to) but its values can also be accessed or updated (but not created) like a list!
Example:
>>> t = indextrie()
View perfectcipher.py
import os
from math import factorial
from random import seed, randrange
class PerfectCipher(object):
"""
Each byte (0-255) of a message is replaced using a translation table which is a permutation of [0..255].
After each replacement a new translation table is used using a Linear Congruential Generator to act as a PRNG:
Next N = (a * N + c) % m
Where m is 256! (total count of [0..255] permutations) and a and c carefully chosen so that the period of the PRNG is equal to m.
@fbparis
fbparis / lorem-client.py
Last active Dec 29, 2018
Client and Server using LoremVPN protocol
View lorem-client.py
import sys
import socket
import zlib
from loremvpn import LoremVPN
if __name__ == '__main__':
VPN = LoremVPN("demo", "demo")
HOST, PORT = "localhost", 9999
data = " ".join(sys.argv[1:]).encode()
@fbparis
fbparis / example.log
Last active Dec 29, 2018
Coding/decoding any binary data to/from random textual content (here Lorem Ipsum like)
View example.log
>>> vpn.Encode(r.content)
2018-12-28 15:18:01,876 loremvpn INFO Data inflated by factor 7.33 (2.79 after zlib compression)
'faugiames metrumstietum orcurat metrie rid ortumst lumstiuscilisit teantum te lum har lia har mesuat orpitorpibustrumstietus faugit fames fam cullicumst nenisiscillandumst lignimes pentenentinc mes la cust custorassapisiturascillustacenaestrumst cullucitur ur nea tea acu ac landie orpis orpitorpitiesel ur lend erius fam peliac fam cust netumstostrumstatem nenascibust las mesemes lucillum lassi sem lasciliam faucincitac orcitiesuat culassectos acienia penibuscitienasciostateandui uraesuam daliscit tetrum semese aculutandui orcu lac harcibenisi hasse hassimet pellusci lac faucie orpenti laceliacuscin ortit iduiss orpitiac lemposustortustrum idignimis orci neandio idapiesus selesumstacustiestincur neanduisit liturumstiesellit orpelibendumstienistrutac neturientur har urassem licincid orpeneandit fam penibendumstiscidio se landignimi ida met tetriscieneneandimes lesumstor mesempostrius iding
View frog-hunting.py
import random
s, z, n = 0, 0, 0
dx, dy = 0, -1
# Let keep it simple :-)
frog = random.randint(-100, 100)
jump = random.randint(-100, 100)
while 1:
i = s + n * z
n += 1
@fbparis
fbparis / ratelimiting.py
Last active Nov 26, 2018
Generic decorator to handle multiple rate limits in API calls
View ratelimiting.py
import sys, time
from collections import deque
_DEFAULT_POLICY = {1:1}
def rate_limited(*args):
"""
policy is an object where each key is a time interval in seconds and each value is a maximum number of requests during this interval.
{1:1} means 1 request max per second
{1:5} means 5 requests max per second
View keybase.md

Keybase proof

I hereby claim:

  • I am fbparis on github.
  • I am fbparis (https://keybase.io/fbparis) on keybase.
  • I have a public key ASAcgU_l1t3GqfnvA9KDRH26an9d87ZCaQ9Xzo3H12o6fQo

To claim this, I am signing this object:

View spinner.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Python Spintax parser
This module provides an efficient spintax parser where every possible spuns have the same probability.
Given a masterspin you can get the total number of possible spuns or a randomly chosen spun.
"""
@fbparis
fbparis / gist:f623c78adfc24b7dd47e5510a7152ea6
Created Jun 2, 2016
Vous en avez marre de ces grèves et de ces blocages, faites le savoir !
View gist:f623c78adfc24b7dd47e5510a7152ea6
Vous en avez marre de ces grèves et de ces blocages, faites le savoir !
------------------------------------------------------------------------------
Coupon à envoyer à votre employeur
------------------------------------------------------------------------------
Je soussigné __________________ __________________,
Aujourd'hui je travaille, je ne revendique rien, je demande à ne pas bénéficier
You can’t perform that action at this time.