Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / Example usage.java
Created September 19, 2009 13:40
How do you like my JQuery implementation in Java?
String result = $(document).find("#result").text();