Skip to content

Instantly share code, notes, and snippets.

View smashingpat's full-sized avatar
🥞
Making pancakes happen

Patrick Gerritsen smashingpat

🥞
Making pancakes happen
View GitHub Profile
function getURLParameters(url) {
var result = {};
var searchIndex = url.indexOf("?");
if (searchIndex == -1) return result;
var pageUrl = url.substring(searchIndex + 1);
var urlVariables = pageUrl.split('&');
for (var i = 0; i < urlVariables.length; i++) {
var parameterName = urlVariables[i].split('=');
result[parameterName[0]] = parameterName[1];
import Promise from 'bluebird'
Promise.config({
warnings: false,
cancellation: true,
})
const convertJson = string => {
try {
return JSON.parse(string);
/**
* Calculate the offset in the duration of time ellapsed
*
* @param t time from 0 to 1 (start to end)
*/
const easing = (t) => t * t;
/**
* Scroll to the element with an animation
* @param {HTMLElement} element
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@smashingpat
smashingpat / example.js
Last active November 5, 2017 22:22
orchestrator for composing tasks
const { series, parallel } = require('./orchestrator.js');
const buildSync = () => 'this was build synchronously';
const buildAsync = () => Promise.resolve('this could have been made asyncronously');
const tasks = series(
series(buildAsync, buildAsync),
series(buildAsync, buildSync),
@smashingpat
smashingpat / .editorconfig
Last active February 9, 2018 17:49
simple prototype setup
root = true
[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SSE</title>
</head>
<body>
<script>
import { withTimer } from './with-timer'
withTimer(() => {
const c = document.createElement('canvas')
document.body.appendChild(c)
const cc = c.getContext('2d')
let hue = 0
return () => {
hue++
// Create the controller that sends a signal if
// an abort is requested by the api
const abortController = new AbortController();
// create a fetch, and pass the signal from the controller to
// the fetch options
const request = fetch('http://my-awesome-site.com/api/awesome', {
signal: abortController.signal,
});
@smashingpat
smashingpat / action-types.ts
Created October 23, 2018 11:29
Typescript Redux actionTypes
import { Dispatch } from 'redux';
type StoreState = any; // preferable this should be the real Type of the store
/** Default action with just the type */
interface Action<T extends string> {
readonly type: T;
}
/** Action extended with a payload that could be any value, used for the reducer */