Skip to content

Instantly share code, notes, and snippets.

View ashleydavis's full-sized avatar

Ashley Davis ashleydavis

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
/// <summary>
/// A simple free camera to be added to a Unity game object.
///
/// Keys:
@ashleydavis
ashleydavis / event-source.ts
Created January 15, 2019 06:12
C# style events in JavaScript
// https://stackoverflow.com/a/15964759/25868
export type BasicEventHandler = () => void;
export type SenderEventHandler<SenderT> = (sender: SenderT) => void;
//
// Simulate C# style events in JS.
//
export interface IEventSource<HandlerType extends Function> {
//
@ashleydavis
ashleydavis / typescript-compiler.ts
Created April 30, 2020 08:36
An example of using the TypeScript compiler from TypeScript
import * as path from "path";
import { IDiagnostic } from "./language-code-generator";
import { readJsonFile } from "../common/file";
//
// Result of compiling TypeScript code.
//
export interface ICompilationResult {
code?: string;
diagnostics: IDiagnostic[];
@ashleydavis
ashleydavis / parsing log data.md
Last active November 6, 2019 10:48
An example of parsing log data for later transformation, analysis and visualization with Data-Forge

This markdown was exported from Data-Forge Notebook

Example of parsing log files so you have structured data to use with Data-Forge

First define some test data:

@ashleydavis
ashleydavis / Node.js require hook.js
Last active September 22, 2019 09:16
This snippet of code sets up a hook to intercept calls to require in Node.js. Put this code at the entry point of your app. It's a great debugging tool for Node.js and it even works under Electron!
//
// Original code here.
//
// https://stackoverflow.com/a/41674522/25868
//
const m = require('module');
const originalLoader = m._load;
m._load = function(request, parent, isMain) {
[
{
"ORDERNUMBER": 10107,
"QUANTITYORDERED": 30,
"PRICEEACH": 95.7,
"ORDERLINENUMBER": 2,
"SALES": 2871,
"ORDERDATE": "2/24/2003 0:00",
"STATUS": "Shipped",
"QTR_ID": 1,
@ashleydavis
ashleydavis / example-vega-lite-chart-with-second-series-on-the-right.vl.json
Created August 11, 2017 01:33
Example vega-lite chart with two time series and multiple layers - the second Y axis is moved to the right hand side of the chart.
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {
"url": "https://vega.github.io/vega-lite/data/seattle-weather.csv"
},
"layer": [
{
"mark": "line",
"encoding": {
"x": {
@ashleydavis
ashleydavis / example-vega-lite-chart-with-series-that-have-different-scales.vl.json
Last active March 22, 2019 14:12
An example vega lite chart with two series that have two different scales. This shows a problem that the scales aren't independent.
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"layer": [
{
"data": {
"url": "https://vega.github.io/vega-lite/data/seattle-weather.csv"
},
"mark": "line",
"encoding": {
"x": {
@ashleydavis
ashleydavis / example-vega-lite-chart-with-independent-y-axis.json
Created August 21, 2017 05:11
Example vega-lite chart with independent y axis'
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"layer": [
{
"data": {
"url": "https://vega.github.io/vega-lite/data/seattle-weather.csv"
},
"mark": "line",
"encoding": {
"x": {
@ashleydavis
ashleydavis / prototype.ts
Last active March 5, 2019 08:06
A prototype multi-core task processing API
/*
This a prototype / pseudo-code in TypeScript for a new multi-core task scheduler that I'm planning to open source.
This is based on my earlier private code that I've used to munge masses of stock market data and also talked about in my
book Data Wrangling with JavaScript.
To give me private feedback on this please email me on ashley@codecapers.com.au.
The basic premise of this is that we can split up a complex data processing job into mulitple 'tasks' each of
which can potentially run in parallel on a multi-core machine.