Skip to content

Instantly share code, notes, and snippets.

View varshard's full-sized avatar

Bhoomtawath Plinsut varshard

  • https://github.com/activehours
  • Bangkok, Thailand
View GitHub Profile
@varshard
varshard / getHrefFromAnchors.js
Created May 14, 2025 04:29
Extract URLs from <a>
function getHrefFromAnchors() {
// Find all anchor elements with the specified classes
const anchors = document.querySelectorAll('a.link-stretched.text-inherit');
// Convert NodeList to Array and extract href attributes
const hrefs = Array.from(anchors).map(anchor => {
// Type assertion to HTMLAnchorElement since we know these are anchor elements
return anchor.href;
});
@varshard
varshard / WK-BATTAM.json
Created May 28, 2024 15:15
VIA file Bat keyboard
{
"name": "Weekin WK-50",
"vendorId": "0xFEE5",
"productId": "0x6036",
"lighting": "qmk_rgblight",
"matrix": { "rows": 4, "cols": 14 },
"layouts": {
"keymap": [
[
{
@varshard
varshard / .<org>.gitconfig
Last active May 15, 2024 01:51
git config to load ssh key based on the current directory
[core]
sshCommand = ssh -i ~/.ssh/<work_private_key>
[user]
email=<org email>
name = <username>
@varshard
varshard / init.lua
Created May 14, 2024 02:47
mouse jump across monitors for Hammerspoon
local hyperShift = { "ctrl", "shift" }
hs.hotkey.bind(hyperShift, "`", function()
local screen = hs.mouse.getCurrentScreen()
local nextScreen = screen:next()
local rect = nextScreen:fullFrame()
local center = hs.geometry.rectMidPoint(rect)
hs.mouse.setAbsolutePosition(center)
end)
@varshard
varshard / iterate_nodes.rs
Created February 6, 2024 09:53
Iterating nodes in petgraph
use petgraph::graph::{UnGraph};
use petgraph::Direction;
use petgraph::visit::IntoNodeReferences;
#[derive(Debug)]
struct Pokemon {
name: String
}
impl Pokemon {
@varshard
varshard / leetcode_relative_line.js
Last active January 28, 2024 14:47
Show relative line number on leetcode.com
const ACTIVE_LINE = 'active-line-number'
const LINE_NUMBER = 'div.line-numbers'
function setRelativeLineNumber() {
let allLines = Array.from(document.querySelectorAll(LINE_NUMBER))
let activeLineIndex = allLines.findIndex(line => line.classList.contains(ACTIVE_LINE))
if (allLines[activeLineIndex].innerHTML == ' ') {
return;
}
for (let i = 0; i < allLines.length; i++) {
let line = allLines[i];
@varshard
varshard / reverse_each_word.py
Created January 22, 2024 14:45
Reverse each word
def reverse_each_word(s: str) -> str:
l = 0
ss = list(s)
length = len(ss)
while l < length:
if ss[l] == ' ':
l+=1
while l < length and ss[l] == ' ':
l+=1
@varshard
varshard / powershell_profile.ps1
Created November 3, 2023 13:50
Powershell profile with partial autocomplete
# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete
Invoke-Expression (&starship init powershell)
Import-Module posh-git
Import-Module DockerCompletion
Import-Module PSReadLine
@varshard
varshard / chatgpt.py
Created June 19, 2023 07:58
A sample chat gpt
import openai
from llama_index import SimpleDirectoryReader, GPTVectorStoreIndex, LLMPredictor, PromptHelper, ServiceContext, StorageContext, load_index_from_storage
from langchain import OpenAI
import gradio as gr
import os
openai.api_key = os.environ["OPENAI_API_KEY"]
max_input_size = 4096
num_outputs = 512
@varshard
varshard / games.go
Last active February 26, 2023 16:27
solid examples
package games
import "fmt"
type Game interface {
GetName() string
Run() []string
}