Skip to content

Instantly share code, notes, and snippets.

View mendelgusmao's full-sized avatar
😅
what's up?

Mendelson Gusmão mendelgusmao

😅
what's up?
View GitHub Profile
let table = [...document.querySelectorAll('table[width="550"] > tbody')][1];
let items = [...table.querySelectorAll("tr")].map(
tr => [...tr.querySelectorAll("td")].map(
td => /good/.test(td.querySelector("img")?.src) || td.innerText || false
)
).map(
it => [it.slice(0, 2), it.slice(3, 5)]
)
.flat()
.filter(it => it.length);
@mendelgusmao
mendelgusmao / gist:2356310
Created April 11, 2012 01:53
high performance URL shortener on steroids using nginx, redis and lua
# based on http://uberblo.gs/2011/06/high-performance-url-shortening-with-redis-backed-nginx
# using code from http://stackoverflow.com/questions/3554315/lua-base-converter
# "database scheme"
# database 0: id ~> url
# database 1: id ~> hits
# database 2: id ~> [{referer|user_agent}]
# database 3: id ~> hits (when id is not found)
# database 4: id ~> [{referer|user_agent}] (when id is not found)
# database 5: key "count" storing the number of shortened urls; the id is generated by (this number + 1) converted to base 62
@mendelgusmao
mendelgusmao / main.go
Last active November 5, 2022 12:57
.zsh_history merge+remove duplicate lines
package main
import (
"fmt"
"io/ioutil"
"os"
"regexp"
"sort"
"strconv"
"strings"
@mendelgusmao
mendelgusmao / gist:5823291
Last active March 28, 2021 08:08
BTSync / BitTorrent Sync behind nginx
# take one
# subdirectory (one server, multiple services)
location /btsync/ {
rewrite ^/btsync/gui(.*) /btsync$1 last;
proxy_pass http://127.0.0.1:8888/gui/;
proxy_redirect /gui/ /btsync/;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@mendelgusmao
mendelgusmao / btsync
Last active March 4, 2021 15:37
init.d script for btsync (based on another script built to run dropbox)
#!/bin/sh
### BEGIN INIT INFO
# Provides: btsync
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Multi-user daemonized version of btsync.
/**
* Calcula o rendimento de poupança de um valor em um período específico.
*
* @param {value} input O valor a ser calculado.
* @param {initialDate} input Data inicial.
* @param {finalDate} input Data final.
* @return O valor corrigido.
* @customfunction
*/
function CORRECAO_POUPANCA(value, initialDate, finalDate = now()) {
@mendelgusmao
mendelgusmao / wa.random.rb
Last active July 10, 2017 08:01
Random Winamp playlist using ActiveWinamp, Ruby and Win32OLE
require "win32ole"
count = 100
ttl = 86400
cache_file = "wa.random.cache"
query = [
'type = "0"',
'length > "2:00"',
'title NOTHAS "intro"',
minSpeed=1500
maxSpeed=5500
highTemp=70
normalTemp=40
output=/sys/devices/platform/applesmc.768/fan1_output
manual=/sys/devices/platform/applesmc.768/fan1_manual
currentSpeed=$(cat $output)
package xml
import (
"testing"
)
var (
fooXML = `
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root xmlns="urn:ietf:params:xml:ns:root-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:root-1.0 root-1.0.xsd">
@mendelgusmao
mendelgusmao / gist:6076361
Last active December 20, 2015 05:09
updates /etc/hosts whenever a host ip changes useful for creating host aliases usage: update-hosts <host_alias> <host_ip>
hosts=/etc/hosts
host=$1
ip=$2
if [ "$ip" = "" ]; then
ip=$(wget -qO- http://checkip.dyndns.org | cut -f2 -d":" | cut -f1 -d"<" | sed "s/ //")
fi
line=$(grep $host $hosts)