Skip to content

Instantly share code, notes, and snippets.

View monkeymars's full-sized avatar
🏠
Working from home

Gery Wibowo monkeymars

🏠
Working from home
View GitHub Profile
@monkeymars
monkeymars / mobile-dimensions-in-px.js
Created February 2, 2022 16:55 — forked from kale-stew/mobile-dimensions-in-px.js
Popular mobile device screen dimensions, as an array of objects in a single file
// Popular Mobile Device Dimensions in px
// taken from https://mediag.com/blog/popular-screen-resolutions-designing-for-all/
export default [
{
// iPhone XR
height: '828px',
width: '1792px'
},
{

update object

var state = {
    id: 1,
    points: 100,
    name: "Goran"
};

var newState = {
@monkeymars
monkeymars / slugify.js
Created February 9, 2020 16:28 — forked from codeguy/slugify.js
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@monkeymars
monkeymars / promiseCatchWithAwait.js
Created December 16, 2019 13:39 — forked from dbayarchyk/promiseCatchWithAwait.js
Async/await without try/catch in JavaScript
async function fetchAndUpdatePosts() {
const posts = await fetchPosts().catch(() => {
console.log('error in fetching posts');
});
if (posts) {
doSomethingWithPosts(posts);
}
}
@monkeymars
monkeymars / axios-catch-error.js
Created October 16, 2019 10:49 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@monkeymars
monkeymars / cloudSettings
Last active December 18, 2022 03:33
vscode-settings
{"lastUpload":"2022-12-18T03:32:45.855Z","extensionVersion":"v3.4.3"}
@monkeymars
monkeymars / workbox.md
Created January 16, 2019 10:19 — forked from addyosmani/workbox.md
Workbox recipes

Workbox runtime caching recipes

Your Service Worker script will need to import in Workbox and initialize it before calling any of the routes documented in this write-up, similar to the below:

importScripts('workbox-sw.prod.v1.3.0.js');
const workbox = new WorkboxSW();

// Placeholder array populated automatically by workboxBuild.injectManifest()
@monkeymars
monkeymars / media-query.css
Created January 15, 2019 11:04 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
<?php
/**
* Return the coefficient of two items based on Jaccard index
* http://en.wikipedia.org/wiki/Jaccard_index
*
* Example:
*
* $tags1 = "code, php, jaccard, test, items";
* $tags2 = "test, code";