Archive

Tag Archives: javascript

Recently I have been working a lot on migrating android projects to use gradle building system. Seriously it is much better than the old time. I can easily use libraries on maven repositories and customize my building process. I also no long need to create a desperate project for testing. Awesome!

it’s been a while since the last post. After coming to new york, I have been very busy on my study, personal projects and (of course) playing around. studying in new york university is harsh, but not as hard as i think. I met nice people, hanged out with my beloved new friends. I even found people having great interests in technologies and software development.

I am trying to work on instamusic as long as i have time. I also shared my project of javascript injector with my friend, and hoping to expand service and functions that it can have. I am grateful to see that there are still many people using my applications and sending emails to me. thank you very much and i will try my best to make something new.

with love, a photo in central park is nice.

peace.

DSC053452

This is a very old draft stuck at the bottom of my draft list. lol

var str = "hello world";
str = str.toLowerCase().replace(/b[a-z]/g, function(letter) {
    return letter.toUpperCase();
});
alert(str); //Displays "Hello World"

Making it as a function, we can do this.

function capitalize(str) {
    return str.toLowerCase().replace(/b[a-z]/g, function(letter) {
        return letter.toUpperCase();
    });
}

Version 1.0.1 Changelog

  • Fixed music pausing bug
  • Fixed bug to open now playing with no song
  • Fixed bug such that music should stop after playing the last song
  • Fixed minor bug that now playing screen will be opened when notification is clicked
  • Fixed bug that the app crashed when back is pressed during song playing

To begin with, we need to understand that in the HTTP protocol, browser send its identity called user agent to the server to request the wanted webpage. Every browser has its only unique user agent value, and therefore we can check that value to identify the user browser. So, first we have to take a look at some examples of user agents of mobile devices.

iPhone user agent

Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3

iPod Touch user agent

Mozilla/5.0 (iPod; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A101a Safari/419.3

iPad user agent

Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10

Android user agent

Mozilla/5.0 (Linux; U; Android 1.1; en-gb; dream) AppleWebKit/525.10+ (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2
Mozilla/5.0 (Linux; U; Android 2.1; en-us; Nexus One Build/ERD62) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17

BlackBerry user agent

BlackBerry9000/4.6.0.266 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/120

After all, in programming, we gather these data to do the checking. First in JavaScript:

if (/(iPhone|iPod|iPad)/.test(navigator.userAgent)) {
    /* This is iOS */
}
if (/Android/.test(navigator.userAgent)) {
    /* This is Android */
}
if (/BlackBerry)/.test(navigator.userAgent)) {
    /* This is BlackBerry */
}
if (/(iPhone|iPod|iPad|BlackBerry|Android)/.test(navigator.userAgent)) {
    /* This is one of the mentioned mobile device browsers */
}

And this is how it works in PHP:

if (preg_match('/iPhone|iPod|iPad/', $_SERVER['HTTP_USER_AGENT'])) {
    /* This is iOS */
}
if (preg_match('/Android/', $_SERVER['HTTP_USER_AGENT'])) {
    /* This is Android */
}
if (preg_match('/BlackBerry/', $_SERVER['HTTP_USER_AGENT'])) {
    /* This is BlackBerry */
}
if (preg_match('/iPhone|iPod|iPad|BlackBerry|Android/', $_SERVER['HTTP_USER_AGENT'])) {
    /* This is one of the mentioned mobile device browsers */
}

To construct a website, from nothing to a pretty one, what is needed is not only technique, but also ideas. When I was young, I constructed my website with Microsoft Frontpage. Later, I uses Dreamwaver to handle coding, programming web functions with PHP and javascript. Now, I even start using templates such as the Grid System and libraries such as jQuery and Dojo to to facilitate the progress and enhance the functionality of my websites. Today, time is usually spent on designing but not technical issues. What I want is no more the basic functionality but a comprehensive project. When I look back the learning route in my life, I feel like I am knowledgeable. I understand there is still a sea of knowledge to explore, but so far I satisfy my progress. =]

Recently I am constructing a website for a friend doing cake shop business. I took some snapshot for it to see how the progress proceeded and how the design changed. After that, I am actually a bit surprise for the great changes throughout the progress. And it is even happened within 1 day time. To end with, the snapshots are uploaded and shared.



In my chrome extension, the javascript injector, localStorage is used as the database to store the clients’ data. However, as localStorage support only data in string, information has to be stringified and parsed whenever saving and retrieving. The database seems unable to hold anymore data. It corrupted and became incorrect data. I need to rewrite the program and use WebSQL or IndexedDb to store the information.

%d bloggers like this: