validation types work like this:
[+]typename[(arg,[arg,...])]
The +
in the beginning makes it required
any arguments applied will be passed to that type's validation function
const timespanToMs=(timeSpan)=>{ | |
let lut={'':1, ms:1, s:1000, m:60000, h:3600000, d: 86400000, w:604800000, y:31556952000 } | |
let ms=(`${timeSpan}`.match(/\d+[ywdhms]{0,2}\s?/g)).reduce((a,s)=>{ | |
let [,v,m] =s.match(/(\d+)([ywdhms]{0,2})/) | |
return a + (v * lut[m]) | |
},0) | |
return ms | |
} | |
let passTests=[ |
const Catch = async (promise, errorHandler) => { | |
if (promise instanceof Promise) { | |
try { | |
let returnValue = await promise | |
return returnValue | |
} catch (e) { | |
if (typeof errorHandler === 'function') return errorHandler(e) | |
return errorHandler | |
} | |
} |
# ... | |
source ~/scriptfinder ss scripts |
function regexMatch(regex, str){ | |
let m; | |
let g=[] | |
while ((m = regex.exec(str)) !== null) { | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++; | |
} | |
g.push({...m.groups}) | |
} |
I needed a tool to tell me the first time a certain string appeared in the git-history of a file. It was a node package, and I wanted to find out why it first got included.
node git.find.first.js <path-to-file> <search-term> [--open]
--open
will open a github-url for that commit if you have a github repository
Vue.component("async", { | |
props: { | |
url: { type: String, default: "", required: true }, | |
params: { type: Object, default: () => ({}) } | |
}, | |
data() { | |
return { | |
pending: true, | |
error: false, | |
data: null |
#!/bin/bash | |
clear | |
fileList=$(git diff --diff-filter=d --cached --name-only | grep -E '\.(js|vue)$') | |
if [ ${#fileList} -lt 1 ]; then | |
echo -e "You have no staged .js or .vue files to test\n" | |
exit | |
fi | |
npx eslint ${fileList[*]} "$@" | |
if [ $? -ne 0 ]; then | |
echo -e "\nPlease fix the above linting issues before committing.\n" |
const SECONDS = { | |
MINUTE: 60, | |
HOUR: 3600, | |
DAY: 86400, | |
WEEK: 604800, | |
MONTH: 2630016, //30.44 day month average | |
YEAR: 31557600, //based on 365.25 days per year | |
} | |
class DForm { |
import { serve } from "https://deno.land/[email protected]/http/server.ts"; | |
const s = serve({ port: 8000 }); | |
console.log("http://localhost:8000/"); | |
let c=0 | |
let st=null | |
for await (const req of s) { | |
if(st===null)st=Date.now() | |
let sd=(Date.now()-st)/1000 | |
let rps=(c+1)/sd | |
req.respond({ body: `Hello World\nRequests Handled:${c++}\nSeconds:${sd}\nRPS: ${rps}` }); |