Skip to content

Instantly share code, notes, and snippets.

View chriskyfung's full-sized avatar

Chris K.Y. FUNG chriskyfung

View GitHub Profile
@chriskyfung
chriskyfung / history.sh
Created March 27, 2025 08:42
A Bash script to display shell history with flexible timestamp formats, timezone support, and custom options for enhanced usability.
#!/bin/bash
# Enhanced History Viewer v1.0 - Flexible Timestamp Formats
# Generated by Qwen2.5-Max
# Get the script name correctly for both sourced and executed contexts
SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
# Function to display help message
show_help() {
echo "Usage: source $SCRIPT_NAME [OPTIONS]"
@chriskyfung
chriskyfung / log_helper.sh
Last active March 27, 2025 07:58
Bash logging tool with quick color-coded log viewing, sanitization, man support, and auto-rotation for Ubuntu.
#!/bin/bash
# Comprehensive Log Helper v2.3.0 - Quick View & Man Page Support
# Generated by Qwen2.5-Max
LOG_FILE="$HOME/admin.log"
VALID_LEVELS=("INFO" "WARN" "ERROR")
RED='\033[0;31m'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
@chriskyfung
chriskyfung / countryRedirect.js
Created February 8, 2025 07:59
Implement country-based redirection in Cloudflare Workers
/**
* Welcome to Cloudflare Workers! This is your first worker.
*
* - Run "npm run dev" in your terminal to start a development server
* - Open a browser tab at http://localhost:8787/ to see your worker in action
* - Run "npm run deploy" to publish your worker
*
* Learn more at https://developers.cloudflare.com/workers/
*/
@chriskyfung
chriskyfung / delete_disabled_workflow_runs.sh
Created January 3, 2025 01:49
A bash script to delete all workflow runs for GitHub Actions workflows with the status "disabled_manually".
#! /bin/bash
# Script to delete all workflow runs for workflows with the status "disabled_manually"
# This script uses the --jq option of GitHub CLI to filter JSON data directly,
# avoiding the need to pipe through the jq command.
# Modified from: https://stackoverflow.com/a/67000032
# Define your organization and repository
org=<your org>
repo=<your repo>
@chriskyfung
chriskyfung / .gh-repo-clone-completion.bash
Last active February 2, 2025 02:58
My sets up GitHub CLI completions and a custom function for to suggest repository names and Git flags.
# Custom bash completion function for 'gh repo clone' command
#
# Copyright (C) 2024 Chris K.Y. Fung (chriskyfung.github.io)
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# To use these routines:
#
# 1) Copy this file to somewhere (e.g. ~/.gh-repo-clone-completion.bash).
# 2) Add the following line to your .bashrc/.zshrc:
@chriskyfung
chriskyfung / importCalendarEventsToSheet.gs
Created May 6, 2024 09:19
This Google Apps Script automatically searches a calendar you specify for events within the last year that contains specific text and writes their details to a Google Spreadsheet. You can further modify and extend this script as needed.
function importCalendarEventsToSheet() {
//Set the calendar ID and text to search for
var calendarId = '[email protected]';
var searchText = 'your_search_text';
// Get calendar events
var events = getCalendarEvents(calendarId, searchText);
//Write event data to the spreadsheet
writeEventsToSheet(events);
@chriskyfung
chriskyfung / Microsoft.PowerShell_profile.ps1
Last active February 7, 2024 06:45
My PowerShell Profile
# Import the posh-git module that provides Git integration, including autocomplete functionality
# See http://dahlbyk.github.io/posh-git/ for details.
Import-Module posh-git
# Generate the autocompletion script for GitHub CLI
# See https://cli.github.com/manual/gh_completion for details.
Invoke-Expression -Command $(gh completion -s powershell | Out-String)
@chriskyfung
chriskyfung / Dockerfile
Created August 7, 2023 06:41
Dockerfile to build an image from bitnami/git with GitHub CLI and BFG Repo-Cleaner installed
FROM bitnami/git:latest
LABEL maintainer="@chriskyfung"
RUN apt update && apt install -y \
curl \
gpg
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg;
RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
| tee /etc/apt/sources.list.d/github-cli.list > /dev/null
@chriskyfung
chriskyfung / Resize-TheBrainNotesYouTubeThumbnail.ps1
Last active November 22, 2023 01:22
A PowerShell script to resize all YouTube thumbnails down to 30% in your theBrain Notes
<#
.SYNOPSIS
Resize YouTube thumbnails down to 30% in theBrain Notes
.DESCRIPTION
Append `#$width=30p$` to the image address within the Markdown files
.PARAMETER None
.INPUTS
@chriskyfung
chriskyfung / Adb-PullAppData.ps1
Created April 1, 2023 17:33
A PowerShell script interactively guides you pull app data from (/sdcard/Android/data/) to your local machine via Android Debug Bridge (adb)
<#
.SYNOPSIS
Pull Android App data from the internal storage of
a device via Android Debug Bridge (adb).
.DESCRIPTION
The Adb-PullAppData.ps1 script uses interavtive prompts to guide you pull app data
from (/sdcard/Android/data/$APPNAME) to the local machine.