Skip to content

Instantly share code, notes, and snippets.

View jaz303's full-sized avatar

Jason Frame jaz303

  • Glasgow, Scotland, UK
  • 23:06 (UTC +01:00)
View GitHub Profile
@jaz303
jaz303 / gist:f2dc513f5c20353a2888
Created December 15, 2014 13:55
Interruptible VM with signal handlers
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
typedef enum opcode {
OP_HALT = 0,
OP_NOP,
OP_JMP,
OP_MAX
} opcode_t;
@jaz303
jaz303 / gist:b0e73bc2effe71283b5c
Last active August 29, 2015 14:11
Weird NSImage double-sizing "bug"...

capture is a CGImageRef returned from a call to CGWindowListCreateImage(). When I try to turn it into an NSImage directly it mysteriously doubles in size. If I manually create a an NSBitmapImageRep from capture and then add it to an empty NSImage everything works ok.

My hardware setup is a retina MBP + non-retina external display. The capture is taking place on the non-retina screen.

NSLog(@"capture image size: %d %d", CGImageGetWidth(capture), CGImageGetHeight(capture));
NSLog(@"logical image size: %f %f", viewRect.size.width, viewRect.size.height);

NSBitmapImageRep *debugRep;
NSImage *image;

Scoping in a beginner's language:

a := 10
def foo {
    a := 20
}

foo()
print a -- should this output 10 or 20?

I have a task system that is controlled by a kernel. This is a simplified version of the spawn logic:

var task = new taskCtor();
taskState.state = INIT; // taskState is private to kernel
task.init();
taskState.state = RUNNING;
task.run();
taskSpawned.emit(task.id); // this is a signal that notifies system a task has been spawned
return task.id;

I'm designing a programming language for beginners/kids and am trying to keep the syntax for basic usage as simple as possible, while still providing useful features for more advanced users such as first-class functions and lambda expressions.

In particular I'm keen that it should be possible to call functions without parentheses:

print "hello world"
@jaz303
jaz303 / gist:d56ee88acf652ca79bf7
Last active August 29, 2015 14:06
Go-style channels in Javascript with promises/generators
//
// Lame implementation of a channel
function channel() {
return new Channel();
}
function Channel() {
this._queue = [];
this._waiters = [];
function makeProgressPromise(cb) {
var currentProgress = 0;
var progressListeners = [];
function updateProgress(newProgress) {
currentProgress = newProgress;
progressListeners.forEach(function(listener) {
try {
listener(currentProgress);
### Keybase proof
I hereby claim:
* I am jaz303 on github.
* I am jf (https://keybase.io/jf) on keybase.
* I have a public key whose fingerprint is 5AD4 A818 DC4B E0B6 34D7 50D4 5658 3F16 9A3F 74EC
To claim this, I am signing this object:
@jaz303
jaz303 / ansible-bootstrap
Last active March 28, 2022 00:27
Shell script to prepare a fresh machine for management with Ansible
#!/bin/bash
# usage: boostrap mybox.example.com path/to/id_rsa.pub
# preconditions: fresh install of Debian with ssh installed/running
# effects:
# - hostname is set
# - `ansible` user created with disabled password and added to sudo/ssh groups
# - specified public key added to user's authorized_keys
# - sudoers updated to allow no password operations
@jaz303
jaz303 / Makefile
Last active October 20, 2016 15:19
Makefile for browserify workflow
MODULE = # insert module name here
EXPORT = $(MODULE)
BUILD_DIR = build
BUNDLE = $(BUILD_DIR)/$(MODULE).js
DEMO_BUNDLE = demo/bundle.js
DEMO_ENTRY = demo/main.js
ENTRY = index.js
SRC = $(ENTRY)