Skip to content

Instantly share code, notes, and snippets.

View rodrigopolo's full-sized avatar

Rodrigo Polo rodrigopolo

View GitHub Profile
@rodrigopolo
rodrigopolo / downloader.sh
Last active April 19, 2024 06:10
Twitter/X Space Downloader
#!/usr/bin/env bash
#
# Twitter/X Space Downloader Bash Script
# Copyright (c) 2024 Rodrigo Polo - rodrigopolo.com - The MIT License (MIT)
#
# Check if a stream URL is provided
if [ -z "$1" ]; then
echo "Usage: $0 <stream_url>"
-- Meters: 6371000, Miles: 3959000
DELIMITER $$
DROP FUNCTION IF EXISTS `DISTANCE_BETWEEN` $$
CREATE FUNCTION DISTANCE_BETWEEN (
lat1 float(10,6), lon1 float(10,6),
lat2 float(10,6), lon2 float(10,6)
) RETURNS DOUBLE DETERMINISTIC
BEGIN
return ACOS(SIN(lat1*PI()/180)*SIN(lat2*PI()/180)
+ COS(lat1*PI()/180)*COS(lat2*PI()/180)
#!/bin/bash
# originally from
# https://raw.githubusercontent.com/mattbrock/mattbrock/master/vCard_photo_extractor/vCard_photo_extractor.sh
# changes:
# - made to work with macOS's base64 (uses -D not -d)
# - does not convert to fixed resolution
# - uses identify to remove invalid images
# - handles special characters better
@rodrigopolo
rodrigopolo / CUIValidation.js
Created January 19, 2019 07:55
Simple and more elaborated Guatemalan CUI validation
// Simple
function valCUI(cui){
var nd, v, t=0, dl, dn = [17,8,16,16,13,14,19,8,24,20,9,29,32,22,8,17,12,5,10,11,7,17];
if(nd = /^(\d{8})(\d{1})(\d{2})(\d{2})$/.exec(cui.replace(/\D/g,''))){
v = parseInt(nd[2]);
for (var i = 0; i < nd[1].length; i++){
t += nd[1][i] * (i + 2);
}
if((t % 11) === v){
if(dl=dn[nd[3]-1]){
@rodrigopolo
rodrigopolo / brew-install.sh
Created November 5, 2017 03:47 — forked from jsz0/brew-install.sh
my default brew/cask installs
# firsrun:
# install xcode-cli-tools
# xcode-select --install
# install homebrew
# ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# install caskroom
# brew install caskroom/cask/brew-cask
# update/install:
@rodrigopolo
rodrigopolo / Guatemala NIT validation in JavaScript
Last active August 15, 2023 13:43
A simple function to validate guatemalan NIT using both, regex and math.
/*
* These functions validate whether a string corresponds to a Guatemalan tax
* identification number, also known as 'Numero de Identificación
* Tributaria' (NIT). They employ regular expressions for this purpose, utilizing
* the metacharacter shorthand '\d' instead of '[0-9]' to save space.
* The approach is highly optimized for bandwidth reduction; readability and
* maintenance are not prioritized over optimization. You can observe how this
* regular expression works through the following links:
* - https://regex101.com/r/d5YFJE/1
* - https://regexr.com/7ieic
@rodrigopolo
rodrigopolo / HumanBandwidth.js
Last active October 14, 2015 16:18
Human readable bandwith
function bandWidth(bits) {
var unit = 1000;
if (bits < unit) return (bits % 1 === 0 ? bits : bits.toFixed(2)) + "B";
var exp = parseInt(Math.log(bits) / Math.log(unit));
var pre = "KMGTPE"[exp-1] + 'bps';
var n = bits / Math.pow(unit, exp);
return (n % 1 === 0 ? n : n.toFixed(2))+pre;
}
@rodrigopolo
rodrigopolo / humanbytes.js
Last active October 14, 2015 16:18
Human readable bytes size in JavaScript
function formatSize(bytes, si) {
var unit = si ? 1000 : 1024;
if (bytes < unit) return (bytes % 1 === 0 ? bytes : bytes.toFixed(2)) + "B";
var exp = parseInt(Math.log(bytes) / Math.log(unit));
console.log(exp)
var pre = (si ? "kMGTPE" : "KMGTPE")[exp-1] + (si ? "" : "i")+'B';
var n = bytes / Math.pow(unit, exp);
return (n % 1 === 0 ? n : n.toFixed(2))+pre;
}
@rodrigopolo
rodrigopolo / gist:d009299c849a7c973a34
Created February 10, 2015 10:23
Tasa de Cambio Banco de Guatemala USD Q Banguat
<?php
// nusoap-0.9.5
require 'lib/nusoap.php';
$client = new nusoap_client('http://www.banguat.gob.gt/variables/ws/TipoCambio.asmx?WSDL', true);
$error = $client->getError();
if($error){
echo $error;
@rodrigopolo
rodrigopolo / gist:62c21b25a23d34fee6a0
Created February 10, 2015 05:54
Calc image resize dimensions in JS
function calcResize(op){
var ratio = Math[(op.fill)?'max':'min'](op.to.width/op.from.width,op.to.height/op.from.height);
var r = {
width: Math.round(op.from.width * ratio),
height: Math.round(op.from.height * ratio)
}
r.x = Math.round((op.to.width - r.width) / 2);
r.y = Math.round((op.to.height - r.height) / 2);
return r;
}