Site Update

Updates for May 2013

After a long abandonment of this blog, I decided to post a few updates on some of the changes I’m going to make over on this site.

  • I will design a new child-theme for this blog using Kickstrap, a Twitter Bootstrap framework, and will be posting a tutorial on how to integrate into WordPress (hint: it is SQLite related).
  • I will no longer post code snippets directly inside future posts. Instead, I will embed the snippets using Github Gist.
  • Since I have renamed this blog to my personal blog, I will use it as a place to practice my speech in front of camera. You can subscribe to my Youtube channel if you understand my speech and/or like my voice although I don’t think anyone would listen to my horrible speech/voice. The primary reason for me to publish these recordings here is because I want to see if my speech can be improved in the future, say 20 years from now. And while I can make these speech related posts private, I’d like to see if anyone would be interested in my voice. If anyone who wants to leave a feedback about my speech or voice, whether like or dislike, feel free to leave a comment in the corresponding post. I will open to take whatever criticism you have. Thanks.
  • Here is the first video on the channel, aka the introductory video:
  • And here is the description for the channel:
    This is the private channel for my personal diary. The purpose of this channel is to practice my speech skill as my speech is terrible. I will upload a video to this channel daily talking about the general events happened in my life during that day. Sometimes I will do some reading from the books I bought long ago if there is nothing to talk about on that day.
    Note that since both of my speech and voice are horrible, I will include the transcript on what I said in the video description.
    Please feel free to subscribe this channel if you like and understand my voice, although I’m certain that no one would listen to my voice.

That’s it for the updates of this month. Stay turned for the upcoming SQLite related post.

Site Update

Site Updates for March 2013

Today is the second day of March and here are some updates I made or will be made on the site so far:

  • Switched to child theme of twentytwelve specifically designed for the site.
  • The comment system switched from WordPress to Disqus.
  • New logo for the site.
  • Changed blog name back to personal blog from “Web and Mobile App Dev” to reflect with the logo.
  • Retain the same tagline as before since there won’t be any change on the site’s content.
  • Will integrate the code for Open Web Analytics (OWA) instead of Google Analytics to analyze the site.
  • Will arrange the navigation and sidebar items to be more modern-like.
  • Will integrate some ads from Google Adsense and Chitika to advertise products which interests you.

I will be more active on the site during this month. On the side note, I will try to install Ubuntu in a virtual machine. If successful, I will be writing more tips on the web development with Ubuntu. Besides, I have been missing some feature for gEdit since I switched to Mac and Sublime Text.

Site Updates for February 2013

It has been almost one month since my last post. As previous stated, I had been trying to separate all sites from my WordPress multisite installation one-by-one. I will write a step-by-step guide on how to convert the sites in the multisite network into single installations in another post. The following are updates for this site for this month, February 2013.

  • The loading speed for this site has been improved thanks to the transition from multisite to single-site.
  • The default background color has been changed in order for a refreshed look.
  • No more Google Analytics for this site.
  • Currently this site is plugin-less. I will add some plugins later. However, I will modify these plugins to be SQLite-compatible. Also integrate them to the child theme I will be creating for this site in order to maintain site speed.

The last update will based on my skill to decipher the original code for the plugins and the ability to modify them.

I don’t use Google Analytics on this site anymore because I think less outside connection means more site speed.

Please leave a comment below if you still experience slow site speed issue. Thanks.

Wordpress and SQLite

SQLite Proof-of-concept WP plugin (Updated)

UPDATE 1: As those who follow me on Twitter already knew, I have been struggling with the loading speed for all of my sites. The main problem I think is that I’m using WordPress multisite and installed a lot of plugins. I’m in the process of separating my sites into single installations of WordPress. Until that time, I won’t be posting new posts.

UPDATE 2: Anyway, here is the future plan for the SQLite concept plugin. I will upload the plugin to both WordPress Plugins Repo and GitHub so that others could contribute to the plugin and hopefully others will use it as a starting point for developing SQLite-based plugins.

UPDATE 3: But before that, I will rewrite the plugin using the WP Plugin Boilerplate for more cleaner code.

As promised, I have been working on this plugin for the last several days. As the name suggests, this plugin is created for developers who want to maintain the performance of WordPress for their end users by storing the data of each plugin into separate SQLite files.

You are free to use any section of the source code for this plugin without contribution. The source code should be clean enough to be readable (I tried to write a comment for each confuse-able code whenever possible). Please leave a comment if you don’t understand certain part of the code.

Here is the plugin. In the next post, I will be uploading this plugin to the official WordPress repo and discussing my experience.

Wordpress and SQLite

New Project on Experimenting SQLite in a WordPress Plugin

This is a little late, but happy new year to all. I’ve been trying to write one post per day for this blog but never got a chance. This post is the first post of 2013 so I will try to write a post every day from now on.

Anyway, lately I’ve been reading the source code of all types of WordPress plugins, and noticed that there are either no SQLite plugins for the current version of WordPress or the SQLite plugins are only compatible with older WordPress version.

According to my own experience, using SQLite in a WordPress plugin has the following benefits:

  • Separate plugin data and settings from the main MySQL database which stores WordPress core data in order to maintain the size and speed of the core database.
  • Eliminate the need for extra code which used to remove the plugin-generated records from the MySQL database, which doesn’t usually work in my opinion.
  • SQLite database file typically resides in the plugin folder. When removing the plugin, the database removed as well. No more useless data generated by the plugin left behind inside the MySQL database.

Most of the benefits above are for end users. However, for the plugin developers like us, there are a few downsides for using SQLite:

  • Since WordPress is a MySQL-based application, all of its build-in functions are specifically made for the MySQL operations. It means that we need to use either PDO (PHP Data Objects) or native SQLite functions in PHP.
  • We need to manually create the database tables for every aspects of the plugin, such as its settings and custom fields.
  • We also need to manually apply and check for the saved plugin settings.
  • SQLite doesn’t have any helpful utilities similar to phpMyAdmin. Although there is SQLiteManager, I don’t find it useful as the SQLite database file needs to be at the same directory as the manager. Imagine that we just need to change one record inside a SQLite database. We need to move the whole file to the manager folder, open the browser, navigate to the SQLiteManager admin page, find and update this one record, and then move the file back to the original folder. If We are debugging database errors, this could become very unproductive.
  • We should familiar with the command line since SQLite doesn’t have any good GUI interface as stated above.

If you have been relying on the build-in WordPress functions to develop database-dependent plugins without knowing anything about PHP and SQL languages, it’s time to learn these two languages.

In the next post, I will write a “proof of concept” plugin to show what you can do with SQLite-based WordPress plugins.

MySQL backup

Backup MySQL Databases Periodically

In this post you will learn how to use cron to schedule the backing up of MySQL databases monthly, weekly, and/or daily.

Prerequisites

Here are some requirements in order to get started:

  • Your server has a control panel for you to control the server (cPanel or others).
  • You are familiar with command line (if you want to customize the script below).

Steps

  1. Login to the control panel of your server.
  2. Locate and enter the “Cron jobs” or similar section in the control panel (use the search feature if yours has one).

    Cron jobs icon

  3. Under “Add New Cron Job”, select the interval you want to have the backup to be executed (hourly, daily, weekly, monthly, etc.) from the drop down menu in the Common Settings field.

    Common Settings drop down menu

  4. Enter the commands below in the Command field:
    [bash wraplines="1"]rm public_html/backup.sql*;mysqldump -u [username] -p’[password]‘ –all-databases > public_html/backup.sql;zip public_html/backup.sql.zip public_html/backup.sql;echo "Remember to download the <a href="http://[domain]/backup.sql.zip">database backup file</a> and copy to external drive for backup." | mail -s "$(echo -e "Backup completed\nContent-Type: text/html")" [Email][/bash]

    Be sure to replace the text along with the square brackets with your own. Here is the explanation for each command:

    1. rm public_html/backup.sql*: Remove the files backup.sql and backup.sql.zip if you backed up before. Note that if you have either of these files for different purpose, make sure you move them to different location before you add the above commands. Or you could change the backup location across the above commands.
    2. mysqldump -u [username] -p’[password]‘ –all-databases > public_html/backup.sql: Dump out all databases on your server into a file named backup.sql. Make sure to replace [username] with the username of your MySQL server, and [password] with your password.
    3. zip public_html/backup.sql.zip public_html/backup.sql: Create a zip archive from the sql file you just dumped out. It’s for easier downloading to your local machine for backup. The browser would simply output the file rather than downloading it if you tried to download the sql file directly.
    4. echo “Remember to download the <a href=’http://[domain]/backup.sql.zip’>database backup file</a> and copy to external drive for backup.” | mail -s “$(echo -e “Backup completed\nContent-Type: text/html”)” [Email]: This command is a little trickier to explain. First it outputs the message to allow you to download the zip file for backup. Then it sends this message to your email address as a HTML document with “Backup completed” subject. Make sure to replace [domain] with your domain name, and [Email] with your email address.
  5. Hit the add button.

You are done with the setup. Now it would execute the script whenever the specified time arrives. If you want to test out the script you wrote, you can edit this job to every minute so you could see its result within next minute. But don’t forget to change it back to your original time interval, or else it would use up your server resources, unless you intended to backup the databases every minute.

If you have any question about setting up the cron job, leave a comment below.

Wordpress Plugin

Some old posts restored and Other updates

I know that I haven’t post anything in a while. I have been busying with the new site lately. In fact, today is the first time I visited this blog after the last post I wrote about two weeks ago.

Anyway, I discovered that the traffic has been surprisingly increasing since this blog relaunched a while ago. All of these traffic surges are thanks to the posts I wrote two years ago or so when I was still using Linux. As you know, I already deleted these posts because of the white screen of death, which means that the visitors of these links were presented with the 404 error page.

Based on the traffic log, I restored some of the posts which are still popular today from my backup copy of the site. These posts didn’t actually stored in the WordPress files. They stored in the WordPress MySQL database. I will write about how to do a scheduled backup of the database in another post.

Here are the restored posts with no specific order:

Unfortunately, not all of the posts are recoverable. Here is one post which I couldn’t find. I can’t remember the exact content for the post. But by looking at its URL, I think it is about using jQuery to generate the breadcrumb navigation.

The URL for each of these post are maintained so that others can visit the posts from other sites without updating their links. This is achieved by changing the publishing date to the original publishing date. For example, the publishing date for the post wrote on 12/19/2010 was set to 12/19/2010 and so on.

The content for these posts are almost original. I removed the images in these posts since I don’t have them anymore. The original comments were retained for nearly all of the posts thanks to Disqus.

I will be adding more of these old posts as they appear in the traffic log.

Now onto the updates for the site. In the next several days, I will be creating the child theme for this blog based on the Twenty Twelve theme. The upcoming posts will be the daily report for the child theme features of the day.

As of right now, I’m focusing on the WordPress development, mainly the plugin. For the last several months, I have been modifying the WordPress plugins for others. Recently I started my own WordPress plugin project. It will be used to managing my modified plugins and others’ feedbacks for  my plugin modification service. If all goes well, I will publish this plugin to the WordPress plugins repo.

That’s all for this post. Be sure to leave a comment below to discuss which of my old posts do you want me to publish except for those that were already on the blog, as well as other feedbacks for this post.

header

rabbweb, A Gameplay and Web Development Vlog site

Today I’m announcing the official opening for my new site, rabbweb. It’s a vlog (video blog) site dedicated to the gameplay and web development tutorial videos. Right now I’m focusing on the iOS games. However, in the future, I will be including console games as well.

As I stated in the last post, this is the side project for me. So I will still be focusing more on the web development projects.

And I haven’t decided on how the web development tutorial videos should format on the site yet. Right now on the site, it’s just about the iOS games.

Please check out the site and tell me what do you think in the comments below. Thanks.

The Blog Relaunches and Some Updates to the Site

Sorry for taking this blog offline for the last couple of months. About six months ago, I had to delete this blog from the WordPress multisite because it experienced an “white screen of death”. At that time, I didn’t know how to deal with this issue. I thought I got hacked by someone. Thanks to my ignorance for not knowing what caused this problem, I lost all of the posts I wrote for the last two years. I suppose you already know how to solve the “white screen of death” issue in WordPress. If not, you can google “white screen of death WordPress”.

For those of you subscribed through RSS, FeedBurner feed, or email on my old blog (although I don’t remember I had an email subscription option), thanks for not unsubscribing and stick around. And for the new readers, thanks for reading the very first article on this newly relaunched blog.

Now for the updates to this site. I haven’t updated the site for a long time. One of the reasons is because I haven’t have time for maintaining the site. I know that is not an excuse. But if you look through my site, robbychen.com, basically there is only one site I’ve done so far, that’s the WCF (World Children’s Festival) site. Others are either somebody created it and maintained by me (ICAF) or I created for the final project for a college course. Neither of those sites are suitable for my upcoming portfolio site. Also, I haven’t have any web development related jobs lately. So I don’t have enough items to place into my portfolio.

Another reason is that I have been busy with promoting my web development business, mainly on Fiverr. Here is my profile page on Fiverr. The reason I choose Fiverr to be my business platform is because I don’t have to manage the price for each project ($5 for each order) and I don’t have any finance management skills. All I have to do besides communicating with potential clients is promoting my Fiverr gigs across the social networks.

By the way, notice the recording iOS gameplay gig at very bottom of the profile page? It is my side project. I will reveal more information in the coming days.

Also, I’m using Twenty Twelve as my default WordPress theme. For some reasons, I think the new default theme (it will be in the future) is better than Twenty Ten or Twenty Eleven theme. I will be using this theme as the parent theme for this blog and create a child theme to customize the site. I will post any changes to the blog as I’m going along with the theme creating process.

Thanks for reading. If you have any question, please feel free to leave a comment below.

Working with jQuery and CakePHP

Recently I’m working with CakePHP and SQLite to develop a gallery for a client. This is going to be my first CakePHP app.

While I’m working on the admin section, I wanted to allow the client to see the image once the image filename field is out of focused so that he could see if it’s the correct image.

The only JS library included with CakePHP is Prototype. Fortunately, the latest version of CakePHP (1.3.11 as of right now) allows us to include with other JS library. I included jQuery with the help of Js helper:

[php]var $helpers = array("Js"=>array("Jquery"));[/php]

The above code is included with the whatever controller(s) you want to use this helper. In my case is galleries_controller.php and images_controller.php.

Then I just need to add the following code into the corresponding views, in my case is some of the admin views (admin_edit.ctp, and admin_add.ctp):

[php]echo $this->Js->set("imageLoc", $this->Html->image("0"));

echo $this->Js->get("#GalleryCover")->event("blur", "$(‘#cover’).html(window.beta.imageLoc.substring(0, window.beta.imageLoc.length-12) + ‘images/’ + $(‘#GalleryPath’).val() + ‘/thumb/’ + $(this).val() + ‘\" />’);");

[/php]

Note that I used image object in the Html helper to generate a dummy img tag so that I could precisely get the image folder location in the webroot folder. Then I used set object in the Js helper to transfer this generated PHP value to Javascript variable “imageLoc”. The second line is self-explanatory if you know jQuery. Here is the documentation in the CakePHP Cookbook for you to review.

In the jQuery code section of the second line, I used the substring function to remove the last 12 characters in the img tag (0″ alt=”" />). And used the html function to include the generated code into the “cover” div. Every time the “GalleryCover” field is blurred out of focus, the image inside the “cover” div would change to the corresponding images.

If you need more information on how to use CakePHP generated Javascript variables, please refer to the second article in the reference section.

Do you have any other tips on how to incorporate jQuery into CakePHP? Please share them in the comment below.

Reference