git fetch upstream && git checkout master && git rebase upstream/master && git push origin master
View mround.ts
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
/** | |
* Rounds one number to the nearest integer multiple of another. | |
* @param value The number to round to the nearest integer multiple of another. | |
* @param factor The number to whose multiples value will be rounded. | |
* @example | |
* mround(10, 3); // 9 | |
* mround(-10, -3); // -9 | |
* mround(5, -2); // Error: Parameters of mround must have same signs (both positive or both negative) | |
*/ | |
export function mround(value: number, factor: number): number { |
View react-lazy-component.html
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>React Lazy Component Demo</title> | |
</head> | |
<body> | |
<div id="root">This is the React root</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.js" integrity="sha512-m7nhpWHotpucPI37I4lPovL28Bm2BhAMV8poF3F8Z9oOEZ3jlxGzkgvG0EMt1mVL1xydr1erlBbmN90js/ssUw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> |
View flat-map.ts
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
export const flatMap = <T, U>( | |
array: T[], | |
callback: (value: T, index: number, array: T[]) => U | |
): U[] => { | |
return Array.prototype.concat(...array.map(callback)); | |
}; |
View react-switch-component.js
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 | |
* |
View .vimrc
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 |
View sample.js
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; |
View interpolate.js
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; |
View make-cancelable.js
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) | |
); | |
}); |
View git-sync-masters.md
View move-props.js
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; |
NewerOlder