Web Design and Programming Pt 6

iPhone DevelopmentIn this part of the Web Design and Programming tutorial, I will show you how to do anything with PHP functions. Specifically I will cover:

  • How to Create Functions
  • How to work with Function Attributes (Variables)
  • How to Pass Multiple Attributes to and from Functions
  • What Does Scope Mean (Local vs. Global)
  • What is Recursion

Continue reading Web Design and Programming Pt 6

Web Design and Programming Pt 5 PHP Arrays

Go Daddy Grid HostingIncrease Website SpeedIn part 5 of my Web Design and Programming tutorial I will cover the following topics:

  • How to turn a string into an array
  • How to turn an array into a string
  • How to sort an array
  • How to pull data from a file and store it in an array

And, I’ll also go over a bunch of other functions specific to arrays. If you missed part 1 of this tutorial it is available here Web Design and Programming.

All of the code in this tutorial will follow the video. Use it in any way that you would like.

If you have any questions or comments leave them below and I’ll answer them.

Code from the Video

<html>
<head>
<title><?php echo “Arrays”;?></title>
</head>

<body>

<?php
# An array is just a big box containing many similar boxes
# This information is similar to each other
# All the the information or values have a coresponding key or label associated with it
# An array can contain any combination of numbers, strings or other arrays

# Create basic array with key value pairs
/* $myInfo = array(“Name” => “Derek”, “Street” => “123 Main St”, “City” => “Pittsburgh”);

# Get the value by calling for the key associated with it
echo “My name is “, $myInfo[“Name”], “<br /><br />”;
$moreInfo = array(“State” => “PA”, “Age” => 35);

# Merge 2 arrays into one
$myInfo = array_merge($myInfo, $moreInfo);

# Iterate through the array with the foreach looping device
foreach( $myInfo as $key => $value)
{
echo $key, ” “, $value, “<br />”;
}
echo “<br /><br />”;

# Search for a key in an array
if(array_key_exists(“Name”, $myInfo)) echo “The name stored is “, $myInfo[“Name”];
echo “<br /><br />”;

# Search for a value in an array
$citySearch = array_search(“Pittsburgh”, $myInfo);
echo “The key for the city is “, $citySearch;
echo “<br /><br />”;
print_r (array_keys($myInfo)); # Short cut to provide the arrays keys
echo “<br /><br />”;
print_r (array_values($myInfo)); # Short cut to provide the arrays keys & values
echo “<br /><br />”;

# Create a Multidimensional Array
$customer1 = array(“Name” => “Derek”, “Street” => “123 Main St”, “City” => “Pittsburgh”);
$customer2 = array(“Name” => “Sally”, “Street” => “213 Grant St”, “City” => “Pittsburgh”);

$customers = array($customer1,$customer2);
print_r(array_values($customers));
echo “<br /><br />”;

foreach( $customers as $key)
{
foreach( $key as $key2 => $value)
{
echo $key2, ” “, $value, “<br />”;
}
} */

$countryStr = “Cuba,Spain,India,France,Italy”;
$randCountry = explode(“,”, $countryStr);
echo $randCountry[0], ” “, $randCountry[1], “<br /><br />”;

$countryStr2 = implode(“,”, $randCountry);

echo $countryStr2, “<br /><br />”;

if(in_array(“India”, $randCountry)) echo “India is in the list”;
echo “<br /><br />”;

print_r(array_reverse($randCountry,true));
echo “<br /><br />”;

sort($randCountry, SORT_STRING);
print_r($randCountry);
echo “<br /><br />”;

$countArray = range(0,50);
foreach($countArray as $printNum)
{
echo $printNum, “, “;
}
echo “<br /><br />”;

echo count($countArray);
echo “<br /><br />”;

$customers = file(“customers.txt”);
foreach($customers as $customer)
{
list($name,$street,$city,$state) = explode(“,”,$customer);
$state = trim($state);

echo “$name $street $city $state”;
echo “<br /><br />”;
}
?>

</body>
</html>

Web Design and Programming Pt 3 Looping

Objective C LoopingIn this web design and programming video tutorial I’ll show you how to use looping statements with PHP. If you missed the first part of this tutorial it is here Web Design and Programming.

I specifically will cover the following topics:

  • Using the $_REQUEST array to pass form data
  • The While Loop
  • The Do While Loop
  • The For Loop
  • How Break and Continue work

Continue reading Web Design and Programming Pt 3 Looping

Web Design and Programming Pt 2 PHP & HTML

Help Web Design and ProgrammingHere I continue covering Web Design and Programming using all of the most used languages being HTML, CSS, JavaScript, PHP, MySQL, etc. If you missed my first video, you should watch that first Web Design and Programming part 1.

In this specific tutorial I’ll cover the following:

  • How to access html form data with PHP
  • How to use if conditional statements in PHP
  • How to use the Switch statement in PHP
  • And more…

Continue reading Web Design and Programming Pt 2 PHP & HTML

Web Design And Programming Pt 1 PHP

Web Design and ProgrammingI have received tons of requests for tutorials. So, I’ve decided to create a massive tutorial that answers them all. In this tutorial I’ll focus on Web Design and Programming using all of the tools required. You should check out my Learn HTML Tutorial if you haven’t ahead of time.

I’ll continue this tutorial, with your input, until you can do pretty much anything in Web Design and Programming. Leave questions and comments below, because you are going to totally control everything I cover here.

I’ll start off with the basics of PHP and move on from there with tons of examples. Of course, all of the code used will follow the video.

All the Code from the Video

<html>
<head>
<title><?php echo “Website Title”;?></title>
</head>
<body>
<?php

// You can use short tags but it is not recommended doesn’t work in 6
# You can also comment code like this
/* Here is a
multiline comment
*/
echo “<p>Random Text</p>”;
print(“<p>You can print with braces</p>”);
print “<p>or without
them!</p>”;

$randVar = “Cats”;
echo “<p>”, $randVar, ” are funny</p>”;

printf(“<p>My name is %s I’m %d years old and
pi is equal to %.2f</p>”, ‘Derek’, 35, 3.14);

// Variables must start with a $ then letter or _ and then numbers
// Variables are case sensitive & don’t require definition before use

$boolEx1 = false; // 0 or false equals false
$boolEx2 = 1; // true equals any number but 0

$intEx1 = -234; // Max size normally 2^31 or 2^63

$floatEx1 = 3534.14;

echo “<p>Cost: $”,number_format($floatEx1,2), “</p>”;

// Arithmetic Operators: + – * / % ++ —

$firstName = “Doctor”;
$lastName = “Who”;

$wholeName = $firstName . ‘ ‘ . $lastName;
printf(“<p>His name is %s</p>”,$wholeName);

define(‘ACONSTANTVAR’, 2345);

echo “A constant is equal to ” . ACONSTANTVAR . “<br />”;

echo “How do quotes differ $wholeName<br />”;
echo ‘How do quotes differ $wholeName<br />’;

/* Escaped Characters in double quotes \” \’ \\ \n \r \t \$ */

$float2Int = (int) $floatEx1;
echo $float2Int, “<br />”;

/*
(array)
(bool)
(int64)
(object)
(float)
(double)
(string)
*/

$strNum = “28”;
echo $strNum * $floatEx1, “<br />”;

echo gettype($strNum), “<br />”;
echo is_string($strNum), “<br />”;

/* is_array() is_bool() is_float() is_integer() is_null() is_object()

?>
</body>
</html>

Python 2.7 Tutorial Pt 19

Python 2.7 TutorialWell it has been a long trip, but I’m going to wrap up the Python Tutorial here. Before I stopped I wanted to answer one question posed to me which was to create a program that automated the process of getting demographics.

I didn’t have much time to perfect this and I plan to come back, but this program will grab tons of demographics for you including:

Continue reading Python 2.7 Tutorial Pt 19

Python 2.7 Tutorial Pt 18 Chat Server

Python PictureIn this Python Tutorial I show you how to build a simple chat server. All you need to do this are the pre-installed modules: asyncore, asynchat and socket.

The code then basically does the following:

  • Assigns a special address for each person that goes to the port (Socket)
  • Listens for any messages
  • When it gets a new message it sends it through the socket and into the port
  • A dispatcher decides what code should be called based off of the message sent

Continue reading Python 2.7 Tutorial Pt 18 Chat Server

Python 2.7 Tutorial Pt 17

Python How ToIn this video tutorial I show you how to create dynamic websites with Python. This is the quickest and easiest way to start using Python in much the same way as PHP is used.

I previously taught you how to scrap websites for information in this tutorial Python Website Scraping. Here I’ll show you how to scrap and then display that information dynamically on the internet.

Leave any questions or comments below and here are all of my previous Python Video Tutorial’s:

Continue reading Python 2.7 Tutorial Pt 17

Python 2.7 Tutorial Pt 16

Python 2.7 TutorialHere I continue to teach you how to use the Tkinter GUI module built into Python. I build an application that allows you to input files, edit them and then save them. I specifically show you how to make the following GUI widgets with Tkinter:

  • Menu Bars
  • Multi-Line Editable Text Boxes
  • Drop Down Menus

If you haven’t seen the previous Tkinter tutorial you should definitely check it out below first. Otherwise this won’t make any sense.

Continue reading Python 2.7 Tutorial Pt 16

Python 2.7 Tutorial Pt 14

Python How ToIn the previous tutorial I showed you how to grab the following from any sites rss feed using Python:

  • Title of Articles
  • All the Content from the Original Article
  • Link to the Original Article

This is known as website scraping and it is the major component used by all automated website applications. One thing I didn’t cover is how to strip the html tags from those articles, so I’ll do that in this video.

Continue reading Python 2.7 Tutorial Pt 14

Personality Type

Martha StewartI was asked today to provide a big personality test that provided easy to understand results. Below I provide a personality quiz and answer sheet along with a detailed report on all 16 possible personality types.

This personality quiz is based off of Myers Briggs, with some additions from more recently developed personality analysis. I hope you find it useful, because I’ve been working on this for some time.

Your Personality Type

Continue reading Personality Type

Python 2.7 Tutorial Pt 13 Website Scraping

Python How ToIn this video tutorial I show you how to scrap websites. I introduce 2 new modules being UrlLib and Beautiful Soup. UrlLib is preinstalled on Python, but you have to install Beautiful Soup for it to work.

Beautiful Soup is available at their website. If you are using Python versions previous to Python 3.0 get this version Beautiful Soup for Python previous to 3.0. If you are using Python 3.0 or higher get this version of Beautiful Soup.

To install it follow these steps:

Continue reading Python 2.7 Tutorial Pt 13 Website Scraping

Python 2.7 Tutorial Pt 12

Python 2.7 TutorialIn this Python Video Tutorial, I will show you how to create databases using the Python SQLite module. SQLite is great because it:

  • Provides most of the basic database structure you want
  • Doesn’t require you to have an actual database server running
  • Provides SQL querying capabilities
  • Is included with Python by default

You enter and retrieve information from an SQLite database just like you do with any other database, by using SQL. Here is a tutorial on how to program with SQL if you don’t know how SQL Statements Video Tutorial. In that tutorial I focus on MySQL, but everything a say about SQL is nearly identical.

Continue reading Python 2.7 Tutorial Pt 12

Python 2.7 Tutorial Pt 11

PythonIn this video tutorial on how to use Python, I will focus on how to use an interesting Python Module called Shelve. Shelve allows you to store data in files similar to how a database works. It is very easy to use and provides a convenient way to take advantage of the power of Python dictionaries while providing you with the ability to change the data.

I’ll continue in the next tutorial to cover another interesting Python Module called SQLite. It is a Module that can be used as if it was a database meaning:

  • You can run SQL queries on it
  • Information is stored logically

Continue reading Python 2.7 Tutorial Pt 11

You on a Diet

Diet Nutritional, Nutrition HeartI realized today that I haven’t mentioned my diet in many months. The reason why most people stop talking about their diet is because it has failed. Mine hasn’t!!!

For those who are unaware, last year at about this time I weighed 248lbs and I decided I wanted to lose weight. I created a diet plan that was based around these core principles:

  • Eat the number of calories I needed to lose 70 lbs (Around 1400 calories)
  • Eat food that was high in fiber and makes your body feel full
  • Avoid foods high in calories, fat, cholesterol and sodium

Continue reading You on a Diet

Python 2.7 Tutorial Pt 8

Python 2.7 TutorialIn this tutorial, I continue to explain how Object Oriented Programming is used with Python 2.7. I cover some of the more complicated subjects including how to:

  • Allow the user to define an infinite number of attributes
  • Use Inheritance and what it is
  • Override Methods
  • Use Polymorphism and what it is
  • Inherit from 2 more more classes
  • Use many of the built in object methods in Python

If you don’t completely understand Object Oriented Programming after this and the first part of this tutorial Python Object Oriented Programming. Please leave a comment below and I’ll do whatever I can to explain this important subject.

Like always, a lot of code follows the video. If you have any questions or comments leave them below. And, if you missed my other Python Tutorials they are available here:

Here is All the Code from the Video

Note: You have to insert the white space and everything will work. I could have styled it with HTML, but that would have required you to erase all of the tags. Hope this helps?

#! /usr/bin/python

__metaclass__ = type

class Animal:

__name = “No Name”
__owner = “No Owner”

def __init__(self, **kvargs): # The constructor function called when object is created
self._attributes = kvargs

# There is a function called a destructor __del__, but its best to avoid it

def set_attributes(self, key, value): # Accessor Method
self._attributes[key] = value
return

def get_attributes(self, key):
return self._attributes.get(key, None)

def noise(self): # self is a reference to the object
print(‘errr’) # You use self so you can access attributes of the object
return

def move(self):
print(‘The animal moves forward’)
return

def eat(self):
print(‘Crunch, crunch’)
return

def __hiddenMethod(self): # A hidden method
print “Hard to Find”
return

class Dog(Animal):

def __init__(self, **kvargs):   # Not needed unless you plan to override the super
super(Dog, self).__init__() # This wouldn’t work without the second line
self._attributes = kvargs

def noise(self):        # Overriding the Animal noise function
print(‘Woof, woof’)
Animal.noise(self)
return

class Cat(Animal):

def __init__(self, **kvargs):  # Not needed unless you plan to override the super
super(Cat, self).__init__()
self._attributes = kvargs

def noise(self):
print(‘Meow’)
return

def noise2(self):
print(‘Purrrrr’)
return

class Dat(Cat,Dog):

def __init__(self, **kvargs):  # Not needed unless you plan to override the super
super(Dat, self).__init__()
self._attributes = kvargs

def move(self):
print(‘Chases Tail’)
return

def playWithAnimal(Animal): # This is polymorphism
Animal.noise()
Animal.eat() # Works even if the method isn’t in Cat because Cat is an Animal
Animal.move()
print(Animal.get_attributes(‘__name’))
print(Animal.get_attributes(‘__owner’))
print ‘\n’
Animal.set_attributes(‘clean’,”Yes”)
print(Animal.get_attributes(‘clean’))

jake = Dog(__name = ‘Jake’, __owner = ‘Paul’)
sophie = Cat(__name = ‘Sophie’, __owner = ‘Sue’)
playWithAnimal(sophie)
playWithAnimal(jake)

# print sophie.__hiddenMethod() Demonstrating private methods

print issubclass(Cat, Animal) # Checks if Cat is a subclass of Animal
print Cat.__bases__           # Prints out the base class of a class
print sophie.__class__        # Prints the objects class
print sophie.__dict__         # Prints all of an objects attributes

japhie = Dat(__name = ‘Japhie’, __owner = ‘Sue’)
japhie.move()
print japhie.get_attributes(‘__name’)