Skip to content

Instantly share code, notes, and snippets.

View TarVK's full-sized avatar

Tar TarVK

View GitHub Profile
@TarVK
TarVK / Watchables.md
Created April 16, 2024 20:06
Watchables exploration/planning document

Idea

Watchable primitives should provide a way of creating fields that are settable and observable, as well as observable derived values that can be computed using other watchable values. For example:

const someField = new Field(25);
const someDerivedValue = new Derived(watch => {
    return watch(someField) * 4;
});
@TarVK
TarVK / TransitionBezier.ts
Last active April 5, 2024 10:55
Smooth scroll + horizontal scroll
import Bezier from "bezier-js";
/**
* A simple bezier curve wrapper that can be used for transitions (x axis represents time)
*/
export class TransitionBezier {
protected bezier: Bezier;
protected start: number;
protected duration: number;
@TarVK
TarVK / RecursionSquare.js
Created December 24, 2020 16:59
Just some random script. The code is quite bad in an attempt to get it in this shape :P
m=" .,-~:;=!*#$@";u=Math;t=u.ceil;c=
(x,y,d)=>d>4?1:1<x&&x<=2&&1<y&&y<=2?
0:c( (x%1)*3, (y%1)*3, d+1)
;f=0 ;w=285;b =u.floor ;i=8
;j=16;while(!0){f+=.02;s=u.pow(3,f%1
)/3;p=new Array(t(w/j)).fill(false).
map((v)=>new Array(t(w/i)
).fill(.0)); for(x=0;x<w;
x++) {for (y=0 ;y<w
;y++ ){v= c((( x/w-
@TarVK
TarVK / Lambda.js
Last active July 14, 2022 18:33
Lambda calculus in js
/** Logic */
True = x=>y=>x
False = x=>y=>y
iff = c=>t=>f=>c(t)(f)
lazyIf = c=>t=>f=>c(t)(f)() // Js evualuation isn't lazy, but it can be simulated by providing callback functions
not = f=>x=>y=>f(y)(x)
and = x=>y=>x(y)(x)
or = x=>y=>x(x)(y)
@TarVK
TarVK / SimpleArithmeticParser.js
Created August 11, 2020 23:41
Wrote a very simple arithmetic parser in javascript to test the general techique
/*******************
* All helper code *
*******************/
/**
* Tokenizes the input text using the given rules
* @param {string} text The text to tokenize
* @param {{[key: string]: RegExp}} rules The rules
* @returns {{type: string, value: string, index: number}[]} The tokens
*/
name: binaryAddition
init: init0
accept: done
// if cursor is started between 2 values:
// init: return2
// Example input: 11011_10101
// 13 states, 34 instructions (when removing init: 12 states, 31 instructions)
@TarVK
TarVK / Elm minesweeper
Created April 24, 2020 16:54
Simple minesweeper game written in elm
-- Minesweeper game for elm, try it out at: https://elm-lang.org/examples/groceries (paste this code there)
import Browser
import Html exposing (Html, button, div, text, br)
import Html.Events as HEV exposing (onClick, custom)
import Html.Attributes exposing (style)
import Json.Decode as Json
import Random
width = 10
@TarVK
TarVK / FontSizeCalculator.ts
Last active March 15, 2020 21:14
Obtain the font size for text to fit a given width or height, using binary search
/** A type for font info */
type IFontStyle = {
family: string;
style?: "normal" | "italic" | "oblique";
weight?:
| "normal"
| "bold"
| "bolder"
| "lighter"
| "100"
@TarVK
TarVK / useAsyncReducer.js
Last active May 13, 2020 16:52
React reducer hook that emulates redux's async action creator capabilities
import { useState, useRef } from 'react';
/**
* A reducer hook that allows for redux's async action creator pattern;
* https://redux.js.org/advanced/async-actions#async-action-creators
* Also allows for sequential dispatching of multiple actions if an array is passed,
* Is otherwise the same as the normal useReducer hook
* @param {Function} reducer The reducer to ue
* @param {*} initialState The intiial state
* @param {object[]} actions The initial actions to dispatch
@TarVK
TarVK / AHK second keyboard layer
Last active January 15, 2020 16:41
A second keyboard layer for programming I am trying to learn to use
#NoEnv
#UseHook
RAlt::BS
; Add fake alt
CapsLock::LAlt
; Detect alt
$LAlt:: isAltDown := TRUE
$LAlt UP:: isAltDown := FALSE