Wednesday, December 3, 2014

Using include include_once print number 1

If in writing your code in php and you are using the include or include_once and the number 1 is printed also, it means that you are using the echo with the include or include_once statement.

So....

if you have

echo include 'foo.php' or echo include_once 'foo.php', remove the echo so it becomes
include 'foo.php' or include_once 'foo.php'

if you are using the short_open_tags, eg:

<?= include_once 'foo.php'?> or <?= include 'foo.php'?>, remove the echo, in this case its the '=' equal sign so it becomes:

<? include_once 'foo.php'?> or <? include 'foo.php'?>

Sunday, November 30, 2014

codeigniter You did not select a file to upload.

This occurs because the field name is missing from the do_upload function.

if($this->upload->do_upload()){
            $data = array('upload_data' => $this->upload->data());
            echo "
";print_r($data);

            //$this->load->view('upload_success',$data);
        } else {
            $error = array('error' => $this->upload->display_errors());
            echo "
";print_r($error);

            //$this->load->view('file_view', $error);
        }

The above code should be:

if($this->upload->do_upload('flyer')){
            $data = array('upload_data' => $this->upload->data());
            echo "
";print_r($data);

            //$this->load->view('upload_success',$data);
        } else {
            $error = array('error' => $this->upload->display_errors());
            echo "
";print_r($error);

            //$this->load->view('file_view', $error);
        }

Add the name of the file field in the do_upload function.

Wednesday, August 13, 2014

HTML5 mobile app page transition flashes/flickers

To solve the flickering of page transitions using HTML5 in mobile developing, set the page transition to none either in the head of your index file:

$(document).bind("mobileinit", function(){
  $.extend(  $.mobile , {
   defaultPageTransition: 'none'
  }); 
}); or in your javascript file:

$(document).bind( 'pageinit', function(event){
    //set defaults
    $.mobile.defaultPageTransition = "none";
});

Tuesday, July 15, 2014

Show create table sql command

Run this command to show the create table sql command:

SHOW CREATE TABLE ;

Get size of database

You can get the size of a specific database by running this command:

SELECT table_schema "Data Base Name",
SUM( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
SUM( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
WHERE table_schema = "";

If you want to show  the size of all databases on a server, then use this command:

SELECT table_schema "Data Base Name",
SUM( data_length + index_length ) / 1024 /
1024 "Data Base Size in MB",
SUM( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;

Thursday, June 26, 2014

Calculating time left in minutes using Javascript

I was creating a mobile app and had a need to be able to show the available time that is left after the user has set the amount of time they have to do something. The code snippet below is from my class:
setEndTime: function(){
        var start_time = new Date();        
        Tracker.start_time = start_time;
        
        var end_time = new Date( start_time.getTime() + ( parseInt(Guests.available_time)*60000 ) );
        Tracker.end_time = end_time;
    },
    
    calculateAvailableTime: function(){
        var current_time = new Date();        
        var difference = current_time - Tracker.start_time;
        difference /= 1000;
        var time_passed = Math.round(difference / 60 );   
        var time_left = parseInt(Guests.available_time) - time_passed;
        Tracker.time_left = time_left;
        var time_value = ( time_left > 1 ) ? " mins" : " min";
        $("#time_left").html(time_left + time_value);
    },
This is how it works. The user sets the time which is Guests.available_time. Upon clicking the button to set the time available, I call the setEndTime function which uses the Javascript date object to capture the time. I set it globally in another class. I then calculate the end time by using the new Javascript object and adding the time available to it. I multiply by 60000 to convert it to timestamp. To get the time that is left, I used a case to capture the page name and then call the calculateAvailableTime function which takes the current time using the Javascript object and then I calculate the difference by subtracting the start time from it. I divide the difference by 1000 to remove the milliseconds then I divide by 60 to get the minutes. I then subtract it from the time that the user had set to get the time that is left.

Wednesday, June 4, 2014

Removing tables from database with a particular prefix

use the statement below to get a list of tables. you can then copy the statement and execute it. if there are alot of tables, you may have to repeat the process as often as needed. SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = 'database_name' AND table_name LIKE 'myprefix_%'; replace 'database_name' with the name of your database and 'myprefix_' with the prefix that you want to delete.

Monday, July 8, 2013

Transfer Blackberry contacts to a Samsung device

I have done my research to find out how to backup my contacts from Blackberry to be able to have access to them on an android device. There is an option on Blackberry to sync your contacts to your Gmail account, assuming you have a Gmail account. :) On your Blackberry, 1. Go to options 2. Advanced options 3. Default services 4. Contact List (SYNC) - your gmail account should be listed there. Once your Gmail account is selected, you can check your Gmail account for for all your contacts from your Blackberry. Once you are logged into your Gmail Account, go to Contacts and all your contacts from your BlackBerry will be listed there. When you get your android phone, you will have to turn on the phone and import all your contacts from Gmail. The other option is to Bluetooth all your contacts over to the android phone before you start using it.

Friday, December 28, 2012

HTML 5 vs Native Mobile App Development

Now, there is alot of debate about using HTML 5 vs coding a mobile app for a specific OS. Right off the bat, I see the positive for using HTML 5 vs having an app to code and doing it more than one time due to the development in several languages to achieve the same thing. I just learnt about Xamarin, which uses C# to do a cross-platform programming for all applications. This is good. In one of the videos, a user said that he was using a language that he loves to develop mobile apps. Why cant this be the case for all programming languages? All programmers do not love and use the same programming language. Yes, the .Net framework is wonderful and it has alot of great features, but what if I use another language? I would be forced to use a language that I do not love. I am reminded of choosing a tablet, which I have been trying to decide for about a week now. One tablet has something, another one doesnt have the same thing, what do I do? I believe its the same with the war between HTML 5 and Native. I mean, the user experience is important and so is their feedback. Does native really provide everything? Speed? A good user interface? Functionality? Isnt it possible to have all that with a HTML 5 mobile app? It may not be the same interface, but the functionality will definitely be there. I believe in not re-inventing the wheel. And if in doing that, I am able to provide the same thing that a native app can do a different way, then why not? I do not think its being lazy, I believe that it is the way that the world is going. There are alot of things to consider: 1. development time 2. cost 3. speed 4. user interface 5. functionality 6. code reuse 7. Familiarity with a language vs learning one, which brings into consideration the learning curve 8. updates to the app (how easy it is to make updates and deploy) This is my two cents, what do you think?

Music to listen to while programming

I was at work and the thought came to me to research if there were any songs that a programmer could listen to while they are coding. Yes, I know that it all depends on the person as some people would prefer to have a quite place where they are all alone to concentrate to get the work done. But for someone like me who is a musician and loves music, I have to have something to listen to. So in my search I actually found a couple of sites that had music and links to music for those who want to listen to music while they are coding? Some artists are: 1. Carbon Based Lifeforms 2. Astral Projection 3. Issak Hypnotizer 4. Solar Fields 5. Aes Dana 6. Hol Baumann 7. I Awake 8. Hybrid Leisure-land 9. Thievery Corporation 10. Ludovico Eunaudi Links: 1. http://musicforprogramming.net 2. http://blog.wolfire.com/2009/05/music-to-listen-to-while-programming-part-1/ 3. http://datassette.net/ Is there a particular type of music that one should listen to? I don't think so. Whatever works for you will help. What would I listen to? Anything rap. I find that if its upbeat, crunky, hype, it will do for me. What works for you?