Power to Build

Home » Articles posted by SamV

Author Archives: SamV

Advertisements

Java Code Search Engines


We all use Google and other Search Engines for searching anything under the sun. Are there any sites like these for searching source code, that new comers and experienced programmers alike, can search for sample code? Here are a couple of links to search for a particular class/method in Java:
 
 
You can search for keyword like Collection, it will fetch samples from a lot of Open Source projects. I use it to find standard (popular?) ways of using any API.
 
 
For e.g., ArrayList:
 
Krugle is another popular site. Here is Krugle search for Geocoding:
Here is a page listing few more sites like these:
 
Happy (code) surfing!
Advertisements

Mystery behind the name : Bluetooth


Bluetooth-PNG-Free-Download.pngWe all use Bluetooth. It’s on your cell phone, earphone, laptop, eve in your car. We use it to link up 2 devices so they can connect wireless-ly. I always wondered what kind of technical term is that. We all know Blu Ray – a device with Blue ray (laser) used to read/write to the disk. Infrared – uses infra red to connect. What kind of ray is in Blue tooth?

Recently, while I was browsing something else, came across a little anecdote about the name. Would you believe, it may be referring to blue teeth a king had due to eating too many blueberries or due to tooth infection!

When one of the founds of Bluetooth, Kardach from Intel, was looking for a name for the new technology, had been reading a book about Vikings that featured the reign of Harald Bluetooth (Scandinavian Blåtand/Blåtann), whom he viewed as an ideal symbol for bringing competing Danish tribes together, as he explained:

Bluetooth was borrowed from the 10th-century, second king of Denmark, King Harald Bluetooth; who was famous for uniting Scandinavia just as we intended to unite the PC and cellular industries with a short-range wireless link.

Apparently, the name stuck when he couldn’t register the technical name for it in time.

The bluetooth logo is a combination of couple of Rune characters as well, as Wikipedia article puts it:

The Bluetooth logo is a bind rune merging the Younger Futhark runes Runic letter ior.svg (Hagall) (ᚼ) and Runic letter berkanan.svg (Bjarkan) (ᛒ), Harald’s initials.

https://www.pcworld.com/article/2061288/so-thats-why-its-called-bluetooth-and-other-surprising-tech-name-origins.html

Sharing: A GUI for the Command Line Interface | JBoss Developer


We are getting into Redhat JBOSS for our Java project. I am currently exploring all the options available in JBOSS (also comparing it with Sybase EA Server we are using currently). I intend to share our experiences with the platform here.

One of the things I use a lot in EA Server will be the Jagtool – a command line interface to the app Server’s repository. In JBoss, I found Jboss-cli to do this for us. And I just found out from the below link, that you can actually start that in GUI mode as well. This link has a detailed information on the GUI mode. More on the tool later.

Source: A GUI for the Command Line Interface | JBoss Developer

Sharing: 5 Best C Programming Books A C Programmer Must Read


Sharing:

Learn C programming by reading some of the best books from expert authors

Source: 5 Best C Programming Books A C Programmer Must Read

27 Best Free Eclipse Plug-ins for Java Developer to be Productive


Sharing:

An exhaustive list of best hand picked free Eclipse plug-ins for a developer to be efficient

Source: 27 Best Free Eclipse Plug-ins for Java Developer to be Productive

Regex Part 2


I earlier posted about exciting world of Regex here.  Let’s try to learn some more in this followup post.

First if you want to play with Regex, here is a nice tool you can use:

http://regexr.com

2017-05-25 17_39_08-RegExr_ Learn, Build, & Test RegEx

Regex Tool online

By default it comes up with a sample pattern and the matches in the given sample text.  You can type in the pattern you are testing, the actual text in the middle box and if you chose Replace, you get to see what the output will look like.

Let’s use this tool to convert our RSVP list in free text to a spreadsheet list.

If you read my original post, we had 4 RSVPs. It looked somewhat like this:

RSVP:

Name:
Will you attend:
Will you be here for lunch:
How many:

Here is my session in Regexr testing this:

2017-05-25 17_44_49-regexr.com_3g1nb

Using Regexr to test/convert our RSVP text

The bottom portion shows the Replaced text – converted and cleaned, readied to be copied out to Excel. The spreadsheet will look like this:

2017-05-25 17_53_11-Microsoft Excel - Book3

Here is the actual regular expression used in this example:

RSVP[0-9]+:\n+Name:[ ]*(.+)\nWill you attend:(.*)\nWill you be here for lunch:(.*)\nHow many:.*([0-9]+).*[\n]*

Let’s go through the regular expression for arriving at this:

First line would have, RSVP:

In Regex any number can be represented by [0-9]+ **. That is a digit is represented by any character between 0 and 9. A whole number would then be one or more digits.

Thus, RSVP: can be written as,

RSVP[0-9]+:

Next text is actually on another line. This can represented by \n. You may know this is newline. Now we are on the second line.

Name:<name>

This can be matched by, Name: (.*)

That would be any character after Name: . If you notice, we have a space after Name:. What if the user didn’t add any space or added many spaces in between? We can rewrite the above as,

Name:[ ]*(.*)

That’s a space inside the square brackets. [ ]* represents 0 or more spaces. This way, we will match it, even if there is no space between the label “Name:” and the name that followis it. If used with a +, it will mean one or more spaces – at least one space must be there.

Next we have (.*). Dot (.) is any character and .* means zero or more characters. By enclosing a pattern within parantheses (), we make a “Capture Group”. This is what will be remembered (like in a variable) when this pattern is matched with a text. This can be returned and useful in Replace functionality. Each captured group will have a number associated with it – like $1*** for the first, $2 for the second etc. This is also called back reference. More on this later.

And we continue with the rest of the lines. The replace pattern will look like this:

$1\t$2\t$3\t\$4\n

That’s all captured variables ($1 – $4) separated by tab characters recognized by Excel as cell separators (we could also use Comma). End it with \n to push to the next line.

Voila! We have successfully converted a free-form text into a spreadsheet.

That was a rudimentary example. And if you noticed, I left out some complications – for e.g., what if they said 1 or 2 people will be coming and I want to take the maximum, meaning 2.

The fact is, Regex is never used alone in a tool like this. Often times, you will build this (and more regex) into a script/program to achieve the full desired results. Perl and Python are heavily invested in Regex. Other programming languages (including Java) do support Regex using some library API.

To be contd…


** As an aside, this is similar to the BNF form for writing language grammar (I’ve considered only positive whole numbers for this discussion):

2017-05-26 09_58_13-Document6 - Microsoft Word.png

*** Sometimes you will see \1 instead of $1.

Quicktip: Windows Remote Desktop – Screen size


Remote Desktop
Do you use Windows Remote Desktop to connect to other computers? If you work in an environment with a lot of servers/machines, chances are you do this constantly.
Typically, you will click on the Remote Desktop icon and you get a screen that looks the one shown below.

It asks you for a computer/server name to connect to. You type in the address and click connect, you get the login window for the remote machine. You type those in and click OK, you will be looking at the other machine’s desktop on your PC. Great tool to have, if you are dealing with multiple machines and you don’t want to get up and go to the other one (what if it that is in the other coast or across the oceans?) or you don’t need multiple monitors.

The display issue
I have one pet peeve about this software. I don’t know about you, but the most annoying thing for me, when using this application, is the display size. Often times, the windows gets scrunched in a corner or too big for the current (host machine’s) display. In this case, you will have to constantly scroll up and down to get to the Start button/task bar and the top of the file you are editing. With so many varied size of monitors available, it seems to be an endless fight!

Where is the start button and the task bar??
Here are some ways to fix that. Actually, Remote Desktop program does offer screen resolution adjustment. This may work for you.

Adjusting the Display size in Remote Desktop program (mstsc)
If you pay attention there is a “Options” button on the left. If you click on this button and go to Display option, you will the below screen.

Here you have an option to make it Full screen (just slide down to the right).

This typically, fixes the issue. After you do this, your remote desktop screen come in full screen, so you won’t the problem mentioned above.

Even if it looks like it is set to Large, try changing it and change back to Large, that may fix the issue.

What if that didn’t help?

But, in reality above tip may not always work. This is where I found the tips in below site very helpful.

5 tips for fixing Remote Desktop Screen settings

We have been clicking on the Remote Desktop icon blindly, that we forget that the program (mstsc*) takes parameters. Try forcing it to open in Fullscreen mode always, by adding it to the shortcut you click for Remote Desktop.

mstsc* /f

Or if you want a specfic size, you can pass in the preferred height and witdth.

mstsc* /H:980 /W:1924

(The actual height and width you use may be different for you. I have a wide monitor).

Alternatively, you can actually save these settings (Save button On the General tab) into a .RDP file and use that to connect to the remote machine. RDP file is actually a text file!! You can edit the settings. You edit the below settings to reolve the display size issue:

DesktopHeight:i:980
Desktopwidth:i:1924

Again these are for my screen. Change to suit your need.

After you do this, hopefully you never again have to do the endless scrolling up and down in Remote Desktop! Here is my rescued Start menu!

See here for more about the program and its parameters.

* In case you are wondering what is mstsc, it is the Remote desktop program on Windows. MSCTSC refers Microsoft Terminal Services Client, probably left over from earlier times. They keep changing the “name/description” of these programs, to keep you guessing!