Skip to content

Instantly share code, notes, and snippets.

View toffaletti's full-sized avatar
👻

Jason Toffaletti toffaletti

👻
  • Apple, Inc.
  • San Francisco, CA
View GitHub Profile
@toffaletti
toffaletti / format.cc
Created September 21, 2012 09:34
basic C++11 string formatting
#include <sstream>
#include <iostream>
struct formatter {
std::string format;
formatter(const std::string &format_)
: format(format_) {}
formatter(const formatter &other) = delete;
formatter(formatter &&other)
@toffaletti
toffaletti / gist:4686420
Last active December 12, 2015 00:48
Low Level Language Thoughts
Finalizer Logic
struct Ptr {
void *value;
}
Finalize(Ptr ptr) {
free(ptr.value);
}
use std::vec;
use std::util::replace;
pub struct FlatMap<K, V> {
priv data: ~[(K, V)],
}
impl<K, V> FlatMap<K, V> {
fn new(capacity: uint) -> FlatMap<K, V> {
FlatMap{data: vec::with_capacity(capacity)}
use std::unstable::sync::UnsafeArc;
use std::unstable::atomics::{AtomicPtr,Relaxed,Release,Acquire};
use std::ptr::{mut_null, to_mut_unsafe_ptr};
use std::cast;
use std::task;
use std::comm;
use std::fmt;
struct Node<T> {
next: AtomicPtr<Node<T>>,
@toffaletti
toffaletti / sshd.go
Last active August 29, 2015 14:10 — forked from jpillora/sshd.go
// A simple SSH server providing bash sessions
//
// Server:
// cd my/new/dir/
// ssh-keygen -t rsa #generate server keypair
// go get -v .
// go run sshd.go
//
// Client:
// ssh foo@localhost -p 2022 #pass=bar
@toffaletti
toffaletti / future.go
Last active August 29, 2015 14:16 — forked from davecheney/future.go
package future
// A Future represents the result of some asynchronous computation.
// Future returns the result of the work as an error, or nil if the work
// was performed successfully.
// Implementers must observe these invariants
// 1. There may be multiple concurrent callers, or Future may be called many
// times in sequence, it must always return the same value.
// 2. Future blocks until the work has been performed.
type Future func() error
@toffaletti
toffaletti / flatbuffers.zig
Created July 19, 2021 23:59
Zig FlatBuffers read-only
///! This package provides a skeleton for read-only access to FlatBuffer encoded binary data.
const std = @import("std");
const assert = std.debug.assert;
const t = std.testing;
/// Header represents the data at offset 0
/// it consists of an unsigned offset to the root table
/// and optionally a 4-byte file identifier
const Header = packed struct {
offset: u32, // root table offset