Skip to content

Instantly share code, notes, and snippets.

View justinbowes's full-sized avatar
💭
I may be slow to respond.

Justin Bowes justinbowes

💭
I may be slow to respond.
View GitHub Profile
@justinbowes
justinbowes / gist:2889905
Created June 7, 2012 16:32
chevyray's post translated from incomprehensible font
private function pushOutUnits(elastic:Number):void
{
for (var i:int = 0; i < units.length - 1; i++)
{
for (var j:int = i + 1; j < units.length; j++)
{
push.x = units[i].x - units[j].x;
push.y = units[i].y - units[j].y;
var d:number = push.length;
// Implements an LCG RNG.
var Random = function Random(seed) {
this.term = (typeof seed !== 'undefined' ? seed : new Date().getTime());
this.multiplier = 60969; // carefully chosen
this.modulus = Math.pow(2, 32);
this.increment = 1;
};
Random.prototype.randInt = function(range) {
this.term = (this.term * this.multiplier + this.increment) % this.modulus;
@justinbowes
justinbowes / gist:3297745
Created August 8, 2012 19:11
JavaScript binary heap with merge support
var BinaryHeap = function BinaryHeap(scoreFunction, populate){
this.content = (populate ? populate.slice(0) : []);
this.scoreFunction = scoreFunction;
if (this.content.length) {
this.build();
}
}
BinaryHeap.prototype = {
@justinbowes
justinbowes / Game.cpp
Last active December 16, 2015 20:19
Making pighead10's SFML Ludum Dare entry, "You are the Minimalist", run in OSX.
// Call to implicitly-deleted copy constructor
Game.cpp:16 --------------------
-sf::RenderTexture Game::gameOutput = sf::RenderTexture();
+sf::RenderTexture Game::gameOutput;
@justinbowes
justinbowes / entity_system
Last active December 21, 2015 05:09
A complete entity system implemented in C. See entity_system.
C entity system. Justin Bowes, Informi Software Inc. Public domain. Go nuts.
The only external dependency is the wonderful UThash by Troy D. Hanson,
which I overuse.
http://troydhanson.github.io/uthash/
The system is intended to be used primarily through the macros. You
supply the component type you expect; the code hashes the type (as
a string) and casts the result (as pointer to the type you passed).
@justinbowes
justinbowes / compile_time_hash.h
Last active January 2, 2019 13:02
Hash strings at compile time.
#ifndef compile_time_hash_h
#define compile_time_hash_h
// Posted by jbowes. Public domain.
// source: (dead link)
// http://lol.zoy.org/blog/2011/12/20/cpp-constant-string-hash
//
// At higher compiler optimization levels (-O1 and higher on clang/llvm),
// C_HASH("string") should be replaced by a hash of "string" at compile time.
@justinbowes
justinbowes / udpnet.c
Last active December 21, 2015 05:39
Hacked-up version of Madgarden's udpnet that will build on Windows+MinGW32. Used successfully on Windows 7, OS X 10.8, iOS 6. win_inet_pton.c is required for Windows only and should not be compiled on other platforms.
#include <sys/unistd.h>
#include <sys/fcntl.h>
#include "net/udpnet.h"
#ifdef SOCK_WIN32
#include <ws2tcpip.h>
#include <ctype.h>
typedef int socklen_t;
@justinbowes
justinbowes / TemplateInfo.plist
Created April 28, 2014 20:03
UUID Guarded Header File.xctemplate
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AllowedTypes</key>
<array>
<string>public.c-header</string>
<string>public.c-plus-plus-header</string>
</array>
<key>BuildableType</key>
@justinbowes
justinbowes / markov.c
Last active August 29, 2015 14:02
Markov chain random name generator. Takes a string of one name per line and generates new names. Has some dependencies on the rest of XPL, but it should be pretty straightforward to fix most of them (tips in the comments).
// xpl/res/markov.c. ©2014 Informi Software Inc. Use and modify this file for any purpose without attribution.
#include <ut/uthash.h> // get from https://github.com/troydhanson/uthash
#include <xpl/mem/memory.h> // you can use calloc(sizeof(type), 1) instead of xpl_calloc_type(type),
// strdup instead of xpl_strdup, free instead of xpl_free, etc.
#include "markov.h"
typedef struct link_entry {
@justinbowes
justinbowes / blackbody_srgb.c
Created June 18, 2014 18:13
Blackbody to SRGB code based on piecewise blackbody curve reconstruction. Depends on XPL, but you can easily replace its vector-construction calls in blackbody_rgbi and blackbody_rgb with your own.
// science/blackbody_srgb.c. ©2014 Informi Software Inc. Use and modify this file for any purpose without attribution.
#include "science/blackbody_srgb.h"
#ifndef XPL_STATIC_INLINE
# define XPL_STATIC_INLINE static inline
#endif
XPL_STATIC_INLINE float r_0_6700(float k) {
return 1.0f;