martedì 31 ottobre 2017

Javascript prototype function collection ------

Mustache ----- mai più stringhe concatenate in Javascript!!!!!

Per utilizzare la libreria Mustache.js sono necessari i seguenti passi:

1) installazione
     https://github.com/janl/mustache.js   in base al vostro ambiente, scegliete il sistema a voi consono.
2) creazione del template da posizionare magari, in una pagina html esistente:

Il template, che vi propongo è rappresentato da un blocco  <script> il cui type è "x-tmpl-mustache", ad esempio:

<script id="idDelTemplate" type="x-tmpl-mustache">
    <div class=' col-md-12 col-sm-12  col-xs-12  input-group' id='{{matricola}}'>
        <span class='form-control'>{{matricola}}</span>
        <span class='input-group-addon' onclick='removeBarcode("{{matricola}}")'> <i class='glyphicon glyphicon-trash'></i> </span>
    </div>
</script>

Successivamente, per utilizzarlo bastera:
 3) Wrappare il template con jquery :

                   var newItem = $('#idDelTemplate').html();

4) Testare se il template sia corretto :

                   Mustache.parse(newItem); // sembra sia optionale e utile in futuro... il progetto 

5) "Stampare" il template collegato al modello nel nostro contenitore:

              var printedModelTemplate= Mustache.render(template, objModel);
              $('body').html(printedModelTemplate);

dove il modello objModel = { matricola:1234123123};

Questa libreria è definita come logicLess, pertanto non si avranno disponibili le funzionalità "di alto livello" presenti in altri framework, vedi React (  che a prima vista pare estenda  Mustache ) o AngularJs/2

ad ogni modo, un minimo di rendering condizionato, il nostro Mustache lo offre, ad esempio supponendo di dover renderizzare un blocco html in base al verificarsi di una condizione,  Mustache offre la seguente sintassi:

{{#VAR}} Do Some Stuff{{/VAR}}
{{^VAR}} Not Do Some Stuff{{/VAR}}

Supponendo che nel modello sia contenuta una property VAR di tipo booleano, se VAR è true verrà stampato 
Do Some Stuff

altrimenti

Not Do Some Stuff

in termini pratici, i blocchi condizionali andranno posizionati dove si ritiene necessario :



objModel = { matricola:1234123123, VAR :true};

<script id="idDelTemplate" type="x-tmpl-mustache">
    <div class=' col-md-12 col-sm-12  col-xs-12  input-group' id='{{matricola}}'>
        <span class='form-control'>{{matricola}}</span>
        <span class='input-group-addon' onclick='removeBarcode("{{matricola}}")'> <i class='glyphicon glyphicon-trash'></i> </span>
    </div>
{{#VAR}}<span>Do Some Stuff</span>{{/VAR}}
{{^VAR}} <p>Not Do Some Stuff</p>{{/VAR}}
</script>





Libreria onesta, semplice e con poche pretese, sebbene l'efficacia sia indiscutibile.

ciao ciao
















martedì 17 ottobre 2017

Media Query!!! how it works ...for me :)

REMINDER :)

hi to all, .... that's a fast post

/* Higher Than  767px WORK*/
@media screen and (min-width: 767px) { body{ background-color: red;    }}
/* Higher Than  968px WORK*/
@media screen and (min-width: 968px) { body{ background-color: yellow; }}




/*Lower Than 768px Work*/
@media screen and (max-width: 768px) { body{ background-color: blue;    } }
/*Lower Than 567px Work*/
@media screen and (max-width: 567px) { body{ background-color: white;    } }


bye

sabato 8 luglio 2017

Java - Scarica file da domini con protocollo https - Download files from domains with https protocol











Italiano
Ciao a tutti,
il download di file, reperiti da domini o siti internet che utilizzano il protocollo https da Java, prevede l'importazione del certificato ssl all'interno di un keystore noto all'utente, in altre parole al keystore utilizzato di solito oppure in un nuovo keystore, e di un semplice programmino che scarica un elemento dopo l'altro, niente di trascendentale, ma per chi non ha familirità con certificati ssl, potrebbe un attimo rallentare l'attività.

procedendo per passi, cercando di snelline al massimo i processi vedremo come:
1) scaricare il certificato in base 64, per questo utilizzeremo google chrome, tab security --> view certificate --> download base 64
2) import del certificato attraverso l'utility keytool

3) applicazione java ( un semplice main va benissimo) e setting del keystore da utilizzare...

Passo 1

sul sito che contiene i file da scaricare, premere F12,

navigare fino al tab security e premere il pulsante "View Certificate"... seguire le indicazioni nelle immagini imm1, 2.. 3




image 1




imm2

imm3



successivamente, salvare il certificato, esempio downcert.cer



Passo 2

l'import del certificato nel keystore è una operazione molto semplice, accertatevi di avere nel path configurata una jdk o jre.... quindi una una shell eseguire :


 keytool -importcert -file downcert.cer -keystore keystore.jks -alias "AliasName"


(si suppone di essere posizionati nella cartella che contiene il certificato quindi il keystore, sebbene non sia corretto ma per comodità....)

Lanciato il comando verrà chiesto se:

il certificato sia attendibile, scrivere si e
la password del keystore, che verrà utilizzata nel codice al passo 3




English 

Hello to all,
Downloading files from domains or websites that use https from Java suggests importing the ssl certificate within a known keystore, in other words to the keystore usually used or in a new keystore , And a simple program that downloads an item after another, nothing transcendental, but for those who do not have familiarity with ssl certificates, it may be a moment to slow down the activity.

By proceeding in steps, trying to streamline the processes at maximum we will see how:
1) download certificate based 64, for this we will use google chrome, security tab -> view certificate -> 64 download base
2) Import the certificate through the keytool utility

3) java application (a simple main goes fine) and keystore setting to use ...

Step 1

On the site that contains the files to download, press F12,

Navigate to the security tab and press the "View Certificate" button ... follow the directions in the images imm1, 2 .. 3
(see previous images)
Then save the certificate.

Step 2

Importing the certificate in the keystore is a very simple operation, make sure you have a jdk or jre configured path ... so a shell execute:

  keytool -importcert -file downcert.cer -keystore keystore.jks -alias "AliasName"

(It is supposed to be placed in the folder that contains the certificate then the keystore, although it is not correct but for convenience ....)

Launched the command will ask if:
The certificate is trusted, write yes and
The keystore password, which will be used in the code at step 3





PASSO 3 / STEP 3



import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;

public class main {
public static String[] links=new String[]{
"https://www.domainexample.com/resource1.jpg",
"https://www.domainexample.com/resource2.jpg",
"",
"",
"https://www.domainexample.com/resourceN.jpg" };

public static void main(String[] args) throws MalformedURLException, IOException{
String  ks= System.getProperty("user.home") + "/Desktop/keystore.jks";
String  folder= System.getProperty("user.home") + "/Desktop/downloadfoldercontainer";

new File(folder).mkdirs();
System.setProperty("javax.net.ssl.trustStore", ks);
System.setProperty("javax.net.ssl.trustStorePassword", "passwordStep2Passo2");

System.out.println("start:"+System.currentTimeMillis());
for(int i=0;i<links.length;i++){
try(InputStream in = new URL(links[i]).openStream()){
   Files.copy(in, Paths.get(folder+"/photo"+i+"image.jpg"));
}
}
System.out.println("stop:"+System.currentTimeMillis());
}
}



ciaoooo ragazzi :)