Skip to content

Instantly share code, notes, and snippets.

View dcousens's full-sized avatar
🇺🇦

Daniel Cousens dcousens

🇺🇦
View GitHub Profile
time notation
constant O(1)
log-logarithmic O(log log n)
logarithmic O(log n)
linear O(n)
quadratic O(n^2)
cubic O(n^3)
polynomial O(n^x)
exponential O(x^n)
factorial O(n!)
@dcousens
dcousens / NineMensMorris.py
Last active September 29, 2016 15:32
Adapted from a StackOverflow answer
from collections import namedtuple
#===========================================================================
class Rule:
""" The rule interface.
"""
def checkForAction(self, player, move):
pass
@dcousens
dcousens / glfw3.sh
Created April 10, 2017 09:40
D bindings for various libraries
mkdir -p glfw3
cd glfw3
echo "module glfw3;" > glfw3.h
curl https://raw.githubusercontent.com/glfw/glfw/3.2.1/include/GLFW/glfw3.h >> glfw3.h
cat glfw3.h |\
grep -v "dllimport" |\
grep -v "__declspec" |\
grep -v "__attribute" |\
@dcousens
dcousens / heightmap.py
Last active June 9, 2017 23:53
Prototype of the midpoint displacement algorithm, also known as the diamond square algorithm.heightmap.py creates a triangular mesh represented as a list vertices and indices from a 2d normalized array of values and some parameters. Commonly used as a heightmap.
import itertools
def get_verts_indices_for_heightmap(heightmap, stepx, stepy, minz, maxz):
""" heightmap assumed to be normalized (values between 0 and 1)
"""
height = len(heightmap)
width = len(heightmap[0])
spanz = maxz - minz
# n_heightmap = width * height
@dcousens
dcousens / ChainedRangeIndexing.d
Last active June 26, 2017 15:34
Various C++/D snippets
import std.stdio;
import std.algorithm;
import std.range;
import std.array;
void main() {
// initial data
int[] x = [10, 20, 30], y = [40, 50, 60, 70, 80], z = [90, 100, 110, 120];
auto linked = [x, y, z];
@dcousens
dcousens / LICENSE.md
Created September 5, 2018 08:36
For all my public gists

Copyright 2018 Daniel Cousens

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OT

// Copyright 2018 Daniel Cousens
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@dcousens
dcousens / ranges.ts
Last active August 10, 2022 02:49
Nice, quick and easy range functions for your ES6 day-to-day
// MIT License
//
// Copyright (c) 2022 Daniel Cousens
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@dcousens
dcousens / .gitignore
Last active September 29, 2022 15:08
Naive JSON string serialisation
.test.actual
test
@dcousens
dcousens / Makefile
Last active September 13, 2023 06:08
A generic D2 to SVG Makefile
# a generic D2 to SVG Makefile
.PHONY: clean watch
SRC = $(shell find . -name '*.d2')
SVGs = $(patsubst %.d2, %.svg, $(SRC))
build: $(SVGs)
%.svg: %.d2
d2 $< $@