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 / deepDiffObj.js
Last active September 15, 2022 02:30 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
import _ from 'lodash';
/**
* Deep diff between two objects - i.e. an object with the new value of new & changed fields.
* Removed fields will be set as undefined on the result.
* Only plain objects will be deeply compared (@see _.isPlainObject)
*
* Inspired by: https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2565071
* This fork: https://gist.github.com/TeNNoX/5125ab5770ba287012316dd62231b764/
*
@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 / .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 / gitlab-ci_script-from-variable.yml
Last active November 23, 2021 05:58
Use code from GitLab environment variable safely in bash and remote SSH
.ssh_deploy_template: &ssh_deploy_template
# TEMPLATE - see https://docs.gitlab.com/ee/ci/yaml/README.html#anchors
# ...
# Here's the magic to get the code from the GitLab variable into a bash variable and then even executed on an SSH session
script:
# Put gitlab variable into shell variable to improve quote handling
- CMD=$SCRIPT_CMD
# Print for debugging
- echo -e "Executing:\n$CMD"
@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