Skip to content

Instantly share code, notes, and snippets.

View thomasfoster96's full-sized avatar
🏠
Working from home

Thomas Foster thomasfoster96

🏠
Working from home
View GitHub Profile
@thomasfoster96
thomasfoster96 / form-example.js
Created December 13, 2018 14:02
Symbol-keyed Hooks
// ⚠️ This is NOT the React Hooks API
const key = Symbol();
function Form() {
// ...
const name = useFormInput(key, "name");
const surname = useFormInput(key, "surname");
// ...
return (

Keybase proof

I hereby claim:

  • I am thomasfoster96 on github.
  • I am thomasfoster96 (https://keybase.io/thomasfoster96) on keybase.
  • I have a public key ASDCAbD60YhJmYb8J9dRvtrYNFA_qnfxOv5nmjaKtgakZwo

To claim this, I am signing this object:

@thomasfoster96
thomasfoster96 / index.html
Last active March 26, 2018 06:22
Batman By-election Visualisation
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<div id="map">Hello World!</div>
</body>
</html>
@thomasfoster96
thomasfoster96 / index.js
Created June 28, 2016 14:39
An ECMAScript to English transpiler.
function transpile(token){
switch(token.type){
case "Literal":
switch(typeof token.value){
case "string":
return `"${token.value}"`;
case "boolean":
return `${token.value ? "true" : "false"}`;
case "null":
return "nothing";
@thomasfoster96
thomasfoster96 / hashtags.md
Last active February 26, 2016 04:58
Political Hashtags Directory
/* Template string as function.
*
* Pros: Only has access to parameters.
* Cons: Have to make a module.
*/
import {template} from './template-string-as-function.js';
let page = template({
title: "10 Wierd Template String Tricks",
@thomasfoster96
thomasfoster96 / graph.js
Last active August 29, 2015 14:23
Data structures.
class Graph {
adjList = new Map()
constructor(iterable, directed = true){
for(let node of iterable){
this.adjList.set(node, new Map());
}
}
@thomasfoster96
thomasfoster96 / script.js
Created June 15, 2015 03:34
Expressions-only ECMAScript
// This gist plays around with a subset of ECMAScript6 (ES2015) that only uses expressions (except for the 'Program' const declaration).
/* Some rules:
* Arrow functions that evaluate an expression are the only kinds of functions allowed.
* All variables are declared as function parameters.
* If you want to scope variables, use the following format of an arrow function in parentheses:
((variables,to,declare,in,function,scope)=>(expressions,within,which,you,will,use,said,variables))()
* No return statement - the last expression in a list of expressions is what is returned.
* No Generators :( Or async/await :(
@thomasfoster96
thomasfoster96 / do-until-loop.js
Created May 23, 2015 12:25
ES6 Loop Functions
/*
* The until version of doWhileLoop.
*/
function untilLoop(condition, body){
if(!condition()){
body();
return untilLoop(condition,body);
}else{
return;