Skip to content

Instantly share code, notes, and snippets.

View tjstebbing's full-sized avatar
🐝
.go .py .js .vim

Timothy Stebbing tjstebbing

🐝
.go .py .js .vim
View GitHub Profile
#!/bin/bash
#apt-get install html-xml-utils
bridgeURL="http://howmanydayssincemontaguestreetbridgehasbeenhit.com"
hookURL="http://example.com"
days=$(echo "$bridgeURL" | \
wget -O- -i- 2>/dev/null | hxnormalize -x | hxselect -i '.day_box' \
| grep -o -E '[0-9+]')

Atomic refreshing in memory DBs without mutexes

This is a simple way of having an in-memory DB which is safe to use across multiple goroutines without needing to use any kind of mutex for updates.

1. Create an interface

type FooDB interface {
@tjstebbing
tjstebbing / infile.txt
Last active December 19, 2018 07:21
thingy for Pat & Welly
11300841 ['1775','10921','3583','5838','15519','1794']
11300841 ['10761','9251','69928','78022','10459','5188','120504','120506','128530','94604']
1345 ['10761','9251','69928','78022','10459','5188','120504','120506','128530','94604']

🚐 MINI BUS

Mini Bus is a drastically simplified version of D-BUS, specifically for plain text communication between terminal UIs / shell scripts and terminal multiplexers.

minibusd

Minibus daemon monitors /tmp/minibus for newly created UNIX Domain sockets (SOCK_STREAM) and connects to them based on their location:

package main
import (
"bufio"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
@tjstebbing
tjstebbing / tests.md
Last active January 4, 2018 02:45
Super simple API tests with bash

Very simple method for writing API tests for REST services using bash, httpie, jq and shunit2.

Write some tests:

#!/bin/sh

# Integration test suite, install: httpie, jq and shunit2

alias http='http --body --pretty=none'
@tjstebbing
tjstebbing / css_selector_regex.js
Created August 15, 2017 05:52
#javascript #css #regex
const reg = /\s*([^\s\{,]+(?:\s+[^\s\{,]+)*)|\s*\{[^\}]*\}/gm
css = `
.car, div.train, #bus
div.jetski:nth-child(4n)!important {
display: none;
}
.banana ,
#fruit.ap_ple.pear {
@tjstebbing
tjstebbing / test_bard.md
Last active August 13, 2017 11:40
This is a bard test file, everything here is run and evaluated.

Bard testing tool

Bard is a commandline utility for running code tests in multiple languages using Markdown files as the source. Bard has two basic concepts:

  1. Bard extracts code blocks from markdown and executes them with the native language test tools.
  2. Bard interleaves shell commands using a special syntax that compares command output with expected responses.
@tjstebbing
tjstebbing / whatIReallyReallyWant.md
Last active August 7, 2017 07:14
Atomic client side stores with server sync

At CampJS this week there were a lot of talks about frontend web components, mostly focused on views. It struck me, as a mostly backend engineer that we could do with some better abstractions around client side/server side data sync to go with the new view model systems out there. Here's a few thoughts I had over the weekend..

A client side, in memory data store:

  1. Which is atomic (transactional?)
  2. With data that is strongly typed (validated)
  3. That syncs to a server (which is authoritative)
  4. That syncs uncommitted content to local storage transparently
  5. That is resilient to connectivity trouble
  6. That is bounded by the developer
@tjstebbing
tjstebbing / anvil.md
Last active May 25, 2017 08:40
anvil

Anvil SQL helper

Anvil is a golang lib and wrapper for database/sql that aims to provide:

  • Out of the box CRUD operations for user defined struct types
  • Extensible operations via user defined SQL templates
  • A structured representation of Tag defined SQL field types for use in SQL templates
  • Helpers for working with multiple DB sharding

Anvil isn't: