Skip to content

Instantly share code, notes, and snippets.

@stephendeyoung
stephendeyoung / gist:4551065
Created January 16, 2013 21:19
This is an attempt to do memoization without mutation. I've left comments in the code regarding how I'd prefer this to work.
var memoize = function(func){
var cache = function(a) {
return {
get: function() {
return a;
},
set: function(b) {
return cache(a.concat(createArray([], b)));
}
App = Ember.Application.create({});
var attr = Ember.attr;
App.Post = Ember.Model.extend({
id: attr('number'),
title: attr('string'),
author: attr('string'),
intro: attr('string'),
extended: attr('string'),
@stephendeyoung
stephendeyoung / actions.cljs
Last active August 16, 2016 07:54
ClojureScript function to show a Bootstrap dropdown.
(defn actions [array-of-funcs]
(doseq [func array-of-funcs] (func)))
$(window).bind("cuePoint", function(event, action) {
self.onCuePoint(action); // action = { eventType: ..., value: ... }
});
onCuePoint: function(action) {
if (action.eventType == "slideChange") {
this.collection.currentActive = action.value;
this.collection.setActive(action.value);
}
}
Marionette.CollectionView.extend({
initialize: function(options) {
this._initChildViewStorage();
this.childView = this.childView || options.childView;
this.createChildren(options);
this._initialEvents();
},
createChildren: function(options) {
// This is an answer to https://gist.github.com/stephendeyoung/6f38ef7664693f040a98
var util = require('util');
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function(chunk) {
var chunk = process.stdin.read();
var data = chunk.split('\n');
var mapCoords = data[0].split(' ').map(convertStringToNumber);

Problem: Martian Robots

The Problem

The surface of Mars can be modelled by a rectangular grid around which robots are able to move according to instructions provided from Earth. You are to write a program that determines each sequence of robot positions and reports the final position of the robot.

A robot position consists of a grid coordinate (a pair of integers: x-coordinate followed by y-coordinate) and an orientation (N, S, E, W for north, south, east, and west).

A robot instruction is a string of the letters “L”, “R”, and “F” which represent, respectively, the instructions:

const EVT = require('evrythng-extended');
const evtClient = new EVT.TrustedApp(apiKey);
function onThngPropertiesChanged(event) {
evtClient.thng(event.thng.id).action('_custom').create({
customFields: {
test: true
}
}).then(() => done()).catch(done);
}
const EVT = require('evrythng-extended');
const evtClient = new EVT.TrustedApp(apiKey);
function onThngPropertiesChanged(event) {
console.log('Running onThngPropertiesChanged');
evtClient.thng('UXmVNF5kBHCe6BRBhHfFtkVq').action('_custom').create({
customFields: {
test: true
}
}).then(() => done()).catch(done);
}
const EVT = require('evrythng-extended');
const evtClient = new EVT.TrustedApp(apiKey);
function onThngPropertiesChanged(event) {
console.log('Running onThngPropertiesChanged');
evtClient.thng('UXmVNF5kBHCe6BRBhHfFtkVq').action('_custom').create({
customFields: {
test2: true
}
}).then(() => done()).catch(done);
}