Return json string with proper name

In C# 7, it is now possible to have tuple return type. You would have to use a var to store the return value. However if you simply return the var as a json, the json will be slightly messed up as it will simply be shown as item1, item2, etc.

In order to make sense of what is being return, you would need to create a new var to “reformat” the naming of the item in the return. Thereafter you can serialize the object. Please refer to the follow for a sample


var obj = new {Id = thing.Id, Name = thing.Name, Age = thing.Age};

Reference: https://stackoverflow.com/questions/331976/how-do-i-serialize-a-c-sharp-anonymous-type-to-a-json-string

Posted in C#, Json | Tagged , | Leave a comment

Android Volley Sending data twice

When you use Android Volley Library to make a http post request, the default situation is that the data will be send twice.

In order to avoid this, you would need to add the line 2 of the below code to set the retry policy.


JsonObjectRequest jsonObjReq = new JsonObjectRequest(...);
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
0,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

Reference: https://stackoverflow.com/questions/27873001/android-volley-sending-data-twice

Posted in Android, Java | Tagged , , , , | Leave a comment

Free Microsoft eBook

Once again, there is a large give away of Microsoft eBooks from Eric Ligman, Microsoft Director of Sales Excellence.

The whole list of the free eBooks is available at Eric’s msdn blog.

However, as a developer, we would always love to do a batch download instead of clicking on each file for download.

Here we can simply do a wget to retrieve the entire list and wget again to download them. The entire collection stand at about 3.77GB, so make sure you have enough storage before you get started.


wget http://ligman.me/2sZVmcG
wget --content-disposition --trust-server-names -i 2sZVmcG

Posted in Uncategorized | Tagged , , , | Leave a comment

Backup of outlook data file

Doing backup of your personal files are very critical. That would include backup-ing your outlook pst/ost file. In this post, I would teach you how to automatically create a backup of the pst/ost.

A good idea would be to backup the pst file to a network drive as such NAS or external hard disk.

As you would know, it is not possible to move or copy the pst file while Microsoft Outlook is still open. Hence this tool here will only be activate when you close Microsoft Outlook. There are simply setting such as location of the pst to copy and the destination of where it should be copied too. You could also set a countdown which allow you to abort the copying if you does not want the tool to perform the backup at that moment.

My suggestion is to close Microsoft Outlook when you are going for lunch/break especially if your pst file is huge as cloning the pst file might take a while to complete.

This only works for Windows.

Posted in backup, Uncategorized | Tagged , , , , , | Leave a comment

Detecting OS and Redirect to a specify site

There will be some instance where we need to redirect user to different site based on their platform. As such the following javascript will do the job to which OS the user is on. In this case, Android, iOS, and Windows (Windows Moble) is supported. The following code snippet will be inserted to the head section of your html page.

Lastly you would need to have window.onload = getMobileOperatingSystem to trigger the javascript after the page finished loading.


<script type="text/javascript">
 function getMobileOperatingSystem() {
 var userAgent = navigator.userAgent || navigator.vendor || window.opera;

// Windows Phone must come first because its UA also contains "Android"
 if (/windows/i.test(userAgent)) {
 window.location = "https://www.microsoft.com/store/apps/9nblggh4trj3";
 //return "Windows Phone"; &amp;amp;nbsp;//you may choose to return value instead
 }

if (/android/i.test(userAgent)) {
 window.location = "http://codeinstincts.xyz/apk/TVDrama.apk";
 }

// iOS detection from: http://stackoverflow.com/a/9039885/177710
 if (/iPad|iPhone|iPod/.test(userAgent) &amp;amp;amp;&amp;amp;amp; !window.MSStream) {
 return "iOS";
 }

return "unknown";
}
window.onload = getMobileOperatingSystem;
</script>

Posted in Web Development | Tagged , , , , , , , | Leave a comment

Flask: Hello World

It works on raspberry pi too!

techtutorialsx

The objective of this post is to explain how to create a simple “Hello world” application with Python and Flask.

View original post 985 more words

Posted in Uncategorized | 2 Comments

Backup Digital Ocean VPS to image

While Digital Ocean does provide backup service, it would also be advisable that we have a local backup of our VPS.

You could do the following

$ ssh user@remote "dd if=/dev/vda1 | gzip -1 -" | dd of="/pwd/image.gz"

It might take a while to load the entire depending on how huge your droplet is and there won’t be feedback from the terminal while it is in progress.

Reference: http://unix.stackexchange.com/questions/132797/how-to-dd-a-remote-disk-using-ssh-on-local-machine-and-save-to-a-local-disk

Posted in Digital Ocean, Uncategorized | Tagged , , , , | Leave a comment

Deploying WAR file to Tomcat

In this post, I will continue to go thru the steps required to deploy a WAR file to the raspberry pi. And yes, it will works for other linux based system.

To deploy the WAR file, simply copy the WAR file to /opt/tomcat9/webapps/ folder and restart the tomcat server. The extraction and deployment of the WAR file will start automatically.

For example if your WAR file is named as jack.war, you could simply browse to http://localhost:8080/jack on your browsers to check that it is working.

Next if you want to change the default port in which Tomcat listen to, you would have to head over to /opt/tomcat9/conf/server.xml, below is the default


<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

Personally I had changed it to port 80 as can be seen below.


<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

Reference used
http://www.mkyong.com/tomcat/how-to-install-apache-tomcat-8-on-debian/

Posted in apache tomcat, Raspberry Pi | Tagged , , , , | Leave a comment

Backup a img of Raspbian for Raspberry Pi

We cannot deny that it is important to always backup your data. It is even much more important to backup your entire Raspberry Pi SD card after going thru so much to setting up all the configuration which you never want to go thru again.

Therefore you should create a img of the SD card by doing the below on either a Linux or Mac machine


sudo dd bs=1M if=/dev/sdb of=raspbian.img

To restore from the img, simply do the below


sudo dd bs=1M if=raspbian.img of=/dev/sdb

While the Raspberry Pi Foundation recommend us to use bs=4M, it does not seem to work for me and hence I had decided to go with bs=1M even though it might be a lot slower but it works.

Just to note, if you are running Raspbian Jessie on Raspberry Pi 2, using the exact same SD card or img on a Raspberry Pi 3 is perfectly fine. There is no need for further configuration and it works out of the box. The only thing is that you might want to do a “sudo apt-get update” to fetch some of the specific updates for Raspberry Pi 3 hardware.

Posted in Raspberry Pi | Tagged , , , , , , | Leave a comment

Tomcat: redirecting traffic from port 8080 to 80 using iptables

Glass Onion Blog

First verify that Tomcat is running on port 8080. Run the following command

# netstat -ntl

The output will look something like

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 ::ffff:127.0.0.1:8005       :::*                        LISTEN
tcp        0      0 :::8009                     :::*                        LISTEN
tcp        0      0 :::8080                     :::*                        LISTEN
tcp        0      0 :::22                       :::*                        LISTEN

Run the following command to redirect port 80 traffic to port 8080

# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Run the folloing command to verify that redirect is working fine

# iptables -t nat -L

The output will look something like

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
REDIRECT   tcp  --  anywhere             anywhere            tcp dpt:http redir ports 8080 Chain OUTPUT (policy ACCEPT) target     prot opt source               destination Chain POSTROUTING (policy…

View original post 28 more words

Posted in Uncategorized | Leave a comment