Skip to content

Instantly share code, notes, and snippets.

View haggen's full-sized avatar

Arthur Corenzan haggen

View GitHub Profile
@haggen
haggen / string.random.lua
Last active February 21, 2024 04:16
Random strings in Lua
math.randomseed(os.time())
local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
function string.random(length)
if length > 0 then
return string.random(length - 1) .. charset:sub(math.random(1, #charset), 1)
else
return ""
end
@haggen
haggen / apple-crayon.scss
Last active February 18, 2024 20:16
Apple Crayon Palette RGB values in SASS
// Apple Crayon Palette RGB
$cantaloupe: rgb(255, 206, 110);
$honeydew: rgb(206, 250, 110);
$spindrift: rgb(104, 251, 208);
$sky: rgb(106, 207, 255);
$lavender: rgb(210, 120, 255);
$carnation: rgb(255, 127, 211);
$licorice: rgb(0, 0, 0);
$snow: rgb(255, 255, 255);
@haggen
haggen / .zshrc
Last active January 15, 2024 14:17
My Linux setup both on Ubuntu or WSL.
# starship prompt
# https://starship.rs/
eval "$(starship init zsh)"
# rtx runtime
# https://github.com/jdx/rtx
eval "$(rtx activate zsh)"
export PIPENV_VENV_IN_PROJECT=1
export VISUAL=vim
@haggen
haggen / package.bat
Last active January 10, 2024 12:41
Package your ESO add-on ready for distribution.
:: Package your ESO add-on ready for distribution.
:: Version 1.3 Sat, 14 Nov 2015 22:36:23 +0000
@echo off
setlocal enableextensions enabledelayedexpansion
set zip=%ProgramFiles%\7-Zip\7z.exe
if not exist "%zip%" goto :zipnotfound
for %%* in (.) do set name=%%~nx*
@haggen
haggen / useForm.ts
Created October 21, 2023 18:03
Draft of zod validated form state hook.
import { ChangeEvent, createContext, useMemo, useReducer } from "react";
import { AnyZodObject, ZodError, z } from "zod";
import { mapValues } from "~/lib/map";
type FieldState = {
name: string;
value: string;
error: undefined | ZodError;
touched: boolean;
};
@haggen
haggen / haggen.opml
Created December 18, 2021 13:23
RSS feed in OPML
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Arthur subscriptions in feedly Cloud</title>
</head>
<body>
<outline text="Everything" title="Everything">
<outline type="rss" text="TechCrunch" title="TechCrunch" xmlUrl="http://feeds.feedburner.com/Techcrunch" htmlUrl="https://techcrunch.com" />
<outline type="rss" text="TorrentFreak" title="TorrentFreak" xmlUrl="http://feeds.feedburner.com/Torrentfreak" htmlUrl="https://torrentfreak.com" />
@haggen
haggen / package.json
Last active July 1, 2023 13:52
Git hook to lint (eslint) and format (prettier) staged files and abort the commit if anything has changed.
{
"scripts": {
"prepare": "test -f .git/hooks/pre-commit || cp scripts/pre-commit .git/hooks",
"format": "prettier . --cache",
"lint": "eslint . --report-unused-disable-directives --max-warnings 0 --cache",
}
}
@haggen
haggen / css.d.ts
Last active May 24, 2023 22:38
TypeScript type for CSS modules. e.g. import styles from "styles.module.css".
/**
* Stylesheet module classes.
*/
declare module "*.module.css" {
const stylesheet: {
[key: string]: string;
};
export = stylesheet;
}
@haggen
haggen / create-component.sh
Last active May 6, 2023 17:34
Script to automate creating new components in a React application.
#!/usr/bin/env bash
#
# Create React Component.
#
# Sane defaults.
# -e Exit on error.
# -u Whine on undefined variables.
# -o pipefail Exit main script if pipe process fails.
set -euo pipefail
@haggen
haggen / text-stroke.scss
Last active April 26, 2023 05:35
Text stroke using text-shadow as SCSS mixin.
/**
* Text stroke using text-shadow.
* @example
* p {
* @include stroke(black, 2px);
* }
*/
@mixin stroke($color, $size: 1px) {
$value: null;