Skip to content

Instantly share code, notes, and snippets.

View diogoalexsmachado's full-sized avatar

Diogo Machado diogoalexsmachado

View GitHub Profile
@diogoalexsmachado
diogoalexsmachado / docker-compose.yml
Created February 20, 2024 01:49
Docker Compose - Radarr + Sonarr + Bazarr + Jackett + Deluge + Plex Server
version: "3.4"
services:
deluge:
container_name: deluge
image: linuxserver/deluge:latest
restart: unless-stopped
environment:
- PUID=${PUID} # default user id, defined in .env
- PGID=${PGID} # default group id, defined in .env
- TZ=${TZ} # timezone, defined in .env
@diogoalexsmachado
diogoalexsmachado / startup_script.sh
Created February 20, 2024 01:35
Startup Script for WD Home NAS + Docker compose start
#!/bin/bash
# Wait for LAN to be available
while ! ping -c 1 192.168.0.1 >/dev/null; do
sleep 1
done
# Change directory
cd Desktop/docker_radarr/
@diogoalexsmachado
diogoalexsmachado / nif-validator.js
Last active June 1, 2021 08:11
Portuguese NIF Validation
function validateNif(nif){
// validation reference:
// http://pt.wikipedia.org/wiki/N%C3%BAmero_de_identifica%C3%A7%C3%A3o_fiscal
var error=0;
if (
nif.substr(0,1) != '1' && // pessoa singular
nif.substr(0,1) != '2' && // pessoa singular
nif.substr(0,1) != '3' && // pessoa singular
nif.substr(0,2) != '45' && // pessoa singular não residente
function formatBytes(bytes) {
var marker = 1024; // Change to 1000 if required
var decimal = 3; // Change as required
var kiloBytes = marker; // One Kilobyte is 1024 bytes
var megaBytes = marker * marker; // One MB is 1024 KB
var gigaBytes = marker * marker * marker; // One GB is 1024 MB
var teraBytes = marker * marker * marker * marker; // One TB is 1024 GB
// return bytes if less than a KB
if(bytes < kiloBytes) return bytes + " Bytes";
/*
* sanitize HTML with jQuery based on whitelist
* example:
* sanitizer.sanitize('<a href="foo" class="bar">aaa</a><script>alert("...")</script>', {'a': ['href'], 'strong': []})
* returns '<a href="foo">aaa</a>'
*/
var sanitizer = {};
(function($) {
function trimAttributes(node, allowedAttrs) {
public class PropertiesToConstantsGenerator {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
InputStream inputStream =PropertiesToInterfaceGenerator.class.getClassLoader().getResourceAsStream("saf_en.properties");
if(null != inputStream ){
properties.load(inputStream);
}
generate(properties);
}
String nome= userDao.getNomeCompleto(2L);
String nomeFiltered="";
for (int i=0;i<str.length();i++) {
//only allows letters from ASCII value
if (str.charAt(i)>64 && str.charAt(i)<=122) {
nomeFiltered=nomeFiltered+str.charAt(i);
}
}
@diogoalexsmachado
diogoalexsmachado / gist:0cfd20374779b50384d4a3b7dfc68298
Created November 15, 2019 15:08
completeemail jquery validator method
// validação email com mais segurança
$.validator.addMethod("completeemail",
function(value, element) {
return /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(value);
},
"O endereço e-mail não é válido"
);
@diogoalexsmachado
diogoalexsmachado / matrix.sh
Created December 19, 2018 10:31
useless but funny :)
#!/bin/bash
#
# matrix: matrix-ish display for Bash terminal
# Author: Brett Terpstra 2012 <http://brettterpstra.com>
# Contributors: Lauri Ranta and Carl <http://blog.carlsensei.com/>
#
# A morning project. Could have been better, but I'm learning when to stop.
### Customization:
blue="\033[0;34m"
# No inicio.jsp
<input type="hidden" id="controloAlteracoes" value="0">
# no acesso.js (chamado no inicio.jsp)
$("#controloAlteracoes").change(function () {
if ($(this).val() == 1) {
toastr.clear();
toastr["info"]("Existem informações não guardadas", "Atenção", {
"closeButton": true,
"debug": false,