Skip to content

Instantly share code, notes, and snippets.

Brew Bundle Brewfile Tips

Copyright & License

Unless otherwise noted (either in this file or in a file's copyright section) the contents of this gist are Copyright ©️2020 by Christopher Allen, and are shared under spdx:Creative Commons Attribution Share Alike 4.0 International (CC-BY-SA-4.) open-source license.

Sponsor

If you more tips and advice like these, you can become a monthly patron on my GitHub Sponsor Page for as little as $5 a month; and your contributions will be multipled, as GitHub is matching the first $5,000! This gist is all about Homebrew, so if you like it you can support it by donating to them or becoming one of their Github Sponsors.

@uhop
uhop / print.html
Created April 24, 2023 16:10
Multi-page print test
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Multi-page print test</title>
<!--
Print to PDF, landscape, letter size, no margins, enable background graphics.
Tested on Chrome.
-->
<style>
@uhop
uhop / str-pad.js
Last active May 16, 2023 14:47
Padding a string: left pad, right pad, repeating a string
const rep = (str, n) => {
if (n < 1 || !str) return '';
let result = '';
for (;;) {
if (n & 1) {
result += str;
}
n >>= 1;
if (n < 1) break;
str += str;
@uhop
uhop / dnd.js
Last active March 3, 2023 18:34
The facelift of the minimalistic DnD code from https://gist.github.com/uhop/d87365fac38ba6b8cbf0b890d0c2258e
'use strict';
// from https://gist.github.com/uhop/d87365fac38ba6b8cbf0b890d0c2258e
const noop = () => {};
class DndMove {
static supportedEvents = {
pointerup: 'onPointerUp',
pointermove: 'onPointerMove',
// runs asynchronous operations in parallel, no more than a specified number at a time
// it takes an array of functions, which return promises when invoked without arguments
// modelled after Promise.all()
const wrap = value => {
if (typeof value == 'function') return value();
if (value && typeof value.then == 'function') return value; // thenable
return Promise.resolve(value);
};
@uhop
uhop / dnd-g.html
Last active August 3, 2021 23:34
A minimalistic generic DnD code. A facelift of https://gist.github.com/uhop/21fa11bf387e234e0d79bf90d7b08735
<!DOCTYPE html>
<html>
<head>
<title>DnD test bed - grouping</title>
<link rel="stylesheet" href="./dnd.css" />
</head>
<body>
<h1>DnD test bed - grouping</h1>
<div class="container">
<div class="item dnd-item dnd-handle">One</div>
@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 / ListHead.js
Last active October 19, 2020 02:59
Simple yet complete implementation of a double-linked list that reuses objects building lists with their properties.
'use strict';
class ListHead {
constructor(head = null, next = 'next', prev = 'prev') {
if (head instanceof ListHead) {
({nextName: this.nextName, prevName: this.prevName, head: this.head} = head);
return;
}
this.nextName = next;
this.prevName = prev;
@uhop
uhop / detectWebp.js
Last active July 4, 2020 15:28
Image-related utilities for use in browsers.
let flag;
const detectWebp = () => {
if (typeof flag == 'boolean') return flag;
const canvas = document.createElement('canvas');
flag = !!(canvas.getContext && canvas.getContext('2d') && /^data:image\/webp;/.test(canvas.toDataURL('image/webp')));
return flag;
};
export default detectWebp;
@uhop
uhop / README.md
Created April 20, 2020 21:39
Access to S3 bucket by roles

What

We need to setup an S3 bucket so we can use AWS JS SDK to upload files from a web application only for logged in users.

We already have a Cognito user pool, e.g., self-managed, and/or tied to a corporate SSO or social networks. Users may have different permissions depending on custom groups they are on. There is an app client, which is used to authenticate users in our web app.

How