Skip to content

Instantly share code, notes, and snippets.

sealed trait Conc[+T] {
def level: Int
def size: Int
def left: Conc[T] = throw new NoSuchElementException("no left subtree")
def right: Conc[T] = throw new NoSuchElementException("no right subtree")
def <>[U >: T](that: Conc[U]): Conc[U] = {
if (this == Empty) that
else if (that == Empty) this
else concat(this, that)
@george-hawkins
george-hawkins / ResolveArgumentTest.java
Created February 1, 2017 15:59
ServletRequestMethodArgumentResolver issue
package com.example;
import java.lang.reflect.Method;
import java.security.Principal;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.core.MethodParameter;
import org.springframework.security.core.Authentication;
[Unit]
Description=Broadcast triggered shutdown
After=network.target
# To install:
# $ sudo apt-get install socat
# $ sudo chown root:root broadcast-shutdown.service
# $ sudo mv broadcast-shutdown.service /etc/systemd/system
# $ sudo systemctl daemon-reload
# $ sudo systemctl enable broadcast-shutdown

Accessing Okta accounts etc. in Java

If you've already followed the Getting Started With Okta document from Stormpath then you should already have a Spring Boot application where users can login.

However if you try to interogate the system e.g. for all accounts you'll quickly find out that most of the methods provided by Application, such as getAccounts(), throw UnsupportedOperationException.

Another way to get at this data is via the Okta Java SDK.

By default this SDK uses a different mechanism to pickup the Okta API token etc. to the one used by the Okta compatible version of the Stormpath Spring Boot SDK.

Gpio interrupt callbacks in Node.js

When using the C++ Gpio method isr or the C function mraa_gpio_isr it's important to know that the passed in function will be called in the context of a low level interrupt.

As such it should be coded very carefully, and typically do as little as possible, in order not to interfere with the environment that has been interrupted.

When using the isr method in Javascript do we have to worry about this kind of thing?

The answer is no, as the logic for the Javascript wrappers ensures that the callback function passed to isr is invoked from the normal Node.js event loop.

#!/bin/bash
DRIVERS_DIR=/sys/bus/pci/drivers
# George Hawkins Nov 18th, 2014
# I found various scripts that bind and unbind the USB devices to reset the whole USB system.
# All used hardcoded slots and drivers - slots aren't consistent across machines and driver names change with OS releases.
# This script attempts to discover all values.
# This awk script finds all PCI devices with class 'USB controller' that have a slot and a driver.

Below is page 2 of the Routledge Frequency Dictionary of German. This screenshot was taken using the "Look inside" feature of the Amazon product page for this book. The dictionary says it is based off the Leipzig/BYU Corpus of Contemporary German. Googling for information on this corpus turns up little or nothing.

Leipzig make available various corpora here but neither it nor Brigham Young University seem to have any web content related to something called the "Corpus of Contemporary German".

The dictionary says the corpus brings together words from spoken language, literature, newspapers, academic texts and instructional language. So the dictionary claims to use a broad based corpus and as its full title is "A Frequency Dictionary o

// Compare IGroupable (with a type parameter) here with IGroupableX below (without a type argument).
// In what situation will the generics version buy you something that the non-generic version won't.
interface IGroupable<E extends IGroupable<E>> {
E fraction(double fraction);
public static class AlphaGroupable implements IGroupable<AlphaGroupable> {
@Override
public AlphaGroupable fraction(double fraction) { return null; }
}