Skip to content

Instantly share code, notes, and snippets.

View teshanshanuka's full-sized avatar

Teshan Liyanage teshanshanuka

View GitHub Profile
@teshanshanuka
teshanshanuka / gh-helpers.sh
Created September 17, 2023 09:39
GitHub CLI helpers
# List PRs you are requested to review
gh search prs --review-requested=@me --json url,state | jq -r '.[] | "\(.state)\t\(.url)"' | sed -E 's/open/\x1B[32m&\x1B[0m/g; s/merged/\x1B[35m&\x1B[0m/g'
@teshanshanuka
teshanshanuka / bard.py
Created August 3, 2023 15:59
Simple Bard chat terminal script
#!/usr/bin/python3.8
# Author: Teshan Liyanage <[email protected]>
from Bard import Chatbot
# pip install GoogleBard
# tokens from Bard webpage: inspect -> Application -> Cookies -> bard.google.com -> __Secure-1PSID, __Secure-1PSIDTS
# ANSI colors
c_b, c_nc = "\033[94m", "\033[0m"
@teshanshanuka
teshanshanuka / cgpt-bard.py
Created April 26, 2023 17:01
ChatGPT talks to Bard
#!/usr/bin/python3.8
# Author: Teshan Liyanage <[email protected]>
import readline
import openai
from Bard import Chatbot # from https://github.com/acheong08/Bard
import time
# ANSI colors
c_b, c_g, c_gr, c_nc = "\033[94m", "\033[32m", "\033[30m", "\033[0m"
@teshanshanuka
teshanshanuka / chatgpt.py
Created April 17, 2023 13:22
Simple ChatGPT terminal app
#!/usr/bin/python3.8
# Author: Teshan Liyanage <[email protected]>
import readline
import openai
openai.api_key = "<get from https://platform.openai.com/account/api-keys>"
# ANSI colors
c_b, c_g, c_gr, c_nc = "\033[94m", "\033[32m", "\033[30m", "\033[0m"
@teshanshanuka
teshanshanuka / .zsh_aliases
Last active April 17, 2023 18:38
My zsh aliases
# To hide stderr from command output (e.g. `find -name "something" NOERR`)
alias -g NOERR="2>/dev/null"
# epoch time(sec) to date - `epocht 123456789` or `echo 123456789 | epocht`
epocht() {
if [ -z $1 ]; then read ip; else ip=$1; fi
date -d @$ip +"%Y-%m-%d %T"
}
# find text in directory
@teshanshanuka
teshanshanuka / search_font.py
Created March 21, 2023 08:54
Find characters by description (regex) from font
#!python3
# Author: Teshan Liyanage <[email protected]>
# Usage: ./search_font.py '^git'
import freetype, sys, re
def findg(f, s):
ret = []
for c,g in f.get_chars():

VSCode Configs

Configs

  1. Change font

    (Powerline font to suport my $PS1 with a git character: see .zshrc, and need apt install fonts-powerline/ powerline-fonts-git for arch)

     "terminal.integrated.fontFamily": "FiraCode Nerd Font Mono"
    
@teshanshanuka
teshanshanuka / .zshrc
Last active February 24, 2023 12:56
My zsh config.
# Set up the prompt
# reference: https://www.youtube.com/watch?v=eLEo4OQ-cuQ&ab_channel=LukeSmith
# https://gist.github.com/LukeSmithxyz/e62f26e55ea8b0ed41a65912fbebbe52
autoload -U colors && colors
# PS1='%(?..%F{red}%?)%f[%B%F{blue}%~%f%b]%F{red}>%f '
# PS1='%(?.%F{green}√.%F{red}?%?)%f[%B%F{blue}%~%f%b]%F{red}>%f '
# History in cache directory:
@teshanshanuka
teshanshanuka / video_to_gif.py
Last active August 30, 2021 04:23
Convert a video to a gif image
# Author: Teshan Liyanage <[email protected]>
import imageio
import cv2
def convert(vid, frm , to, outfile, fps):
cap = cv2.VideoCapture(vid)
image_lst = []
vid_fps = cap.get(cv2.CAP_PROP_FPS)
assert vid_fps >= fps, f"Video fps {vid_fps} is smaller thank provided fps {fps}"
@teshanshanuka
teshanshanuka / download.py
Last active August 16, 2021 12:11
A better download function for Python
# Author: Teshan Liyanage <[email protected]>
import os
from urllib.parse import urlparse
import requests
import re
def is_valid_url(x):
try:
result = urlparse(x)