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 / hello-world-sharpdx-1.cs
Last active December 25, 2015 04:29
Game Dev Samples
namespace SharpDx1
{
class HelloWorld
{
[STAThread]
public static void Main()
{
var app = new HelloWorld();
app.Run();
}
@axefrog
axefrog / hello-world-sharpdx-2.cs
Last active December 25, 2015 04:39
Game Dev Samples
using System;
using SharpDX;
using SharpDX.Direct2D1;
using SharpDX.Direct3D10;
using SharpDX.DirectWrite;
using SharpDX.DXGI;
using SharpDX.Windows;
using AlphaMode = SharpDX.Direct2D1.AlphaMode;
using Device1 = SharpDX.Direct3D10.Device1;
@axefrog
axefrog / game.cs
Created October 22, 2013 16:58
Not quite sure why resizing the window causes the polygon edges to become a bit jagged.
using System;
using System.Windows.Forms;
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Windows;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
@axefrog
axefrog / App.cs
Last active December 26, 2015 06:29
My cube won't render :(
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SharpDX.Windows;
using SharpDx3.Direct3D;
namespace SharpDx3
{
@axefrog
axefrog / example-test.js
Last active February 29, 2016 14:05
Utilities for easily running tests against streams of arrays of arrays of streams of streams of... you get the idea. (most.js + mocha + chai)
it('projectStaticsToArrayOfPairStreams() should return an array of streams of key/state objects', () => {
const statics = internals.projectStaticsToArrayOfPairStreams(partitioned.statics);
return deepCapture(statics)
.then(result => {
const expected = [
$([{ key: 'a', state: { x: 1, y: 2 } }, { key: 'a', state: { x: 3, y: 4 } }]),
$([{ key: 'b', state: { x: 5, y: 6 } }, { key: 'b', state: { x: 7, y: 8 } }]),
$([{ key: 'c', state: { } }])
];
assert.deepEqual(expected, result);
@axefrog
axefrog / contextDriver.js
Last active April 1, 2016 01:59
Experiment: Context driver providing a way to recognise the inherit coupling of state with a view, its metadata and children. A context object is built and extended by each nested component as it is emitted to its parent.
export function makeContextDriver(domDriver) {
return function(context$) {
const ctx$ = context$.multicast();
const vtree$ = ctx$.filter(c => c.vtree).map(c => c.vtree);
const state$ = ctx$.filter(c => c.state).map(c => c.state);
const metadata$ = ctx$.filter(c => c.metadata).map(c => c.metadata);
return {
DOM: domDriver(vtree$),
state$,
@axefrog
axefrog / #upgradeSources.js
Last active April 1, 2016 01:59
An idea I was playing around with for improving the way sources are passed around in Cycle.js. I since discarded the approach after the discussion at https://github.com/cyclejs/core/issues/284
export function upgradeSources(sources) {
const sourceKeys = Array.from(Object.keys(sources));
const cleanSources = sources => sourceKeys
.reduce((acc, key) => (acc[key] = sources[key], acc), {});
function withCustom(baseSources, customSources) {
const cleanedSources = cleanSources(baseSources);
const nextSources = Object.assign({}, cleanedSources, customSources);
return augment(nextSources, cleanedSources);
@axefrog
axefrog / an-imperative-approach.js
Last active April 1, 2016 02:04
An experiment in functional programming for validating and normalizing a variably-structured options argument
function sanitizeOptions(options) {
if(!options) {
options = {}
}
else if(typeof options === `string`) {
options = { scope: options }
}
else if(Array.isArray(options)) {
options = { include: options }
}
@axefrog
axefrog / conventions.md
Last active April 6, 2016 23:58
A WIP document I'm putting together for Epicycle, my boilerplate framework for building isomorphic web applications using Motorcycle and Most.js.

Conventions, Naming & Best Practices

Though you don't have to follow these conventions, you'll get off to a quicker start if you do, and your code will be more consistent and thus easier to maintain. Many of these conventions are largely an attempt to reuse common ideas and best practices that have been discovered by the Cycle community, and to provide additional abstractions to cover the specialised concerns of an isomorphic web application, and to promote the DRY principle.

Streams

Variables representing streams should be suffixed with $, for example data$. The variable name chosen, or a suffix thereof, should be a suitable name to represent the data emitted. For example, data$ should emit data. Similarly, userAuthData$ is fine for emitting any of userAuthData, authData, or just data. Example: authData$.map(data => ...) or authData$.map(authData => ...)

var frog$ = most.of({ name: 'Hopper' })
@axefrog
axefrog / intercept.js
Last active May 6, 2016 04:49
A very quick-and-dirty proxy interceptor for introspection of an object's behaviour. Assumes chalk is installed.
import chalk from 'chalk';
function str(val) {
return val ? val.toString().replace(/\s+/g, ' ') : val;
}
let i = 0;
export function intercept(obj, title) {
return new Proxy(obj, {
get(target, name) {