Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
var pubsub = {};
(function (q) {
var topics = {},
subUid = -1;
q.subscribe = function (topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
//https://developer.mozilla.org/en-US/docs/Web/Events/resize
;
(function() {
var throttle = function(type, name, obj_) {
var obj = obj_ || window;
var running = false;
var func = function() {
if (running) {
return;
}
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@johnloy
johnloy / bytesToSize.js
Created March 1, 2021 13:34 — forked from lanqy/bytesToSize.js
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@johnloy
johnloy / convert-seconds.js
Created March 28, 2021 12:56 — forked from martinbean/convert-seconds.js
Convert seconds to HH:MM:SS format in JavaScript.
new Date(seconds * 1000).toISOString().substr(11, 8)
@johnloy
johnloy / transformObj.js
Created October 18, 2021 16:45 — forked from juliarose/transformObj.js
Recursively transform key/values in object, including array values
/**
* Recursively transform key/values in object, including array values
*
* Also can act as a basic deep clone method
* @param {Object} obj - Object to transform
* @param {Object} [transforms={}] - Object containing transformation functions
* @param {Function} [transform.keys] - Function for transforming keys from 'obj'
* @param {Function} [transform.values] - Function for transforming values from 'obj'
* @param {Number} [level=0] - Level of recursion, passed as the 2nd argument to a transform function
* @returns {Object} Transformed object
@johnloy
johnloy / font-stacks.css
Created October 26, 2021 23:40 — forked from don1138/font-stacks.css
CSS Modern Font Stacks
/* Modern Font Stacks */
/* System */
font-family: system, -apple-system, ".SFNSText-Regular", "San Francisco", "Roboto", "Segoe UI", "Helvetica Neue", "Lucida Grande", sans-serif;
/* Times New Roman-based serif */
font-family: Cambria, "Hoefler Text", Utopia, "Liberation Serif", "Nimbus Roman No9 L Regular", Times, "Times New Roman", serif;
/* A modern Georgia-based serif */
font-family: Constantia, "Lucida Bright", Lucidabright, "Lucida Serif", Lucida, "DejaVu Serif", "Bitstream Vera Serif", "Liberation Serif", Georgia, serif;
@johnloy
johnloy / github.bash
Created February 4, 2022 16:52 — forked from igrigorik/github.bash
Open GitHub URL for current directory/repo...
alias gh="open \`git remote -v | grep git@github.com | grep fetch | head -1 | cut -f2 | cut -d' ' -f1 | sed -e's/:/\//' -e 's/git@/http:\/\//'\`"
@johnloy
johnloy / debounce.js
Created June 6, 2022 14:11 — forked from rpemberton/debounce.js
Debounce with requestAnimationFrame
// Useful for debouncing callbacks to mousemove, resize, scroll event listeners
function debounce(fn) {
let raf;
return (...args) => {
if (raf) {
console.log('debounced');
return;
}