Skip to content

Instantly share code, notes, and snippets.

@alexrqs
alexrqs / videojs-plugin-events-logger.js
Last active November 9, 2023 10:09
VideoJS event list
// The events are from https://www.w3.org/TR/html5/semantics-embedded-content.html#media-elements-event-summary
import videojs from 'video.js'
const Plugin = videojs.getPlugin('plugin')
const EVENTS = [
'loadstart',
'progress',
'suspend',
'abort',
'error',
@alexrqs
alexrqs / nodejsTiming.js
Last active July 16, 2023 17:48
Log nodejs hrtime to measure time of a process or function for nodejs
const start = new Date()
const hrstart = process.hrtime()
const simulateTime = 500
setTimeout(function(argument) {
// execution time simulated with setTimeout function
const end = new Date() - start
const hrend = process.hrtime(hrstart)
console.info('Execution time: %dms', end)
const crypto = require('crypto');
const { publicKey, privateKey } = crypto.generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
},
privateKeyEncoding: {
type: 'pkcs8',
@alexrqs
alexrqs / avoid-dups.sh
Created May 27, 2023 19:35
avoid/remove duplicates from zsh history
code ~/.zshrc
# add => "setopt HIST_IGNORE_ALL_DUPS"
omz reload
cp $HISTFILE ${HISTFILE}.backup
awk '!a[$0]++' ${HISTFILE}.backup > $HISTFILE
@alexrqs
alexrqs / update-tags.md
Last active February 5, 2020 18:30
Update github tags with new commits
Create a branch with the tag
	git branch {tagname}-branch {tagname}
	git checkout {tagname}-branch
Include the fix manually if it's just a change ....
	git add .
	git ci -m "Fix included" # or cherry-pick the commit, whatever is easier
	git cherry-pick {num_commit}
@alexrqs
alexrqs / .circleci_config.yml
Created October 1, 2019 18:42
JS project should have (active development)
aliases:
- &restore-yarn-cache
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- &save-yarn-cache
paths:
- node_modules
@alexrqs
alexrqs / loadUniqueScripts.js
Last active September 4, 2019 12:39
How to load only one time even if the script is required multiple times, and how to check or detect if the script is loaded.
// keep track of the loaded libraries
const loadedLibraries = []
function registerLibraryLoaded(id) {
// record the libs only if the array doesn't contain the same already
if (loadedLibraries.indexOf(id) < 0) {
loadedLibraries.push(id)
}
}
@alexrqs
alexrqs / rgbtostring.js
Created August 31, 2019 07:00
RGB function with params per color to string
const normalColor = number => number > 255 ? 255 : number < 0 ? 0 : number
const toHEX = color => Number(normalColor(color)).toString(16).toUpperCase()
const normalHEX = hex => ((hexi = toHEX(hex)) => hexi.toString().length < 2 ? '0' + hexi : hexi)()
const rgb = (r,g,b) => normalHEX(r) + normalHEX(g) + normalHEX(b)
Test.assertEquals(rgb(0, 0, 0), '000000')
Test.assertEquals(rgb(0, 0, -20), '000000')
Test.assertEquals(rgb(300,255,255), 'FFFFFF')
Test.assertEquals(rgb(173,255,47), 'ADFF2F')
@alexrqs
alexrqs / bin.js
Created August 26, 2019 16:40
spawn child process with colors nodejs
#!/usr/bin/env node
if (process.platform == 'win32') {
process.exit(0)
}
const { spawn } = require('child_process')
const packages = ['webpack']
const yarnAdd = ['yarn', 'add', '-D']
@alexrqs
alexrqs / .npmrc.sh
Last active July 1, 2019 21:35
npm token use
export NPM_TOKEN="00000000-0000-0000-0000-000000000000"
# .npmrc
package-lock=false
//registry.npmjs.org/:_authToken=${NPM_TOKEN}