This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function wait (s) { | |
| return new Promise((resolve, reject) => { | |
| setTimeout(() => resolve(true), s) | |
| }) | |
| } | |
| async function main () { | |
| console.log('start now') | |
| await wait(2000) | |
| console.log('end after 2 seconds') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ----------------------------------------- * | |
| Lazy List Implementation | |
| * ----------------------------------------- */ | |
| // Haskell-like infinite List, implemented with es6 generators | |
| // Lazyness lets you do crazy stuff like | |
| List.range(0, Infinity) | |
| .drop(1000) | |
| .map(n => -n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var targetObject = { | |
| sayHi(){ return `returning show: ${p.show}` }, | |
| show: 'family guy', | |
| characters: { | |
| dad: 'peter', | |
| mom: 'lois', | |
| daughter: 'meg', | |
| son: 'chris', | |
| baby: 'stewie', | |
| dog: 'brian' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let easing = { | |
| // classic linear | |
| linear: t => t, | |
| // slow -> fast | |
| easeInQuad: t => t*t, | |
| easeInCubic: t => t*t*t, | |
| easeInQuint: t => t*t*t*t, | |
| // fast -> slow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function scrollTo (element, duration) { | |
| if (!element) { | |
| return | |
| } | |
| var target = element.scrollHeight | |
| target = Math.round(target) | |
| duration = Math.round(duration) | |
| if (duration < 0) { | |
| return false | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function () { | |
| var module = {}; | |
| // maps | |
| var LOBBY = [ | |
| [ 1, 1, 1, 1, 1, 1, 1, 1 ], | |
| [ 1, 0, 0, 0, 1, 0, 0, 1 ], | |
| [ 1, 0, 0, 0, 1, 0, 0, 1 ], | |
| [ 1, 0, 0, 0, 1, 0, 0, 1 ], | |
| [ 1, 0, 0, 0, 1, 1, 0, 1 ], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Returns a hash code for a string. | |
| * (Compatible to Java's String.hashCode()) | |
| * | |
| * The hash code for a string object is computed as | |
| * s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] | |
| * using number arithmetic, where s[i] is the i th character | |
| * of the given string, n is the length of the string, | |
| * and ^ indicates exponentiation. | |
| * (The hash value of the empty string is zero.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // PUBLIC DOMAIN | |
| // | |
| // Single function that implements A-Star pathfinding algorithm in ~75 lines of code | |
| // | |
| // (why use a huge library..?) | |
| // | |
| // Parameters: | |
| // solid array of booleans (of size width * height) that determine if a tile is solid | |
| // width width of the map | |
| // height height of the map |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let _id; | |
| const id = () => { | |
| let now = Date.now(); | |
| if (now <= _id) now++; | |
| _id = now; | |
| return now; | |
| } | |
| const hash = (n) => n.sort((a, b) => a > b).join('$'); | |
| const remove = (a, v) => a.splice(a.indexOf(v), 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Turns out this was not too difficult. | |
| // By using the event loop as a global mail box ordering is even guaranteed for messages between only two actors. | |
| // TODO would like to try and put one actor in a web worker to get some real parallism | |
| // TODO would like to handle errors and have the concept of a deceased actor while a reference to an actor still exists. Probably involves creating an actor system like in Scala. Eurgh. | |
| var actor = { | |
| send: function(message) { | |
| var self = this; | |
| console.log("sending to:", self); | |
| setTimeout(function(){ |