Skip to content

Instantly share code, notes, and snippets.

View nrkn's full-sized avatar

Nik nrkn

View GitHub Profile
@brigand
brigand / nonBlockingGenerator.js
Last active February 2, 2017 04:31
This allows doing expensive computation, periodically yielding to the event loop, while keeping synchronous syntax
function nonBlocking(generator) {
return (...args) => {
var callback = args[args.length - 1];
var iter = generator(...args);
function next() {
try {
var res = iter.next();
}
catch (e) {
callback(e);
anonymous
anonymous / GAME_MASTER_v0_1.protobuf
Created July 16, 2016 16:31
Pokemon Go decoded GAME_MASTER protobuf file v0.1
Result: 1
Items {
TemplateId: "BADGE_BATTLE_ATTACK_WON"
Badge {
BadgeType: BADGE_BATTLE_ATTACK_WON
BadgeRanks: 4
Targets: "\nd\350\007"
}
}
Items {
@rafaeljesus
rafaeljesus / js-micro.js
Created May 16, 2016 20:15 — forked from yuval-a/js-micro.js
Javascript micro-optimizations
// Array literal (= []) is faster than Array constructor (new Array())
// http://jsperf.com/new-array-vs-literal/15
var array = [];
// Object literal (={}) is faster than Object constructor (new Object())
// http://jsperf.com/new-array-vs-literal/26
var obj = {};
// property === undefined is faster than hasOwnProperty(property)
// http://jsperf.com/hasownproperty-vs-in-vs-undefined/17

here are the most useful pull streams modules

combining pull streams

a library of simple functions that will be familiar functional programmers.

@arcollector
arcollector / gist:a7a1492689dee2e947ec
Last active November 21, 2023 01:34
Polygon scanline filling in JS
var polygonFilling = function( vertices ) {
// "global" variables
var verticesCount = vertices.length,
edgesEntered,
// table cols
yMax, yMin, xInt, invNegSlope;
// *************************
@Flafla2
Flafla2 / Perlin_Tiled.cs
Last active April 27, 2024 19:43
A slightly modified implementation of Ken Perlin's improved noise that allows for tiling the noise arbitrarily.
public class Perlin {
public int repeat;
public Perlin(int repeat = -1) {
this.repeat = repeat;
}
public double OctavePerlin(double x, double y, double z, int octaves, double persistence) {
double total = 0;
@mmckegg
mmckegg / gist:44c31fa6c51ed15b06ad
Created August 2, 2014 03:50
observable array
var mutators = [
'fill', 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'
]
function ObservableArray(onChange){
var array = []
array.set = set
array.onchange = onChange
@blixt
blixt / prng.js
Last active January 14, 2024 07:01
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**
@jonlabelle
jonlabelle / string-utils.js
Last active May 5, 2024 19:44
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.