2017년 8월 8일 화요일

Python Sample


  • Write, Append, Read of file

f = open("C:/Python/new_file.txt", 'w')
f.write("1111")
f.close()

f = open("C:/Python/new_file.txt", 'a')
f.write("2222")
f.close()

f = open("C:/Python/new_file.txt", 'r')
lines = f.readlines()
for line in lines:
    print(line)
f.close()



  • Check existing

if os.path.exists("./myfile.txt"):
    print "Exist file"
else:
    print "Not exist"

if os.path.isdir("./myfolder"):
    print "It is folder"
else:
    print "It is not folder"

if os.path.isfile("./myfile.txt"):
    print "It is file"
else:
    print "It is not file"




  • Try catch

import sys

f = None
try:
    f = open('myfile.txt')
    s = f.readline()
    i = int(s.strip())
except IOError as e:
    print "I/O error({0}): {1}".format(e.errno, e.strerror)
except ValueError:
    print "Could not convert data to an integer."
except:
    print "Unexpected error:", sys.exc_info()[0]
    raise
finally:
    if f is not None:
        f.close()






Built-in String Methods

Python includes the following built-in methods to manipulate strings −
SNMethods with Description
1
capitalize()
Capitalizes first letter of string
2
Returns a space-padded string with the original string centered to a total of width columns.
3
Counts how many times str occurs in string or in a substring of string if starting index beg and ending index end are given.
4
Decodes the string using the codec registered for encoding. encoding defaults to the default string encoding.
5
Returns encoded string version of string; on error, default is to raise a ValueError unless errors is given with 'ignore' or 'replace'.
6
endswith(suffix, beg=0, end=len(string))
Determines if string or a substring of string (if starting index beg and ending index end are given) ends with suffix; returns true if so and false otherwise.
7
Expands tabs in string to multiple spaces; defaults to 8 spaces per tab if tabsize not provided.
8
Determine if str occurs in string or in a substring of string if starting index beg and ending index end are given returns index if found and -1 otherwise.
9
Same as find(), but raises an exception if str not found.
10
Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.
11
Returns true if string has at least 1 character and all characters are alphabetic and false otherwise.
12
Returns true if string contains only digits and false otherwise.
13
Returns true if string has at least 1 cased character and all cased characters are in lowercase and false otherwise.
14
Returns true if a unicode string contains only numeric characters and false otherwise.
15
Returns true if string contains only whitespace characters and false otherwise.
16
Returns true if string is properly "titlecased" and false otherwise.
17
Returns true if string has at least one cased character and all cased characters are in uppercase and false otherwise.
18
Merges (concatenates) the string representations of elements in sequence seq into a string, with separator string.
19
Returns the length of the string
20
Returns a space-padded string with the original string left-justified to a total of width columns.
21
Converts all uppercase letters in string to lowercase.
22
Removes all leading whitespace in string.
23
Returns a translation table to be used in translate function.
24
Returns the max alphabetical character from the string str.
25
Returns the min alphabetical character from the string str.
26
Replaces all occurrences of old in string with new or at most max occurrences if max given.
27
Same as find(), but search backwards in string.
28
Same as index(), but search backwards in string.
29
Returns a space-padded string with the original string right-justified to a total of width columns.
30
Removes all trailing whitespace of string.
31
Splits string according to delimiter str (space if not provided) and returns list of substrings; split into at most num substrings if given.
32
Splits string at all (or num) NEWLINEs and returns a list of each line with NEWLINEs removed.
33
Determines if string or a substring of string (if starting index beg and ending index end are given) starts with substring str; returns true if so and false otherwise.
34
Performs both lstrip() and rstrip() on string
35
Inverts case for all letters in string.
36
Returns "titlecased" version of string, that is, all words begin with uppercase and the rest are lowercase.
37
Translates string according to translation table str(256 chars), removing those in the del string.
38
Converts lowercase letters in string to uppercase.
39
Returns original string leftpadded with zeros to a total of width characters; intended for numbers, zfill() retains any sign given (less one zero).
40
Returns true if a unicode string contains only decimal characters and false otherwise.


String Formatting Operator

One of Python's coolest features is the string format operator %. This operator is unique to strings and makes up for the pack of having functions from C's printf() family. Following is a simple example −
#!/usr/bin/python

print "My name is %s and weight is %d kg!" % ('Zara', 21) 
When the above code is executed, it produces the following result −
My name is Zara and weight is 21 kg!
Here is the list of complete set of symbols which can be used along with % −
Format SymbolConversion
%ccharacter
%sstring conversion via str() prior to formatting
%isigned decimal integer
%dsigned decimal integer
%uunsigned decimal integer
%ooctal integer
%xhexadecimal integer (lowercase letters)
%Xhexadecimal integer (UPPERcase letters)
%eexponential notation (with lowercase 'e')
%Eexponential notation (with UPPERcase 'E')
%ffloating point real number
%gthe shorter of %f and %e
%Gthe shorter of %f and %E
Other supported symbols and functionality are listed in the following table −
SymbolFunctionality
*argument specifies width or precision
-left justification
+display the sign
<sp>leave a blank space before a positive number
#add the octal leading zero ( '0' ) or hexadecimal leading '0x' or '0X', depending on whether 'x' or 'X' were used.
0pad from left with zeros (instead of spaces)
%'%%' leaves you with a single literal '%'
(var)mapping variable (dictionary arguments)
m.n.m is the minimum total width and n is the number of digits to display after the decimal point (if appl.)




Bash Shell Sample


  • Read File

while read line; do
    echo "${line}"
done < test.txt




  • Make list by separating character

for line in `echo "12;34" | tr ";" " "`
do
    echo "${line}"
done

12
34



  • Compare string type

# = : equal
if [ "$a" = "$b" ]; then
    echo "A is equal B"
else
    echo "A is not equal B"
fi

# == : equal
if [ "$a" == "$b" ]; then
    echo "A is equal B"
else
    echo "A is not equal B"
fi

# != : not equal
if [ "$a" != "$b" ]; then
    echo "A is not equal B"
else
    echo "A is equal B"
fi

# < : less
if [[ "$a" < "$b" ]]; then
    echo "A is less than B"
else
    echo "A is greater than B"
fi

if [ "$a" \< "$b" ]; then
    echo "A is less than B"
else
    echo "A is greater than B"
fi

# > : greater
if [[ "$a" > "$b" ]]; then
    echo "A is greater than B"
else
    echo "A is less than B"
fi

if [ "$a" \> "$b" ]; then
    echo "A is greater than B"
else
    echo "A is less than B"
fi


# -z : null
if [ -z "$a" ]; then
    echo "A is null"
else
    echo "A is not null"
fi

# -n : not null
if [ -z "$a" ]; then
    echo "A is not null"
else
    echo "A is null"
fi



  • Compare integer type

# -eq : equal
if [ "$a" -eq "$b" ]; then
    echo "A is equal B"
else
    echo "A is not equal B"
fi

# -ne : not equal
if [ "$a" -ne "$b" ]; then
    echo "A is not equal B"
else
    echo "A is equal B"
fi

# -gt : greater
if ["$a" -gt "$b" ]; then
    echo "A is greater than B"
else
    echo "A is less than B"
fi

# -ge : greater equal
if [ "$a" -ge "$b" ]; then
    echo "A is greater equal than B"
else
    echo "A is less than B"
fi

# -lt : less
if [ "$a" -lt "$b" ]; then
    echo "A is less than B"
else
    echo "A is greater than B"
fi

# -le : less equal
if [ "$a" -le "$b" ]; then
    echo "A is less equal than B"
else
    echo "A is greater than B"
fi

# > : greater
if (( "$a" > "$b" )); then
    echo "A is greater than B"
else
    echo "A is less than B"
fi

# >= : greater equal
if (( "$a" >= "$b" )); then
    echo "A is greater equal than B"
else
    echo "A is less than B"
fi

# < : less
if (( "$a" < "$b" )); then
    echo "A is less than B"
else
    echo "A is greater than B"
fi

# <= : less equal
if (( "$a" <= "$b" )); then
    echo "A is less equal than B"
else
    echo "A is greater than B"
fi



  • Compare float type

$> echo "76.0 < 9.5" | bc
0

$> echo "76.0 > 9.5" | bc
1

$> echo "76.0 >= 91.5" | bc
0

$> echo "76.0 <= 91.5" | bc
1

$> echo "76 > 91.5" | bc
0

$> echo "76 < 91.5" | bc
1

$> echo "76 > 91" | bc
0

$> echo "76 < 91" | bc
1

$> echo "76.0 > 91" | bc
0

$> echo "76.0 < 91" | bc
1


if [[ `echo "76.0 > 9.5" | bc` == 1 ]]; then
    echo "76.0 is greater than 9.5"
else
    echo "76.0 is less than 9.5"
fi

if [[ `echo "76.0 < 91.5" | bc` == 1 ]]; then
    echo "76.0 is less than 91.5"
else
    echo "76.0 is greater than 91.5"
fi



  • Find string in any file

$> grep -r "abcabc" ./*
./views/Picture/Picture.js:             dispatch(abcabcPath(path));



2017년 6월 5일 월요일

Technology enabling CNA

In the previous article (What is cloud native applications?), I learned about the necessity and characteristics of CNA (Cloud Native Application).

This time, let's look at the technology to enable such a CNA.
To implement a CNA, you need six technologies as shown in the figure below.





  • Microservices

As you can see from the name, it is a function to divide into functions and to develop the service.
This structure is called the Micro Service Architecture (MSA).
The opposite of the MSA is the Monolithic Architecture.


The monolithic architecture is to make all the features a bunch.
So if you develop a monolithic architecture, you can guarantee optimal efficiency, but problems arising from one function will affect the entire system.
For this reason, it is a structure suitable for a simple structure application, but it is a structure which degrades stability for an application having a complicated function.
On the other hand, the MSA separates services by function, preventing errors in one service from affecting other services.
Instead, the amount of data communication between each service is increased, so that more resources are consumed and additional code development is required to match the consistency of the shared data.


12-Factors App
The 12-Factors App definition is defined in the header of the 12factor.net site.

In the modern era, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps that: 
Use declarative formats for setup automation, to minimize time and cost for new developers joining the project;
Have a clean contract with the underlying operating system, offering maximum portability between execution environments;
Are suitable for deployment on modern cloud platforms, obviating the need for servers and systems administration;
Minimize divergence between development and production, enabling continuous deployment for maximum agility;
And can scale up without significant changes to tooling, architecture, or development practices.


For more information on the 12 Factors, please visit the 12factor.net site.


  • Multi-tenancy

Multi-tenancy is an architecture with multiple users (tenant).
If you compare it to a house, it is an apartment.



We are already accustomed to this kind of service environment.
For example, let's look at the webmail service.
The webmail service is a web application, but several users are using it in their own environment.
Their mail boxes can not be separated and can not be viewed by others. You can also use your own personalized UI by creating your own screens or mailboxes.
As described above, the storage space and the setting contents are managed independently for each user in one service.
The advantage of this architecture is that it can save money because one system is shared by multiple users.
It is also advantageous that data integration is easy because it has a schema internally that looks different from user to user.
However, in order to show different users, it is necessary to develop the service precisely, and there is also a disadvantage that if a bug occurs, it can affect the entire system.
In addition, data is integrated and managed, making it vulnerable to security.


  • Container

Container technology is compared with virtualization technology.
These two seemingly similar sides are always comparable.
But strictly speaking, container technology and virtualization technology are completely different.



Virtualization technology is virtualization of the entire OS, and container technology isolates the environment on the OS.
So, container technology is no booting process during instance creation, and it is fast because it shares OS resources.
Container technology keeps each operating environment in a container and isolates them from each other.
It is a built-in feature of Linux, and it is a technology that will support future Windows operating systems.


  • API

API (Application Programming Interface) is an interface technology between programs.
A UI (User Interface) is required for one program to communicate with a user.
Similarly, APIs are required for different applications to interact.
The API has a structure for requesting and responding to a service in accordance with previously promised rules.
In recent years, REST APIs have been mainly developed and data types are being developed mainly using JSON format.



The initial API was defined as a packet, and the data was developed as a binary.
The packet type API is defined by the developer as a packet structure.
Therefore, the structure of the packet is all different, so much learning was needed for the API usage.
Also, since the data format is binary, the contents can not be known without the packet definition document.
So, Simple Object Access Protocol (SOAP) has emerged.
SOAP was introduced to standardize packet types, and it was able to serialize and transmit objects.
This means that it is possible to represent hierarchical data that was difficult to generate in a packet-type protocol.
Distributing WSDL that defines SOAP in XML format also makes protocol sharing much easier.
However, there are disadvantages of data corruption when interworking with other languages, which requires much effort to be developed.
The REST API was easy to integrate regardless of the platform, development language, or device type using the Web protocol, and the readability of the data was enhanced by using the JSON format.
The JSON format provides a compact size compared to XML and is the most recently developed API type.


  • PaaS

CNA is an application for the SaaS model. So it works on the foundation of PaaS technology.
For more information on PaaS, see "What is cloud computing?".

2017년 6월 2일 금요일

What is cloud native application?

In the previous article, I understood the concept of cloud computing.

Then there will be some questions.
Cloud computing will evolve as a SaaS model. But is that easy?
It has evolved from IaaS to PaaS through virtualization technology.
So, what other skills do you need to develop from PaaS to SaaS?

To solve these questions, you first need to understand the Cloud Native Application.

The figure below shows the type of application and the stage of development.




  • Native Application

With the introduction of personal computers, all programs had to run on a PC.
So the applications that were initially created were packaged and distributed to fit the PC environment.
Therefore, the same application is classified as Linux for Window.
In addition, the same Window application was packaged and distributed differently to Window7, Window10, and so on.
The application that was packaged and deployed is Native Application.


  • Web Application

Web applications appeared in the PC environment with the introduction of the Internet.
The web application is installed and running on a remote server,
PC is a type of service provided from server through internet.
Therefore, it was not necessary to distribute the application according to the environment of the PC.
And upgrading the application was easy.
However, there is a disadvantage in that it can not be used when the Internet can not be used and the execution speed becomes slow when the Internet speed is slow.
The application user receives the service of the server unilaterally.
It is more passive than Native Application.


  • Cloud Native Application

Cloud Native Application is the emerging form of cloud computing environment.
Cloud-native applications are applications that run in the SaaS model environment.
So it is similar to web application in that it is served over the Internet.
However, Cloud Native Application can be installed by users themselves.
You can also control the service.



You can see that the three types of applications above have emerged around the world in almost every 20 years.
It is understandable that the current process is changing from web application to CNA (Cloud Native Applcation).

The current business environment has increased uncertainty.
To drive business success in this uncertain environment, applications must also meet the following requirements:




  • Speed

I think the quickest way to overcome business uncertainty is to deploy and recall services.
In addition, damage due to incorrect distribution can be minimized by immediate release of the new version.


  • Safety

A failure occurring in one service should not be transferred to another service.
Also, faults must be quickly restored.
So users should not be aware of the failure.


  • Scalability

Do not waste resources by overestimating service usage.
Also, quality of service should not be made with poor usage prediction.
To this end, it should be possible to expand the service horizontally.
It should also be able to dynamically apply this.


  • Diversity

Users should be provided with access to various channels.
As many users as possible should be given service opportunities.



Let's see what characteristics a CNA should have to have the elements for such a business success.




  • Services

Each service is loosely coupled to one another and is run and managed through the Web API.


  • Handling Failures

You should be able to control if a failure occurs.


  • Horizontal Scalability

It should be designed to be horizontally expandable.


  • Asynchronous Processing

Service requests must be processed asynchronously, and queues must be used to separate functions.


  • Stateless Model

All data must be separate from the application code and be available to multiple users at the same time.


  • Minimize Human Intervention

Rapid and repetitive deployment (Deploy) requires minimal user intervention.
If a fault occurs, the fault must be detected.
You should be able to remove the lost instance and quickly create a new instance.





2017년 5월 30일 화요일

What is cloud computing?

What is cloud computing?

Refers to providing a computing environment such as file repositories, databases, virtual servers, networks, and software via the Internet.
In other words, it can be thought that it is collectively referred to as all the functions that the personal computer, including the server, can have or serve through the Internet.

To service everything on the Internet, cloud computing should have the following characteristics.



  • Broad network access
Various user devices must be able to access the service through the Internet.

  • On-demand and Self-service
Resources such as servers, networks, and storage must be available at the request of the user at all times and must be user-controllable.

  • Resource pooling
The entire resource provided must be shared and reused by multiple users, and instead each user domain must remain independent until the resource is returned.
To do this, virtualization and multi-tenant must be implemented.

  • Rapid elasticity
The resources provided should be supplied with rapid elasticity.

  • Measured service
The user's service usage should be measured quantitatively and delivered to the user.



Cloud computing having the above characteristics can be classified as follows according to the service range.

Source : https://blogs.msdn.microsoft.com/eva/?p=1383

  • Packaged Software
With the advent of personal computers, a model has emerged in which individuals manage their own resources, from hardware to software.
The software was packaged, and users had to install the packaged software on their computers before they could use it.
Moreover, in order to access the internet, I had to apply for Internet service to the telecommunication service provider, and if the storage capacity was insufficient, I had to do all the work to increase the capacity of the hard disk (HDD).
The user was a model that had to be professional at the computer.


  • IaaS(Infrastructure as a Service)
The IaaS model of cloud computing is a model in which the infrastructure resources are provided as services and only the rest are managed by the user.
Therefore, the user does not directly select an Internet service provider or increase the capacity of a hard disk (HDD), but is provided as a service.
The user's task is to determine the speed of the Internet and the capacity of the hard disk to self-service and pay for it.
Early cloud computing developed services with the IaaS model.
At present, EC2 and S3 from Amazon (AWS), Azure and IBM from Microsoft both provide services for the IaaS model.


  • PaaS(Platform as a Service)
The PaaS model extends beyond the IaaS model to O / S and middleware as a service.
The user can receive not only the hardware resource (H / W Resource) but also the O / S and the middleware running on the O / S as a service request.
Ultimately, the user is only concerned with application development and data management.
Currently, cloud computing is expanding its IaaS model service to PaaS.
Amazon (AWS), the cloud computing leader, and Microsoft's Azure all offer PaaS model services.


  • SaaS(Software as a Service)
The SaaS model extends the scope of the PaaS model to provide both application and data management services.
The user's task is to develop a business model and select the services corresponding to the business model.
Current cloud computing providers are not yet fully supporting the SaaS model.



From the local computing age to the cloud computing age, the world is changing rapidly.
Cloud computing is also rapidly evolving from IaaS to PaaS.
Cloud computing will soon evolve in SaaS in PaaS.

2017년 5월 29일 월요일

Game story of the Jumping Frog

I would like to try to make a story about the birth of the Jumping Frog game because I would like to help some people who want to make the game a hobby like myself.

I am currently a software development freelancer.
I am currently working on testing related development, and I have 18 years of experience!

This is the first time when I started making games in 2013.
I used the Opensource game engine that supports Cross-Platform libGDX (https://libgdx.badlogicgames.com/).
It was remembered that it was developed with 0.9.3 version at the time, but today I check it and release until 1.9.6.



The main reason I chose libGDX was because it supports Cross-Platform, so I was able to test it in Windows environment while developing.
I do not need to use the slow emulator of Android.
I remember that I was very impressed with the way Android runs in a Windows environment without any work.


Then, in March 2015, I received an article saying that Unity (https://unity3d.com) was provided free of charge.



I started studying Unity at the end of 2015 and made my first game in June of 2016.


  • First game: Follow Me

This is an arcade side-scrolling game.
The operation method should adjust the Leader bird by touching the button.
The goal of the game is to fly as many birds as possible to their destination.



This game failed to launch.
It was a game that I made while learning so the touch sense control failed. 
Also, the effect was not gorgeous, so I could not give the game a fun factor.
However, it means that I have tried to improve the understanding of Unity engine and the game with the feeling of ink painting.



  • Launch "Jumping Frog - Leaf Cleaner" to Android
The Jumping Frog (https://play.google.com/store/apps/details?id=com.kimssoft.jumpingfrog) is a puzzle game using a brush stroke.
The goal of the game is to get the frog to the destination with all the leaves removed.



As the genre of the game is a puzzle, I am not expected that it would be downloaded to many users.
Nonetheless, the reason I chose the puzzle genre was in character design.
I was so hard and time consuming to draw a picture.



So what I thought was a tile-based puzzle game.
The tile-based puzzle game only seems to be able to reuse tiles on all stages after only a few types of tiles.
Fortunately, the forecast was right, and the time spent on the picture was reduced a lot.
But a few downloads.



Of the 250 downloads currently available, 50 are acquaintances and the remaining 200 are paid advertisers.
Eventually, the number of downloads of the first game was disappointing.

If I am looking for meaning, it is my first release and I have created all the features that I want to create.
I used Unity's IAP library to add items to the item purchase function, and also included video ads using Unity Ads.
Admob ads were also attached for banner and full screen ads.
I also released both free and paid games.






  • Second launch "Jumping Frog - Dark River" to Android

The goal of the game is to avoid the obstacles (Tornado) in the dark river and reach the target point.



From "Jumping Frog - Dark River", I began to add a subtitle to the game.
The original title of "Jumping Frog - Leaf Cleaner" was just "Jumping Frog".
The second game was based on the theme of a frog, so I added a subtitle.
So I added a sub-title "Leaf Cleaner" to the first game.

You would have expected.
I was so hard to paint again that I had to find a way to recycle the design of the first game.
And I decided to make a second game with the idea of making a game with the Jumping Frog series.



The "Dark River" was better than the "Leaf Cleaner".
Within a few days of starting the ad, the number of downloads reached 450.
Download Country Rankings is Iraq -> Mongolia -> Bangladesh.



The "Dark River" and "Leaf Cleaner" spent $ 50 each on advertising campaigns on Google Play.
The "Dark River" then had twice as many downloads as the "Leaf Cleaner".
I do not know why the "Dark River" has twice as many downloads recorded.
However, I guess the game icon seems to be more obvious.



I am currently preparing for the Jumping Frog 3 and this time I am trying to make a game out of the puzzle genre.