Skip to content

Instantly share code, notes, and snippets.

@tennox
tennox / migadu-dnscontrol-example.js
Last active March 20, 2024 12:12
Migadu DNSControl setup
// Adapt all occurrences of `EXAMPLE.org` and `REPLACEME` with the correct values
D("EXAMPLE.org", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
// other records - e.g.
//A("@", "1.2.3.4"),
////////////
// MIGADU //
////////////
TXT("@", "hosted-email-verify=REPLACEME"),
@tennox
tennox / .envrc
Last active June 7, 2023 12:11
devenv reproduction - exit code
#!/usr/bin/env bash
set -euo pipefail
# Docs: https://direnv.net/
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
fi
nix_direnv_watch_file devenv.nix
@tennox
tennox / Readme.md
Created May 26, 2023 20:54
Nix: Flatten VSCode settings to allow structured config

Instead of

{
  "editor.fontLigatures" = true;
  "editor.inlayHints.enabled" = "offUnlessPressed";
  "editor.inlayHints.fontSize" = 12;
}

I want to be able to write

@tennox
tennox / .state-to-child.tsx
Last active December 9, 2021 22:58
React: Pass useState hook to child
import React, { FC, useState } from 'react';
const Component = () => {
const [barFoo, setBarFoo] = useState(1);
return <Foo bar={[barFoo, setBarFoo]} />;
};
const Foo: FC<{ bar: StateRef<number> }> = ({ ...state }) => {
const [bar, setBar] = state.bar;
return <div />;
@tennox
tennox / sanitize.js
Created November 29, 2021 14:43
Sanitize string & filename
const _ = require('lodash')
const sanitize = str => _.chain(str)
.replace(/[^A-Za-z0-9&.-]/g, '-') // sanitise via whitelist of characters
.replace(/-(?=-)/g, '') // remove repeated dashes - https://regexr.com/6ag8h
.trim('-') // trim any leading/trailing dashes
.truncate({
length: 40, // max length
omission: '-' // when the string ends with '-', you'll know it was truncated
})
@tennox
tennox / basic_cmd.sh
Last active January 21, 2022 04:10
Github latest release download
# basic bash command
wget $(curl -s https://api.github.com/repos/filiph/linkcheck/releases/latest \
| jq -r '.assets | .[] | select(.name|contains("linux-x64.tar.gz")) | .browser_download_url')
@tennox
tennox / gulpfile.js
Created October 2, 2021 16:00
Gulp task to downscale & convert images using sharp
const gulp = require('gulp')
const rename = require('gulp-rename')
const sharp = require('sharp')
var useAsync = require('gulp-use').async
export default function convertImages () {
return gulp
.src('static/original/uploads/*.*')
.pipe(useAsync(async function (file, next) {
try {
@tennox
tennox / _castle.md
Last active June 16, 2021 09:33
Can you reach the throne?

Can you reach the throne?

You (brian) are allowed to change the cleaning code, but nothing else.

Can you reach the throne?

JS Fiddle here

@tennox
tennox / keybase.md
Created February 14, 2021 15:14
keybase.md

Keybase proof

I hereby claim:

  • I am tennox on github.
  • I am tennox (https://keybase.io/tennox) on keybase.
  • I have a public key ASDT0ovBTBQowbqsJSPKzUTNpf6Dw0-iCRqLAkAuwq1u4Qo

To claim this, I am signing this object:

@tennox
tennox / object-field-mapper.js
Created June 4, 2020 09:51
JS Object field mapper
import _ from 'lodash'
/**
* Map fields of an object:
*
* ```
* ObjectUtils.mapFields(
* { a: 1, b: 2, c: 3, d: 4 },
* {
* a: num => num + 10,