Skip to content

Instantly share code, notes, and snippets.

View pascaldekloe's full-sized avatar

Pascal S. de Kloe pascaldekloe

View GitHub Profile
@pascaldekloe
pascaldekloe / Colfer.js
Last active April 2, 2017 22:25
Demo JavaScript Compilation
// Code generated by colf(1); DO NOT EDIT.
// The compiler used schema file demo.colf for package demo.
// Package demo offers a demonstration.
// These comment lines will end up in the generated code.
var demo = new function() {
const EOF = 'colfer: EOF';
// The upper limit for serial byte sizes.
var colferSizeMax = 16 * 1024 * 1024;
@pascaldekloe
pascaldekloe / Colfer.go
Created April 2, 2017 22:20
Demo Go Compilation
// Package demo offers a demonstration.
// These comment lines will end up in the generated code.
package demo
// Code generated by colf(1); DO NOT EDIT.
// The compiler used schema file demo.colf.
import (
"encoding/binary"
"fmt"
@pascaldekloe
pascaldekloe / Colfer.c
Last active April 2, 2017 22:19
Demo C Compilation
// Code generated by colf(1); DO NOT EDIT.
// The compiler used schema file demo.colf for package demo.
#include "Colfer.h"
#include <errno.h>
#include <stdlib.h>
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \
defined(__BIG_ENDIAN__) || \
@pascaldekloe
pascaldekloe / stream.go
Created January 4, 2017 19:20
Streaming Colfer records example
func writeAll(w io.Writer, records []*batch.Record) error {
var buf []byte
for _, r := range records {
n, err := r.MarshalLen()
if err != nil {
return err
}
if n > len(buf) {
buf = make([]byte, n*2)
@pascaldekloe
pascaldekloe / utf8.js
Last active September 9, 2023 05:21
JavaScript UTF-8 encoding and decoding with TypedArray
// This is free and unencumbered software released into the public domain.
// Marshals a string to an Uint8Array.
function encodeUTF8(s) {
var i = 0, bytes = new Uint8Array(s.length * 4);
for (var ci = 0; ci != s.length; ci++) {
var c = s.charCodeAt(ci);
if (c < 128) {
bytes[i++] = c;
continue;