Skip to content

Instantly share code, notes, and snippets.

@addyosmani
addyosmani / visibly.js
Created August 3, 2011 12:44
Cross-browser Page Visibility API polyfill
/*!
* isVis - v0.5.5 Aug 2011 - Page Visibility API Polyfill
* Copyright (c) 2011 Addy Osmani
* Dual licensed under the MIT and GPL licenses.
*/
(function () {
window.visibly = {
b: null,
q: document,
@joepie91
joepie91 / es-modules-are-terrible-actually.md
Last active July 12, 2024 23:04
ES Modules are terrible, actually

ES Modules are terrible, actually

This post was adapted from an earlier Twitter thread.

It's incredible how many collective developer hours have been wasted on pushing through the turd that is ES Modules (often mistakenly called "ES6 Modules"). Causing a big ecosystem divide and massive tooling support issues, for... well, no reason, really. There are no actual advantages to it. At all.

It looks shiny and new and some libraries use it in their documentation without any explanation, so people assume that it's the new thing that must be used. And then I end up having to explain to them why, unlike CommonJS, it doesn't actually work everywhere yet, and may never do so. For example, you can't import ESM modules from a CommonJS file! (Update: I've released a module that works around this issue.)

And then there's Rollup, which apparently requires ESM to be u

@Howard3
Howard3 / github_copy_tag_button.js
Last active May 3, 2023 01:20
userscript - Github: Add "Copy" button next to package tags
// ==UserScript==
// @name GitHub Docker Image Tag Copy Button
// @description Adds a "copy" icon next to each Docker image tag on GitHub pages that list published Docker images.
// @version 2
// @match https://github.com/*
// @grant GM_setClipboard
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/js/all.min.js
// @license MIT
// @author Howard D. Lince III
// @supportURL https://twitter.com/HowardL3
@Howard3
Howard3 / README.md
Last active July 5, 2024 08:17
Postgres - fix sequences after importing data

This script is designed to help reset all sequences in a PostgreSQL database to their correct values based on existing data in the tables.

Purpose

In PostgreSQL, sequences are used to auto-increment integer columns in tables. These sequences need to have their "last value" accurately set to avoid conflicts when inserting new rows into the table. This can become an issue, for example, when data is imported into the database and the sequences are not updated accordingly, leading to unique constraint

How it Works

The script works by iterating over each table in the current schema of the PostgreSQL database. For each table, it dynamically looks up the associated sequence and the column that the sequence is used for. It then finds the maximum value in that column and sets the "last value" of the sequence to this maximum value.

@bilalmughal
bilalmughal / ec2_graviton_dl_bootstrap.sh
Last active June 6, 2024 06:56
This script automates the setup of an Amazon EC2 Graviton ARM-based instances for deep learning tasks. It takes care of installing essential utilities, setting up latest Nvidia drivers and CUDA 12.2 toolkit and cuDNN library, and build PyTorch from source. The step-by-step guided can be checked here. https://jumpshare.com/blog/deep-learning-on-a…
#!/bin/bash
set -e # Exit on any error
# Check if required arguments are provided
if [ -z "$REGION" ] || [ -z "$SECURITY_GROUPS" ] || [ -z "$KEY_PAIR" ] || [ -z "$SUBNET" ]; then
echo "Error: You must provide REGION, SECURITY_GROUPS, KEY_PAIR, and SUBNET as environment variables."
echo "Example:"
echo " export REGION=us-east-1"
echo " export SECURITY_GROUPS=sg-12345678,sg-87654321"
echo " export KEY_PAIR=my-key-pair"