Skip to content

Instantly share code, notes, and snippets.

View Keith-Hon's full-sized avatar
👋
Hello!

Keith Hon Keith-Hon

👋
Hello!
View GitHub Profile
@Keith-Hon
Keith-Hon / retention.ts
Last active August 27, 2024 06:25
retention
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const periods = [1, 7, 14, 30];
const output = {};
for (let j = 0; j < periods.length; j++) {
const period = periods[j];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Office Layout</title>
<style>
.room {
width: 250px;
height: 350px;
1
00:00:01,231 --> 00:00:02,072
係喇咁,好咁
2
00:00:02,072 --> 00:00:03,613
咁或者我簡單
3
00:00:03,613 --> 00:00:04,735
@Keith-Hon
Keith-Hon / gist:49594ef8a26379fcc46cf5c11c7cf3f2
Created June 27, 2024 05:28
Realtime WebSocket Audio Streamin
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Realtime WebSocket Audio Streaming</title>
<style>
body {
background-color: black;
color: green;
}
@Keith-Hon
Keith-Hon / preprocessed_brands.json
Created September 21, 2022 14:48
preprocessed brands
[
"at t",
"molecole",
"enquiret",
"fairphone",
"ラスタバナナ",
"dcenta",
"caoy",
"sonim",
"jensa",
## Imports
from typing import Tuple
import torch
from torch import Module, Tensor
from transformers.models.roberta.modeling_roberta import RobertaPreTrainedModel, RobertaConfig, RobertaModel, RobertaEncoder
from torch.nn import CrossEntropyLoss, CosineEmbeddingLoss
## Function
@Keith-Hon
Keith-Hon / google_taxonomy_parser.py
Created July 30, 2022 13:24
Python parser for google taxonomy
import requests
en_content = requests.get('https://www.google.com/basepages/producttype/taxonomy-with-ids.en-US.txt')
def load_taxonomy_hierarchy(root, taxonomy_content, is_root):
lines = taxonomy_content.split('\n')
filtered_lines = lines[1:]
filtered_lines = list(filter(lambda line: len(line) > 0, filtered_lines))
# extract the root taxonomy from content
root_taxonomy_set = set()
@Keith-Hon
Keith-Hon / gist:3e8bcf998d8aeae0f1f41f19a7d1f409
Last active April 8, 2022 10:00
Reset k8s for master and work nodes if pod-network-cidr changed
kubeadm reset
## master only
etcdctl rm --recursive registry
rm -rf /var/lib/cni
rm -rf /run/flannel
rm -rf /etc/cni
@Keith-Hon
Keith-Hon / gist:ed48526c3d9a249d5d56048df6172762
Created February 15, 2022 03:36
Github webhook handler for Next.js
// pages/api/webhooks/github.js
const { exec } = require("child_process");
const crypto = require("crypto");
// Handle GitHub Webhooks
export default function handler(req, res) {
try {
console.log("Incoming Request");
if (req.method !== 'POST') {
res.send(404);
@Keith-Hon
Keith-Hon / gist:0098bd40a208de2dc9217df457584845
Created January 10, 2022 10:10
Recursively rename files in windows 10
forfiles /S /M *.ext1 /C "cmd /c rename @file @fname.ext2"