Skip to content

Instantly share code, notes, and snippets.

View attentive's full-sized avatar

Tom attentive

View GitHub Profile
@attentive
attentive / GdalReadVirtualFile.cs
Created April 30, 2024 08:39
Read the raw data from a GDAL VSI file in C#
/// <summary>
/// On various GDAL mailing lists and forums one can find people complaining about the lack of the VSIFReadL
/// function in GDAL's C# bindings, which allows data to be read from a GDAL "virtual file".
///
/// An example is here: https://lists.osgeo.org/pipermail/gdal-dev/2018-July/048838.html
///
/// However it is possible to use .NET Platform Invoke as below to call this function straight from the native
/// GDAL DLL entry point.
/// </summary>
internal static class GdalReadVsiFile
@attentive
attentive / Combine.cs
Last active March 16, 2024 03:54
Path.Combine doesn't work correctly. Here's an alternative function that works a bit better and accepts variadic arguments.
public static class Paths
{
/// <summary>
/// Combine up to 1,000 filesystem paths in a way that you'd hope works better than Path.Combine, which it turns out
/// doesn't work properly.
/// </summary>
/// <param name="paths">A non-null, non-empty array of non-empty, non-whitespace input paths to join together (properly)</param>
/// <returns>A combined path</returns>
public static string Combine(params string[] paths)
{
@attentive
attentive / README.md
Last active February 6, 2024 14:00
Using tsconfig "paths" path aliases with Angular and tsc-alias

Getting tsconfig "paths" path aliases to work with Angular using tsc-alias

If you look around you'll find quite a few people complaining that Angular CLI doesn't work "out of the box" with path aliases for the TypeScript compiler.

Fortunately the handy tool tsc-alias will run the rule over your compiled output and replace the still-present path aliases from your dev codebase with correctly resolved relative paths.

This tool mostly works correctly out of the box, but there are a couple of frustrating gotchas:

  1. Angular sets up custom tsconfig.json files everywhere (eg tsconfig.lib.json). Tools such as ESLint etc don't love this practice and the TypeScript compiler itself doesn't recognise these files or apply their "paths" aliases correctly.

This does turn out to be quite annoying.

I have just spent some time fossicking through all the various answers to this and have found a combination of things that is working for me nicely on Mac OS Ventura.

How to get a real Compose key on OS X Ventura

1. Install the so-called "U.S. Custom" keyboard layout

This is just a "playground" custom keyboard layout for doing exactly what we're going to do, namely setting up a typical Linux style Compose key for an English keyboard.

@attentive
attentive / films.txt
Created December 1, 2022 23:06
List of director's favourites scraped from a MUBI forum post
Original source here: https://archive.ph/qUnBJ
Pedro Almodóvar
The Night of the Hunter (Laughton)
The Rules of the Game (Renoir)
All About Eve (Mankiewicz)
Leave Her to Heaven (Stahl)
North by Northwest (Hitchcock)
Out of the Past (Tourneur)
@attentive
attentive / wat.clj
Last active December 1, 2022 11:01
Example of MP3 metadata access in Clojure via Java interop and JAudioTagger
; I fooled around a bit with this years ago, creating this Gist to replace the defunct repository on my personal GitHub.
; This is just standard Clojure Java interop, you can find out a bit more about JAudioTagger here if you're interested:
;
; https://search.maven.org/artifact/net.jthink/jaudiotagger
(ns wat.core
(:import (org.jaudiotagger.audio AudioFileIO AudioFile)
(org.jaudiotagger.tag FieldKey)
(java.io File)))
@attentive
attentive / default_tuple_dict.py
Last active October 15, 2022 05:18
Versions of Python dict and collections.defaultdict that allow one to use tuples as keys in a natural way
# -*- coding: utf-8 -*-
from collections import defaultdict
# A defaultdict variant of TupleDict with some improvements (eg better exceptions)
class DefaultTupleDict(defaultdict):
__slots__ = ()
@classmethod
def fromkeys(cls, keys, v=None):
@attentive
attentive / rename_prefixed_filesystem.sh
Created February 10, 2022 02:17
Rename a filesystem where directories and files have some consistent prefix, with only the utilities available to msysGit Bash on Windows
#!/bin/sh
# Do all the directories first
find . -name 'SomePrefix*' -type d | awk '{print "mv "$0" "gensub(/\/SomePrefix(.*)$/,"/SomeOtherPrefix\\1","g");}' | sh
# Then do all the files
find . -name 'SomePrefix*' -type f | awk '{print "mv "$0" "gensub(/\/SomePrefix(.*)$/,"/SomeOtherPrefix\\1","g");}' | sh
@attentive
attentive / carve_mbtiles.py
Created October 13, 2020 21:11
Using GDAL and Python (QGIS 3.10 compatible) to carve a set of MBTiles from a larger raster based on the polygon region features in a shapefile
import itertools, os, time
from sys import stdout
from osgeo import gdal, ogr, osr
# change these to the local paths if running this yourself
scratch = r"D:\scratch"
mbtilesFile = r"D:\big-mbtiles-file.mbtiles"
shapefile = r"C:\temp\regions.shp"
webMercator = osr.SpatialReference()
@attentive
attentive / qgsblockingnetworkrequest_example.py
Last active September 26, 2020 23:10
Use QgsBlockingNetworkRequest to download a file
# Just chucking this here because the documentation's a little weak and someone
# might find it useful. This has changed a few times in QGIS history.
# NB this was hacked up from some code that worked in QGIS 3.4, 3.10 and 3.14, it
# may have minor indentation issues but … this is the gist of it.
from qgis.PyQt.QtCore import QObject, QUrl
from qgis.PyQt.QtNetwork import QNetworkReply, QNetworkRequest
from qgis.core import Qgis, QgsMessageLog, QgsBlockingNetworkRequest