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 http.client | |
| conn = http.client.HTTPSConnection("HOSTNAME") | |
| payload = 'grant_type=password&username=USERNAME&password=PASSWORD' | |
| headers = { | |
| 'Authorization': 'Basic abcdef0123456==', | |
| 'Content-Type': 'application/x-www-form-urlencoded' | |
| } | |
| conn.request("POST", "/api/oauth/token", payload, headers) | |
| res = conn.getresponse() | |
| data = res.read() |
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
| """Unquote a URL-encoded string | |
| adapted from https://gist.github.com/scottcode/374a3849f96ba29624fd7dd6c4fa1074""" | |
| import sys | |
| import urllib.parse | |
| def unquote(string): | |
| return urllib.parse.unquote(string.strip()) |
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
| # Jq querying | |
| jq 'path(.. | select(.target?))' example.json | |
| jq '.. | select(.target?) | .target' example.json | |
| # Or you can do the same as above on YAML files by using yq and the .yml file as the argument |
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 SetComparer: | |
| def __init__(self, a, b): | |
| self.a = set(a) | |
| self.b = set(b) | |
| @property | |
| def union(self): | |
| return self.a | self.b | |
| @property |
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 networkx as nx | |
| G: nx.Graph | |
| nodes: set | |
| adjacency_map = { | |
| node: set(G.neighbors(node)) | |
| for node in nodes | |
| } |
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
| # where 'bkp' is a remote corresponding to a bare local repository in a cloud-synced folder | |
| git stash push --include-untracked | |
| git branch stashed/DATE stash@{0} | |
| git push -u bkp stashed/DATE | |
| git stash pop | |
| git_backup () { | |
| local remote=$1 | |
| if [ -z "$remote" ] |
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
| # Following goes in ~/.ssh/config to ensure that OpenSSH uses the appropriate proxy | |
| ProxyCommand connect -H proxy_host:proxy_port %h %p |
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
| url=https://example.com/my%20quoted%20url | |
| echo $url | python -c "import sys, urllib.parse; print(urllib.parse.unquote(sys.stdin.read().strip()))" |
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
| ' taken from https://docs.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/count-cells-number-with-color-using-vba | |
| Function CountCcolor(range_data As Range, criteria As Range) As Long | |
| Dim datax As Range | |
| Dim xcolor As Long | |
| xcolor = criteria.Interior.ColorIndex | |
| For Each datax In range_data | |
| If datax.Interior.ColorIndex = xcolor Then | |
| CountCcolor = CountCcolor + 1 | |
| End If | |
| Next datax |
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
| """ | |
| For inspiration on how to do decorators with optional first calls before the decoration, | |
| see example in pytest.fixture: | |
| https://github.com/pytest-dev/pytest/blob/8300b266a8e48b7db2240ae5b52632f018d2c0bd/src/_pytest/fixtures.py#L1339 | |
| """ | |
| class decorated(object): | |
| """https://stackoverflow.com/a/48491028/1789708""" | |
| def __init__(self, func, type_=None): |
NewerOlder