Skip to content

Instantly share code, notes, and snippets.

View kripod's full-sized avatar

Kristóf Poduszló kripod

View GitHub Profile
class PathMe {
moves: string[] = [];
constructor() {
this.moves = [];
return this;
}
moveTo(x: number, y: number) {
import * as React from 'react';
const useIsFirstRender = (): boolean => {
const isFirst = React.useRef(true);
if (isFirst.current) {
isFirst.current = false;
return true;
} else {
@dpeek
dpeek / tsconfig.json
Created August 30, 2023 01:40
Somewhat OK TSConfig defaults and explanations
/*
Enabled by "strict":
- alwaysStrict
- noImplicitAny
- noImplicitThis
- strictNullChecks
- strictBindCallApply
- strictFunctionTypes
- strictPropertyInitialization
- useUnknownInCatchVariable
@bramus
bramus / css-scrollbars.md
Created July 20, 2023 20:44
CSS Scrollbars

An issue we’ve heard from authors is that they want to know what scrollbars are doing and respond to that.

There’s a bunch of issues that might go hand in hand to actually solve this:

  1. [^1] Expose an env() variable that allows you to get the scrollbar-size. This is a fixed value, independent of whether a scrollbar is shown or not – it just gives you back the size
  2. [^2] A way to query which type of scrollbars are being used on the page.
  3. A container state query to be able to know if something is overflowing or not

If you combine these three, authors can do things like:

@jordienr
jordienr / tailwind.config.ts
Created July 15, 2023 09:10
Tailwind SVG Grid Background
// Remember to install mini-svg-data-uri
// Follow me on twitter for memes @jordienr
import { type Config } from "tailwindcss";
const {
default: flattenColorPalette,
} = require("tailwindcss/lib/util/flattenColorPalette");
const svgToDataUri = require("mini-svg-data-uri");
export default {
// 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 => {
import invariant from "tiny-invariant";
class AmalgoBox extends HTMLElement {
get input() {
return this.querySelector("input") as HTMLInputElement;
}
get button() {
return this.querySelector("button") as HTMLButtonElement;
}
@KATT
KATT / ErrorBoundary.tsx
Last active May 12, 2022 21:00
A suspense hook for tRPC
import React, { Component, ErrorInfo, ReactNode } from 'react';
import NextError from 'next/error';
import { TRPCClientErrorLike } from '@trpc/client';
import { AppRouter } from 'server/routers/_app';
interface Props {
children: ReactNode;
}
interface State {

Cheat sheet: Arrays

JavaScript Arrays are a very flexible data structure and used as lists, stacks, queues, tuples (e.g. pairs), etc. Some

Using Arrays

Creating Arrays, reading and writing elements:

@alyssarosenzweig
alyssarosenzweig / demo.m
Created September 25, 2021 02:09
AppleJPEGDriver decode routine for the Apple M1
/*
* Copyright (C) 2021 Alyssa Rosenzweig <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*