Skip to content

Instantly share code, notes, and snippets.

View simonwo's full-sized avatar

Simon Worthington simonwo

View GitHub Profile
@simonwo
simonwo / s3vfs.py
Created September 28, 2021 10:08
SQLite Virtual File System for S3 – MVP
import boto3
import apsw
BLOCK_SIZE = 64 * 1024
EMPTY_BLOCK = b"".join([b"\x00"] * BLOCK_SIZE)
# Inheriting from a base of "" means the default vfs
class S3VFS(apsw.VFS):
def __init__(self, s3, bucket, vfsname=f"s3vfs", basevfs=""):
self.vfsname = vfsname
@simonwo
simonwo / spec.yml
Created January 24, 2023 23:38
Bacalhau job spec with Inline storage
Spec:
Engine: Docker
Verifier: Noop
Publisher: Estuary
Docker:
Image: "jsacex/easyocr"
Entrypoint: ["easyocr", "-l", "ch_sim", "en", "-f", "./inputs/chinese.jpg", "--detail=1", "--gpu=True"]
Inputs:
- StorageSource: IPFS
Path: "/root/.EasyOCR/model/zh_sim_g2.pth"
@simonwo
simonwo / rust-wasm32-wasi-compile.sh
Last active November 3, 2022 09:29
Compile Rust to WASM with WASI
#!/bin/sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs -o rustup.sh
sh rustup.sh -y
export PATH=~/.cargo/bin:$PATH
rustup target install wasm32-wasi
apt-get install -y build-essential libc6-dev clang-8 gcc-multilib
cd /code
CC_wasm32_wasi=clang-8 cargo build --target wasm32-wasi --release
@simonwo
simonwo / docxtables2json.py
Created July 20, 2020 20:10
Pulling all of the tables from a Word document into JSON files
#!/usr/bin/env python3
from sys import stdout, stderr, argv
import os.path
import json
try:
from docx import Document
except ImportError:
print("Maybe you should $ pip install python-docx", file=stderr)
@simonwo
simonwo / compact-trello.css
Last active July 26, 2017 10:10
Compact Trello userstyle. If you have the Stylus extension, you can download the JSON and use "Import styles".
@-moz-document domain("trello.com") {
.card-label.mod-card-front {
width: 8px;
height: 32px;
}
.list-card-labels {
margin-right: 6px;
margin-top: 2px;
float: left;
}
@simonwo
simonwo / gist:6868309
Created October 7, 2013 13:47
Partial classes in Ruby. Generates a new, specialised class by defining some of it's initializer arguments ahead of time.
class Class
def partial(*prep)
Class.new(self) do
define_method(:initialize) do |*args|
super(*(prep + args))
end
end
end
def << (prep)
@simonwo
simonwo / wireless_check.sh
Created March 9, 2015 00:45
Script to be called from cron to check Raspberry Pi's wireless connection
#!/bin/bash
# The address of the wireless access point itself
GATEWAY=`netstat -nr | grep wlan0 | grep G | awk '{ print $2 }'`
# Let's try and contact the wireless access point
ping -c 1 $GATEWAY
# Did we succeed? (ping will make $? equal to 1 if it failed, or 0 if it succeeded)
if [[ $? == 1 ]]; then
@simonwo
simonwo / cleartypes.h
Created February 25, 2015 18:58
These aliases make pointers and references look more like real types. See https://simonwo.net/code/clearer-cpp-types for more.
#pragma once
/* These type alias templates (introduced in C++11) allow
* us to template typedefs (via a different syntax).
*
* Here we are templating generic pointer and reference types
* so we could write ptr<T> instead of T*.
*
* See simonwo.net/code/clearer-cpp-types for more.
*/
@simonwo
simonwo / pending.rb
Created February 2, 2015 10:49
Pending scenarios in Cucumber
# Place me in your support/ directory and then use the @pending tag
Unless Cucumber::VERSION =~ /^2\./
Around '@pending' do |scenario, block|
scenario.steps.each &:skip_invoke!
block.call
scenario.steps.each {|step| step.status! :pending}
end
else
raise "Well done on upgrading to Cucumber 2. It's time to delete #{__FILE__}!"
end