Skip to content

Instantly share code, notes, and snippets.

View hansamlin's full-sized avatar
🎯
Focusing

Sam Lin hansamlin

🎯
Focusing
View GitHub Profile
/* http://meyerweb.com/eric/tools/css/reset/
v5.0.2 | 20191019
License: none (public domain)
*/
html,
body,
div,
span,
applet,
@hansamlin
hansamlin / dom_performance_reflow_repaint.md
Created July 23, 2024 08:38 — forked from faressoft/dom_performance_reflow_repaint.md
DOM Performance (Reflow & Repaint) (Summary)

DOM Performance

Rendering

  • How the browser renders the document
    • Receives the data (bytes) from the server.
    • Parses and converts into tokens (<, TagName, Attribute, AttributeValue, >).
    • Turns tokens into nodes.
    • Turns nodes into the DOM tree.
  • Builds CSSOM tree from the css rules.
@hansamlin
hansamlin / isJavaScriptProtocol.js
Created December 29, 2023 08:57
check is javascript protocol
export const isJavaScriptProtocol = /^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*\:/i;
class LinkedListNode {
constructor(value) {
this.next = null;
this.value = value;
}
}
class LinkedList {
constructor() {
this.head = null;
function _get(obj, path, _default) {
if (typeof obj !== "object") {
throw new Error("param 1 must be an object")
}
if (typeof path !== "string" && !Array.isArray(path)) {
throw new Error("param 2 must be an object or a string")
}
let _path = path
function getArrayBuffer(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener('load', () => {
resolve(reader.result);
});
reader.addEventListener('error', () => {
reject();
});
import { useEffect } from 'react'
import Script from 'next/script'
import { useRouter } from 'next/router'
import * as gtag from './gtag'
const App = ({ Component, pageProps }) => {
const router = useRouter()
useEffect(() => {
const handleRouteChange = (url) => {
gtag.pageview(url)
@hansamlin
hansamlin / Messages.js
Created September 13, 2021 08:49 — forked from Gpx/Messages.js
Check if user is logged in Express otherwise redirect to /login
// Set an error message and redirect
var redirectWithMessage = function (message, url, req, res) {
req.session.messages = message;
res.redirect(url);
};
// Return 'messages' value or null instead
var getMessages = function (req) {
var messages = req.session.messages || null;
delete req.session.messages;
@hansamlin
hansamlin / nginx.conf
Created September 9, 2021 09:03
Example Nginx configuration for serving pre-rendered HTML from Javascript pages/apps using the Prerender Service (https://github.com/collectiveip/prerender).Instead of using try_files (which can cause unnecessary overhead on busy servers), you could check $uri for specific file extensions and set $prerender appropriately.
# Note (November 2016):
# This config is rather outdated and left here for historical reasons, please refer to prerender.io for the latest setup information
# Serving static html to Googlebot is now considered bad practice as you should be using the escaped fragment crawling protocol
server {
listen 80;
listen [::]:80;
server_name yourserver.com;
root /path/to/your/htdocs;
function bubbleSort(arr) {
for(var i = 0; i < arr.length; i++) {
if(arr[i] > arr[i + 1]) {
var tmp = arr[i + 1];
arr[i + 1] = arr[i];
arr[i] = tmp;
}
}