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?

Monday, August 13, 2012

Create ftp user on symbolic link folder in Ubuntu

You cannot create or give ftp access to a folder that is a symbolic link. The solution is to use the mount command with the bind:

create the folder in the destination path first

sudu mkdir /destination/path/folder_name
enter system password

give access to the folder:
sudo chmod -R 777  /destination/path/folder_name

Then, mount folder to the destination path

sudo mount --bind /path/to/original/folder  /destination/path/folder_name

How to create a symbolic link on a folder in Ubuntu

A symbolic link is done by using the link, ln, command in the terminal.

The -s flag is used to indicate a symbolic link.

At the prompt, type:

sudo ln -s /path/to/original/folder  /new/path
enter system password

the /new/path excludes the name of the destination folder because it will be created from the command.

Saturday, August 4, 2012

Has anyone ever wondered how it appears as though once a decision is made to do something that is different, breaking a habit, or just doing something to better one's self, the challenges seem to occur more frequently? That's what seems to be happening to me today. My challenges just appear to be happening more frequently.

After getting the assistance I needed, I feel equipped and ready and so I guess that this is where the challenges come in. Sometimes I feel as though I'm not getting anywhere and I honestly don't believe that that is due to me not seeing what is happening but more of a lack of understanding and patience from others. Why do I speak of a lack? Similar situations can and due occur and the response is different.

Life has a way of setting up situations in your life, to teach you things. Its always up to you to recognize, understand and act accordingly to what life throws at you. Its not going to be easy.

Don't give up no matter what, just believe in yourself and continue to do what you know is correct.
Sent from my BlackBerry® device from Digicel

No words

At times, all a person can do is write.

Not for a lack of words but as a means of expressing, releasing whats on the mind and just setting one's self free.

Thursday, January 27, 2011

How to password protect your site

this requires two files: one for the username(s) with an encrypted password and one with the path to the password file.

1. create a new file and name it ".htpasswd"
2. go to http://www.4webhelp.net/us/password.php and enter the desired username and password
3. in it put the username and password, copied from step 2
4. create another file and name it ".htaccess"
5. copy and paste:

AuthUserFile /path-to-htpassword-file/.htpasswd
AuthType Basic
AuthName "Login Details"
Require valid-user

remember to change "path-to-htpassword-file" to the path you have to your .htpasswd file
"Login Details" can be changed to whatever title you would like

save both files and put in the desired folder of choice