Skip to content

Instantly share code, notes, and snippets.

View HenrikJoreteg's full-sized avatar

Henrik Joreteg HenrikJoreteg

View GitHub Profile
@HenrikJoreteg
HenrikJoreteg / persist-to-ls-redux-middleware.js
Created January 8, 2016 23:24
Example redux middleware
import { STAR_PERSON, MET_PERSON, UPDATE_NOTES, SET_URL } from '../constants/action-types'
import { LS_KEY } from '../constants/localstorage-keys'
import tryit from 'tryit'
import debounce from 'lodash.debounce'
const userPreferenceActions = [STAR_PERSON, MET_PERSON, UPDATE_NOTES]
function writeToLocalStorage (getState) {
let data = {
starred: {},
@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created October 22, 2010 21:20
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&')
.replace(/>/g,'>')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
@HenrikJoreteg
HenrikJoreteg / inbox.html
Created October 23, 2014 17:59
"view source" of Google Inbox
<html lang="en-US" jsl="$t t-Tkdr7Li1J_A;$x 0;" jsvs="true;'en-US';" jsan=
"t-Tkdr7Li1J_A,0.lang" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 25 March 2009), see www.w3.org" />
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Inbox &#8211; hjoreteg@gmail.com</title>
<link class="i1Vy9" href=
@HenrikJoreteg
HenrikJoreteg / run-on-main.js
Created January 26, 2017 05:34
serializable functions for running code in unknown context on the main thread
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 / switcheroo-blocked-case-reducer.js
Last active August 24, 2016 14:37
reducer pattern with blocks
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 February 16, 2016 17:31
Polyfill module with callback. Original idea credit: Ryan Florence
export default (cb) => {
ensurePromise(() => {
ensureFetch(cb)
})
}
const ensurePromise = (cb) => {
if (typeof Promise === 'undefined') {
require.ensure([], (require) => {
require('imports?this=>window!es6-promise')
@HenrikJoreteg
HenrikJoreteg / clientAndServerUtilFuncs.js
Created June 1, 2011 18:18
Solution for utility functions to be used with underscore.js as mixins or commonjs
/*
Building a module this way allows you to do this on the client:
<script src="underscore.js"></script>
<script src="myutils.js"></script>
Then use it in your code as children of '_' without polluting your global namespace.
_.myFunction();
@HenrikJoreteg
HenrikJoreteg / nodeconf_2011.md
Created May 6, 2011 18:50 — forked from guybrush/nodeconf_2011.md
a list of slides from nodeconf 2011
@HenrikJoreteg
HenrikJoreteg / postageApp.js
Created April 28, 2011 16:23
Example of using sending mail with PostageApp using fermata in node.js
var fermata = require('fermata'),
uuid = require('node-uuid');
var apiKey = 'YOUR_API_KEY'; // should probably be imported from an external keys file
var site = fermata.api({url: 'https://api.postageapp.com/v.1.0'});
exports.send = function (details, cb) {
site['send_message.json'].post(details, cb);
};
=text_shadow($color, $x, $y, $blur)
:text-shadow = $color $x $y #{$blur}px
=box_shadow($color, $x, $y, $blur)
:-webkit-box-shadow = $color $x $y #{$blur}px
:-moz-box-shadow = $color $x $y #{$blur}px
:box-shadow = $color $x $y #{$blur}px
=inner_shadow($color, $x, $y, $blur)
:box-shadow = inset $color $x $y #{$blur}px