Skip to content

Instantly share code, notes, and snippets.

View HenrikJoreteg's full-sized avatar

Henrik Joreteg HenrikJoreteg

View GitHub Profile
@HenrikJoreteg
HenrikJoreteg / rollup-plugin-add-import.js
Created January 20, 2017 22:25
Simple rollup plugin to automatically add an import line
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\';'
@HenrikJoreteg
HenrikJoreteg / ajaxfileupload.js
Created April 26, 2012 19:47
AJAX file uploading using jQuery and XMLHttpRequest 2.0 and adding listener for progress updates
// grab your file object from a file input
$('#fileInput').change(function () {
sendFile(this.files[0]);
});
// can also be from a drag-from-desktop drop
$('dropZone')[0].ondrop = function (e) {
e.preventDefault();
sendFile(e.dataTransfer.files[0]);
};
@HenrikJoreteg
HenrikJoreteg / gumroad-analytics-api.js
Created April 24, 2015 20:50
Gumroad Sales Data "API"
// There's no way to retrieve detailed sales info from Gumroad.com through
// their official API.
// This bypasses that by posting a login form and then hitting an API only accessible
// via AJAX with a session cookie
// you just need USERNAME and PASSWORD set as environment variables where this is ran
var request = require('request');
module.exports = function (cb) {
@HenrikJoreteg
HenrikJoreteg / README.md
Last active September 20, 2021 01:36
Minimalist routing in Redux

Why would you want to do this? Because you often don't need more. It's nice to not have to think about your "router" as this big special thing.

Instead, with this approch, your app's current pathname is just another piece of state, just like anything else.

This also means that when doing server-side rendering of a redux app, you can just do:

var app = require('your/redux/app')
var React = require('react')
@HenrikJoreteg
HenrikJoreteg / native-virtual-dom.js
Last active December 18, 2020 15:34
Native virtual dom?
// 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 / extra-args-bundle.js
Created July 23, 2018 03:55
Light graphQL / redux-bundler example
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 / get-array-sorter.js
Created August 17, 2018 22:07
get an array sort function
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 August 9, 2018 15:44
lodash omit() in ~120 bytes lines instead of 2.5k
// 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
}
@HenrikJoreteg
HenrikJoreteg / data.json
Created August 3, 2018 16:03
map with heatmap
[
{
"location": {
"lat": 42.2152227,
"lng": -89.4553088
},
"weight": 4
},
{
"location": {
@HenrikJoreteg
HenrikJoreteg / index.html
Created October 26, 2017 21:25
WebComponent playground boilerplate (just edit and refresh)
<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 {