a cadenza discontinua
Come se fossi

A volte vi è la necessita di localizzare un certo orario e una certa data nel fuso orario dell'utenza che visita il nostro sito web. Per far ciò esistono due possibili strade:

  •  Localizzare l'IP facendo una richiesta a servizi del tipo geoip
    https://geoip.tools/v1/xml/?q=192.168.200.200
  • Utilizzare JS per captare il fusorario del browser.

In questa snippet utilizziamo JS e PHP per localizzare un determinato datetime rispetto all'orario dello stesso.

La componente JS, semplicemente memorizza l'informazione nei cookie che recuperiamo con PHP successivamente. 

$(document).ready(function(){
    var tz = jstz.determine(); 
    var timezone = tz.name(); 
	document.cookie = "timezone="+timezone;
});

In questo caso è inserito in jquery. Richiede ( )

Successivamente in PHP stabiliremo di default l'orario in cui i nostri datetime sono creati e successivamente recuperemo dai cookie il timezone preso dalla componente JS.

 

date_default_timezone_set('Europe/Rome');
if(isset($_COOKIE['timezone'])){ $userTimezone = $_COOKIE['timezone']; }


Fatto ciò tutti i datetime cui necessitano questo timo di localizzazione saranno così impostati:

$date = new DateTime($table["datetime"]);
$date->setTimezone(new DateTimeZone($userTimezone));

Per poi proseguire con la formattazione desiderata

echo $date->format('Y-m-d H:i');

Ciauz!



di GuiZ

Tempi duri, AdBlock è uno strumento utile per i navigatori ma al quanto penalizzante per i possessori di siti web, blog o altro. Personalmente non ci guadagno nulla però ci pago le spese del blog e mi consente di continuare a scrivere. Oltre agli articoli sponsorizzati è l'unica "entrata". Penso entro quest'anno ci sarà una nuova veste grafica del sisto utilizzando boostrap, il che mi consente di rendere il sito responsive e di eliminare la versione mobile. Oggi spiego molto rapidamente le tecniche più comuni per individuare se il visitare abbia installato AdBlock e quindi per mostrare un messaggio o qualsiasi cosa vogliate. Personalmente preferisco avvisare che impedire la navigazione, anche se capisco perfettamente che ci sono persone che ci vivono.

Analizziamo il primo caso: Adsense

L'individuazione di Adsense è uno dei casi più comuni ed è facilmente implementabile, alla fine del caricamento della pagina vericheremo se il carimento delle ads è stato effettuato correttamente altrimente mostreremo un altert o qualsiasi cosa vogliate.

<script>
  window.onload = function() {
    setTimeout(function() {
      if ( typeof(window.google_jobrunner) === "undefined" ) {
	alert("Per sostenere questo sito disabilita AdBlock.");
        console.log("ad blocker installato");
      } else {
        console.log("nessun ad blocker installato.");
      }
    }, 10000);  
  };
</script>

Ovviamente dove è presente l'alert jquery sarà possibile inserire qualsivoglia avviso anche nella forma limitativa, cioè oscurando il sito o altro.


Il secondo caso si basa sul caricamento di un file js di nome ads.js . Gli adblocker provano ad impedire il caricamento di questo js e quindi tramite un piccolo controllo possiamo verificare il caricamento.


<script>var isAdsLoaded=false;</script><script src="js/ads.js"></script><script>
if (!isAdsLoaded) { 
  console.log("The visitor is blocking ads");
}
</script>

Il file ads.js sarà composto unicamente dalla riga isAdsLoaded=true; banalmente si basa su una variabile che varia unicamente se il file js viene caricato. ads.js può essere incluso in qualsiasi percorso.

Salutoni



di GuiZ

Hard times, AdBlock is a useful tool for surfers but penalizing for the owners of websites, blogs or other. Personally I do not gain anything but I pay the costs of the blog and allows me to continue writing. In addition to sponsored articles it is the only "entry". I think this year there will be a new layout of the sisto using boostrap, which allows me to make the site responsive and delete the mobile version. Today I explain very quickly the most common techniques to find out if the visit has installed AdBlock and then to show a message or whatever you want. Personally I prefer to warn that to prevent navigation, even if I fully understand that there are people who live there.


Let's analyze the first case: Adsense

The detection of Adsense is one of the most common cases and is easily implemented, at the end of the page load we will check if the ads have been successfully uploaded otherwise we will show an altert or whatever you want.

<script>
  window.onload = function() {
    setTimeout(function() {
      if ( typeof(window.google_jobrunner) === "undefined" ) {
	alert("Per sostenere questo sito disabilita AdBlock.");
        console.log("ad blocker installato");
      } else {
        console.log("nessun ad blocker installato.");
      }
    }, 10000);  
  };
</script>


Obviously where the jquery alert is present it will be possible to insert any warning even in the limiting form, that is, obscuring the site or other.



The second case is based on loading a js file named ads.js. The adblockers try to prevent the loading of this js and then through a small check we can verify the loading


<script>var isAdsLoaded=false;</script><script src="js/ads.js"></script><script>
if (!isAdsLoaded) { 
  console.log("The visitor is blocking ads");
}
</script>

The ads.js file will only be composed of the line isAdsLoaded = true; trivially it is based on a variable that only varies if the js file is loaded. ads.js can be included in any path.

Salutoni



di GuiZ

Oggi mi sono imbattuto nel porting di un codice per renderlo compatibile per Android 7, quindi nougat, da versione precedenti. Durante questa fase ho scoperto che dal SDK 25 in poi non vi è più la possibilità di listare tramite il listFiles della /proc .

Questo è avvenuto per motivi di sicurezza restringendo maggiormanete il raggio d'azione che differenzia Android da iOS. ( non di sicurezza sia ben inteso ) Il codice che vi incollo è quello relativo prima della versione SDK 25.

Questa funzione mi è utile per capire e recuperare il pid di un processo in background partendo dal suo nome. Resta ancora valido dalle versioni 25 in poi ma è ristretto ai permessi di lettura dell'utenza che esegue l'applicazione, quindi non listerà tutti i processi.

 

public static List pidof(String str) {
        List < String > listOfPid = new ArrayList();
        for (File file : new File("/proc").listFiles()) {
            if (!file.isFile()) {
                File file2;
                if (Build.VERSION.SDK_INT < 25) {
                    file2 = new File(file.toString() + "/cmdline");;
                }else {
                    file2 = new File(file.toString() + "/comm");
                }
                if (file2.canRead()) {
                    try {
                        BufferedReader bufferedReader = new BufferedReader(new FileReader(file2), 8192);
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else if (readLine.toString().contains(str.toString())) {
                                listOfPid.add(file2.getPath().split("\/")[2].toString());
                            }
                        }
                        bufferedReader.close();
                    } catch (IOException e) {
                    }
                } else {
                    continue;
                }
            }
        }
        return listOfPid;
    }

In alternativa, parliamo sempre di dispositivi con root, è possibile creare un piccolo script in sh:

sudo -c 'pidof nomeprocesso'

Salvarlo per esempio nella folder files della nostra app dandogli i permessi corretti tramite adb e successivamente richiamarlo tramite getRuntime().exec() Non so se esistano altri metodi validi e funzionali nel caso mi commentate suggerendomi?

Grazie a tutti!

Salutoni

GuiZ



di GuiZ

Today I came across the porting of a code to make it compatible for Android 7, so nougat, from the previous version. During this phase I discovered that from the SDK 25 onwards there is no longer the possibility to list via the listFiles of /proc.

This happened for security reasons narrowing the range of action that differentiates Android from iOS. (not of safety is well understood) The code that you glue is the relative one before the SDK 25 version. It remains valid from versions 25 onwards but is restricted to the reading permissions of the user running the application, so it will not list all the processes.

public static List pidof(String str) {
        List < String > listOfPid = new ArrayList();
        for (File file : new File("/proc").listFiles()) {
            if (!file.isFile()) {
                File file2;
                if (Build.VERSION.SDK_INT < 25) {
                    file2 = new File(file.toString() + "/cmdline");;
                }else {
                    file2 = new File(file.toString() + "/comm");
                }
                if (file2.canRead()) {
                    try {
                        BufferedReader bufferedReader = new BufferedReader(new FileReader(file2), 8192);
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else if (readLine.toString().contains(str.toString())) {
                                listOfPid.add(file2.getPath().split("\/")[2].toString());
                            }
                        }
                        bufferedReader.close();
                    } catch (IOException e) {
                    }
                } else {
                    continue;
                }
            }
        }
        return listOfPid;
    }

Alternatively, we always talk about devices with root, you can create a small script in sh:

sudo -c 'pidof processname'

For example, save it in the folder files of our app giving it the correct permissions via adb and then retrieve it via getRuntime().exec().I don't know if there are other valid and functional methods in case you comment to me suggesting?

Thank you all!

This happened for security reasons narrowing the range of action that differentiates Android from iOS. (not of safety is well understood) The code that you glue is the relative one before the SDK 25 versio


di GuiZ

 

Settare il full screen dell'app nell'evento onCreate rigenera l'evento onCreate, questo può causare problematiche nel caso si utilizzano determinati thread o task. Per ovviare ciò è necessario modificare il tema dell'app, settando nel manifest un tema personalizzato. 

android:theme="@style/AppTheme"

Nello style del tema è possibile modificare i parametri di configurazione della window ad esempio:


<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="@style/Theme.Leanback">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>



di GuiZ

Setting the app's full screen in the onCreate event regenerates the onCreate event, which can cause problems if certain threads or tasks are used. To avoid this, it is necessary to modify the theme of the app, setting a custom theme in the manifest..

android:theme="@style/AppTheme"

In the style of the theme it is possible to modify the configuration parameters of the window, for example:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppTheme" parent="@style/Theme.Leanback">
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowNoTitle">true</item>
    </style>
</resources>



di GuiZ

Tantissimi software di videochat non permetto la registrazione delle videochiamate come ad esempio Skype, lasciando persi nel tempo alcuni dei nostri momenti da ricordare con parenti, amici e nipotini che crescono lontani.

...(Continua)


Leggi >>


di GuiZ

Nel forex la strategia di breakout è una delle più usate, questo piccolo script consente di ricevere un alert al verificarsi di un breakout sia di supporto che di resistenza. E' possibile impostare il count del breakout, cioè dalla candela alla candela su cui trovare supporto e resistenza, tramite i parametri:

  • candle from breakout
  • candle to breakout 

E' un piccolissimo script scaricabile qui dove ci sono sorgenti e compilato. Per migliorie o altro lasciate un commento, sono disponibile!



di GuiZ

In the forex breakout strategy is one of the most used, this small script allows you to receive an alert at the occurrence of a breakout of both support and resistance. It is possible to set the breakout count, ie from the candle to the candle on which to find support and resistance, using the parameters:

  • candle from breakout
  • candle to breakout 

It's a very small downloadable script here where there are sources and compiled. For improvements or other comments, I'm available!



di GuiZ

Oltre alla classica boot animation in Android è possibile inserire un video come animazione di boot. In questa mini guida vi indicherò le informazioni per abilitare o disabilitare il bootvideo e la sua posizione.

Nel file build.pro (/system/build.prop) è presente una prop relativa

#add for video boot, 1 means use video boot, others not .
service.bootvideo=1
 
Il file bootvideo risiede in /system/etc/bootvideo ed è un mp4.
 
Se disabilitata la service.bootvideo=0 il sistema cercherà la bootanimation in system/media
 


di GuiZ

 

In addition to the classic boot animation on Android, you can insert a video as a boot animation. In this mini guide I will explain you the informations to enable or disable the bootvideo and its location.

The build.pro file (/system/build.prop) has a relative prop

#add for video boot, 1 means using video boot, others not.
service.bootvideo = 1

The bootvideo file resides in /system/etc/bootvideo and is an mp4.If service.bootvideo=0 is disabled the system will try to bootanimation in system/media



di GuiZ

In questo piccolo script illustro come creare un piccolo effetto bounce parametrizzabile applicabile su qualsiasi game object, che quindi può contenere qualsiasi risorsa. Si basa su 2 fasi una di transizione e l'altra di bounce. Ovviamente è ampiamente modificabile. La parametrizzazione è importante al fine di trovare il risultato desiderato. 

Vi lascio al codice commentato.

...(Continua)


Leggi >>


di GuiZ

In this little script i explains how to create a small effect bounce parameterized applicable on any game object, which then can contain any resource. It is based on a 2 phase transition and the other of the bounce. Obviously it is widely editable. Parameterization is important in order to find the desired result.

I leave to the commented code.

...(Continua)


Leggi >>


di GuiZ

Un nostro contributor, Armando Vaccaro, ci ha inviato un collage di pianeti osservati nel 2016. Vi proponiamo queste bellissime osservazioni amatoriali di Giove, Saturno e Marte per l'anno 2016.

Grazie ARMANDO!



di GuiZ

La creazione di un'interfaccia grafica è sempre stato compito arduo sopratutto se si vuole creare qualcosa che utilizzi diversi dispositivi con un infinità di risoluzioni,schermi etc...

Ho pensato che fosse utile implementare qualcosa per rendere il touch più efficiente soprattutto nei device più piccoli che è, senza ombra di dubbio, un alternativa alla creazione di un'interfaccia grafica dedicata. Una soluzione efficiente è la creazione di un collider che gestisca tutti i gli eventi che desideriamo, al fine di individuare l'oggetto più vicino compatibile con l'evento ed inviarglielo. Una sorta di manager touch.

Il collider occupa tutta la camera e è al di sopra di tutto, per praticità lo chiamo SmartTouchCollider. Questo intercetta tutti gli eventi, che vogliamo che gestisca e tramite il suo script individua l'oggetto più vicino.

...(Continua)


Leggi >>


di GuiZ

The creation of a graphical interface has always been daunting task especially if you want to create something that uses different devices with an infinite number of resolutions, screens etc ...

I thought it was useful to implement something to make the most efficient touch especially in the smaller device which is, without a doubt, an alternative to creating an interface dedicated graphics. An efficient solution is the creation of a collider which manages all of the events that we wish, in order to locate thenearest object compatible with the event and send it. A sort of touch manager.

The collider takes up the whole room and is above all, for convenience I call SmartTouchCollider. This intercepts all events, we want to manage, and through his script locates the nearest object.

...(Continua)


Leggi >>


di GuiZ

L'effetto di shake, vibrazione o terremoto è facilmente implementabile utilizzando alcuni metodi come Random.insideUnitCircle che genera randomicamente un punto in un cerchio di raggio 1.

Risulta quindi facilmente applicabile ad una sprite soprattutto in ambiente 2D. Considerando la generazione di un punto randomico in un cerchio, avente cento coordinate 0x, 0y possiamo facilmente applicare una forza per moltiplicare la "potenza" quindi il raggio d'azione.

Supponiamo di aver ottenuto un punto random "Random Point 1" di coordinate (esempio) -0.5x e -0.6y a cui applicheremo una costante, che chiameremo forza dello shake ma in sostanza è un aumento del raggio per esempio forza 2.

...(Continua)


Leggi >>


di GuiZ

The effect of shake , vibration or earthquake is easily implemented using some methods such as Random.insideUnitCircle that generates randomly a point on a circle of radius 1 .

It is therefore easily applicable to a sprite especially in 2D environment . Whereas the generation of a point randomico in a circle , having the center coordinates 0x , 0y we can easily apply a force to multiply the "power" then the radius of action.

Suppose you've got a point random " Random Point 1 " Coordinate ( example) -0.5x and -0.6y to which we apply a constant , called the shake strength but in essence it is an increase in the radius for example, force 2 .

...(Continua)


Leggi >>


di GuiZ

Questo è un mini tutorial in ambiente Unity 2D con il fine di spiegare semplicemente la gestione delle collisioni. C'è ne saranno diversi dove verranno spiegate le più comuni problematiche riscontrate nello sviluppo di giochi 2D.

La gestione della collisione è alla base di qualsiasi videogioco, in Unity è possibile gestirle in maniera molto rapida ed intuitiva. Supponiamo di avere un oggetto di nome "Box" con una sprite raffigurante una cassa.

...(Continua)


Leggi >>


di GuiZ