Skip to content

Instantly share code, notes, and snippets.

View jdrew1303's full-sized avatar
probably drinking coffee

James Drew jdrew1303

probably drinking coffee
View GitHub Profile
@jdrew1303
jdrew1303 / euribor_3_m_rates.json
Created June 3, 2019 20:56
euribor 3 month rate
[
{
"date": "02/01/2019",
"rate": -0.31
},
{
"date": "03/01/2019",
"rate": -0.309
},
{

Fundamentals: why state machines?

States. The final frontier. These are the voyages of an enterprising developer. Her eternal mission: to explore strange new techniques, to seek out better ways to engineer for mental models and new design patterns. To boldly go where a few awesome devs have gone before.

So you’ve found our poignant guide to SCXML and surely you’re wondering “Why should I want to go out of my way to use formal state machines?” or something like that. Hopefully this introduction addresses that kind of question.

An example: Nancy’s RPG

The problem

@jdrew1303
jdrew1303 / index.js
Last active October 30, 2018 23:02
text classification with neural networks in javascript
const mimir = require('mimir');
const brain = require('brain.js');
/* few utils for the example */
// our output is recorded as a vector, where the index in the vector
// is the enum (we create it with a zero index). We fill the index in
// the array with a 1 and the rest of the items as a 0 (true and false).
const vectorise = (category, numberOfCategories) => {
const vector = new Array(numberOfCategories).fill(0);
@jdrew1303
jdrew1303 / readme.md
Last active October 1, 2018 23:19
setting up raspberry pi for headless operation

Enable SSH

To enable SSH, first navigate to the boot directory:

cd /Volumes/boot Now create an empty file called "ssh":

touch ssh This will enable SSH when the Pi is booted.

@jdrew1303
jdrew1303 / index.js
Created August 15, 2018 23:43
javascript nes emulator
require('text-encoding');
const fs = require("fs");
const {NES} = require("jsnes");
const sinon = require("sinon");
const SCREEN_WIDTH = 256;
const SCREEN_HEIGHT = 240;
@jdrew1303
jdrew1303 / modules.js
Created August 15, 2018 22:52 — forked from branneman/1-globals.js
A history of different JavaScript module formats
/**
* Globals
*/
var Carrousel = function(elem) { this.init() };
Carrousel.prototype = { init: function() {} };
new Carrousel();
/**
* Namespacing
* - No globals (only the namespace variable itself is global)
@jdrew1303
jdrew1303 / fp-lenses.js
Created August 15, 2018 22:52 — forked from branneman/fp-lenses.js
JavaScript: Lenses (Functional Programming)
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
@jdrew1303
jdrew1303 / primitive-reference-types-javascript.md
Created August 15, 2018 22:52 — forked from branneman/primitive-reference-types-javascript.md
Primitive Types & Reference Types in JavaScript

Primitive Types & Reference Types in JavaScript

An explanation of JavaScript's pass-by-value, which is unlike pass-by-reference from other languages.

Facts

  • JavaScript has 2 kinds of variable types: primitive and reference.
  • A fixed amount of memory is reserved after creation of every variable.
  • When a variable is copied, it's in-memory value is copied.
  • Passing a variable to a function via a call also creates a copy of that variable.

Primitive Types

@jdrew1303
jdrew1303 / vscode-settings.md
Created August 15, 2018 22:52 — forked from branneman/vscode-settings.md
Visual Studio Code: My setup

Visual Studio Code: My setup (macOS)

Global settings

git clone [email protected]:branneman/dotfiles.git ~/.dotfiles
ln -s ~/.dotfiles/vscode-settings.json "~/Library/Application Support/Code/User/settings.json"

Run from terminal

  • Open the Command Palette ( + + P)
@jdrew1303
jdrew1303 / better-nodejs-require-paths.md
Created August 15, 2018 22:50 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions