Skip to content

Instantly share code, notes, and snippets.

View rodrigopolo's full-sized avatar

Rodrigo Polo rodrigopolo

View GitHub Profile
@rodrigopolo
rodrigopolo / readme.md
Last active June 29, 2024 21:12
FlightAware path to KML

absolute# FlightAware path to KML A simple JS ES5 snipet to get a KML file from a flight path in FlightAware, can be used as a bookmarklet:

Bookmark JS Code

javascript:!function()%7Bvar%20e%2Ct%2Cl%2Ci%2Cn%2Co%2Ca%3D(o%3Ddocument.title.match(%2F%5C((%5Ba-z0-9%5D%2B)%5C)%2Fi))%3Fo%5B1%5D%3Adocument.title%2Cr%3D%5B%27%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%27%2C%27%3Ckml%20xmlns%3D%22http%3A%2F%2Fwww.opengis.net%2Fkml%2F2.2%22%3E%27%2C%22%3CDocument%3E%22%2C%22%3Cname%3E%22%2Ca%2C%22%3C%2Fname%3E%22%2C%27%3CStyle%20id%3D%22lineStyle%22%3E%27%2C%22%3CLineStyle%3E%22%2C%22%3Ccolor%3Eff0000ff%3C%2Fcolor%3E%22%2C%22%3Cwidth%3E4%3C%2Fwidth%3E%22%2C%22%3C%2FLineStyle%3E%22%2C%22%3CPolyStyle%3E%3Cfill%3E0%3C%2Ffill%3E%3C%2FPolyStyle%3E%22%2C%22%3C%2FStyle%3E%22%2C%22%3CPlacemark%3E%22%2C%22%3Cname%3E%22%2Ca%2C%22%3C%2Fname%3E%22%2C%22%3Cdescription%3E%22%2Cdocument.title%2C%22%5Cn%22%2Cdocument.URL%2C%22%3C%2Fdescription%3E%22%2C%22%3CstyleUrl%3E%23lineStyle%3C%2FstyleUrl%3E%22%2C%22%3CLine
@rodrigopolo
rodrigopolo / downloader.sh
Last active May 16, 2024 18:19
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;