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 jsonData = JSON.parse(responseBody); | |
const payload = jsonData.id_token.split('.')[1]; // Assuming the JWT is in id_token | |
const parsed = JSON.parse(atob(payload)); | |
pm.environment.set('user_id', parsed.user_id); // Assuming user_id is in the payload |
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 | |
# $1 - a folder containing multiple git repos; i.e. ~/work | |
# The Mac way to get number of logical cores | |
# You can run more parallel processes than the number of cores, | |
# but at some point the process will slow to a crawl | |
cores=$( sysctl -n hw.ncpu ) | |
# list all paths below $1 in single column, and pipe to xargs: | |
# ls -d1 $1/*/ | | |
# Run a bash command on each path, using $cores number of processes: | |
# xargs -I % -n 1 -P $cores bash --login -c |
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 toDigits (str = '') { | |
// replace every (/g) non-digit (\D) with the character code (charCodeAt) for that non-digit. | |
return str.replace(/\D/g, nondigit => nondigit.charCodeAt(0) ); | |
} | |
console.log(toDigits('A1b2C3-4'); |
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 x100(nStr) { | |
function replacer(match, p1, p2) { | |
return `${`${p1}${p2.padEnd(2, '0').substr(0,2)}`.padStart(1, '0')}.${p2.padEnd(2, '0').substr(2)}`; | |
} | |
return String(nStr) // just in case | |
.replace(/(\d*)\.?(\d*)/, replacer); | |
} | |
const tests = [ | |
'0.00', |
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 | |
# $1 = # of seconds | |
# $@ = What to print after "Waiting n seconds" | |
countdown() { | |
secs=$1 | |
shift | |
msg=$@ | |
while [ $secs -gt 0 ] | |
do | |
printf "\r\033[KWaiting %.d seconds $msg" $((secs--)) |
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
// You could play around with allowed inputs | |
import Moment from 'moment'; | |
import { extendMoment } from 'moment-range'; | |
const moment = extendMoment(Moment); | |
function excludesTime(start, end, when) { | |
let startTime = moment(start, 'HH:mm'); | |
const endTime = moment(end, 'HH:mm'); |
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
// Limited to max 16 digits | |
function randomDigits(digits) { | |
return parseInt( | |
crypto | |
.randomBytes(Math.floor(digits/2)) | |
.toString('hex') | |
,16) | |
.toString(10) | |
.substr(-digits); | |
} |
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
return ( (new Date( new Date( (new Date()).toISOString().slice(0,10) ) - 1 ) ).toISOString().slice(0,10) ); |
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
#!env jjs | |
// jjs filesize.js -- config.txt | |
// Sample config.txt: | |
// http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf | |
var Files = Java.type('java.nio.file.Files'); | |
var Paths = Java.type('java.nio.file.Paths'); | |
var URL = Java.type('java.net.URL'); | |
function getSize(url) { |
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
// given an array of n integers (example: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113] ), | |
// remove all odd numbers, leaving only the even numbers. | |
const x = [ | |
-Math.MAX_VALUE, -113, -112, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -Math.MIN_VALUE, -0, | |
0, Math.MIN_VALUE, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 112, 113, Math.MAX_VALUE | |
]; | |
console.log(x.filter( n => { return ( n % 2 === 0); })); |