Skip to content

Instantly share code, notes, and snippets.

View ObjectBoxPC's full-sized avatar

Philip Chung ObjectBoxPC

View GitHub Profile
@ObjectBoxPC
ObjectBoxPC / califblueprintcovid19.hs
Created May 31, 2021 09:33
Functions implementing California's COVID-19 reopening tiers introduced in August 2020 (not including 2021 updates) https://www.cdph.ca.gov/Programs/CID/DCDC/Pages/COVID-19/COVID19CountyMonitoringOverview.aspx
data RiskTier = Widespread | Substantial | Moderate | Minimal
deriving (Show, Eq)
instance Ord RiskTier where
compare x y = compare (tierNumber x) (tierNumber y)
where
tierNumber t = case t of
Widespread -> 1
Substantial -> 2
Moderate -> 3
@ObjectBoxPC
ObjectBoxPC / makepassword.py
Created May 24, 2021 21:58
Quickly generate random passwords
#!/usr/bin/env python3
import secrets
entropy_bytes = 16
print(secrets.token_urlsafe(entropy_bytes))
@ObjectBoxPC
ObjectBoxPC / andref.cpp
Last active May 1, 2021 03:55
Misusing C++ alternative tokens
#include <utility>
class my_class {
public:
compl my_class() {} // Destructor
};
int main() {
my_class example_obj;
my_class bitand example_ref = example_obj;
@ObjectBoxPC
ObjectBoxPC / shell_start.c
Created November 28, 2020 06:12
Simple program start a shell based on certain inferences (mainly to learn some POSIX C programming)
#include <unistd.h>
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
/**
* @file
* Utility function to start a shell based on reasonable inferences
*/
@ObjectBoxPC
ObjectBoxPC / git-sct.sh
Created November 25, 2020 20:36
"git sct" script ("show commit with tool") to view the changes made in a commit using a diff tool
#!/bin/sh
# To integrate, place the following into your .gitconfig:
# [alias]
# sct = !path/to/git-sct.sh
if [ $# -lt 1 ]; then
echo "Usage: git sct <revision> [<parent-number>]"
exit 1
fi
@ObjectBoxPC
ObjectBoxPC / pangram.hs
Last active July 7, 2020 13:48
Simple Haskell program to check if the input (command-line arguments) form a pangram, containing all 26 letters of the English alphabet
import Data.Char (toUpper)
import Data.List (intercalate)
import Data.List.NonEmpty (NonEmpty, nonEmpty, toList)
import System.Environment (getArgs)
data PangramResult = Pangram | MissingLetters (NonEmpty Char)
checkPangram :: String -> PangramResult
checkPangram s = case nonEmpty missingLetters of
Just ls -> MissingLetters ls