Skip to content

Instantly share code, notes, and snippets.

View axefrog's full-sized avatar

Nathan Ridley axefrog

  • Brisbane, Australia
View GitHub Profile
@axefrog
axefrog / build.ps1
Last active August 29, 2015 14:14
A simple MSVC++ build script for my game development. Supports an arbitrary source folder structure and command arguments for running the built file and optionally starting the debugger.
$postbuild = ""
foreach ($arg in $args) {
switch ($arg) {
"run" { $postbuild = "run" }
"debug" { $postbuild = "debug" }
}
}
if (!(test-path build)) { mkdir build }
if (!(test-path build/obj)) { mkdir build/obj }
@axefrog
axefrog / font-atlas-plan.cpp
Created February 22, 2015 01:16
Planning out a font atlas
std::shared_ptr<FontAtlas> generateFontAtlas(int fontId, int fontSizeInPixels, int sdfPadding)
{
/* ACTION PLAN:
create a new list (vector) in which to stage a set of character glyphs, each prepared in isolation
for each character:
load the character and its metrics from the font engine, using a very large font size (10 times the requested font size)
create a new image expanded to include padding for the distance field
copy the character bitmap into the centre of the image
render the distance field into the image
downsize the image
@axefrog
axefrog / linked-data.html
Created April 13, 2015 23:57
Aurelia self-referencing view causing stack overflow error
<template>
<require from="./linked-data"></require>
<table>
<tbody>
<tr repeat.for="pair of pairs()">
<td>${pair.predicate}</td>
<td>
<linked-data subject.bind="this" predicate.bind="pair.predicate" value.bind="pair.value"></linked-data>
</td>
</tr>
@axefrog
axefrog / scope.js
Last active August 31, 2015 19:14
An idea for scoping Cycle.js child components/dialogues in the context of their parent. Any driver can optionally supply a scope() function, which returns a scoped instance of itself. A driver can also supply an unscope() function which returns a transformed instance of its associated sink. Anything that is scope-unaware is preserved.
function runInScope(main, sources, context, ...args) {
if(!main) {
throw new Error('A "main" function must be supplied, which will be called in scope and from which a (sinks) object will be returned');
}
if(!sources) {
throw new Error('A source drivers object must be supplied, to which scoping can be applied');
}
if(!context) {
throw new Error('A scope context object must be supplied, either as a string, or as an object of key/value pairs');
}
@axefrog
axefrog / example.js
Last active September 8, 2015 14:14
Simple logger for my Cycle.js apps. Writes pretty console output and exposes an observable message stream if further processing is desired.
import logger from './logger';
let log = logger('Category');
log.trace('Just tracing stuff');
log.debug('Here is a debug message');
log.success('The successful thing happened that we wanted to happen');
log.info('Information makes the world go around, and here is that string:', str);
log('An info message can be logged using short form');
log.warn('You better be careful about this kind of thing');
@axefrog
axefrog / make.ps1
Created October 15, 2015 13:24
Power Shell make script I wrote for my game project; can be easily adapted for other projects too. Note: BUILDING_DLL #define is used for DLLs, for use with __declspec import/export switching. I've included an example header file that illustrates this.
# ----------------------------------------------------------------------------------------------------------------------------
# Generic VC++ Make Script
# ----------------------------------------------------------------------------------------------------------------------------
# Note: Make sure that vcvars.bat has been run in the current powershell session
#
# Power Shell Reference: http://ss64.com/ps/
# VC++ Compiler Options: https://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
# VC++ Linker Options: https://msdn.microsoft.com/en-us/library/y0zzbyt4.aspx
# Plugin handling library: http://apolukhin.github.io/Boost.DLL/
# ----------------------------------------------------------------------------------------------------------------------------
@axefrog
axefrog / sample.html
Last active December 14, 2015 05:40
jQuery plugin that allows any sequence of block elements to become sortable by dragging. Inserts a drag handle element into each item if one is not provided.
<!doctype html>
<html>
<head>
<title>Sortable List</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="sortable-list.js"></script>
<script>
$(function() { $('#rows').sortablelist(); });
</script>
<style type="text/css">
@axefrog
axefrog / ioc.ts
Last active December 20, 2015 03:09
MyIOC - A simple, lightweight IOC container for TypeScript (and therefore JavaScript) that does everything I need and nothing I don't.
/*
MyIOC - IOC Container for TypeScript/JavaScript
designed and developed by Nathan Ridley
------------------------------------------------------------------
Copyright (c) 2013 Nathan Ridley (axefrog@gmail.com).
All rights reserved.
Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
@axefrog
axefrog / computeArrayUpdateOperations.js
Last active December 20, 2015 22:09
A JavaScript algorithm I came up with to calculate the operations to be applied to an array L to make it the same as a new array R when it is undesirable to simply replace L with R. Typically this is when doing so is a costly operation (such as when the elements represent the items of a DOM collection) and/or each component of the update require…
// both arrays should be presorted
function computeArrayUpdateOperations(oldarr, newarr, compare) {
if (!compare)
compare = computeArrayUpdateOperations.compare;
var l = 0, r = 0, p = 0,
op = null, ops = [],
leof = l >= oldarr.length, reof = r >= newarr.length;
while (!(leof && reof)) {
if (!leof && (reof || compare(oldarr[l], newarr[r]) < 0)) {
if (op && op[0] === 'i')
@axefrog
axefrog / test.js
Last active December 24, 2015 04:39
<!-- snip -->
<script type="text/x-handlebars" data-template-name="data_sources">
<h3>Data Source List</h3>
<section id="data-source-list">
{{#each}}
<div id="data-source-list-item-{{id}}" class="data-source">
<h4>{{name}}</h4>
enabled: {{enabled}}
</div>
{{/each}}