Skip to content

Instantly share code, notes, and snippets.

View jupegarnica's full-sized avatar
🔍

Garn jupegarnica

🔍
View GitHub Profile
const inBrowser = typeof window !== 'undefined'
const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase()
const UA = inBrowser && window.navigator.userAgent.toLowerCase()
const isIE = UA && /msie|trident/.test(UA)
const isIE9 = UA && UA.indexOf('msie 9.0') > 0
const isEdge = UA && UA.indexOf('edge/') > 0
const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android')
const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios')
export const cacheAsync = fn => {
const cached = {};
return async (...args) => {
const key = args.join('-');
if (cached[key] === undefined) {
cached[key] = await fn(...args);
}
return cached[key];
export const debounce = (fn, delay = 0) => {
let id;
return (...args) => {
if (id) {
clearTimeout(id);
}
id = setTimeout(fn, delay, ...args);
return id;
};
};
https://unsplash.it/200/200
###
https://picsum.photos/200/300
###
https://unavatar.now.sh/
https://unsplash.it/200/200
###
https://picsum.photos/200/300
function takeOverConsole(){
var console = window.console
if (!console) return
function intercept(method){
var original = console[method]
console[method] = function(){
// do sneaky stuff
if (original.apply){
// Do this for normal browsers
original.apply(console, arguments)
.grid {
display: grid;
grid-template-columns: repeat(7, minmax(0, 1fr));
}
wget -O /tmp/wallpaper.jpg https://unsplash.it/2560/1440/?random
gsettings set org.gnome.desktop.background picture-uri file:///tmp/wallpaper.jpg
const toCamelCase = str => {
let s =
str &&
str
.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(x => x.slice(0, 1).toUpperCase() + x.slice(1).toLowerCase())
.join('');
return s.slice(0, 1).toLowerCase() + s.slice(1);
};
toCamelCase('some_database_field_name'); // 'someDatabaseFieldName'