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 / 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 / raspi-motd.sh
Created June 30, 2012 12:15
Script for setting a nice raspberry pi logo as MOTD on debian.
#!/bin/bash
logo="$(tput setaf 2)
.~~. .~~.
'. \ ' ' / .'$(tput setaf 1)
.~ .~~~..~. $(tput sgr0) _ _ $(tput setaf 1)
: .~.'~'.~. : $(tput sgr0) ___ ___ ___ ___| |_ ___ ___ ___ _ _ ___|_|$(tput setaf 1)
~ ( ) ( ) ~ $(tput sgr0) | _| .'|_ -| . | . | -_| _| _| | | | . | |$(tput setaf 1)
( : '~'.~.'~' : ) $(tput sgr0) |_| |__,|___| _|___|___|_| |_| |_ | | _|_|$(tput setaf 1)
~ .~ ( ) ~. ~ $(tput sgr0) |_| |___| |_| $(tput setaf 1)
@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 ":")
@piksel
piksel / docker-desktop-haunted-binding-mount.md
Last active February 18, 2022 11:36
Dockr Desktop haunted binding mount

Docker, run this container with my file mounted.

❯ docker run --rm -it -v /src/app/nginx/mime.types:/etc/nginx/mime.types nginx:latest ls /etc/nginx/
docker: Error response from daemon: not a directory.
See 'docker run --help'.

Eh, thanks I guess?

❯ ls -lha /src/app/nginx/mime.types