Skip to content

Instantly share code, notes, and snippets.

View huangsam's full-sized avatar
🌱
Continuous learning

Samuel Huang huangsam

🌱
Continuous learning
View GitHub Profile
@huangsam
huangsam / imdb.py
Created January 13, 2026 07:27
Running neural net to train and eval against IMDb ratings
from typing import Any
import torch
from datasets import Dataset, DatasetDict, load_dataset
from transformers import AutoModelForSequenceClassification, AutoTokenizer
# --- 1. CONFIGURATION CONSTANTS ---
MODEL_NAME = "bert-base-uncased" # The Hugging Face model to use
MAX_LENGTH = 128 # Max length for tokenization
BATCH_SIZE = 16 # Batch size for training
@huangsam
huangsam / imagecompare.py
Created December 31, 2025 19:58
Comparing an image with itself using PyTorch
import torch
from torchvision import transforms
from PIL import Image
import torch.nn.functional as F
# Load images
image1 = Image.open("images/image1.jpg").convert("RGB")
image2 = Image.open("images/image1.jpg").convert("RGB") # Comparing to itself
# Transform to tensors, scale to 0-255 for SSIM
@huangsam
huangsam / eldest.go
Created June 17, 2025 15:36
Finding oldest Git lines with Go
package main
import (
"bufio"
"fmt"
"io"
"log"
"os"
"os/exec"
"path/filepath"
@huangsam
huangsam / ssh-verify.go
Created February 14, 2025 19:16
SSH verification in Go
package main
import (
"bytes"
"os"
"github.com/rs/zerolog/log"
"golang.org/x/crypto/ssh"
)
@huangsam
huangsam / DeadlockExample.java
Last active November 4, 2024 21:55
Deadlock stuff
public class DeadlockExample {
public static void main(String[] args) {
Object lock1 = new Object();
Object lock2 = new Object();
Thread thread1 = new Thread(() -> {
synchronized (lock1) {
System.out.println("Thread 1: Acquired lock1");
try {
Thread.sleep(1000);
@huangsam
huangsam / HelloWriter.java
Created November 3, 2024 09:33
Protobuf madness with multiple languages
package com.tutorial.hello;
import com.tutorial.hello.HelloOuterClass.Hello;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@huangsam
huangsam / app.py
Created May 20, 2024 00:17
flask_app_context.py
from flask import Flask, Response, current_app, jsonify, make_response
from flask.views import MethodView
def create_app() -> Flask:
"""Create application context."""
created_app = Flask(__name__)
return created_app
@huangsam
huangsam / sqlalchemy_20.py
Last active March 1, 2023 06:36
Testing out SQLAlchemy 2.0
from datetime import datetime, timezone
from typing import Any, Optional, Sequence, Type
from sqlalchemy import (
DateTime,
Dialect,
ForeignKey,
Result,
Row,
String,
@huangsam
huangsam / thread_queue.py
Last active January 7, 2023 08:09
Try Thread class and Queue class together
from queue import Queue
from threading import Thread
from time import sleep
# https://docs.python.org/3/library/queue.html
# https://stackoverflow.com/questions/27200674/python-queue-join
# https://stackoverflow.com/questions/7445742/runtimeerror-thread-init-not-called-when-subclassing-threading-thread
_TASK_QUEUE = Queue()
@huangsam
huangsam / sudoku.go
Last active October 7, 2024 05:39
Sudoku solver for demonstration purposes
package main
import (
"fmt"
)
type Sudoku = [9][9]int
func main() {
unsolved := Sudoku{