Friday, October 25, 2013

My Google App Engine NDB Datastore Notes in Python


Get the Geopoint of an Address
def get_lat_long(address):
  address = cgi.escape(address.replace(" ","+"))
  sensor = "true"
  url = "" + address + "&sensor="+ sensor
  result = urlfetch.fetch(url)
  data = json.loads(result.content)
  lat = data['results'][0]['geometry']['location']['lat']
  long = data['results'][0]['geometry']['location']['lng']
  return ndb.GeoPt(str(lat) +","+ str(long))
Convert query to become a json
  def render_json(self,queries):
    queries_list = []
    for query in queries:
    for value in queries_list:
      value['dateCreated'] = value['dateCreated'].strftime('%b %d, %Y')
      value['dateUpdated'] = value['dateUpdated'].strftime('%b %d, %Y')
      value['geopoint'] = str(value['geopoint'])
    self.response.content_type = 'text/json'

Convert queries to become multiple json
      def render_multi_json(self,**kwargs):
        queries_list = []
        queries_dict = {}
        for kw_query, queries in kwargs.items():
          queries_dict[kw_query] = []
          for query in queries:
          for value in queries_dict[kw_query]:
            value['dateCreated'] = value['dateCreated'].strftime('%b %d, %Y')
            value['dateUpdated'] = value['dateUpdated'].strftime('%b %d, %Y')
            value['geopoint'] = str(value['geopoint'])
        self.response.content_type = 'text/json'

Saturday, October 5, 2013

Narration of A Project Before A Flow Chart

Creating a flow chart on the first part of the project can lose the detail of information needed to create a project. Although a picture can say a thousand words of what a project could become in a flow chart, the idea can trap itself in a box from the image of a flow chart, making the idea too simple that the idea looses its information because an image can make you think what it means. While I agree that a flow chart can make a project easier to understand, it can also limit the detail that a concept can allow the flow of inserting an additional idea of creating a system.

If we create a project of a flow of how a human body works, for instance, starting a flow chart can limit the complexity of information because the image can only tell us about one certain aspect of a flow. Comparing the flow chart to a human body, the human body should have different layers of flow systems involving respiratory systems, nervous system, digestive system, etc. The variables listed to be understood belong to certain object flow and objects that can make a flow harder to draw, but can become easier if we use a narrative way to write and update.

After data gathering, a written project narration becomes the backbone of a project because the ease of implementing the updates of revising the project could become the source of all the information.

Narrative Form Advantages
The advantage of writing a paragraph form, before creating a project, can give the detail of a project. A narrative form can also be corrected depending on the type of idea that the information suggests. Inserting sentences in a narrative form could demonstrate ease in writing and removing an idea by appending sentences or removing an inconsistent idea that does not support the system makes ideas easier to add.

Flow chart and Its Image Limitations
A picture, like a flowchart, can demonstrate detail, but the exactness of the detail allows to tell information based on the image alone. This does not demonstrate innovation because the image allows you to guess what the image is trying to convey. So, the idea of correcting a flow chart by innovation can make it harder to modify, especially if the knowledge of the reader has limitations.

Narration vs Flow Chart
A narrative idea when compared to inserting ideas in a flow chart can take you less time than inserting a process in a flow chart. Because the narrative form allows modifying a data, innovation comes into play without questioning how it should be placed. If the sentences fit together with the system of the project, the ideas can easily be replaced with another idea to make it useful. Therefore, making it more innovative.

Can a narration and a flow chart work together?
Although a narrative form of explaining a project could be more detail than a flow chart, a narration and a flow chart should work together because the information does not really contradict the effectiveness of how the final project would exist. Making the narrative form and the flow chart that work hand-in-hand makes the information more effective because it can create a view of different angles in a project. A flow chart can show the final draft of a project on how it should flow to become the final product, and a narrative form supports the explanation of how it should exist.

Narration and flow chart revisions
If the narrative information would reach its final state, the flow chart can then be implemented to become the final draft. Although the revision of the narrative form can happen while the flow chart has already been finalized, revising the flow chart make it easier to update because by reading the narrative information allows the data to become clear to the reader. Writing would explain to the reader some reasons why the plan did not make it as an idea.

Creating a narration makes it crucial in planning a project because it creates a clearer idea of what the project outcome becomes. From the narration of the project plan, the ideas can flow easily making innovation easier to implement.

How did you come up to this?
I always created projects starting on a flow chart, then I leave my projects behind. After months of going back to the project, I don't know what the flow chart meant, and would sometimes find myself coming back to the previous mistakes I did in the past. When I started creating projects in narrative form, it made it easier to add more information to the project and create flow chart anytime. So, losing the flow chart would not matter much, just as long as I have the narrative form of my projects.

Tuesday, September 24, 2013

Memorizing Shortcut Keys Made Me Ahead of The Game

One thing that I have the advantage of in my computer programming skills include the ability for me to memorize easily the shortcut keys on any computer operating systems, but mostly on Windows.

I learned to memorize shortcut keys because one of my teacher in college has a weird way in teaching us how to use a computer without a mouse. I remembered him saying, "Class, we're going to have an exam using a computer without a mouse". Everybody in the classroom has a look of "What?!" in their faces. The subject did not even have anything to do about Computer Science, rather it was about using Microsoft Word.

You see, my professor, during his years of starting to use a computer, never really used a mouse because he was born in that era. Actually, the way I see it now, it seems much more efficient in memorizing the keyboards rather than having a mouse, or having a command console in your computer if you only memorize the keyboards.

Let's say for instance, I was using a Windows operating system. The shortcut keys for "Start" would be Ctrl+Esc. It's going to take me about ten to twenty repetitions to get used to the pattern. Then, I can type in the name of the folder that I want, and it highlights the folder that I want. I think this is more efficient than memorizing the name of the folder path.

This skill has also allowed me to increase the repetitive input speed. A normal person would take about 600 products in about 8 hours. I could probably do it in 4 hours using the mouse the least amount that I can. If I was using spreadsheet, the pattern of looking for the data, switching from one window to the next, going back, putting the cursor in the right cell, and pasting the value that was copied would probably take most people about 5 to 10 seconds seconds. I can probably do it in 2 to 3 seconds.

One of the things I like about this skill is that it is not only efficient, it's also entertaining for the reason I can not really explain. One of my co-worker asked me to do bar code scanning for 800 pieces of phones, when I was working on a cell phone manufacturing company, and the job included sticking information stickers at the back of cell phones found when you open the battery case. He stood at my back for about 3 to 5 minutes looking to see what buttons I was pressing, and it seems like he was memorizing it, too.

It's probably as entertaining as a cowboy slinging his gun, tosses it in the air, catches his gun, pivots it around his fingers, puts the gun back to his holster, and does it again.

I would also compare it to playing a lead guitar where a guitarist plays his guitar without even thinking, which his hands run around on the guitar, and the only thing that he can feel is the sound it creates that whistles into the air, raises his guitar to feel the tune, and it would seem almost like he's in climax, but not really. Just him, his guitar, and the music it plays.

Playing desktop games also has never been the same, like playing Starcraft. If the shortcut keys are an advantage, it could cost some milliseconds to move the mouse to the right spot than pressing the keyboard to execute the right action.

So I guess, I'm writing this article to thank the professor who shocked us during college in his old school ways of using a keyboard without a mouse. Touche!

Thursday, December 13, 2012

Open ID and Oauth Difference

I've been reading a little bit about Open ID and OAuth, and I just don't want to forget it. So, my explanation here may sound like a layman's term, but anybody can correct me if they want.

Open ID (identifies the person)
  • OpenID is given after you have supplied yourusername and password to the Open ID provider.
  • OpenID does not use API key nor consumer secret because you have provided your username and password to the website that you are logging into.
  • The way authentication works is: It logs you in and identifies that you are you, just by clicking a button.
  • Open ID Analogy: If you are going to go inside a secure laboratory and they use fingerprint scanner and card reader, you need to have your key card and yourself. Your username is you and your key card is your password.
OAuth (is like a ticket)
  • Oauth does not use a username and password because an API key is given to the user from the website/application he is using.
  • The API key that has been given from the website/application will give you access if the website that you are using gets your information needed for the website/application.
  • OAuth Analogy: If you are going to watch a concert, then you should buy a ticket. The ticket will act as your API key. With your API key/ticket, you can be able to watch the show. The ticket proves that you have allowed the Concert Booth to sell and give you a ticket. (It does not matter where you got the ticket from just as long as you have one.) Since the tickets of each passenger are all the same, you don't need to show any identification. If you have a VIP pass on your ticket, then you can access VIP passes. If your access is limited to the balcony area of the concert, then you are not allowed to go anywhere.
  • When using Oauth, it may have an option of using Consumer Secret key. A consumer secret is the password for the API key. Your API key is known to be your username, and Consumer secret is your pasword.
  • Consumer Key and Secret Analogy: In a ticket, it is the black striped magnetic strip that is located at the back of your ticket. It contains the information of the ticket to be proven the authenticity of the ticket when swiped.

Friday, September 7, 2012

Object Oriented Programming Analogy

I have started to learn Object Oriented Programming. It seems like it was really a long cycle because there is something about Procedural Programming that totally is different from Obejct Oriented Programming. Most human thinks in a procedural way. For example:

  • What are the steps in cooking? 
  • What are the steps in creating a site? 
  • What are the steps to gain muscles? 
  • What are the ways to get healthy?
  • How to drive a car, and so on...

Steps and ways rules the world. But not really...

If you're going to think about it deeper, Industrialism says a lot about Object Oriented Programming. People will only be able to communicate efficiently if they are in one company where each people play different roles. In Object Oriented Programming, one class is considered one employee. One method is considered one skill or one process. One package is considered one company.

A manager for instance thinks about the goal first. Let us say the goal is to create a computer. Then, he asks the questions: What are the things that he needs to build a computer? Well, he needs people! One person to receive and order the parts, one person to construct or assemble the computer, and one person to check if the quality of the computer is well built.

Person/Employees can be considered one class in a project. If we are going to build using Object Oriented Programming, we should think like a manager.

  1. The Person/Employee/Class that receives the order, for instance, has these methods that will make sure that: 
    • the order is completely defined when it orders an item. 
    • As soon as it receives the orders, it will make sure that the quantity is correct
    • it will make sure that the quality is correct
    • it will also make sure that the precision of what the order was is correct. 
    • It will return an error otherwise.
  2. The Person/Employee/Class that will assemble the order will make sure that the
    • parts of a computer are complete before it starts building the computer.
    • Part by part and layer by layer it will build the computer, both software and hardware. 
    • It then puts the computer for checking.
  3. The Person/Employee/Class that will act as the Quality assurance should be the one to. 
    • Check if the assembled computer is acceptable, 
    • There are certain limits that the Quality Assurance needs to check, 
      • such as: the right casing precision measurement without gaps in between layers when attached together, 
      • checking if the computer turns on, 
      • and checking if the computer was loaded with the right Operating Sytem successfully without any errors.

Note: I have arranged the Class and Methods above wherein the Class is in a numbered list, and Methods in a bulleted list.

Without all of these three Person/Employee/Class, the goal is never achieved, because they do not communicate. They cannot create a computer.

Note also, that a Person/Employee/Class may be substituted with other Companies/Packages' Person/Employee/Class that may have a different Skill/Process/Method.

Sometimes, once you come back after a month or weeks of programming, some method is already forgotten, you'll have a hard time puzzling what you wrote.

So there are few things that you are going to need to consider to program efficiently with Object Oriented Programming:

  • First thing is to imagine the goal.
  • Second is to make a flow of how each object will communicate.
  • Third thing is to make sure that you understand one Skill/Process/Info/Method
  • Last is to make sure that you finish or understand one flow of steps, not just part of a flow, before forgetting it entirely.
Another Way:
Another way of looking at object oriented programming could be just as simple as methods are equivalent to functions. In PHP for instance, mysql_query() function can be similar to mysql->query() method. The only difference would be that using mysql->query() method for a different class can be extended or replaced to do something else if it does not belong to 'mysql' class anymore. Just like a flow of Skill/Process/Method can vary to every Person/Employee/Class.