Skip to content

Instantly share code, notes, and snippets.

View jsmrcaga's full-sized avatar

Jo Colina jsmrcaga

View GitHub Profile
@jsmrcaga
jsmrcaga / gist:29791e3594a4073ad3c6
Created April 5, 2015 11:56
JavaScript to get 500px photo URL (remember to always give credit to photographer)
//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
@jsmrcaga
jsmrcaga / workshop-add.js
Created July 24, 2016 11:05
Add Workshop from console
var s = document.createElement('script');
s.src = 'https://jocolina.tk/workshop/workshop.min.js';
document.body.appendChild(s);
@jsmrcaga
jsmrcaga / getElementsByAttributeName.js
Created July 30, 2016 10:39
Function to get all elements that have an attribute that starts with a given string
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 / ClosingTabsTimes.js
Created August 18, 2016 10:18
a small script to get the time needed to close a tab
// Closing time with mouse, trackpad and keyboard
;(function(){
var begin = null;
var mouseMoved = false;
window.times = {
mouse: [],
keyboard: [],
trackpad: [],
};
@jsmrcaga
jsmrcaga / Git Magic
Created December 13, 2016 13:34
Command to auto rebase a branch from another.
[alias]
magic = "!sh -c 'git checkout \"$1\" && git pull && git checkout \"$0\" && git rebase \"$1\"'"
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');
// 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
*/
@jsmrcaga
jsmrcaga / webauthn.md
Created March 7, 2019 08:21
WebAuthn API compilation

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
Last active March 7, 2019 08:42
WebAuthn API compilation

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 / version-args.js
Created May 1, 2019 05:09
A simple version reporter
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