Skip to content

Instantly share code, notes, and snippets.

View nilium's full-sized avatar
🍉
internal screaming intensifies

Noel nilium

🍉
internal screaming intensifies
View GitHub Profile
@nilium
nilium / bitset.go
Created March 5, 2014 02:04
Quick bitset written in Go. No use for it yet, so in a gist it goes.
package main
import "log"
import "fmt"
import "bytes"
type BitSet struct {
bits []uint64
length uint64
}
@nilium
nilium / anon.rb
Created March 8, 2014 11:54
Horrible hack to enable _s as placeholders in Ruby, similar to Scala.
# A horrible hack to enable _ as placeholders in Ruby, similar to block behavior
# in Scala.
#
# Obviously breaks if used across multiple threads, though probably in subtle
# ways. The break can be mitigated by instead wrapping the arguments in an
# instance of something and then doing instance_exec, where _ is a method on
# the instance, but this messes up the block's binding.
#
# There's probably a way around it all, but it's honestly not worth the trouble
# and the typing saved isn't worth the utter confusion anything like this would
@nilium
nilium / NSObject+QTestCase.h
Last active August 29, 2015 13:57
Switch-case-like test category for NSObject. Uses blocks. Probably not the fastest thing you could do, but handy nonetheless.
#ifndef NSObject_QTestObject_h_58095849_FEC4_4085_8A11_C6B2C7A2EBFB
#define NSObject_QTestObject_h_58095849_FEC4_4085_8A11_C6B2C7A2EBFB
#import <Foundation/Foundation.h>
extern id const QBlockTest;
typedef id (^QTestCase)();
@interface NSObject (QTestObject)
@nilium
nilium / md3.rb
Created March 11, 2014 22:26
Quickly thrown-together script for converting MD3 files to OBJ files. Each frame gets its own file. This script is very slow.
#!/usr/bin/env ruby -WKu
require 'stringio'
module MD3View
def run_view(*) ; raise NotImplementedError ; end
end
begin
require("#{File.dirname $0}/md3view.rb")
type signalFunc func()
type waitFunc func()
// signalWaitFuncs returns a signalFunc and a waitFunc. Calling the returned
// waitFunc blocks until the signalFunc is called.
func signalWaitFuncs() (signalFunc, waitFunc) {
port := make(chan bool)
return func() { port <- true }, func() { <-port }
}
@nilium
nilium / build-gsc-docset
Last active August 29, 2015 13:59
Ruby script to build a Dash docset for Gambit-C (http://gambitscheme.org)
#!/usr/bin/env ruby
require 'fileutils'
require 'sqlite3'
require 'cgi'
HELP_TEXT = <<-EOS
build-gsc-docset [options...]
@nilium
nilium / utf8_bits.hh
Created April 15, 2014 23:15
UTF8 bits stuff.. not entirely sure what the point of this was.
template <int OCTETS_>
struct utf8_bits_t
{
enum : int
{
OCTETS = OCTETS_,
OFFSET = 6 * (OCTETS - 1),
};
enum : uint32_t
@nilium
nilium / bitalloc.c
Created May 6, 2014 20:57
Quick example of using a bitset to determine free indices in something (e.g., a cache of reusable objects, maybe a memory pool, etc.)
#include <stdint.h>
#include <stdio.h>
#define OBJ_UNUSED_BITS_MAX 8
static uint32_t obj_unused_bits[OBJ_UNUSED_BITS_MAX] = { 0 };
int obj_first_unused()
{
// Based off the code at Sean Eron Anderson's bit twiddling hacks page, in
/* Subset of config.hh */
#ifndef __SNOW_COMMON__CONFIG_HH__
#define __SNOW_COMMON__CONFIG_HH__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wundef"
#if defined(__APPLE__)
# include <TargetConditionals.h>
#endif
@nilium
nilium / vm_rwlock.cpp
Last active August 29, 2015 14:02
Temporary storage for a pthread rwlock wrapper class.
/*
Copyright (c) 2014 Noel Raymond Cower.
This file is part of Rusalka VM.
Rusalka VM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.