Skip to content

Instantly share code, notes, and snippets.


Jens Alfke snej

View GitHub Profile
snej /
Last active May 8, 2021
Tails! A tiny Forth core written as a hack for May Forth 2021, using some of Wasm3's secret optimization sauce.
// Tails has grown a bit and moved out into its own repository:
// Please visit it there!
// If you want to see the tiny original version from May Forth 2021, it's still here;
// click the "Revisions" button above, or go to:
snej / threadSafeFuture.nim
Last active Nov 12, 2020
Thread-safe Futures for Nim
View threadSafeFuture.nim
# threadSafeFuture.nim
# Jens Alfke, 30 June 2020
import asyncdispatch, deques, locks, sugar, threadpool
## Utilities for mixing async/await with threads.
## ``threadSafe()`` takes a Future and returns a new Future that can be completed on any thread.
## The original Future's callback will still be invoked on its original thread, and ``await``
## works normally.
snej / Async.hh
Created Aug 28, 2018
C++ implementation of C# / JavaScript style async calls
View Async.hh
// Async.hh
// Copyright © 2018 Couchbase. All rights reserved.
#pragma once
#include "RefCounted.hh"
#include <functional>
snej /
Created Jul 8, 2016
Stuff to prove my identity on

Keybase proof

I hereby claim:

  • I am snej on github.
  • I am snej ( on keybase.
  • I have a public key ASA32IteNIxEuZRwRwerBGrd-RL2UMiz4nxBpK5Kqu6TjQo

To claim this, I am signing this object:

snej / bitcodesize.rb
Created Mar 1, 2016
Simple tool that scans an iOS library and checks the size of the bitcode segment for each included object file. It logs a warning for files with no bitcode or whose bitcode is less than 1Kbyte; or with the -v flag it logs the sizes of all bitcode segments.
View bitcodesize.rb
#! /usr/bin/env ruby
# By Jens Alfke. Do What Thou Wilt shall be the whole of the license.
def listBitcode(path, arch, verbose =false)
result = []
filename = nil
section = nil
output = `otool -l -arch #{arch} "#{path}"`
snej / QRCode.m
Created Sep 21, 2015
Shows how to generate a QRCode on iOS or Mac OS X
View QRCode.m
#import <UIKit/UIKit.h>
typedef UIImage QRImage;
#import <AppKit/AppKit.h>
typedef NSImage QRImage;
+ (QRImage*) QRCodeImageWithData: (NSData*)data size: (CGFloat)size {
snej / QRCodeScanner.m
Created Sep 21, 2015
Snippet showing how to capture QR codes from the device camera on iOS or Mac OS X
View QRCodeScanner.m
- (BOOL) startCapture: (NSError**)outError {
if (!_session) {
_session = [[AVCaptureSession alloc] init];
AVCaptureDevice* video = [AVCaptureDevice defaultDeviceWithMediaType: AVMediaTypeVideo];
if (!video)
return [self failWithMessage: @"No video camera available" error: outError];
AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice: video
error: outError];
if (!input)
return [self failWithMessage: @"Couldn't acquire input device" error: outError];
snej / geo_bug.sql
Last active Aug 29, 2015
Demonstrates a possible rtree regression in sqlite 3.8.5
View geo_bug.sql
-- This demonstrates what seems to be a regression in the SQLite version (3.8.5) in OS X 10.10 DP7.
-- The final 'select' statement at the end of the file returns zero rows, not three.
-- The query works fine in OS X 10.9.4 (SQLite 3.7.13) and in earlier versions of 10.10 up to DP6.
-- If I alter the bboxes table to be a regular (non-rtree) table, the bug goes away.
-- Run this like so:
-- sqlite3 -init geo_bug.sql
snej / Issue280Logs
Created Mar 18, 2014
Logs from both clients, for Couchbase Lite issue #280
View Issue280Logs
Device A: (Has existing data)
12:41:03.289| Logging mode 2 enabled in domains: {ChangeTracker, Sync, SyncVerbose}
12:41:03.346‖ Sync: CBL_Puller[] STARTING ...
12:41:03.349‖ Sync: CBL_Puller[]: Reachability state = <>:unreachable (00), suspended=0
2014-03-17 12:41:03.348 ShotBOT[55788:a0b] Application windows are expected to have a root view controller at the end of application launch
12:41:03.350‖ Sync: CBL_Pusher[] STARTING ...
12:41:03.351‖ Sync: CBL_Pusher[]: Reachability state = <>:reachable (20002), suspended=0
12:41:03.351‖ Sync: CBL_Pusher[]: Going online
12:41:03.351‖ Sync: CBL_Pusher[] Progress: set active = 1
snej / gist:6216072
Created Aug 12, 2013
Output of 'changes' view of sync gateway, in form "key[tab]value[tab]docid". Note the discontinuity, where keys 1181-2174 appear at the start (before 401) and then later there is a gap from 994-2175.
View gist:6216072
/db: “channels” View
Key Value ID
["*",1181] ["78k9je3j3k6","1-7b6054260a204912852c3021cab9168c"] 78k9je3j3k6
["*",1182] ["kcd0neg7kac","1-ebd3a623c406b28b80d1ebf651ffacec"] kcd0neg7kac
["*",1183] ["eb33dbinaii","1-4b4a5598313a2f79321f60364b43a990"] eb33dbinaii
["*",1184] ["f41cig0kk86","1-d44e48481e63331720822afa9fbf3e1f"] f41cig0kk86
["*",1185] ["6k5anc2kaii","1-1cec51d3336824eaefc45b3b5fc492f8"] 6k5anc2kaii
["*",1186] ["j026jml39","1-92f7448c5727533df4e070d06f67386d"] j026jml39
["*",1187] ["bnn1ae3b6","1-6dd3cd60eefd7a44184db3368bdcaa7a"] bnn1ae3b6