Wednesday, September 14, 2011

Setting the input className to the object value

The code below creates and set the value of the object when filling out a form. This can be used for POST or GET method request.

<input type="text" class="balls" />
<input type="text" class="bat" />
<script>
var stat = {
data: {date: '2011-02-01', type: 'balls'},
column: //sets the value to stat.data
function(){
$('input').focusout(function () {
var attr = $(this).attr("class");//get the attribute (className) of tag
//create and set value for the object
stat.data[attr] = $(this).val(); //set value to stat.data
});
}() //this autostarts the function
}
<script/>

From locahost/stats website

Monday, September 12, 2011

Optical character recognition (OCR)

Optical character recognition

I had a scanned document on my computer as an image and I didn't want to type the whole thing out nor did I have expensive software to covert the text on the image to "encoded text". I found a free software called onlineocr. It does exactly that, I wished I had something like this back in college.

Friday, September 9, 2011

Don't Think

Don't think. Want to get it done? Don't think. If you do think you will think about how long it will take, think about the chances of failing, think about another time to do it (procrastination), think yourself out of it. Don't Think, DO.

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.

Monday, September 5, 2011

Javascript Object Inheritance and Overwriting - Using Constructors

Read the comments(green text) in the code below
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

Friday, September 2, 2011

jQuery AJAX .load()

jQuery AJAX is wonderfully powerfull. The more I use it the more I like it. Its very simple compared to the pure AJAX javascript code. jQuery has a couple of different AJAX syntax but the simplest is the .load(). Choose which element you want to target and which location/file you want to pull content from. Barabam AJAX.

Example:
$('div').load('test.html');
Above changes the div tag in current page to the test.html

One cool feature is the ability to pull a selected portion of the location by having a space after the location name and specifying the part.

Example:
$('div').load('test.html #content');
Above changes the div tag in current page to the test.html where the id equals "content"

More information check .load() – jQuery API

Wednesday, August 31, 2011

MySQL Cheat Sheet

MySQL Commands

//select database
mysql> use [databasename]

//show all databases
mysql> show databases;

//show database tables
mysql> show tables;

//describe table, must have the database selected
mysql> show tables;

//a search query that allow regular expressions
SELECT * FROM customers WHERE city like 'Air%';

//create table, must have a type after the name. eg: name=customerid, type=text
create table books
(customerid text, name text);

//delete table
drop table balls;

//insert values
insert into customers values
(null,'blahblah', 3);

//connecting subqueries
select name from customers where customers.customerid = any (select orders.orderid from orders,order_items where orders.orderid = order_items.orderid);

//Update record
update books set price = price1.1;

//alter table, add columns. its like create table, name and type
alter table books
add (tax text);

alter table books
drop tax;

//delete record
delete from customers
where cus

Monday, August 29, 2011

Center HTML/Webpage

To center your webpage its simple. By setting the width and margin you can achieve this. However, depending on the browser (Internet Explorer) you must include the doctype or it will not work. See the code below


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<body>
<html>
<style>
#main {
width: 900px;
margin: 0 auto;
}
</style>
</head>
<body>
<div id="main">



</div>
</body>
</html>

Thursday, August 25, 2011

Quote: Stick to it

Steve Jobs stepped down as CEO at Apple today. He is an inspiration to me and many others through his products, life and beliefs.

The problem with the Internet startup craze isn’t that too many people are starting companies; it’s that too many people aren’t sticking with it. That’s somewhat understandable, because there are many moments that are filled with despair and agony, when you have to fire people and cancel things and deal with very difficult situations. That’s when you find out who you are and what your values are.
So when these people sell out, even though they get fabulously rich, they’re gypping themselves out of one of the potentially most rewarding experiences of their unfolding lives. Without it, they may never know their values or how to keep their newfound wealth in perspective. -Steve Jobs

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

Sunday, August 21, 2011

Self-discipline

Simple definition to self-discipline

The ability to make yourself do, what you know you should do, when you should do it, when you feel like it or not. That's the difference between success and failer is whether you feel like it or not. -Brian Tracy

Saturday, August 20, 2011

Giveaway

This is baligena first Giveaway. What better way to thank all you who been supporting the site. baligena will be giving an iPod shuffle. The giveaway starts today and ends on September 3rd 2011.




Now here is how to win

1. First you must subscribe to my feed by putting your email under "Follow by Email" on the left sidebar and click submit.

2. Leave a comment on any of my post saying "This is the first comment".

Wednesday, August 17, 2011

Just Try

"There is nothing impossible to him who will try." - Alexander The Great

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

Friday, August 12, 2011

Quote: The climb is the best part

"To climb up the mountain is the best thing. you know preparing for it. Living every day in practice, working hard, talking about it, seeing the commitment out of the kids, everybody on the team is at practice, 100 percent all the time and just working hard every day. That’s where the comradely happens that’s where you bond and hopefully when you get the chance you'll be able to do it" -Russ Cozart Brandon High School Wrestling Coach

Cozart makes this statement in an interview about the next chance he gets at the National High School Dual Meet Wrestling Tournament after lost in the finals.

Watch the interview

Wednesday, August 10, 2011

Youtube Data API

Below is a PHP script that uses Youtube API through xml to show the comments on your personal website.

I didn't include any CSS.
Use this link a reference
http://code.google.com/intl/it-IT/apis/youtube/2.0/developers_guide_protocol.html

<?php

//// video id
$videoId='M1Wm9nGJcYo';

//echo the video
echo "";

// url where feed is located
$url="http://gdata.youtube.com/feeds/api/videos/$videoId/comments";

// get the feed
$comments=simplexml_load_file($url);

// parse the feed using a loop
foreach($comments->entry as $comment)
{
echo '
'. $comment->content .'
'. $comment->author->name .'
';
}



?>

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.

include('page.inc');

page.inc or page.php both work the same way.

I would stick with the .php extension instead of the .inc extension because the difference is that the .inc is easier to identify when navigating through files in website directory. It has security issues because if positioned in the wrong directory it will not be parse as php by your host if opened directly, making you code readable. But when you have a .php extension php is parsed and the code is not shown to the outside.

Thursday, August 4, 2011

Quote: Taking risk

Life is about taking risks. You are very young and have a promising future. Why are you willing to subject yourself to this disability just because of that 1% risk? Take that 99% chance of success and do yourself a favor."

Monday, August 1, 2011

AutoStart WAMP when windows start(apache and mysql)

Auto starting Mysql and Apache when windows starts gives you a desktop application feel built on PHP.

The Instructions:
Easiest way is to move 'start wampserver' from the start>program menu>wampserver and drag it into your start>program menu>startup folder. However if windows ask for permission to start the program the option below will fit your needs better

Go start>run> type in 'services.msc' and press enter

scroll down to the two services

wampapache
wampmysql

right click them and select properties.

on the general tab change startup from manual to automatic.

WARNING: Doing this method will not show the wamp icon at the bottom right hand conner of screen

in order to adjust Apache and Mysql settings start wamp and the icon will then appear