Skip to content

Instantly share code, notes, and snippets.

Henrik Joreteg HenrikJoreteg

Block or report user

Report or block HenrikJoreteg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@HenrikJoreteg
HenrikJoreteg / get-array-sorter.js
Created Aug 17, 2018
get an array sort function
View get-array-sorter.js
export default (property, ascOrDesc = 'asc') => (a, b) => {
const asc = ascOrDesc === 'asc'
const valA = a[property]
const valB = b[property]
if (valA > valB) {
return asc ? 1 : -1
}
if (valB > valA) {
return asc ? -1 : 1
}
@HenrikJoreteg
HenrikJoreteg / omit.js
Last active Aug 9, 2018
lodash omit() in ~120 bytes lines instead of 2.5k
View omit.js
// compare to https://bundlephobia.com/result?p=lodash.omit@4.5.0
export default (obj, keys = []) => {
const copy = Object.assign({}, obj)
keys.forEach(key => {
delete copy[key]
})
return copy
}
View data.json
[
{
"location": {
"lat": 42.2152227,
"lng": -89.4553088
},
"weight": 4
},
{
"location": {
@HenrikJoreteg
HenrikJoreteg / extra-args-bundle.js
Created Jul 23, 2018
Light graphQL / redux-bundler example
View extra-args-bundle.js
import gqlFetch from '../helpers/gql-fetch'
import config from '../config'
export default {
name: 'extraArgs',
getExtraArgs: store => {
return {
gqlFetch: gqlFetch({
apiUrl: config.apiUrl,
getToken: () => store.selectAuthToken(),
@HenrikJoreteg
HenrikJoreteg / index.html
Created Oct 26, 2017
WebComponent playground boilerplate (just edit and refresh)
View index.html
<html>
<head>
<style>
body {
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
color: gray;
}
badass-list-thing {
View native-virtual-dom.js
// what if this was something browsers just gave us?
const { vdom } = document;
// this is same idea as React.createElement
// or any of the other similar appraoches
const newVirtualDom = vdom('div', {className: 'some-class'}, [
vdom('p', null, 'hi')
])
// if preferred, someone could easily use JSX and precompile it
@HenrikJoreteg
HenrikJoreteg / run-on-main.js
Created Jan 26, 2017
serializable functions for running code in unknown context on the main thread
View run-on-main.js
export default (fn, ...args) => {
if (typeof window !== 'undefined') {
fn(...args)
} else {
const last = args.slice(-1)[0]
let argString = ''
if (typeof last !== 'undefined') {
argString = args.reduce((accum, val, index) => {
const type = typeof val
const isLast = index === args.length - 1
@HenrikJoreteg
HenrikJoreteg / rollup-plugin-add-import.js
Created Jan 20, 2017
Simple rollup plugin to automatically add an import line
View rollup-plugin-add-import.js
import { createFilter } from 'rollup-pluginutils'
function assign (target, source) {
Object.keys(source).forEach((key) => {
target[key] = source[key]
})
return target
}
const DEFAULT_HEADER = 'import React from \'react\';'
View switcheroo-blocked-case-reducer.js
import { DO_THING, DO_OTHER_THING, SOMETHING_ELSE } from './actions'
export default (state, { type, payload }) => {
switch (type) {
case DO_THING: {
// by using blocks in our case statements we can create locally scoped vars
// and returning early keeps things readable
const scopedVariable = payload.thing
return Object.assign({}, state, {do: scopedVariable})
}
@HenrikJoreteg
HenrikJoreteg / polyfill.js
Created Feb 16, 2016
Polyfill module with callback. Original idea credit: Ryan Florence
View polyfill.js
export default (cb) => {
ensurePromise(() => {
ensureFetch(cb)
})
}
const ensurePromise = (cb) => {
if (typeof Promise === 'undefined') {
require.ensure([], (require) => {
require('imports?this=>window!es6-promise')
You can’t perform that action at this time.