Skip to content

Instantly share code, notes, and snippets.

View davidglezz's full-sized avatar
😃
Happy

David Gonzalez davidglezz

😃
Happy
View GitHub Profile
@davidglezz
davidglezz / gh-org-top-contributors.ts
Last active March 28, 2025 13:30
List the top contributions of an organization
#!/usr/bin/env node
/**
* Create top contributors list for a GitHub organization.
* Usage: ./gh-org-top-contributors.ts <org-name>
*/
const accessToken = process.env.GITHUB_TOKEN || process.env.GH_TOKEN || 'your-token'
const headers = {
Authorization: `token ${accessToken}`,
@davidglezz
davidglezz / jest-to-vitest.sh
Last active March 27, 2025 15:06
Jest to vitest migration script
#!/bin/bash
# This is a copy of:
# https://gist.github.com/wojtekmaj/6defa1f358daae28bd52b7b6dbeb7ab6
# read the comments
# Also: npx codemod jest/vitest
# Ensure we're working on the latest version of the main branch
# git switch develop
# git fetch
@davidglezz
davidglezz / replace-v-t-syntax.js
Last active March 24, 2025 17:09
Replace v-t="x" attribute with $t(x) function in vue files
const fs = require('node:fs')
const path = require('node:path')
const glob = require('glob')
// Find all Vue files
const vueFiles = glob.sync(path.join(__dirname, '../**/*.vue'))
vueFiles.forEach(filePath => {
let content = fs.readFileSync(filePath, 'utf8')
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
/**
* A class for storing and retrieve compressed objects into local storage.
*/
export class CompressedStorage {
async get(key: string) {
const base64 = localStorage.getItem(key);
if (base64 === null) {
return null;
}
const blob = await this.fromBase64Url(base64);
@davidglezz
davidglezz / b256.ts
Last active March 19, 2024 22:32
Basa256 encoder / decoder
// A simple way to store binary data inside a js/ts file with a density of 1 char per byte.
// Even though each char takes 2 bytes.
const b256enc = (buff: Uint8Array) => [...buff].map(i => String.fromCodePoint(i + 192)).join('');
const b256dec = (str: string) => str.split('').map(c => c.charCodeAt(0) - 192);
// Example 1: Basic usage
const data = new Uint8Array([ 127, 127, 168, 226, 120, 62, 44, 146, 82, 213, 0, 30 ]);
const encoded = b256enc(data);
console.log(encoded); // 'ĿĿŨƢĸþìŒĒƕÀÞ'
@davidglezz
davidglezz / uuid-pack.ts
Last active September 11, 2023 13:59
UUID pack/unpack
export function packUUID(uuid: string): string {
let v;
let bytes = '';
// Parse ########-....-....-....-............
bytes += String.fromCharCode((v = parseInt(uuid.slice(0, 8), 16)) >>> 24);
bytes += String.fromCharCode((v >>> 16) & 0xff);
bytes += String.fromCharCode((v >>> 8) & 0xff);
bytes += String.fromCharCode(v & 0xff);
@davidglezz
davidglezz / css-loader.html
Last active September 9, 2023 14:50
Basic CSS Loader
<div class="loader"></div>
<style>
.loader {
--size: 5rem;
--weight: .5rem;
--background: rgba(127, 127, 127, .1);
--color: rgba(127, 127, 127, .9);
--duration: 1s;
position: fixed;
top: calc(50% - var(--size) / 2);
@davidglezz
davidglezz / unwatchOrgRepos.js
Last active October 3, 2021 16:32
Github: Unsubscribe from all "orgName" watched repositories
/**
* Unsubscribe from all "orgName" repositories in https://github.com/watching
*
* https://github.com/isaacs/github/issues/641
* @param string orgName
*/
function unwatchOrgRepos(orgName) {
if (!window.location.href.startsWith('https://github.com/watching')) {
throw new Error('This script is intended to be run in "https://github.com/watching"')
@davidglezz
davidglezz / RelativeTime.ts
Last active May 24, 2021 07:48
RelativeTime formatter inspired by DayJs
/**
* Locale strings
* You can get it from https://github.com/iamkun/dayjs/blob/dev/src/locale/
*/
const loc = {
future: 'in %s',
past: '%s ago',
s: 'a few seconds',
m: 'a minute',