Skip to content

Instantly share code, notes, and snippets.

View ammojamo's full-sized avatar

James Watmuff ammojamo

  • Planticle
  • Adelaide, Australia
View GitHub Profile
@ammojamo
ammojamo / bionet-spname-sqlite.sh
Created March 7, 2022 11:16
Convert Bionet Species Names to Sqlite
curl https://data.bionet.nsw.gov.au/biosvcapp/odata/SpeciesNames > SpeciesNames.json
cat SpeciesNames.json | jq -r '(.value|map(keys)|add|unique) as $cols | (.value | map(. as $row | $cols | map($row[.]))) as $rows | $cols, $rows[] | @csv' > SpeciesNames.csv
echo '.mode csv
.import SpeciesNames.csv spname' | sqlite3 spname.sqlite
@ammojamo
ammojamo / Diff.kt
Created March 24, 2021 12:23
Diff algorithms in Kotlin
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
abstract class Diff {
sealed class Op<T> {
data class Insert<T>(val index: Int, val value: T) : Op<T>()
data class Delete<T>(val index: Int) : Op<T>()
}
@ammojamo
ammojamo / JSON.swift
Created February 11, 2020 23:11
Messing around with different ways to describe JSON types in Swift
import Foundation
// Protocol-based approach
protocol JSONValue {}
extension Int: JSONValue {}
extension String: JSONValue {}
extension Bool: JSONValue {}
extension Double: JSONValue {}
@ammojamo
ammojamo / drag-zoom.js
Created January 13, 2020 04:33
Google maps - drag rectangle to zoom
// Zero-dependencies drag zoom control
function dragZoomControl(map) {
var drawingManager = new google.maps.drawing.DrawingManager();
drawingManager.setOptions({
drawingMode : google.maps.drawing.OverlayType.RECTANGLE,
drawingControl : false,
rectangleOptions : {
@ammojamo
ammojamo / pipe.rs
Created July 27, 2016 06:48
Rust pipe from Read to Write
use std::io::prelude::*;
// Feedback welcome
fn pipe(source: &mut Read, dest: &mut Write) -> std::io::Result<usize> {
let mut buf = [0; 512];
let mut bytes_read: usize = 0;
let mut bytes_written: usize = 0;
let mut total_bytes: usize = 0;
loop {
@ammojamo
ammojamo / InsertSpecialSymbolCommand.py
Created July 3, 2014 11:07
ST2 Insert Special Symbol Plugin
import sublime, sublime_plugin
import unicodedata
class InsertSpecialSymbolCommand(sublime_plugin.TextCommand):
DEBUG = True
replacements = dict((unicodedata.name(L).split()[-1].lower(), L) for L in map(unichr, range(945, 970)))
@staticmethod
def debug(string):
@ammojamo
ammojamo / viewport-scaling-test.html
Created May 11, 2012 02:57
Viewport scaling test
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=2.5, maximum-scale=2.5, minimum-scale=2.5, width=device-width, user-scalable=no" />
</head>
<body>
<div style="width: 100px; height: 100px; background: red;">Hello World</div>
</body>
</html>
@ammojamo
ammojamo / track.sh
Created December 6, 2011 23:38
Time tracking bash script for Mac OS X - periodically asks what you have been doing
#!/bin/sh
input=
while true
do
input="$(/usr/bin/osascript 2>/dev/null <<-__HEREDOC__
with timeout of 300 seconds
tell application "System Events"
@ammojamo
ammojamo / wkt.jison
Created June 27, 2011 05:55
WKT Grammar for Jison
/*
* Description: WKT Grammar
*
* Based on OGC document 06-103r4:
* OpenGIS Implementation Standard for Geographic information
* - Simple feature access
* - Part 1: Common architecture (Version 1.2.1)
*
* Copyright (c) 2011 James Watmuff
*
@ammojamo
ammojamo / mvn-all.sh
Created December 20, 2010 04:54
Run maven in a list of directories, passing arguments and failing fast
#!/bin/sh
parent=$(pwd)
for dir in proj1 \
proj2 \
proj3
do
pushd $dir && mvn $@ | tee $parent/mvn-out && expr $PIPESTATUS = 0 && popd || break
done
osascript -e 'tell app "System Events" to activate'