Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am benadamstyles on github.
  • I am benadamstyles (https://keybase.io/benadamstyles) on keybase.
  • I have a public key ASCoqtUtnEKNadbubzwnDKTw-1hG6Da4ULe2g2-GU-wgZgo

To claim this, I am signing this object:

@benadamstyles
benadamstyles / rapt-example-1.js
Last active February 18, 2018 18:25
Examples for Rapt Medium story
import {Map} from 'immutable'
// without Rapt
const processUser = user => {
log(user)
let userMap = Map(user)
if (emailHasBeenVerified) {
userMap = userMap.set('verified', true)
}
syncWithServer(userMap)
@benadamstyles
benadamstyles / flow-utility-type-functions.js
Last active September 24, 2017 16:21
Flow Utility Type Functions
// Below are some useful Flow utility type functions, some I've written and some I've found on the web.
// All contributions welcome!
// Extracting a data type from a maybe type, e.g. getting `string` from `?string`
type _ExtractFromMaybe<T, M: ?T> = T
export type ExtractFromMaybe<M> = _ExtractFromMaybe<*, M>
// FROM https://hackernoon.com/redux-flow-type-getting-the-maximum-benefit-from-the-fewest-key-strokes-5c006c54ec87
// Extracting the type of a function's return value
type _ExtractReturn<R, F: (...args: any[]) => R> = R

Keybase proof

I hereby claim:

  • I am leeds-ebooks on github.
  • I am benstyles (https://keybase.io/benstyles) on keybase.
  • I have a public key whose fingerprint is 9551 FCA3 0E1C E683 6ADF 9001 5FFB B35C 8695 F553

To claim this, I am signing this object:

var uuidCount = 0
function uuid() {
return uuidCount++
}
function arrayFrom(arrayLike) {
var array = []
for (var i = 0; i < arrayLike.length; i++) {
array.push(arrayLike[i])
@benadamstyles
benadamstyles / CreateCrosslink.jsx
Created November 23, 2015 16:24
InDesign: CreateCrosslink
@benadamstyles
benadamstyles / CreateHyperlinkDestinationsFromParagraphStyles.jsx
Created November 23, 2015 16:23
InDesign: CreateHyperlinkDestinationsFromParagraphStyles
var uuidCount = 0
function uuid() {
return uuidCount++
}
function process(doc, paraStyle) {
app.findTextPreferences = NothingEnum.nothing
app.changeTextPreferences = NothingEnum.nothing
const keypaths = [];
const values = [];
const mapper = (input, keypath = '') => {
if (!_.isObject(input)) {
keypaths.push(keypath);
values.push(input);
} else {
const isArray = Array.isArray(input);
@benadamstyles
benadamstyles / macros.js
Last active August 29, 2015 14:24
Sweet.js macros
// for rebuilding an array without reassignment
macro rebuild {
rule {$oldArr $newArr} => {
$oldArr.length = 0
$oldArr.push.apply($oldArr, $newArr)
}
}
rebuild arr newArr;
@benadamstyles
benadamstyles / smoothNativeScroll.js
Created June 21, 2015 16:18
Smooth Native Scroll
smoothScroll = speed => {
var endPos, comp, step;
const goScroll = function goScroll() {
scrollBy(0, step);
if (comp(window.scrollY, endPos)) {
window.requestAnimationFrame(goScroll);
}
},
runner = end => {
endPos = end;