giovedì 10 dicembre 2015

Automatically clean and format a file name for Web in Bash

Hello there!

You want to automatically format and clean a file name before upload on a website?
Do you want to remove spaces, symbol and accents from a filename automatically, or in batch?

These command will strip anything that's not good to have in a web filename and copy your file to the new file! You can rename original file by change last "cp" with "mv"

#!/bin/bash
FILE=$1
# Remove path
FILECLEAN="${FILE##*/}"
# Find extension (sometimes useful)
FILEXT="${FILECLEAN##*.}"
# Find filename without extension

FILENAME="${FILECLEAN%.*}"

# Convert spaces in dash

FILENAME="${FILENAME// /-}"

# Remove symbols and keep dash and underscores

FILENAME="${FILENAME//[^[:alnum:]_-]/}"

# Remove eventual double dashes from filename

FILENAME="$(echo $FILENAME | tr -s '-')"

# First letter uppercase and other lowercase

FILENAME="$(tr '[:lower:]' '[:upper:]' <<< ${FILENAME:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${FILENAME:1})"


cp "$FILE" "$FILENAME"".""$FILEXT"

Save it into a file with .sh extension, then do this to make it executable:
chmod +x file.sh

Execute with:
./file.sh file

You can even bath the process with a script like this:
#!/bin/bash

# Rimuovo i *.jpg etc dalla lista dei FILE

shopt -s nullglob
for FILE in *; do   
   # Remove path
   FILECLEAN="${FILE##*/}"  
   # Find extension (sometimes useful) 
   FILEXT="${FILECLEAN##*.}"   
   # Find filename without extension
   FILENAME="${FILECLEAN%.*}"
   # Convert spaces in dash   
   FILENAME="${FILENAME// /-}"
   # Remove symbols and keep dash and underscores   
   FILENAME="${FILENAME//[^[:alnum:]_-]/}"   
   # Remove eventual double dashes from filename   
   FILENAME="$(echo $FILENAME | tr -s '-')"   
   # First letter uppercase and other lowercase  
    FILENAME="$(tr '[:lower:]' '[:upper:]' <<< ${FILENAME:0:1})$(tr '[:upper:]' '[:lower:]' <<< ${FILENAME:1})"

   cp "$FILE" "$FILENAME"".""$FILEXT"
done

Convert PDF to JPEG, JPG, PNG or other images format Mac OSX

Hello there,

You want to convert PDF to image for free? You are in the right place!
You can even automate the process in batch!

We will use Brew to install all the necessary stuff to convert PDF in JPEG, JPG, PNG or other images format.

1. Go to http://brew.sh/ and paste into a terminal the installation string:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Install ImageMagick with Brew:
brew install imagemagick

3. Install GhostScript with Brew: (used for PDF conversion)
brew install ghostscript

4. Ready to go!
Type name of file you want to convert followed by save name of the converted file and the format you want:
PDF to JPG
convert SourceFile.pdf DestinationFile.jpg

PDF to PNG
convert SourceFile.pdf DestinationFile.png

If converted images have a black background instead of white, you have to set default background as white and remove transparency:
-background white -alpha remove

So command will be:
convert SourceFile.pdf -background white -alpha remove DestinationFile.png

Resize output images:
convert SourceFile.pdf -resize <Width>x<Height> DestinationFile.jpg

We can specify only one dimension or both like:

Resize as 600px width:
convert SourceFile.pdf -resize 600x DestinationFile.jpg

Resize as 600px height:
convert SourceFile.pdf -resize x600 DestinationFile.jpg

Resize both as squared 600x600:
convert SourceFile.pdf -resize 600x600 DestinationFile.jpg

Resize shortest dimension to preserve aspect ratio (use '^' operator):
convert SourceFile.pdf -resize 600x600^ DestinationFile.jpg

You want to convert file in batch?

Create a script file with this:

#!/bin/bash
# Remove *.jpg *.JPG *.jpeg from list of filesshopt -s nullglob
for FILE in *.jpg *.JPG *.jpeg; do   convert "$FILE" -resize x150 "$FILE""_x150.jpg"
done

Save it in a file with .sh extension and from terminal do this to make it executable:
chmod +x file.sh

Then execute this in you images folder:
./file.sh

It will convert and save the result of all the .jpg images in that folder.

Let me know if helped!

domenica 9 novembre 2014

Install and configure ArkOS on BananaPi with Arch Linux / Come configurare ArkOS su un BananaPi con Arch Linux


Colors Meaning/Legenda dei Colori:
Blue/Blu: English
Green/Verde: Italiano
Gray/Grigio: Commands or code / Comandi o codice

1. Get the Arch Linux image for BananaPi from http://www.lemaker.org/

Scaricate l'immagine di Arch Linux per il vostro BananaPi da http://www.lemaker.org/

2. Write image on an SD card and put in on the Banana Pi, then power it

Scrivete l'immagine sulla SD ed inseritela nel Banana Pi, successivamente accendetelo

3. Login with user: root and pass: bananapi

Effettuate il login con user: root e password: bananapi

4. Add ArkOS repository to Pacman. 


Aggiungete i repository di ArkOS a Pacman.

Edit /etc/pacman.conf. 

Modificate il file /etc/pacman.conf

Near the bottom you will see sections that look like this:

Sul fondo del file dovreste vedere una stringa di questo tipo:

[core]
Include = /etc/pacman.d/mirrorlist

Add one more like this, then save:

Aggiungete una stringa come la seguente e salvate:

[arkos]
Server = http://amnl.mirror.arkos.io/$arch/$repo

5. Update pacman with sudo pacman -Sy

Aggiornate pacman con sudo pacman -Sy

6. Install all the dependency:

Installate le dipendenze:

sudo pacman -S base-devel python2-passlib python2-lxml python2-pyopenssl python2-feedparser python2-gevent supervisor python2-pip python2-pillow python2-ntplib python2-nginx python2-psutil python2-iptables git fail2ban nginx wget

7. Configure nginx to use a multisite format, which it does not do by default in Arch. 

Configurate nginx per usare un formato multisito.

Create folders at /etc/nginx/sites-available and /etc/nginx/sites-enabled, then replace/etc/nginx/nginx.conf with the version available here:https://raw.githubusercontent.com/cznweb/arkos/master/scripts/nginx.conf

Create due cartelle in /etc/nginx/sites-available e /etc/nginx/sites-enabled, quindi sostituite il file /etc/nginx/nginx.conf con la versione disponibile qui: https://raw.githubusercontent.com/cznweb/arkos/master/scripts/nginx.conf

sudo mkdir /etc/nginx/sites-available
sudo mkdir /etc/nginx/sites-enabled
wget https://raw.githubusercontent.com/cznweb/arkos/master/scripts/nginx.conf && sudo cp nginx.conf /etc/nginx/nginx.conf && rm nginx.conf

NEWS: repos has changed, you can find the file here:
http://pastebin.com/njpawFEg

8. Install Genesis automatically with sudo pacman -Sy genesis

Installate Genesis automaticamente con sudo pacman -Sy genesis

9. Start genesis with sudo systemctl start nginx genesis


Avviate genesis con sudo systemctl start nginx genesis


10. Start genesis panel for debug with genesis-panel

Avviage il pannello di debug di genesis con genesis-panel

11. Connect to your ArkOS server by typing in any browser inside your network this: http://banana_pi_ip:8000 or http://arkos:8000

Collegati al tuo server ArkOS digitando in un qualsiasi browser, all'interno della tua rete, questo:
http://banana_pi_ip:8000 oppure http://arkos:8000

For further information follow this: https://arkos.io/doc/getting-started/

Per informazioni aggiuntive e come proseguire seguite il link ufficiale: https://arkos.io/doc/getting-started/

sabato 28 dicembre 2013

Recuperare Logo Samsung Clone S4 / Recover Samsung Logo on Samsung S4 Clone

Ciao a tutti!

Oggi trattiamo come recuperare il logo Samsung su telefoni cinesi con MTK6575 / MTK6577 / MTK6589 / MT6575 / MT6577 / MT6589 cloni del Samsung S4 o simili.

Molti di questi telefoni, una volta resettati alle impostazioni di fabbrica, perdono l'affascinante logo della casa Koreana, lasciando spazio al (lasciatemelo dire) orribile logo Mediatek grigio arancione con un piccolo android che fa capolino da un angolo oppure la semplice scritta android grigia che si illumina.

Quello che dovrete fare è semplicemente aprire l'applicazione "Telefono" (Quella da cui digitate i numeri da chiamare, per intenderci) e inserire uno dei seguenti codici fino a che il telefono non si riavvia o da qualche segno di risposta (che non siano errori UMC o simili) come "successfull", "ok", etc..:

*#0066#
*#7501#
*#91#
*#*#1478963#*#*
*#*#0066#*#*
*#*#11111#*#*

Riavviate e controllate che il logo sia tornato al suo posto!

Se questi codici non dovessero funzionare, scaricate la fantastica applicazione MTK Mobile Uncle, che oltre a dare tantissime informazioni sui vostri dispositivi, ed essere quindi indispensabile, vi da la possibilità di vedere il vostro build.prop e cercare se il codice di attivazione è nascosto tra i commenti "#" sopra a righe del tipo: "ro.bootanimation.switch code : *#--------# etc."

Buona fortuna!

Fatemi sapere come va!
Il primo su un clone che ho avuto sotto mano ha funzionato egregiamente!