Skip to content

Instantly share code, notes, and snippets.

View RichardMarks's full-sized avatar

Richard Marks RichardMarks

View GitHub Profile
@RichardMarks
RichardMarks / README.md
Created March 10, 2018 22:32
Building Windows Exe on OSX
  • Download SDL2 SDL2_image SDL2_ttf mingw development libraries from libsdl.org
  • Create external/SDL2/32 and external/SDL2/64 directories
  • Extract the appropriate files from the dev libraries into the newly created directories

You should have

external/SDL2/32/include
external/SDL2/32/lib
external/SDL2/32/bin
external/SDL2/32/share
@RichardMarks
RichardMarks / xorshift.c
Created March 9, 2018 17:05
XORShift random number generator
#include "stdio.h"
#include <stdlib.h>
unsigned long long rngState[2] = { 1, 2 };
unsigned rngSeed(int n, int n2) {
if (n) {
rngState[0] = n;
} else {
rngState[0] = rand() * 65535 | 0;
@RichardMarks
RichardMarks / rgba2-abgr.c
Created March 8, 2018 23:52
RGBA to ABGR bit manipulation
#include "stdio.h"
#define INPUT_COLOR 0x10203040
#define EXPECTED_COLOR 0x40302010
typedef unsigned char u8;
typedef unsigned int u32;
int main(void) {
printf("\n");
@RichardMarks
RichardMarks / playground.nim
Last active February 28, 2018 03:06
nim particles playground
import
os,
times,
math,
sdl2,
sdl2.image,
random
const SCREEN_SCALE = 2
const SCREEN_W = 1920 div SCREEN_SCALE
@RichardMarks
RichardMarks / fibonacci.js
Created June 26, 2017 20:02
Exploring Fibonacci Algorithms
// Exploring Fibonacci Algorithms
// (C) 2017, Richard Marks
// MIT License
// Time: O(2^n), Space: O(n)
const fibRecursive = n => n <= 1 ? n : fibRecursive(n - 1) + fibRecursive(n - 2)
// Time: O(n), Space: O(n)
const fibIterative = n => {
const f = [0, 1]
@RichardMarks
RichardMarks / gitsafetynet.sh
Created June 7, 2017 18:52
Git Safety Net -- Stop losing work from context switching
#!/bin/sh
# git safety net v1.0
# (C) 2017, Richard Marks <ccpsceo@gmail.com>
# MIT License
function git_safety_net () {
if [[ "$BASH_COMMAND" == *"git checkout"* ]]
then
echo -e "\x1b[93m \x1b[41m git safety net triggered! \x1b[39m \x1b[49m"
@RichardMarks
RichardMarks / deepCopy.js
Created June 2, 2017 19:46
JavaScript ES6 - simple deep copy routine (does not handle circular references) MIT License
// deepCopy.js
// simple deep copy routine
// does not handle circular references
// (C) 2017, Richard Marks. MIT License
// ccpsceo@gmail.com http://www.ccpssolutions.com
// use:
// const { deepCopy, runTests } = require('./deepCopy')
// const clone = deepCopy(source)
//
@RichardMarks
RichardMarks / isEqual.js
Created June 1, 2017 20:40
A deep equal implementation in ECMAScript 2015
const isEqual = module.exports = (a, b) => {
if (typeof a === 'object' && typeof b === 'object') {
const deltas = []
for (const prop of Object.keys(a)) {
if (prop in b) {
if (typeof a[prop] === 'object') {
const eq = isEqual(a[prop], b[prop])
!eq && deltas.push(prop)
} else if (typeof a[prop] === 'function') {
const eq = a[prop].toString() === b[prop].toString()
@RichardMarks
RichardMarks / .bash_profile
Last active June 22, 2017 22:00
OSX bash profile
# GNU coreutils
PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"
MANPATH="/usr/local/opt/coreutils/libexec/gnuman:$MANPATH"
# bash completion
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# Added by n-install (see http://git.io/n-install-repo).
export N_PREFIX="$HOME/n"; [[ :$PATH: == *":$N_PREFIX/bin:"* ]] || PATH+=":$N_PREFIX/bin"
@RichardMarks
RichardMarks / maze.js
Created April 16, 2017 22:27
Simple 2D Maze Generator
// Maze Generator
// (c) 2017, Bang Bang Attack Studios
// http://www.bangbangattackstudios.com
const random = options => {
const index = Math.random() * options.length
return options[~~index]
}
const maze = (width, height, factory) => {