Skip to content

Instantly share code, notes, and snippets.

@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;

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 / static-server.mjs
Last active May 12, 2023 17:22
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 'http';
import fs from 'fs';
import path from 'path';
const fsp = fs.promises;
@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 / 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

@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',
@uhop
uhop / print.html
Last active November 29, 2022 23:35
The way to print slides as PDF.
<!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>
// 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 / getAWS.js
Last active June 17, 2021 22:24
Script to set up AWS environment according to its profile.
'use strict';
const AWS = require('aws-sdk');
let profile = process.env.LAMBDA_TASK_ROOT && process.env.AWS_EXECUTION_ENV ? '' : 'default';
const profileIndex = process.argv.indexOf('--profile');
if (profileIndex > 0 && profileIndex + 1 < process.argv.length) {
profile = process.argv[profileIndex + 1];
}