Skip to content

Instantly share code, notes, and snippets.

@sjohnr
sjohnr / Grunge.g4
Created March 12, 2014 02:13
Learning ANTLR
grammar Grunge;
root : statement*;
// language rules
literal : LITERAL
| '{' LITERAL ( ',' LITERAL )* '}'
;
variable : VAR ;
constant : CONSTANT ;
@sjohnr
sjohnr / TestZreLogMsg.java
Last active August 29, 2015 14:02
GSL Codec
package org.zyre;
import static org.junit.Assert.*;
import org.junit.Test;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Socket;
import org.zeromq.ZFrame;
import org.zeromq.ZContext;
/**
@sjohnr
sjohnr / SGML.g4
Last active February 6, 2016 06:21
SGML (Sounds like sigmal)
grammar SGML;
// rules
root : aggregate ;
aggregate : START_TAG ( aggregate | element )* END_TAG ;
element : START_TAG content END_TAG? ;
content : WORD+ ;
// tokens
START_TAG : LT IDENTIFIER GT ;
enum class CharacterClass(val regex: String) {
Alpha("[A-Za-z]"), UpperAlpha("[A-Z]"), LowerAlpha("[a-z]"), Numeric("[0-9]"), AlphaNumeric("[A-Za-z0-9]"), Symbol("[!@#$%^&*()\\-_+|~=`{}\\[\\]:\";'<>?,.\\/\\\\]"), Character(".")
}
enum class PolicyType(val text: String) {
MustContain("MUST contain"), MustNotContain("MUST NOT contain"), MustMatch("MUST match")
}
enum class RangeType(val text: String) {
AtMost("at most %s"), AtLeast("at least %s"), Exactly("exactly %s"), Between("between %s and %s")
@sjohnr
sjohnr / app.html
Last active June 8, 2017 03:16 — forked from AStoker/app.html
Select Material
<template>
<require from="./ux-select"></require>
<div style="margin: 20px 0;">
<ux-select options.bind="['Option 1', 'Option 2', '', 'Option 3']" value="Option 2"></ux-select>
</div>
<div style="margin: 20px 0;">
<ux-select options.bind="['Some other option', 'A second option', 'A third option', 'A really long fourth option that is wider than the known universe']"></ux-select>
</div>
<div style="margin: 20px 0;">
<ux-select options.bind="['CA', 'NE', 'WY']"></ux-select>
@sjohnr
sjohnr / RingBuffer.kt
Created July 8, 2019 02:50
RingBuffer.kt
import java.util.AbstractQueue
/**
* RingBuffer implementation of the Queue interface, used to create a fixed-size
* collection. A ring buffer is a collection that is safe to add to, will not
* run out of space, and drops the oldest element when adding to a full buffer.
*/
class RingBuffer<E>(private val capacity: Int = 16) : AbstractQueue<E>() {
private var head = 0
override var size = 0
@sjohnr
sjohnr / .zshrc
Last active July 16, 2021 14:53
Export output of piped command to an environment variable
function exp() {
export $1=$(cat /dev/stdin)
}
@sjohnr
sjohnr / DaoRegisteredClientRepository.java
Last active November 24, 2021 01:22
DaoRegisteredClientRepository for Spring Authorization Server
/*
* Copyright 2020-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sjohnr
sjohnr / Client.java
Last active October 15, 2022 19:05
JpaRegisteredClientRepository
/*
* Copyright 2020-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@sjohnr
sjohnr / AuthorizationConsent.java
Last active May 10, 2022 22:25
JpaOAuth2AuthorizationConsentService
/*
* Copyright 2020-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software