Skip to content

Instantly share code, notes, and snippets.

@brimworks
brimworks / Example.java
Last active September 23, 2022 16:40
JsonValue avoiding casting.
import static JsonUtil.match;
public class Example {
class Pojo {
String field1;
int field2;
}
public Pojo toPojo(JsonValue val) {
return match(val, new JsonMatch<Pojo>() {
public Pojo matchDefault() {
return null;
@brimworks
brimworks / TLSByteChannel.java
Last active July 2, 2021 14:18
Implements the ByteChannel and GatheringByteChannel interfaces in a blocking way.
package io.nats.client.channels;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.GatheringByteChannel;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
Copyright 2020 Brian Maher
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
@brimworks
brimworks / build.gradle
Last active April 18, 2020 21:10
Generate java files in a gradle build using ragel.
abstract class Ragel extends DefaultTask {
@InputFile
abstract File inputFile
@OutputFile
abstract File outputFile
@TaskAction
void execute(InputChanges inputChanges) {
project.exec {
commandLine "ragel", "-J", "-o", outputFile, inputFile
@brimworks
brimworks / grep-r
Created November 14, 2019 17:17
grep-r
#!/bin/bash -e
#
# Usage: grep-r PATTERN [ GREP-ARGS ] [ -- [ DIRECTORIES ] [ FIND-ARGS ] ]
#
# PATTERN - The pattern to grep within files for
# GREP-ARGS - A list of arguments to pass to grep, for example -E for extended regex
# DIRECTORIES - A list of directories to seach (may not begin with `-`)
# FIND-ARGS - A list of arguments to pass to find, for example `-regex '.*/[fF]ile.txt'`
#
# Defaults:

Keybase proof

I hereby claim:

  • I am brimworks on github.
  • I am brimworks (https://keybase.io/brimworks) on keybase.
  • I have a public key whose fingerprint is 9EB6 148F ECF7 5520 AF44 7A0C 371C 6A35 2FB9 34A6

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am brimworks on github.
  • I am bmaher (https://keybase.io/bmaher) on keybase.
  • I have a public key whose fingerprint is DFD2 9E51 3F65 4C79 1E76 3833 DB9B 9FF1 153F 2817

To claim this, I am signing this object:

local uv = require("uv")
local ffi = require("ffi")
local PIPE_NAME = "Windows" == ffi.os and "\\\\.\\pipe\\luv-bug" or "luv-bug"
local function mkresume()
local thread = coroutine.running()
return function(...)
coroutine.resume(thread, ...)
end
end
@brimworks
brimworks / gist:1390733
Created November 24, 2011 06:08
lua cairo railroad diagram
#!/usr/bin/env lua
-- "Quick" hack to generate rail road diagrams.
--
local cairo = require("lcairo")
-- reverse ipairs():
local function ripairs(t)
local function ripairs_it(t,i)
local v=t[i]
if v==nil then return v end
@brimworks
brimworks / gist:1308155
Created October 24, 2011 01:10
Get luvit to build on OS-X
diff --git a/Makefile b/Makefile
index b4fef80..59bd580 100644
--- a/Makefile
+++ b/Makefile
@@ -58,8 +58,8 @@ ${GENDIR}:
${LUADIR}/src/libluajit.a:
git submodule update --init ${LUADIR}
- sed -e "s/#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT/XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT/" -i deps/luajit/src/Makefile
- sed -e "s/#XCFLAGS+= -DLUA_USE_APICHECK/XCFLAGS+= -DLUA_USE_APICHECK/" -i deps/luajit/src/Makefile