Skip to content

Instantly share code, notes, and snippets.

View phpnode's full-sized avatar

Charles Pick phpnode

View GitHub Profile
@Yaffle
Yaffle / sort.js
Last active September 8, 2018 06:09
merge sort
// `Array#sort` implementation using the merge sort
// Notes:
// 1) calls comparator for undefined values, holes, values from the prototype chain;
// 2*) replaces holes with undefined values or values from the prototype chain;
// 3*) does not use `ToObject(this)`, `ToLength(this.length)`;
// 4*) does not throw errors for non-undefined non-function `comparefn`.
// 5*) uses `Math`, `Math.floor`, `String`, `Array`.
// 6*) calls setters of `Array.prototype` during internal buffer initialization.
// * This behaviour is inconsistent across browsers even for built-in `Array#sort`.
@monostere0
monostere0 / GlobalEvents.js
Last active February 19, 2020 08:10
Fire events between different browser windows using localStorage.
(function(window){
var EVENT_EXISTS = 'GlobalEvents: Event already exists.';
var eventIsRunning,
_eventStack,
_findByName,
stackEvent,
removeEvent,
eventListener,
@bripkens
bripkens / event-loop-nashorn.js
Last active August 21, 2021 06:18
Java 8 Nashorn event loop "polyfill". javax.script.ScriptEngine#eval calls should immediately call window.main to enter the event loop and thus to avoid concurrency issues. The XMLHttpRequest simulation is not yet finished.
(function(context) {
'use strict';
var Timer = Java.type('java.util.Timer');
var Phaser = Java.type('java.util.concurrent.Phaser');
var TimeUnit = Java.type('java.util.concurrent.TimeUnit');
var AsyncHttpClient = Java.type('com.ning.http.client.AsyncHttpClient');
var timer = new Timer('jsEventLoop', false);
var phaser = new Phaser();
@justinfagnani
justinfagnani / mixins.md
Last active April 13, 2022 12:14
Maximally Minimal Mixins
@lambdahands
lambdahands / _readme.md
Created September 28, 2015 17:09
FlowType and CSS Modules

Huh?

So basically FlowType doesn't know about CSS Modules, a really handy way of dealing with the plagues of CSS in codebases (global variables and dependency wackiness mainly).

What WebPack allows us to do is "require" CSS files and use their class names:

import styles from "my_styles.css";
import React from "react";
@idibidiart
idibidiart / GraphQL-Architecture.md
Last active September 16, 2023 18:36
Building an Agile, Maintainable Architecture with GraphQL

Building a Maintainable, Agile Architecture for Realtime, Transactional Apps

A maintainable application architecture requires that the UI only contain the rendering logic and execute queries and mutations against the underlying data model on the server. A maintainable architecture must not contain any logic for composing "app state" on the client as that would necessarily embed business logic in the client. App state should be persisted to the database and the client projection of it should be composed in the mid tier, and refreshed as mutations occur on the server (and after network interruption) for a highly interactive, realtime UX.

With GraphQL we are able to define an easy-to-change application-level data schema on the server that captures the types and relationships in our data, and wiring it to data sources via resolvers that leverage our db's own query language (or data-oriented, uniform service APIs) to resolve client-specified "queries" and "mutations" against the schema.

We use GraphQL to dyn

@dherman
dherman / shared-array-buffer.md
Last active October 29, 2023 11:04
fine-grained borrowing (read-write) and sharing (read-only) of buffers

Goal

Typed arrays can be copied or transferred between workers, but it's not possible for multiple workers to work with a buffer in parallel without copies. This document describes two ways to improve this without introducing data races: transferring read-write access to disjoint regions of buffers, and transferring read-only access to shared buffers/regions.

This variant of the API enables fine-grained borrowing and sharing, where a single ArrayBuffer can have multiple disjoint regions parceled out. This way individual workers can work with their regions at their original indices. This makes the API more amenable to being a compilation target.

Example

Here is an example that demonstrates sharing a read-only segment and multiple read-write segments with four separate workers.

@schempy
schempy / stream-file-upload-s3-nodejs.js
Last active March 11, 2024 10:20
Streaming File Uploads To Amazon S3 With Node.js
var http = require('http');
var router = require('routes')();
var Busboy = require('busboy');
var AWS = require('aws-sdk');
var inspect = require('util').inspect;
var port = 5000;
// Define s3-upload-stream with S3 credentials.
var s3Stream = require('s3-upload-stream')(new AWS.S3({
accessKeyId: '',
@zhpengg
zhpengg / skip_list.c
Created June 5, 2012 07:52
skiplist implementation in c
/* Skip Lists: A Probabilistic Alternative to Balanced Trees */
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#define SKIPLIST_MAX_LEVEL 6
typedef struct snode {
int key;
var Bar1 = base => class extends base {
componentWillMount(){
super.componentWillMount();
console.log('Bar1');
}
};
var Bar2 = base => class extends base {
componentWillMount(){
super.componentWillMount();