Array of cities in JS and show it on a div

In this example, I have a bunch of city names as an array variable in JavaScript. Then I want to make a list of links for all the city names.

Here I do it using jQuery:

 

How to check is the device connected to internet or not in Android

With this simple snippet, we can check is the device is connected to internet or not:

So this “isConnected()” returns true if it’s connected, otherwise it returns false.

Listing image files in a directory and populate a ListView from it in Android

I have a directory in sdcard called “mydir” and there are lot of .png image files with another files. Then I want to list only that .png files and populate a ListView from it.

I do it like this:

 

Simple clickable Android ListView example

Follow this short tutorial to create a ListView in Android.

First let’s create the list view element in our layout file:

Then in your Java file:

By clicking on each item a toast message will be displayed containing item text.

JSON to Object and Array in Java

Try this snippet to convert JSON text into object and/or array in Java:

jsontext is your JSON text.

Listing all files in a directory in Android

Let’s say we have a directory in device’s storage called “mydir” and there are files inside it. By using this snippet we can list all names of that files and folders:

Now downloadedbooks string variable contains all files and folders name.

Requesting permission in run time in Android

If we are making an app for Android greater than SDK 23, we need to request some sensitive permissions (for example, to write file in external storage) in run time.

Here is a snippet to do so:

 

If a folder (directory) is not existed, create it – Android Java Snippet

With this snippet, we are able to check if a folder existed in device’s storage or not. If not, then we create it.

Here is the snippet:

 

Simple PHP read and write to a text file

This code snippet reads a text file that if it is not existed it will create one with some text in it.

Next time this code is executed, if the file existed, PHP echoes the content of the file.

Or this one, the better one:

 

Changing the skybox material programmatically in Unity

I’m using this simple script after attaching it to UI Buttons to change my skybox materials. Let’s say we have two skybox materials with two UI Buttons to switch between them.

Here is the script: