Skip to content

Instantly share code, notes, and snippets.

function Point(x, y) {
this.x = x
this.y = y
}
function Boundary(x, y, x2, y2) {
this.x = x
this.y = y
this.x2 = x2
this.y2 = y2
function HashTable(object, size) {
this.length = size || 1
this._ = new Array(this.length)
this.size = 0
const hash = function (key) {
let h = 1
let keyLength = key.length
for (let i = 0; i < keyLength; i++) {
h += key.charCodeAt(i)
class vector {
constructor(x, y, z) {
this.x = x || 0
this.y = y || 0
this.z = z || 0
}
add(a) {
if (a instanceof vector) {
return new vector(this.x + a.x, this.y + a.y, this.z + a.z)
} else {
@zserge
zserge / example.html
Last active April 2, 2021 21:49
This is the smallest possible CSS-in-JS that supports all CSS rules, media queries, keyframes and generates unique class names for each CSS block. Can be used with React or with any other framework.
<body>
<script type="module">
import { css } from './zercss.js';
// Global styles
css`
&{} /* This would be a global CSS */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { max-width: 40rem; padding: 2rem; margin: auto; }
`;
@maitrungduc1410
maitrungduc1410 / create-vod-hls-gpu.sh
Last active June 28, 2024 04:22
Bash scripts to create VOD HLS stream with ffmpeg using GPU
#!/usr/bin/env bash
START_TIME=$SECONDS
set -e
echo "-----START GENERATING HLS STREAM-----"
# Usage create-vod-hls-gpu.sh SOURCE_FILE [OUTPUT_NAME]
[[ ! "${1}" ]] && echo "Usage: create-vod-hls.sh SOURCE_FILE [OUTPUT_NAME]" && exit 1
# comment/add lines here to control which renditions would be created
renditions=(
@oze4
oze4 / DOMRegex.js
Last active March 16, 2023 23:30
Essentially querySelectorAll with regex support. Modified from: https://stackoverflow.com/a/62144522
/**
* @plug
* DOMRegex.js
* https://mattoestreich.com
*
* @description
* Modified from: https://stackoverflow.com/a/62144522
* TLDR; querySelectorAll with regex support
*
* @important
@xem
xem / JSGameFramework2020.html
Last active November 11, 2023 19:53
JS game framework 2020
<body style=margin:0>
<canvas id=a>
<script>
// initialize 2D canvas (c)
// initialize game state (s)
// initialize keys states (u,r,d,l for directions, k for all the keyboard)
c=a.getContext`2d`,k=[u=r=d=l=s=0]
// (initialize your global variables here)
export const h=(t,p,...c)=>({t,p,c,k:p&&p.key})
export const render=(e,d,t=d.t||(d.t={}),p,r,c,m,y)=>
// arrays
e.map?e.map((e,p)=>render(e,d,t.o&&t.o[p])):
// components
e.t.call?(e.i=render((render.c=e).t(Object.assign({children:e.c},e.p),e.s=t.s||{},t=>
render(Object.assign(e.s,t)&&e,d,e)),t.i||d,t&&t.i||{}),d.t=t=e):(
// create notes
m=t.d||(e.t?document.createElement(e.t):new Text(e.p)),
// diff props
var s;
function supportsModuleWorkers() {
if (s==null) {
s = false;
try {
new Worker('data:,', Object.defineProperty({}, 'type', {
get() { s = true; }
})).terminate();
} catch (e) {}
}
@WebReflection
WebReflection / handle-event-doodle.md
Last active July 25, 2024 10:58
The `handleEvent` ASCII doodle

About This Gist

This gist summarizes the handleEvent(event) pattern features, something standard, something described by me many times, written in my tiny book, tweeted about, and yet it's something most Web developers ignore.

The handleEvent ASCII Doodle

                  ┌---------------------------------┐
var handler = {   | any object that inherits or     |