Friday, March 30, 2012

Parsing the Logical expression

Sometimes you need to parse the logical expression.

I have made for my own purposes the regular expression which would distringuish all important tokens from the logical expression:
([\(!\s]*)[\s]*([^<=\s]+)[\s]*(<>|!=|==|<=|>=|<|>)[\s]*([^\s&|\)]*)[\s]*([\)]*)(&&|\|\|)?
or as java string:
"([\\(!\\s]*)[\\s]*([^<=\\s]+)[\\s]*(<>|!=|==|<=|>=|<|>)[\\s]*([^\\s&|\\)]*)[\\s]*([\\)]*)(&&|\\|\\|)?"

this would give for

 !(! (one== 56) && two>45) || !three!=funny
the following solution
Regular Expression ([\(!\s]*)[\s]*([^<=\s]+)[\s]*(<>|!=|==|<=|>=|<|>)[\s]*([^\s&|\)]*)[\s]*([\)]*)(&&|\|\|)?
as a Java string "([\\(!\\s]*)[\\s]*([^<=\\s]+)[\\s]*(<>|!=|==|<=|>=|<|>)[\\s]*([^\\s&|\\)]*)[\\s]*([\\)]*)(&&|\\|\\|)?"
Replacement $1fieldValue(\"$2\")$3$4$5$6
groupCount() 6
Test Target String matches() replaceFirst() replaceAll() lookingAt() find() group(0) group(1) group(2) group(3) group(4) group(5) group(6)
1 !(! (one== 56) && two>45) || !three!=funny No !(! (fieldValue("one")==56) && two>45) || !three!=funny !(! (fieldValue("one")==56) && fieldValue("two")>45) || !fieldValue("three")!=funny Yes Yes !(! (one== 56) !(! ( one == 56 ) null
next find() Yes two>45) two > 45 ) null
next find() Yes !three!=funny ! three != funny null

Friday, March 23, 2012

A useless, but nice Excel trick

To show just the fields in the worksheet which are useful, and hide all the rest of the fiels,

To Hide Rows

Select row whereyour data finishes
Press Ctrl + Shift + Down Arrow Key
Move mouse pointer over the row numbers, Right Click, Hide

To Hide Columns

Select Column 21
Press Ctrl + Shift + Right Arrow Keys
Move mouse pointer over the column numbers/letters, Right Click, Hide

Thursday, March 22, 2012

jQuery print example

This is just a small update of BenNadel's great post on printing the part of the page using jQuery/Javascript.

The code is placed here


Wednesday, March 7, 2012

Encoding troubles UTF-8 in Eclipse/Rational Application Developer...

Uh, I never understood at all what is the reason for all these encoding types!
I had to do some modifications on a custom made JavaEE project which uses velocity template engine. I ended up having a lots of encoding problems.

Now I want to write sort of a step by step instruction how fix it.

Ok, so let's start.
Sooo, you have troubles with your spring/javaEE eclipse project. Several steps to take a look:


1) Check here: Window->Preferences->General->Workspace->Text file encoding - set to UTF-8
This setting will let even your new files to be encoded in UTF-8. It is usual cause of troubleshttp://www.blogger.com/img/blank.gif

2) under Window->Preferences search for encoding keyword and set everything you see to UTF-8 (this does not help too much, but sometimes is useful)

3) If your files are created outside eclipse project, check whether they are written/saved in UTF-8 coding. Notepad++ has a nice feature that is able to show you encoding of your file/text and also to convert from one encoding to another. TRY NOT USING UTF-8 WITH BOM (adds additional bytes to the beginning of the textual file so the editors can know this is UTF-8. Otherwise it causes  at the beginning of the file as soon as you get some encoding issues (like with ISO-8859-1 and CP1252)).

3.1) if you find this a bit problematic you can either use:
- Solution with Batch Convert to UTF-8 with Iconv and Sponge (under the moreutils package).
- Use the UTFcast Express Edition

4) Usually, Spring and velocity are nicely interconnected, and easily solve the issue with encodings, but if the velocity is directly used, one has to take care additionally to use the getTemplate function in the following way:
getTemplate(templateFile,"UTF-8");
Otherwise, it defaults to ISO-8859-1.

Thursday, March 1, 2012

Samsung Galaxy S2 tip

It seems that Samsung is using by default the fast dormancy, a new technology which tries to save your battery life by turning your phone completely connection less if no activity is detected. This is cool, right? Not really, since in order for this to work, network provider has to support it as well, which makes the completely opposite effect, by draining the phone battery and still make phone disconnected when idle (e.g. no SMSes received).

To disable this (my strong suggestion), do the following:
*#*#9900#*#* and then choose
disable fast dormancy
and then
Exit
.

I have tested this already for 1 month, and it works pretty fine, and battery life is extended definitely by some 20%-30%.

Summary:
- it prolongs/extends the battery life
- it solves the issue of phone being completely disconnected at times

Sources:http://www.blogger.com/img/blank.gif
Source
More about fast dormancy:
Here

Some other codes are also interesting, which I haven't tested yet (but will test soon GPS configurations):
*#1234# (View SW Version PDA, CSC, MODEM)
*#12580*369# (SW & HW Info)
*#197328640# (Service Mode)
*#0228# (ADC Reading)
*#32489# (Ciphering Info)
*#232337# (Bluetooth Address)
*#232331# (Bluetooth Test Mode)
*#232338# (WLAN MAC Address)
*#232339# (WLAN Test Mode)
*#0842# (Vibra Motor Test Mode)
*#0782# (Real Time Clock Test)
*#0673# (Audio Test Mode)
*#0*# (General Test Mode)
*#2263# (RF Band Selection)
*#9090# (Diagnostic ConfiguratioN)
*#7284# (USB I2C Mode Control)
*#872564# (USB Logging Control)
*#4238378# (GCF Configuration)
*#0283# (Audio Loopback Control)
*#1575# (GPS Control Menu)
*#3214789650# (LBS Test Mode)
*#745# (RIL Dump Menu)
*#746# (Debug Dump Menu)
*#9900# (System Dump Mode)
*#44336# (Sofware Version Info)
*#7780# (Factory Reset)
*2767*3855# (Full Factory Reset)
*#0289# (Melody Test Mode)
*#2663# (TSP / TSK firmware update)
*#03# (NAND Flash S/N)
*#0589# (Light Sensor Test Mode)
*#0588# (Proximity Sensor Test Mode)
*#273283*255*3282*# (Data Create Menu)
*#273283*255*663282*# (Data Create SD Card)
*#3282*727336*# (Data Usage Status)
*#7594# (Remap Shutdown to End Call TSK)
*#34971539# (Camera Firmware Update)
*#526# (WLAN Engineering Mode)
*#528# (WLAN Engineering Mode)
*#7412365# (Camera Firmware Menu)
*#80# (Unknown)
*#07# (Test History)
*#3214789# (GCF Mode Status)
*#272886# (Auto Answer Selection)
*#8736364# (OTA Update Menu)
*#301279# (HSDPA/HSUPA Control Menu)
*#7353# (Quick Test Menu)
*2767*4387264636# (Sellout SMS / PCODE view)
*#7465625# (View Phone Lock Status)
*7465625*638*# (Configure Network Lock MCC/MNC)
#7465625*638*# (Insert Network Lock Keycode)
*7465625*782*# (Configure Network Lock NSP)
#7465625*782*# (Insert Partitial Network Lock Keycode)
*7465625*77*# (Insert Network Lock Keycode SP)
#7465625*77*# (Insert Operator Lock Keycode)
*7465625*27*# (Insert Network Lock Keycode NSP/CP)
#7465625*27*# (Insert Content Provider Keycode)
*#272*imei#* (Product code)