Skip to content

Instantly share code, notes, and snippets.

View calvang's full-sized avatar
🎯
Focusing

Calvin Huang calvang

🎯
Focusing
View GitHub Profile
@calvang
calvang / latest_gh_release.py
Created December 25, 2020 22:00
CLI utility to detect a specific binary from the latest Github release given a repository and a list of keywords. Returns either the full url to retrieve the binary or the filename of the binary.
import sys
import requests
if len(sys.argv) < 4:
print(
"""Invalid arguments.
Format: python3 latest_github_release.py <repo> [OPTIONS] <keywords>.
Type 'help' in options for more.""")
exit(1)
if sys.argv[2] == "help":
@calvang
calvang / url_unshorten.py
Created January 31, 2021 04:52
Brief python3 script to recursively unmask url's that have been shortened.
from sys import argv
from requests import head
def url_unshorten(url, verbose=True):
full_url = head(url, allow_redirects=True).url
verbose and print(full_url)
return full_url
if __name__ == '__main__':
url_unshorten(argv[1])
@calvang
calvang / pika_mock.py
Created July 11, 2021 03:01
Mock AMQP connection using Pika RabbitMQ Client
from unittest.mock import patch
import pika
def callback_func(channel, method, properties, body):
print("Message consumed:", body)
@patch("pika.BlockingConnection", spec=pika.BlockingConnection)
def mock_publish(mock_conn):
def side_effect_publish(exchange, routing_key, body):
print(f"Message published to {routing_key}:", body)
@calvang
calvang / http2ssh.py
Last active August 21, 2021 22:28
Migrate Github repositories from HTTP to SSH for a given username
import os
from sys import argv
import re
import subprocess
user = None
ignore = [
"node_modules",
".git",
"env",