Skip to content

Instantly share code, notes, and snippets.

View ktnyt's full-sized avatar
🐱

ktnyt ktnyt

🐱
View GitHub Profile
@kripod
kripod / Box.tsx
Last active March 27, 2024 18:14
Superseded by https://www.kripod.dev/blog/behind-the-as-prop-polymorphism-done-well/ – Polymorphic `as` prop for React components with TypeScript
import React from 'react';
// Source: https://github.com/emotion-js/emotion/blob/master/packages/styled-base/types/helper.d.ts
type PropsOf<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
E extends keyof JSX.IntrinsicElements | React.JSXElementConstructor<any>
> = JSX.LibraryManagedAttributes<E, React.ComponentPropsWithRef<E>>;
export interface BoxOwnProps<E extends React.ElementType = React.ElementType> {
as?: E;
@shafik
shafik / WhatIsStrictAliasingAndWhyDoWeCare.md
Last active April 24, 2024 03:49
What is Strict Aliasing and Why do we Care?

What is the Strict Aliasing Rule and Why do we care?

(OR Type Punning, Undefined Behavior and Alignment, Oh My!)

What is strict aliasing? First we will describe what is aliasing and then we can learn what being strict about it means.

In C and C++ aliasing has to do with what expression types we are allowed to access stored values through. In both C and C++ the standard specifies which expression types are allowed to alias which types. The compiler and optimizer are allowed to assume we follow the aliasing rules strictly, hence the term strict aliasing rule. If we attempt to access a value using a type not allowed it is classified as undefined behavior(UB). Once we have undefined behavior all bets are off, the results of our program are no longer reliable.

Unfortunately with strict aliasing violations, we will often obtain the results we expect, leaving the possibility the a future version of a compiler with a new optimization will break code we th

@vincentriemer
vincentriemer / ResizeObservable.js
Created December 4, 2017 20:15
React Component prototype that provides element query functionality via ResizeObserver
// @flow
import * as React from "react";
import ResizeObserver from "resize-observer-polyfill";
import invariant from "invariant";
type Entry = {
+contentRect: {
+width: number,
+height: number
@simonhaenisch
simonhaenisch / video-player.html
Last active June 22, 2023 01:30
Play local video files in the browser (HTML5 video player) with playlist, speed control and keyboard shortcuts for pause (spacebar) and 5 second jump (left/right arrow). Created to watch Wes Bos tutorials offline. Playback speed defaults to 2x.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Local HTML5 Video Player</title>
</head>
<body>
<style>
* { box-sizing: border-box; }
@tonets
tonets / kanazawa.md
Last active March 15, 2016 06:39
BH15.15向け金沢案内
@ktnyt
ktnyt / stapgolf.pl
Last active August 21, 2021 14:16
はやったやつ
while("STAP"ne$s){print$s=join("",map{qw(S T A P)[4*rand]}0..3),"\n"}print"陽性かくにん! よかった☆\n"
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@jimbojsb
jimbojsb / gist:1630790
Created January 18, 2012 03:52
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

@jed
jed / LICENSE.txt
Created May 10, 2011 16:39 — forked from 140bytes/LICENSE.txt
use anchor tags to parse URLs into components
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE