Skip to content

Instantly share code, notes, and snippets.

View attentive's full-sized avatar

Tom attentive

View GitHub Profile
@attentive
attentive / core.cljs
Last active February 12, 2019 04:53
How to integrate react-native-splash-screen with ClojureScript
(ns rnss.core
(:require [oops.core :refer [oget ocall]]
[reagent.core :as r]
["react-native" :as RN]
["react-native-splash-screen" :as RNSS]))
;; The code below depends on the existence of a separate splash screen
;; layout in your app, as per the react-native-splash-screen doco.
;; This sample shows only how to reference the splash screen library and
@attentive
attentive / console.js
Last active July 11, 2019 13:30
Unlike tweets from the Twitter Likes page, via JavaScript in console
// See https://www.quora.com/How-do-I-bulk-delete-likes-on-Twitter
inter = setInterval(() => {
$("html, body").animate({
scrollTop: $(document).height()-$(window).height(),
complete: setTimeout(() => {$('.ProfileTweet-action--unfavorite').click().remove()}, 1000)
})
if($('.has-more-items').length == 0) {
clearInterval(inter)
@attentive
attentive / core.cljs
Last active March 11, 2019 08:56
Unexpected clojure.spec behaviour
(namespace foo.core
(:require [clojure.spec.alpha :as s]))
(s/def ::n (s/or :integer integer? :string string?))
(s/def ::m (s/keys :req-un [::n]))
(defn m-even? [m] (even? (:n m)))
(s/def ::m-even (s/and ::m m-even?))
@attentive
attentive / swagger.json
Last active October 4, 2019 02:46
EML Data Services Swagger
{
"swagger": "2.0",
"info": {
"description": "This is a partial Swagger representation of the EML Data Services API documentation version 1.0 that will be used to generate a .NET client. See https://developer.emerchants.com.au/paywith/eml.v1.html# for vendor documentation.",
"version": "1.0",
"title": "EML Data Services API",
"contact": {
"email": "tom.lynch@radicalsystems.com.au"
}
},
@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
@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 / 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 / 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 / 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 / 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)