Skip to content

Instantly share code, notes, and snippets.

View sstur's full-sized avatar

Simon Sturmer sstur

View GitHub Profile
// node_modules/@babel/plugin-proposal-object-rest-spread/lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _helperPluginUtils() {
type Listener<T extends Array<unknown>> = (...args: T) => void;
export class EventEmitter<
E extends Record<string, Array<unknown>> = Record<never, []>
> {
private listenerMap: { [K in keyof E]?: Set<Listener<E[K]>> } = {};
on<K extends keyof E>(key: K, listener: Listener<E[K]>) {
return this.addListener(key, listener);
}
@sstur
sstur / package.json
Last active September 25, 2019 10:39 — forked from darcien/package.json
Jest configuration for RN with expo
{
"jest": {
"preset": "jest-expo",
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js",
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": [
"**/__tests__/**/*.ts?(x)",
"**/?(*.)+(spec|test).ts?(x)"
@sstur
sstur / promise-streams.js
Last active February 13, 2018 03:23
[RFC] Node Streams to Promise-based Streams
// @flow
import fs from 'fs';
import {join} from 'path';
async function main() {
let filePath = join(__dirname, '../assets/image.jpg');
// The first one uses Promise-based readable stream.
await getFileSizeOne(filePath);
// The second one uses "for await" async iterator approach.
await getFileSizeTwo(filePath);
@sstur
sstur / asyncAwait.js
Last active February 21, 2017 09:23 — forked from oshimayoan/asyncAwait.js
Fetching github users, orgs, and repos and print it.
// @flow
/* global fetch */
/* eslint-disable babel/no-await-in-loop */
type JSONData = null | string | number | boolean | {[key: string]: JSONData} | Array<JSONData>;
function handleResponseJSON(response: Response): Promise<JSONData> {
return response.json();
}
import React from 'react';
import './App.css';
class App extends React.Component {
constructor() {
super();
this.state = {
error: null,
data: null,
};
const http = require('http');
let server = http.createServer();
server.on('request', (request, response) => {
let {method, url, headers} = request;
console.log(`Received ${method} request for "${url}".`);
for (let headerName of Object.keys(headers)) {
let headerValue = headers[headerName];
// ES5
var getBound = Function.prototype.apply.bind(Function.prototype.bind)
function createDate() {
for (var i = 0, length = arguments.length, args = new Array(length + 1); i < length; i++) {
args[i + 1] = arguments[i];
}
var BoundDate = getBound(Date, args);
return new BoundDate();
import RichTextEditor from 'react-rte';
import React from 'react';
class StatefulRichTextEditor {
constructor() {
this.state = {
value: RichTextEditor.createEmptyValue(),
};
}
@sstur
sstur / MyArray.js
Created July 7, 2015 17:44
Extend (subclass) native Array
function MyArray() {
var array = [];
if (arguments.length) {
array.push.apply(array, arguments);
}
// note: use `Object.setPrototypeOf` instead of __proto__ to be truly standards-compliant
array.__proto__ = MyArray.prototype;
return array;
}