Skip to content

Instantly share code, notes, and snippets.

@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)
@0xack13
0xack13 / avl_tree.py
Created December 18, 2020 14:31 — forked from girish3/avl_tree.py
AVL tree implementation in python
#import random, math
outputdebug = False
def debug(msg):
if outputdebug:
print msg
class Node():
def __init__(self, key):
@0xack13
0xack13 / 2pc.py
Created December 22, 2020 15:29 — forked from affo/2pc.py
Implementation of 2 Phase Commit protocol
'''
Implementation of 2 Phase Commit as explained at Wikipedia:
https://en.wikipedia.org/wiki/Two-phase_commit_protocol
'''
import random, logging, time
from threading import Thread, Semaphore, Lock
_fmt = '%(user)s:%(levelname)s >>> %(message)s'
logging.basicConfig(format=_fmt)
LOG = logging.getLogger(__name__)