This file contains hidden or 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 readOnDrop = (element, onRead) => { | |
element.addEventListener('dragover', ev => ev.preventDefault()) | |
element.addEventListener('drop', ev => { | |
ev.preventDefault() | |
const dt = ev.dataTransfer | |
const file = dt.files[0] | |
const reader = new FileReader() | |
reader.onload = event => onRead(event.target.result) | |
reader.readAsText(file) | |
}) |
This file contains hidden or 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
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem | |
# only enter the Common Name: your ip address or your domain name |
This file contains hidden or 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
// https://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array/6274381#6274381 | |
/** | |
* Shuffles array in place. ES6 version | |
* @param {Array} a items The array containing the items. | |
*/ | |
function shuffle(a) { | |
for (let i = a.length; i; i--) { | |
let j = Math.floor(Math.random() * i); | |
[a[i - 1], a[j]] = [a[j], a[i - 1]]; | |
} |
This file contains hidden or 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
function formatTime(seconds, format) { | |
var values = { | |
h: Math.floor(seconds / 3600), | |
m: Math.floor(seconds % 3600 / 60), | |
s: Math.round(seconds % 60), | |
} | |
var type | |
var value | |
return format.split(':') |
This file contains hidden or 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
git log --all --decorate --oneline --graph |
This file contains hidden or 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
/** | |
* https://github.com/react-bootstrap/react-bootstrap/blob/master/src/utils/createChainedFunction.js | |
* Safe chained function | |
* | |
* Will only create a new function if needed, | |
* otherwise will pass back existing functions or null. | |
*/ | |
export function chainFunctions(...funcs) { | |
return funcs | |
.filter(f => f != null) |
This file contains hidden or 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
var isNumber = (val) => /[0-9]/.test(val) | |
var isAlpha = (val) => /[a-z]/.test(val) | |
var isEmpty = (arr) => arr.length === 0 | |
var top = (stack) => stack[stack.length - 1] | |
var calculate = function(str) { | |
var i = 0 | |
var snum = [] | |
var sop = [] |
This file contains hidden or 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 dataURItoBlob = (dataURI) => { | |
// convert base64/URLEncoded data component to raw binary data held in a string | |
let byteString | |
if (dataURI.split(',')[0].indexOf('base64') >= 0) { | |
byteString = atob(dataURI.split(',')[1]) | |
} else { | |
byteString = unescape(dataURI.split(',')[1]) | |
} | |
// separate out the mime component | |
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0] |
This file contains hidden or 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 onPasetImage = (event, onLoadImageDataURI) => { | |
const items = (event.clipboardData || event.originalEvent.clipboardData).items | |
for (let index in items) { | |
const item = items[index] | |
if (item.kind === 'file') { | |
const blob = item.getAsFile() | |
const reader = new FileReader() | |
reader.onload = (event) => { | |
onLoadImageDataURI(event.target.result) | |
} |
This file contains hidden or 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
#/bin/bash | |
stat -f "%OLp %N" $@ |