Category Archives: Software Development

Anything to do with developing Apps, Desktop application, server application, API etc.

Project/CMS Development Workflow

Lately I been pondering about CMS development since I work alone on projects. It didnt matter but then what if I dont work alone? What if we use WP or Drupal on our website. I read a lot of articles how it can be done.

I keep getting swept away about this article and how they are doing it. Then I realised , well I am already learning Docker/Vagrant. But its just fixing one issue anyways. Here I most of the issue encounters when developing a project be it a CMS or a stand alone one.

  • Setting up development-server ENV. This includes the server, this is where Docker comes in.
  • Setting up development set-up , the stacks you use for your project SPA, a plugin for CMS, theme , etc. (try to include unit testing)
  • Database migration set up. You cant just develop a database driven project without thinking how you can easily migrate your database schema, required data , etc. It is as important as your main application itself.
  • Using version control. You also have to think what files needs to be included to your repository. If its a public repo and your project is a public facing site, you might want to have .gitignore and exclude config files and other folders like node_modules etc.
  • Above has although bullet-ed does not mean straight forward. There is a lot of separation that needs to be done to make your workflow manageable and understandable for you(or your team).
  • Deployment. And high overview how its going to work after we set up the development side. We DEVELOP -> PUSH TO GIT -> AUTOMATION SERVER (eg. Jenkins) -> FEEDBACK TO DEVELOPER(testing etc) -> CREATE IMAGE FROM DOCKER -> DEPLOY TO PRODUCTION (CLOUD)
  • There is a lot in deployment , I mean a LOT of moving parts. But in the end, you do it often and hopefully like driving it becomes second nature until another NEW KID in town comes along. Such life for us Technologizt.

Learning Python: Gunicorn

Just putting this on here little quick.

What is Gunicorn? Apparently its sort of like a middle man between your user and application. Python is good and all handling request but its not made to be a web server handling 1000s or more of requests. For eg. Flask application can handle several request at ones locally. Web servers are good with that.

So the workflow pretty much like this:

[USER] -> [LOAD BALANCER (eg. nginx) ] -> [WEB SERVER LIKE (GUNICORN) ] -> [FLASK APP]

Very intuitive indeed!

Learning Python: Arguments, *args and **kwargs and Decorators

While reading through python. I came across some python only terms. And a very odd syntax using * and **.  And then there is this @ symbol called decorator.

Positional and Keyword Arguments 

Lets start with positional argument. This is pertaining to how a normal function with arguments is define.

# POSITIONAL ARGUMENT (conventional)
def myfunc(a,b,c):
   print a + b + c
myfunc(1,2,3)
# Output: 123
""" 
In this example a normal function is called , with their argument in order of a ,b ,c. This is positional and very common in any programming languages.
""" 
# KEYWORD ARGUMENT
def myfunc(a,b,c)
  print a + b + c
myfunc(c=3,b=2,c=1)
# Output: 123
"""
In this example same function definition, but the arguments are reflecting the argument names in the function thus the same output regardless of order.
"""

*args and **kwargs (unpacking)

Now lets look at *args, in other programming languages we can have optional arguments like in C# eg. main(string[] arg) or C++ main(int argc, char [] *argv) or main(int argc ,char ** argv).

So its basically similar with python see below:

def myfunc(*argv)
  argc = len(argv)
  for x in argv:
    print (x)
myfunc(1,2,3)
# output: 
1
2
3

** args is a bit similar above. It lets the caller specify the name of the argument. Confused? See below

def myfunc(**kwargs)
  print (a + b + c)
myfunc(a=1,b=2,c=3)
# Output: 123
# See what happens there? another way to access is
def myfunc(**kwargs)
  for key in kwargs:
    print (kwargs[key])
myfunc(a=1,b=2,c=3)
# Output: 
1
2
3
# You can also use to unpack collections and provide to the function
# using *args for a list or tuple
def myfunc(arg1, arg2, arg3):
  print (arg1 + arg2 + arg3)
mytup = (1,2,3)
myfunc(*mytup)
# Output: 123
# using **args for dictionary
def myfunc(**args):
  print (arg1 + arg2 + arg3)
mydict = {"arg1":1, "arg2":2, "arg3":3 }
myfunc(**mydict)
# Output: 123

@ Decorators

We will start with an example first below as this is the best way to explain it.

def mydecor(another_func):
    print ("Im in first")
    another_func()
    print ("Im in last")
@mydecor
def thisfunc():
    print ("I am in the middle")
thisfunc # Note: Do not call it like this thisfunc() check this for information:
https://www.thecodeship.com/patterns/guide-to-python-function-decorators/
# Output:
Im in first
Im am in the middle
Im in last

Learning Python: List, Tuple, Dictionary and Set

Taken from w3schools.com. These are collections in Python

  • List is a collection which is ordered and changeable. Allows duplicate members.
  • Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
  • Set is a collection which is unordered and unindexed. No duplicate members.
  • Dictionary is a collection which is unordered, changeable and indexed. No duplicate members.
a_list = ["I","am","list"] # a_list[0]
for x in a_list:
   print x
-----------
a_tuple= ("I","am","tuple") # a_tuple[0]
// Loop save as above
-----------
a_set  = {"I" , "am" , "set"} # to access you need to iterate through it eg. get_i = next(iter(a_set))
for x in a_set:
   print x
-----------
a_dict = {"say":"I am", "respond": "dict"}  # a_dict["say"]
for name, value in a_dict.items():
   print(name + ' says ' + str(value))

This is a quick overview how to use these array like objects. I know this is very basic but since in the real world development we will most likely use one of these collections.

Learning with Python: Class Object, Inheritance and Comments

I’m going to start learning python as a side hobby. So with all upcoming python related topics will have the title “learning”. Anyways the syntax of python is fairly straight forward but there are some of those bits that is not “fairly” straight forward. Like declaring a class object.

In python  depending on the version , there is an old style class and new style class. Old style don’t have inheritance but new style do.

# old style
class myClass():
  pass
# new style
class myClass2(Object) # all class inherits Object
  pass
# inheritance
class myClass3(myClass, myClass2)
  pass

The new style class in here has “Object” as base class. All class inherits from Object.

Thats it for class.

By the way comments in python is # and multi-line comments is a little weird but like this

# One line comment
"""
 Im a multi-line comment, and please dont indent this block as it becomes an error.
"""

YAML

Meet Uncle Yammy, or Yamel or Yamil?

I been using JSON and XML as my standard go to objects for as long as I can remember. They are both very capable. But I think I need to give YAML a try too as its good for storing very simple to very complex representation of your data.

The syntax? [ my_yaml.yml ]

PROPERTY_NAME: VALUE

Thats it. Yaml is also structured with indentation. Its actually pretty straight forward. Theres also parsers available already to use yml type files.

Please see video below by Giraffe Academy for more syntax specification

Programmer Code Guidelines

Been reading lots lately and never actually put into writing how I write my code. First thing first, variety of things and habits what you should keep in the back of mind.

Functions and Methods I’ve been writing functions and methods and never in my mind try to stop between the difference. Here is what I’ve learn about functions

  • Functions should be stateless and only cares about the argument being passed.  Can return a value or just do any work. Mostly use for utility helpers.
  • Methods are usually part of an object. When methods are called it should change a state or depends on the state the object belongs to.

Arguments pass as Copy or Reference When passing an argument to a method or function, should we consider passing a value or a reference? Passing a value means creating a copy of the argument that can increase memory usage, passing a reference avoid this. This is basically useful when passing a resource reference value.

Modularity Write codes in a modular way, this decreases headaches of debugging later on. Making it modular allows for add ons and modules to be added later on. Modularity is separation of functions and logic  in your code. If you can have separate files for each function is ideal.

Naming Convention make sure to adhere to a convention in declaring functions , objects and variables. I have decided to use this convention for general programming, although different conventions works for different  languages. For C# and windows related code, function name starts with capital letter. And private property starts with “_” underscore. For other things I use, “_” underscore for variables and camel casing for functions. Classes starts with capital letter.

Understanding Sorting Algorithm

I was once asked years ago if I know any sorting algorithm and I terribly failed to answer. As a self taught coder I never encounter having to sort records manually. Because most programming languages have a function already built-in to do this ‘sort’ of thing (pun intended).

So what is it? You my future self should already know the gist of it. Its basically a way to sort set of records based on from lowest or highest to lowest. There are bunch of sorting algorithm listed in this below link:

Different types of sorting algorithms

The most common one is Bubble sorting, you take the first value in the collection or array and compare to the second, if second value is lower, you swap the second to the first. Then we take the second value and compare to the third. Every swap you flip a flag that a swap has happen. You just keep repeating until the swap flag remain false and then everything should be sorted.

For more detailed videos of known sorting algorithm whenever you need it below are full explanations.

Algorithms Playlist