Skip to content

Instantly share code, notes, and snippets.

View fersilva16's full-sized avatar
🦀

Fernando Silva fersilva16

🦀
View GitHub Profile
@fersilva16
fersilva16 / init-docker.sh
Last active March 22, 2023 21:31
Magento 2 cloud docker init-docker.sh fixed
#!/usr/bin/env bash
set -e
# complain to STDERR and exit with error
die()
{
echo "$*" >&2
print_usage
exit 2
@fersilva16
fersilva16 / lcts-parser.md
Last active March 22, 2023 02:16
LCTS parser step by step

Trying to parse: λx.λy.x x

Tokens: [Lambda, 'x', Dot, Lambda, 'y', Dot, 'x', Space, 'x']

Step Op State Tokens
1 Start [] [Lambda, 'x', Dot, Lambda, 'y', Dot, 'x', Space, 'x']
2 Shift [Lambda] ['x', Dot, Lambda, 'y', Dot, 'x', Space, 'x']
3 Reduce [Lambda] ['x', Dot, Lambda, 'y', Dot, 'x', Space, 'x']
4 Shift [Lambda, 'x'] [Dot, Lambda, 'y', Dot, 'x', Space, 'x']
const assert = require('assert');
const Value = (n) => ({ type: 'value', n });
const Sum = (a, b) => ({ type: 'sum', a, b });
const Prod = (a, b) => ({ type: 'prod', a, b });
const Div = (a, b) => ({ type: 'div', a, b });
const Sub = (a, b) => ({ type: 'sub', a, b });
const sliceLast = (a, n) => a.slice(n > a.length ? 0 : a.length - n, a.length);
@fersilva16
fersilva16 / lclr.md
Last active May 30, 2022 11:29
Lambda Calculus LR parser

Hoje imagino que os steps do LR parser serão desta maneira:

Action Stack Remaining
Shift ( λx.λy.x y) z
Shift x.λy.x y) z
Shift (λx .λy.x y) z
Shift (λx. λy.x y) z
Shift (λx.λ y.x y) z
Shift (λx.λy .x y) z
@fersilva16
fersilva16 / GetLast.ts
Created May 29, 2022 17:43
Taking the last element in an array in TypeScript type system.
// Or just get the last element!
type GetLast<XS extends unknown[]>
= [never, ...XS][XS['length']];
// => never
type Empty = TakeLast<[]>;
// => 1
type OneEl = TakeLast<[1]>;
@fersilva16
fersilva16 / asb.js
Created May 28, 2022 19:07
a*b parser
const assert = require('assert');
/**
* @param {string} str
*/
const asb = ([head, ...tail]) => {
if (head === 'a') return asb(tail);
if (head === 'b' && !tail.length) return true;
return false;
@fersilva16
fersilva16 / asbFS.js
Last active May 28, 2022 19:07
a*b parser with first and second
const assert = require('assert');
/**
* @param {string} str
*/
const asb = ([fst, scd, ...tail]) => {
if (fst === 'a' && scd === 'a') return asb([fst, ...tail]);
if (fst === 'b' && !scd) return true;
if (fst === 'a' && scd === 'b') return true;
name: Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
import { useRef } from 'react';
export const useCounter = () => {
const stepCount = useRef<number>();
stepCount.current = 0;
return () => {
stepCount.current = (stepCount.current || 0) + 1;
@fersilva16
fersilva16 / md-to-org.fish
Created April 18, 2022 03:14
Tranform MD files to ORG with fish and pandoc
for f in **/*.md
pandoc -f markdown -t org -o $f.org $f;
rm $f
set n (basename $f .md)
set dn (string replace -a " " "-" $n)
mv $f.org (dirname $f)/(string lower $dn).org
end