tag:blogger.com,1999:blog-4081249896445464492024-03-14T13:16:21.794+06:00Ε Γ И І И О# c o d e rΕ Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.comBlogger23125tag:blogger.com,1999:blog-408124989644546449.post-63484564579013124412020-11-24T17:02:00.014+06:002020-11-25T11:34:55.889+06:00Touchpad not working on CloudReady / Chrome OS? Here's how to fix it!<p>Covid-19 break seems to be opening up interesting avenues for me. I started a storeroom cleanup activity and I found an old laptop which I set aside a long time back. To my surprise, it booted up with no issues but the OS was extremely slow. It was running Windows but only had 2GB RAM. My instant thought was to install Linux on it.</p><p>So without even thinking, I started downloading Ubuntu. That's what you install when it comes to Linux, right? When the download was almost done, I figured that I was wrong. Ubuntu now requires 4GB RAM at a minimum! Sigh!</p><p>So I started looking at lighter distros. One was Lubuntu, which claimed to work with 2GB RAM. I downloaded that onto my flash drive and booted it up. It came straight to the GUI, without prompting me to install it. Now Lubuntu is running off my flash drive, and I cannot seem to find a way to make it install into the laptop. Maybe I have downloaded the wrong image, but whatever! (Guess what, there was this BIG icon on the desktop titled "Install OS" and I've missed it. So much for being a Software Engineer.)</p><p>One of my searches came up suggesting me to try out Chrome OS. I've been excited about it ever since Google released it but have never got a chance to try it out. Well, my laptop was made by <a href="https://en.wikipedia.org/wiki/EMachines" target="_blank">eMachines</a>, so there is no way I could install the version that comes installed on Chromebooks. But I found that a company called Neverware releases a port of Chrome OS for free. That sounded just right for me, so I got that downloaded by following the instructions on their website: <a href="https://www.neverware.com/freedownload#home-edition-install">https://www.neverware.com/freedownload#home-edition-install</a></p><p>And then it happened again. The OS booted up off the flash drive just like Lubuntu without prompting me for a clean install. But at least this time, I didn't have to curse all the way up to Linus Torvalds because CloudReady was much more explicit. Thank you! But my joy didn't last very long. Once the OS was installed and the laptop booted from its own hard drive, the touchpad seems to be not working. Now you cannot conveniently press the Windows key, type Device Manager, and go look for an updated driver, can you? Once again, Google to the rescue. How can something be more ironic?</p><p></p><p>Thankfully, I'm not alone. This touchpad issue seems to be something resident with Chrome OS. But the bad news is none of the solutions mentioned on the threads in <a href="https://neverware.zendesk.com/hc/en-us/search?utf8=%E2%9C%93&query=touchpad+not+working" target="_blank">CloudReady Community</a> worked for me. The only promising solution was <a href="https://arnoldthebat.co.uk/wordpress/2013/01/08/how-to-get-the-touch-pad-working-in-chromium-os/" target="_blank">this</a>. It sounded insanely simple. But I hit some roadblocks while following along. Keep that link open on a separate tab, we'll be needing to refer it from time to time.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-tIBX8ndaEoU/X7vQ_aJ5XII/AAAAAAAAR68/Q9J1Xx8hZmAcHZgnamGog5zOLPiq-wIoACLcBGAsYHQ/s505/ChromiumOsFix.PNG" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="322" data-original-width="505" height="254" src="https://1.bp.blogspot.com/-tIBX8ndaEoU/X7vQ_aJ5XII/AAAAAAAAR68/Q9J1Xx8hZmAcHZgnamGog5zOLPiq-wIoACLcBGAsYHQ/w400-h254/ChromiumOsFix.PNG" width="400" /></a></div><p>And before I forget, I've been doing my research on my regular laptop which was running Windows, and trying out all the hacks on the other. I didn't have an external mouse at my disposal, otherwise, I would've done all that in CloudReady itself. I recommend doing it there itself because it makes your life easy when it comes to copying URLs and stuff.</p><p>First of all, you need to open up a terminal. It turned out that Ctrl+Alt+F2 doesn't work on CloudReady. You need to hit Ctrl+Alt+T in Chrome to get a terminal. And when you type '<span style="font-family: courier;">sudo su</span>', it doesn't seem to like that.</p><p>Then you learn you need to type '<span style="font-family: courier;">shell</span>', to get a proper terminal, or bash if that's what you should be calling it. And voila, you get a bash logged in as 'chronos', who is the root I believe. Perfect!</p><p>Now you try out the command '<span style="font-family: courier;">mount -o remount, rw /</span>' just to learn that it doesn't work either. It tells you that '<span style="font-family: courier;">mount: only root can use "--options" option'</span>. Seems 'chronos' is not the root after all.</p><p>Now you learn you gotta type 'sudo su -' to log in as root. And then you get a properly elevated bash, along with some funny warnings saying now you should better know what you are doing. Yeah right! What you are actually going to do is execute some low-level commands on your laptop, as root, which some stranger on the Internet claimed to fix your touchpad. So much for security!</p><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto;"><tbody><tr><td style="text-align: center;"><a href="https://1.bp.blogspot.com/-QnUtyDDvAwo/X73PKqeQDNI/AAAAAAAAR7c/3U51Zp97wxML19u67D8msEZYbnnR2VyvQCLcBGAsYHQ/s1366/Screenshot%2B2020-11-25%2Bat%2B8.19.42%2BAM.png" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="768" data-original-width="1366" height="225" src="https://1.bp.blogspot.com/-QnUtyDDvAwo/X73PKqeQDNI/AAAAAAAAR7c/3U51Zp97wxML19u67D8msEZYbnnR2VyvQCLcBGAsYHQ/w400-h225/Screenshot%2B2020-11-25%2Bat%2B8.19.42%2BAM.png" title="You got thus far..." width="400" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><br /></td></tr></tbody></table>So you run the mount command again anyway, just top be greeted with this: '<span style="font-family: courier;">mount: cannot remount rw read-write, is write protected</span>'. Well, this is the built-in protection kicking in so you cannot go around doing any harm out of your own stupidity, even as root. You need to disable it. That's how the hacker gets to gain access to your system remotely. Wait, what?<span> </span><p>Type "<span color="rgba(0, 0, 0, 0.8)" style="background-color: white;"><span style="font-family: courier;">sudo disable_verity</span></span>" to take care of that. Oh, I forgot to mention, that step was irreversible. Too late to worry about that now, so go ahead and reboot. Well, how? You may ask. "<span color="rgba(0, 0, 0, 0.8)" style="background-color: white;"><span style="font-family: courier;">sudo reboot</span></span><span color="rgba(0, 0, 0, 0.8)" style="background-color: white; font-family: monospace, monospace; font-size: 13.8px;">" </span>is what you need.</p><p>Once you are back online, try out the mount command again and it shouldn't give you an error this time. Remember, you gotta repeat the steps to log in as root first. Now you try out the next command in that tutorial "<span style="font-family: courier;">cp /etc/X11/xorg.conf.d/50-touchpad...</span>" and figure out that it doesn't work as well. The reason seems to be that the path does not exist. Now you are literally screwed!</p><p>I didn't understand any of those Linux bash commands on that tutorial, but with my limited DOS knowledge, I could tell that we are trying to backup an existing configuration file related to the touchpad and then replace the original with one from the Internet.</p><p>So the first thing I did was to see if that URL still works. All my future effort will go in vain if that final bit fails. <a href="https://chromium.arnoldthebat.co.uk/files/fw/etc/X11/xorg.conf.d/50-touchpad-cmt.conf">httpys://chromium.arnoldthebat.co.uk/files/fw/etc/X11/xorg.conf.d/50-touchpad-cmt.conf</a> seems to be valid. Now I need to find where the heck my configuration files are.</p><p>First I tried a couple of DOS commands and was surprised to find out that those work! There's that "etc" folder, but there is no 'X11'. I need to find where my touchpad configuration file is. A little bit of googling told me that "<span style="font-family: courier;">find -name "*touchpad*.*</span>" will do the trick.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-1u0BpH5yp5k/X73X9gqtfsI/AAAAAAAAR70/b6T0WAskfzo3KvKZG3pK5jVwrgm98uqZACLcBGAsYHQ/s1366/Screenshot%2B2020-11-25%2Bat%2B9.34.33%2BAM.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="225" src="https://1.bp.blogspot.com/-1u0BpH5yp5k/X73X9gqtfsI/AAAAAAAAR70/b6T0WAskfzo3KvKZG3pK5jVwrgm98uqZACLcBGAsYHQ/w400-h225/Screenshot%2B2020-11-25%2Bat%2B9.34.33%2BAM.png" title="'X11' folder is no more!" width="400" /></a></div><p>There you have it. That stupid config is buried in the "gesture" folder now. But wait, the name is somewhat different. Mine is called "40-touchpad-cmt.conf", so I'm guessing that replacing it with the one mentioned in the tutorial is not gonna work. Off to google again...</p><p style="text-align: left;">Searching for that file name took me here: <a href="https://chromium.googlesource.com/chromiumos/platform/xorg-conf/+/refs/heads/master/40-touchpad-cmt.conf">https://chromium.googlesource.com/chromiumos/platform/xorg-conf/+/refs/heads/master/40-touchpad-cmt.conf</a>. That seems to be mirroring their official repo if I'm not mistaken. But how the heck am I gonna download this without the nagging html styling? Well, it turns out there is no such way! Really? Well, I got a better idea. How about just copy-paste the damn text into a new file and host it somewhere? Github Gists to the rescue!</p><p>So I created a gist with the content of that file. Now anyone can download it as a raw file by going to this URL: <a href="https://gist.githubusercontent.com/elninoisback/82d0a014d13c330d225cbcd52ed3ceb9/raw/4ae1773388197ef1802953873e2ae2e2cf38aaed/40-touchpad-cmt.conf">https://gist.githubusercontent.com/elninoisback/82d0a014d13c330d225cbcd52ed3ceb9/raw/4ae1773388197ef1802953873e2ae2e2cf38aaed/40-touchpad-cmt.conf</a>. But wait, how on earth am I going to type that into a console? I could've used my keyboard skills to open up a new tab, login to my Github, and try to copy that off somehow, but I was too lazy for that. I tried a URL shortener instead. So now it's down to this: <a href="http://shorturl.at/qtvMS">http://shorturl.at/qtvMS</a>. I dunno if this will stay working forever, but you just need it to work only 5 minutes, so why not?</p><div style="text-align: left;">Back to the bash. Few commands to get inside the "gesture" folder. Then run the following:</div><div style="text-align: left;"><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;">cp 40-touchpad-cmt.conf 40-touchpad-cmt.conf.bak
rm 40-touchpad-cmt.conf
wget http://shorturl.at/qtvMS</span></div><div style="text-align: left;"><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: Noto Mono, Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;">mv qtvMS 40-touchpad-cmt.conf</span></div><div style="text-align: left;"><br /></div><div style="text-align: left;">If you are lucky, you will have no issues. If so, skip the below step. But for me, nah, are you kidding me? I wasn't that lucky. It said "wget" is not a valid command. Fcuk this, I'm going to install Windows XP. Yep, that's exactly what I felt. But after a little bit of more googling, I got to know that you can actually enable wget by running the below:</div><div style="text-align: left;"><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;">sudo su - <br /></span><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;">dev_install<br /></span><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;">emerge net-misc/wget</span></div><div style="text-align: left;"><span style="background-color: #f6f7f8; color: #1c1c1c; font-family: "Noto Mono", Menlo, Monaco, Consolas, monospace; font-size: 13px; white-space: pre;"><br /></span></div><div style="text-align: left;">So after getting that hosted config file downloaded into that folder, and after getting it renamed back to its original name, you gotta reboot the laptop. We covered that earlier didn't we? Just type "<span style="font-family: courier;">sudo reboot</span>", and the next time when it boots, your touchpad will be responsive! Err but I know your mileage might vary. Did I mention, you gotta be very very lucky too? :P</div><div style="text-align: left;"><br /></div><div style="text-align: left;">If you got any hiccups, or even if this didn't work for you at all, let me know in the comments. I'll try my best to help you out. Cheers to your new OS!</div>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-39067642208120927312020-07-20T16:17:00.005+06:002020-08-06T01:13:02.442+06:00What's Blazor WebAssembly and why should you care?<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">There was a peaceful time where web application development was simple. With ASP.NET, all we had to do was just open the IDE and drag UI elements from a toolbox to design a web page. Double-click on a button and we could write code in C# to be executed when that button was clicked, without needing to worry about how the web works. Needless to say, Microsoft devotees like me were living the dream. Well, JavaScript was still there, but it was the black sheep in the family, due to its amateurish design and issues with compatibility. Nobody took it seriously unless they wanted some fancy animations. And then, someone saw it through and started standardizing it across browsers. It didn't take long for AJAX to come along and turn things upside down. We survived the first wave but when jQuery hit us, it hit us hard. Just when we were coping with the repercussions, a plethora of JavaScript-based SPA frameworks started to mushroom. All hell broke loose.</span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;"><a href="https://1.bp.blogspot.com/-2lm0N_D0-do/XysEgJ3WcHI/AAAAAAAARWw/t8OftVQ9Hoo_biFARl68wuMTMPrOYovUwCLcBGAsYHQ/s586/meme.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="426" data-original-width="586" height="232" src="https://1.bp.blogspot.com/-2lm0N_D0-do/XysEgJ3WcHI/AAAAAAAARWw/t8OftVQ9Hoo_biFARl68wuMTMPrOYovUwCLcBGAsYHQ/w320-h232/meme.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div>
</div><div style="text-align: justify;"><span style="font-family: "trebuchet ms", sans-serif;">Does the above sound relatable? Well then guess what, </span><span style="font-family: "trebuchet ms", sans-serif;">Microsoft's Blazor WebAssembly is exactly </span><span style="font-family: "trebuchet ms", sans-serif;">what you've been dreaming of. Finally, a framework where you could forget about JavaScript and write client-side code in C# over WebAssembly. Sounds crazy right? But what on earth is WebAssembly anyway? It's another type of code that can be run on the JavaScript runtime which already comes built-in to browsers. WebAssembly in its purest form is not exactly readable. Hello, it's called Web *Assembly*! Ring any bells? But the thing is, you can convert code written in other languages to WebAssembly and make them run on the browser. That's how you get to write C# code instead of JavaScript. But wait, isn't C# compiled into IL and needs a .NET runtime? Well, how correct you are. That's why the Microsoft guys have ported the .NET runtime to WebAssembly which in turn runs your compiled code. Sweet!</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="clear: left; float: left; font-family: "trebuchet ms", sans-serif; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="380" data-original-width="1358" height="110" src="https://1.bp.blogspot.com/-Uehke-4CBwQ/XxVOVUSWybI/AAAAAAAARTI/HwMNQ1YEK80Omkng1TOy3NMMs0bOBKKWgCLcBGAsYHQ/s400/WA1.PNG" width="400" /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">I must mention that there is a different way to use Blazor on the server-side, having no dependency on WebAssembly whatsoever. It's called the 'Blazor Server' where the client-side becomes extremely lightweight and the plumbing happens via SignalR. But that's not everybody's cup of tea, at least not mine. And probably a topic for another day so don't get confused when I say 'Blazor', it's short for Blazor WebAssembly. </span><span style="font-family: "trebuchet ms", sans-serif;">Before you get all skeptical, Blazor WebAssembly is now production-ready and is officially released in May 2020. What's even better is that the 3rd party UI component builders like Telerik, DevExpress, Infragistics and the rest have already hopped in the bandwagon with their library counterparts for Blazor. It is open-source and free therefore it's receiving immense community support from around the world as a lot of additional component libraries, frameworks and whatnot are being created for Blazor as we speak. The ecosystem is booming and trust me it will be huge when .NET 5 hits the shores in November. So, this would be the best time to start investing, if you know what I mean.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">Let's briefly look at a couple of things Blazor provides you out of the box. If you happen to create a Blazor app using the template which uses ASP.NET Core as the back-end, you can enable authorization with a single line of code. The authorization bearer tokens would be included in the request headers without you needing to do any manual work, thanks to the boilerplate code created by the project template. Localization is a similar cross-cutting concern but .NET has a proven way of nailing it for decades. Yes, you guessed it right, Resource Files FTW! You just have to wrap your string literals with @Localize[""] and the magic happens behind the scenes. The same goes for other i18n aspects like the number and date formats. .NET thread culture is set </span><span style="font-family: "trebuchet ms", sans-serif;">automatically</span><span style="font-family: "trebuchet ms", sans-serif;"> </span><span style="font-family: "trebuchet ms", sans-serif;">to the browser's culture so there is very little left for you to do.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-DsEu0QYm2ZI/XxfaiiOFkVI/AAAAAAAART4/DG33SDww1MslgFB09z1NmcOGg2CPrVzDgCLcBGAsYHQ/s1600/feat1.png" style="clear: right; float: right; font-family: "times new roman"; margin-bottom: 1em; margin-left: 1em; text-align: center;"><img border="0" data-original-height="256" data-original-width="808" height="126" src="https://1.bp.blogspot.com/-DsEu0QYm2ZI/XxfaiiOFkVI/AAAAAAAART4/DG33SDww1MslgFB09z1NmcOGg2CPrVzDgCLcBGAsYHQ/s400/feat1.png" width="400" /></a></div>
<span style="font-family: "trebuchet ms", sans-serif;"></span><br />
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">Interoperability with JavaScript is another cool feature that shouldn't go unnoticed. Blazor supports calling JavaScript from .NET and vice versa. It becomes quite handy when you want to reuse an existing JavaScript library without wanting to rewrite it in Blazor. Incidentally, you might also want to write your own piece of JavaScript code and make it available for Blazor. Whatever the requirement, it's a piece of cake to hook these two together. If you are conscious about offline support, you'll need to use IndexedDB, the NoSQL storage provided by the browser. And if you've already used it by any chance, you know its asynchronous API is a disaster to work with. But the good news is, there are NuGet packages already being built for Blazor which lets you consume it similar to EF, letting you only worry about the data and not how you store or retrieve it. </span></div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-lA3GPkpxeco/Xxfa9ml6BGI/AAAAAAAARUA/zS3hTPABrs45wDLV1EdutnYS0Eh4FM0_gCLcBGAsYHQ/s1600/feat2.png" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" data-original-height="266" data-original-width="694" height="122" src="https://1.bp.blogspot.com/-lA3GPkpxeco/Xxfa9ml6BGI/AAAAAAAARUA/zS3hTPABrs45wDLV1EdutnYS0Eh4FM0_gCLcBGAsYHQ/s320/feat2.png" width="320" /></a></div>
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms", sans-serif;">One other great feature you get when developing with Blazor is full-stack debugging support in Visual Studio. For example, you can seamlessly put breakpoints in your server code, client code or even in JavaScript code which you interop with and simultaneously step through them in a single session. There are no messy debugger statements or switching between IDEs, just true full-stack debugging. And you can even do the same in Visual Studio Code. Since Blazor uses regular .NET assemblies on the client, code sharing becomes a breeze. How many times have you had to duplicate your DTOs in your server and client? Since it's all in .NET now, you can just define them in a shared library and refer it either from server or client, being totally oblivious to the fact that the latter runs on a browser.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<a href="https://1.bp.blogspot.com/-o5GEN3LVe1s/XxVPLVPxGII/AAAAAAAARTU/fbXadOGRD64_G3VDRLEdv6Ekoh_i89nLACLcBGAsYHQ/s1600/WA0.png" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;"><span style="font-family: "trebuchet ms", sans-serif;"><img border="0" data-original-height="352" data-original-width="352" height="200" src="https://1.bp.blogspot.com/-o5GEN3LVe1s/XxVPLVPxGII/AAAAAAAARTU/fbXadOGRD64_G3VDRLEdv6Ekoh_i89nLACLcBGAsYHQ/s200/WA0.png" width="200" /></span></a><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">There is more to Blazor apps like its ability to convert them into Progressive Web Apps and to be hosted as pure static sites. So it's definitely something you should try out to see where it stands in the crowd. And if you are a .NET enthusiast, it's undoubtedly a crucial skill set to add to your arsenal. It's already a game-changer and there is so much yet to come. Keep an eye out for stuff like Hot reloading, AoT compilation and CSS isolation when Blazor gets shipped with .NET 5. Visit <a href="https://blazor.net/" target="_blank">https://blazor.net</a> today and give it a try. The tables have started to turn, so grab your seat. It's now or never!</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms", sans-serif;">References:</span></div>
<div style="text-align: justify;">
</div>
<ol>
<li><a href="https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-now-available/"><span style="font-family: trebuchet;">https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-now-available/</span></a></li>
<li><a href="https://www.pluralsight.com/courses/web-assembly-big-picture"><span style="font-family: trebuchet;">https://www.pluralsight.com/courses/web-assembly-big-picture</span></a></li>
<li><a href="https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor"><span style="font-family: trebuchet;">https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor</span></a></li>
<li><a href="https://youtu.be/My_XOzQWwc4"><span style="font-family: trebuchet;">https://youtu.be/My_XOzQWwc4</span></a></li>
</ol>
<br />
<div style="text-align: justify;">
<br /></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-63621723743324823822020-05-10T16:06:00.008+06:002020-05-13T11:16:38.985+06:00Singleton: Are you doing it right?<div style="text-align: justify;">
<b style="font-family: "trebuchet ms", sans-serif;">"Tell us about a design pattern that you've used."</b></div>
<span style="font-family: "trebuchet ms" , sans-serif;"></span><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Probably one of the most asked questions in a programming interview. And the canned answer always happens to be "Singleton". Why? Because that's the easiest design pattern which you cannot go wrong with. Or is it?</span></div>
<span style="font-family: "trebuchet ms" , sans-serif;"></span><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">If you don't remember what singleton code looks like, I don't blame you because I don't either. But after giving a little bit of thought, you might be able to come up with this:</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<script src="https://gist.github.com/elninoisback/ad415be4363fc0d21db869aba8b1843d.js"></script><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Well, true it doesn't have all the bells and whistles like thread-safety and whatnot, but it's a good start. To be frank, I hate locks. It makes the code looking out of place. May be it's just me.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">But I have to admit, thread syncing is crucial if you are serious about multi-threaded execution. And you might even want to use "<a href="https://en.wikipedia.org/wiki/Double-checked_locking" target="_blank">double-checked locking</a>" to favor performance. But what if we could get the same without using locks?</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<script src="https://gist.github.com/elninoisback/ee40d9414af7e91c71f4867921251ba4.js"></script><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Notice that the above code makes use of how static type initialization works. Static type initialization is guaranteed to happen only once per AppDomian hence line 3 will be executed by the runtime only once, no matter how many threads asked for it.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">So what's the caveat? Hmm, glad that you asked. Well, apparently you cannot guarantee when this initialization kicks off, so spawning of our singleton instance will not exactly be "lazy". In fact, it would even be initialized without the class being referred at all. Yikes! Can we fix it?</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">That's why we've slapped a static constructor in line 6. Mind you, you could've written the same code without it and it'll still work. But with that in place, the compiler generates IL code which fires the initializers in a more predictable fashion. Now the initialization would only happen whenever you refer the static class for the first time. But still, it's not ideal. At least in theory.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">What if you have other static members in this class? They could get referred elsewhere and your singleton instance would be spawned prematurely. It's a valid case h</span><span style="font-family: "trebuchet ms", sans-serif;">ypothetically</span><span style="font-family: "trebuchet ms", sans-serif;">. To circumvent this, you could add a nested static class only to hold your singleton instance and return it when needed. But that's overkill in my opinion. I'm pretty content with the above.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Ok, but can't we achieve this lazy behavior with something much more simple? Sure you can. </span><span style="font-family: "courier";">Lazy<T></span><span style="font-family: "trebuchet ms" , sans-serif;"> to the rescue!</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<script src="https://gist.github.com/elninoisback/54d2fa028b3cb085eb80a762319d39cb.js"></script><br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">This seems to be the most elegant solution of all. It has everything we tried to achieve: performance and laziness in one package. Have you coded your singletons like this? I have to confess that I have not. In fact, I've only used the style shown in the 2nd code snippet. But I'm looking forward to try out the <span style="font-family: "courier";">Lazy<T></span> implementation when I get my next chance. probably you should give it a shot too. Cheers!</span></div>
<br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">PS: One more thing to note before wrapping up. By using locks or static initialization, you are only making your "singleton instance initialization" thread-safe. It doesn't magically make your other instance methods that do the real productive work thread-safe. You'll need to handle those case by case, if they are prone to be problematic in multi-threaded environments. </span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-85335448092345266262020-05-02T16:11:00.001+06:002020-05-10T16:48:33.010+06:00Demystifying pass by value & pass by reference<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Here's a simple code block. Try to figure out the possible output.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<a href="https://1.bp.blogspot.com/-zyYHaV8JFD4/Xq0LJkYvvLI/AAAAAAAAQnE/mliHEKuCxjk7PyzRfCcHYATOKu9nePhtwCLcBGAsYHQ/s1600/pass%2Bby%2Bref.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "trebuchet ms" , sans-serif;"><img border="0" data-original-height="591" data-original-width="921" height="409" src="https://1.bp.blogspot.com/-zyYHaV8JFD4/Xq0LJkYvvLI/AAAAAAAAQnE/mliHEKuCxjk7PyzRfCcHYATOKu9nePhtwCLcBGAsYHQ/s640/pass%2Bby%2Bref.PNG" width="640" /></span></a></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">When you run this, the </span><span style="font-family: "courier new" , "courier" , monospace;">test1.Name</span><span style="font-family: "trebuchet ms" , sans-serif;"> will still write </span><span style="font-family: "courier new" , "courier" , monospace;">"original"</span><span style="font-family: "trebuchet ms" , sans-serif;"> to the console. If you thought that accessing </span><span style="font-family: "courier new" , "courier" , monospace;">test1.Name</span><span style="font-family: "trebuchet ms" , sans-serif;"> after it being set to </span><span style="font-family: "courier new" , "courier" , monospace;">null</span><span style="font-family: "trebuchet ms" , sans-serif;"> will throw a </span><span style="font-family: "courier new" , "courier" , monospace;">NullReferenceException</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "trebuchet ms" , sans-serif;">then you definitely need to keep on reading :)</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">If you got the correct answer, then good for you but you might also be wondering why I pulled out a silly question like this which the outcome is fairly obvious. Well, it turned out that it's not fairly obvious to an untrained eye, despite how many years it might have looked at code.</span><br />
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif;">I had a somewhat heated argument with one of my colleagues regarding this phenomenon, who happened to be a seasoned programmer. And finally, I had to type the above code in Visual Studio to prove my point. So I believe that this is a tricky area where most programmers tend to trip sooner or later. Hopefully, this post will set things straight.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><b>Back to Basics</b></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">So what are value types and reference types? In .NET, value types are derived from </span><span style="font-family: "courier new" , "courier" , monospace;">System.ValueType</span><span style="font-family: "trebuchet ms" , sans-serif;"> and reference types are derived from </span><span style="font-family: "courier new" , "courier" , monospace;">System.Object</span><span style="font-family: "trebuchet ms" , sans-serif;">. While value types are generally stored in the stack, reference types are stored in the managed heap. Examples of value types are </span><span style="font-family: "courier new" , "courier" , monospace;">Int</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">Char</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">DateTime</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">Enum</span><span style="font-family: "trebuchet ms" , sans-serif;"> or </span><span style="font-family: "courier new" , "courier" , monospace;">Struct</span><span style="font-family: "trebuchet ms" , sans-serif;"> whereas </span><span style="font-family: "courier new" , "courier" , monospace;">String</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">Delegate</span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;">Interface</span><span style="font-family: "trebuchet ms" , sans-serif;"> or </span><span style="font-family: "courier new" , "courier" , monospace;">Class</span><span style="font-family: "trebuchet ms" , sans-serif;"> are examples of reference types.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">You can think of a variable as a container. When the variable is of a value type, the variable's value is stored inside the container itself. But when the variable is of a reference type, what the container contains is not its actual value but a light-weight meta value pointing to a different place where you would find the actual value.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">The best analogy I can think of is the meta redirect tag on an HTML page. When you access this page's URL from a browser, some HTML would be rendered. But due to the meta redirection, what's rendered would be fetched from a different URL. The original page is the container of your reference type variable. However, when you access it, it will bring you the value from a different place.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">I hope I didn't make it sound more confusing. I'm trying my best to explain without talking about pointers.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Ok so if you've been following me thus far, you would still scratch your head why on earth a reference type variable still holds its value even after being set to null. For that, you have to understand what happens when you pass variables around.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><b>Pass by value & pass by reference</b></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">When you pass a variable to a method by value, you pass a copy of that variable. So whatever you do to that variable does not affect the original. But when you pass by reference, you work with the same copy and therefore all changes are sort of "global".</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><b><br /></b></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">In the above example, what you saw is an example of a variable passed by value.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Wait, what? Isn't that a reference type variable? Don't they get passed only by reference? You may ask.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Well, that's what you used to believe because whenever you manipulate an object's properties via a passed in variable, the original object retains those changes throughout. But if that was passed by value as I say, how could those changes persist? <span style="background-color: white;">Yes, it's </span></span><span style="font-family: "trebuchet ms" , sans-serif;"><span style="background-color: white;">highly confusing when the phrase "objects are passed by reference" is already baked into your head.</span></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Back to basics. Go back and read how I explained the variables using a container analogy. When you pass a reference type variable to a method, by value, shown in the example above, a copy of the variable is passed in just like for any value type. In this cause, what do we have inside the variable's container? A meta value pointing to a different place.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Was a copy of the value which it points, created? No. Then? Only a copy of the variable with its content was created. A reference type variable does not contain its value inside it, so now we just have two variables pointing to the same actual value. What happens when we set this new copy to null? Does it change what it pointed earlier? No. Just like when you change the meta redirect tag in an HTML page. Just because it redirects to a new URL now, it doesn't magically delete the HTML page which it redirected earlier. That page will still continue to exist.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">If you want to change the original content of a variable from inside a method which it was passed in, you need to pass in by reference using </span><span style="font-family: "courier new" , "courier" , monospace;"><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ref" target="_blank">ref</a></span><span style="font-family: "trebuchet ms" , sans-serif;">, </span><span style="font-family: "courier new" , "courier" , monospace;"><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier" target="_blank">out</a></span><span style="font-family: "trebuchet ms" , sans-serif;"> or </span><span style="font-family: "courier new" , "courier" , monospace;"><a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in-parameter-modifier" target="_blank">in</a></span><span style="font-family: "trebuchet ms" , sans-serif;"> keyword.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Woah, wait. Then how did my code work all this time? I happen to mutate my objects all over the place without a problem not worrying about how I passing them in</span><span style="font-family: "trebuchet ms" , sans-serif;">.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Err... well yeah that's probably because most of the time, if not all that you did was the dot (.) dance on your objects. Back in the day, we had to explicitly say go fetch data using the arrow (->) notation when dealing with reference type variables, so this confusion was not commonplace I suppose. But now, dotting on a reference type variable or on a value type variable (think of a Struct) works more or less the same way, thanks to the compiler.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><b>Retrospect</b></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">If you take the above example and change the line inside </span><span style="font-family: "courier new" , "courier" , monospace;">ModifyTest1</span><span style="font-family: "trebuchet ms" , sans-serif;"> method to </span><span style="font-family: "courier new" , "courier" , monospace;">test1.Name = "fake";</span><span style="font-family: "trebuchet ms" , sans-serif;"> the output would print </span><span style="font-family: "courier new" , "courier" , monospace;">"fake"</span><span style="font-family: "trebuchet ms" , sans-serif;"> instead of </span><span style="font-family: "courier new" , "courier" , monospace;">"original"</span><span style="font-family: "trebuchet ms" , sans-serif;">. Because as soon as you do </span><span style="font-family: "courier new" , "courier" , monospace;">test1.(something)</span><span style="font-family: "trebuchet ms" , sans-serif;"> it applies to the destination object instance. But when you do </span><span style="font-family: "courier new" , "courier" , monospace;">test1 = null;</span><span style="font-family: "trebuchet ms" , sans-serif;"> or even </span><span style="font-family: "courier new" , "courier" , monospace;">test1 = new Test1("fake");</span><span style="font-family: "trebuchet ms" , sans-serif;"> for that matter, you are basically changing your variable's (container's) content, not what its previous content was pointing at. Since the calling code still has a </span><span style="font-family: "courier new" , "courier" , monospace;">test1</span><span style="font-family: "trebuchet ms" , sans-serif;"> variable pointing to the original content, setting the copy of the </span><span style="font-family: "courier new" , "courier" , monospace;">test1</span><span style="font-family: "trebuchet ms" , sans-serif;"> variable </span><span style="font-family: "trebuchet ms" , sans-serif;">to point to null or to a different instance by </span><span style="font-family: "trebuchet ms" , sans-serif;">the </span><span style="font-family: "courier new" , "courier" , monospace;">ModifyTest1 </span><span style="font-family: "trebuchet ms" , sans-serif;">method </span><span style="font-family: "trebuchet ms" , sans-serif;">does not affect the original content.</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Running the above code would have resulted in a </span><span style="font-family: "courier new" , "courier" , monospace;">NullReferenceException </span><span style="font-family: "trebuchet ms" , sans-serif;">if the method signature happened to be </span><span style="font-family: "courier new" , "courier" , monospace;">ModifyTest1(ref Test1 test1)</span><span style="font-family: "trebuchet ms" , sans-serif;"> and the call was done as </span><span style="font-family: "courier new" , "courier" , monospace;">test2.ModifyTest1(ref test1);</span><span style="font-family: "trebuchet ms" , sans-serif;">. And that's the same way you generally pass your value type variables, as reference, at times (Remember </span><span style="font-family: "courier new" , "courier" , monospace;">int.TryParse()</span><span style="font-family: "trebuchet ms" , sans-serif;">?).</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">I sincerely wish that I have not made you completely go nuts with this explanation. This is just my understanding of how value types and reference types work when you pass them around. I wish I could include how </span><span style="font-family: "courier new" , "courier" , monospace;">string</span><span style="font-family: "trebuchet ms" , sans-serif;"> type behaves like a value type even though it's a reference type, but this post has become too long already so maybe that's for another day. Cheers!</span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-9060450555264355952020-04-22T19:10:00.000+06:002020-04-25T17:27:34.951+06:00How to sort divs based on visitor's country<br />
<div style="text-align: justify;">
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css" rel="stylesheet" type="text/css"></link>
<link href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css" rel="stylesheet" type="text/css"></link>
<script src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js" type="text/javascript">
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>
<span style="font-family: "trebuchet ms" , sans-serif;">Recently I've got an opportunity to participate in revamping our company's official website.</span></div>
<br />
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">One of the suggestions that came up there was to sort the clients' testimonies according to their relevance. And how would you know that you may ask? Well, one way to infer that is by capturing the visitor's geolocation and arranging the testimonials so the closest would show up first. Time to get to work!</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">To get the visitor's geolocation, initially, I tried the following service:</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><a href="https://www.geoplugin.com/">https://www.geoplugin.com</a> (BTW later I ended up using <a href="https://ipstack.com/" target="_blank">this </a>instead)</span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Well, that was the easy part. You just include their script and call a method to get country information.</span></div>
<br />
<pre class="code javascript" style="background-color: #f7f9fa; border: 1px dashed rgb(140, 172, 187); font-size: 12.48px; margin-bottom: 1em; overflow: auto; padding: 0.5em; text-align: justify;"><span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"><</span>html<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"><</span>head<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"><</span>script src=<span class="st0" style="color: red; margin: 0px; padding: 0px;">"http://www.geoplugin.net/javascript.gp"</span><span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></</span>script<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"></</span>head<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"><</span>body<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"><</span>script<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
alert(geoplugin_countryName<span class="br0" style="color: #66cc66; margin: 0px; padding: 0px;">(</span><span class="br0" style="color: #66cc66; margin: 0px; padding: 0px;">)</span><span class="br0" style="color: #66cc66; margin: 0px; padding: 0px;">)</span>;
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"></</span>script<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"></</span>body<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span>
<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;"></</span>html<span class="sy0" style="color: #66cc66; margin: 0px; padding: 0px;">></span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">The hard part was rather to get the testimonies sorted. Here's what I did.</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">We have clients from europe, america, middleast and australia. If someone from Norway visits our site, testemonies by Norgegian clients should show up first, then may be Swidish ones and so on.</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">So it's not just sorting by one country. You need something like </span><i style="font-family: "trebuchet ms", sans-serif;">"ORDER BY this, this too, this as well"</i><span style="font-family: "trebuchet ms" , sans-serif;"> which should work up to many degrees. I was much more interested in writing the sorting algo, overlooking the mechanism to compute the order by sequence. So the order by sequence was merely hardcoded for each potential geographic:</span></div>
<pre class="code javascript" style="background-color: #f7f9fa; border: 1px dashed rgb(140, 172, 187); font-size: 12.48px; margin-bottom: 1em; overflow: auto; padding: 0.5em; text-align: justify;">let computeSortOrder = function(countryCode) {
switch (countryCode) {
case 'NO':
return ['NO', 'SE'];
break;
case 'SE':
return ['US', 'CA'];
break;
...
default:
return [countryCode];
break;
}
}</pre>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: "trebuchet ms" , sans-serif;">Now we got ourselves an array of counties that we would like our testimonies to be recursively sorted. How would you implement that? Custom sort with recursion!</span></div>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;"><div style="font-family: "Times New Roman";">
<span style="font-family: "trebuchet ms" , sans-serif;">
</span></div>
<pre class="code javascript" style="background-color: #f7f9fa; border: 1px dashed rgb(140, 172, 187); font-size: 12.48px; margin-bottom: 1em; overflow: auto; padding: 0.5em; text-align: justify;"> 1. let sortClients = function(sortOrder, containerId) {
2. let divs = $('#' + containerId).find('.testimony');
3. let orderedDivs = divs.sort(
4. function(a, b) {
6. let index = 0;
7. return innersort();
8. function innersort() {
9. var matchA = getMatch(a);
10. var matchB = getMatch(b);
11. if (matchA && !matchB) {
12. return -1;
13. } else if (!matchA && matchB) {.
14. return 1;
15. } else if (!matchA && !matchB) {
16. index++
17. if (index < sortOrder.length) {
18. return innersort();
19. }
20. }
21. return 0;
22. }
23. function getMatch(item) {
24. return $(item).data('country') === sortOrder[index];
25. }
26. });
27. $('#' + containerId).append(orderedDivs);
30. }</pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">Let me explain. The "sortOrder" is the array of countries returned from my earlier (ugly) function. The "containerId" is the id of the div which encloses all testimonies. Each testimony div is tagged with a class called "testimony".</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<div style="font-family: "Times New Roman";">
<span style="font-family: "trebuchet ms" , sans-serif;">
</span></div>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">In line 2, we get hold of all testimony divs we are interested in sorting. From line 3, the custom sort starts.</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">Basically the sorting function takes two arguments, essentially two adjacent items in the unsorted array say a & b and returns an integer where a negative value means a < b, positive means a > b and 0 means a = b. It is repeated many times for many pairs until all the elements in the array are in sorted order. The algorithm used will depend on your browser's implementation of ECMAScript. Does anyone still remember how bubblesort works? :) Here's some <a href="http://www.pkirs.utep.edu/CIS3355/Tutorials/chapter9/tutorial9A/bubblesort.htm" target="_blank">headsup</a>.</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<div style="font-family: "Times New Roman";">
<span style="font-family: "trebuchet ms" , sans-serif;">
</span></div>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">So here, the modification to the general sort is we do the matcing recursively for everything in our sortOrder array. In line 15, when we don't find a match for the currently sorted country, we try to find a match for the next potential country in line at the sortOrder array. And it's repeated till the array is exhausted. The beauty is, it's not depending on any fixed degree of sorting. You can pass in an array of all the countries in the world and still get your divs sorted accordingly.</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<div style="font-family: "Times New Roman";">
<span style="font-family: "\f trebuchet ms" , sans-serif;">
</span></div>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">Alright, I hope you got some idea of the code now. By the way, the "data('country')" is how I tagged a testimony to a country in its div. Example below.</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;">
</span></pre>
<pre class="brush: html"></pre>
<pre class="brush: html"><span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;"><div style="font-family: "Times New Roman";">
<span style="font-family: "trebuchet ms" , sans-serif;">
</span></div>
<pre class="code javascript" style="background-color: #f7f9fa; border: 1px dashed rgb(140, 172, 187); font-size: 12.48px; margin-bottom: 1em; overflow: auto; padding: 0.5em; text-align: justify;"><div class="testimony" data-country='NO'>
bla bla bla
...
</div></pre>
</span></pre>
</span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif;"><span style="white-space: normal;">
</span></span></pre>
<pre class="brush: html" style="text-align: justify;"><span style="font-family: "trebuchet ms" , sans-serif;"><span style="white-space: normal;">That's all for now. Stay safe and don't forget to wash your hands! #covid19</span></span></pre>
<div>
<span style="font-family: "trebuchet ms" , sans-serif; white-space: normal;"><br /></span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-36314906972539761472020-03-20T14:34:00.001+06:002020-05-10T16:53:40.238+06:00COVID-19 Status - Sri Lanka<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">COVID-19 is rapidly spreading in Sri Lanka at the moment.
The Epidemiology Unit, Ministry of Health in Sri Lanka publishes a report at 10AM every day with data collected from all hospitals treating COVID-19 cases.
I thought of creating a timeline using ArcGIS map to better visualize this data. </span><br />
<span style="font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">Currently, it's hosted here: <a href="https://srilanka-covid19.netlify.com/">https://srilanka-covid19.netlify.com/</a></span>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://1.bp.blogspot.com/-a8j8zDO9ktA/XqBM_4jSZ9I/AAAAAAAAQdk/eRaowIgJSrgyd0CwXgQ1xZncpk4qqr_mQCLcBGAsYHQ/s1600/covid19.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="790" data-original-width="1600" height="316" src="https://1.bp.blogspot.com/-a8j8zDO9ktA/XqBM_4jSZ9I/AAAAAAAAQdk/eRaowIgJSrgyd0CwXgQ1xZncpk4qqr_mQCLcBGAsYHQ/s640/covid19.PNG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;"><br /></span>
<span style="font-family: "trebuchet ms" , sans-serif; font-size: large;">PS: Now it's showing the realtime counts too, thanks to the API provided by the Health Ministry.</span>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-8402889308855667542014-08-11T18:43:00.004+06:002014-08-17T20:25:28.224+06:00Google Charts: How to change axis, legend styles beyond what is provided by the API<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">If you are familiar with Google Charts, you know that you need to pass a 'Configuration Options' object when drawing a chart. Properties of that object for bar charts are found <a href="https://developers.google.com/chart/interactive/docs/gallery/barchart#Configuration_Options" target="_blank">here</a>.</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">For a recent project I worked, I needed to show the axis and legend labels as 'clickable' links hence I needed to show the cursor as a 'hand/pointer' when hovered above them. But Google Charts API only provides a limited set of styling for axis and legend labels. </span><span style="font-family: 'Trebuchet MS', sans-serif;">More precisely it only supports color, fontName, fontSize, bold, italic & underline styles.</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">But after inspecting the generated HTML DOM for the charts, I figured out a simple way to manipulate the elements properties and change the styling the way you want.</span></div>
<br />
<span style="font-family: 'Trebuchet MS', sans-serif; text-align: justify;">I prefer jQuery so here goes how the vertical axis labels were manipulated:</span>
<br />
<pre class="brush: js;"> $('text[text-anchor=end]').each(
function (index, value) {
$(value).attr('cursor', 'pointer');
...
});
</pre>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">Here's how the horizontal axis labels were manipulated:</span>
<br />
<pre class="brush: js;">
$('text[text-anchor=middle]').each(
function (index, value) {
$(value).attr('cursor', 'pointer');
...
});
</pre>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">Here's how the legend labels were manipulated:</span>
<br />
<pre class="brush: js;">
$('text[text-anchor=start]').each(
function (index, value) {
$(value).attr('cursor', 'pointer');
...
});
</pre>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">If you are a plain JavaScript guy, here you go:</span>
<br />
<pre class="brush: js;">
var labels = document.querySelectorAll('text[text-anchor=end]');
for (var i = 0; i < labels.length; i++) {
labels[i].setAttribute('cursor', 'pointer');
...
}
</pre>
<br />
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Make sure you understand that the above hacks basically set the styling to every matching element found on the page. So if you have multiple charts on the same page and you need styling done individually, you will have to check additional properties of those elements inside the loops to determine which chart they belong to.</span>
</div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">If you need further clarification on this, post it as a comment :)</span>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-21217452183802539222014-08-10T16:08:00.000+06:002014-08-17T20:29:49.768+06:00Android: Implementing a One-Way Lockable View Pager<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">While implementing a fun Android app, I came across a scenario where the ViewPager should only be swiped right-to-left. Visiting back should be restricted. Also at some points, I needed to lock the whole view pager so that it cannot be swiped at any direction.</span></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">The following code shows how I did it by extending the ViewPager class. Note that I was using the support library.</span></div>
<br />
<br />
<pre class="brush: csharp;">
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class OneWayLockableViewPager extends ViewPager {
private boolean enabled;
private float lastX;
public OneWayLockableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
boolean lockScroll;
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
lockScroll = lastX <= event.getX();
break;
default:
lockScroll = false;
lastX = event.getX();
break;
}
return lockScroll ? false : super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void lock() {
this.enabled = false;
}
public void unlock() {
this.enabled = true;
}
}
</pre>
<br />
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">It is quite easy to change it if you want to reverse the allowed direction of swiping. Just change the less than or equal sign to a greater than sign in line number 21.</span></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Also when you want to lock down the whole view pager, just call the lock() method and swiping will be disabled.</span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-27253146393401652392014-06-25T09:19:00.000+06:002014-08-17T20:29:10.840+06:00SLT Usage Meter goes Android!<span style="font-family: Trebuchet MS, sans-serif;">Get the Android App here:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><a href="https://play.google.com/store/apps/details?id=lk.elnino.sltusagemeter">https://play.google.com/store/apps/details?id=lk.elnino.sltusagemeter</a></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Finally I had time to spare on this pet project, which the idea was originally coined by one of my colleagues who writes cool Android apps. Initially I thought this wouldn't be any use to have as a mobile app but then again when I thought that it could be useful as a widget on the home screen, I got motivated to try. Simply because I have not written any widgets for Android before :)</span></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">I got to say that this ain't the only app on the play store which can check your SLT broadband usage. I've seen a couple of others which basically does the same thing. So why I wrote yet another one? Because none of them had a home screen widget or notifies you when the limit is reached.</span></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Let's have a look at the party piece.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-pf27kT5Gfc0/U6o7H-XDn-I/AAAAAAAAAfo/5DnLzOEVQtY/s1600/device-2014-06-22-103727.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-pf27kT5Gfc0/U6o7H-XDn-I/AAAAAAAAAfo/5DnLzOEVQtY/s1600/device-2014-06-22-103727.png" height="320" width="192" /></a></div>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">This widget is shown at the bottom. I just cropped the home screen. The green and yellow bars show the percentage used. When you touch the widget, the numbers change to either show the percentages, used GBs or unused GBs. No surprise there, it works just like the <a href="http://www.elnino.lk/2013/02/slt-usage-meter-chrome-extension.html" target="_blank">browser widgets</a>.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">When you touch the icon, the usage is updated. Anyhow the app updates the usage automatically in the background, but if you want you can turn off that feature.</span></div>
<br />
<br />
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;">When you reach the end of your monthly limit, you will get notified whether you had the widget or not. Then again that'll also work if the auto updates are enabled.</span></div>
<br />
<br />
<br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">The main app looks like this. Nothing to brag though.</span><br />
<br />
<a href="https://3.bp.blogspot.com/-jf3PuxRIUf4/U6o9cvjDypI/AAAAAAAAAf0/BiAhDR0D_OM/s1600/screen1.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://3.bp.blogspot.com/-jf3PuxRIUf4/U6o9cvjDypI/AAAAAAAAAf0/BiAhDR0D_OM/s1600/screen1.png" height="320" width="192" /></a><a href="http://3.bp.blogspot.com/-0ZLEHPiQiXg/U6o9gfmkZII/AAAAAAAAAgE/lFX_rNiSIp8/s1600/screen3.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-0ZLEHPiQiXg/U6o9gfmkZII/AAAAAAAAAgE/lFX_rNiSIp8/s1600/screen3.png" height="320" width="192" /></a> <a href="http://3.bp.blogspot.com/-pdVFoqLApvI/U6o9e5Dfp2I/AAAAAAAAAf8/uXhLDEfFpJw/s1600/screen2.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-pdVFoqLApvI/U6o9e5Dfp2I/AAAAAAAAAf8/uXhLDEfFpJw/s1600/screen2.png" height="320" width="192" /></a><br />
<br />
<span style="font-family: Verdana, sans-serif;">So there you have it. Try it out and let me know how it is.</span><br />
<span style="font-family: Verdana, sans-serif;">As always, it's free and not adware.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Enjoy!</span><br />
<br />
<br />
<!-- Blogger automated replacement: "https://3.bp.blogspot.com/-jf3PuxRIUf4/U6o9cvjDypI/AAAAAAAAAf0/BiAhDR0D_OM/s1600/screen1.png" with "https://3.bp.blogspot.com/-jf3PuxRIUf4/U6o9cvjDypI/AAAAAAAAAf0/BiAhDR0D_OM/s1600/screen1.png" --><!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F3.bp.blogspot.com%2F-jf3PuxRIUf4%2FU6o9cvjDypI%2FAAAAAAAAAf0%2FBiAhDR0D_OM%2Fs1600%2Fscreen1.png&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://3.bp.blogspot.com/-jf3PuxRIUf4/U6o9cvjDypI/AAAAAAAAAf0/BiAhDR0D_OM/s1600/screen1.png" -->Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-13838583164744389112014-02-03T00:38:00.003+06:002014-08-11T17:16:17.988+06:00Android: How to embed Google Map<span style="font-family: Verdana, sans-serif;">Well here I am specifically talking about getting it done with Android Studio and with Maps API v2.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">First of all you need the Google Play services downloaded using the SDK Manger.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-xSMSrd4-1wI/Uu4qZA2R-GI/AAAAAAAAAdM/a1lPiRP-xJ4/s1600/sdk+manager.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-xSMSrd4-1wI/Uu4qZA2R-GI/AAAAAAAAAdM/a1lPiRP-xJ4/s1600/sdk+manager.png" height="456" width="640" /></a></div>
<br />
<span style="font-family: Verdana, sans-serif;">Then add the Google Play services version to your app's manifest file.</span><br />
<pre class="prettyprint notranslate" style="background-color: #fafafa; border: 1px solid rgb(187, 187, 187); color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto; padding: 6px 10px; vertical-align: baseline;" translate="no"><code style="border: 0px; font-family: 'Droid Sans Mono', monospace; font-size: 1em; line-height: 1.5; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><meta-data</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:name</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"com.google.android.gms.version"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:value</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"@integer/google_play_services_version"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">/></span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span></code></pre>
<span style="font-family: Verdana, sans-serif;">Get your Google Maps API key.</span><br />
<br />
<ul>
<li><span style="font-family: Verdana, sans-serif;">Go here: <a href="https://code.google.com/apis/console/?noredirect" target="_blank">https://code.google.com/apis/console/?noredirect</a> and click 'Cloud Console' link.</span></li>
<li><span style="font-family: Verdana, sans-serif;">Register a project there and turn on your Google Maps Android App v2 Service</span></li>
<li><span style="font-family: Verdana, sans-serif;">Create a new key under APIs & auth -> Credentials</span></li>
<li><span style="font-family: Verdana, sans-serif;">Add the key information to the manifest. See below.</span></li>
</ul>
<pre class="prettyprint notranslate" style="background-color: #fafafa; border: 1px solid rgb(187, 187, 187); color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto; padding: 6px 10px; vertical-align: baseline;" translate="no"><code style="border: 0px; font-family: 'Droid Sans Mono', monospace; font-size: 1em; line-height: 1.5; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><meta-data</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:name</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"com.google.android.maps.v2.API_KEY"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:value</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"AasdJHJHKSDHfcFJLbZhndBC_fdsd1KEHk"</span><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">/></span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span></code></pre>
<div>
<code style="border: 0px; font-size: 1em; line-height: 1.5; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="tag" style="border: 0px; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="font-family: Verdana, sans-serif;">Add permissions in the manifest to access Internet.</span></span></code></div>
<pre class="prettyprint notranslate" style="background-color: #fafafa; border: 1px solid rgb(187, 187, 187); color: #007000; font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto; padding: 6px 10px; vertical-align: baseline;" translate="no"><code style="border: 0px; font-family: 'Droid Sans Mono', monospace; font-size: 1em; line-height: 1.5; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><uses-permission</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:name</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"android.permission.INTERNET"</span><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">/></span></code></pre>
<span style="font-family: Verdana, sans-serif;">Add a map fragment to your layout. Note that I have used SupportMapFragment. That comes with Android Support Repository.</span><br />
<pre class="prettyprint notranslate" style="background-color: #fafafa; border: 1px solid rgb(187, 187, 187); font-family: 'Droid Sans Mono', monospace; font-size: 13px; line-height: 1.5; margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto; padding: 6px 10px; vertical-align: baseline;" translate="no"><code style="border: 0px; font-family: 'Droid Sans Mono', monospace; font-size: 1em; line-height: 1.5; margin: 0px; padding: 0px; vertical-align: baseline;"><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><fragment</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:id</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"@+id/map"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:layout_width</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"match_parent"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="atn" style="border: 0px; color: #660066; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">android:layout_height</span><span class="pun" style="border: 0px; color: #666600; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"match_parent"</span><span class="pln" style="border: 0px; color: black; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">
class</span><span class="pln" style="border: 0px; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;"><span style="color: #666600;">=</span></span><span class="atv" style="border: 0px; color: #008800; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">"com.google.android.gms.maps.SupportMapFragment"</span><span class="tag" style="border: 0px; color: #000088; font-family: inherit; font-style: inherit; font-weight: inherit; margin: 0px; padding: 0px; vertical-align: baseline;">/></span></code></pre>
<span style="font-family: Verdana, sans-serif;">Check device compatibility. If Google Play Services are not up-to-date on the phone, this will let the user to update then and there.</span><br />
<pre class="prettyprint notranslate" style="background-color: #fafafa; border: 1px solid rgb(187, 187, 187); margin-bottom: 1.5em; margin-top: 1.5em; overflow: auto; padding: 6px 10px; vertical-align: baseline;" translate="no"><span style="font-size: x-small;"><span style="color: #000088; font-family: 'Droid Sans Mono', monospace; line-height: 19.5px;">SupportMapFragment m</span><span style="color: #000088; font-family: 'Droid Sans Mono', monospace; line-height: 19.5px;">apFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);</span>
<span style="color: #000088; font-family: Droid Sans Mono, monospace;"><span style="line-height: 19.5px;">int mapResult = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (mapResult != ConnectionResult.SUCCESS) {
GooglePlayServicesUtil.getErrorDialog(mapResult, this, 0).show();
} else {
mapFragment.getMap().animateCamera(CameraUpdateFactory.zoomIn());
}</span></span></span></pre>
<span style="font-family: Verdana, sans-serif;">That's about it. Now the map should be visible on your app. If not, p</span><span style="font-family: Verdana, sans-serif;">atiently</span><span style="font-family: Verdana, sans-serif;"> </span><span style="font-family: Verdana, sans-serif;">go through the above check-list again and see what you have missed :)</span>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-83434497282354217372014-01-06T18:44:00.003+06:002014-01-06T18:53:08.368+06:00All new SLT Usage Meter is here!<a href="http://2.bp.blogspot.com/-VDXCmqCgd5g/UsqlE0zLvsI/AAAAAAAAAco/TO7T6ZpcAek/s1600/icon48.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-VDXCmqCgd5g/UsqlE0zLvsI/AAAAAAAAAco/TO7T6ZpcAek/s1600/icon48.png" /></a><span style="font-family: Trebuchet MS, sans-serif;">The SLT has revamped their website and not surprisingly has fixed the security hole too, which enabled us to grab the usage data only by giving the user id. Now users are required to create a new profile <a href="https://www.internetvas.slt.lk/SLTVasPortal-war/register/register.jsp" target="_blank">here</a> in order to view their usage.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Sadly this made my 'SLT Usage Meter' browser add-ons obsolete. Well technically for few days, until I found some spare time to figure out the new thing. Hey SLT, we are still keeping up :)</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">I have updated add-ons for <a href="https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc" target="_blank">Chrome</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/slt-usage-meter/" target="_blank">Firefox</a> both, which now work fine with the new portal login credentials. Now you need to enter the password as well so the gadjet's wow factor is gone, but that's the way it is...</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">I changed the icon and the layout of the gadjet too. Special thanks to <a href="http://www.elnino.lk/2013/04/slt-usage-meter-firefox-add-on.html?showComment=1370011040354#c22332721733231652" target="_blank">GK</a>, who supplied me with a sample icon and encouraged me to make it more eye candy. Please feel free to comment about what you think of the new look. Thank you.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Download links:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Chrome: </span><span style="font-family: Trebuchet MS, sans-serif; font-size: x-small;"><a href="https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc" target="_blank"><b>https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc</b></a></span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Firefox: </span><a href="https://addons.mozilla.org/en-US/firefox/addon/slt-usage-meter" target="_blank"><span style="font-family: Trebuchet MS, sans-serif; font-size: x-small;"><b>https://addons.mozilla.org/en-US/firefox/addon/slt-usage-meter</b></span></a>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com11tag:blogger.com,1999:blog-408124989644546449.post-7742875139161260472013-12-29T21:46:00.000+06:002013-12-29T21:46:36.820+06:00Connecting your Android phone to your Windows WiFi HotSpot<span style="font-family: Trebuchet MS, sans-serif;">Now this actually something I thought would be a piece of cake, until the day I actually wanted to do it.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">This is how I tried:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">I went to 'Network and Sharing Center' and selected 'Set up a Connection or Network' and clicked on 'Set up a wireless ad hoc (computer-to-computer) network'.</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-gBhV95tGj50/UsA4rgTVPhI/AAAAAAAAAbw/NqTCAHMKe4Y/s1600/adhoc1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="291" src="http://1.bp.blogspot.com/-gBhV95tGj50/UsA4rgTVPhI/AAAAAAAAAbw/NqTCAHMKe4Y/s400/adhoc1.png" width="400" /></a></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">Then gave the following details.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-lQ6qYBwvnmQ/UsA5EAXmfNI/AAAAAAAAAb4/uroUalg2OLM/s1600/adhoc2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="292" src="http://2.bp.blogspot.com/-lQ6qYBwvnmQ/UsA5EAXmfNI/AAAAAAAAAb4/uroUalg2OLM/s400/adhoc2.png" width="400" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Windows said my network is ready to use but it was not showing up on my Android phone.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Googled a bit, and got the <a href="https://code.google.com/p/android/issues/detail?id=82" target="_blank">bad news</a>. Android does not support WiFi ad hoc networks! Well at least if your phone is not rooted. In my case I was trying with a Nexus running Vanilla Android. Doh!</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Again, Google to the rescue. I found out that we can use 'netsh' administrative commands to host a wireless network in the access point mode instead of the ad hoc mode.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">So on an administrative command prompt, you type:</span><br />
<span style="font-family: Courier New, Courier, monospace;">netsh wlan set hostednetwork mode=allow ssid=MyAdHocNetwork</span><br />
<span style="font-family: Courier New, Courier, monospace;">key=12345678</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-_9g-h1XTdHs/UsA9fwmKgUI/AAAAAAAAAcE/snJ0X8rOHlQ/s1600/adhoc3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="201" src="http://2.bp.blogspot.com/-_9g-h1XTdHs/UsA9fwmKgUI/AAAAAAAAAcE/snJ0X8rOHlQ/s400/adhoc3.png" width="400" /></a></div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Then you start it:</span><br />
<span style="font-family: Courier New, Courier, monospace;">netsh wlan start hostednetwork</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-fq73cD5BC3M/UsBAzVM8KgI/AAAAAAAAAcQ/d7aLVOQ6Was/s1600/adhoc4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="201" src="http://4.bp.blogspot.com/-fq73cD5BC3M/UsBAzVM8KgI/AAAAAAAAAcQ/d7aLVOQ6Was/s400/adhoc4.png" width="400" /></a></div>
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Now you will see 'MyAdHocNetwork' in your Android phone's WiFi networks list!</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">PS: Later I found out this can be done with ease using '<a href="http://virtualrouterplus.com/" target="_blank">Virtual Router Plus</a>', but it doesn't hurt to get a little grease under the nails once in a while :)</span>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-18370491700652958652013-12-29T19:49:00.000+06:002014-08-11T17:16:39.785+06:00Android Studio: How to refer an external library (.jar)<span style="font-family: Trebuchet MS, sans-serif;">I had quite a bit of trouble doing this, hence thought of blogging it.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">First you need to download the required .jar file. In my case it is '<a href="http://commons.apache.org/proper/commons-codec/download_codec.cgi" target="_blank">commons-codec-1.9.jar</a>'.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Then create a folder named 'lib' in your project folder and copy the .jar file.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">From Android Studio, right click the lib file and select 'Add as Library...'.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-CbWnAI9It-Q/UsAlfjcUIsI/AAAAAAAAAa8/HaHo-SUuz2Y/s1600/refer+ext1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-CbWnAI9It-Q/UsAlfjcUIsI/AAAAAAAAAa8/HaHo-SUuz2Y/s640/refer+ext1.png" height="640" width="441" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Select your project and confirm.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-_LcCE7csmlk/UsAl-c3gpyI/AAAAAAAAAbE/z6V7ZBlb6kI/s1600/ref+ext2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-_LcCE7csmlk/UsAl-c3gpyI/AAAAAAAAAbE/z6V7ZBlb6kI/s320/ref+ext2.png" height="165" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<span style="font-family: Trebuchet MS, sans-serif;">Open 'build.gradle' of your project and add line 'the following line </span><span style="font-family: 'Trebuchet MS', sans-serif;">under 'dependencies'</span><span style="font-family: 'Trebuchet MS', sans-serif;">:</span><br />
<span style="font-family: Courier New, Courier, monospace;">compile files('libs/commons-codec-1.9.jar')</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-40IfGIXeerc/UsAmnrYUS6I/AAAAAAAAAbM/hoK5iUFEtLw/s1600/ref+ext3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-40IfGIXeerc/UsAmnrYUS6I/AAAAAAAAAbM/hoK5iUFEtLw/s640/ref+ext3.png" height="640" width="622" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Add code to use the referenced library.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-x6Y2pebIyjE/UsAoDBaK2oI/AAAAAAAAAbc/qjzRsGddgFM/s1600/ref+ext4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-x6Y2pebIyjE/UsAoDBaK2oI/AAAAAAAAAbc/qjzRsGddgFM/s640/ref+ext4.png" height="496" width="640" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Rebuild your project.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-A693D7u597M/UsAoC79Y8KI/AAAAAAAAAbg/FskhFTd-CSg/s1600/ref+ext5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-A693D7u597M/UsAoC79Y8KI/AAAAAAAAAbg/FskhFTd-CSg/s400/ref+ext5.png" height="127" width="400" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">That's it! :)</span>Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-90651647071064615562013-12-22T18:52:00.000+06:002014-08-11T17:16:53.281+06:00Android Studio: New Project Wizard Weird Blank Error Resolution<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Recently I bought a new laptop and had to install all my software from scratch. Everything worked fine but I just couldn't get the Android Studio working. Whenever I tried to complete the New Project Wizard, it backed off throwing the following blank error message.
</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-pPd8U3hbVUc/Urbc9MlDwlI/AAAAAAAAAaY/m-EbFUKsh6c/s1600/android+error1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-pPd8U3hbVUc/Urbc9MlDwlI/AAAAAAAAAaY/m-EbFUKsh6c/s400/android+error1.jpg" height="302" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">I tried re-installing the Studio, JDK, trying various setup configurations, typical restarts and whatnot but this was not going away. Surprisingly the samples which comes with SDK seem to load fine. Therefore I tried to copy one sample project folder to my working folder and thought of changing everything to suit my new project. Kaboom! The error came back!!!</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Then only I checked whether my working folder path is to blame...</span></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-LAn6XjSVMxE/UrbeoaKMtaI/AAAAAAAAAak/U2U32EBt3RM/s1600/androiderror2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-LAn6XjSVMxE/UrbeoaKMtaI/AAAAAAAAAak/U2U32EBt3RM/s400/androiderror2.jpg" height="255" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">Zoomed...</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-NJe8joRW4Uc/Urbe5fFKfbI/AAAAAAAAAas/CDp6UZ2HYWo/s1600/androiderror3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-NJe8joRW4Uc/Urbe5fFKfbI/AAAAAAAAAas/CDp6UZ2HYWo/s400/androiderror3.jpg" height="91" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Damn it! That single quotation mark is screwing things up all this time. Shame on you Android Studio. It's almost 2014 and still you cannot sanitize user inputs? So I changed my working directory and all went fine just like the old days :) Hope this post will help someone someday who is splitting hair across this stupid error. Peace out!</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com2tag:blogger.com,1999:blog-408124989644546449.post-13960992212863164782013-09-21T22:48:00.001+06:002013-09-21T23:12:11.671+06:00How to run AutoCAD R14 in 64bit Windows 7<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">If you hate reading all the step-by-step crap about how I did it, just scroll to the bottom. The summary is there :)</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-MNJv4p-82zo/Uj3J8R4tVdI/AAAAAAAAAYU/cGEzerqAxQ0/s1600/autocad142.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="123" src="http://2.bp.blogspot.com/-MNJv4p-82zo/Uj3J8R4tVdI/AAAAAAAAAYU/cGEzerqAxQ0/s200/autocad142.jpg" width="200" /></a> <a href="http://1.bp.blogspot.com/-nuNTqsMFPhg/Uj3J8SDyvGI/AAAAAAAAAYY/_VjtRYWmodo/s1600/winx64_teaser_0.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="123" src="http://1.bp.blogspot.com/-nuNTqsMFPhg/Uj3J8SDyvGI/AAAAAAAAAYY/_VjtRYWmodo/s200/winx64_teaser_0.jpg" width="200" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">First of all a bit of history on why I actually want to do this. My father is a surveyor. While I was doing my bachelors, I wrote a program to automate block plan drawing using </span><a href="http://en.wikipedia.org/wiki/AutoLISP" style="font-family: Verdana, sans-serif;" target="_blank">AutoLISP</a><span style="font-family: Verdana, sans-serif;">. This was running on top of AutoCAD R14, and since then he was using it to do all his work. This was installed on Windows XP and was running on a desktop PC. Recently I upgraded my laptop and I wanted to give my old one to him and it was running a genuine Windows 7. Then I faced this problem on running AutoCAD R14 on 64bit Windows 7...</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Before we start, I have to confess that I actually had a copy of the files which I got from the installed directory in Windows XP. If you want to do a fresh installation, then I am not sure how you can go about running the AutoCAD setup on Windows 7. Most probably you will have to set up a virtual box running Windows XP, install AutoCAD on it and then get the installed files copied to somewhere else. (The reason being the AutoCAD R14 setup does not run on Windows XP compatibility mode)</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Ok, so let's assume you have a complete copy of AutoCAD folder from a Windows XP box. If you run the AutoCAD.exe directly in Windows 7, you get a message saying 'heidi3.dll' is not found. So first thing I did was to download it and copy it to the AutoCAD folder. You can download it <a href="http://www.4shared.com/file/odNse-5M/HEIDI3.html" target="_blank">here</a>.</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Now when you run AutoCAD, a different type of error message starts to appear. It's thrown from 'SmartHeap Library' and reveals nothing other than its <a href="http://en.wikipedia.org/wiki/Enumerated_type" target="_blank">enum</a> value :D 'MEM_BAD_POINTER'. A bit of googling revealed that it is due to the 'sh31w32.dll' which is probably out of date when dealing with a 64bit OS. So I downloaded a more recent copy and replaced which was inside the AutoCAD directory. You can get it <a href="http://www.4shared.com/file/BcbPKK_o/SH31W32.html" target="_blank">here</a>.</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">And voila! AutoCAD splash screen came up! Hold on... that was just for a second. The main interface also got loaded and greeted me with another error message. I started loving it! This time it was more specific, just like the first one. It said now it cannot find 'gdifont3.hdi'. No worries, Internet to the rescue. So I downloaded the god damn file and copied it just like before. Get it <a href="http://www.4shared.com/file/AsVVjmbi/GDIFONT3.html" target="_blank">here</a>.</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">I was expecting a series of file missing error messages, but to my surprise, AutoCAD loaded fine and seemed to work just like it was freshly installed on Windows 7! Even my lisp program was running perfectly. So there you have it. AutoCAD R14 running on 64bit Windows 7 without skipping a beat!</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Cheers!</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Ok so here's what you need to do in a nutshell:</span></div>
<div style="text-align: justify;">
</div>
<ol>
<li><span style="font-family: Verdana, sans-serif;">You need a copy of working AutoCAD R14 files from another computer.</span></li>
<li><span style="font-family: Verdana, sans-serif;">Copy the following files into that folder. (Replace whatever necessary)</span></li>
<ul>
<li><span style="font-family: Verdana, sans-serif;"><a href="http://www.4shared.com/file/odNse-5M/HEIDI3.html" target="_blank">heidi3.dll</a></span></li>
<li><span style="font-family: Verdana, sans-serif;"><a href="http://www.4shared.com/file/BcbPKK_o/SH31W32.html" target="_blank">sh31w32.dll</a></span></li>
<li><span style="font-family: Verdana, sans-serif;"><a href="http://www.4shared.com/file/AsVVjmbi/GDIFONT3.html" target="_blank">gdifont3.hdi</a></span></li>
</ul>
<li><span style="font-family: Verdana, sans-serif;">Done!</span></li>
</ol>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com2tag:blogger.com,1999:blog-408124989644546449.post-71243963453442041632013-07-07T03:38:00.002+06:002013-09-21T22:59:25.116+06:00The Android+Azure Love Story<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Once upon a time, there was this
beautiful princess named ‘Android’. ‘Azure’ was the most powerful warrior at that
time. One sunny day… Ok, let’s cut the crap and get down to business.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">If you haven’t tried out Windows
Azure yet, well then you’ve been missing out a lot. Windows Azure is amazing!
If you’ve been living under a rock for the last couple of years, Azure is
Microsoft’s flexible, open & rock solid cloud platform. And by any chance
if you haven’t heard of Android, stop reading right now and go kill yourself!<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">With the introduction of the
Mobile Services SDK for Android, Windows Azure supports developers with super
easy access to structure data storage, authenticate and push notifications
using GCM. Now you are going to learn how to get started.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 0in; mso-add-space: auto; text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Prerequisites:</span></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: 0in; mso-add-space: auto; text-align: justify;">
</div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-indent: -0.25in;">Sign up for <a href="http://www.windowsazure.com/" target="_blank">Windows Azure</a>.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-indent: -0.25in;">Install the <a href="http://developer.android.com/sdk" target="_blank">Android SDK Tools</a> with Google APIs.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif; text-indent: -0.25in;">Download <a href="https://github.com/WindowsAzure/azure-mobile-services" target="_blank">Mobile Services SDK</a> for Android.</span></li>
</ul>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Let’s build a simple ‘Contacts’
app which saves its content on the cloud. Sounds pretty lame, but we gotta
start somewhere right?<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 1:</b> Create a new mobile service in Azure.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://4.bp.blogspot.com/-B24E7NJZMaM/UdiMblSzyZI/AAAAAAAAAVg/q0CNH9FPyo4/s1600/create+service+overview.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="191" src="http://4.bp.blogspot.com/-B24E7NJZMaM/UdiMblSzyZI/AAAAAAAAAVg/q0CNH9FPyo4/s400/create+service+overview.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<span style="font-family: Trebuchet MS, sans-serif;"><b><span style="font-size: 11pt; line-height: 115%;">Step
2:</span></b><span style="font-size: 11pt; line-height: 115%;"> Go to the DATA tab and create a new table named
‘Contact’. You do not need to create the columns. They are automatically generated
when the data is inserted.</span></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><span style="font-size: 11pt; line-height: 115%;"><br /></span></span>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 3:</b> Create a new Android project.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 4: </b>Extract the .jar files in Mobile Services SDK to the
project’s lib folder.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 5:</b> Create a new class to hold the contact data.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://4.bp.blogspot.com/-fzYkOwlXZms/UdiMrwT69DI/AAAAAAAAAVo/AOLOskNz4VU/s1600/contacts+class.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="226" src="http://4.bp.blogspot.com/-fzYkOwlXZms/UdiMrwT69DI/AAAAAAAAAVo/AOLOskNz4VU/s400/contacts+class.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">The class name has to be the same
name as of the table in mobile service database. Case doesn't matter.</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<br />
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Did you notice the annotations?
They specify the mapping between the DTO fields and the back end Azure table
columns. They even work with private fields.</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 6:</b> Modify onCreate method of your main activity to insert a
random contact.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://4.bp.blogspot.com/-7WN7AFuwiKs/UdiNAs55Y_I/AAAAAAAAAVw/g_KdC2CtKpI/s1600/oncreate.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="http://4.bp.blogspot.com/-7WN7AFuwiKs/UdiNAs55Y_I/AAAAAAAAAVw/g_KdC2CtKpI/s400/oncreate.png" width="371" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Client creation takes the mobile
service URL and the application key, which can be found in the portal.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
</div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Note: `getRandomContact’ and ‘showMessage’ method implementation details are
omitted for brevity.</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 7:</b> Run the app couple of times.<o:p></o:p></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://4.bp.blogspot.com/-VvkbCF7LKUM/UdiNPeKvctI/AAAAAAAAAV4/GPG7OjePzic/s1600/droid@screen-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://4.bp.blogspot.com/-VvkbCF7LKUM/UdiNPeKvctI/AAAAAAAAAV4/GPG7OjePzic/s320/droid@screen-4.png" width="179" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><b>Step 8:</b> Browse the Contact table in Azure.</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://2.bp.blogspot.com/-BJyF92bMHA0/UdiNWSfpaWI/AAAAAAAAAWA/rWcbIxkH-Js/s1600/contacts.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="227" src="http://2.bp.blogspot.com/-BJyF92bMHA0/UdiNWSfpaWI/AAAAAAAAAWA/rWcbIxkH-Js/s400/contacts.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">So there you have it. An Android
app hookup up with an Azure backend in no time! And that’s not all; you can
perform all your CRUD operations with ease. You can even intercept requests to the
database using the ‘Script’ tab. This is particularly useful for hooking up push
notifications for the GCM clients, like illustrated below.</span><o:p></o:p></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<a href="http://1.bp.blogspot.com/-DbiWrfrfvAQ/UdiNmoMFRZI/AAAAAAAAAWI/QvkXMHegWqs/s1600/push.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="265" src="http://1.bp.blogspot.com/-DbiWrfrfvAQ/UdiNmoMFRZI/AAAAAAAAAWI/QvkXMHegWqs/s400/push.png" width="400" /></a></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">The only thing you have to do is to
enter your API key in the ‘Push’ tab. You can get your API key by registering the
app in Google APIs console.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Also you can setup authentication
for your app using Google, Facebook, Microsoft or Twitter accounts very easily.
All you gotta do is add the credentials under the ‘Identity’ tab.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">So, hopefully you figured how
easy it is to use Azure mobile services with Android. Remember that you get 10
free mobile services with your free trial, so start experimenting now. I’m sure
you are going to love it.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">Inspired by a Colombo Mobile
Developer Meetup <a href="http://www.meetup.com/Colombo-Mobile-Developer-Meetup/events/116997802/" target="_blank">session</a>.</span></div>
<div class="MsoNormal" style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">References: <a href="http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-android/" target="_blank">Get started with Mobile Services</a>.<o:p></o:p></span></div>
<div class="MsoNormal" style="text-align: justify;">
<br /></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-76019115886652273722013-04-23T17:15:00.001+06:002013-09-21T22:59:53.456+06:00SLT Usage Meter - Firefox Add-on<div style="text-align: start;">
<span style="font-family: Verdana, sans-serif; text-align: justify;">Get the firefox add-on</span><span style="text-align: justify;"> <a href="https://addons.mozilla.org/en-US/firefox/addon/slt-usage-meter" target="_blank"><span style="font-family: Verdana, sans-serif;">here</span></a></span><span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">.</span></span></div>
<div style="text-align: start;">
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;"><br /></span></span></div>
<div style="text-align: start;">
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">I ported the <a href="http://elninoisback.blogspot.com/2013/02/slt-usage-meter-chrome-extension.html">Chrome extension</a> to Firefox. Nothing new there. Just use :)</span></span></div>
<div style="text-align: start;">
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;"><br /></span></span></div>
<div style="text-align: start;">
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">Here is a screenshot:</span></span><br />
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-L137Z6H7CkU/UXZuaHWddxI/AAAAAAAAAUo/ZvFmMBImpSk/s1600/firefox03.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="275" src="http://3.bp.blogspot.com/-L137Z6H7CkU/UXZuaHWddxI/AAAAAAAAAUo/ZvFmMBImpSk/s400/firefox03.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Verdana, sans-serif; text-align: justify;">Get the firefox add-on</span><span style="text-align: justify;"> <a href="https://addons.mozilla.org/en-US/firefox/addon/slt-usage-meter" target="_blank"><span style="font-family: Verdana, sans-serif;">here</span></a></span><span style="text-align: justify;"><span style="font-family: Verdana, sans-serif;">.</span></span></div>
<div style="text-align: start;">
<span style="text-align: justify;"><span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com20tag:blogger.com,1999:blog-408124989644546449.post-29189528709301110552013-02-17T00:58:00.002+06:002013-09-21T23:02:41.196+06:00SLT Usage Meter - Chrome Extension<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Get the chrome extension <a href="https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc" target="_blank">here</a>.</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<a href="http://1.bp.blogspot.com/-rfZ2t_85MZ8/UXZdaqwynGI/AAAAAAAAAT8/PETCn_3Em9M/s1600/icon48.png" imageanchor="1" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: small; margin-bottom: 1em; margin-right: 1em; text-align: left;"><br /></a><a href="http://1.bp.blogspot.com/-rfZ2t_85MZ8/UXZdaqwynGI/AAAAAAAAAT8/PETCn_3Em9M/s1600/icon48.png" imageanchor="1" style="clear: left; float: left; font-family: Verdana, sans-serif; font-size: small; margin-bottom: 1em; margin-right: 1em; text-align: left;"><img border="0" src="http://1.bp.blogspot.com/-rfZ2t_85MZ8/UXZdaqwynGI/AAAAAAAAAT8/PETCn_3Em9M/s1600/icon48.png" /></a><span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I previously wrote a small Windows application for checking the SLT ADSL usage for one of my colleagues. (If you came looking for that, go <a href="http://elninoisback.blogspot.com/2012/08/slt-usage-meter.html" target="_blank">here</a>.) And now he has changed his laptop to a MacBook Pro and wanted to run it there. We tried installing it via <a href="http://winebottler.kronenberg.org/" target="_blank">Wine Bottler</a> using .NET v2.0, but it didn't quite work out. Although we managed to get the UI, it looked like the HTTP requests are not going through. This limitation drove me to implement a more generic version of the same which would work practically on any OS. And a <a href="http://developer.chrome.com/extensions/index.html" target="_blank">Chrome Extension</a> seemed to be the way to go...</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">To be honest I have never written one. So went through the default developer tutorials and a hell of other stack overflow posts to get things rolling. Finally managed to get it working the way I wanted. And yes it DOES work on the Mac :)</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"> Here is the link to install the chrome extension:</span></div>
<div style="text-align: justify;">
<a href="https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc" target="_blank"><span style="font-family: Verdana, sans-serif; font-size: x-small;">https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc</span></a></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Or else you can go to <a href="https://chrome.google.com/webstore/category/home?hl=en" target="_blank">Chome Extensions</a> home page and search for 'SLT Usage Meter'. Make sure you search under 'Extensions'. It will ask for your permission to access the website which you would normally check your usage. That's all your needs to do to get it working!</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Here is a screenshots of the extension at work.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-Z8D1VSFlZw4/UXZqYUyv4WI/AAAAAAAAAUM/89V-K2DSOd8/s1600/chrome02.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="250" src="http://1.bp.blogspot.com/-Z8D1VSFlZw4/UXZqYUyv4WI/AAAAAAAAAUM/89V-K2DSOd8/s400/chrome02.png" width="400" /></a></div>
<br />
<br />
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Try it out and let me know how it is. Comments are most welcome. And don't forget to rate and share it :) Thanks!</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Get the chrome extension </span><a href="https://chrome.google.com/webstore/detail/slt-usage-meter/hofjanlkemfjdabokampgoehhfifbbjc" style="font-family: Verdana, sans-serif; font-size: small;" target="_blank">here</a><span style="font-family: Verdana, sans-serif; font-size: x-small;">.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">PS: If you want the same for Firefox, its <a href="http://elninoisback.blogspot.com/2013/04/slt-usage-meter-firefox-add-on.html">here</a>.</span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com16tag:blogger.com,1999:blog-408124989644546449.post-30701308740659579882012-11-21T03:51:00.000+06:002013-09-21T23:04:48.337+06:00Etisalat Post Pay Bill Viewer<span style="background-color: white; color: #444444; font-family: Verdana, sans-serif; font-size: xx-small; line-height: 18px; text-align: justify;">Application Download Link: </span><span style="color: #444444; font-family: Verdana, sans-serif; font-size: xx-small;"><span style="line-height: 18px;"><a href="http://www.mediafire.com/?vq0zp3tdjn7746h" target="_blank">http://www.mediafire.com/?vq0zp3tdjn7746h</a></span></span><br />
<br />
<div class="post-body entry-content" id="post-body-5521835070581058808" style="background-color: white; position: relative; width: 586px;">
<div style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><b>*** <span style="color: red;">This does not work anymore</span>. Etisalat guys have fixed this security hole within 24hrs since I released this! Impressive! So kudos to them :) And cheers to anyone who got lucky and had fun while it lasted ;) ***</b></span><br />
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="color: #444444;">
<span style="font-family: Verdana, sans-serif;">Suddenly my Etisalat data package stopped working so I logged in using my other Airtel connection to check what's wrong. After bit of Googling, found <a href="https://ebill.etisalat.lk/" target="_blank">this</a> official portal which lets you view your current and previous bills. While on it, it appeared that their portal is easily vulnerable to exploit. Although you need authentication to view the bills, but once you know the bill URL and get the hang of how they are classified, getting the customer data out </span><span style="font-family: Verdana, sans-serif;">is a piece of cake!</span></div>
</div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;">After checking few bills of random users, I thought of writing a utility which can be used to check the outstanding bill amount when a customer number is given. Customer number is printed as 'Customer No' in your actual bill. You can download the application <a href="http://www.mediafire.com/?vq0zp3tdjn7746h" target="_blank">here</a>. You can use it to view your previous bills too. But the best part is you can check details of other random users. Just for the kicks, I decided to reveal their name, address, post pay plan and the actual phone number. So have fun while it lasts ;)</span></div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;">The application has a simple interface. You will have to enter your customer number and choose the month and year of the bill which you want to see. When you click 'Get Bill Details' button, it will get busy for a while and display details if available. Check out the screenshot.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-IY3Mx-ZcnFU/UK0vF7rlsoI/AAAAAAAAAS4/Yz_66V5LrLA/s1600/etisalat.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="254" src="http://4.bp.blogspot.com/-IY3Mx-ZcnFU/UK0vF7rlsoI/AAAAAAAAAS4/Yz_66V5LrLA/s320/etisalat.png" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Do try out the app and comment if you need any improvements to be added in the later versions. Also comment if there are any bugs. Enjoy!</span></div>
<div style="color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; text-align: justify;">
<span style="font-family: Verdana, sans-serif; font-size: xx-small;"><br /></span></div>
<div style="text-align: justify;">
<span style="color: #444444; font-family: Verdana, sans-serif; font-size: xx-small; line-height: 18px;">Application Download Link: </span><span style="color: #444444; font-family: Verdana, sans-serif; font-size: xx-small;"><span style="line-height: 18px;"><a href="http://www.mediafire.com/?vq0zp3tdjn7746h" target="_blank">http://www.mediafire.com/?vq0zp3tdjn7746h</a></span></span></div>
</div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com7tag:blogger.com,1999:blog-408124989644546449.post-91352655697438940312012-11-19T14:53:00.000+06:002014-08-11T17:17:54.526+06:00C#: Handling the “The remote host closed the connection” exception in WCF REST<div style="text-align: justify;">
<span style="font-family: Trebuchet MS, sans-serif;">In a recent project, I was involved in developing WCF Restful services for mobile clients. There were some services where the clients send files as multi-part POST requests. In some cases the file data parsing on the server fails due to missing form data fields or missing file data but those scenarios ended up throwing exception on the server. It was the most common communication exception 'The remote host closed the connection'.</span></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">The WCF method signature looked like this:</span><br />
<span style="color: blue; font-family: Consolas; font-size: 13px;">public bool</span><span style="background-color: white; font-family: Consolas; font-size: 13px;"> SaveImage(</span><span style="color: #2b91af; font-family: Consolas; font-size: 13px;">Stream</span><span style="background-color: white; font-family: Consolas; font-size: 13px;"> stream)</span><br />
<pre style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"></pre>
<pre style="background-color: white; text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">And inside the method, there is absolutely nothing special I am doing when parsing fails. I am returning true when parsing failed and false otherwise. But when it fails, it throws this exception for no reason.</span></pre>
<pre style="background-color: white; text-align: justify;"><span style="font-family: Trebuchet MS, sans-serif;">After much of Googling, I found that when client is no longer connected to the service this exception may occur on the server. And the solution was to check </span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;">Response</span><span class="pun" style="background-color: transparent; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; border: 0px; color: #2b91af; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; line-height: 18px; margin: 0px; padding: 0px; vertical-align: baseline;">IsClientConnected </span><span style="font-family: Trebuchet MS, sans-serif;">property and act accordingly if its false. When I checked it, to my surprise it was false even when the method itself gets called! That is only when the parsing failed. So my conclusion was that the WCF infrastructure takes care of those requests which are not legit at the very beginning of its pipeline and releases the client to free its connection pool. But I still wonder why it passes the context to the method, if it is not willing to listen for the response.</span></pre>
<pre style="background-color: white;"><span style="font-family: Trebuchet MS, sans-serif;">So to fix this I added this method to my base service class:</span></pre>
<pre style="background-color: white;"><pre style="background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"><span style="color: blue;">protected</span> <span style="color: blue;">bool</span> IsClientConnected
{
<span style="color: blue;"> get </span>{ <span style="color: blue;">return</span> <span style="color: #2b91af;">HttpContext</span>.Current.Response.IsClientConnected; }
}</pre>
<pre><pre><span style="font-family: Trebuchet MS, sans-serif;">In every method which takes in a </span><span style="color: #2b91af; font-family: Consolas; font-size: 13px;">Stream</span><span style="font-family: 'Trebuchet MS', sans-serif;">, I call this method and make sure client is still listening and return the response. So what do I return when client is not connected? Just </span><span style="color: blue; font-family: Consolas; font-size: 13px;">null. </span><span style="font-family: 'Trebuchet MS', sans-serif;">This gets rid of getting the nasty 'remote host' exception and you can save you logs from overflowing with that.</span></pre>
<pre><span style="font-family: Trebuchet MS, sans-serif;">Happy coding!</span></pre>
<pre><span style="font-family: Trebuchet MS, sans-serif;">PS: The downside of using this method is that you have to use </span><span style="color: #2b91af; font-family: Consolas; font-size: 13px;">HttpContext </span><span style="font-family: 'Trebuchet MS', sans-serif;">which forces you to use </span><span style="color: #2b91af; font-family: Consolas; font-size: 13px;">AspNetCompatibilityRequirementsMode</span><span style="font-family: Consolas; font-size: 13px;">.Required, </span><span style="font-family: Trebuchet MS, sans-serif;">in your service which will prevent you from self-hosting it. But then again I don think clients would be disconnected in this fashion unless in that case. So I guess it's fair enough :)</span></pre>
<pre style="background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 13px;"></pre>
</pre>
</pre>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0tag:blogger.com,1999:blog-408124989644546449.post-55218350705810588082012-08-07T20:28:00.000+06:002014-03-25T10:25:39.407+06:00SLT Usage Meter<div style="text-align: justify;">
<span style="color: red; font-family: Verdana, sans-serif; font-size: x-small;"><b>[This does not work now. Please refer <a href="http://www.elnino.lk/2014/01/all-new-slt-usage-meter-is-here.html">this</a> post, it has browser plugins which do the same thing.]</b></span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Application Download Link: <a href="http://www.mediafire.com/?5ndfsq7ytz92zu4">http://www.mediafire.com/?5ndfsq7ytz92zu4</a></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">One of my colleagues was checking his ADSL usage via the SLT's usage meter found on their <a href="http://sltpassu.sltnet.lk/jsp/SLT_UsageMeter.jsp" target="_blank">website</a>. But it was a lengthy process and practically not worth logging in every time just to see how much he has utilized from his quota. So he requested me to write a windows application to automate it.</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">I tried to develop it during a weekend and when I was inspecting the http traffic through <a href="http://www.fiddler2.com/" target="_blank">Fiddler</a>, I found that although the web users have to login to view their usage, the actual page which shows the usage is not checking any user session. That means if we can directly post data to the usage page, we can get the results without providing credentials. The creepiest thing is even we can check other people's usage if we know their usernames! Way to go SLT!</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><a href="http://www.mediafire.com/?5ndfsq7ytz92zu4" target="_blank">Here</a> you can download the application. It has a really simple interface. You will have to enter your username at start and it will be saved in the registry. The application runs in the system tray and when you click the icon, it will notify you of the total usage. Check out the screenshots.</span></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-1t2zIxEmqxk/UCLVIWUnN4I/AAAAAAAAARo/0JF3-ZAcx9o/s1600/main.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="http://4.bp.blogspot.com/-1t2zIxEmqxk/UCLVIWUnN4I/AAAAAAAAARo/0JF3-ZAcx9o/s1600/main.jpg" /></span></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-iWiAneNScVI/UCLVPe9BbEI/AAAAAAAAARw/DQ8EPndxwfE/s1600/task.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Verdana, sans-serif;"><img border="0" src="http://2.bp.blogspot.com/-iWiAneNScVI/UCLVPe9BbEI/AAAAAAAAARw/DQ8EPndxwfE/s1600/task.jpg" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">If you want this app to be loaded automatically when you start Windows, just copy it to your start-up folder.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Do try out the app and comment if you need any improvements to be added in the later versions. Also comment if there are any bugs. Enjoy!</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Application Download Link: </span><span style="color: #0000ee; font-family: Verdana, sans-serif; font-size: x-small;"><u><a href="http://www.mediafire.com/?5ndfsq7ytz92zu4">http://www.mediafire.com/?5ndfsq7ytz92zu4</a></u></span><br />
<span style="color: #0000ee; font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="color: #0000ee; font-family: Verdana, sans-serif; font-size: x-small;">PS: I wrote a Google Chrome Extension to do the same thing. Go <a href="http://elninoisback.blogspot.com/2013/02/slt-usage-meter-chrome-extension.html">here</a> if you do not trust running EXEs :)</span><br />
<span style="color: #0000ee; font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="color: #0000ee; font-family: Verdana, sans-serif; font-size: x-small;">PPS: I ported it to Firefox as well. Get it <a href="http://elninoisback.blogspot.com/2013/04/slt-usage-meter-firefox-add-on.html">here</a>.</span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com20tag:blogger.com,1999:blog-408124989644546449.post-67981832034823179622012-07-30T00:31:00.001+06:002013-09-21T23:03:37.498+06:00How to unlock your Huawei E173 dongle<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">I had a Huawei E173 dongle locked to Dialog and was able to unlock it successfully.</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">If that interests you, keep on reading... </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-C6QOM8e6xuY/UCQMroBbyWI/AAAAAAAAASA/cmbndrOra9M/s1600/large-huawei-e173-usb-modem.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-C6QOM8e6xuY/UCQMroBbyWI/AAAAAAAAASA/cmbndrOra9M/s1600/large-huawei-e173-usb-modem.jpg" /></a></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Download the following stuff: </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">1. <a href="http://download.myusbmodem.com/home/Huawei%20Unlocking%20Tools/Universal_MasterCode.exe">Code generator</a> </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">2. <a href="http://download.myusbmodem.com/home/Huawei%20Firmwares/E173/E173Update_11.126.85.00.209_B427.zip">New firmware installer</a> </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">3. <a href="http://www.dc-unlocker.com/uploud/uploud/uploads/Mobile_Partner_11.302.09.01.539_Voice_USSD.zip">Unbranded dashboard</a> (optional)</span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">
Steps: </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">1. Run the code generator and enter your IMEI. Note the unlock code. </span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">2. Run the new firmware installer and input the <span style="background-color: white;">unlock code when prompted. </span></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">3. <span style="background-color: white;">Optionally install unbranded dashboard software. (Dialog dashboard works with other SIMs!) </span></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="text-align: justify;">
<span style="font-family: Verdana, sans-serif;">Enjoy!!!
</span></div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com13tag:blogger.com,1999:blog-408124989644546449.post-90314912279419641442012-02-29T15:14:00.001+06:002014-08-11T17:17:39.641+06:00C#: Exploring OpenSSL.NET<span style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">I am currently involved in a project module which involves a bit of cryptography. The basic requirements are:</span><br />
<ul style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<li>Generating RSA key pair</li>
<li>Creating a CSR file</li>
<li>Generating a Checksum</li>
<li>Encrypting with private key</li>
<li>Reading a certificate file</li>
<li>Verifying a signature </li>
</ul>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
So while I was googling for hints, I came across this free library called <a _mce_href="http://openssl-net.sourceforge.net" href="http://openssl-net.sourceforge.net/" style="color: #007bff;" target="_blank" title="OpenSSL.NET">OpenSSL.NET</a> which looked promising. <span style="background-color: white;">Find the code below which I use to accomplish the above tasks.</span></div>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
</div>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<br />
This function generates an RSA key pair and returns a CryptoKey object. The length of the keys are hard-coded to be 2048.</div>
<pre class="brush: csharp"> /// <summary>
/// Generates a 2048 bit RSA key pair.
/// </summary>
/// <returns>The key container</returns>
public static CryptoKey GenerateRsaKeyPair()
{
using(var rsa = new RSA())
{
rsa.GenerateKeys(2048, 0x10021, null, null);
return new CryptoKey(rsa);
}
}
</pre>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<br />
The following function takes in a RSA key and creates a CSR file. I have used a DTO to pass in the additional details needed for the CSR generation.</div>
<pre class="brush: csharp"> /// <summary>
/// Generates a CSR file content according to the details given.
/// </summary>
/// <param name="csr">CSR details</param>
/// /// <param name="key">RSA key</param>
/// <returns>The CSR file content</returns>
public static string GenerateCsr(CsrProperties csr, CryptoKey key)
{
using (var subject = new X509Name
{
Country = csr.CountryName,
Organization = csr.OrganizationName,
OrganizationUnit = csr.OrganizationalUnitName,
SerialNumber = csr.SerialNumber,
Common = csr.CommonName
})
{
using (var req = new X509Request(0, subject, key))
{
return req.PEM;
}
}
}
</pre>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<br />
For Checksum generation, which is also knowing as generating the hash, I used the following code. The algorithm was SHA256.</div>
<pre class="brush: csharp"> /// <summary>
/// Generates checksum using SHA256 algorithm.
/// </summary>
/// <param name="payLoad">Data to be used for hashing</param>
/// <returns>The hash</returns>
public static byte[] GenerateChecksum(byte[] payLoad)
{
using (var algo = new SHA256Managed())
{
return algo.ComputeHash(payLoad);
}
}
</pre>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<br />
To do RSA encryption, I used .NET's native cryptography methods.</div>
<pre class="brush: csharp"> /// <summary>
/// Encrypts the data using RSA key.
/// </summary>
/// <param name="payLoad">Data to be encrypted</param>
/// <param name="key">RSA key</param>
/// <returns>The encrypted data</returns>
public static byte[] Encrypt(byte[] payLoad, CryptoKey key)
{
using (var rsa = key.GetRSA())
{
return rsa.PrivateEncrypt(payLoad, RSA.Padding.PKCS1);
}
}
</pre>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
<br />
Well that's about it for now. I will update this with more functions as I move on.</div>
<div style="background-color: white; font-family: 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px;">
Cheers!</div>
Ε Γ И І И Оhttp://www.blogger.com/profile/00418146150246575647noreply@blogger.com0