Skip to content

Instantly share code, notes, and snippets.

@mizchi
mizchi / singlefile-frontend.md
Created November 23, 2023 10:27
How to run a minimal front-end stack in Single-File for prototyping.

Original(japanese) https://zenn.dev/mizchi/articles/standalone-html-frontend

Mostly translated by deepl


How to run a minimal front-end stack in Single-File for prototyping.

Note: Do not use in production, tailwind is running in CDN mode and esm.sh builds scripts dynamically, so performance is not good.

@henryivesjones
henryivesjones / postgresql_date_timestamp_interval_cheat_sheet.md
Created February 14, 2023 16:56
PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

PostgreSQL DATE, TIMESTAMP, and INTERVAL cheat sheet

Working with DATE, TIMESTAMP, and INTERVAL in PostgreSQL can be confusing. In this article I will go over the three date/time related data types, and the two most useful date/time functions: DATE_PART and DATE_TRUNC. Finally, I will provide some real life examples of how these types and functions can be used within queries.

Types

PostgreSQL Date/Time Documentation

DATE

The DATE type contains the year, month, and day of a date. It is not possible to do any type of time related functions on a DATE without first converting it to a TIMESTAMP. Subtracting two DATE values from one another results in an INT representing the # of days between.

TIMESTAMP

The TIMESTAMP type contains a year, month, day, hour, minute, second, and microsecond. This is the type that I most often use.

@Pierstoval
Pierstoval / confirm.Makefile
Last active March 7, 2024 09:34
"confirm" action for your Makefile
# To use the "confirm" target inside another target,
# use the " if $(MAKE) -s confirm ; " syntax.
mycommand:
@if $(MAKE) -s confirm ; then \
execute_your_command_here ; \
fi
.PHONY: mycommand
# The CI environment variable can be set to a non-empty string,
@lyrixx
lyrixx / index.php
Created April 22, 2020 13:20
Very low memory usage iterator
<?php
function m()
{
$memory = round(memory_get_usage() / 1024 / 1024, 2);
$frame = debug_backtrace(0, 1)[0];
$file = basename($frame['file']);
$line = $frame['line'];
printf("%s:%d | %sMb\n", $file, $line, $memory);

high res tiled rendering with canvas-sketch

Copy these files in the gist to a new folder. Generate a package.json:

cd folder-with-code
npm init -y

Then install deps:

@soyuka
soyuka / example-1.js
Last active August 24, 2021 16:38
Promise reflect API by bluebird to handle multiple errors in Promise.all
const Promise = require('bluebird')
const lambdas = require('./lambdas.js')
// Ref: https://stackoverflow.com/questions/25817366/bluebird-promise-all-multiple-promises-completed-aggregating-success-and-rejec
Promise.all(lambdas.map(function(promise) {
// On utilise l'API reflect pour inspecter a la main nos promesses voir http://bluebirdjs.com/docs/api/reflect.html
// grace a ca, la promesse réussira toujours
return promise.reflect();
})).each(function(inspection) {
// Ici la lambda (ou promesse) a réussi
@huntrar
huntrar / full-disk-encryption-arch-uefi.md
Last active September 19, 2024 04:49
Arch Linux Full-Disk Encryption Installation Guide [Encrypted Boot, UEFI, NVMe, Evil Maid]

Arch Linux Full-Disk Encryption Installation Guide

This guide provides instructions for an Arch Linux installation featuring full-disk encryption via LVM on LUKS and an encrypted boot partition (GRUB) for UEFI systems.

Following the main installation are further instructions to harden against Evil Maid attacks via UEFI Secure Boot custom key enrollment and self-signed kernel and bootloader.

Preface

You will find most of this information pulled from the Arch Wiki and other resources linked thereof.

Note: The system was installed on an NVMe SSD, substitute /dev/nvme0nX with /dev/sdX or your device as needed.

@astoilkov
astoilkov / readme.md
Last active March 13, 2024 10:19
Async Operations with useReducer Hook

Async Operations with useReducer Hook

9 March, 2019

We were discussing with @erusev what we can do with async operation when using useReducer() in our application. Our app is simple and we don't want to use a state management library. All our requirements are satisfied with using one root useReducer(). The problem we are facing and don't know how to solve is async operations.

In a discussion with Dan Abramov he recommends Solution 3 but points out that things are fresh with hooks and there could be better ways of handling the problem.

Problem

@ernierasta
ernierasta / sway-record
Last active August 18, 2022 19:36
Swaywm screen and audio recording
#!/bin/bash
# Sway WM screen + audio recorder
# original author: Aaron D. Fields
# blog post: https://blog.spirotot.com/2017/08/21/a-dirty-hack-to-enable-acceptable-sway-wm-screen-recording/
# currently error 503 :-(
#
# Updated version: ernierasta
# Repo: https://gist.github.com/ernierasta
#
# Changelog:
@mattdesl
mattdesl / sol-lewitt-wall-drawing-273.js
Created October 17, 2018 12:40
Sol LeWitt "Wall Drawing 273" (7th wall) recreated in JavaScript
const canvasSketch = require('canvas-sketch');
const random = require('canvas-sketch-util/random');
const { lerp, lerpArray } = require('canvas-sketch-util/math');
const palettes = require('nice-color-palettes');
const settings = {
dimensions: 'A4',
orientation: 'landscape',
units: 'cm',
pixelsPerInch: 300