Skip to content

Instantly share code, notes, and snippets.

View haggen's full-sized avatar

Arthur Corenzan haggen

View GitHub Profile
// Turn all HTML <a> elements into client side router links, no special framework-specific <Link> component necessary!
// Example using the Next.js App Router.
import { useRouter } from 'next/navigation';
import { useEffect } from 'react';
function useLinkHandler() {
let router = useRouter();
useEffect(() => {
let onClick = e => {
@haggen
haggen / create-component.sh
Last active May 6, 2023 17:34
Script to automate creating new components in a React application.
#!/usr/bin/env bash
#
# Create React Component.
#
# Sane defaults.
# -e Exit on error.
# -u Whine on undefined variables.
# -o pipefail Exit main script if pipe process fails.
set -euo pipefail
@EllyLoel
EllyLoel / reset.css
Last active April 13, 2024 18:14
CSS Reset
/*
Made by Elly Loel - https://ellyloel.com/
With inspiration from:
- Josh W Comeau - https://courses.joshwcomeau.com/css-for-js/treasure-trove/010-global-styles/
- Andy Bell - https://piccalil.li/blog/a-modern-css-reset/
- Adam Argyle - https://unpkg.com/open-props@1.3.16/normalize.min.css / https://codepen.io/argyleink/pen/KKvRORE
Notes:
- `:where()` is used to lower specificity for easy overriding.
*/
@haggen
haggen / .zshrc
Last active January 15, 2024 14:17
My Linux setup both on Ubuntu or WSL.
# starship prompt
# https://starship.rs/
eval "$(starship init zsh)"
# rtx runtime
# https://github.com/jdx/rtx
eval "$(rtx activate zsh)"
export PIPENV_VENV_IN_PROJECT=1
export VISUAL=vim
@mesaavukatlik
mesaavukatlik / analytics.js
Created April 22, 2021 08:51 — forked from janispritzkau/analytics.js
Minimal Google Analytics script in modern javascript (677 bytes minified)
((document, location, navigator) => {
const domain = location.hostname.split(".")
const match = document.cookie.match(/(^|; ?)_ga=GA1\.\d\.(\d+\.\d+)(;|$)/)
// use existing client id or generate one
const cid = match ? match[2] : ~~(2147483648 * Math.random()) + "." + ~~(Date.now() / 1000)
// set cookie at highest possible domain level
for (let i = domain.length; i--;) {
const cookie = `_ga=GA1.${domain.length - i}.${cid}`
@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@haggen
haggen / Jason.yaml
Created April 10, 2020 13:54
EVE Online overview.
backgroundOrder:
- 13
- 44
- 52
- 11
- 51
- 50
- 9
- 12
- 14
@elierotenberg
elierotenberg / BLOG.md
Last active August 16, 2023 12:01
Idiomatic Data Fetching using React Hooks

Idiomatic Data Fetching using React Hooks

This post has been written in collaboration with @klervicn

Virtually all web apps and websites need to pull data from a server, usually through a JSON-returning API. When it comes to integrating data fetching in React component, the "impedence mismatch" between the React components, which are declarative and synchronous, and the HTTP requests, which are imperative and asynchronous, is often problematic.

Many apps use third-party libraries such as Redux or Apollo Client to abstract it away. This requires extra dependencies, and couple your app with a specific library to perform data fetching. In most cases, what we want is a direct way to integrate plain HTTP requests (e.g. using native fetch) for usage in React components.

Here we will discuss how we can use React Hooks to do this in an elegant, scalable manner.

Everything I Know About UI Routing

Definitions

  1. Location - The location of the application. Usually just a URL, but the location can contain multiple pieces of information that can be used by an app
    1. pathname - The "file/directory" portion of the URL, like invoices/123
    2. search - The stuff after ? in a URL like /assignments?showGrades=1.
    3. query - A parsed version of search, usually an object but not a standard browser feature.
    4. hash - The # portion of the URL. This is not available to servers in request.url so its client only. By default it means which part of the page the user should be scrolled to, but developers use it for various things.
    5. state - Object associated with a location. Think of it like a hidden URL query. It's state you want to keep with a specific location, but you don't want it to be visible in the URL.
const lunr = require('lunr')
require('lunr-languages/lunr.stemmer.support')(lunr)
require('lunr-languages/lunr.fr')(lunr)
require('./lunr.unicodeNormalizer')(lunr)
var idx = lunr(function () {
this.use(lunr.fr)
this.use(lunr.unicodeNormalizer)
...