Skip to content

Instantly share code, notes, and snippets.

View maryrosecook's full-sized avatar

Mary Rose Cook maryrosecook

View GitHub Profile
@maryrosecook
maryrosecook / alltogether.js
Created May 25, 2011 16:53
Examples for Machine.js
var landscape = new Landscape(); // one actor
// make instance of Machine and get the root nodes for each actor
var machine = new Machine();
landscape.state = machine.generateTree(landscapeJson, landscape);
// every second, something happens in the ecosystem
setTimeout("step()", 1000);
var step = function() {
// trigger the next state transition
@maryrosecook
maryrosecook / enemyai.js
Created May 26, 2011 14:20
The behaviour tree for Pistol Slut
{
identifier: "idle", strategy: "prioritised",
children: [
{
identifier: "spot", strategy: "sequential",
children: [
{ identifier: "callRange" },
{ identifier: "stopSpotting" },
]
},
@maryrosecook
maryrosecook / basicidea.js
Created August 14, 2011 15:01
Examples for Snowflake.js
var s = new Snowflake();
s.aSnowflakeFunc(supportingVar, actionFunc(arg) {
// do stuff in here.
}, arg);
var aliens = [{}, {}, {}];
var aliensCollidingWithPlayer = [];
for (var i = 0; i < aliens.length; i++) {
if(colliding(alien[i], player)) { // is colliding current tick
var collidingInPreviousTick = false;
for (var j = 0; j < aliensCollidingWithPlayer.length; j++) {
if (aliens[i] === aliensCollidingWithPlayer[j]) {
collidingInPreviousTick = true;
break;
var applyFn = function(node, fn) {
var applied = fn(node);
return applied === undefined ? node : applied;
};
var macro = function(key, val) {
if (key.firstBit === repeatChild) {
repeatChild(key, val)
}
};
block_size = 16
blocks = []
a_size = 128
b_size = 32
a = [0, 1, 2]
b = [0, 1, 2]
print a == b
def memoise(fn):
# A practical introduction to functional programming
Many functional programming articles teach abstract functional techniques. That is, composition, pipelining, higher order functions. This one is different. It shows examples of imperative code that people write every day and translates them to a functional style.
The imperative examples are all loops. The first section of the article takes short, data transforming loops and translates them into functional maps and reduces. The second section takes longer loops, breaks them up into units and makes each unit functional. The third section takes a loop that is a long series of successive data transformations and decomposes it into a functional pipeline.
The examples are in Python, because many people find Python easy to read. A number of the examples eschew pythonicity in order to demonstrate functional techniques common to many languages: map, reduce, pipeline.
## A guide rope
### Keybase proof
I hereby claim:
* I am maryrosecook on github.
* I am maryrosecook (https://keybase.io/maryrosecook) on keybase.
* I have a public key whose fingerprint is 59DB 7EF4 2BAC 5D67 22FB F7DA 7DFF 4628 A3F1 83AF
To claim this, I am signing this object:
@maryrosecook
maryrosecook / gist:7cca0b83b896ade99f69
Created November 16, 2014 16:10
Lauren's first program!
shopping_list = ["apple", "toothbrush", "banana", "black lava"]
shopping_list.append("cheese")
shopping_list.reverse()
print("Shopping List")
for shopping_list_item in shopping_list:
if len(shopping_list_item)<7 or shopping_list_item=="black lava":
print("-" + shopping_list_item)