Skip to content

Instantly share code, notes, and snippets.

@dariusf
dariusf / codecombat-integration.io
Last active August 29, 2015 14:01
CodeCombat Io integration example
# Create Player prototype
Player := Object clone
Player moveRight := method(writeln(self name .. " moved right"))
# Instantiate player
player := Player clone
player name := "Bob"
player actions := method(
# Insert user's code here
@dariusf
dariusf / cc-example.js
Last active August 29, 2015 14:01
Example of compiled output
/*
This is the compiled result of the following:
chooseAction := method(
# Written by user
moveRight
)
connected to: 127.0.0.1
2014-05-30T11:33:24.602+0800 /home/darius/coco/dump/coco/thang.types.bson
2014-05-30T11:33:24.602+0800 going into namespace [coco.thang.types]
2014-05-30T11:33:24.603+0800 Created collection coco.thang.types with options: { "create" : "thang.types", "flags" : 1 }
2014-05-30T11:33:27.246+0800 Progress: 112876218/140627061 80% (bytes)
1075 documents found
2014-05-30T11:33:28.071+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "coco.thang.types" }
2014-05-30T11:33:28.093+0800 Creating index: { unique: true, key: { slug: 1 }, name: "slug index", ns: "coco.thang.types", sparse: true, background: true, safe: null }
2014-05-30T11:33:28.099+0800 Creating index: { unique: true, key: { original: 1, version.major: -1, version.minor: -1 }, name: "version index", ns: "coco.thang.types", background: true, safe: null }
2014-05-30T11:33:28.107+0800 Creating index: { key: { index: 1, _fts: "text", _ftsx: 1 }, name: "search index", ns: "coco.thang.types", sparse: true, language_overrid
@dariusf
dariusf / index.html
Created July 11, 2014 15:19
Phaser pointer.worldX/Y issue
<!DOCTYPE html>
<html>
<head>
<title>example</title>
<meta name="Viewport" content="width=device-width; user-scaleable=no; initial-scale=1.0" />
<style type="text/css">
#everything {
max-width: 500px;
width: 100%;
package ui;
import javafx.scene.Node;
import javafx.scene.control.ListView;
import ui.components.FilterTextField;
import ui.issuecolumn.ColumnControl;
import ui.issuepanel.IssuePanel;
import ui.issuepanel.IssuePanelCard;
public class UITraversal {

Higher-order functions

debug

display is useful for seeing the intermediate results of a function as it runs. It's tiresome to clutter our programs with calls to display, though. A way to log the inputs and outputs of a function would be nice.

Define the function debug1, which takes a function argument f and returns a function that, when called, writes its input and output to the console, and returns the same thing f would have when called. In other words, the type of debug1 is (x -> y) -> (x -> y).

var PASSED = 'passed',
STARTED = 'started',
FAILED = 'failed',
ERRORED = 'errored',
CANCELED = 'canceled',
POLL_PERIOD = 5000,
MAX_MINUTES = 22;
function icon(which) {
@dariusf
dariusf / OOP.md
Last active October 21, 2015 02:43

We were introduced to OOP this week. While it may seem very complex, at heart it's still about the same notions of data and operations on data.

As JediScript has a rather complicated OOP system with many moving parts, it's important to distinguish the ideas from the implementation.

Ideas

  • State and behaviour: Objects comprise state and behaviour. Programs are no longer structured around just functions, but around a central object which specific functions operate on. Computation usually involves updating the state of that central object over time.

  • Aggregation: As with functions, we can compose objects, building large objects out of smaller ones.

Streams

Definition: Important to keep in mind! Will help you reason about streams and guide you when you get confused.

Wishful thinking: Useful strategy for thinking about recursion and infinite things. Basically you assume that the function you are writing already has a correct implementation, and you use that assumption to write its recursive case. Keeping the return type of the function in mind can help.

Infinity: Streams can be finite or infinite.

Some functions can only deal with finite streams, for example stream_length and stream_append (first argument should be finite). They need to evaluate an entire stream to have an effect.

using UnityEngine;
using System.Collections;
public class PlayerControl : MonoBehaviour {
public float moveSpeed;
public float jumpForce;
private Rigidbody2D myRigidbody;