Skip to content

Instantly share code, notes, and snippets.

View jsmrcaga's full-sized avatar

Jo Colina jsmrcaga

View GitHub Profile
@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 / 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 / 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