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 / 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{
@huangsam
huangsam / person.py
Created January 7, 2021 18:49
Snippet of how the State design pattern works
from stately.base import State
from stately.enums import PersonStateKey
_INITIAL_STAMINA = 5
_WALKING_EFFORT = 2
_RUNNING_EFFORT = 3
_RESTING_POWER = 5
# Placed Person here to avoid cyclic dependencies. The con though is that too
@huangsam
huangsam / .editorconfig
Last active January 5, 2021 16:59
Play around with CSS Grid
root = true
[*]
indent_size = 2
indent_style = space
@huangsam
huangsam / datanerd.py
Created October 28, 2020 06:03
Play around with NumPy
import numpy as np
# https://numpy.org/doc/stable/user/quickstart.html
def main():
# a_reshape (3 x 5)
a_reshape: np.ndarray = np.arange(15).reshape(3, 5)
assert a_reshape.shape == (3, 5)
assert a_reshape.ndim == 2
assert a_reshape.dtype.name == "int64"