Skip to content

Instantly share code, notes, and snippets.

View thedelk's full-sized avatar
💀
Probably refactoring.

Ryan Delk thedelk

💀
Probably refactoring.
View GitHub Profile
@ef4
ef4 / examples.md
Last active May 23, 2024 04:31
Webpack 5 Node Polyfills Upgrade Cheatsheet

Webpack 5 Node Polyfills Upgrade Cheatsheet

Webpack 4 automatically polyfilled many Node APIs in the browser. This was not a great system, because it could lead to surprisingly giant libraries getting pulled into your app by accident, and it gave you no control over the exact versions of the polyfills you were using.

So Webpack 5 removed this functionality. That means you need to make changes if you were relying on those polyfills. This is a quick reference for how to replace the most common patterns.

List of polyfill packages that were used in webpack 4

For each automatically-polyfilled node package name on the left, this shows the name of the NPM package that was used to polyfill it on the right. Under webpack 5 you can manually install these packages and use them via resolve.fallback.

@codenamezjames
codenamezjames / boot-vuex-persistence.js
Created May 18, 2020 18:07
Vuex persist ssr auth
import VuexPersist from 'vuex-persist'
import Cookies from 'js-cookie'
export default ({ store, ssrContext }) => {
// Cookie Store for user/auth (ssr ajax auth)
const cookieModules = ['user']
const startsWithCookieRegex = new RegExp(`^(${cookieModules.join('|')})/`)
new VuexPersist({
filter: mutation => startsWithCookieRegex.test(mutation.type),
restoreState: key => {
try {
/**
* -------------------------------------------------------------
* 1. Removing Duplicates from an array
* -------------------------------------------------------------
* @description We make use of sets and create an array from a Set. Sets don't allow duplicates
* @returns [1,2,3,1,2,3] -> [1,2,3]
*/
const duplicates = [1, 2, 3, 1, 2, 3];
const removedDuplicates = Array.from(new Set(duplicates));
@uladzislau-stuk
uladzislau-stuk / Readme.md
Last active March 14, 2024 08:25
The art of naming variables

The art of naming variables

Arrays

// bad
const fruit = ['apple', 'banana', 'cucumber']

// okay
const fruitArr = ['apple', 'banana', 'cucumber']

// good
@yann-yinn
yann-yinn / ApolloQuery.vue
Last active March 21, 2024 09:28
Use "apollo-client" package with Vue.js, without "vue-apollo"
<!--
If you really like to use apolloClient declaratively, here is a naive implementation
of a custom 'ApolloQuery' component
-->
<template>
<div>
<slot name="result" :result="this.result" />
</div>
</template>
@anthonybrown
anthonybrown / px-rem-cheat-sheet.css
Created September 5, 2018 14:05 — forked from glueckpress/px-rem-cheat-sheet.css
Cheat sheet for rem-calculations based upon 14px and 16px.
/*! = $rembase: 14px
--------------------------------------------------------------
* hmtl { font-size: 87.5%; }
* body { font-size: 14px; font-size: 1rem; line-height: 1; }
* 4px 0.28571429rem
* 8px 0.571428571rem
* 12px 0.857142857rem
* 13px 0.928571429rem
* 14px 1rem
* 16px 1.142857143rem
@jeromecoupe
jeromecoupe / webstoemp-gulpfile.js
Last active January 21, 2024 16:28
Gulp 4 sample gulpfile.js. For a full explanation, have a look at https://www.webstoemp.com/blog/switching-to-gulp4/
"use strict";
// Load plugins
const autoprefixer = require("autoprefixer");
const browsersync = require("browser-sync").create();
const cp = require("child_process");
const cssnano = require("cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const gulp = require("gulp");
@JacobBennett
JacobBennett / blog.md
Last active June 7, 2024 17:42
Clean up your Vue modules with ES6 Arrow Functions

Recently when refactoring a Vue 1.0 application, I utilized ES6 arrow functions to clean up the code and make things a bit more consistent before updating to Vue 2.0. Along the way I made a few mistakes and wanted to share the lessons I learned as well as offer a few conventions that I will be using in my Vue applications moving forward.

The best way to explain this is with an example so lets start there. I'm going to throw a rather large block of code at you here, but stick with me and we will move through it a piece at a time.

<script>

// require vue-resource...

new Vue({
@ahtcx
ahtcx / deep-merge.js
Last active June 9, 2024 14:56
Deep-Merge JavaScript objects with ES6
// ⚠ IMPORTANT: this is old and doesn't work for many different edge cases but I'll keep it as-is for any of you want it
// ⚠ IMPORTANT: you can find more robust versions in the comments or use a library implementation such as lodash's `merge`
// Merge a `source` object to a `target` recursively
const merge = (target, source) => {
// Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties
for (const key of Object.keys(source)) {
if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key]))
}
@ourmaninamsterdam
ourmaninamsterdam / LICENSE
Last active April 24, 2024 18:56
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions: