Skip to content

Instantly share code, notes, and snippets.

View jackmott's full-sized avatar

Jack Mott jackmott

  • Looking for employment
  • Texas,USA
View GitHub Profile
@jackmott
jackmott / programmingadvice.md
Last active May 1, 2017 21:15
On one liner programming adivce

In general I have a problem with the whole set of short form, appeal to authority programmer advice things, of which there are many common examples:

  • premature optimization is the root of all evil
  • functional programming is easier to reason about
  • it is easier to make a correct program fast than a fast program correct
  • etc

One problem with these is that they are often stated as global truths, but are usually only true in specific cases. For each of these rules you must know when to break it. For instance the lead engine devs at ID Software say the exact opposite of the first quote - "Premature optimization is the root of all good". More important many of these things we just don't know to be true, we just think they are. And while I may

proc nameScore(name : string) : int =
for c in name:
result += int(c)-64
var names = "names.txt".readFile().replace("\"").split(',')
names.sort(system.cmp)
var sum =0
for i,name in names:
sum += nameScore(name)*(i+1)
@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);