Skip to content

Instantly share code, notes, and snippets.

View shamansir's full-sized avatar

Ulric Wilfred shamansir

View GitHub Profile
@shamansir
shamansir / Pairs.purs
Last active June 14, 2023 12:20
PureScript Records Pairing
module Data.Record.Pairs where
import Prelude
import Data.Symbol (class IsSymbol)
import Prim.RowList as RL
class Pairs (xsA :: RL.RowList Type) (xsB :: RL.RowList Type)
@shamansir
shamansir / draw_svg.js
Last active February 20, 2023 16:11
draw SVG path on canvas
// take SVG commands and draw this path to HTML5 canvas
// commandList should look like that: [ { marker: "M", values: [ 10, 10 ] },
// { marker: "l", values: [ 5, 7 ] },
// { marker: "C", values: [ -5, 7.2, .3, -16, 24, 10 ] },
// . . .
// { marker: "z", values: [ ] } ]
// there's another gist which has the code to parse SVG paths:
// https://gist.github.com/shamansir/0ba30dc262d54d04cd7f79e03b281505
@shamansir
shamansir / lisp.lang.xml
Created August 23, 2011 07:34
Special highlighting files for gEdit: common lisp, processingJS, pegJS, pegC...
<?xml version="1.0" encoding="UTF-8"?>
<!--
Author: Ma Jiehong <ma.jiehong@gmail.com>
Copyright (C) 2010 Ma Jiehong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
@shamansir
shamansir / _.js
Last active September 17, 2022 18:47
Parse and convert any SVG path to the list of commands with JavaScript + Regular Expressions
// svgPathToCommands('M10,10 l 5,7 C-5,7.2,.3-16,24,10 z');
//
// produces:
//
// [ { marker: "M", values: [ 10, 10 ] },
// { marker: "l", values: [ 5, 7 ] },
// { marker: "C", values: [ -5, 7.2, 0.3, -16, 24, 10 ] },
// { marker: "z", values: [ ] } ]
//
// commandsToSvgPath(svgPathToCommands('M10,10 l 5,7 C-5,7.2,.3-16,24,10 z'))
@shamansir
shamansir / backloggery_load_games.js
Last active August 16, 2021 09:30
Load games list as JSON From Backloggery page
let games = Array.from(document.getElementsByClassName('gamebox'));
function loadTitle(gamebox) {
if (!gamebox) return null;
return gamebox.querySelector('h2 b') ? gamebox.querySelector('h2 b').textContent.trim() : null;
}
function isNowPlaying(gamebox) {
return gamebox.classList.contains('nowplaying');
}
@shamansir
shamansir / Covered.purs
Last active May 21, 2021 12:45
PureScript & Haskell Errors
module Rpd.API.Covered where
data Covered error state =
Covered (Array error) (Maybe state)
nothing :: forall error state. Covered error state
nothing =
Covered [] Nothing
@shamansir
shamansir / purs-typeclasses.cue
Last active May 15, 2021 10:46
PureScript typeclasses in CUE -> JSON, for https://imgur.com/a/ESOR7
plus: {
name: "Plus"
info: "Left and Right identity for Alt"
parent: "alt"
"package": "Control*"
members:
[
{ name: "empty"
, def: "f a"
, laws : // FIXME: laws are incorrect
@shamansir
shamansir / FromHex.elm
Last active May 3, 2021 20:07
Color from Hex in Elm
module FromHex exposing (..)
import Color exposing (Color)
hexToColor : String -> Result String Color
hexToColor str =
let
digitToInt digit =
case digit of
@shamansir
shamansir / macOSVideoScreenSaver.md
Last active October 2, 2020 12:22
Installing video file as a screensaver on macOS

Based on this article: https://workspacevita.com/how-to-use-own-videos-screensavers-mac-catalina/

The difference is that the Aerial Configuration screens shown there are outdated.

First, you need to prepare the video file so it would be visible to Aerial. Due to security.

  1. Create /Users/Shared/screensavers folder.
  2. Put a copy of your video file to /Users/Shared/screensavers.
  3. That should be enough.
@shamansir
shamansir / BinPack.elm
Created August 26, 2020 07:09
Elm 2D Bin Packing
module BinPack exposing (..)
import Browser
import Html exposing (Html, button, div, text, input)
import Html.Attributes as H exposing (..)
import Html.Events exposing (onClick)
import Random
import Svg exposing (..)
import Svg.Attributes as S exposing (..)