Category: Technology

  • Android: 2-dimensional List String (List of List)

    For a web developer who used mostly PHP and JavaScript for several years, plunging into Java can be challenging especially when it comes to data types.

    PHP and JavaScript are loosely typed languages, while Java is strict about types.

    I was told that in Android, List<String> is very commonly used, even more than arrays. And now I’ve come to the point when I need to use a 2-dimensional List<String>.

    Here’s a sample code:

    Output of System.outprintln(Arrays.deepToString(ls.toArray())); is this:

    The output of Log.d("serialized", listOfList.toString()); is this:

  • Android confirm dialog box with OK and Cancel button

    Android confirm dialog box with OK and Cancel button

    This will probably be one of the Android code snippets that I will need to go back to from time to time.

    I’m sharing the codes we need to show an Android confirm dialog to prompt the user to click “yes” or “no”, or in my case, “OK” or “Cancel”.

    The following code for Android confirm dialog is in my MainActivity.java file:

    (more…)

  • Android Studio dark theme (change into Darcula theme)

    Android Studio dark theme (change into Darcula theme)

    You might feel more comfortable with a dark theme in Android Studio, but the default theme is light in color.

    Default light theme in Android Studio
    Default light theme in Android Studio

    I’m one of the developers who always code in dark screens since it’s less tiring to the eyes.

    Android Studio dark theme
    Android Studio dark theme — Darcula

    If you’re like me who prefers dark themes while coding, then I’ll show you how to change into a dark theme called Darcula in Android Studio here. (more…)

  • How to change app name in Android Studio

    How to change app name in Android Studio

    I’m trying to learn how to build a simple app in Android just to satisfy my curiosity. This will also be a very handy skill because I use Android phones often, and there are times that the apps I download from Google Play Store lack features that I need.

    This will be a very simple guide on how to change app name in Android Studio, something that most beginners in Android development probably want to know.

    It is assumed in this guide that you have prior knowledge in coding.

    The app name that I’m referring to is the one that says “My Application”, as marked on the image below:

    How to change app name in Android Studio

    To change that, go to your Project and find the app folder. Under app, find AndroidManifest.xml and edit android:label="My Application", replacing “My Application” with the name you’d like to use.

    Refer to the image below:

    android-studio-android-manifest

    Your changed app name should be reflected in the live preview now, if you have it activated. If you don’t have live preview yet, check this out: Where is Android Studio layout preview?

    Updates…

    How to rename project folders of Android Studio

    You may also want to change the name of your Android app’s folder. Check this folder, it’s probably where your Android project folder is located — C:\Users\catkeng\AndroidStudioProjects\

    How to rename package in Android Studio

    Right-click on your package name in the Project tree. It’s probably under app->java. Then choose “Refactor”, then choose “Rename”. Take note that you’ll see “Rename package” and “Rename folders” button here — you might need to go back to this screen later to click “Rename folders”. For now, click the “Rename package” button. Type the new name that you want to use, then click “Refactor”. If that hasn’t changed all package name instances for you, follow the same steps until you can click “Rename folders” button too. That should do it!

  • CCNA V5 Curriculum Download – Portable Offline Study (Routing & Switching)

    CCNA V5 Curriculum Download – Portable Offline Study (Routing & Switching)

    An older blog post about CCNA Exploration 4.0 Curriculum was one of my most popular pages in this site. A guest requested that I share CCNA V5 Curriculum Download links here for Routing and Switching, and I decided to try to fulfill such request because I think this will help a lot of people who are studying to get certified by Cisco.

    These are portable offline curriculum files for CCNA Routing & Switching — there’s no need for installation I’m not sure yet if it’s the same but more updated version of CCNA Exploration or completely different.

    Extract the .rar files into your computer so that you can study for CCNA even when you are offline. You can also make the curriculum portable by extracting the contents into your USB flash drive and take your CCNA V5 curriculum with you anywhere.

    Please download these and check if they are what you need for your CCNA studies. Let me know what you think. šŸ™‚ (more…)

  • SSH without password: PuTTY or Git Bash

    SSH without password: PuTTY or Git Bash

    We access remote Linux servers everyday from our Windows computers. Having different servers for different projects, it can be difficult having to enter the passwords over and over in everyday. And so, I suggest that we use SSH Keys instead for authentication to save us some time and boost productivity. SSH keys should also make logins more secure than passwords — just be careful when someone else uses your computer.

    I’ll show you two methods that we can use to connect to our Linux servers using SSH keys and without a password.

    Method 1: PuTTY
    Method 2: Git Bash

    Requirements for this tutorial:

    I personally like using Git Bash to connect via SSH to our server because it’s done in fewer steps than when using PuTTY, but in this tutorial I will first show you password-less connection to SSH via PuTTY.

    Method 1: SSH Connection without password in PuTTY

    1. Download PuTTY from theĀ PuTTY Download Page if you haven’t yet. No installation is required — you just run this .exe file when you need it.
    2. You also need PuTTYgen so if you don’t have it yet, download PuTTYgen from the PuTTY Download Page. This is the PuTTY Key Generator, and will be used to generate a key later. Like putty.exe, no installation is needed for this.
    3. Right click on puttygen.exe then run it.
    4. Make sure that under Parameters,Ā SSH-2 RSA is selected, then click the Generate button. Move your mouse pointer all over the blank area to hasten the key generation.
    5. Copy the generated key, edit theĀ Linux server’s authorized_key file in the .ssh folder (e.g.Ā /home/username/.ssh), and paste the generated key into it. If the .ssh folder orĀ authorized_key Ā file doĀ not exist yet, create a .ssh folder with permission 700, then create the file authorized_key file with permission 600.
    6. In PuTTY Key Generator, click “Save public key” and save it as a .txt file.
    7. Still in PuTTY Key Generator, click “Save private key” and save it as a .ppk file. It’s recommended for youĀ to save a passphrase for the private key.
    8. Now, run PuTTY. Go to Connection -> SSH -> Auth. Click the browse button to find and select the private key (.ppk file) that you saved in the previous step.
    9. From Connection, go to Session so that you can connect to the Linux serverĀ via SSH. Enter the host name or IP address then click Open.
    10. Enter your username.
    11. You should be logged in now without being prompted for password. I think you need to select the .ppk file under Connection -> SSH -> Auth each time you will log in.

    Method 2: SSH Connection without username & password in Git Bash

    1. Install Git on your Windows computer if you haven’t yet. Download Git here. During setup, I didn’t change any setting aside from ticking the “Enable file system caching” checkbox.
    2. If a .ssh folder doesn’t exist yet underĀ C:\Users\<YOUR-WINDOWS-USERNAME>\ then please create it. (I used the browser for Local Site in FileZilla to create .ssh folder)
    3. While inside the .ssh window, right click then choose Git Bash Here.
    4. Run this command: ssh-keygen -t rsa -C "[email protected]", then type theĀ file name for your key (we’ll use this in aĀ config file later), and then type the passphrase that you want to use, twice.
    5. Create a file named config, with no extension name, under the .ssh folder. (FileZilla’s browser for Local Site might help again)
    6. Paste the following into the config file and edit as necessary. <NAME_OF_SSH_KEY> should be the file name you typed earlier after the ssh-keygen command.
    7. Open the .pub key fileĀ that you just generated inĀ C:\Users\<YOUR-WINDOWS-USERNAME>\.ssh\ and copy its contents.
    8. Edit theĀ Linux server’s authorized_key file in the .ssh folder (e.g.Ā /home/username/.ssh), and paste the key from the .pub file into it. If the .ssh folder orĀ authorized_key Ā file doĀ not exist yet, create a .ssh folder with permission 700, then create the file authorized_key with permission 600.
    9. Run Git Bash then enter this command: ssh <LABEL_FOR_CONNECTION> The label for connection should be as set in the config file. If you set a passphrase, you will be prompted for that too.
    10. Just run the same command in Git Bash each time you want to start the connection.

     

    Resources:

    Let me link to the web pages that helped me complete this tutorial:

    HOW TO PASSWORDLESS SSH LOGIN – Server Mom explains how passwordless SSH connections work and will teach you how to implement a Linux to Linux or Windows to Linux connection. This page mostly helped me with Method 1: PuTTY.

    Adding SSH Keys to Authorized_Keys – this page was my reference for chmod settings

    Simplify Your Life With an SSH Config File – helped me complete the Method 2: Git Bash.

  • Google Maps get coordinates on click or drag and drop

    Google Maps get coordinates on click or drag and drop

    With this tutorial you’ll see how we can place a Google map with search box on your web page, and then get coordinates (i.e. latitude and longitude) based on where you click or where you drag and drop the marker into. The JavaScript API of Google Maps will help us achieve this.

    This kind of map will be useful if you want to save coordinates from a Google map into your database. For example, if you’d like to save coordinates of a user-defined location, you can incorporate this map into your registration process — ask your users to point the marker to their location by clicking on the map or by dragging then dropping the marker.

    There will be two types of icons in this map. First, a red default marker. Wherever you move it, we’ll get the coordinates that it points to. Second, white square markers which will appear to point to the location you searched for using the search box.

    Map Demo

    Try the map below — this is more or less how our map will look like later at the end of this tutorial. šŸ™‚ Please read on and soon I’ll share the codes with you.

    Get coordinates from Google Map

    Latitude: Ā Ā Longitude:


    Click on any point or drag the marker to get coordinates.

     

    This tutorial will cover the following:

    • Google map on a web page
    • Search box for map
    • Get map coordinates on click
    • Get map coordinates on drag and drop of the marker
    And you will need these:

    • Familiarity with HTML and JavaScript
    • Internet connection
    • Google account
    • Development environment (I used XAMPP on Windows 7 for this)
    • Code editor (I use Sublime Text)

    (more…)