Tuesday, September 20, 2011

Chaining scripts with LABjs

This article-guide on the use of LABjs may be simple or complex depending on how you approach.

Simple, if you're starting up or your scripts are located in external files and your chain of scripts are accessible from inside the <head> and are called the same from all over your scripts.

Complex, if you have otherwise and/or script blocks are inserted within or after the page. Changes can be all over.

The comment post of "Kevin Hakanson" provided the more simpler way to approach it, at least on how my projects are made : (script blocks can be anywhere you need them against putting all in one location and manipulating them there --- atomic approach may not always work). The method allows a single $LAB chain accross your pages, even if they are called separately or individually == define the instance of $LAB and use this variable in all independently called script blocks (taking his example):

  var instance = $LAB
.script("framework.js")
.script("myscript.js")
.wait(function(){ myscript.init(); });

instance.wait(function(){
framework.init();
framework.doSomething();
});

As you defined the variable as "instance", you can then call it on the other script blocks as "instance.script().wait()" chain to all script blocks.

Monday, July 25, 2011

MySQL "Push" backup strategy

A "pull" backup strategy can be achieved by a MySQL replication.

Alternatively, a "push" backup strategy can also be achieved through cron or task scheduler with the following 2-step strategy:

1. take a backup of the database

> mysqldump [options] database > backup.sql

2. send or dump the backup to the remote database

> mysql -u<user> -p<password> -h<remotehost> [options] < backup.sql

Note: the second step should have an explicit password, it should not be blank; to avoid prompt.

You can then add this to your cronjob or Task Scheduler (on Windows) to execute at a certain interval and frequency.

Friday, July 22, 2011

Duplicating MySQL table to another table

Method #1: [the better option]

  1. get the creation table information of the table to be duplicated
  2. change the table name
  3. execute the script

Method #2: this will remove the index definitions of the table though. Use:

CREATE TABLE <newtable>  SELECT * FROM <oldtable> WHERE 1 = 0;

the where clause just says you are ONLY copying the structure and not the data.

Method #3: Copy to and from another database

  1. Copy the table to another database[#2]
  2. Rename the table on the other database[#2]
  3. Copy back to the source database[#1]

 

Tuesday, July 19, 2011

Requirement Management in four notes

  • Planning good requirements: "What the heck are we building?"
  • Collaboration and buy-in: "Just approve the scope, already!"
  • Traceability and change management: "Wait, does the dev team know that changed?"
  • Quality assurance: "Hello, did anyone test this thing?"

http://bit.ly/n6cMjM

Friday, July 15, 2011

Scheduled Remote MySQL backup using PHP

There's a nice 10 ways to backup mysql database from here.

There's also the use of MySQL Administrator or MySQL Workbench if both machines are Windows-based.

However, if you have the MySQL remotely and can be on Linux; some are on Windows; on different machines; and you want to grab backup from all of them, this one can be helpful.

On my development desktop, I have PHP and MySQL installed. Though it is not necessary to have these installed, it's rather handy on a development workstation.

1. Copy, paste it to your favorite text editor and save it somewhere as backup.php (or any filename you wish, just make sure it's recognized by PHP). For the sake of this tutorial, I saved it at D:\DBbackup\

<?php
/**
* This should be run on command prompt
* @params
* host
* user
* password
* [db] defaults as {host}
* [port] defaults as 3306
*/
#host,user,password,database,port
$DATABASES = array(
array(
'user' => 'user1'
,'host' => '8.8.8.8.8'
,'password' => 'mypassword'
)
,array(
'user' => 'user2'
,'host' => 'mysql.mysql.com'
,'password' => 'anotherpassword'
,'port' => '6609'
)
,array(
'user' => 'user2'
,'host' => 'host.localdomain.net'
,'password' => 'itspassword'
,'db' => 'mydatabase'
,'port' => '3308'
)
# add as many database connection as needed using the structure above
);
if (defined('STDIN')){ # make sure it's only run on command line interface (CLI)
$start = date('H:i:s');
$date = date('Ymd');
foreach($DATABASES as $instance){
$port = (isset($instance['port']) ? $instance['port'] : '3306');
$db = (isset($instance['db']) ? $instance['db'] : $instance['user']);
exec("mysqldump "
." -h".$instance['host'] #host
." -u".$instance['user'] #user
." -p".$instance['password'] #password
." -P".$port
." --compress" #you may customize the options appropriate to your servers
." --create-options"
." --extended-insert"
." --no-create-db"
." --quote-names"
." --verbose"
." ".$db
." --result-file=".dirname(__FILE__).DIRECTORY_SEPARATOR.$date."-".$db."@".$instance['host'].".sql"
);
}
# you may add other routines here like:
# compress using 7z
exec("echo 'STARTED: ".$start." DONE: ".date('H:i:s')."' > ".$date.".txt"); #keep log
} else{
echo 'This should be run on a command line';
}
?>


2. Test it on your local
a. open a command prompt on d:\dbbackup\ directory
> d:
> cd dbbackup
b. test php [PHPpath]php --info
> C:\PHP\php.exe D:\dbbackup\backup.php
c. it will create *.sql files on d:\dbbackup\ directory for every database you want to backup

3. Add as task to automate execution
a. Open Task Scheduler
b. Add new task that starts a program.
Program to execute: C:\PHP\php.exe
Parameters (or add it to Program to execute depending on your Windows version)
: D:\dbbackup\backup.php
This will basically execute as
C:\PHP\php.exe D:\dbbackup\backup.php
Put the desired frequency and schedule to backup.

The length of time to execute the script will depend on the amount of data and speed of your connection to the server.

Wednesday, February 16, 2011

JQuery Mobile Project update

I just launched a list of modules using jQueryMobile just in time for the Alpha3 release of jQueryMobile. I had employed tabs, menu-selections, form submissions.

I just yet to know more on how to execute JS routines on the modules in any way possible. I'm hoping it would be jQuery(ish) and not native JS.

It is easy and fun doing the modules. I had not to worry about layout, design and color-selections as they are already pre-built with the package. I created a templating system to make development even faster. This allowed me to produce the mobile-counterpart of submodules on the system.

Next move is to add more functionalities and open opportunities exploiting the user-experience of the mobile. A new module fo e-commerce shop will be underway.

Wednesday, February 2, 2011

Web Development for the Mobile

A new project drops heavily on my lap the past few days: develop a system that interfaces with a mobile browser primarily to support the online education project of the college.

The college has been using Moodle (http://moodle.com) as its Learning Management System (LMS) and the closest link towards the project is Mobile Moodle (MOMO http://mobilemoodle.org/).

I read through the product and it requires me to have a mobile device with web browser and preferrably with a WiFi connection. At the back of my mind, if I am to build with a web browser, there's not much options to choose from away from what I am currently doing -- web application with PHP, MySQL and JS (jQuery preferrably).

With more searches, clicks and reading, I have come accross to:

  • Sencha (http://sencha.com) - a Mobile Javascript built from ExtJS background.
  • WebKit Open Source Project (http://webkit.org) - web browser engine.
  • FMA SDK (http://fma.sourceforge.net) - had used it to interface between mobile and other appliances.
  • PhoneGap (http://phonegap.com) - open source mobile platform that supports 6 platforms. 
  • jQTouch (http://jqtouch.com) - "A jQuery plugin for mobile web development on iPhone, iPod Touch, and other forward-thinking devices". This can use the WebKit for a preview and development.
  • dotMobi (http://mtld.mobi) - This offers training for design, development and background information about mobile development.
  • Nokia SDKs (http://forum.nokia.com) - flowing through with the dotMobi leads and just about to start dwelling into learning each one of those mentioned in its training articles and archives.

Then suddenly, I just felt the urge to go ahead and start to code. I decided to make a new module - new set of libraries, objects, structure and coding standards. But in order to do that, it's nice to get acquianted with MVC platforms for a change. I crossed with Kohana (http://kohanaphp.com) -- a PHP5 MVC framework from CodeIgniter background.

I then went through a little tutorial on how to use Kohana and it seems promising. Tried a few samples but then I stopped. Starting a new one with this platform would mean I have to forget about how I got through all the codes I've used in the same project I am working with.

After a few minutes of big sighs and a mug of coffee, my click landed on jQMobile (http://jqmobile.com) - jQuery's own(as in from the creator of jQuery) mobile platform. It is on its Alpha 2 release and sounds very promising:

  • least adjustment in coding structure
  • gets me more intimate with jQuery
  • gets me more intimate with MVC framework
  • lets me grow with it

Well, a new tool for keeping me to speed, a big step in keeping me ahead.

Wish me luck!