Skip to content

Instantly share code, notes, and snippets.

View benwrk's full-sized avatar
😴

Benjapol Worakan benwrk

😴
View GitHub Profile
@benwrk
benwrk / App.jsx
Created June 7, 2024 10:37
Solution to React's Tic-Tac-Toe tutorial with all optional tasks completed.
import { useState } from "react";
function Square({ value, onSquareClick }) {
return (
<button className="square" onClick={onSquareClick}>
{value}
</button>
);
}
@benwrk
benwrk / thai_id_card_check_digit_validator.py
Last active June 7, 2024 10:38
One-liner Thai National ID Card check digit calculator and validator
def calculate_id_card_check_digit(card_number: str) -> int:
return (11 - sum([(len(card_number) - i) * x for i, x in enumerate(map(lambda s: int(s), card_number[:-1]))]) % 11) % 10
def validate_id_card_number_check_digit(card_number: str) -> bool:
return int(card_number[-1:]) == calculate_id_card_check_digit(card_number)
@benwrk
benwrk / deploy.sh
Created December 4, 2019 09:15
GitHub Automatic Deployment Webhook Config for `ist-fr.vistec.ist`
#!/bin/bash
# Location: /var/www/ist-fr.vistec.ist
# Redirects stdout/stderr to a file
exec > ./deploy.log 2>&1
# Add snap bin PATH (npm is here)
export PATH=$PATH:/snap/bin
# Remove existing repo
@benwrk
benwrk / MediaControl.ahk
Last active August 4, 2018 20:16
Media Control Macro Keys Script for AutoHotKey
; Media Control Macro Keys Script For AutoHotKey
; Version 1.0
;
; (C) Benjapol Worakan
;
; Created out of frustation that my new laptop does not have multimedia hotkeys (e.g. Play/Pause/Next/Previous)
; Feel free to use or modify this script :)
; RightCtrl+Spacebar = Play/Pause
>^Space::Media_Play_Pause
@benwrk
benwrk / right_shift.asm
Last active February 22, 2018 17:52
Manual compilation of C to MIPS R3000 Assembly - Shifts the first element of an array to position 9 (0-indexed)
#
# Manual compilation - C to MIPS R3000 Assembly
#
# Shift the first element of an array to position 9 (0-indexed)
#
# Author: Benjapol Worakan (benwrk)
#
.data
array: .word 0 : 20 # int A[20] // array declaration
size: .word 10 # int size = 10 // actual size
@benwrk
benwrk / HW3-3.asm
Last active December 8, 2016 13:14
Assembly homework solutions for the Computer Organization and Computer Architecture course.
.data
array: .word 0 : 50
size: .word 50
space: .asciiz " "
.text
.globl main
main:
init_value_init:
lw $t3, size
la $t8, array
import urllib
import urllib2
import json
API_ENDPOINT = 'http://api.openweathermap.org/data/2.5/forecast/daily'
API_KEY = 'PUT API KEY HERE'
DAYS = 13
THRESHOLD = 70
def is_dangerous(province, date=0):
@benwrk
benwrk / ConcurrentAdder1.java
Last active June 30, 2016 03:02
Part of 'Lab 12 - High Level Concurrency in Java' of the Computer Systems Laboratory course (01219215).
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Add numbers using ExecutorService.
@benwrk
benwrk / IndependentSetOfMaximumWeight.java
Last active February 23, 2018 03:16
An algorithm to find 'Independent Set of Maximum Weight' (solution to Exercise 6.1(c) from the first edition of Algorithm Design by Jon Kleinberg, Eva Tardos.) in Java, part of Algorithm Design and Analysis course.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class IndependentSetOfMaximumWeight {
public static void main(String[] args) {
System.out.println("Independent set of maximum weight: "
+ findIndependentSetOfMaximumWeight(Arrays.asList(6, 8, 7, 6, 8, 1)));
}
@benwrk
benwrk / InsertionSort.asm
Last active April 3, 2024 03:13
Insertion Sort - MIPS Assembly Version
#
# "Insertion Sort -- Assembly Version"
#
# This MIPS assembly code -- based on MIPS R3000's instruction set -- first
# receives the number of values to be sorted (N), then receives the values
# (for N times) to be sorted, and then sort the values using "Insertion Sort"
# and prints the result of the sorting.
#
# Note: Maximum number of values to be sorted (N) is 999 numbers.
#