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 / ReplaySource.js
Last active September 12, 2016 04:36
A simple `replay` operator for most.js. Specialises `multicast` so that new sinks are replayed the history of events from the source, including termination events. If a termination event exists, the sink is not cached for future events. After a termination, future sinks will not trigger a fresh `run` operation on the source.
const MulticastSource = require('most/lib/source/MulticastSource');
const PropagateTask = require('most/lib/scheduler/PropagateTask');
const CompoundDisposable = require('most/lib/disposable/CompoundDisposable');
module.exports = ReplaySource;
function ReplaySource(source) {
this._buffer = [];
this._ended = false;
MulticastSource.call(this, source);
@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 / scope.js
Last active May 6, 2024 05:20
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 / router.js
Last active May 6, 2024 05:17
Simple router driver for Cycle.js utilising Router5 for routing functionality and adapting some of the code from VisionMedia's Page.js for automatic link click intercepting
'use strict';
import {Router5, RouteNode} from 'router5';
import logger from '../logger';
// The set of valid sink functions includes synchronous state-affecting router functions that do not require a callback
// and which do not have a significant return value other than the router object itself.
const validSinkFuncs = ['add','addNode','canActivate','deregisterComponent','navigate','registerComponent','setOption','start','stop'];
function validateAndRemapSinkArgument(arg) {
@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 / example.js
Last active October 4, 2016 04:01
Logging driver for cycle.js
import {Rx} from '@cycle/core';
export default function (responses, strings) {
var log = responses.log.create('Sample');
var str$ = Rx.Observable
.from(strings)
.do(str => {
log.trace('Just tracing stuff');
log.debug('Here is a debug message');
log.success('The successful thing happened that we wanted to happen');
@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 / 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 / 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 / cubeapp.cs
Created October 16, 2014 08:07
Rendering an animated texture
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;