Skip to content

Instantly share code, notes, and snippets.

View alexjyong's full-sized avatar

Alex Yong alexjyong

View GitHub Profile
@alexjyong
alexjyong / MarsAndMoonTime.py
Created February 26, 2024 21:43
Script to calculate mars and moon time at a given location.
from datetime import datetime, timezone
import pytz
# Constants for Martian and Lunar day lengths in seconds
MARS_DAY_LENGTH = 88775.244
MOON_DAY_LENGTH = 2551442.8 # Average lunar day
# Function to get Earth time in a specific timezone
def get_earth_time(timezone):
tz = pytz.timezone(timezone)
@alexjyong
alexjyong / RestoreDeletedBranch.md
Last active October 25, 2023 19:30
Restore a deleted branch
  1. Fire up a codespace instance in the repo
  2. Run gh api repos/OWNER/REPO/events > myJson.json
  3. The JSON that comes out is unreadable, so clean it up with jq . myJson.json > clean.json
  4. Go through the json file, find the DeleteEvent where you nuked your branch, and below it, find the last push event you did to your branch. In the payload, find the head's SHA and grab it.
  5. Create a JSON file in this format
{
  "ref": "refs/heads/YOUR_BRANCH_NAME",
  "sha": "SHA_VALUE"
}
@alexjyong
alexjyong / googleDriveList.py
Created August 23, 2023 01:57
get file list from google drive
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
ACCESS_TOKEN = 'YOUR_ACCESS_TOKEN_FROM_PLAYGROUND'
def bytes_to_human_readable(byte_size):
"""Convert bytes to human-readable file sizes."""
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if byte_size < 1024.0:
return f"{byte_size:.2f} {unit}"
@alexjyong
alexjyong / HelpfulCommands.md
Created August 22, 2023 14:06
helpful commands

These are commands I've found helpful for day to day work.

Generally geared for *nix environments.

Nuke all docker resources on a machine.

docker rm -f $(docker ps -a -q) && docker rmi -f $(docker images -q) && docker volume rm $(docker volume ls -q) && docker network rm $(docker network ls -q) && docker system prune -a --volumes -f
@alexjyong
alexjyong / codespace_port_forward.sh
Created June 22, 2023 20:09
codespace_port_forward.sh
#!/bin/bash
#this script is meant to be ran on your local machine with gh installed.
#it is not meant to be ran within codespaces.
# this will select a codespace from a repo of your choosing and forward the ports to your
#local machine, so you can visit any process running on the codespace in your browser instead of going to the
# complex codespace generated url, which may break some code.
# this is pretty much the codespace version of this for gitpod https://www.gitpod.io/blog/local-app
# Function to clean up port forwarding processes
@alexjyong
alexjyong / bot.py
Last active June 16, 2023 20:07
gist for my poll bot. too lazy to make a repo rn
import discord
from discord.ext import commands
# Set up the bot prefix
prefix = "!"
# Create a bot instance with intents
intents = discord.Intents.all()
intents.typing = False # Disable typing event (optional)
intents.presences = False # Disable presence event (optional)

How to create a Dynamic Manual Workflow with Github Actions

Overview

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

Context

With all this feature, it's still missing some feature like making a request before a the workflow is created.

@alexjyong
alexjyong / base64Html.js
Last active April 13, 2023 12:54
Converts an html page with image links to an html page with base64 links in node.js
const fs = require('fs');
const request = require('request');
const { JSDOM } = require('jsdom');
const $ = require('jquery');
const pretty = require('pretty');
function convertImagesToBase64(inputFile, outputFile) {
fs.readFile(inputFile, 'utf8', (err, htmlContent) => {
if (err) throw err;
@alexjyong
alexjyong / base64Html.py
Last active April 14, 2023 18:59
Converts an html page with image links to an html page with base64 links in python
import sys
import base64
import requests
from bs4 import BeautifulSoup
def convert_images_to_base64(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as f:
html_content = f.read()
soup = BeautifulSoup(html_content, 'html.parser')
@alexjyong
alexjyong / pasteEnabler.js
Created January 6, 2023 14:51
Renable paste on web pages that block it
var allowPaste = function(e){
e.stopImmediatePropagation();
return true;
};
document.addEventListener('paste', allowPaste, true);