Friday, October 7, 2022

Reversing a Odia Unicode String

Odia is a language with lot of combining characters. Therefore simple reversal of string like str.split('').reverse().join('') will not work . With this naive approach, the reverse of string like ଜଳାର୍ଣ୍ଣବ will end up in ବଣ୍ଣ୍ରାଳଜ where as the expected reversal would be ବର୍ଣ୍ଣଳାଜ. 

Even I failed with BreakIterator of Java with Odia Locale. I also tried packages like esrever but failed. Finally I tried with basic decomposition of Unicode Odia syllables. A string like ଜଳାର୍ଣ୍ଣବ is composed of characters like [  'ଜ', 'ଳ', 'ା', 'ର',  '୍',  'ଣ', '୍',  'ଣ',  'ବ' ], therefore handling the matras and falas did the job. Here is the code in JavaScript: 

function reverseOdia(str)
{
   var reverseStr = "" ;
   var chars = [...str] ;
   var maatraas = "ାିୀୁୂୃେୈୋୌଂଁ";
   var isEnd = false ;
   syllable = "" ;
   for (let index = 0; index < str.length; index++) {
      char = str[index] ;
      nextChar = str[index+1] ;
      syllable += char ;
      if (maatraas.indexOf(nextChar) != -1 ) {
         syllable += nextChar ;
         index++ ;
         isEnd = true ;
      }
      else {
         if( nextChar == '୍') {
            isEnd = false ;
            syllable += nextChar ;
            index++ ;
         }
         else {
            isEnd = true ;
         }
      }
      if (isEnd)
      {
         reverseStr = syllable + reverseStr ;
         syllable = "" ;
      }
   }
   return reverseStr ;
}

str = "ଜଳାର୍ଣ୍ଣବ" ; // କଟକ // ଅସତ୍‌କର୍ମ // ନୃପସ୍ଥାୟକ ;
console.log(reverseOdia(str)) ;

Saturday, July 30, 2022

Katex: Cool Math for Web

 Well, I was late to discover Katex. It's really cool and faster in rendering Math in Web. Just downloaded the Katex Release, and got it working. Sample code below:

<!DOCTYPE html>
<!-- KaTeX requires the use of the HTML5 doctype. Without it, KaTeX may not render properly -->
<html>
  <head>
    <!-- 
    <link href="fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2">
    <link href="fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2">
    <link href="fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2">
    <link href="fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2">
    -->
    <link rel="stylesheet" type="text/css" href="katex.min.css">
    <script src="katex.min.js"></script>
    <script src="contrib/mhchem.min.js"></script>
    <script src="contrib/copy-tex.min.js"></script>
    <script src="contrib/auto-render.min.js"></script>
    <script>
        function ready() {
            renderMathInElement(document.body, {
                delimiters: [
                  {left: "$$", right: "$$", display: true},
                  {left: "\\[", right: "\\]", display: true},
                  {left: "$", right: "$", display: false},
                  {left: "\\(", right: "\\)", display: false}
                ]
            });
        }
    </script>
  </head>
  <body onload="ready()">
    <div>The formula $a^2+b^2=c^2$ will be rendered inline, but $$a^2+b^2=c^2$$ will be rendered as a block element.</div>
    <br>
    <div>The formula \(a^2+b^2=c^2\) will be rendered inline, but \[a^2+b^2=c^2\] will be rendered as a block element.</div>
    
</body>
</html>

Monday, January 3, 2022

How to Geotag a Photo safely and effectively

Of late, I found that, If a photo is shared over Whatsapp, the Geotag is lost. I guess, WhatsApp removes it in order to compress the image so as to reduce the size.

Many Android users use third party software to Geotag the photos. These software impose the location on top of the photo like a watermark. Actually the Geotag Location information is stored internally as extra information in the image. Those software just impose that location information on top of the photo just to give an impression to the ordinary user that the photo got geotagged.  However these software MAY be harmful because you dont know what all permissions you have allowed while installing it.

The trouble comes, when the photo is shared over Whatsapp. Whatsapp simply remove the Geotag Location information (EXIF data) when shared as a photo. The location information imposed by those third-party software as a watermark on those photos are still visible when shared over Whatsapp but technically those photos are NOT geotagged.

How to Geotag safely and effectively

You really dont need any third-party software to Geotag a photo.

1. Just enable Location/GPS in your phone

2. Also enable Location in your Camera app's settings. Dont worry if such option is not there in your phone.

3. Take the photo.

4. Do not share over Whatsapp as a photo. If you do so, the location information is lost. However you can share it as document in Whatsapp.

5. You can transfer the photo using phone cable, Email, Bluetooth, Wifi-Direct etc.

In few of the gallery apps, you can find the location of the photo in the details view. Alternatively you can use this service http://exif.regex.info/exif.cgi to check if the photo is geotagged or not.