Skip to content

Instantly share code, notes, and snippets.

@alexanderi96
alexanderi96 / config.yaml
Last active February 3, 2025 15:48
My GlazeWM config file
gaps:
inner_gap: 10
outer_gap: 10
general:
# Whether to show floating windows as always on top.
show_floating_on_top: true
bar:
height: "30px"
@jeferandom
jeferandom / config
Last active January 4, 2024 08:37
my i3 config file, custom workspaces
# i3 config file (v4) for Regolith Desktop Environment
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
# This defines which key super maps to on your keyboard.
# Alt key is Mod1, and Windows key is Mod4
set $mod Mod4
set $alt Mod1
# i3xrocks config file

I> Khái niệm cản bản về React Hook

React hook đã được lên bản chính thức kể từ phiên bản 16.8. Trước đó, vào React Conf 2018 ở Cali đội ngũ phát triển đã giới thiệu nó và bắt đầu bản beta cho các phiên bản kế và nay đã là bản chính thức. Nếu ta vào https://reactjs.org/docs/hooks-intro.html bản đã thấy nó từ beta sang new

Hook cho phép ta không cần thiết phải tạo class component, chỉ cần tạo function less component vẫn có thể có thể sử dụng state và các features. Điều này khiến các component nhẹ nhàng hơn hơn nhiều, giảm số lượng code cần thiết phải code, đồng thời dễ hiểu ít nhầm lẫn hơn về một số khái niệm như livecycle với 1 lập trình viên mới

1. Lợi ích từ hook:

a. Giảm số lượng code đáng kể

Có thể giảm số lượng đáng kể, theo thống kê khoảng 90% với 1 project trung bình do:

  • Nhờ việc quản lý state dễ dàng và hiệu quả hơn với hook, ta có thể tránh lỗi wrapper hell
@wojtekmaj
wojtekmaj / react-highlight-text-by-pattern.js
Last active August 15, 2024 10:19
Highlight text in React by providing text and RegExp pattern.
function highlightPattern(text, pattern) {
const splitText = text.split(pattern);
if (splitText.length <= 1) {
return text;
}
const matches = text.match(pattern);
return splitText.reduce((arr, element, index) => (matches[index] ? [
@flekschas
flekschas / conclusion.md
Created July 31, 2018 14:59
Performance of Object.keys vs Object.values for getting the number of props of an object

Results

Let's get started!
VM73:13 Object.keys took: 20234.000000054948msecs
VM73:19 Object.values took: 5987.800000002608msecs

Conclusion

@tnolet
tnolet / puppeteer_youtube.js
Created February 23, 2018 18:17
Puppeteer search youtube
const puppeteer = require('puppeteer')
const screenshot = 'youtube_fm_dreams_video.png'
try {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://youtube.com')
await page.type('#search', 'Fleetwood Mac Dreams')
await page.click('button#search-icon-legacy')
await page.waitForSelector('ytd-thumbnail.ytd-video-renderer')
@virolea
virolea / upload.js
Last active December 12, 2024 16:14
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
@AdamMarsden
AdamMarsden / sassas.md
Last active August 11, 2025 12:26
Sass Architecture Structure

Sass Architecture Structure

sass/
|
|– base/
|   |– _reset.scss       # Reset/normalize
|   |– _typography.scss  # Typography rules
|   ...                  # Etc…
|
@rxaviers
rxaviers / gist:7360908
Last active November 8, 2025 14:28
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@davidtheclark
davidtheclark / isElementInViewport.js
Created May 4, 2013 02:00
JavaScript: Is element in viewport?
/*
No jQuery necessary.
Thanks to Dan's StackOverflow answer for this:
http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
*/
function isElementInViewport(el) {
var rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&