Skip to content

Instantly share code, notes, and snippets.

View peterszerzo's full-sized avatar
🥝

Peter Szerzo peterszerzo

🥝
View GitHub Profile
I am attesting that this GitHub handle peterszerzo is linked to the Tezos account tz1Qd57kL3wjCdmhUBaHJVvDaPcBcq79nik9 for tzprofiles
sig:edsigtsnLtDTvKMcRkpMdMmw4reKBXTG72iJ7DzYKbUAyw1LAppp6majPRmUjwLQmZ3zgxHwwgAqEgRTRZFQ8qMtJhfVJMVGNZh
@peterszerzo
peterszerzo / Undoable.ts
Created March 4, 2021 13:41
Undo-redo functionality in TypeScript
import equals from "ramda/src/equals";
export interface Undoable<T> {
_current: T;
_prevs: Array<T>;
_nexts: Array<T>;
}
export const create = <T>(val: T): Undoable<T> => ({
_current: val,
@peterszerzo
peterszerzo / Guards.svelte
Last active October 23, 2020 15:52
Type guards working like a charm inside Svelte templates
<script lang="ts">
type Pet = Fish | Bird;
interface Fish {
type: "fish";
isLarge: boolean;
}
interface Bird {
type: "bird";
@peterszerzo
peterszerzo / RemoveConsecutiveEmptyLines.ts
Last active September 4, 2020 09:13
Remove consecutive empty lines from a piece of text
import mapAccum from "ramda/src/mapAccum";
const removeConsecutiveEmptyLines = (val: string): string =>
mapAccum(
(previous: null | string, current: string) => {
return [current, previous === "" && current === "" ? null : current];
},
null,
val.split("\n")
)[1]
@peterszerzo
peterszerzo / RequestAnimationFrame.purs
Created March 14, 2020 09:57
requestAnimationFrame hooke for purescript-react-basic-hooks
module CustomHooks where
import Prelude
import Data.Maybe (Maybe(..), maybe)
import Data.Newtype (class Newtype)
import Data.DateTime.Instant (unInstant)
import Data.Nullable (Nullable, notNull, null)
import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Effect.Now (now)
@peterszerzo
peterszerzo / ElmUiWithReader.elm
Created March 6, 2020 12:01
Prototype for adding context to Elm views using the reader monad
module Main exposing (main)
import Browser
import Element as Element
import Element.Background as Background
import Element.Events as Events
import Element.Font as Font
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
import Reader
@peterszerzo
peterszerzo / floorplan.clj
Created December 21, 2019 14:30
Abstract floor plan animation in http://www.quil.info/
(ns floorplan.core
(:require [quil.core :as q]
[quil.middleware :as m]))
(defn setup []
; Set frame rate to 30 frames per second.
(q/frame-rate 30)
; Set color mode to HSB (HSV) instead of default RGB.
(q/color-mode :hsb)
; setup function returns initial state. It contains
@peterszerzo
peterszerzo / TicTacToe.hs
Created October 10, 2019 16:32
Tic-tac-toe in Haskell
module TicTacToe where
import Control.Monad.State
import Data.Char
import Data.List
import qualified Data.Map as Map
import Data.Maybe
import qualified System.Process as Process
-- Cell
module Main exposing (main)
import Browser
import Dict
import Html exposing (..)
import Html.Events exposing (onClick)
import Mark
@peterszerzo
peterszerzo / hex-anim.js
Created April 20, 2019 12:49
canvas-sketch hex animation
const canvasSketch = require("canvas-sketch");
const dim = 1000;
const range = n => [...Array(n).keys()];
const settings = {
dimensions: [dim, dim],
animate: true,
duration: 30,