Skip to content

Instantly share code, notes, and snippets.

Avatar
🌊
All is well.

Giuseppe giuseppeg

🌊
All is well.
View GitHub Profile
View streaming-styles.jsx
import * as React from "react";
/*
Usage
import { Style } from "style";
function Heading({children}) {
return (
<>
<Style>{`h1 { color: red }`}</Style>
@giuseppeg
giuseppeg / lagcheck.mrc
Created Mar 23, 2021
Old mIRC script to check for lag I wrote when I was a teenager
View lagcheck.mrc
on 1:connect: {
if (%Lagchk == on) { .timerLAG 0 %Lag.secs lagcheck }
}
alias lagcheck { .ctcpreply $me LAGGC $ticks }
on *:CTCPREPLY:LAGGC*: { if ($nick == $me) { set %lag $round($calc((($ticks - $2) / 2) / 1000),2) | echo -a $timestamp lag: %lag $+ secs.. | halt } }
alias lag {
if ($1 == on) { /set %lagchk on | echo -a Lag Meter: on. | goto { end } }
if ($1 == off) { /set %lagchk off | echo -a Lag Meter: off. | goto { end } }
if ($1 == delay) { set %Lag.secs $2 | echo -a Lag Meter: checking every: $2 $+ secs. | goto { end } }
View pause-hydration.jsx
function Hydrator(props) {
const [isPaused, setIsPaused] = React.useState(typeof window !== "undefined");
React.useEffect(() => {
console.log("Loading polyfills...");
setTimeout(() => {
console.log("Done.");
setIsPaused(false);
}, 3000);
}, []);
View screenshot-dom.js
async function dom2canvas(element) {
await import('https://cburgmer.github.io/rasterizeHTML.js/rasterizeHTML.allinone.js')
const canvas = document.createElement('canvas')
canvas.width = element.scrollWidth
canvas.height = element.scrollHeight
await rasterizeHTML.drawHTML(element.outerHTML, canvas)
return canvas
}
View care-pizza.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View Dynamic-svg-icon.html
<link rel="icon" href="data:image/svg+xml,%3Csvg viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle style='fill: red' cx='10' cy='10' r='10'/%3E%3Ctext x='10' y='14' text-anchor='middle' style='fill: white; font-family: sans-serif; font-size: 0.7em;'%3E1%3C/text%3E%3C/svg%3E" type="image/svg+xml" />
@giuseppeg
giuseppeg / useSystemTheme-singleton.js
Last active Apr 12, 2020
Note this is a proof of concept and probably there are corner cases that I haven't considered. https://twitter.com/pacocoursey/status/1249226550756573184
View useSystemTheme-singleton.js
let currentTheme = 'light'
const broadcastThemeChangeFunctions = new Set()
let media = null
function listener(media) {
currentTheme = themes[media.matches ? 'dark' : 'light']
for (let setTheme of broadcastThemeChangeFunctions) {
setTheme(currentTheme)
}
}
View react-native-fetch-charset-issue.js
// RN's fetch seems to not handling responses with other charsets correctly like Node.js does
// eg. the following link returns content-type: "text/html; charset=ISO-8859-1"
// https://www.corriere.it/cronache/20_marzo_13/coronavirus-ultimi-aggiornamenti-dall-italia-mondo-d4c07168-64f4-11ea-ac89-181bb7c2e00e.shtml
// response.text() resolves to undefined
const src = await fetch(url)
.then(response => {
const charset = (response.headers.get("content-type") || "").split(
"charset="
)[1];
if (!charset || charset.toLowerCase() === "utf-8") {
View isFocusableNode.js
const focusableSelectors = [
'a[href]:not([tabindex^="-"]):not([inert])',
'area[href]:not([tabindex^="-"]):not([inert])',
'input:not([disabled]):not([inert])',
'select:not([disabled]):not([inert])',
'textarea:not([disabled]):not([inert])',
'button:not([disabled]):not([inert])',
'iframe:not([tabindex^="-"]):not([inert])',
'audio:not([tabindex^="-"]):not([inert])',
'video:not([tabindex^="-"]):not([inert])',
@giuseppeg
giuseppeg / createOrderedCSSStyleSheet.js
Last active Jan 25, 2019 — forked from necolas/createOrderedCSSStyleSheet.js
OrderedCSSStyleSheet: control the insertion order of CSS
View createOrderedCSSStyleSheet.js
/**
* Copyright (c) Nicolas Gallagher.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
*/
type Groups = { [key: number]: Array<string> };