Skip to content

Instantly share code, notes, and snippets.

View frontsideair's full-sized avatar

Fatih Altinok frontsideair

View GitHub Profile
@frontsideair
frontsideair / do-we-really-need-node_modules-or-npm.md
Created April 9, 2020 09:05
Do we really need `node_modules` or `npm`?

Do we really need node_modules or npm?

I remember thinking that the way we're doing JavaScript is complex but we don't have any choice. What we've been doing for the last few years is that we are downloading a lot of JavaScript modules from npm to ournode_modules folder and we transform and bundle it for browsers using webpack and babel. This was necessary because browsers didn't have support for new features, most importantly module support and sending a lot of separate files to the browser was inefficient, so we transformed and bundlead ahead-of-time.

Now the times are changing. Many popular browsers support the crucial features including module support and HTTP/2 makes it more efficient to send a bunch of files. But we're stuck with the old ways now, and we're paying the price for what made sense at the time. As it turns out putting al your JavaScript in one bundle is not that efficient either, since you're sending non essential code which makes it load and parse slower thus affecting the us

@frontsideair
frontsideair / form.js
Created March 12, 2018 11:04
Type-safe form validation
// @flow
import React, { Component } from "react"
import { isIP, isURL, isEmail, isPort } from "validator"
import { allValid, getErrors } from "./validation"
import { makeAPICall } from "./api"
// a flat data structure for viewing in the UI
type Inputs = {
hasAuth: boolean,
@frontsideair
frontsideair / keybase.md
Created December 17, 2017 19:59
Keybase proof

Keybase proof

I hereby claim:

  • I am frontsideair on github.
  • I am frontsideair (https://keybase.io/frontsideair) on keybase.
  • I have a public key ASAPGnaC_3WM2q986wv9RYI23GHLA7eJVZ11fbdqFt0ylwo

To claim this, I am signing this object:

@frontsideair
frontsideair / _rxjs-ajax.md
Last active March 30, 2017 08:35
esnextbin sketch

Enter the username of a Github user to get their full name. Request on keystroke with XHR cancellation instead of debounce, which results in less latency and better user experience. Very simple implementation with RxJS. The magic is the .switch operator.

See live on esnextbin, don't forget to open Network tab in DevTools to see cancellation.

@frontsideair
frontsideair / objects_and_closures.js
Created March 2, 2017 07:51
Objects and closures are (in some ways) the same thing! (Illustrated in ES6)
const obj = { foo: 'bar', baz: 'quux' } // let's define our object
const { foo, baz } = bar // the keys are now in the envorinment!
const hello = 'world' // hello is defined in our environment
const newObj = { hello } // and now it's captured in our object!
@frontsideair
frontsideair / comma-operator-push-pop.js
Created January 3, 2017 10:47
Simple implementation of push/pop with comma operator, function scope
const pop = (arr, tmp) => (tmp = arr.slice(0), tmp.pop(), tmp)
const push = (arr, item, tmp) => (tmp = arr.slice(0), tmp.push(item), tmp)
// Can you see why and how this works? Does it really? Can you guess if it's pure or impure?
// Does it modify any of its arguments, or pollute global scope?
@frontsideair
frontsideair / copy-no-flash-test.md
Last active February 7, 2017 07:21
Test case for copying test with native APIs. (Works on latest Chrome, Firefox, Safari.)

Test case for copying test with native APIs. (Works on latest Chrome, Firefox, Safari.)

made with esnextbin

@frontsideair
frontsideair / index.html
Last active February 7, 2017 07:23
RR4 isolated test case
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- test here: https://esnextb.in/?gist=7cba0a35afc77d49ebb2bf5b99e944f1 -->
</head>
<body>
<div id="app"></div>
</body>
@frontsideair
frontsideair / cycle-with-reducers.js
Created July 7, 2016 19:37
Cycle.js with reducer-like events
const Cycle = require('@cycle/core');
const {makeDOMDriver, div, button} = require('@cycle/dom');
const {Observable} = require('rx');
function intent({ DOM }) {
const incr$ = DOM
.select('.incr')
.events('click')
.map(() => prev => prev + 1);