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 / 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',
@davidglezz
davidglezz / .gitconfig
Created February 22, 2020 10:22 — forked from pksunkara/config
Sample of git config file (Example .gitconfig)
[user]
name = Pavan Kumar Sunkara
email = pavan.sss1991@gmail.com
username = pksunkara
[core]
editor = vim
whitespace = fix,-indent-with-non-tab,trailing-space,cr-at-eol
excludesfile = ~/.gitignore
[sendemail]
smtpencryption = tls
@davidglezz
davidglezz / gitconfig.ini
Created February 22, 2020 10:21 — forked from tdd/gitconfig.ini
Nice, useful global Git configuration
# Put this in your ~/.gitconfig or ~/.config/git/config
# Windows users: "~" is your profile's home directory, e.g. C:\Users\<YourName>
[user]
name = Your Full Name
email = your@email.tld
[color]
# Enable colors in color-supporting terminals
ui = auto
[alias]
# List available aliases
// IsValidEan13 return true if given ean13 number is valid
func IsValidEan13(code string) bool {
if len(code) != 13 {
return false
}
oddSum := 0
evenSum := 0
for i, n := range code[:12] {
digit := int(n - '0')
@davidglezz
davidglezz / README.md
Created September 28, 2017 18:58 — forked from joyrexus/README.md
Node.js streams demystified

A quick overview of the node.js streams interface with basic examples.

This is based on @brycebaril's presentation, Node.js Streams2 Demystified

Overview

Streams are a first-class construct in Node.js for handling data.

Think of them as as lazy evaluation applied to data.

@davidglezz
davidglezz / index.html
Created July 2, 2017 14:11 — forked from sandeep1995/index.html
Convert Callbacks to Promise to Async/Await
<!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>Document</title>
<style media="screen">
html,body{
font-family: monospace;