Skip to content

Instantly share code, notes, and snippets.

View peterszerzo's full-sized avatar
🥝

Peter Szerzo peterszerzo

🥝
View GitHub Profile
@peterszerzo
peterszerzo / nested-ternary.js
Created April 24, 2018 06:07
Functional alternative to nested ternaries
const cond = (condition, value) => (condition ?
{
state: value,
or(obj) {
return this
},
valueOr(defaultValue) {
return this.state
}
}
@peterszerzo
peterszerzo / canvas-sketch-example.js
Created April 8, 2019 08:13
Looking at canvas-sketch frame rates
const canvasSketch = require("canvas-sketch");
const utils = require("./utils");
const dim = 1024;
const settings = {
dimensions: [dim, dim],
animate: true,
duration: 30
};
@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,
module Main exposing (main)
import Browser
import Dict
import Html exposing (..)
import Html.Events exposing (onClick)
import Mark
@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
@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 / 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 / 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 / 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 / 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";