Monday, June 13, 2011

Sort an Array of Arrays in PHP

Want to know how to sort the code below by [name]?
Click me to navigate to the tutorial.
Array
(
[0] => Array
(
[id] => 1
[name] => Rob
)
[1] => Array
(
[id] => 4
[name] => Ultimate
)
[2] => Array
(
[id] => 8
[name] => Dog
)

eg:
//for array
function views($a,$b){
return strnatcmp($a['name'], $b['name']);//to reverse the sort swap the variables(letters)
}
//for stdClass object array
function viewsObj($a,$b){
return strnatcmp($a->name, $b->name);
}
usort($result,'views');
echo '
';
print_r($result);
echo '
';

Sunday, June 12, 2011

Adding Syntax Highlighting to Blogger

Do you want to show code on your blog like I'm doing below? Click Me to see instructions.

<?php 
echo "hello world";
$ball = "ball";
?>

Saturday, June 11, 2011

Coolest Website Design

There's always a trade off. A cool ass website and slow or boring website and fast. The one to use will be determine by your needs. Tijuana Flats is by far the coolest website design I've seen.

Wednesday, June 8, 2011

I have no Time. Shut up!

Today I was sitting at my desk contemplating all the things I don't do because I don't have time. Then I stopped and remember that I'm a programmer. And then I told myself real loud, in my head of course because there were people around me. "Shut up and build it".

Having limited time is a gift because it forces you to create things that are efficient, automatic and non-time consuming.

Monday, June 6, 2011

Security Tip: Inserting index.html in every folder

Building a website is simpler than most people imagine. Its a bunch of folders with files. Now to increase your website security is to include a index.html in every folder that is accessible to the visitor. Here's why.

index.html is a default document that is automatically loaded when someone visits the webpage. If its not loaded the visitor has access to view ALL your files in your directory. Some files are not meant to be seen by the visitor because it can give information that may comprise your security.

Lets use www.example.com/folder/photo.html as an example. If photo.html part of the url is deleted (www.example.com/folder ) the visitor now has access to see all your files in that directory/folder. To avoid this vulnerability put an index.html in every folder inside your website.

CodeIgniter is a PHP framework which follows this concept.

Check out the site example below
Now delete /edit/ to see what page it leads you to

Saturday, June 4, 2011

Making your server accessible to the internet (outside your own network).

If you want to see a prettier version of this post with pictures and color coding (part of this post won't make sense if you don't see the pictures) click on the link below to view the pdf format
setting up your server.pdf

There are two types of IP address. I like to call it the internet ip address and the server ip address. The way it works is that the internet ip address points to the server ip address. The INTERNET cannot access your server directly but can access your internet ip address.

Figure:
This works
INTERNET(The world)->your internet ip address ->your server ip address

This doesn’t work
INTERNET(The world)->your server ip address

To find your internet ip address go to http://myipaddress.com

Your server ip address is what you created with Ubuntu or any server.

To point your internet ip address to your server ip address you need to access your router. You do this by typing 192.168.1.1 in browser (for Linksys, it may be different if you have a different router). What we will be doing is Port Forwarding.

In Applications & Gaming-> Port Range Foward

Applications-> can be anything you want
Start and End-> needs to be 80
Protocol->needs to be Both (TCP & UDP)
IP Address -> need to be your server IP

Save and exit

That’s it . Type your internet ip address in the browser. It will now direct you to your server.

Connect using domain name
I purchased my domain from godaddy
All were doing is connecting a domain name to the internet ip address

Log into godaddy.com account
Select the domain name you want to use
And access you Domain Manager
Click Launch where it says DNS Manager



Put your internet ip address (not the server) under Points To (next to Host) where its highlighted in blue


Then save

Now when you type your domain name it will take you to your site

Figure:
INTERNET(The world)->Domain Name->your internet ip address->your server ip address


You did it!!!
Thumbs up Everybody for Rock and Roll

Wednesday, June 1, 2011

How to set up Static IP address for Server

Its good practice to give your server a static IP address because
1. You don't always need to reconfigure your router
2. It's easy to do

Click on the link below for a full explanation

http://www.howtogeek.com/howto/ubuntu/change-ubuntu-server-from-dhcp-to-a-static-ip-address/

PS. It's not true that you need a static IP address for the world to access you website from you server. You can also use a dynamic (DHCP), which is the default when you set up your Ubuntu server.

For more infomation on Making your server accessible to the internet

Monday, May 30, 2011

Changing permissions for /var/www Ubuntu Server

The video below explains how to change the permissions for /var/www Ubuntu Server




Saturday, May 28, 2011

How to Fix it. IPhone sound stop working

FYI

If your IPhone or Ipod Touch internal sound stop working, the volume control is non-reponsive and the sound meter does not appear. Below is what you need to do.

On the top of your device there is a small button. Click and hold it, then slide to power off and turn it back on. This reboots your device and the mic will work again.

Wednesday, May 25, 2011

Don't trust your memory

A good habit is to always document and comment your discoveries. Have a piece of paper or computer be an extension of your brain. Many may say "I figured it out once, I can figure it out again." That may be true but it sucks!

When I discover something new I tend not to write it down because I trust my memory. However, its not always reliable when working with huge amount of data. Our brain can only hold so much. Recently I forgot how I set up a feature in Microsoft's Access which I created 3 days ago. I can recreate it but with an unnecessary headache.

Monday, May 23, 2011

Difficulties in your path

All afternoon I tried to get gmail to send an email using php. When I finally discovered what was wrong I remember the poem Push on.

There are difficulties in your path. Be thankful for them. They will test your capabilities of resistance; you will be impelled to persevere from the very energy of the opposition. But what of him that fails? What does he gain? Strength for life. The real merit is not in the success, but in the endeavor; and win or lose, he will be honored and crowned. William Morley

Saturday, May 21, 2011

Create and Learn

In a canoe, if you decide to row only on one side what will happen? You will go around in a circle. So why are you only studying? If you're only learning a craft but not putting into practice what you learn, you're shotting yourself in the foot. I have spent a lot of my time learning new techniques and software however I can't find time to create. I have committed everyday to learn about programming but now I'm committing some days to only creating. Because what's the point of knowledge if you're not going to do anything with it?

Wednesday, May 18, 2011

printObj() => outputs object properties

The javascript function below is used to output the objects and its properties. Alternative to the php function => print_r
I use it mostly for looking up the document DOM eg. printObj(document)

Insert code inside JavaScript <script> tags
_________________________________________________

function printObj(obj) //reads the objects properties
{
var object ="";// sets the variable
for(var type in obj)
{object += type +"=> " + obj[type] + "<br /> ";}
document.write(object);
}

//create a new array or object
var num = new Array(1,2,3,45,6);
//outpuy the object and its properties by
printObj(num)
______________________________________________

Output:
0=> 1
1=> 2
2=> 3
3=> 45
4=> 6



bookmarklet: shows all the the p tags for the page. Copy and paste the code below in the address bar.

javascript:e = document.getElementsByTagName('p');function printObj(obj){var object ="";for(var type in obj){object += type +"=> " + e[type].innerHTML + "<br />";}document.write(object);}printObj(e);

Monday, May 16, 2011

Bad Experience: Ergonomics

Couple of months ago I bought a Microsoft Ergonomic Keyboard and a Logitech Wireless Trackball M570 to make my computer experience more comfortable. However, I started feeling pain on my wrist like I never had before. I didn't want to believe that these devices were causing pain so I wore wrist braces to see if it would help and it didn't. I pulled out my non-ergonomic keyboard and regular mouse on 04/25/11 and the pain has diminished. I have since sold my ergonomic keyboard and trackball to an advertised fool. What I do now is put a pillow under my arm when typing and that seems to solve the problem.

Saturday, May 14, 2011

Running 2 hard drives

Running two hard drives is easy. What's needed is connecting an extra hard drive on your motherboard. It can be either a SATA and or a IDE connection. Once the new hard drive is plugged in (the motherboard automatically detects it) enter into your computer BIOS and change the boot order.

The BIOS software is built into the PC, and is the first code run by a PC when powered on, access by pressing a specific key when the computer boots up, before the operating system is loaded .

Usually the original hard drive is listed first. Change the boot order so the new hard drive is listed as first boot, make sure an operating system CD is insert and reboot the computer. Once the computer restarts the new hard drive will boot and the operating system will install.

To change back to the old hard drive go back to BIOS and change the boot order.

If any question leave a comment.

Wednesday, May 11, 2011

10 years from now

When I hear someone 10 years younger than me talk about how they will be going on a field trip at their school, will be meeting up with friends, are getting into trouble and etc. It takes me back, I stop and think about when I was that age and wish I did more. But then I remembered that no one has invented a time machine yet so my only option is to change. Stop waiting to make a billion dollars to have fun. Go out and travel more, meet with friends, take risks, overcome fear and live your life not someone else because the last thing you want is to look back 10 years from now and wish you did more.

Monday, May 9, 2011

Setup xampp/lampp on Linux unbuntu

video below gives everything you need to set up xampp/lampp

and the link below gives additional information. Like how to create a xampp control panel app.


PS. if you looking to reset password. Follow the video and you'll discover it.

Saturday, May 7, 2011

How to get the microphone to work, Ubuntu 11.04

First click on the speaker on the right hand corner->sound preference->input. Make sure that a input device is selected, the input volume is not muted, or isnt set too low.
------------------------------------------------------
Open terminal and enter:
alsamixer

press F5 to view all controls bars
tab allows you to select a specific bar (the description will turn red)

the arrow keys up and down allows you to increase or decrease the property selected

Capture, Capture 1, Input Source, Rear Mic and Rear Mic Boost was what allowed my microphone to work.

Initially I turned everything up until I saw a red square on each bar. Then I played with the Input Source and realize that by setting the first Input Source to Rear Mic it made my microphone work. Then I played with the volumes to reduce the background noise.

I used the 'sound recorder' to test my microphone. I tried skype and the microphone also worked.

AlsaMixer v.1.0.24.2 my configuration











Any questions leave it in the comments

Wednesday, May 4, 2011

The way to Learn

Studying sucks! The best way to learn is multiple exposure. You retain more of a movie when you watch it twice compared to once, and more on the third than second and so on. It's the same with studying. Stop this memorizing bull that makes a fun subject boring. Watch a tutorial and read a book but don't try to remember everything. Realize that as long you're being exposed to the information multiple times over time your subconscious mind will link things together.

Monday, May 2, 2011

It ain't easy being Lazy

Larry Wall the creator of Perl programming language couldn't put it better. One of the first qualities of being a great programmer is laziness. He later says "its only a joke" but deep down I know its not. However, its not the same laziness of sitting on the couch all day watching TV but a laziness towards doing repetitive tasks.

Growing up I was always taught not to be lazy but here goes another unconventional way of life for a programmer. It seems that programmers are always breaking the rules, next we will be break the law of gravity.

Programmers make computers their slaves not the other way around. Computers were meant to make our life simpler, free our time and be more efficient. I'm really stating the obvious. The desire to be lazy was what created amazon.com, zappos.com and other online stores.