Skip to content

Instantly share code, notes, and snippets.

View doesdev's full-sized avatar
💻
prolly just making codes

Andrew Carpenter doesdev

💻
prolly just making codes
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Map vs For vs ForEach</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Test for string match</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@doesdev
doesdev / index.html
Created March 19, 2018 20:42
String.match(/x/i) vs toLowerCase() + indexOf() (http://jsbench.github.io/#2fa19472783ddeb4272f5d1d77dc1f94) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>String.match(/x/i) vs toLowerCase() + indexOf()</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@doesdev
doesdev / git-message-filtered-files-changed.js
Last active January 21, 2019 17:45
Find files changed in git commits with message matching a pattern
'use strict'
const repo = require('simple-git')(__dirname)
const rgx = /this|that/i
const start = (new Date('2014-12-29 00:00:00 -0500')).valueOf()
const sinceStart = (c) => (new Date(c.date)).valueOf() > start
const fileMap = {}
repo.log([], async (err, d) => {
const commits = d.all.filter((c) => c.message.match(rgx) && sinceStart(c))
@doesdev
doesdev / get-file-hash-and-size-in-stream.js
Created February 19, 2019 23:32
Get hash and filesize in stream
const fs = require('fs')
const crypto = require('crypto')
const getHashAndSize = (file, alg = 'sha1') => new Promise((resolve, reject) => {
let size = 0
const hasher = crypto.createHash(alg, { encoding: 'hex' })
const filestream = fs.createReadStream(file)
filestream.pipe(hasher)
filestream.on('data', (d) => { size += d.length })
@doesdev
doesdev / split-array-into-arrays-of-x-length.js
Last active August 27, 2019 13:53
Split Array into Arrays of X length
let srcAry = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
let splitBy = 3
let split = []
srcAry.forEach((val, i) => {
let ary = i % splitBy ? split[split.length - 1] : (split[split.length] = [])
ary.push(val)
})
console.log(split)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Prefix Comparison</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@doesdev
doesdev / pretty-print-single-level-array-of-objects.js
Created January 30, 2020 19:33
Pretty Print Single Level Array of Objects
const printer = (a) => `[\n ${a.map((o) => `{ ${Object.entries(o).map(([k, v]) => {
return `${k}: ${typeof v === 'string' ? `'${v}'` : v}`
}).join(', ')} }`).join(',\n ')}\n]`
@doesdev
doesdev / index.html
Last active March 29, 2020 01:08
Find Records Matching ID (https://jsbench.github.io/#3b50454e2196a88886eff74c223f132b) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Find Records Matching ID</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@doesdev
doesdev / talend-to-postman.js
Created July 6, 2023 19:04
Convert Talend API Tester JSON to Postman Collection(s) 2.1.0
const fs = require('fs')
const path = require('path')
const schema = 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json'
const remappers = {
'somesecurethinglikeapasswordoranauthtoken': '{{VARIABLE}}'
}
const processHeaders = (headers = []) => {
const authHeader = headers.find((h) => h.name.toLowerCase() === 'authorization')