Skip to content

Instantly share code, notes, and snippets.

@robshep
robshep / gen_weeknotes.py
Last active April 24, 2019 16:01
Hugo Blog: Generate weekly blog content file
"""
Generate a year's worth of \"Week notes\" blog content files using ISO week format.
Usage: cd <hugo content sub-folder> && python3 <year>
E.g. $ cd ~/hugo/content/blog
$ python3 ~/hugo/scripts/gen_weeknotes.py 2019
Produces a folder for each week for publication on a Sunday:
20190106-weeknotes-2019W01 to 20191229-weeknotes-2019W52
Each with an index.md having suitable frontmatter: E.g. week 31 of 2019 looks like:
@robshep
robshep / tct.html
Created April 14, 2019 11:22
Testing out Hugo's image finding routine in the twitter_card shortcode
<!-- save in /layouts/shortcodes/tct.html -->
<!-- usage: {{< tct >}} -->
<div>
{{- with $.Page.Params.images -}}
<span>Image: page.params.images[0]: <code>{{ index . 0 | absURL }}</code> </span>
{{ else -}}
{{- $images := $.Page.Resources.ByType "image" -}}
{{- $featured := $images.GetMatch "*feature*" -}}
{{- $featured := cond (ne $featured nil) $featured ($images.GetMatch "{*cover*,*thumbnail*}") -}}
{{- with $featured -}}
@robshep
robshep / hl.bash
Created March 17, 2019 16:23
Highlight a character at a position
#!/bin/bash
# Inserts a single Red background highlight at the chosen character position
# usage: hl -c <pos> <file>
#
# E.g. /usr/local/bin/hl -c 384 /tmp/query.sql
head $1 $2 $3; \
gecho -e -n "\e[41m"; \
@robshep
robshep / build.sh
Created February 13, 2019 11:14
Building ovpn
# OVPN local build
export GOPATH=/root/gocode
cd /root/gocode
go get -u github.com/cad/ovpm/...
go get -u github.com/jteeuwen/go-bindata/...
cd ~/gocode/src/github.com/cad/ovpm
@robshep
robshep / CompareRoundingImplementations.java
Created November 27, 2018 14:21
Testing Java against Javascript implemenations
import static org.assertj.core.api.Assertions.assertThat;
import java.io.InputStreamReader;
import java.util.Random;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import org.junit.Test;
@robshep
robshep / README.md
Last active July 7, 2018 22:33
Hotswap Agent for JVM on MacOS
@robshep
robshep / AccessLogToMainLogAppender.java
Last active May 10, 2018 14:07
Logging Logback-access messages via another logger
package net._95point2.common.logging;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.Charset;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.OutputStreamAppender;
import ch.qos.logback.core.encoder.Encoder;
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
@robshep
robshep / FromNow.js
Last active June 25, 2019 19:42
Make relative times using moment.js
/**
* inspired by https://timeago.yarp.com but useful if you already have moment.js and don't want another library.
*
* using moment.js, make relative times.
*
* Public Domain - See LICENSE.txt
*
* <time datetime="2018-05-02 16:16:33.58">2018-05-02 16:16:33.58</time>
* gives
* <time datetime="2018-05-02 16:16:33.58">26 minutes ago</time>
@robshep
robshep / index.html
Created April 24, 2018 09:40
UKHO Bathymetry Tiles
<html>
<head>
<title>Demo leaflet.TileLayer.WMTS</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<script src="https://rawgithub.com/mylen/leaflet.TileLayer.WMTS/master/leaflet-tilelayer-wmts.js"></script>
</head>
<body>
@robshep
robshep / usbtemper_mqtt.py
Created March 27, 2018 15:52
Temp from USB Temper to MQTT
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'temperusb==1.5.3','console_scripts','temper-poll'
__requires__ = 'temperusb==1.5.3'
from temperusb.temper import TemperHandler
from paho.mqtt.publish import single as mqtt_single
def getTempReading():
th = TemperHandler()
devs = th.get_devices()
readings = []