Skip to content

Instantly share code, notes, and snippets.

View jackmott's full-sized avatar

Jack Mott jackmott

  • Olo
  • Texas,USA
View GitHub Profile
@jackmott
jackmott / numberphile.txt
Created April 21, 2017 14:38
Equations that almost evaluate to 10958
(1 + (2 + (3^((4 / 5) + (6 + ((7 + 8) / 9))))))
(1 * ((((2^3) + 4) / 5)^(((6 + 7) / 8) + 9)))
((1 + (((2^3) * 4) * (5 | 6))) * (7 - (8 / 9)))
((1 + 2) + (3^((4 / 5) + (6 + ((7 + 8) / 9)))))
(((1^2) - 3) + ((4^(5 - ((6 - 7) / 8))) * 9))
((1 / (2^((3^(4 / (5 + 6))) * (7 - 8))))^9)
((1^2) + ((3 / 4)^(5 - ((6 * (7 * 8)) / 9))))
((1^2)+((3/4)^(5 - ((6*7)*(8/9)))))
(((1^2)*((3*4)/5))^(((6+7)/8)+9))
@jackmott
jackmott / codingame.rs
Last active April 13, 2017 02:34
learning rust
#[derive(Clone,PartialEq,Eq)]
24 enum Tile {
25 MeasuredWater,
26 Water,
27 Land,
28 Finalized(usize),
29 }
30
31
32 fn get_area(map: &mut Vec<Vec<Tile>>, startx: usize, starty: usize) -> usize {
@jackmott
jackmott / maptest2.fs
Created April 4, 2017 21:16
maptest2.fs
open System.Collections.Concurrent
open System.Threading.Tasks
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Running
open BenchmarkDotNet.Jobs
open System
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
@jackmott
jackmott / map.fs
Created April 3, 2017 22:52
map benchmark
open System.Collections.Concurrent
open System.Threading.Tasks
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Running
open BenchmarkDotNet.Jobs
open System
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
@jackmott
jackmott / simdandjits.txt
Last active March 28, 2017 16:19
SIMD and jits
With no JIT that I am aware of (not jvm, not ryujit, not v8) can you make say, _mm256_sll_epi32 happen, at all.
With C++ I can call that with an intrinsic: `_mm_and_ps(x,y);` Now is it a pain, because to hit the various SIMD targets, I have
to write the SSE2 and AVX512 equivalents and detect which to use at runtime? Yes, it is a pain, though libraries like bSIMD exist
to remove that pain.
Also, no JIT that I am aware of can autovectorize something simple like a for loop adding up floats. The JVM doesn't do it, .NET doesn't
auto vectorize any user code ever. There isn't time to figure those out at runtime.
GCC, MSVCC, and LLVM, and Intel AOT compilers can all auto-vectorize simple cases like that, and Intel can sometimes do rather
amazing autovectorization.
@jackmott
jackmott / testmap.js
Last active March 28, 2017 15:08
javascript map vs imperative testing
<script>
//All tests run repeatedly until numbers stabilize (jit warmup)
//Node 7.7.4 NODE_ENV = production - 42ms
//Firefox 52.0.1 32bit 250 to 280ms
//Firefox 52.0.1 64bit 210 to 250 ms
//Chrome 57.0.2987.110 (64-bit) 45ms
function testImperative(values)
{
@jackmott
jackmott / fastforeach.cs
Created March 26, 2017 03:18
fast foreach
public static void ForEach<T>(this T[] array, Action<T> lambda)
{
foreach (var x in array)
{
lambda.Invoke(x);
}
}
//use like
@jackmott
jackmott / sprites.cs
Created March 24, 2017 19:23
composing sprite sheets with monogame
// Compose a bunch of sprite sheets to make a uniqe npc as they
// come on screen. The sheets contain all the animation frames.
Texture2D shirtSheet = content.Load<Texture2D>(RandUtil.Index(shirtPaths));
Texture2D pantSheet = content.Load<Texture2D>(RandUtil.Index(pantsPaths));
Texture2D shoeSheet = content.Load<Texture2D>(RandUtil.Index(shoePaths));
var renderTarget = new RenderTarget2D(PRPGame.graphics,baseSheet.Width,baseSheet.Height,false,SurfaceFormat.Color,DepthFormat.None,0,RenderTargetUsage.DiscardContents);
PRPGame.graphics.SetRenderTarget(renderTarget);
PRPGame.graphics.Clear(Color.Transparent);
@jackmott
jackmott / minby.cs
Last active March 24, 2017 02:32
Handy way to do minby / maxby extension methods in C# 7
public static (T obj, float value) MinBy<T>(this T[] array,Func<T,float> lambda)
{
float minValue = float.MaxValue;
T minT = default(T);
//note if you implement this for List<T>, don't use foreach, it is slower. Use a for loop.
foreach (var t in array)
{
var value = lambda.Invoke(t);
if (value < minValue)
{
@jackmott
jackmott / example.cs
Created March 23, 2017 13:51
c# 7 pattern matching
switch (SomeClass)
{
case DerivedClassA a:
a.dostuff();
break;
case DerivedClassB b:
b.dostuff();
break;
}