Skip to content

Instantly share code, notes, and snippets.

View peterschussheim's full-sized avatar

Peter Schussheim peterschussheim

View GitHub Profile
@peterschussheim
peterschussheim / index-0-non-debounced.js
Last active February 25, 2019 19:21 — forked from elijahmanor/index-0-non-debounced.js
React Debouncing Events
import React, { Component } from "react";
import { render } from "react-dom";
import "./index.css";
class Widget extends Component {
state = { text: "" };
handleChange = (e) => {
this.setState({ text: e.target.value });
};
render() {
@peterschussheim
peterschussheim / 01-object-readable.js
Created January 11, 2018 00:43 — forked from bellbind/01-object-readable.js
[ES2017][WHATWG-Streams] Basic examples for WHATWG Streams API (on nodejs)
// npm i web-streams-polyfill
const streams = require("web-streams-polyfill");
const {ReadableStream, WritableStream, TransformStream} = streams;
// (default) object stream
const rs1 = new ReadableStream({
async start(controller) {
// called by constructor
console.log("[start]");
controller.enqueue("a");
@peterschussheim
peterschussheim / fb.es6
Created December 27, 2017 16:41 — forked from raganwald/fb.es6
An elegant expression of the Fibonacci Sequence using generators https://en.wikipedia.org/wiki/Fibonacci_number
function * zipWith (zipper, ...iterables) {
const iterators = iterables.map(i => i[Symbol.iterator]());
while (true) {
const pairs = iterators.map(j => j.next()),
dones = pairs.map(p => p.done),
values = pairs.map(p => p.value);
if (dones.indexOf(true) >= 0) break;
yield zipper(...values);
@peterschussheim
peterschussheim / 1-easy.js
Created December 26, 2017 20:26 — forked from nybblr/1-easy.js
3 examples of using Async Generators and Async Iteration in JavaScript!
// Create a Promise that resolves after ms time
var timer = function(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Repeatedly generate a number starting
// from 0 after a random amount of time
var source = async function*() {
@peterschussheim
peterschussheim / launch.json
Created December 21, 2017 20:06 — forked from auchenberg/launch.json
VS Code Node inspector launch
{
"configurations": [
{
"name": "Node",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/server.js"
},
]
@peterschussheim
peterschussheim / launch.json
Last active March 23, 2018 18:56 — forked from auchenberg/launch.json
VSCode + React debug config
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"name": "Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",

Difference between Debounce and Throttle

Debounce

Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.

Throttle

@peterschussheim
peterschussheim / function_invocation.js
Created April 20, 2017 18:15 — forked from myshov/function_invocation.js
11 Ways to Invoke a Function
console.log(1);
(_ => console.log(2))();
eval('console.log(3);');
console.log.call(null, 4);
console.log.apply(null, [5]);
new Function('console.log(6)')();
Reflect.apply(console.log, null, [7])
Reflect.construct(function(){console.log(8)}, []);
Function.prototype.apply.call(console.log, null, [9]);
Function.prototype.call.call(console.log, null, 10);
@peterschussheim
peterschussheim / The Technical Interview Cheat Sheet.md
Created March 9, 2017 00:15 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@peterschussheim
peterschussheim / LinkedList.js
Created March 6, 2017 15:03 — forked from klugjo/LinkedList.js
LinkedList ES6 Implementation
class LinkedList {
constructor() {
this.head = null;
this.tail = null;
this.count = 0;
}
get length() {
return this.count;
}