Skip to content

Instantly share code, notes, and snippets.

Avatar
🇺🇦

Daniel Cousens dcousens

🇺🇦
View GitHub Profile
@dcousens
dcousens / ranges.ts
Last active Aug 10, 2022
Nice, quick and easy range functions for your ES6 day-to-day
View ranges.ts
// 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 Sep 29, 2022
Naive JSON string serialisation
View .gitignore
.test.actual
test
View morgan_gql_token.js
// 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 / LICENSE.md
Created Sep 5, 2018
For all my public gists
View LICENSE.md

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

@dcousens
dcousens / glfw3.sh
Created Apr 10, 2017
D bindings for various libraries
View glfw3.sh
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 / ChainedRangeIndexing.d
Last active Jun 26, 2017
Various C++/D snippets
View ChainedRangeIndexing.d
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 / _scripttemplates.md
Last active Mar 26, 2022
Transaction / Script Templates
View _scripttemplates.md
  • <> represents data or script
  • {} represents data that must prefixed by OP_PUSHDATA
  • [] represents multiple {}

Standard Scripts

PubKey (pay-to-pubkey / P2PK)

Address: N/A
scriptPubKey: {pubKey} OP_CHECKSIG
View complexity.txt
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 Sep 29, 2016
Adapted from a StackOverflow answer
View NineMensMorris.py
from collections import namedtuple
#===========================================================================
class Rule:
""" The rule interface.
"""
def checkForAction(self, player, move):
pass
@dcousens
dcousens / heightmap.py
Last active Jun 9, 2017
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.
View heightmap.py
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