var state = {
id: 1,
points: 100,
name: "Goran"
};
var newState = {
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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' | |
| }, | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function fetchAndUpdatePosts() { | |
| const posts = await fetchPosts().catch(() => { | |
| console.log('error in fetching posts'); | |
| }); | |
| if (posts) { | |
| doSomethingWithPosts(posts); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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 😨 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {"lastUpload":"2022-12-18T03:32:45.855Z","extensionVersion":"v3.4.3"} |
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()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ##Device = Desktops | |
| ##Screen = 1281px to higher resolution desktops | |
| */ | |
| @media (min-width: 1281px) { | |
| //CSS | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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"; |