Skip to content

Instantly share code, notes, and snippets.

View giuseppeg's full-sized avatar
🌊
All is well.

Giuseppe giuseppeg

🌊
All is well.
View GitHub Profile
@giuseppeg
giuseppeg / dependabot.yml
Created September 5, 2021 09:36
github workflow (action) to update dependencis
name: Update Dependencies
on:
schedule:
# https://crontab.guru/#0_0_*_*_WED,SAT
# Run every Wednesday and Saturday at 00:00
# 0 0 * * WED,SAT
- cron: '0 0 * * WED,SAT'
jobs:
dependabot:
import { NextApiRequest as DefaultNextApiRequest, NextApiResponse } from "next";
/**
* // Route /pages/api/posts/[id]
*
* const api = defineApi<{ id: string }>()
* .get<{ query: { foo: "1" } }, "foo" | "bar">(
* async function handler(req, res) {
* const session = await getSession({ req });
* if (!session) {
import * as React from "react";
/*
Usage
import { Style } from "style";
function Heading({children}) {
return (
<>
<Style>{`h1 { color: red }`}</Style>
@giuseppeg
giuseppeg / lagcheck.mrc
Created March 23, 2021 20:47
Old mIRC script to check for lag I wrote when I was a teenager
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 } }
function Hydrator(props) {
const [isPaused, setIsPaused] = React.useState(typeof window !== "undefined");
React.useEffect(() => {
console.log("Loading polyfills...");
setTimeout(() => {
console.log("Done.");
setIsPaused(false);
}, 3000);
}, []);
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
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<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 April 12, 2020 19:13
Note this is a proof of concept and probably there are corner cases that I haven't considered. https://twitter.com/pacocoursey/status/1249226550756573184
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)
}
}
// 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") {