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

Correctly switch between 2 Column and 1 Column grid on iPhone Landscape/Portrait mode

I had been designing a website with 4 banner that each takes col-md-3 for desktop-sized screen and takes col-xs-12 on portrait mode on the iPhone.

//screenshot will be added in a short moment.

It turned out that it looks horrible on landscape mode as the banner are over-stretched. In this post, with the help of xander, we had managed to successfully put up 2 column of grid on the landscape mode. The main issue here is that on the landscape mode, the iphone will only use c0l-xs as such we have to force it to use col-sm.


@media only screen and (-webkit-min-device-pixel-ratio: 2) and (min-width: 568px) {
.col-sm-6 {
float: left;
width: 50%;
}
}
Posted in Web Development | Tagged , , , | Leave a comment