Skip to content

Instantly share code, notes, and snippets.

View fersilva16's full-sized avatar
🌀

Fernando Silva fersilva16

🌀
View GitHub Profile
@fersilva16
fersilva16 / 00-nix-darwin-opencode-workflow.md
Last active March 19, 2026 19:11
nix-darwin + OpenCode + tmux + Git Worktrees: complete macOS dev environment from scratch

nix-darwin + OpenCode + tmux + Git Worktrees

A complete macOS dev environment managed by Nix. Everything is declarative — one darwin-rebuild switch rebuilds your entire setup from scratch. This guide walks you through creating every file from zero.

┌─────────────────────────────────────────────────────────────┐
│ Ghostty terminal                                            │
│  ┌─────────────────────────────────────────────────────────┐│
│  │ tmux                                                    ││
│  │  ┌──────────────────────┬──────────────────────────────┐││
@fersilva16
fersilva16 / battery-widget.sh
Last active March 19, 2026 19:06
nix-darwin + OpenCode + tmux + Git Worktrees: complete macOS dev environment from scratch
#!/usr/bin/env bash
# tmux-battery-widget: Status bar widget showing battery percentage and state.
# Only shown when remote access mode is active (to keep status bar clean normally).
# Uses pmset to read battery info on macOS.
STATE_FILE="/tmp/tmux-remote-state"
# Flexoki light theme colors
BG="#f2f0e5"
@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