Skip to content

Instantly share code, notes, and snippets.

View alexsasharegan's full-sized avatar

Alex Regan alexsasharegan

View GitHub Profile
@alexsasharegan
alexsasharegan / nuke_s3.go
Created October 1, 2024 04:12
Drop all your S3 buckets like it's hot 🔥
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"log"
"os"
"os/exec"
@alexsasharegan
alexsasharegan / recovery.sh
Created February 10, 2020 16:36
System76 recovery script for nvidia errors.
sudo cryptsetup luksOpen /dev/nvme0n1p3 cryptdata
sudo lvscan
sudo vgchange -ay
sudo mount /dev/mapper/data-root /mnt
sudo mount /dev/nvme0n1p1 /mnt/boot/efi
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo cp /etc/resolv.conf /mnt/etc/
sudo chroot /mnt
@alexsasharegan
alexsasharegan / WrappedError.ts
Created January 3, 2020 17:51
Wrap errors using a linked list. Error burritos 🌯
export class WrappedError<ErrKind = any> extends Error implements Iterable<WrappedError | ErrKind> {
previous: ErrKind | null = null;
guid: Guid;
constructor(message: string, previous?: ErrKind) {
super(message);
// We update the error's name to distinguish it from the base Error.
this.name = this.constructor.name;
this.guid = `<${this.name}:empty>`;
// We add our reference to the original error value (if provided).
/**
* Creates a mapped type from the `Subject`
* that excludes all members with types
* that extend the `ExcludeType`.
*/
type ExcludeBy<Subject, ExcludeType> = {
[P in {
[K in keyof Subject]: Subject[K] extends ExcludeType ? never : K
}[keyof Subject]]: Subject[P]
};
Screen 0: minimum 8 x 8, current 5760 x 2160, maximum 32767 x 32767
HDMI-0 disconnected (normal left inverted right x axis y axis)
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
DP-2 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 597mm x 336mm
3840x2160 60.00*+ 29.98
2560x1440 59.95
1920x1200 59.88
1920x1080 60.00 59.94 50.00 23.98
1680x1050 59.95
@alexsasharegan
alexsasharegan / idleMap.ts
Created June 3, 2019 18:39
Schedule multiple promise-based tasks on idle browser time.
port async function idleMap<Item, Output>(
iterable: Iterable<Item>,
op: (item: Item) => Promise<Output>
): Promise<Output[]> {
return new Promise((resolve) => {
let iter = iterable[Symbol.iterator]();
let buf: Output[] = [];
async function process(deadline: RequestIdleCallbackDeadline) {
do {
@alexsasharegan
alexsasharegan / intersection-support.js
Last active May 16, 2019 22:38
Adds a window global for IntersectionObserver support at `Symbol.for("@@support.IntersectionObserver")`.
window[Symbol.for("@@support.IntersectionObserver")] = (function(w, k) {
let y = k.io in w && k.en in w && k.ra in w[k.en][k.pr];
if (!y) {
return false;
}
if (!(k.ix in w[k.en][k.pr])) {
Object.defineProperty(w[k.en][k.pr], k.ix, {
get() {
return this[k.ra] > 0;
},
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Change Event</title>
<style>
body {
:root {
--base-unit: 1rem;
--margin: var(--base-unit);
}
.m {
margin-top: var(--margin-top, var(--margin-y, var(--margin)));
margin-right: var(--margin-right, var(--margin-x, var(--margin)));
margin-bottom: var(--margin-bottom, var(--margin-y, var(--margin)));
margin-left: var(--margin-left, var(--margin-x, var(--margin)));
@alexsasharegan
alexsasharegan / Bits.js
Last active December 8, 2018 01:22
Bitwise manipulations wrapped in a class with semantically meaningful methods.
export class Bits {
static get Nil() {
return 0;
}
static get All() {
// Flip the sign bit out of all bits engaged.
return ~0 ^ (1 << 31);
}