Skip to content

Instantly share code, notes, and snippets.

View selbekk's full-sized avatar
👨
Working dad

Kristofer Giltvedt Selbekk selbekk

👨
Working dad
View GitHub Profile
@selbekk
selbekk / timeproxy_tagged_template_literal_example.js
Created April 26, 2018 16:49
Timeproxy with tagged template literals
import tp from 'timeproxy';
const REQUEST_TIMEOUT = tp`twenty seconds`;
const COOKIE_EXPIRY_TIME = tp`1 week`;
const DEBOUNCE_PERIOD = tp`.5 seconds`;
@selbekk
selbekk / calidation_simple_example.jsx
Created April 21, 2018 07:54
Calidation simple example
import { FormValidation } from 'calidation';
const config = {
username: {
isRequired: 'You need a username',
},
email: {
isRequired: 'We need your email',
isEmail: 'We need a valid email, too',
},
@selbekk
selbekk / time_sensitive_timeproxy_examples.js
Created April 20, 2018 19:17
Time sensitive timeproxy examples
import tp from 'timeproxy';
const SESSION_EXPIRES = tp.IN_THIRTY_SECONDS;
const OLD_POST_TIMESTAMP = tp.TWO_WEEKS_AGO;
@selbekk
selbekk / more_timeproxy_examples.js
Created April 20, 2018 18:12
More timeproxy examples
import tp from 'timeproxy';
const TIME_UNTIL_NEXT_PUSH = tp.ONE_WEEK_AND_A_DAY;
const SHOW_DONT_LEAVE_DELAY = tp.TWELVE_MINUTES_TWO_SECONDS;
const WOW = tp.NINE_WEEKS_TWELVE_DAYS_SEVEN_MINUTES_AND_HALF_A_SECOND;
@selbekk
selbekk / timeproxy_examples.js
Created April 20, 2018 18:05
Some nice and fancy new timeproxy examples
import tp from 'timeproxy';
const REQUEST_TIMEOUT = tp.TWENTY_SECONDS;
const COOKIE_EXPIRY_TIME = tp.A_WEEK;
const DEBOUNCE_PERIOD = tp.HALF_A_SECOND;
@selbekk
selbekk / constant_examples.js
Last active April 20, 2018 16:56
Some good ol' regular examples
const REQUEST_TIMEOUT = 1000 * 20;
const COOKIE_EXPIRY_TIME = 1000 * 60 * 60 * 24 * 7;
const DEBOUNCE_PERIOD = 500;
@selbekk
selbekk / registerServiceWorker.js
Created March 16, 2018 10:27
A service worker with refresh dispatching
import { showSnackbar } from './actions';
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
@selbekk
selbekk / action-utils.js
Created February 5, 2018 10:26
Action creator creators!
import Case from 'case';
export const createAction = name => ({
[Case.constant(name)]: Case.constant(name),
[Case.camel(name)]: payload => ({
type: Case.constant(name),
payload,
}),
});
export const createNetworkAction = name => ({
@selbekk
selbekk / action.sublime-snippet
Created August 21, 2017 11:38
Sublime snippet for action and matching action creator
<snippet>
<content><![CDATA[
export const ${1:ACTION_NAME} = '${1}';
export const ${1/(?<=[^\W_])_+([^\W_])|([^\W_]+)|_+/\U$1\L$2/g} = ${2:opts} => ({
type: ${1},${3:}
});
]]></content>
<tabTrigger>action</tabTrigger>
</snippet>
@selbekk
selbekk / server.js
Created August 18, 2017 12:39
Super simple server side rendering with React and styled-components
const express = require('express');
require('babel-register')({
ignore: /\/(build|node_modules|.svg)\//,
presets: ['env', 'react-app']
});
const universal = require('./universal');
const app = express();