Skip to content

Instantly share code, notes, and snippets.

View EryouHao's full-sized avatar
✔️
Yes! Gridea!

Zayn Hao EryouHao

✔️
Yes! Gridea!
View GitHub Profile
@sobelk
sobelk / react-markdown-toc.tsx
Created March 22, 2022 03:58
React Markdown TOC Proof-of-Concept
/*
This is based on an idea for building a table of contents on top of
React Markdown using a custom renderer. The original conversation is at
https://github.com/remarkjs/react-markdown/issues/48
*/
import React from "react";
import ReactMarkdown from "react-markdown";
@slikts
slikts / advanced-memo.md
Last active September 12, 2024 18:33
Advanced memoization and effects in React

nelabs.dev

Advanced memoization and effects in React

Memoization is a somewhat fraught topic in the React world, meaning that it's easy to go wrong with it, for example, by [making memo() do nothing][memo-pitfall] by passing in children to a component. The general advice is to avoid memoization until the profiler tells you to optimize, but not all use cases are general, and even in the general use case you can find tricky nuances.

Discussing this topic requires some groundwork about the technical terms, and I'm placing these in once place so that it's easy to skim and skip over:

  • Memoization means caching the output based on the input; in the case of functions, it means caching the return value based on the arguments.
  • Values and references are unfortunately overloaded terms that can refer to the low-level implementation details of assignments in a language like C++, for example, or to memory
@davestewart
davestewart / helpers.js
Last active November 26, 2019 04:31
Vue "route helpers" example
/**
* Helper function to reduce boilerplate in route creation
*
* @param {string} path The route's path
* @param {object} page A page component definition
* @param {Function} page A function that returns a page import
* @param {string} page A string path to a file in the view/pages folder
* @param {object} attrs Any additional attributes
*/
export function route (path, page, attrs = {}) {
@philippkuehn
philippkuehn / Component.vue
Created May 22, 2019 17:56
codeblock extension for tiptap using on scrumpy.io
<template>
<div class="c-code-block">
<div class="c-code-block__meta" contenteditable="false" v-if="editable">
<icon-btn
class="c-code-block__action-icon"
name="more"
:dropdown-props="{ closeOnClick: false }"
ref="icon"
>
<template v-slot:dropdown>
// vscode-keybindings for navigation with I/J/K/L and additional functionality with surrounding characters
// Place your key bindings in this file to overwrite the defaults
// ALT + I/J/K/L: up/left/down/right
// ALT + SHIFT + I/J/K/L: mark text up/left/down/right
// CTRL + J/L: send cursor to start/end of line
// CTRL + ALT + J/L: send cursor to start/end of word
// CTRL + ALT + U/O: send cursor to "wordPartLeft"/"wordPartRight"
// CTRL + ALT + SHIFT + U/O: mark from cursor to "wordPartLeft"/"wordPartRight"
// CTRL + ALT + Y: got to declaration
@plcosta
plcosta / postcss.config.js
Created December 7, 2018 00:10
PostCSS Config - TailwindCSS, Vuetify and PurgeCSS
const tailwindcss = require('tailwindcss')
const autoprefixer = require('autoprefixer')
const purgecss = require('@fullhuman/postcss-purgecss')
module.exports = {
plugins: [
tailwindcss('./tailwind.js'),
autoprefixer({
add: true,
grid: true
@origamid
origamid / smooth-scroll.js
Last active July 21, 2022 15:23 — forked from clemlatz/smooth-scroll.js
Smooth Scroll Animation - JavaScript
/**
* Smooth scroll animation
* @param {int} endX: destination x coordinate
* @param {int} endY: destination y coordinate
* @param {int} duration: animation duration in ms
*/
function smoothScrollTo(endX, endY, duration) {
const startX = window.scrollX || window.pageXOffset;
const startY = window.scrollY || window.pageYOffset;
const distanceX = endX - startX;
@javilobo8
javilobo8 / download-file.js
Last active October 27, 2024 09:15
Download files with AJAX (axios)
axios({
url: 'http://localhost:5000/static/example.pdf',
method: 'GET',
responseType: 'blob', // important
}).then((response) => {
const url = window.URL.createObjectURL(new Blob([response.data]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'file.pdf');
document.body.appendChild(link);
@LoyEgor
LoyEgor / gulpfile.js
Last active March 13, 2023 17:22
best image compression settings (gulp-imagemin)
// install
// npm i gulp-cache gulp-imagemin imagemin-pngquant imagemin-zopfli imagemin-mozjpeg imagemin-giflossy -f
// node node_modules/jpegtran-bin/lib/install.js
// node node_modules/gifsicle/lib/install.js
// node node_modules/zopflipng-bin/lib/install.js
// node node_modules/mozjpeg/lib/install.js
// node node_modules/giflossy/lib/install.js
// node node_modules/pngquant-bin/lib/install.js
@paulirish
paulirish / what-forces-layout.md
Last active November 14, 2024 11:03
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent