This file contains 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
/** | |
* Get an element by XPath. | |
* @param {string} expression - A string representing the XPath to be evaluated. | |
* @param {Element} [context] - The context node. Defaults to the current document. | |
* @param {Document} [document] - The document against which evaluate() will be called. Defaults to the context node's document. | |
* @param {boolean} [ordered=true] - Whether to return the "first" node selected by the expression. If false, allows the XPath engine to return an arbitrary node selected by the expression. | |
* @returns {Element|null} | |
*/ | |
function getElementByXPath(expression, context = null, document = null, ordered = true) { | |
if (context === null) context = window.document; |
This file contains 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
#!/bin/bash | |
set -e | |
set -o pipefail | |
# USAGE: | |
# bash gamertag_to_xuid.sh GAMERTAG [...] > out.csv | |
# DEPENDENCIES: | |
# - GNU Bash version 4 or newer (or any shell supporting pipefail, heredocs, read, readarray, and POSIX printf) | |
# - GNU sed version ?? or newer (or any sed implementation supporting, -n, -e, the "p" flag to "s", and capturing-group references in substitution) |
This file contains 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 email.message, email.parser, email.policy | |
import urllib.parse | |
import re | |
from collections import namedtuple | |
try: | |
from resource import getpagesize | |
except ImportError: | |
import mmap | |
def getpagesize(): | |
return mmap.PAGESIZE |
This file contains 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 Bitwise | |
require Logger | |
# "MEkDAgcAAgEgAh9n5rQmt3zJukGmwwvEVwfbZFS3NJ9oW7hgpJ0Db5ORAh8mOLmbP3+DfEQvEFbOcqymWoF6s9GHVcv8UegJBcWz" 3210790 1959110000000 | |
defmodule TS3H do | |
def cmd_main(argv) do | |
[pk_str, ctr_best, ctr_cur] = |
This file contains 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
defmodule BitStringStream do | |
def binary_to_stream(s) do | |
Stream.unfold(s, fn | |
<<next::8, rem::binary>> -> {next, rem} | |
<<>> -> nil | |
end) | |
end | |
def bitstring_to_stream(s, n) do |
This file contains 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
# Usage: | |
# import _cachedir | |
# CACHEDIR = _cachedir.cachedir('my_application@company.com') | |
# CACHEDIR = _cachedir.cachedir('my_packagename@pypi.org') | |
# NOTE: | |
# This does not create a secure enclave of any kind. | |
# Obviously, malicious applications running on the same | |
# user account could read or modify the cache directory. |
This file contains 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 contextlib import contextmanager, ExitStack | |
import io | |
__all__ = ['maybe_open'] | |
@contextmanager | |
def maybe_open(file_or_path, mode, *, **k, mode_strict=False): | |
with ExitStack() as _inner_ctx: | |
if isinstance(file_or_path, io.IOBase): |
This file contains 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 contextlib import contextmanager | |
import select | |
import signal | |
import socket | |
try: | |
from resource import getpagesize | |
except ImportError: | |
import mmap | |
def getpagesize(): |
This file contains 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 contextlib import contextmanager | |
import tkinter as tk # https://stackoverflow.com/questions/66734619/no-module-named-tkinter#66735147 | |
import tkinter.messagebox | |
# Two different approaches to handling mainloop errors in tkinter. | |
# 1. A context manager that will display errors in callbacks and initializers (RECOMMENDED) | |
# 2. A subclass of Tk that will only display errors in callbacks, not initializers | |
@contextmanager |
This file contains 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 itertools import combinations, permutations | |
import re | |
MIN_LENGTH = 4 | |
ILLEGAL_PATTERN_RE = re.compile('(%s)' % '|'.join( | |
# Simulate negative lookbehind via negative lookahead | |
# h/t https://learnbyexample.github.io/py_regular_expressions/lookarounds.html#negated-groups | |
f'^(?!.*{b}.*{a}{c}).*{a}{c}' for a,b,c, in | |
['123', '159', '147', '258', '369', '357', '321', '456', '654', '789', '741', '753', '852', '987', '951', '963'] |