Skip to content

Instantly share code, notes, and snippets.

@trygvis
trygvis / Example usage.java
Created September 19, 2009 13:40
How do you like my JQuery implementation in Java?
String result = $(document).find("#result").text();
@trygvis
trygvis / jarindex.sh
Created July 22, 2010 11:24
Utility to create an index of all JAR files recursively
$ cat ~/bin/jarindex
#!/bin/bash
if [ -x /opt/csw/bin/gawk ]
then
awk=/opt/csw/bin/gawk
else
awk=awk
fi
@trygvis
trygvis / 00README.md
Last active September 13, 2015 21:21
usage: arp-to-mqtt [-t <prefix>] [-h host] [-i <interface>]

A utility script to dump an ARP table to a set of MQTT topics.

For each MAC with an IP publish a message to

<prefix>/<mac of interface>/<mac of device>/ip

and

@trygvis
trygvis / LocaleUtils.java
Created April 13, 2011 11:36
String to java.util.Locale parser
public class LocaleUtil {
private static Pattern pattern = Pattern.compile("^([a-z][a-z])(_([A-Z][A-Z]))?$");
/**
* Returns null if the string couldn't be parsed
*/
public static Locale parseStringToLocale(String s) {
Matcher matcher = pattern.matcher(s);
if(!matcher.matches()) {
@trygvis
trygvis / Blaze.hs
Created May 7, 2011 16:41
My first CPU
module Blaze where
import CLasH.HardwareTypes
type Word = Signed D4
type RegisterIndex = Index D4
data Instruction =
Nop
| In RegisterIndex
@trygvis
trygvis / Format.hs
Created June 7, 2011 11:30
Format parser for hledger
-- This is hledger-lib/Hledger/Read/Format.hs
module Hledger.Read.Format where
import Numeric
import Data.Maybe
import Test.HUnit
import Text.ParserCombinators.Parsec hiding (spaces)
{-
@trygvis
trygvis / json-parser.scala
Created September 27, 2011 10:26
Monadic json parser descriptor
{
object Parser {
def apply(name: String): Parser = Parser(name, Nil)
}
case class Parser(name: String, items: List[Parser]) {
// println("parser constructor: " + this)
def flatMap(parser: Parser => Parser): Parser = {
println("flatMap: " + this)
@trygvis
trygvis / sbt
Created December 1, 2011 14:37
My SBT wrapper scripts
#!/bin/sh
if [ -z "$SBT_VERSION" ]
then
SBT_VERSION=0.7.7
fi
JAR=$HOME/.sbt/sbt-launch-$SBT_VERSION.jar
mkdir -p $HOME/.sbt
@trygvis
trygvis / spi_packet_analyzer.sh
Created December 23, 2011 22:21
ENC28J60 SPI packet analyzer written i bash
#!/bin/bash
first=1
# Skip the first line
read junk
export IFS=","
last_id=abc
@trygvis
trygvis / Build.scala
Created March 31, 2012 15:51
An improved sbt build file for Scalatron
// Based off http://jmhofer.johoop.de/?p=292 / https://gist.github.com/2260897
// Put this file under project/Build.scala
// Copy Scalatron/bin/Scalatron.jar to lib/ before compiling
// Tested with sbt version 0.11.2
import sbt._
import Keys._
object Build extends Build {
val botDirectory = SettingKey[File]("bot-directory")