Poss Blog

Just another WordPress.com weblog

Ajax Project Intro January 20, 2010

Filed under: Computers — jposs @ 11:30 pm
Tags: , , , ,

This is an introductory blog about my experiences developing an Ajax style application. This project is my first time to develop any type of web based program. I still have a ways to go before it is complete. Future blogs will present information I think might be useful to other developers. If you have a question or advice, please leave a comment.

Programming languages used: Javascript, HTML, CSS, Python
Web Service Framework: Django
Javascript library: JQuery
Editors: Notepad++ for everything but Python, Idle for Python
Web Hosting: WebFaction
FTP File Transfer (between my pc and WebFaction): FileZilla
SSH(secure command line connection to WebFaction): PuTTY
Client OS: Windows 7 Home Premium
Client PC: Lenovo laptop, 2 yrs old, 2 core intel 1.5ghz, 2.5gb ram, low end machine-paid $600

So far I am really pleased with all the tools used to work on this project. I just upgraded from WinXP to Win7 and am glad I did (very nice OS). Python and Javascript are great. Compared to Java or C?, these languages are a lot more fun to use. My next blog will probably be on Javascript objects, which are totally cool. If you plan to work with a web hosting company like WebFaction, get some type of Linux/Unix reference. Using a text command line interface, which is needed for some tasks, can be a pain especially if you haven’t worked in that environment. WebFaction does have a nice interface for some of the setup and loads all the Django files for you. They also have a nice feature that lets you put static files in a fast load area that doesn’t use your machine partition (I think).

I use Django to provide a data only web service. My html, javascript, css files are stored in the Webfaction fast load area (mentioned above). After the page loads in the browser, requests are sent to the Django web service. The service sends JSON formatted data back which is stored in javascript arrays. I came up with a really neat (my opinion) way to store/manipulate this data using javascript. Data updates are also sent in JSON format back to the service and the server side database is updated. I’m using Postgresql, but the Django object relational mapper reduces the need to know much about the db.

Django looks to be first class. Python may be my favorite language and in Django, pretty much everything is Python code, including setup files that other frameworks would probably store as xml. The whole approach is very clean.

Adios

 

Python Cracked #2 September 3, 2009

Filed under: Computers — jposs @ 6:44 pm
Tags: , , ,

This post has to do with Python variable binding (the way I understand it).

All variables are binded (point) to an object or None.

Everything is an object (numbers, strings, classes, modules, functions,etc.) 

A variable can point to any type of object.

Some objects are mutable (can be changed); some are immutable (cannot be changed).

Example mutable objects: lists, dictionaries

Example immutable objects: strings,  numbers of any type ,  tuples 

 

x = 1 ( var x points to integer object with value of 1)

x= x + 1 ( var x points to a different integer object with value of 2)

The original object x was bound to is  now unbound and will be removed by the garbage collector.

If x pointed to a list object and it was changed,  x would still point to the same object.

 

Variables as function parameters:

  • A pointer is passed to the original object for each parameter.
  • If the parameter object is immutable, then any changes will cause creation of a new object.
  • The variable used in the calling statement will still point to the original (unchanged) object. 
  • If the parameter object is mutable, then any changes will affect the original object.
  • The variable used in the calling statement will see affects of the changes made.
 

Python Cracked #1 September 2, 2009

Filed under: Computers — jposs @ 1:55 pm
Tags: ,

# This post is a working Python module that demonstrates key concepts.
# Target audience is programmers experienced with other languages (Java,C#).
# It is intended as a supplement to other reference materials.

# Copy and paste into an editor. Preferrably one that knows Python.

# Python is picky about formatting. Indents mean something. Each indent level should be 4 spaces.

# ———– CODE BEGINS HERE —————————————————
class Customer:
    “Customer Record”
   
    log = []           
    __nextCustNo = 0        # __private
   
    def __init__(self, name, city, st, contact=”unknown”): 
        Customer.__nextCustNo += 1
        self.custno = Customer.__nextCustNo
        self.name = name
        self.city = city
        self.st = st
        self.contact = contact
        self.sales = 0.00
        self.pastDue = 0.00
        Customer.log.append(name + ” – customer rec created”)
   
    def addSales(self, salesAmt):
        self.sales += salesAmt
        Customer.log.append(“%s sales amt of %d added” % (self.name, salesAmt))
       
    def addPastDue(self, pastDueAmt):
        self.pastDue += pastDueAmt
        Customer.log.append(“%s pastdue amt of %d added” % (self.name, pastDueAmt))
                           
# ———————————————————————–
def goodCust(cust):
    “return true, if cust (instance of Customer) is a good customer, else return false”
    if cust.sales > 1000 and cust.pastDue < (cust.sales * .10):
        return True
    else:
        return False
   
# ———————————————————————-
def printCustomerLog():    
    for logMsg in Customer.log:    
        print logMsg
       
# ———————————————————————-
def addAmts(custName, salesAmt=0, pastDueAmt=0):
    “Add specified salesAmt and pastDueAmt to Customer record in customers[]”
    findName = custName.upper()
    custFound = False
   
    for cust in customers:
        if cust.name.upper() == findName:
            cust.addSales(salesAmt)
            cust.addPastDue(pastDueAmt)
            custFound = True
            break
       
    if custFound: pass
    else:
        print “addAmts customer not found ” + custName
       
# ———————————————————————-
customers = []

customers.append( Customer(“Hughs Ton Parts”, “Houston”, “TX”) )
customers.append( Customer(“MyAmMe Inc.”, “Miami”, “FL”) )
customers.append( Customer(“Tamp Ahh”, “Tampa”, “FL”, contact=”S.S. Simpson”) )
customers.append( Customer(“Sana Tone”, “San Antonio”, “TX”, contact=”Dee Dee Dunby”) )

addAmts(“Hughs Ton Parts”, salesAmt=500)
addAmts(“MyAmMe Inc.”, salesAmt=333.33, pastDueAmt=75.00)
addAmts(“Tamp Ahh”, salesAmt=5000, pastDueAmt=475.00)
addAmts(“Sana Tone”, salesAmt=999, pastDueAmt=100)                           

# *** floridaCustomers and goodCustomers are created using a feature called “list comprehension”

floridaCustomers = [a.custno for a in customers if a.st == “FL”]

goodCustomers = [“%s – %s” % (a.custno,a.contact) for a in customers if goodCust(a)]

coastCities = (“Houston”, “Miami”, “Pensacola”, “Tampa”)   # a tuple

coastCustomers = []

for i in range( len(customers) ):        
    if customers[i].city in coastCities:
        coastCustomers.append(customers[i])
       
# ————————————————————————–

print “Doc string for addAmts function: \n” + addAmts.__doc__

print “\n\nCustomer Log”
printCustomerLog()

print “\n\nFlorida Customers – custno only”       
for x in floridaCustomers: print x

print “\n\nGood Customers – custno-contact”
for custno_contact in goodCustomers: print custno_contact

print “\n\nCoast Customers – Name City,St”
for x in coastCustomers: print x.name + ” ” + x.city + “,” + x.st