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

Advertisements
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