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 / wordwrap.cs
Last active November 11, 2018 20:44
word wrap for monogame
public static string Wrap(string s, int width, Func<string, int> widthMeasure)
{
StringBuilder builder = new StringBuilder(s.Length);
var text = s.AsSpan();
int start = 0;
int len = 0;
for (int i = 0; i < text.Length; i++) {
if (text[i] == ' ')
{
@jackmott
jackmott / pqeueu.cs
Created September 29, 2018 00:14
pqueue
using System.Collections.Generic;
using System.Linq;
namespace FB
{
public class PQueue<T>
{
private SortedDictionary<float, Stack<T>> sdict;
@jackmott
jackmott / simd_test.rs
Last active August 6, 2018 17:37
compiler bug?
// SSE returns the correct answer in Debug and Release
// AVX returns the correct answer in Debug but not Release
// This seems to be related to add_stuff being recursive
#[cfg(target_arch = "x86")]
use std::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::*;
use std::fmt::Debug;
@jackmott
jackmott / foreach.cs
Created July 27, 2018 01:53
for vs foreach
using System;
using System.Diagnostics;
namespace ConsoleApp11
{
class Program
{
static long count_for(int[] a1, int[] a2)
{
long count = 0;
@jackmott
jackmott / benchmark.rs
Created July 1, 2018 18:50
faster benchmark
#[macro_use]
extern crate criterion;
extern crate faster;
extern crate simdeez;
use criterion::Criterion;
use criterion::Fun;
use faster::*;
use simdeez::*;
use simdeez::sse2::*;
@jackmott
jackmott / json.fs
Created June 19, 2018 12:59
customizing newtonsoft
namespace AlphaFront
module JsonCustomConverters =
open Newtonsoft.Json
open Microsoft.FSharp.Reflection
open System
open System.IO
type DuConverter() =
inherit JsonConverter()
@jackmott
jackmott / rustvc.c
Last active June 13, 2018 13:19
rust vs c
// An example of how tuples and treating if statements as expressions makes things nicer
// C version, a snippet from simlpex noise.
int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if (x0 >= y0) {
if (y0 >= z0) {
i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0;
}
@jackmott
jackmott / ast.rs
Created May 17, 2018 21:22
how to ast in rust
//represents an AST - such as Plus(Sin(x),y)
pub enum Op {
Plus ( Vec<Op> ),
Sin ( Vec<Op> ),
X,
Y,
Constant (f32),
Empty
}
@jackmott
jackmott / verts.go
Created April 17, 2018 23:50
vertices for opengl cube
vertices := []float32{
-0.5, -0.5, -0.5, 0.0, 0.0,
0.5, -0.5, -0.5, 1.0, 0.0,
0.5, 0.5, -0.5, 1.0, 1.0,
0.5, 0.5, -0.5, 1.0, 1.0,
-0.5, 0.5, -0.5, 0.0, 1.0,
-0.5, -0.5, -0.5, 0.0, 0.0,
-0.5, -0.5, 0.5, 0.0, 0.0,
0.5, -0.5, 0.5, 1.0, 0.0,
@jackmott
jackmott / img2tex.go
Created April 13, 2018 00:33
Golang img to sdl texture
func imgFileToTexture(renderer *sdl.Renderer, filename string) *sdl.Texture {
infile, err := os.Open(filename)
if err != nil {
panic(err)
}
defer infile.Close()
img, err := png.Decode(infile)
if err != nil {