Sunday, July 27, 2014

How to setup Mongoose Web Server: a really lightweight one

Developing web applications always requires a web infrastructure, in order to test them, before getting them into production, but many times, we just want our app to consume a web service (that is, to be working as a client), so the requirements for a web server are very lightweight.

If we aren't familiar with web servers and similar stuff and we just want to quickly setup a server in order to test our web app's functionality, Mongoose is here to give the answer, as it's the most easy to setup and use web server in the market.

To quickly download and set it up, come along:

  1. Visit this link and download the Windows Executable that corresponds to free edition:
  2. Add the directory path of the executable in the environmental variable called "Path" (if you need more assistance getting over this, please refer here); for example, my executable's absolute path is C:\Thodoris\Servers\mongoose-5.3.5\bin\mongoose.exe, so I should add C:\Thodoris\Servers\mongoose-5.3.5\bin in my "Path".
Good to go, just navigate to the working directory (folder) of your project, through command line and type mongoose; this produces a web server that runs and serves that folder as the web root.

Regarding the simple web apps that I'm developing over time for educational purposes,  I have set a global "mongoose" folder, where I place all the required assets. It lies under C:\Thodoris\Workspaces\mongoose directory andhere is a dummy view of it:


So, let me run my server:


After successful execution of the command, server root in the default browser:

And it's not over. If you 're aware of host's IP address, you can ping it from any other device, connected in your LAN!

Cheers!

Tuesday, July 22, 2014

How to convert tabs to spaces in Notepad++

So, the very first project that I was exposed on, as a professional, included, among others, YAML and as you obviously know YAML has a strict syntax.

Notepad++ is till now, my favourite editor, but it comes without something that is very useful to the case that we 're investigating today, a "Tabs to Spaces" plugin/feature (I found that the one provided under the Edit -> Blank Operations menu was missing basic functionality). 

There is a solution, though, come along!

  • First of all, we have to download the plugin.
  • We then copy the CLRTabsToSpaces.dll from the .zip file that we just downloaded into \path\to\Notepad++\installation\plugins folder.
  • If Notepad++ is open, we have to close it and restart it again, in order to let the software track the changes.
  • Navigating to the "Plugins" menu, we should see something like below:


That is, we have set properly our plugin, so to get it working, we just follow the above screenshot, to get the tab characters be converted into spaces.

Note: it's better to edit such code snippets, having enabled the "Show all characters" button: 

And a small example (sample code from here ):

Before applying the plugin.

After applying the plugin.


Cheers!


Wednesday, July 9, 2014

How to solve Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V in Android

So today, while writing an example for the JCG community, I came across the following exception, while trying to add an EditText element to my application:

Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V

Despite the fact that I selected Android 4.4 (API 19) for my application, I noticed that the selected Android API in the Graphical Layout of my XML code was actually wrong:


So, the easy way, I clicked the dropdown to select again my initial option:


Note: the Wear versions don't support EditText elements and that's why we got the exception.
And of course, everything was fine after that:


Cheers!

Thursday, July 3, 2014

How to generate random UUID in Java

Hi there! Generating a random UUID is much more easier than you could ever imagine! I use the following block of code, whenever I'm in a need of more than ten:
for(int i = 0; i < 30; i++) {
   System.out.println(UUID.randomUUID());
}
If things get difficult and time passes, working with UUIDs, you 'll probably get lost, if the way you chose to generate your UUID was "a bunch at a time", like above, so you could either visit a site, like this or modify your program like below:
   System.out.println(UUID.randomUUID());
Cheers!