Skip to content

Instantly share code, notes, and snippets.

View gangsthub's full-sized avatar
Creative developer

Paul Melero gangsthub

Creative developer
View GitHub Profile
@gangsthub
gangsthub / README.md
Last active September 29, 2023 01:09
DeepClone-js: JS utility with circular replacer

DeepClone-js

Utility to clean up circular references while creating a new reference of an object performing a deep copy (as oposite to a shallow copy). Bear in mind it doesn't work with some data types: Date, Map, RegExp, Set, TypedArray...

📦 Install

npm i -S gist:0bce1161cfd2aa91ae7cad9abb42c342
@gangsthub
gangsthub / component.vue
Created April 25, 2023 19:51
Vue Props as enums
<script setup lang="ts">
enum VariantEnum {
PRIMARY = 'primary',
SECONDARY = 'secondary',
}
// Turn enums into string union types!
type TypeFromEnum<T> = T extends `${infer U}` ? U : never;
type VariantType = TypeFromEnum<VariantEnum>;
@gangsthub
gangsthub / _fake-clamping.scss
Last active February 1, 2023 08:44
Alternative to `-webkit-line-clamp` as a mixin.
///*
//* Usage:
//* @include fake-clamping(1.2, 1);
//*/
@mixin fake-clamping($line-height: 1.4, $lines: 1, $padding: 0, $w: false) {
$_height: $line-height * $lines + $padding;
height: #{$_height}em;
@gangsthub
gangsthub / vitest.config.mjs
Created January 21, 2023 17:31
Basic vitest config for a Nuxt project
// vitest.config.mjs
import { defineConfigWithNuxtEnv } from 'vitest-environment-nuxt/config'
export default defineConfigWithNuxtEnv({
test: {
globals: true,
},
})
@gangsthub
gangsthub / index.js
Last active May 11, 2022 15:26
JS Quiz
const quiz = {
...{ a: { b: 1, c: 3 }},
...{ a: { b: 2 }}
}
@gangsthub
gangsthub / README.md
Last active November 29, 2021 19:02
Simple Debounce Vue 2 Mixin: `simple-debounce-vue-mixin`

SimpleDebounce (Vue Mixin)

If you are listening to changes on an Event (DOM Events) to execute any side effects like performing network requests, you'd probably want to "debounce" your attached function executions.

This is an alternative to lodash.debounce but "vanilla js" packed as a Vue SFC to import it as a mixin.

@gangsthub
gangsthub / main.vue
Created September 30, 2021 12:56
Specificity Challenge
<template>
<p id="one" class="hello">hello world</p>
</template>
<style scoped>
#one {
color: blue;
}
.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello {
@gangsthub
gangsthub / README.md
Last active November 27, 2020 09:14
`img-exists`
@gangsthub
gangsthub / asyncOnce.js
Created July 22, 2020 15:49
Async once
/**
* Takes a generator function that can yeild async functions.
* When the wrapped generator is called again, the previous call will cancel ASAP.
* Note: it won't cancel in-flight requests made (see: AbortController)
* @param {GeneratorFunction} generator
* @see https://dev.to/chromiumdev/cancellable-async-functions-in-javascript-5gp7
* @author Sam Thorogood
* @returns {(...args: any[]) => Promise<any>}
*/
@gangsthub
gangsthub / README.md
Last active July 16, 2020 16:40
`copytoclipboard`: Alternative to clipboard.js: Async implementation of "Copy to clipboard" in plain JS. Works in Safari, Chrome, Firefox, Opera and Edge Canary. Less than 1kb minified.

copyToClipBoard.js

copytoclipboard: Alternative to clipboard.js: Async implementation of "Copy to clipboard" in plain JS. Works in Safari, Chrome, Firefox, Opera and Edge Canary. Less than 1kb minified.

copyToClipBoard accepts an html element and returns a Promise.

Copies the content of the html element with the format included and also as plain text (both options).

📦 Install