Skip to content

Instantly share code, notes, and snippets.

In this tutorial we're going to build a set of parser combinators.

What is a parser combinator?

We'll answer the above question in 2 steps

  1. what is a parser?
  2. and.. what is a parser combinator?

So first question: What is parser?

@0xack13
0xack13 / bobp-python.md
Created September 30, 2020 02:29 — forked from sloria/bobp-python.md
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens
@0xack13
0xack13 / make-keys.bat
Created October 6, 2020 07:07 — forked from codingoutloud/make-keys.bat
Handy OpenSSL command-line combinations I've used - they might've been hard to find or come up with, so capturing them here.
@echo off
if _%1_==__ goto USAGE
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem -subj "/CN=My Cert Name"
openssl pkcs12 -export -out mycert.pfx -inkey mycert.pem -in mycert.pem -passout pass:%1
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer
openssl pkcs12 -in mycert.pfx -nodes -passin pass:%1 | openssl x509 -noout -fingerprint
openssl x509 -in mycert.pem -noout -fingerprint
@0xack13
0xack13 / use_pfx_with_requests.py
Created October 6, 2020 09:01 — forked from erikbern/use_pfx_with_requests.py
How to use a .pfx file with Python requests – also works with .p12 files
import contextlib
import OpenSSL.crypto
import os
import requests
import ssl
import tempfile
@contextlib.contextmanager
def pfx_to_pem(pfx_path, pfx_password):
''' Decrypts the .pfx file to be used with requests. '''
@0xack13
0xack13 / StoneWall.java
Created October 23, 2020 15:10 — forked from ceva24/StoneWall.java
A solution to the Stone Wall Codility problem
import java.util.ArrayList;
class Solution
{
public int solution(int[] H)
{
// rules
/*
* so when we find two indices that are of the same height, we can use the same block, providing all the values in-between are higher.
*
@0xack13
0xack13 / shardcalc.py
Created October 29, 2020 04:54 — forked from colmmacc/shardcalc.py
Calculate the blast radius of a shuffle shard
import sys
def factorial(n):
if n == 0:
return 1
else:
return n * factorial(n - 1)
def choose(n, m):
return factorial(n) / (factorial(m) * factorial(n - m))
@0xack13
0xack13 / parsec.py
Created November 1, 2020 04:46 — forked from higherorderfunctor/parsec.py
Port of Stephen Diehl's nanoparsec in Typed Python
"""
Port of nanoparsec in typed python from https://github.com/sdiehl/write-you-a-haskell/blob/master/chapter3/parsec.hs.
pip install attrs mypy
"""
from typing import Callable, Sequence, Text, Tuple, TypeVar
import attr
@0xack13
0xack13 / dfa.py
Created November 15, 2020 00:38 — forked from juanplopes/dfa.py
simple dfa in python
class Automaton:
def __init__(self, nstates):
self.transitions = [{} for i in range(nstates)]
self.accept_states = [False] * nstates
def register(self, source_state, char, target_state):
self.transitions[source_state][char] = target_state
def register_accept(self, state):
self.accept_states[state] = True
@0xack13
0xack13 / ordered_dicts_python.py
Created November 30, 2020 00:35 — forked from dgrant/ordered_dicts_python.py
An ordered dict implementation in Python using a second hash map to store the order information.
#!/usr/bin/env python
import random
import operator
import time
from collections import OrderedDict
import unittest
class ordered_dict(dict):
def __init__(self):
self.order = {}
@0xack13
0xack13 / ordered_dict.py
Created November 30, 2020 00:35 — forked from joequery/ordered_dict.py
Python 3.5.0b1 OrderedDict implementation
# Located in Lib/collections/__init__.py
################################################################################
### OrderedDict
################################################################################
class _OrderedDictKeysView(KeysView):
def __reversed__(self):
yield from reversed(self._mapping)