Skip to content

Instantly share code, notes, and snippets.

⚡️
bam

Jo Colina jsmrcaga

⚡️
bam
Block or report user

Report or block jsmrcaga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jsmrcaga
jsmrcaga / version-args.js
Created May 1, 2019
A simple version reporter
View version-args.js
if (process.argv && process.argv.indexOf('-v') > -1) {
const { name, version } = require('./package.json');
return console.log(`${name} version ${version}`);
}
/*
Example:
node mystuff.js -v
> mystuff version 3.0.4
@jsmrcaga
jsmrcaga / webauthn.md
Last active Mar 7, 2019
WebAuthn API compilation
View webauthn.md

WebAuthn Protocol

Utility

ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer;

let challenge = ArrayBuffer.from('super hard challenge created in server');
let id = ArrayBuffer.from('id created in server')

@jsmrcaga
jsmrcaga / webauthn.md
Created Mar 7, 2019
WebAuthn API compilation
View webauthn.md

WebAuthn Protocol

Utility

ArrayBuffer.from = (string) => Uint8Array.from(string.split('').map(e => e.charCodeAt(0))).buffer;

let challenge = ArrayBuffer.from('super hard challenge created in server');
let id = ArrayBuffer.from('id created in server')

View sigint.js
// INSTRUCTIONS
/*
* 1) Run node sigint.js and call ctrl-c, then wait 1 second (for process to exit)
* Expected output: SIGINT 1
*
* 2) Run npm start (see end of file for example, which runs node sigint.js) and call ctrl-c, then wait 1 second (for process to exit)
* Expected output SIGINT 1
* Unexpected output SIGINT 2
*/
View csv-to-json.js
const fs = require('fs');
console.time('Reading CSV...');
let csv = fs.readFileSync('./rocket.csv', {encoding: 'utf8'});
console.timeEnd('Reading CSV...');
let lines = csv.split('\n');
let names = lines.splice(0,1)[0].split(';');
console.log('Got names', names.join(', '));
console.log('And', lines.length, 'lines');
@jsmrcaga
jsmrcaga / Git Magic
Created Dec 13, 2016
Command to auto rebase a branch from another.
View Git Magic
[alias]
magic = "!sh -c 'git checkout \"$1\" && git pull && git checkout \"$0\" && git rebase \"$1\"'"
@jsmrcaga
jsmrcaga / ClosingTabsTimes.js
Created Aug 18, 2016
a small script to get the time needed to close a tab
View ClosingTabsTimes.js
// Closing time with mouse, trackpad and keyboard
;(function(){
var begin = null;
var mouseMoved = false;
window.times = {
mouse: [],
keyboard: [],
trackpad: [],
};
@jsmrcaga
jsmrcaga / getElementsByAttributeName.js
Created Jul 30, 2016
Function to get all elements that have an attribute that starts with a given string
View getElementsByAttributeName.js
function getElementsByAttributeName(startsWith, type){
return Array.from(document.querySelectorAll(type || '*')).filter(function(el){
var ok = false;
Array.from(el.attributes).forEach( function(attr){
if(startsWith instanceof RegExp){
ok = attr.name.match(startsWith);
} else {
ok = attr.name.startsWith(startsWith);
}
});
@jsmrcaga
jsmrcaga / workshop-add.js
Created Jul 24, 2016
Add Workshop from console
View workshop-add.js
var s = document.createElement('script');
s.src = 'https://jocolina.tk/workshop/workshop.min.js';
document.body.appendChild(s);
@jsmrcaga
jsmrcaga / gist:29791e3594a4073ad3c6
Created Apr 5, 2015
JavaScript to get 500px photo URL (remember to always give credit to photographer)
View gist:29791e3594a4073ad3c6
//REMEMBER TO ALWAYS GIVE CREDIT TO THE PHOTOGRAPHER
//NOT INTENDED TO STEAL 500PX PHOTOS
//THEY ARE NOT PUBLIC PROPERTY AND SHOULD NOT BE USED FOR COMERCIAL PURPOSES
function getPhoto () {
// usage:
// function returns object with URL, author and title tags
// simply use getPhoto().URL, or .author or .title
// or store result in variable, var someVar = getPhoto()
// and access values in the same way
You can’t perform that action at this time.