Skip to content

Instantly share code, notes, and snippets.

View GwynethLlewelyn's full-sized avatar
👩
Learning Go

Gwyneth Llewelyn GwynethLlewelyn

👩
Learning Go
View GitHub Profile
@GwynethLlewelyn
GwynethLlewelyn / imagemagick-convert-multiple-resolutions.md
Last active April 7, 2024 21:15
ImageMagick Simultaneously Convert To Multiple Resolutions
convert gw-original-1400.png -write mpr:img +delete \( mpr:img -resize 1280x +write gw-1280.png \) \( mpr:img -resize 1024x +write gw-1024.png \) \( mpr:img -resize 512x +write gw-512.png \) \( mpr:img -resize 500x +write gw-500.png \) \( mpr:img -resize 300x +write gw-300.png \) \( mpr:img -resize 256x +write gw-256.png \) \( mpr:img -resize 160x +write gw-160.png \) \( mpr:img -resize 128x +write gw-128.png \) \( mpr:img -resize 100x +write gw-100.png \) \( mpr:img -resize 90x +write gw-90.png \) \( mpr:img -resize 80x +write gw-80.png \) \( mpr:img -resize 64x +write gw-64.png \) \( mpr:img -resize 50x +write gw-50.png \) \( mpr:img -resize 40x +write gw-40.png \) \( mpr:img -resize 32x +write gw-32.png \) \( mpr:img -resize 16x +write gw-16.png \) null:
h
@GwynethLlewelyn
GwynethLlewelyn / generate-dane-tlsa-records.sh
Last active November 14, 2023 09:45
Viktor Dukhovni's shell script to generate all possible TLSA records for DANE from the full certificate chain
#! /usr/bin/env bash
# Bash needed for PIPESTATUS array
# Author: Viktor Dukhovni <openssl-users@dukhovni.org> (@ietf-dane)
# Date: 28 December 2015
# From https://community.letsencrypt.org/t/making-a-dane-tlsa-to-work-with-le/2129/8
# See also https://community.letsencrypt.org/t/please-avoid-3-0-1-and-3-0-2-dane-tlsa-records-with-le-certificates/7022
extract() {
case "$4" in
0) openssl x509 -in "$1" -outform DER;;
@GwynethLlewelyn
GwynethLlewelyn / convert-from-Latin-1-to-UTF-8.md
Created November 2, 2023 13:20
One-liner shell script to convert every file in a large directory tree from ISO-Latin-1 to UTF-8

Convert files from ISO-8859-1 (Latin-1) to UTF-8, recursively

This requires recode to be installed (brew install recode or apt install recode).

The example shows HTML files only. Adjust as required.

Process:

  1. (Recursively) find all files that end with *.htm or *.html.
  2. For each match, check its file type using file.
@GwynethLlewelyn
GwynethLlewelyn / get-flag.go
Created August 4, 2023 10:53
Go lang conversion from ISO-3166-1 two-letter codes to flag emoji
// To run this on the Go Playground: https://go.dev/play/p/9na7SU0ExdD
package main
import "fmt"
func main() {
country := "PT"
fmt.Printf("%s — Decimal: %d %d Hex: %#[1]x %#x\n", country, rune(country[0]), rune(country[1]))
@GwynethLlewelyn
GwynethLlewelyn / go-testing-fs-readdir.go
Created March 6, 2023 18:37
How to walk through a directory in Go (using the 'modern' post-1.16 functionality)
// See this in action: https://go.dev/play/p/mA3RRGhyZRe
// Read more about it: https://bitfieldconsulting.com/golang/filesystems#generalising-the-file-counter (scroll down a bit)
//
// The following code excerpt is placed in the Public Domain (CC0) by Gwyneth Llewelyn (2023)
package main
import (
"fmt"
"io/fs"
@GwynethLlewelyn
GwynethLlewelyn / direct-messages.js.md
Created December 15, 2022 14:01
Convert Twitter JSON direct messages to an easier format

Suppose you need to do a copy & paste of a conversation you had on Twitter to send it by email. Unfortunately, it's very hard to copy & paste it in toto from either the app or the web. Twitter makes it as hard as possible to do so, especially if you wish the whole conversation.

Conversations are conveniently stored as JSON files, but... you need to get access to them. One possible way to do so is the following:

  1. Ask Twitter for a link to an archive of all your data to be downloaded (they'll take up to 24 hours to provide you with it)
  2. Make sure jq is installed
  3. "862741-8538292" represents a conversation between two Twitter IDs (recipientId)
  4. You may have to massage the first line of direct-messages.js so that it reads
@GwynethLlewelyn
GwynethLlewelyn / date2exifdate.sh
Created November 19, 2022 18:36
Shell script to change the modification date of a PSD file to the EXIF data within
# !/bin/sh
#
# date2exifdate shell script
# (tested on bash only)
# (c) 2022 by Gwyneth Llewelyn. Most rights reserved.
#
# Licensed under a MIT License (see https://gwyneth-llewelyn.mit-license.org/)
#
#
# Purpose: Change the modification date of a PSD file to the EXIF data within
@GwynethLlewelyn
GwynethLlewelyn / change-email-from-admin-address.php
Created September 21, 2022 14:13
WordPress plugin to Change Email From Admin Address
<?php
/*
Plugin Name: Change Email From Admin Address
Description: A way to get rid of email coming from the wrong address that will cause problems with spam filters.
Author: Clifford Paulick
Version: 1.0
Author URI: https://wpmudev.com/blog/wordpress-email-settings/
*/
/*
@GwynethLlewelyn
GwynethLlewelyn / m4atomp3.sh
Last active December 19, 2022 14:33
Converts M4A to MP3 respecting the original bitrate (uses ffmpeg)
#!/usr/bin/env bash
# Takes a directory as parameter and converts everything inside it
# from M4A to MP3, respecting the bitrate, and creating a directory
# for the converted files.
#
# MIT Licensed by Gwyneth Llewelyn (2022)
#
# Based on https://superuser.com/a/1211902/127382 by @jbowman (2017)