Skip to content

Instantly share code, notes, and snippets.

View piksel's full-sized avatar
📠

nils måsén piksel

📠
View GitHub Profile
@piksel
piksel / git-install-hooks
Last active March 10, 2025 09:51
Common pre-commit hook
#!/bin/bash
git_root=$(git rev-parse --show-toplevel)
if [[ "$git_root" == "" ]]; then
exit 1
fi
cd "$git_root/.git/hooks"
curl -LO https://gist.github.com/piksel/af64b9ca445c1354be862cd1485e15c0/raw/pre-commit
chmod a+x pre-commit
#!/bin/bash
tree --noreport -F $* | sed -E 's/ ?([0-9|A-Z|a-z|.|*|_|-]+)$/📄 \1/gm; s/ ?(\S+)\//📁 \1/gm'
@piksel
piksel / export-prs.sh
Created April 5, 2024 11:53
Bitbucket Export
#!/bin/bash
if [[ -z "$BB_WORKSPACE" ]]; then echo "Missing variable BB_WORKSPACE"; exit 1; fi
if [[ -z "$BB_TOKEN" ]]; then echo "Missing variable BB_TOKEN"; exit 1; fi
if [[ -z "$BB_REPO" ]]; then echo "Missing variable BB_REPO"; exit 1; fi
step=0
while read id; do
if [[ -d "prs/pr-$id" ]]; then
#!/bin/bash
tmp_dir=${TMPDIR:-/tmp}
max_itm_len=24
max_val_len=100
hth_key_col=35
hth_val_col=97
hth_itk_col=94
hth_itv_col=97
sec_hdr_col=96
@piksel
piksel / fake-window.ts
Created February 23, 2024 14:12
Fake Window/Location
class FakeWindow implements Window {
[index: number]: Window;
get clientInformation(): Navigator {
console.log('Called get clientInformation');
return {} as Navigator;
}
closed: boolean = false;
customElements: CustomElementRegistry = {} as CustomElementRegistry;
devicePixelRatio: number = globalThis.devicePixelRatio;
@piksel
piksel / conlib.mjs
Last active February 1, 2024 17:42
conlib
import readline from 'node:readline/promises';
/**
* conlib v6
* @author nils måsén
* @copyright 2018-2024, nils måsén
*/
export default class ConLib {
constructor(stream) {
@piksel
piksel / http-serve-autoreload.mjs
Created May 27, 2023 11:21
Node script that serves files from a directory, injecting a script into HTML pages that reloads the page whenever a POST request to the file completes
#!/usr/bin/env node
/*
Serves files from a directory, injecting a script into HTML pages that reloads the page whenever a POST request to the file completes.
Requires Node.js v18+
Usage:
node http-serve-autoreload.mjs [ROOT-PATH] [PORT]
*/
import { createServer } from 'node:http';
@piksel
piksel / export-all.mjs
Last active May 25, 2023 15:53
Script for re-exporting all .ts(x) files in a directory
import { readdir, readFile, writeFile, access, stat } from 'node:fs/promises';
import { resolve } from 'node:path';
const [, , path] = process.argv;
const HEADER = '// AUTO-GENERATED by export-all.mjs DO NOT CHANGE!';
if (!path) {
console.error('Missing argument PATH')
process.exit(1);
@piksel
piksel / extras.go
Created December 13, 2022 21:22
rust vs go
func (MarkdownTreeRenderer) writeFieldExtras(sb *strings.Builder, field *FieldInfo) {
if len(field.Keys) > 1 {
sb.WriteString(" Aliases: `")
for i, key := range field.Keys {
if i == 0 {
// Skip primary alias (as it's the same as the field name)
continue
}
if i > 1 {
sb.WriteString("`, `")
@piksel
piksel / strip_wind_paths.sh
Last active September 1, 2022 07:30
Remove windows PATHs in WSL
export PATH=$(echo $PATH | tr ":" "\n" | grep -v '/mnt/' | paste -sd ":")