Skip to content

Instantly share code, notes, and snippets.

@paitonic
paitonic / doGoodEstimate.js
Created April 27, 2020 16:41
doGoodEstimate.js
const GOOD_OVERALL_EFFORT_DAYS = 30;
const MAX_DAYS_PER_TASK = 4
const doGoodEstimate = (tasks) => {
let estimated = tasks.map((task) => {
task.effort = Math.floor((Math.random() * MAX_DAYS_PER_TASK) + 1);
return task;
});
const totalEffort = estimated.reduce((sum, task) => {
@paitonic
paitonic / useDebounced.js
Created April 23, 2020 06:42
useDebounced.js
const useDebounced = (func, dependencies, ms) => {
const timer = useRef(null);
useEffect(() => {
if (timer.current) {
clearTimeout(timer.current);
}
timer.current = setTimeout(() => {
func();
@paitonic
paitonic / to-camel-case.js
Last active April 18, 2020 14:24
to camel case
toCamelCase = (value) => value.toLowerCase().replace(/\s\w/, (match) => match.slice(1).toUpperCase());
// 'Blue Grey' -> 'blueGrey'
@paitonic
paitonic / material-design-palette.js
Last active April 18, 2020 14:24
Material Design Palette
// https://material.io/resources/color/#!/?view.left=0&view.right=0
toCamelCase = (value) => value.toLowerCase().replace(/\s\w/, (match) => match.slice(1).toUpperCase());
names = Array.from(document.querySelectorAll('.color-labels .color-label')).map((element => {
return toCamelCase(element.innerText)
}))
shades = Array.from(document.querySelectorAll('.align-bottom.ng-binding.ng-scope')).map((element => element.innerText))
palette = Array.from(document.querySelectorAll('.palette-container')).reduce((obj, palette, index) => {
@paitonic
paitonic / Remove-GitBranch.ps1
Last active February 14, 2020 12:30
Powershell script to remove git branches by pattern
function Remove-GitBranch {
# Example:
# Remove-GitBranch -regex feature # remove local branches matching regex pattern
# Remove-GitBranch -regex feature -origin # remove local & origin branches
param (
[string] $regex,
[switch] $origin # remove the origin branch?
)
@paitonic
paitonic / simulateKeyPress.js
Created November 1, 2019 19:47
simulateKeyPress
function keyboardEventFromText(text) {
return [...text].flatMap((letter) => {
return [
new KeyboardEvent('keydown', {key: letter}),
new KeyboardEvent('keypress', {key: letter}),
new InputEvent('input', {data: letter, inputType: 'insertText'}),
new KeyboardEvent('keyup', {key: letter}),
]
})
}
@paitonic
paitonic / chunk.js
Created August 24, 2019 04:49
chunk
function chunk(array, size) {
function partition(array, start, result=[]) {
if (array.length === 0) {
return result;
}
return partition(array.slice(start+size, array.length), start+size, [...result, array.slice(0, size)])
}
return partition(array, 0);
# javascript
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
@paitonic
paitonic / react-jest-enzyme.md
Created June 29, 2019 18:55
Setup Jest and Enzyme for React
@paitonic
paitonic / index.html
Created March 24, 2019 07:13
svg-charts.js
<html>
<head>
<title>SVG Charts</title>
</head>
<body>
<div id="svg-bar"></div>
<div id="svg-area"></div>
<div id="svg-line"></div>
<script src="svg-charts.js"></script>