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
| @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 |
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 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. ''' |
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 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. | |
| * |
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 | |
| 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)) |
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
| """ | |
| 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 |
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
| 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 |
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
| #!/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 = {} |
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
| # Located in Lib/collections/__init__.py | |
| ################################################################################ | |
| ### OrderedDict | |
| ################################################################################ | |
| class _OrderedDictKeysView(KeysView): | |
| def __reversed__(self): | |
| yield from reversed(self._mapping) |
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 random, math | |
| outputdebug = False | |
| def debug(msg): | |
| if outputdebug: | |
| print msg | |
| class Node(): | |
| def __init__(self, key): |
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
| ''' | |
| 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__) |