Skip to content

Instantly share code, notes, and snippets.

View DanCouper's full-sized avatar

Dan Couper DanCouper

  • Strive Gaming
  • Newcastle, UK
  • 03:48 (UTC)
  • X @DanCouper
View GitHub Profile
@DanCouper
DanCouper / calculator-spike.re
Last active June 5, 2017 10:41
Not really functional initial spike for a calculator processor
/**
* Dunno how to phrase this as I'm at a very early stage of learning OCaml/Reason,
* but I'm writing a calculator as first semi-complex toy app, and not sure if what
* I'm trying to do is completely wrongheaded (& if I'm making some futile attempt
* to replicate Erlang tagged tuple conventions using the OCaml type system).
* Calculator takes a sequential stream of inputs, and I need to parse those as
* they come in. To facilitate pattern matching, I wanted to set it up so that each
* input is a tuple of `type * displayValue`, eg `(Digit One, "1")` or
* `(Number Int, "1234")` or `(Op Div, "÷")`, so I can do basically all
* processing using the type system, and configure how the display looks by
@DanCouper
DanCouper / controlled-slider.markdown
Last active May 26, 2017 08:23
Controlled slider
@DanCouper
DanCouper / index.pug
Created May 23, 2017 20:49
React Calculator
#app
@DanCouper
DanCouper / index.html
Created May 23, 2017 20:38
React Calculator
<div id="wrapper">
<div id="app"></div>
</div>
@DanCouper
DanCouper / index.html
Created May 23, 2017 20:34
React Calculator
<!--
Nothing here, the app will render on the Body.
Sorry.
-->
@DanCouper
DanCouper / calculator-using-shunting-yard-algorithm.markdown
Created May 8, 2017 13:27
Calculator using Shunting Yard Algorithm
<!--FCC Tic Tac Toe-->
<header></header>
<main>
<button onclick='gameData.reset()'>New Game</button>
<section id='gameOverall'>
<div id='gameCentral' class='gameCentralDefault'></div>
</section>
</main>
@DanCouper
DanCouper / reduce.md
Last active February 28, 2017 16:20
Explanation of how reduce works

So you have an array and you want to add it up. Here:

var arr = [1,2,3]
var accumulator = 0
for (var i = 0; i < arr.length; i++) {
  accumulator = accumulator + arr[i]
}
return accumulator
@DanCouper
DanCouper / dice.ex
Last active February 13, 2017 23:42
Exploratory investigation of methods of creating dice rolls (first spike)
defmodule Dice do
@moduledoc """
Fragile function that turns a string into a list of rolls - _e.g._
> Dice.roll("2d6")
[4, 3]
> Dice.roll("d12")
[11]
"""

By Mark Damon Hughes [email protected]

The original Rogue algorithm is pretty nifty. Any time you need a random dungeon, give this a try:

  1. Divide the map into a grid (Rogue uses 3x3, but any size will work).
  2. Give each grid a flag indicating if it's "connected" or not, and an array of which grid numbers it's connected to.
  3. Pick a random room to start with, and mark it "connected".
  4. While there are unconnected neighbor rooms, connect to one of them, make that the current room, mark it "connected", and repeat.
  5. While there are unconnected rooms, try to connect them to a random connected neighbor (if a room has no connected neighbors yet, just keep cycling, you'll fill out to it eventually).
  6. All rooms are now connected at least once.