Bing Wallpaper and Lockscreen script

Here is a simple script to update your wallpaper and your lockscreen every two hours!
Enjoy!

#!/bin/bash

# Bing wallpapers
# Cesário Garcia Mil-Homens
# cesario@cesariogarcia.com
# https://www.cesariogarcia.com

# 1. Execute this script the first time and set "bingwallpaper.jpg" as wallpaper and lockscreen
# 2. Config $wallpaperPath (line 13 of this script) for the full path of where you want "bingwallpaper.jpg" to be (it should be on the user Pictures folder)
# 3. On the terminal execute the following script, this will check for new updates every two hours
# crontab -l | { cat; echo "0 */2 * * * /bin/bash /home/cesario/Programs/bingwallpapers.sh >/dev/null 2>&1"; } | crontab -

wallpaperPath="/home/cesario/Pictures"

wget -q --spider http://google.com

if [ $? -eq 0 ]; then
    echo "Online"
	imageName=$(curl -s "https://www.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1&mkt=en-US" | grep -o -m 1 "/az/hprichbg/rb/.*._1366x768.jpg")
    prefix="/az/hprichbg/rb/";
	imageName=${imageName#$prefix};
	suffix="_1366x768.jpg";
	imageName=${imageName%$suffix};
		if [ -e $wallpaperPath"/"$imageName"_1366x768.jpg" ]
		then
			echo "$imageName found."
		else
			echo "$imageName not found."
			wget "https://www.bing.com/az/hprichbg/rb/"$imageName"_1366x768.jpg" -P $wallpaperPath
			cp $wallpaperPath"/"$imageName"_1366x768.jpg" $wallpaperPath"/"bingwallpaper.jpg
		fi
else
    echo "Offline"
fi

Validação de NIF em C++

Algoritmo de validação de um NIF em C++

#include <iostream>

int nif, n, nif_d[8], resto, dig_controlo, verificacao;
int resultado=0;

int main(){
  printf("Insira o seu NIF \n");
  scanf("%d",&nif);

  //Separação de dígitos num array
  for(n=9;n>=1;n--){
    nif_d[n]=nif%10;
    nif/=10;
  }

  //Atribui o último dígito à variável verificacao
  verificacao = nif_d[9];

  //Verificar se o NIF possuí 9 dígitos e consequente verificação dos primeiros dígitos
  if((nif<=999999999||nif>99999999)&&((nif_d[1]==1||nif_d[1]==2||nif_d[1]==3)||(nif_d[1]==4&&nif_d[2]==5)||(nif_d[1]==5)||(nif_d[1]==6)||(nif_d[1]==7&&nif_d[2]==0)||(nif_d[1]==7&&nif_d[2]==4)||(nif_d[1]==7&&nif_d[2]==5)||(nif_d[1]==7&&nif_d[2]==1)||(nif_d[1]==7&&nif_d[2]==2)||(nif_d[1]==7&&nif_d[2]==7)||(nif_d[1]==7&&nif_d[2]==8)||(nif_d[1]==7&&nif_d[2]==9)||(nif_d[1]==8)||(nif_d[1]==9&&nif_d[2]==0)||(nif_d[1]==9&&nif_d[2]==1)||(nif_d[1]==9&&nif_d[2]==8)||(nif_d[1]==9&&nif_d[2]==9))){

    //Calcular o valor da soma da multiplicação dos dígitos
    for(n=9;n>=2;n--){
      resultado+=nif_d[10-n]*n;
    }

    //Calcular o valor do resto
    resto=resultado%11;

    //Cálculo do dígito de controlo
    if(resto<2){
      dig_controlo=0;
    }else{
      dig_controlo=11-resto;
    }

    //Verificação com o dígito de controlo
    if(dig_controlo==verificacao){
      printf("O NIF é válido\n");
    }else{
      printf("O NIF é inválido\n");
    }
  }else{
    printf("O NIF é inválido\n");
  }
}

PBLS4Lin v1.0 – Peerblock for Linux and Transmission

Um script para linux que permite utilizar as listas do Peerblock.
Estas listas podem ser utilizadas no Transmission.

#!/bin/bash

#This script creates the same lists as peerblock http://www.peerblock.com/, it outputs a file that you
#can use on Transmission under Edit -&gt; Preferences -&gt; Privacy -&gt; Blocklist. In the first time copy the
#http link and use it. All lists are from http://www.iblocklist.com
#This script was created by Cesário Garcia Mil-Homens - http://www.cesariogarcia.com just for the fun.
#PBLS4Lin - v1.0

#CONFIGURATION - WARNING THE DIRECTORIES SHOULD ALREADY EXIST.

#Insert here the dir where is your Dropbox/Google Drive/etc public folders or you local server with apache
#Using Dropbox
#destination_folder=&quot;$HOME/Dropbox/Public&quot;
#Using localhost
destination_folder=&quot;/var/www/peerblock&quot;

#Insert here your own temporary download folder, do not use /tmp
temp=&quot;$HOME/tmp&quot;

#DO NOT EDIT BELOW THIS LINE

clear
echo &quot;Peerblock Lists - Automatic Uptades for Transmission&quot;
echo &quot;My destination folder is $destination_folder and my temporary download folder is $temp is this correct? (y/n)&quot;

function download() {
	sudo cd $temp
	sudo wget -O - &quot;http://list.iblocklist.com/?list=bt_ads&amp;fileformat=p2p&amp;archiveformat=gz&quot; &gt; bt_ads.txt.gz
	sudo wget -O - &quot;http://list.iblocklist.com/?list=bt_level1&amp;fileformat=p2p&amp;archiveformat=gz&quot; &gt; bt_level1.txt.gz
	sudo wget -O - &quot;http://list.iblocklist.com/?list=bt_spyware&amp;fileformat=p2p&amp;archiveformat=gz&quot; &gt; bt_spyware.txt.gz
	sudo gunzip *.gz
	}

function combine() {
	sudo cat bt_ads.txt bt_level1.txt bt_spyware.txt &gt; peerblock.txt
	sudo rm bt_ads.txt
	sudo rm bt_level1.txt
	sudo rm bt_spyware.txt
	 }

function upload() {
	sudo mv -f peerblock.txt $destination_folder
	}

read op

case $op in
	y) download; combine; upload;;
	*) exit;;
esac