Skip to content

Instantly share code, notes, and snippets.

View joshuapbritz's full-sized avatar
🤓
Always Learning

Josh Britz joshuapbritz

🤓
Always Learning
View GitHub Profile
// This trick will make your image 30px wide and
// will automatically adjust the height of the
// image based on its aspect ratio. However, if
// the browser supports `object-fit`, the image
// will be made 30px by 30px and will size the
// image based on its aspect ratio
// (like background-size: cover)
img {
width: 30px;

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@joshuapbritz
joshuapbritz / IndexedDB101.js
Created September 10, 2018 09:40 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@joshuapbritz
joshuapbritz / QueryReader.js
Created November 23, 2017 06:38
Decode a Url Query String With JavaScript
function parseQuery(queryString) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}
function randomNumber() {
return 4 //Determined by dice roll. 100% guaranteed to be random
}
@joshuapbritz
joshuapbritz / url.js
Created November 8, 2017 14:22
A JavaScript function for constructing urls
function urlMaker(origin, path) {
var pl = path.length - 1;
var pathname = path.charAt(pl) === '/' ? path : path + '/';
pathname = pathname.charAt(0) === '/' ? pathname : '/' + pathname;
var url = origin + pathname;
return url;
}
//Usage