Skip to content

Instantly share code, notes, and snippets.

View cdiggins's full-sized avatar
🐉
Eliminating Lines of Code

Christopher Diggins cdiggins

🐉
Eliminating Lines of Code
View GitHub Profile
@cdiggins
cdiggins / vector3-generated-example.cs
Created October 16, 2022 19:28
Example of Plato code, and generated backing C# code, for a Vector3 class.
/*
* This is a sample of the auto-generated code currently produced by Plato
* along with the code it was generated from.
* Plato and the generated code is compatible with .NET Standard 2.0 and C# 8.0
*/
using System;
namespace Plato2
{
/// <summary>
@cdiggins
cdiggins / inlining.cs
Created March 11, 2022 19:31
On the Importance of Inlining
[Test]
public static void Inlining()
{
var length = 1000;
// Our Two Lambdas
Func<int, bool> Lt5 = x => x < 5;
Func<int, int, int> AddInts = (x, y) => x + y;
// Original expression
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
public static class VimApi
{
/// <summary>
/// Represents a node in a VIM scene and provides access to useful information about the object associated with that node.

array.h

A C++11 header-only library of array containers, views, and iterators that provide a standard interface to different layouts of data in memory, as well as to computed data.

This is a single header file with no other dependencies (including STL) which means it is portable, fast to compile, and easy to include in different projects.

Unlike std::array the size of ara3d::array is specified in the constructor. It is rare in practice that array sizes are known at compile time. The ara3d::array_view is similar to stl::span but permits writing of data elements. If read-only semantics are desired then the ara3d::const_array_view structure can be used.

Design Rationale

#pragma once
/*
This is a C++14 wrapper around a number of STL algorithms that operate directly on an STL random access container, valarrays,
Boost range, or even a C style array. It also works of course on the various Ara 3D array classes.
The underlying container is only required to supply an implementation of standalone
begin/end functions or begin/end member functions.
The goal is to facilitate using the STL algorithms library by reducing the amount of boilerplate
/*
Ara 3d Array Operations Library
Copyright 2018, Ara 3D
Usage permitted under terms of MIT Licenese
This is a header-only library of generic algorithms that operate on random-access indexable containers such as
std::vector, std::array, and std::valarray from the STL, and raw C arrays.
It also works on ara3d::array, ara3d::func_array, and so forth.
This enhances algorithms found in the
STL library with algorithms designed specifically for arrays (like slicing, selecting, and striding).
/*
Ara 3d Array Library
Copyright 2018, Ara 3D, Inc.
Usage licensed under terms of MIT Licenese
*/
#pragma once
namespace ara3d
{
// Iterator for accessing of items at fixed byte offsets in memory
using System;
using System.Diagnostics;
using Vim.Logger;
namespace Vim.DotNetUtilities
{
/// <summary>
/// This interface is different from the IProgress&lt;T&gt; class in the system library
/// https://docs.microsoft.com/en-us/dotnet/api/system.iprogress-1?view=netframework-4.8
/// It was designed to simplify the use case of percentage reporting where the number of steps
@cdiggins
cdiggins / naive-binary-array-pack.cs
Created August 24, 2019 04:01
A simple algorithm for packing and unpacking binary byte arrays.
public static byte[] NaivePack(IList<byte[]> buffers)
{
using (var stream = new MemoryStream())
using (var bw = new BinaryWriter(stream))
{
bw.Write(buffers.Count);
foreach (var b in buffers)
{
bw.Write(b.Length);
bw.Write(b);
@cdiggins
cdiggins / myna_arithmetic_evaluator.js
Created July 23, 2018 18:40
An example Arithmetic evaluator in JavaScript written using the Myna parsing library:
"use strict";
function EvalArithmetic(exprNode)
{
switch (exprNode.rule.name)
{
case "expr":
{
return EvalArithmetic(exprNode.children[0]);
}