As a programmer it's impossible to remember everything you learn. I saw this as being bad but today I see it as being good. Programs, languages, technology change and involve, and if you're not consistently learning you're being left behind and if you're remembering everything you are also being left behind.
Recently PHP had a new update with new syntax and deprecated old ones. Just like your memory, in with the new out with the old. Why hold on to all that useless code or memory? This is why I don't believe in computer science degrees. What you learned 5 years ago may not be relevant today. I would rather hire someone who consistently learns everyday for the past 2 years compared to someone who has a computer science degree 10 years ago.
Program everyday like you eat everyday, have your daily dose of it. Don't try to learn everything. At 9, when I started using a computer I didn't try to learn everything about it. I learned what I needed and that was how to play games. Today I'm not going to try to learn every language like its the end of the world but learn what is needed and it will lead to huge gains in the future without me noticing.
Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts
Monday, March 19, 2012
Wednesday, February 29, 2012
Programming Languages Comparison
Programming languages are alike. If you know how to program in one language changes are you know how to program in other languages. However the only difference is the syntax. I always wanted a chart that showed this and I finally found it hyperpolyglot.org.
Labels:
C++,
Javascript,
jQuery,
PHP,
programming,
Python
Tuesday, January 24, 2012
Learn how to program thru examples
Learning how the program is like riding a bike. You cannot fully learn it without applying it. After learning various languages I noticed that not everything the languages contains is useful, at least for me at this time. I found this by building my own useful programs or dissecting one. I need examples!
I have found no use for interfaces, I have study it but i have yet to see it in a necessary program. You can learn all kinds of theories but if you dont apply it to real life situations, its a waste just like formal education, half of the crap you learn in school you never use. They teach you things that you "might" use giving you a general knowledge.
I have found no use for interfaces, I have study it but i have yet to see it in a necessary program. You can learn all kinds of theories but if you dont apply it to real life situations, its a waste just like formal education, half of the crap you learn in school you never use. They teach you things that you "might" use giving you a general knowledge.
Saturday, January 21, 2012
Learn other programming languages
The first programming language I started learning was PHP then came javascript, python and c++. What I'm amazed is how much better understanding about a language when you study other ones. In reality programming languages are the same the only difference is syntax and couple different features here and there.
You'll enjoy learning a new language while refreshing general programming skills such as functions, loops, class, switch, if statements as so on. The other benefit is a common technique used in c++ might not be common in other languages. And now you have learned it and you can implement it into your language of choice.
OOP is quite new in PHP compared to c++. The reason PHP added this feature was because OOP made c++ very powerful and easy to maintain, and why not have the same for PHP.
You'll enjoy learning a new language while refreshing general programming skills such as functions, loops, class, switch, if statements as so on. The other benefit is a common technique used in c++ might not be common in other languages. And now you have learned it and you can implement it into your language of choice.
OOP is quite new in PHP compared to c++. The reason PHP added this feature was because OOP made c++ very powerful and easy to maintain, and why not have the same for PHP.
Monday, November 21, 2011
Keep it Sensitive, Case Sensitive!
They're case sensitive operating systems and programming languages, and others that are not. Now do you give in to the medium rules or do you stay congruent no matter what or where you are developing?
This is an easy question. Of course you stay congruent across mediums but the challenge is discipline. Because not being congruent today may not effect you now but it will in the future, like it happened to me.
Recently I transferred my websites from my windows to Linux server. I could not get the sites to work on Linux. After hours of debugging I found that the error lied in the case of the string. Not only did it effect my variables but also the URL. I looked around for a way to change this feature but realize that its a good thing to have. I was practicing a bad habit and needed to brake it now.
Now when you have that thought "Is this case sensitive." You'll know what to tell yourself. Keep it Sensitive.
Ways to be congruent:
Defining your variables, folders, files and so on in a standard naming convention. Camel back (camelBack) your variables and capitalize your classes.
Notes:
Case Sensitive => Linux, Unix, Javascript
Case Insensitive => PHP, Windows
This is an easy question. Of course you stay congruent across mediums but the challenge is discipline. Because not being congruent today may not effect you now but it will in the future, like it happened to me.
Recently I transferred my websites from my windows to Linux server. I could not get the sites to work on Linux. After hours of debugging I found that the error lied in the case of the string. Not only did it effect my variables but also the URL. I looked around for a way to change this feature but realize that its a good thing to have. I was practicing a bad habit and needed to brake it now.
Now when you have that thought "Is this case sensitive." You'll know what to tell yourself. Keep it Sensitive.
Ways to be congruent:
Defining your variables, folders, files and so on in a standard naming convention. Camel back (camelBack) your variables and capitalize your classes.
Notes:
Case Sensitive => Linux, Unix, Javascript
Case Insensitive => PHP, Windows
Wednesday, November 16, 2011
Mind Cloaking
In my writing I have noticed that I can prof read and re-read and will not find any errors but if I change the background of what I'm reading on, the error becomes evident.
It's like your mind is auto completing, tricking, cloaking the errors.
There may be a name for this occurrence. It seems similar to those images with a black dot in the middle where if you stare at it long enough a secret image will show or when two colors are next to each other they look like the complete opposite but when apart they're only different shades of the same color.
This also happens in programming. You may be looking at a bug right in the face but you cannot find it unless you take a break or change the environment.
It's like your mind is auto completing, tricking, cloaking the errors.
There may be a name for this occurrence. It seems similar to those images with a black dot in the middle where if you stare at it long enough a secret image will show or when two colors are next to each other they look like the complete opposite but when apart they're only different shades of the same color.
This also happens in programming. You may be looking at a bug right in the face but you cannot find it unless you take a break or change the environment.
Friday, October 21, 2011
Internet is like a Candy Store, Open Source is its Candy
The internet is like a candy store and the candy is free. They're many free stuff online but what makes me excited is the open source, this is high quality free. It may be hard for someone who doesn't program to understand what I'm talking about. I feel spoiled when I run across an open source software. Seriously, these are unequivocally amazing. From programing languages such as PHP, Python and javascript, to libraries like jQuery and jqPlot to applications such as piwik, to software like blender, to frameworks like CodeIgniter, to operating systems like Ubuntu linux, mail transfer agent like Postfix and the list goes on. There's so many its hard to use them all. Here is a list of high quality open source projects per category.
Wednesday, October 19, 2011
Web Charts - PHP and Javascript
pChart.net and jqPlot.com are two different libraries that allow you as a web developer create beautiful charts and graphs.
jqPlot is a javascript library that uses jQuery. jqPlot is great because it can pull data directly from multiple mediums such as csv, txt, json and so on. However it sucks because different charts may need different plugin files and you need to make sure the right script is included, but its still simple.
pChart is a PHP libray that uses its GD library. You may need to configure your php depending if this library is installed or not. pChart is a object oriented class that creates an image of a chart on the webpage. The webpage becomes an image which will not let you output any html. The only way you can link to the chart is by using <img> or <iframe> tag. Whats great is that you can create an image that can be save but what sucks is that you may not be able to use AJAX and it takes a huge load on your CPU.
jqPlot is a javascript library that uses jQuery. jqPlot is great because it can pull data directly from multiple mediums such as csv, txt, json and so on. However it sucks because different charts may need different plugin files and you need to make sure the right script is included, but its still simple.
pChart is a PHP libray that uses its GD library. You may need to configure your php depending if this library is installed or not. pChart is a object oriented class that creates an image of a chart on the webpage. The webpage becomes an image which will not let you output any html. The only way you can link to the chart is by using <img> or <iframe> tag. Whats great is that you can create an image that can be save but what sucks is that you may not be able to use AJAX and it takes a huge load on your CPU.
Friday, October 14, 2011
Example: JSON
WARNING!! Do not test it in Chrome it will not work. Only live.
JSON: is used for data storage and can be an alternative to XML.
HTML:
JSON (info.js) - everything must have double quotes except numbers. You cannot comment in JSON. It has to look like the example below and it has to be in object/brackets {}
JSON: is used for data storage and can be an alternative to XML.
HTML:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
window.onerror = function(a,b,c){alert(a+b+c);} //if error alert
$(document).ready(function(){
//Short hand
$('button').click(function(){
$.getJSON("info.js", function(json) {
alert(json.name[1].first)
});
//Long
$.ajax({
async: false,
url: 'info.js',
dataType:'json',
success: function(json) {
ret = json.name[1].first;
}
});
});
});
</script>
<p>hello</p>
<button>Click Me</button>
JSON (info.js) - everything must have double quotes except numbers. You cannot comment in JSON. It has to look like the example below and it has to be in object/brackets {}
{
"name" : [{"first" : "Britney", "last":"Spears"},
{"first" : "Angelina", "last":"Jolie"}],
"age" : 25
}
Friday, October 7, 2011
Javascript Object Inheritance - Extend and Multiple
These two javascript functions does the inheritance
Below test the object to see if it worked
Another example of javascript inheritance using constructors
//inheritance
function extendCopy(obj){
var n = {};
for(var i in obj){
n[i] = obj[i];
}
n.uber = obj;
return n;
}
//multiple inheritance
function multi(){
var n={}, stuff, j=0, len = arguments.length;
for(j=0;j<len;j++){
stuff = arguments[j];
for(var i in stuff){
n[i] = stuff[i];
}
}
return n;
}
Below test the object to see if it worked
//Setting objections
var first_obj = {name:'first', doSomething: function(){alert(2+2);}}
var second_obj = {date:'today', location: 'USA'}
var third_obj = {felling:'happiness', status: 'fun'}
http://www.blogger.com/img/blank.gif
//append/inheritance first first_obj to second_obj
var second_obj = extendCopy(first_obj);
document.write(second_obj.name); // first
//add both the first_obj and third_obj at the same time
var fourth_obj = multi(first_obj,third_obj);
document.write(fourth_obj.felling);// happiness
Another example of javascript inheritance using constructors
Friday, September 23, 2011
DOMDocument, accessing other sites HTML. Bypassing the Same Origin Policy
Below is a code that retrieves <a> tags from a webpage outside the server using the DOMDocument. A built in PHP class that retrieves HTML and XML from a webpage. Bypassing the Same Origin Policy. This is an alternative to cURL which downloads the entire HTML page.
$keywords = array();
$domain = array('http://bing.com');//select website to extract
$doc = new DOMDocument;
$doc->preserveWhiteSpace = FALSE;
foreach ($domain as $key => $value) {
@$doc->loadHTMLFile($value); //Load HTML from a file
$anchor_tags = $doc->getElementsByTagName('a'); //get <a> tags by accessing the DOM
foreach ($anchor_tags as $tag) {
$keywords[] = strtolower($tag->nodeValue);
}
}
echo '';';
print_r ($keywords);
echo '
Wednesday, September 21, 2011
Don't be specific
When coding, you should attempt to be the least specific as possible. One way to achieve this is by using more variables.
This is beneficial because if you ever need to update your code you only do it at one location, easy maintenance. I created an application that fetched data from a database. But coded using code specific to a table and database at multiple locations in the app. When I decided to change the table I would get an error because different parts of the code was requesting data from different tables. It took me hours to search through my code to match all these request.
This is beneficial because if you ever need to update your code you only do it at one location, easy maintenance. I created an application that fetched data from a database. But coded using code specific to a table and database at multiple locations in the app. When I decided to change the table I would get an error because different parts of the code was requesting data from different tables. It took me hours to search through my code to match all these request.
Wednesday, September 7, 2011
Chrome is Pissing me Off
I've been programming lately and this week I had Google Chrome web browser not work correctly. I was using jQuery JSON and AJAX, and tried to view a webpage source and these three instances didn't work in Chrome but worked perfectly in Firefox. I don't know if the issue is because I'm using it natively on my desktop to test, I hope it is. Chrome is a good browser to surf the internet but not the best to test your code. Imagine the frustration of coming to a conclusion that a code doesn't work but later finding out it works because chrome doesn't work when using local files. That's a bunch a BS.
I would say "I hope they fix that" but I'm going to do what I can control. I'm switching to Firefox.
I would say "I hope they fix that" but I'm going to do what I can control. I'm switching to Firefox.
Monday, September 5, 2011
Javascript Object Inheritance and Overwriting - Using Constructors
Read the comments(green text) in the code below
The output is 25Triangle
Another example of javascript inheritance using the pure object
Special Thanks Object-Oriented Javascript
function shape(){
this.name='shape';
this.tostring = function() {return this.name;};
}
function TwoDshape(){
this.name = '2D shape';
}
function Triangle(side,height){
this.name = 'Triangle';
this.side = side;
this.height = height;
this.getArea = function(){return this.side * this.height /2;};
}
//Inheritance
//overwriting objects sort of. if you print the TwoDshape.constructor it will show the assigned object but all the properties from inside both functions are accessible unless one has the same name, the original is printed so below shape() properties is added to TwoDshape() and TwoDshape() is added to Triagle(). making Triangle() have itself and shape() and TwoDshape() propeties within
TwoDshape.prototype = new shape();
Triangle.prototype = new TwoDshape();
//good idea to reset the constructor after inheriting, because overwrite the object has negative side effects
TwoDshape.prototype.constructor = TwoDshape;
Triangle.prototype.constructor = Triangle; http://www.blogger.com/img/blank.gif
var my = new Triangle(5,10);
document.write(my.getArea());
document.write(my.tostring());
The output is 25Triangle
Another example of javascript inheritance using the pure object
Special Thanks Object-Oriented Javascript
Wednesday, August 24, 2011
Frameworks
Don't reinvent the wheel. Below are frameworks that allow you to code without having to start from scratch.
HTML - Boilerplate
PHP - CodeIgniter
CSS - Twitter Bootsrap
CSS structure - 960
Javascript - jQuery
HTML - Boilerplate
PHP - CodeIgniter
CSS - Twitter Bootsrap
CSS structure - 960
Javascript - jQuery
Monday, August 15, 2011
Principle of Least Privilege
The principle of least privilege can be used to improve the security of any computer system. It's a basic but important principle that is often overlooked. The principle is as follows:
A user (or process) should have the lowest level of privilege required to perform his assigned task.
It applies in MySQL as it does elsewhere. For example, to run queries from the Web, a user does not need all the privileges to which "root" has access. You should therefore create another user who has only the necessary privileges to access the database you just created.
Excerpt from PHP and MySQL Web Development page 223
A user (or process) should have the lowest level of privilege required to perform his assigned task.
It applies in MySQL as it does elsewhere. For example, to run queries from the Web, a user does not need all the privileges to which "root" has access. You should therefore create another user who has only the necessary privileges to access the database you just created.
Excerpt from PHP and MySQL Web Development page 223
Monday, August 8, 2011
.inc vs .php file extention
.inc stands for include.
Some may prefer to name their file page.inc when using the php function include() because it looks prettier.
Some may prefer to name their file page.inc when using the php function include() because it looks prettier.
include('page.inc');
page.inc or page.php both work the same way.
Saturday, August 6, 2011
Sending Text Message with PHP
Below are resources on sending text messages with PHP.
http://net.tutsplus.com/tutorials/php/how-to-send-text-messages-with-php/
http://www.venture-ware.com/kevin/web-development/email-to-sms/
https://www.tropo.com/
http://net.tutsplus.com/tutorials/php/how-to-send-text-messages-with-php/
http://www.venture-ware.com/kevin/web-development/email-to-sms/
https://www.tropo.com/
Saturday, July 30, 2011
jQuery $.ajax and $.post
Below is an ajax jQuery code that allow uses for POST. Communication between two pages.
$.post is a simpler version with less features than $.ajax. In the code below they are both configured to do the same concept.
$.post is a simpler version with less features than $.ajax. In the code below they are both configured to do the same concept.
mouseover me Type in box to see ajax
Wednesday, July 20, 2011
Working with .htaccess
What is .htaccess:
.htaccess (hypertext access) is the default name of a directory-level configuration file that allows for decentralized management of web server configuration. -Wikipedia
.htaccess is a way to modify the web server without editing the Master file.
In Apache the master file is called httpd.conf
How to create 404 and 403 pages:
404 pages appear when it doesn't exist (alternative to index.html in every directory on site) and 403 is a page exist but is forbidden to access.
In order for .htaccess to work you need to configure httpd.conf
AllowOveride must be set to All. See below. Remember its case sensitive. For some reason apache ships as "all" instead of a capitalized "All".
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
What to put in .htaccess:
ErrorDocument 404 /yourerrorpage.html
ErrorDocument 403 /yourerrorpage.html
# Options -Indexes is what allows the 403 error to work
Options -Indexes
If you don't want to use .htaccess you can simply put
ErrorDocument 404 http:yourerrorpage.html
ErrorDocument 403 /yourerrorpage.html
Warning: Make sure you always restart Apache when changes are made to the httpd.conf because the changes won't be taken into effect until you do
You must edit httpd.conf at the server, you can't use ftp unless it's not secured. It should be located at /etc/apache2/httpd.conf
How to rewrite URLs?
To manipulate your links like transfroming ?name=page&URL's into /friendly/cute/links
you must activate rewrite_module in Apache.
Left click on the wamp icon then hover over "Apache" and go to "Apache Modules" and click on rewrite_module (or mod_rewrite) so it has a check. (or 500 Internal Server Error may throw)
or open httpd.conf and uncomment(remove #) the line below
LoadModule rewrite_module modules/mod_rewrite.so
Wait for Apache to restart.
In .htaccess insert this code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) mvc/index.php/$1
------or-------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
More information:
http://corz.org/serv/tricks/htaccess2.php
Good MVC clean URL video
_________________________________________________
Ubuntu sever 11.10
Now the mod rewrite is a little different in the Ubuntu server. You have to create a "rewrite.load" symlink from /etc/apache2/mods-available to /etc/apache2/mods-enabled by running:
$ sudo a2enmod rewrite
then edit:
$ sudo nano /etc/apache2/sites-available/default
and make line 11 to AllowOverride None to AllowOverride All, see snippet below
<Directory /home/marko/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
then restart apache:
$ sudo service apache2 restart
reference: http://www.techytalk.info/enable-apache-mod_rewrite-on-ubuntu-linux/
description: mod_rewrite wamp, .htaccess issue (500 - Internal Server Error), .htaccess apache mvc configuration 500, redirecting and rewriting
.htaccess (hypertext access) is the default name of a directory-level configuration file that allows for decentralized management of web server configuration. -Wikipedia
.htaccess is a way to modify the web server without editing the Master file.
In Apache the master file is called httpd.conf
How to create 404 and 403 pages:
404 pages appear when it doesn't exist (alternative to index.html in every directory on site) and 403 is a page exist but is forbidden to access.
In order for .htaccess to work you need to configure httpd.conf
AllowOveride must be set to All. See below. Remember its case sensitive. For some reason apache ships as "all" instead of a capitalized "All".
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
What to put in .htaccess:
ErrorDocument 404 /yourerrorpage.html
ErrorDocument 403 /yourerrorpage.html
# Options -Indexes is what allows the 403 error to work
Options -Indexes
If you don't want to use .htaccess you can simply put
ErrorDocument 404 http:yourerrorpage.html
ErrorDocument 403 /yourerrorpage.html
Warning: Make sure you always restart Apache when changes are made to the httpd.conf because the changes won't be taken into effect until you do
You must edit httpd.conf at the server, you can't use ftp unless it's not secured. It should be located at /etc/apache2/httpd.conf
How to rewrite URLs?
To manipulate your links like transfroming ?name=page&URL's into /friendly/cute/links
you must activate rewrite_module in Apache.
Left click on the wamp icon then hover over "Apache" and go to "Apache Modules" and click on rewrite_module (or mod_rewrite) so it has a check. (or 500 Internal Server Error may throw)
or open httpd.conf and uncomment(remove #) the line below
LoadModule rewrite_module modules/mod_rewrite.so
Wait for Apache to restart.
In .htaccess insert this code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) mvc/index.php/$1
------or-------
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
More information:
http://corz.org/serv/tricks/htaccess2.php
Good MVC clean URL video
_________________________________________________
Ubuntu sever 11.10
Now the mod rewrite is a little different in the Ubuntu server. You have to create a "rewrite.load" symlink from /etc/apache2/mods-available to /etc/apache2/mods-enabled by running:
$ sudo a2enmod rewrite
then edit:
$ sudo nano /etc/apache2/sites-available/default
and make line 11 to AllowOverride None to AllowOverride All, see snippet below
<Directory /home/marko/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
then restart apache:
$ sudo service apache2 restart
reference: http://www.techytalk.info/enable-apache-mod_rewrite-on-ubuntu-linux/
description: mod_rewrite wamp, .htaccess issue (500 - Internal Server Error), .htaccess apache mvc configuration 500, redirecting and rewriting
Subscribe to:
Posts (Atom)