Skip to content

Instantly share code, notes, and snippets.

View Honga1's full-sized avatar
🐈
Gitting my head around things.

Jae Honga1

🐈
Gitting my head around things.
  • Amsterdam, The Netherlands
View GitHub Profile
const tuple = ["a", "b", "c", "d"] as const;
type Tuple = typeof tuple;
type FirstElement<Tuple extends readonly any[]> = Tuple[0];
type ShiftOne<Tuple extends readonly any[]> = Tuple extends readonly [Tuple[0], ...infer U] ? U : never;
type PopOne<Tuple extends readonly any[]> = Tuple extends readonly [...infer U, Tuple[number]] ? U : never;
type LastElement<Tuple extends readonly any[]> = Tuple extends readonly [...Tuple[number], infer U] ? U : never;
type Indices<Tuple extends readonly any[], TStart extends number[]> = Tuple['length'] extends 0 ? PopOne<[0, ...TStart]> : Indices<ShiftOne<Tuple>, [Tuple['length'], ...TStart]>;
@Honga1
Honga1 / Mouse.ts
Created March 4, 2020 18:09
A Typescript DOM Mouse singleton. Holds and updates mouse move / touch move pointer positions.
/**
* A singleton which holds and updates mouse move / touch move pointer positions.
* Exporting or placing this in your code exposes Mouse.
*/
export class Mouse {
private static instance = new Mouse();
private position: [number, number] = [0, 0];
private constructor() {
@Honga1
Honga1 / workflow.sh
Last active November 4, 2021 11:59
A git rebase workflow explained
# To add a change to our repository
git checkout -b "feature/feature-name" # Creates a branch called "feature/feature-name", then checks it out, locally.
git push --set-upstream origin feature/feature-name # Publish the branch on GitHub
# Make changes to your files
git add FILENAME(S) # Adds your files to "Tracked".
git status # See your "Staged and Unstaged files (green and red respectively"
@Honga1
Honga1 / uber.ts
Created December 20, 2019 15:28
Solution to 20/12/19 Devmat problem
const countTokens = (tokenMatcher: RegExp, input: string) =>
input
.match(tokenMatcher)
?.map((token: string) =>
token.replace(/((\+|\-|^){1}$(?![0-9]))/g, match => (match === '-' ? '-1' : '1')),
)
.map(token => parseInt(token))
.reduce((accumulator, currentValue) => accumulator + currentValue, 0) ?? 0;
const countVariables = (input: string) => countTokens(/((\+|\-|^)|(-*)[0-9]){1}(?=x)/g, input);
#!/usr/bin/python
# -*- coding: utf-8 -*-
import json
import csv
from nltk.stem.lancaster import LancasterStemmer
stemmer = LancasterStemmer()
f = open('mscoco.json')
data = json.load(f)
f.close()
@Honga1
Honga1 / waterBathPitchFollower.ino
Created March 3, 2018 14:21
Arduino code to follow X position water bath as linear resistor and output a tone.
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
pinMode(7, OUTPUT); //Left Plate
pinMode(6, OUTPUT); //Right plate
}
int sens_flip = 0;
int av = 0;
void loop() {