Skip to main content

Posts

Showing posts from August, 2015

Trick for PHP Server timeout

Every once in a while I'll need to run an extremely time-consuming query that compares two or more tables in a database and updates multiple tables from there. Realistically speaking, it would take way more than 30 seconds to compute. Sometimes, and there are numerous occasions that I've run into, it's not realistic to do everything on your local server (where you can extend the execution time) and you must do it on the non-accessible server where you host your site.

My trick is to load the content into a $_SESSION, loop through the that session and after every 50 to 100 iterations, refresh the page. After each iteration the current value of the session is unset to avoid duplicate values. After all values have been unset, the script will end.

Pride in your Work

I'm asked frequently how is that I'm able to receive job offers on almost a weekly basis without applying anywhere. There are a few techniques of course, such as making sure that you're well connected and that you have a steady online-and-offline presence. But I strongly believe that the main reason is the fact that I take extreme pride in pushing myself to achieve new benchmarks at work (and in life in general).

My feeling is that regardless of your feeling towards a specific employer, strive to achieve your best: it's practice for the next job. That way, your work ethic, consistency, dedication and precision will be regarded highly by your current employer, future employer and of course you.

Setting Goals

I've previously mentioned that I follow a check-list to a t each and every day regardless of the situation. My brother has even made a rather dark joke once saying that when confronted about what I was doing staring at a phone during someones hypothetical funeral, I would reply "perfect time to finish reading my articles...don't want to waste any time."
Another important tendency to develop is to achieve goals and accomplish them on time. I've generated a list of work related, as well as life-related, goals that I want to finish over the next 1 to 5 years and now that it's out in cyber-space I hold myself personally accountable to finishing them. A few goals actually begin tomorrow; others have already been in progress and a few are about to be completed.

Java: Aggregation

"Aggregation is a special form of association. It is also a relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a Has-A relationship.

For example consider two classes Student class and Address class. each student must have an address so the relationship between student and address is a Has-A relationship. But if you consider its vice versa then it would not make sense as an Address doesn’t need to have a Student necessarily."

Why we need Aggregation?
To maintain code re-usability.

Planning Your Life

What an important topic and yet it's quite underutilized. People need to escape the mindset of:

Go to schoolGet good gradesGet a degreeGet a jobWork 9-5Make and spend money Although vital, numerous studies point to the fact that more money doesn't necessarily equal happiness. At a certain point you'll buy everything that you've ever wanted but you won't know who you truly are.
I'm planning on sitting down with my wife this weekend and creating a list of what we believe defines us as individuals. What are our goals and ambitions? What makes us happy? What kind of a person is our dream person?
A quick one for me: to have a PhD in Theoretical Computer Science and to have multiple bachelor degrees in fields like Math, Physics, Biology, Philosophy, Psychology and Chemistry.

Abstract Class Example

An example from my code of an abstract class and how to extend it to a concrete class. You really don't have to understand what's going on in the code; the purpose of this code is just simply to show you how to extend and utilize an abstract class.

The Abstract Class
The Concrete Class that extends that Abstract class

Normalization

What is Normalization?

Normalization, more commonly referred to as database normalization, is the process of organizing the attributes and tables of a relational database to minimize redundancy. The first step in creating and using a relational database (like MySQL) is to establish the database's structure. Database modeling is crucial for successful long-term management of information. You'll carefully eliminate redundancies and other problems that would undermine the integrity of your database.

Normalization involves decomposing a table into less redundant (and smaller) tables but without losing information; defining foreign keys in the old table referencing the primary keys of the new ones. The objective is to isolate data so that additions, deletions, and modifications of an attribute can be made in just one table and then propagated through the rest of the database using the defined foreign keys.

A typical example of normalization is that an entity's unique ID is stor…

Abstraction vs Encapsulation

"You do abstraction when deciding what to implement. You do encapsulation when hiding something that you have implemented."

Abstraction refers to the ability to make a class abstract in OOP. An abstract class is one that cannot be instantiated. All other functionality of the class still exists, and its fields, methods, and constructors are all accessed in the same manner. You just cannot create an instance of the abstract class.

If a class is abstract and cannot be instantiated, the class does not have much use unless it is subclass. This is typically how abstract classes come about during the design phase. A parent class contains the common functionality of a collection of child classes, but the parent class itself is too abstract to be used on its own.

Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction.

Encapsulation is the technique of making the fields in a class private and providing access to the fi…

PHP Polymorphism

Polymorphism is a topic that programmers seem to be afraid of...even though it's a simple concept attached to a frightening word.

Polymorphism describes a pattern in object oriented programming in which classes have different functionality while sharing a common interface. A variable of a supertype can refer to a subtype object.

An example:
Circle and Rectangle class implement the shape interface. Shape contains the getArea() declaration. By implementing the Shape interface, Circle and Rectangle must have the getArea() method. Each method performs a different operation since retrieving the area is different when it comes to circles and rectangles.

Lets say you have a file with the function computeCost(). That method will take the getArea() and multiply it by 1.25. If you wanted to compute the cost for the circle, you would have to instantiate the Circle class, pass the radius, call the computeCost() function and pass the instantiated circle object. Within the computeCost() method,…

Abstract Classes

Just wanted to list a few key features of abstract classes that might help you grasp the concept.

So what defines an abstract class?

A class with the abstract reserved word in its header. Abstract classes are distinguished by the fact that you may not directly construct objects from them using the new operator. An abstract class may have zero or more abstract methods.
Consider using abstract classes if any of these statements apply to your situation:

You want to share code among several closely related classes.You expect that classes that extend your abstract class have many common methods or fields, or require access modifiers other than public (such as protected and private).You want to declare non-static or non-final fields. This enables you to define methods that can access and modify the state of the object to which they belong.
Benefits?

Code management and speed of modification.Cleaner code. If you have certain methods that you know will always have the same code: i.e. getFirstNam…

CMS

"A content management system (CMS) is a computer application that allows publishing, editing and modifying content, organizing, deleting as well as maintenance from a central interface. Such systems of content management provide procedures to manage workflow in a collaborative environment. These procedures can be manual steps or an automated cascade. CMSs have been available since the late 1990s.


CMSs are often used to run websites containing blogs, news, and shopping. Many corporate and marketing websites use CMSs. CMSs typically aim to avoid the need for hand coding, but may help it for specific elements or entire pages.

The function and use of content management systems is to store and organize files, and provide version-controlled access to their data. CMS features vary widely. Simple systems showcase a handful of features, while other releases, notably enterprise systems, offer more complex and powerful functions. Most CMSs include Web-based publishing, format management, re…

PHP Generate Links

The following code can be used throughout your existing PHP classes. If you use a similar URI pattern, you won't have any issues with instantly plugging the methods into your existing code. Otherwise, you may have to tweak them slightly.

To generate a link, you'll call the generateLink() method from your file and pass either NULL or an associative array with key/value pairs to add onto the URI.

i.e.
Example URI: http://example.com/index.php?page=view_by_size&type=0&id=10&xxx=something
$this->_frequent->generateLink(array("type" => "2"));

Read the comments above each method to understand what's happening:


Meteor Shower Tonight

Get ready for a spectacular meteor shower tonight. NASA will be broadcasting the entire event over their website starting at 10:00pm: https://www.youtube.com/user/ScienceAtNASA

"The Perseids have been observed for at least 2,000 years and are associated with the comet Swift-Tuttle, which orbits the sun once every 133 years. Every August, the Earth passes through a cloud of the comet’s orbital debris. This debris field -- mostly created hundreds of years ago -- consists of bits of ice and dust shed from the comet which burn up in Earth’s atmosphere to create one of the premier meteor showers of the year.

The best opportunity to see the Perseid meteor shower is during the dark, pre-dawn hours of Aug. 13. The Perseids streak across the sky from many directions, with theoretical rates as high as 100 per hour. The last time the Perseids peak coincided with a new moon was in 2007, making this one of the best potential viewings in years."

Programming: Not for the faint of heart

“If you can't explain it to a six year old, you don't understand it yourself.” -- Albert Einstein
I love and hate this particular saying. I love it for the simple fact that it's absolutely right and hate it because it's one of the most aggravating sentences ever created: let me explain.
Once you explain what you're working on, people have the tendency of assuming that they can do your job as well as you can. I can instantly see their minds working and saying, "we can just hire anyone off of the street to do his job; heck, I can even do his job! Why are we paying him again?" 
If you explain it using your field's vocabulary then they start thinking you're pretentious and that you need to step back down to Earth like every other normal person. 
So, it's a lose, lose situation.
Programming takes it to a completely new level. You have to be truly passionate about what you do. Slowly, but surely, you'll find out that your programming job involve…

Specializing

You may have recalled that I wrote about whether to specialize or broaden your knowledge.
http://dinocajic.blogspot.com/2015/08/broadening-your-overall-knowledge-or.html

Although I'm still a believer in broadening your knowledge, I think I've finally come to the conclusion to specialize 80% and broaden about 20%.

Why?
It hit me the other day when I started researching "Positive News" articles. To date, I've read (and recorded) over 6,000 articles: most are negative by nature or they simply make you want to rip your hair out (i.e. any news related to Donald Trump). However, these seem to dominate. I try to skip over them as much as I can but it takes me roughly 30 minutes every day to just figure out what I'm going to read. Seems like a waste of time and one can't help but read the titles of articles as one is browsing for articles to read.

So, I've come to terms with substituting news articles (most of them anyway) with tutorials or industry related art…

Future of Web Programming

I knew it was inevitable that PHP will one day be replaced by a more client friendly language, but didn't think it would come so soon and was quite surprised that JavaScript would leap as far as it has. I believe the MEAN framework will do just that. It was almost like you needed PHP (or another server side language) to perform database task, but now there's AngularJS that allows you to connect to the mongoDB (vs. MySQL).
Although it will take some time for JavaScript to take over, client demand will surely outpace PHP's page reload method.
"No, JavaScript won't be the only language in the programming world, especially given the surprising number of ads for Cobol programmers still being filed, but it will certainly begin to seem that way. JavaScript is inescapable on the browser, which now dominates almost everything a client computer does. Now the server side is embracing it with tools like Node.js.
JavaScript will assuredly become more dominant in other areas as…

CodeIgniter

Just a quick update. Started looking at CodeIgniter and the framework is extremely simple to use. If you have MVC experience (or are looking to get some) and a decent understanding of PHP itself, CodeIgniter might be the way to go for you.

Day 2 into it and I was ready to start building websites with it on Day 1. Read the documentation since it's surprisingly very helpful.

Browsed through their forum section and it looks like they have a decent following.

I've already made a few examples over the past few days but will start an actual site this Monday. After that, Laravel.

Benefits of PHP MVC Frameworks

I've been reluctant to switch to an MVC framework for quite some time now, but the benefits outweigh the negatives. I'm officially going to start using CodeIgniter, Laravel, Yii, CakePHP, Symphony and Zend to create (or modify existing websites) and to adhere to those standards. Each website will be written with a different framework of course.

I'll let you know how each framework does for me as I finish each site creation or transition.

Some benefits for using an MVC framework:
Code and File OrganizationWhen you setup a PHP Framework, it already has a certain folder structure. It is expected from you to follow the same standards and keep everything organized in a certain way. Once you get used to this model, you will never want to go back.Utilities and LibrariesAll top PHP frameworks come with certain Libraries and Helpers, that help you with:Form ValidationInput/Output filteringDatabase AbstractionSession and Cookie HandlingEmail, Calendar, Pagination etc…The MVC PatternT…

Stress-Free Work

The number one (#1) thing that will push me away from a job is the stress-level. I've had the tendency of creating unnecessary stress for myself in the past by attempting to improve areas that I saw were flawed; just be careful if you attempt to do the same that the owner (or your manager) doesn't micromanage everything for he or she will make your life somewhat miserable if you attempt, and succeed, at doing more than your current duties entail. 
With that said, there are also different types of stress: direct and indirect. Direct stress for me is my current salary, unrealistic deadlines and unnecessary aggravation directed towards me. Indirect stress is witnessing aggravation directed towards someone else. Although not as stressful, I do have to take a vacation from time to time to escape the indirect stress.
My current job is great in the aspect that it really doesn't produce much stress for me anymore. I've stuck with the company for 6 years now and will be there f…

Broadening your overall knowledge or specializing

I've recently run into a dilemma: whether to keep the specialized to broad learning ratio at 70% - 30% or move more towards a 100% specialized learning. It seems more likely that financially I'll attain better results if I move more towards the 100% computer programming all the time regime; I struggle with this almost daily.

I've achieved my financial dreams that I set out for myself 3 years ago; I honestly didn't think I'd achieve them this quickly. I've bought everything that I've ever wanted and live in a place that I honestly could retire in.

I guess my only real dilemma is status; whether I want it or not. Do I want to be recognized as an expert in a field or not? When I look at it this way, I know that what I'm doing is exclusively for myself and I move back towards the broad learning. The only problem is that it's difficult to keep motivated when you break your day apart into so many different tasks (i.e. I'll read 4 books at a time and it…

Vacations

It seems that every time I take a vacation I exclusively use it to catch up on work, whether work-work or home-work related. This vacation so far has been roughly the same. I have focused on tasks related in or around the house such as assembling the bookcases.

Regardless of the task, it seems that every time I do genuinely feel rested. My mind doesn't have to deal or listen to the politics and that's enough for me.

I am dedicating the remainder of this vacation to my son and spending every second with him.

If you haven't taken a vacation in a while, take one. You'll feel better.

Positive Thinking

Your belief (or lack of) doesn't have to dictate your positive thinking capabilities. It seems that once you start requesting proof of everything, going as far as refusing to answer a simple "do you believe in this" question (without some proof), your mind starts spiraling into a somewhat pessimistic outlook on life.

It came to the point that my inner-voice would break down everything that anyone said to me into simple philosophical questions: does this question violate any fallacies? Should I even answer such a question?

When you get consumed by questions like that, your mind (or at least mine) seems to slowly stray away from happiness in general.

I read an article not too long ago on a scientific study that stated how a person's brain will actually look different if they just though positively for at least 2 weeks. I decided to give it a try. I constantly listened to music, watched stand-up comedy and pushed negative and even neutral thoughts out of my head. And wo…

Behaving like Humans

It seems like the topic of whether the government (money coming out of our paycheck) should help the poor and underprivileged during the time when they need it the most, such as during the time of unemployment.

While undergoing lengthy conversations with these individuals, the one thought keeps resurfacing itself over and over again: that many Americans have lost their sense of humanism and are blindly following what they're told is destroying America.

During the conversation, I'll always pose the following question: Do you believe that every single person truly has the motivation, will power and intelligence to do what you want them to do? They'll always answer with a forceful yes.

Nothing is ever that simple. Ask yourself how are there still cannibals in the world. Why do the North Korean people still truly love their leader? How are genocides still possible?

People are bread very differently. It's up to us and our government to educate them differently and not to fl…

PHP: Error Reporting

As previously mentioned, this post deals with Error Reporting. The class itself is pretty simple. You have the main() method that creates the error page and you can also call the error() method from another class to email and store the message.

In both instances the previous and current pages are recorded for diagnosis.

If you take a look at the storeErrorMessage() method, you'll notice how the error message is constructed and stored into the $error variable. The sendErrorToWebmaster() method is then called.

In another file, instantiate the class. Where an error is likely to occur, construct the $error variable and call the error() method i.e. $this->_error_reporting_obj->error($error);