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 / 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;
}
@jackmott
jackmott / p2d.cpp
Created March 21, 2017 17:17
perlin2dsimd
#include "FastNoise.h"
inline int fastFloor(float x) {
int xi = (int)x;
return x < xi ? xi - 1 : xi;
}
__m128 onef = SetOne(1.0);
__m128i one = SetOnei(1);
@jackmott
jackmott / json.fs
Created March 16, 2017 11:26
makes json.net handle options and DUs the way one would expect
namespace AlphaFront
module JsonCustomConverters =
open Newtonsoft.Json
open Microsoft.FSharp.Reflection
open System
open System.IO
type DuConverter() =
inherit JsonConverter()
@jackmott
jackmott / ShaderManager.cs
Created March 13, 2017 19:21
Hot Swappable Shaders for MonoGame
/*
HotSwap shader sytem for MonoGame
HotSwap code only exists for debug builds
Edit paths to match your project
Construct in your Initialize method
Add shaders in LoadContent (or whenever)
Call CheckForChanges in Update() or periodically however you like
mgcb.exe usually located in C:\Program Files (x86)\MSBuild\MonoGame\v3.0\Tools
*/
@jackmott
jackmott / frogs.cpp
Last active March 7, 2017 22:04
Frog Jumping!
#include <stdio.h>
#include <string>
#include <iostream>
#include <chrono>
using namespace std;
typedef int lilly;
struct Move{
@jackmott
jackmott / files.fs
Created February 23, 2017 03:56
iterate over a file in F#
open System.IO
[<EntryPoint>]
let main argv =
//use gaurantees that the file handle is disposed when it goes out of scope
use s = new StreamReader ("c:\path\to\text.txt")
while not s.EndOfStream do
let s = s.ReadLine()
printfn "%s" s
@jackmott
jackmott / nonsense post.md
Last active January 11, 2017 14:59
nonsense climate scince blog post

Climate Models – the Strange Case of Missing Hardware September 9, 2016 By Leo Goldstein at Defeat Climate Alarmism

The General Circulation Models (GCM), alleged by IPCC to forecast climate, are computationally intensive computer programs that repetitively perform the same task: integrating specific sets of differential equations, such as the primitive equations of weather. In such situations, a normal practice is developing specialized hardware for performing that task. One example is video encoding hardware, which evolved from big boxes, making grainy and jumpy 640×480 moving pictures, to the tiny circuits inside of the CPUs of modern cell phone, producing smooth 1920×1080 full motion video.

Even more relevant example is development of specialized Bitcoin mining hardware. Bitcoin was invented in 2009. Initially, Bitcoin miners used conventional desktops, equipped with CPUs and GPUs. Within few years, multiple generations of Bitcoin-mining FPGAs and ASICs were developed and manufactured. In 2015, speciali

@jackmott
jackmott / response.md
Last active January 5, 2017 19:05
Climate response

Next we are told that science is impartial. Yet I just saw an article with an climatologist who is pretty well respected Science Academy William Happer and Duane Thresher and Judith Curry saying they had to play their cards close to their vests in regards to their doubts about the models to keep funding and not kill their career. That's not good science and it supports the distrust that many of us have that this may be political and not good science. It certainly makes a case that we aren't crazy for wondering if there is political bias. The article points out that much of the research they do must be funded by govt. Which means politics decides what is researched.

>I think the big difference we ha

@jackmott
jackmott / Imagine.md
Created December 31, 2016 16:23
Imagine

Imagine it from the experts point of view. They just traveled to the arctic to drill ice cores, to bring back for analysis to learn more about the climate. They have been built climate models they worked for years on, the code is published and available to the public, you aren 100 other experts have had a go at this and come up with roughly the same results, for decades. You hop on twitter and see someone who says "I think climate change is a liberal plot" or "I think climate science is bunk" and you reply with data. The response to your data is "but I read this blog with this other data that contradicts yours!" and you go and look at the blog. It was written by a guy who is paid by the heritage foundation (who is paid by exxon and so on) who has never been to the arctic to drill ice cores, who has never built a climate model, never done any actual work except take your data and crop it in a way to sell his message. You try to explain this but communicating your expertise takes days while skeptical memes ta