Skip to content

Instantly share code, notes, and snippets.

@uhop
uhop / index.js
Created November 22, 2024 04:41
Fast pow() vs. slow pow()
const fastPow = (x, n) => {
if (x <= 0) return 0;
if (n === 0) return 1;
if (n === 1) return x;
const result = fastPow(x, n >> 1);
return (n & 1) ? result * x : result;
};
@uhop
uhop / gist:3259255
Created August 4, 2012 18:41
Bezier Shaders & Vector openGL rendering
@uhop
uhop / static-server.mjs
Last active August 1, 2024 08:32
No-dependency ES6 drop-in modular static development HTTP server.
// https://gist.github.com/uhop/fbb7fc3606cbb2fa54e0ce4f9a200037
// License: BSD-3
// (c) 2023 Eugene Lazutkin
import http from 'node:http';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
const fsp = fs.promises;
@uhop
uhop / dll.js
Last active July 27, 2024 19:30
Minimal circular SLL and DLL (lists).
// doubly linked list
const removeNode = node => {
node.prev.next = node.next;
node.next.prev = node.prev;
node.prev = node.next = node;
return node;
};
class DLL {
@uhop
uhop / min-heap-ext.js
Last active July 27, 2024 16:21
Minimal min-heap
import {up, down} from './min-heap.js';
// more efficient operations based on up() and down()
// WARNING: untested (if I wrote comprehensive tests it wouldn't be a gist, would it?)
const replaceTop = (heapArray, value, less) => {
const top = heapArray[0];
heapArray[0] = value;
down(heapArray, 0, less);
return top;
@uhop
uhop / admin.py
Created March 14, 2011 00:31
Adding Dojo's rich editor to Django's Admin.
# Example how to add rich editor capabilities to your models in admin.
from django.contrib.admin import site, ModelAdmin
import models
# we define our resources to add to admin pages
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',

Shell scripting with Markdown documents

alias ~~~=":<<'~~~sh'";:<<'~~~sh'

@uhop
uhop / nginx-webp-sample.conf
Last active May 25, 2024 17:02
Serving WEBP with nginx conditionally.
user www-data;
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
@uhop
uhop / LC_COLORS.md
Created March 23, 2024 05:28 — forked from thomd/LC_COLORS.md
LSCOLORS & LS_COLORS

alternatively use: http://geoff.greer.fm/lscolors/

LSCOLORS

The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatenation of pairs of the format fb, where f is the foreground color and b is the background color.

The color designators are as follows:

a black

@uhop
uhop / 0.README.md
Created March 22, 2024 18:22 — forked from izabera/0.README.md
tput codes

This is the table from man 5 terminfo.

Do NOT hardcode terminal escape sequences. Use tput with the cap-names from the table below to get the right code for your terminal.

(P) indicates that padding may be specified