Skip to content

Instantly share code, notes, and snippets.

@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";
@justinwoo
justinwoo / Counter.js
Last active September 29, 2022 08:29
React 0.14 function components and a fake Elm Architecture written with RxJS subjects (instead of Signal.mailbox). Inspired by Dan's tweet: https://twitter.com/dan_abramov/status/648517117176745984 ((i guess this is pretty ugly so please don't take it super seriously))
import React from 'react';
/**
* Counter.js
*
* exposes:
* init
* update
* view
*/
{-# LANGUAGE DataKinds, TypeOperators, KindSignatures, GADTs, StandaloneDeriving, ScopedTypeVariables, Rank2Types, PolyKinds, DeriveTraversable #-}
import Unsafe.Coerce
import GHC.TypeLits
import Data.Type.Equality
import Data.Proxy
import Prelude hiding (drop)
import Data.Foldable
data Tree :: Nat -> Nat -> * -> * where
Bin :: a -> Tree i j a -> Tree j k a -> Tree k (1 + j + k) a
@staltz
staltz / slim-cycle-core.js
Created September 22, 2015 12:35
Cycle.js without sanity checks and comments in a single file. Don't use this, use normal Cycle.js. :-)
let Rx = require(`rx`)
function makeRequestProxies(drivers) {
let requestProxies = {}
for (let name in drivers) {
if (drivers.hasOwnProperty(name)) {
requestProxies[name] = new Rx.ReplaySubject(1)
}
}
return requestProxies
@gaearon
gaearon / slim-redux.js
Last active December 3, 2024 06:34
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@paulirish
paulirish / what-forces-layout.md
Last active May 14, 2025 12:58
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@paf31
paf31 / ListT.purs
Created August 27, 2015 04:03
Stack-safe ListT in PureScript using FreeT
module Control.Monad.List.Trans where
import Prelude
import Data.List
import Data.Either
import Control.Apply
import Control.Bind
import Control.Monad.Eff
@rauschma
rauschma / regexp_es6.md
Last active April 16, 2018 19:43
Regular expressions in ES6

Methods of regular expressions:

Flags Start matching Anchored to Result if match No match re.lastIndex
exec() 0 Match object null unchanged
/g re.lastIndex Match object null index after match
/y re.lastIndex re.lastIndex Match object null index after match
/gy re.lastIndex re.lastIndex Match object null index after match
test() (Any) (like exec()) (like exec()) true false (like exec())
@Falconerd
Falconerd / gulpfile.js
Last active April 10, 2019 17:16
Gulp + Watchify + Babelify + BrowserSync
/**
* This gulpfile will copy static libraries and a index.html file as well as
* merge, babelify and uglify the rest of the javascript project.
*
* TODO:
* - Separate media, libs and src with different watchers.
* - Media and libs should only be copied to dist if they are different sizes.
*
* The expected project is to be laid out as such:
*
@chpatrick
chpatrick / lazy-parsers.hs
Last active December 18, 2017 00:39
Regex-style lazy parsers
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, PatternSynonyms, RankNTypes #-}
import Control.Applicative
import Control.Monad.Codensity
import Control.Monad.Trans
import Text.Parser.Combinators
import Text.Parser.Char
import qualified Data.Attoparsec.ByteString.Char8 as AP