git fetch upstream && git checkout master && git rebase upstream/master && git push origin master
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* react-switch-component.js | |
* Copyright (c) 2018 marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
*/ | |
import { Children, createElement } from 'react'; | |
/** | |
* Switch Component | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright (C) 2009-2018 marlun78 | |
Permission is hereby granted, free of charge, to any person obtaining a copy of | |
this software and associated documentation files (the "Software"), to deal in | |
the Software without restriction, including without limitation the rights to | |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
of the Software, and to permit persons to whom the Software is furnished to do | |
so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filetype plugin indent on | |
syntax on | |
set number | |
set tabstop=4 | |
set shiftwidth=4 | |
set expandtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sample.js | |
// Samples a given number of characters from a given string. | |
// Example; | |
// sample('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 4); // Eg. 'uY7m' | |
function sample(characters, length) { | |
var result = ''; | |
for (var i = 0; i < length; i++) { | |
result += getRandomChar(characters); | |
} | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// interpolate.js | |
// Based on Crockford’s supplant (http://www.crockford.com/javascript/remedial.html) | |
// Example; | |
// interpolate('Hello {name}!', { name: 'Martin' }); // 'Hello Martin!' | |
// interpolate('Hello {0}!', ['Vanja']); // 'Hello Vanja!' | |
function interpolate(template, values) { | |
return template.replace(/\{([^{}]*)\}/g, function(match, key) { | |
const value = values[key]; | |
const type = typeof value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Angular $rootScope.Scope.$once | |
* Copyright (c) 2014 marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
*/ | |
$provide.decorator('$rootScope', function ($delegate) { | |
var Scope = $delegate.__proto__.constructor; | |
Scope.prototype.$once = function (name, listener) { | |
var deregister = this.$on(name, function () { | |
deregister(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just an idea, completely untested! | |
function makeCancelable(promise) { | |
let canceled = false; | |
const proxy = new Promise((resolve, reject) => { | |
promise.then( | |
(value) => canceled === false && resolve(value), | |
(error) => canceled === false && reject(error) | |
); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// const source = {name: 'Martin', age: 38}; | |
// const target = moveProps(/name/, source); | |
// console.log(source, target); => {age: 38}, {name: 'Martin'} | |
export default function moveProps(pattern, source, target = {}) { | |
return Object.keys(source).reduce((accumulator, key) => { | |
if (pattern.test(key)) { | |
accumulator[key] = source[key]; | |
delete source[key]; | |
} | |
return accumulator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Number.isFinite | |
* Copyright (c) 2014 marlun78 | |
* MIT License, https://gist.github.com/marlun78/bd0800cf5e8053ba9f83 | |
* | |
* Spec: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfinite | |
*/ | |
if (typeof Number.isFinite !== 'function') { | |
Number.isFinite = function isFinite(value) { | |
// 1. If Type(number) is not Number, return false. |