JavaScript, how life has changed

June 1st, 2010

If you’ve been a web-developer/design for a while, you definitely remember this picture :

What a headache ! huh ? I remember whenever I wrote a JavaScript code or snippet, when I hit F5 to run it, I was praying all the time not to see this freaking error message again. It gave no clue what’s going wrong, where the error is, and it did everything other than helping you out to solve the problem. Oh God! How much stupid Internet Explorer was (or maybe still is). Back then it was the most commonly used web-browser that we had to made our works compatible to.

Now we can do all the stuff we want with JavaScript, getting an error message is not much a problem anymore and debugging, is kind of fun. None of are because any change in the language itself or that stupid browser (Internet Explorer).

It’s all because of the great browser “FireFox” which was flexible enough for other third-party addons to be added to and make it enormously strong and usefull for web-developers/designers. All the tools from FireBug , Web developer toolbar and all the JavaScript Consoles (including the one which comes built-in with FireBug) have made our lives much easier.

FireFox has sort of pushed the web-browsing boundaries and forced all other existing web-browsers and the ones coming in future to be standard, and developers friendly (I’m not talking about IE, which I’m pretty glad I abandoned it since version 7).

I was thinking about the way our lives as developers/designers have changed and how much more we’re enjoying our jobs with out the need to struggle with very basic and dull stuff.

P.S: No need to mention about the JavaScript Frameworks and such pain relievers they are (most of the times though).

FireBug, FireFox, General, JavaScript, Server , , , ,

Written by: MajiD Fatemian  

get DB handler in CodeIgniter for stand-alone Libraries

February 11th, 2010

We were working on a project where some developers were working with CI and were developing libraries there, and some developers were developing stand-alone libraries. But both groups were working on the same project.

At some point we needed all those stand-alone libraries to be  used in CI as well.
For common code it’s not a big deal, the only problem which took a little bit of time to figure out was using the DataBase. We didin’t want to make new DB connections, so how could we use the current connection, inside an stand-alone code.

The answer is pretty easy, CI’s DB class has a non-documented attribute which returns back the DB handler.

$this->db->conn_id

or if you have multiple DB cnnections that would be :

$this->dbr->conn_id;

$this->dbw->conn_id;

and then you can easily pass the DB connection to regular mysql_query function like this :

mysql_query ( string $query [, resource $link_identifier ] );

and as an example :

mysql_query ( ‘SELECT * FROM `table1`’, $this->dbr->conn_id );

CodeIgniter, General, MySQL , , ,

Written by: MajiD Fatemian  

CodeIgniter’s log system issue

November 18th, 2009

First of all I have to admit that I love this framework. I will write more about this fantastic framework later.

But one issue I faced this morning and I was pulling my hair was its logging system.

I was editing the module which has few Ajax calls, some part was not working properly and it was absolutely because of the SQL. We have the main SQL commands being outputed in the CI log system as well. So I SSHed to server and open the log file in vi , searched for the desired point and was trying to figure out what’s the SQL problem.

At this point I got a message from a colleague asking whether our server is down or what ?

That was so confusing, some parts of the application were working and some parts were not. All the sections which were working like a Swiss watch few seconds ago. So what was wrong!
As usual everything was working properly on localhost.
I didn’t even give it a small chance that having the log file open for reading [I'm stressing this out : JUST FOR READING] could be the problem. CI couldn’t proceed with logging in the sections where we had used it. I just quit the vi editor and Voila. Coming back to life.

This is not a proper approach for log system, if it can not write to the log file it shouldn’t prevent the whole system from working. Or may be it should ! Depends on how logging is important for your system.

CodeIgniter, General, PHP , , ,

Written by: MajiD Fatemian  

How to Work ON Your Business, Not IN it

November 18th, 2009

We get so caught up in the daily life of running a business, it’s easy to miss the forest for the trees.

Not that you have a choice! You’re fighting fires, handling a pissed-off customer, rending your face over an emergency bug-fix, the website just went down, and the accountant is coming tomorrow and the books are in shambles.

That’s the quote from this interesting article about managing your tasks and priorities as a start-up or freelancer.

And God knows how delegation is important. But I think all of us have the same feeling:

no one else can do them as well or as quickly

Management , , , ,

Written by: MajiD Fatemian  

Yahoo! Mail + FireFox + Mac ; Home , End shortcuts issue

November 16th, 2009

Yahoo Mac FireFox Home / End Issue

If you are a Firefox/Mac/Yahoo lover, you might have come across this annoying issue in Yahoo! Mail in Firefox [Mac version] that when you want to go to the home or end of a line with + Left  Arrow [command - left] or + Right Arrow [command - right] , it acts like a browser’s Back or Forward button and messes up the email you are composing or sometimes even ruins the whole thing.

You can see that everybody blames Yahoo! about not following the standard rules in their editor over the net. But this can be fixed through a very very simple FireFox add-on.
KeyConfig
is the handy tool for configuring your FireFox keyboard shortcuts. After installing if [and restarting the firefox] simply go to tools > KeyConfig and there search for “goBackKb” and “goForwardKb” and disable the ones allocated to + Left Arrow and + right Arrow.

From then on, on the newly opened windows this will be fixed and you will no longer have the same problem with those lovely combination [FireFox , Yahoo! , Mac]

FireFox, General, Mac, osx , , , ,

Written by: MajiD Fatemian  

who is “Definer” in terms of MySQL

May 21st, 2009

Today I was playing with our database settings and trying to grant/ cut permissions of users from the development DB and production DB, changing passwords and so on.
Using our primitive hosting’s control panel I wanted to remove the main production DB user from Development DB, which I ended up loosing the user completely.
I created a new user/pass and in few seconds I changed the configurations. Evertyhing looked fine till I got a phone call from  by boss and I found that something is missing and not working properly.

The problem was on one of our scripts and the error was :

The user specified as a definer : (’no_such_user’@'no_such_host’) is invalid or unregistered

And thank to our primitive control panel, I was not able to recreate the user as it contains “_” [underscore] in the username.

All the settings were fine and I was wondering what’s causing the problem. At first rush I thought that it could be a cache, as I had requested recently to have xcache on our server.

But it wasn’t the case. The error was much more stupid than even one can imagine. That specific script uses a stored procedure to insert / fetch data to/from MySQL. The user who had created the sp was the one who was deleted. And that was the problem. The term “Definer” in terms of MySQL is the one who creates the stored procedure and for the stored procedure to be executed that user must exists.

A quick solution for that was dropping the old stored procedure and re-create it while logged in to MySQL with the new user.

Voila, it solved our issue. Not the best solution but at least I figured out what “Definer” means and it must exists when a sp is being called.

MySQL, SQL, Server , ,

Written by: MajiD Fatemian  

Concurrent projects has never been easier

May 14th, 2009

The way I kept my tasks for each project organized and easy to follow up, was writing them in an Excel file. Having several different columns for different information and color-codes for different statuses.

A nice team of developers who are working with us in one of projects, intorduced us to this fantastic web-based project management tool, basecamp.

It has made my life much easier. This wonderful tool, allow you to add different projects, TODO lists, Milestones, files, white boards ,etc.
Assign each one to one of the team members and follow how is he/she progressing and what’s the status of that task from the comments.

The user-Interface is just perfectly user-friendly and easy to use. Even people in finance and marketing departments can find their way around easily. Every thing is well designed and organized. That’s one of the rare tools in this field which I can say is built by experts, not only perfect programmers. Looking at the ease of use is the best evidence of that.

The professional one is commercial and one has to subscribe to and pay the monthly charges, which is pretty inexpensive in comparision to what you get and I believe it does worth it. But it has a free “single project” version as well, which you can give it a try and see what I’m talking about.

I migrated the Excel files to basecamp and now everybody is enjoying it. I can track and follow the tasks I give out to people and organized my own ones and see what’s remaining at a glance.

project Management , ,

Written by: MajiD Fatemian  

Stress ! The good one … webserver stress benchmark

April 27th, 2009

It’s been for several years that I have not been in need of using a stress tool for testing my applications, for load-balancing and at those ages I used to use “Microsoft [ough] Web Application Stress Tool [link]“. At those ages I didn’t have any other FREE tool to stress the webserver and get the benchmarks [at least I wasn't aware of].

On the other hand we’re facing a very high traffic application which needs to be optimized byte by byte so we got a optimization guru on board and today he introduced me this fantastic Apache tool for benchmarking the load and traffic and I wanted to share it with you.

It’s “ab” [ Apache HTTP server benchmarking tool] and you can find it here. It’s a command prompt utility which works just perfect. And you can see the result of every single line that you change and how does it affect the performance.

Apache, General, Server, load-balance , , , ,

Written by: MajiD Fatemian  

WAMP server: right-click and select your version

April 27th, 2009

Have you ever been in a situation that you need to install PHP5 to have one application which is spcifically written in PHP5 and you have also some legacy applications which are written in PHP4 and are not compatible with PHP5 but you want to have them both.

I used to hate all those software bundles installing Apache/MySQL/PHP for you easily. I prefered to have them separately installed by myself to have more control over it. But considering WAMP server with an amazing feature of having many versions of Apache/MySQL/PHP and just switch from one to another by right-clicking and selecting it, is awesome.

I’ll definitely consider it for my local machine. [First need to be done with my exam on Wednesday]

Apache, General, MySQL, PHP, Server , , , , ,

Written by: MajiD Fatemian  

MySQL - group results by second/minute/hour

April 27th, 2009

This is a simple MySQL tip, but it helped me a lot.

We have a traffic table which monitors every single coming traffic to our applciation. I wanted to get the real values for how many requests I we have per Second / Minute / Hour and also what times of the the day are high traffic and what times are low traffic, to do some load-balancing on the application and server.

The query is very simple, just COUNT the number and do a GROUP BY and extract the minute/hour/…

Like :

SELECT tr_date_time,count(*) AS NUM FROM `traffic` WHERE DATE(`tr_date_time`) = ‘2009-04-25′ GROUP BY EXTRACT(HOUR_MINUTE FROM tr_date_time)

The script above extracts the number of hits per minute during the day.
Don’t forget that if you want to have the result by minutes, you have to add the hour as well to make it unique.

p.s: I hope your Date/Time/DateTime field is human friendly not Unix_timestamp, which will add some more extra calcuations on the result set.

General, PHP, SQL , ,

Written by: MajiD Fatemian