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 / if.fs
Created February 12, 2018 01:43
if expression
x :=
if foo {
do_stuff() // returns an int
} else if bar {
a := do_stuff()
print("stuff"
3*a
} else {
5
}
@jackmott
jackmott / apt.go
Last active February 10, 2018 18:28
abstract picture tree
package apt
import (
"github.com/jackmott/noise"
"math"
"math/rand"
"strconv"
)
@jackmott
jackmott / simplex.go
Created January 21, 2018 19:47
simplex noise in go
/* This code ported to Go from Stefan Gustavson's C implementation, his comments follow:
* https://github.com/stegu/perlin-noise/blob/master/src/simplexnoise1234.c
* SimplexNoise1234, Simplex noise with true analytic
* derivative in 1D to 4D.
*
* Author: Stefan Gustavson, 2003-2005
* Contact: stefan.gustavson@liu.se
*
*
* This code was GPL licensed until February 2011.
@jackmott
jackmott / sdl2.go
Created January 15, 2018 15:05
Games With Go EP06 OSX fix
package main
// Experiment! draw some crazy stuff!
// Gist it next week and I'll show it off on stream
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
)
@jackmott
jackmott / draw.cs
Created December 22, 2017 18:33
monogame problem
public static void Draw(GameTime gameTime)
{
var effect = DDGame.contentManager.Load<Effect>("road");
effect.Parameters["TerrainTexture"].SetValue(MainState.level.tex);
effect.Parameters["MaskTexture"].SetValue(MainState.maskTex);
DDGame.batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, effect);
DDGame.batch.Draw(MainState.roadTex, new Rectangle(0, 0, Settings.WINDOW_WIDTH, Settings.WINDOW_HEIGHT), Color.White);
DDGame.batch.End();
}
@jackmott
jackmott / RotatedRectangle.cs
Created October 11, 2017 14:06
Rotated rectangle collision detection
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
//Faster linq-style convenience functions https://github.com/jackmott/LinqFaster
using JM.LinqFaster;
namespace DrawAndDrive
{
@jackmott
jackmott / slow.md
Created July 10, 2017 14:45
A List Of Modern Software That Is Annoyingly Slow

I will add to this during the day each time I encounter annoyingly slow software

  • Microsoft Visual Studio 2015 Shell Uninstall. ~1 hour on an I7 laptop with an SSD
@jackmott
jackmott / finishline.rs
Created June 10, 2017 11:54
checkerboard pattern sdl2 rust
let mut finish_line_tex = texture_creator
.create_texture_streaming(PixelFormatEnum::RGB24,
FINISH_LINE_LENGTH as u32,
FINISH_LINE_WIDTH as u32)
.unwrap();
finish_line_tex.set_blend_mode(BlendMode::Add);
finish_line_tex
.with_lock(None,
|buffer: &mut [u8], pitch: usize| for y in 0..FINISH_LINE_WIDTH {
@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)