Skip to content

Instantly share code, notes, and snippets.

@jmars
jmars / cat.purs
Created January 12, 2024 12:06
simplified implementation of cat in purescript
module Main where
import Prelude
import Effect (Effect)
import Node.FS.Aff (Encoding(UTF8))
import Effect.Aff (launchAff_)
import Node.Process (getArgs, stdout)
import Node.Stream.Readable (createReadStream)
import Node.Stream.Writable (end)
import Data.Array (drop)
@jmars
jmars / abnf.purs
Created January 12, 2024 12:05
purescript earley parser + ABNF grammar
let rules = [
Tuple "rulelist" ["rule", "rulelist"],
Tuple "rulelist" ["rule"],
Tuple "rule" ["rulename", "defined-as", "elements", "c-nl"],
Tuple "rulename" ["ALPHA", "rulename"],
Tuple "rulename" ["ALPHA"],
Tuple "defined-as" ["equals"],
Tuple "defined-as" ["equals", "slash"],
Tuple "elements" ["alternation", "c-wsp", "c-nl"],
Tuple "elements" ["alternation"],
-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEAAAAABYJKwYBBAHaRw8BAQdAd5HP5ouxdgaIUEqi4xp5ykN+Z830qKxE
zBboJh6MC/TNLEpheWUgTWFyc2hhbGwgKFJpZ2h0IGhhbmQgcGF0aCkgPG1l
QGpheWUuY2g+wowEEBYKAD4FggAAAAAECwkHCAmQZmyDpYtk0RUDFQgKBBYA
AgECGQECmwMCHgEWIQTTmOVbj3jmmE1v+WZmbIOli2TRFQAAtWoA/2siez8f
oxmBeW/UQ8g21lTADo3HNXJk+xOyPj7xkn6JAP9UAWHgsujwFrh/h6BkQnBA
7PD3GDgaEWtqfupo7OSqD844BAAAAAASCisGAQQBl1UBBQEBB0BaQtgvwW61
FWZfZmw8Snjbu0j5TBnxgnDnq+4g1EVbFAMBCAfCeAQYFggAKgWCAAAAAAmQ
ZmyDpYtk0RUCmwwWIQTTmOVbj3jmmE1v+WZmbIOli2TRFQAA1vsA/iLDoAiV
@jmars
jmars / just-move-it-10px.md
Last active December 10, 2019 16:50
Move the thing

canvas

The blue lines is what the font defines as its space to render. The red lines is the actual bounds of the characters on screen. The black line is the baseline. As you can see, adding a 10px margin does not result in 10px of actual space, usually it is more due to decenders and ascenders.

This is the reason sketch and other tools show the 'gray box' that does not fit the actual characters, because that box is the size actually taken up during normal rendering. If text is laid out ignoring the box, then negative spacing has to be added to remove the descenders and ascenders which will only work for the particular font size and font and has to be hardcoded.

Also see: The nitty gritty of text rendering in sketch

And for react native in particular (and to show the gymnastics required to implement physi

@jmars
jmars / keybase.md
Created October 10, 2016 01:26
keybase.md

Keybase proof

I hereby claim:

  • I am jmars on github.
  • I am jmars (https://keybase.io/jmars) on keybase.
  • I have a public key whose fingerprint is 0D05 B954 6DE8 A3F2 C0C2 6202 63CA 98F7 79DD 1FE1

To claim this, I am signing this object:

pscjit -jv -jdump test.psc
---- TRACE 5 start test.psc
0005 ISNEN 4 0 ; 0
0006 JMP 6 => 0008
0008 MULVV 3 5 4
0009 SUBVN 2 4 1 ; 1
0010 MOV 5 3
0011 MOV 4 2
0012 JMP 6 => 0004
@jmars
jmars / defunctionalize.js
Created August 9, 2014 02:24
defunctionalizing full function application is worth it
function F2 (fun) {
function wrapper(a) { return function (b) { return fun(a,b) } }
wrapper.arity = 2;
wrapper.func = fun;
return wrapper
}
function A2 (fun, a, b) {
return fun.arity === 2 ? fun.func(a, b) : fun(a)(b);
}
@jmars
jmars / typedarrays.js
Created August 9, 2014 02:17
typed arrays not necessary for fast javascript objects
var buffer = new ArrayBuffer(3);
var i8 = new Int8Array(buffer);
function js (fst, snd, trd) {
this.fst = fst;
this.snd = snd;
this.trd = trd;
};
function typed (fst, snd, trd) {
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name=apple-mobile-web-app-capable content=yes>
<meta name=apple-mobile-web-app-status-bar-style content=black>
<title>Test fullscreen</title>
<style>
html, body {
margin: 0;
padding: 0;
@jmars
jmars / app
Created June 13, 2011 19:40
Mount express/jade/stylus app with absolute URLs
stylus = require 'stylus'
route = if app.route is '/' then '' else app.route
compile = (str, path) ->
route = if app.route is '/' then '' else app.route
stylus(str)
.set('filename', path)
.set('compress', true)
.define('route', new stylus.nodes.String(route))