Skip to content

Instantly share code, notes, and snippets.


Tomasz Czajęcki tchayen

View GitHub Profile
steveruizok / castRay.tsx
Created Oct 4, 2020
A minimal ray-casting function.
View castRay.tsx
export type RayOptions = {
max?: number
min?: number
start?: number
* Casts a ray in a given direction and check if it hits something.
* @param from - [x, y]
View AppMinHeightWrapper.tsx
import { Box, useDimensions, useSafeAreaInsets } from '@th3rdwave/ui';
import * as React from 'react';
import { updateSafeAreaInsets } from './metrics';
* This is a hack to simulate iOS keyboard behavior on Android. We use the
* keyboard behavior that causes the window to resize and make sure
* the min height stays the same when we detect that the keyboard opens.
export function AppMinHeightWrapper({
acutmore /
Last active Nov 24, 2021
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
    ["push", N_1],         // 1
    ["push", False],       // 2
    ["peek", _],           // 3
enepomnyaschih / base64.js
Last active Nov 24, 2021 - Encode JS Uint8Array, simple array of bytes or native JS string to base64 and back
View base64.js
MIT License
Copyright (c) 2020 Egor Nepomnyaschih
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
View useReducerWithEmitEffect.js
const {useCallback, useEffect, useReducer, useRef} = require('react');
let effectCapture = null;
exports.useReducerWithEmitEffect = function(reducer, initialArg, init) {
let updateCounter = useRef(0);
let wrappedReducer = useCallback(function(oldWrappedState, action) {
effectCapture = [];
try {
let newState = reducer(oldWrappedState.state, action.action);
View hole2.pde
// Processing code by Etienne JACOB
// motion blur template by beesandbombs
// opensimplexnoise code in another tab might be necessary
// --> code here :
int[][] result;
float t, c;
float ease(float p) {

‪“‬In what way is JS any more maintainable than CSS? How does writing CSS in JS make it any more maintainable?”

‪Happy to chat about this. There’s an obvious disclaimer that there’s a cost to css-in-js solutions, but that cost is paid specifically for the benefits it brings; as such it’s useful for some usecases, and not meant as a replacement for all workflows. ‬

‪(These conversations always get heated on twitter, so please believe that I’m here to converse, not to convince. In return, I promise to listen to you too and change my opinions; I’ve had mad respect for you for years and would consider your feedback a gift. Also, some of the stuff I’m writing might seem obvious to you; I’m not trying to tell you if all people of some of the details, but it might be useful to someone else who bumps into this who doesn’t have context)‬

So the big deal about css-in-js (cij) is selectors.

kimamula / sort.js
Created Oct 28, 2017
JavaScript asynchronous sort
View sort.js
* return the mid value among x, y, and z
* @param x
* @param y
* @param z
* @param compare
* @returns {Promise.<*>}
async function getPivot(x, y, z, compare) {
if (await compare(x, y) < 0) {
threepointone /
Last active Aug 30, 2021
why css purists will love glam

I made a little styling lib called glam

(some features are in development)


let's start off with the simplest use case. we'll make an 'index.html' page, and assume we've setup our js bundler to output bundle.js

View save-and-restore-contenteditable-selection.js
function saveSelection() {
if (window.getSelection) {
var sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
return sel.getRangeAt(0);
} else if (document.selection && document.selection.createRange) {
return document.selection.createRange();
return null;