Simple Regex


  1. Finditer
    reg = ‘\\s(\\w*?)=’               # word between space and =
    line = ‘<lalala=”x” lala=”y” la=”z”>’
    .for match in re.finditer(reg, line, re.S):
    .print(, end=””)
  2. Findall
    reg = ‘”(.*?)”‘                  # between ” and ”
    line = ‘<lalala=”x” lala=”y” la=”z”>’
    .ret = re.findall(reg, line)


. wildcard/any character
* repeated  more than 1
? occurrence 0 or 1

*? is used to make it lazy (match the shortest one) because there are many ” in the input string line. If ? is not used, it will match the longest possible answer (from the first ” to the last “)

Quantifier, by default: greedy
e.g. for string “123”,  regex \d+ will match 123, instead of 1
(additional note: + is for occurrence more than 1)

lazy = as few as possible = shortest match = reluctant
by adding ?
string: 123EEE
reg = \w*?E
match = 123E

*? :


Libraries in Python

Useful modules, packages, and libraries in Python. This is a list of personal preferences (previously/currently used).
Some definitions are taken from here and here.

Purpose Modules name Additional information
GUI TkInter Traditional python UI toolkit
PyQt Qt framework
PySide Qt framework

  • QtGui
  • QtCore
Foreign function interface CTypes Package for calling functions of dlls/shared libraries
[now is included w/ Py2.5 as Standard Library ]
 XML processing ElementTree [now is included w/ Py2.5 as Standard Library]
 Database sqlite3
 Operating System services os miscellaneous OS interfaces
[Standard Library]
time time access and conversions
[Standard Library]
 Text Processing services re Regular expression
[Standard Library]
Numeric & Mathematical modules  math mathematical functions
[Standard Library]
 Data types copy shallow & deep copy operations
[Standard Library]
 Structured Markup processing tools xml.dom XML processing, Document Object Model (DOM) API
[Standard Library]
xml.dom.minidom minimal DOM implementation
[Standard Library]
 Binary Data Services codecs Codec registry and base classes
[Standard Library]
 3D-rendering related pivy python binding library for Coin3D (3D-rendering library)
Read/write office files openpyxl to read/write Ecxel 2010 files
[stored in PyPackageIndex]

OOP in C++

Disarikan dari sini –> slightly rephrasing from this wonderful site (for personal purpose)
–> now that I’m half of reading it, that is just such an awesome site. Thanks NTU 🙂

  1. Why OOP?
    – to avoid re-invent the wheels
    – to make parts/components reusable
    1.1. Traditional Procedural-oriented languages
    – not reusable, because function is likely to reference the headers, global variables and other funcs.
    – not suitable of high-level abstraction
    – separate the data structures and algorithms of the software entities>> hardware faults can be isolated, but software faults could affect other programs running in computers1.2 OOP languages
    – basic unit is a class:
    >> encapsulates both the static attributes and dynamic behavior within a box
    >> specifies the public interface for using these boxes
    – well encapsulated, that it is easier to reuse the classes
    – OOP combines the data structures (in data members) and algorithms (member functions) of a software entity inside the same box
  2. OOP Basics
    2.1. Classes & Instances
    – Class: DEFINITION of objects of the same kind
    >> a blueprint/template/prototype
    >> defines & describes the static attributes and dynamic behaviors common to all objects of the same kind
    – Instance: REALIZATION of a particular item of a class
    >> an instantiation of a class
    >> all the instances of a class have similar properties (as described in the class definition)
    – object: usually instance, but can also be a class (used loosely)2.2. Class: 3-Compartment Box encapsulating Data & Functions
    -a class:
    >> classname (identifier)
    >> class members (data members + member functions)- a class can be visualized as:
    >> classname (identifier)
    >> data members/variables (attributes, states, fields) –> static attributes of the class
    >> member functions (methods, behaviors, operations) –> dynamic operations of the class

    – value of data member: class state
    – member function: class behavior

    – in UML (notation):
    >> instanceName:Classname
    >> public members, denoted with +
    >> private members, denoted with –

    naming convention:
    – class: noun or noun phrase, and initial-capitalized, meaningful & self-descriptive
    >> e.g., SoccerPlayer, FileInputStream,
    – data members (variables) noun or noun phrase, first word is lowercase, the rest are initial-capitalized
    >> e.g., fontSize, roomNumber,first word is lowercase, the rest are initial-capitalized, + parentheses
    – member functions: verb or verb phrase,
    >> e.g., printLine(), getArea()

    2.3. Creating Instances of a Class
    You need to:
    – Declare an instance identifier/name of a particular class
    – invoke a constructor to construct the instance
    >> allocate storage for the instance and initialize the variables

    Construct 3 instances of Circle, named (of the instances) c1, c2, c3, with 3 ways (either specify radius or/and color, or using the default value)

    Circle c1(1.2, "red");
    Circle c2(3.4); //using default color
    Circle c3; //using default radius and color
    Alternative: invoke the constructor explicitly
    Circle c1 = Circle(1.2, "red");
    Circle c2= Circle(3.4);
    Circle c3 =Circle();

    2.4. Dot operator to reference a member of a object
    To reference data or member function of a object, you  must:
    – using dot operator instanceName.memberName

    E.g., to invoke the getArea() function of instance c1:
    – c1.getArea()

    2.5. An OOP example
    Class diagram (class definition vs instances)


    class Circle{
    double radius;
    string color;
    Circle(double r=1.0, string c="red"){
    radius =r ;
    color =c;
    } //constructor with default values
    double getRadius(){
    return radius;

    when referring (after instantiation) in the main function
    (don’t forget to include iostream (for IO function), string (for using string), and using namespace std; )


    (and to compile using “g++ -o OutputFileName.exe SourceCode.cpp”)

    2.6. Constructor
    – to initialize all the data members
    – has no return statements
    – are not inherited

    2.7 Default Arguments for functions
    – put it in the function header
    – e.g.
    int sum(int n1, int n2, int n3=0, int n4=0, int n5=0);

    int main(){

    int sum(int n1, int n2, int n3, int n4, int n5){
    return n1+n2+n3+n4+n5;

    2.8. Information hiding an encapsulation
    – principle of information hiding
    >> object communicate w/ each other using well-defined interfaces (public functions)
    >> implementation details are hidden/encapsulated within the class
    >> this information hiding facilitates reuse of the class
    >> data member of a class are typically hidden from outside world (access control modifier: private)
    >> access to private data members are provided via public functions, getters (to read) and/or setters (to modify)


Inheritance (C++)

Reference dari sini dan sini

– allows you to create a hierarchy of classes
— generalized classes (e.g., class Animal)
— various classes of more specific nature (e.g., class Dog & class Cat) inheriting the general aspects of more generalized classes
base class vs derived class
derived classes:
>> inherent the traits that are general to parent class base class
>> but derived classes will have specific attributes

One possibility:
– starting a program with abstract idea
– then implemented by specific classes

Base class: (general class)
– contain functions that all the derived classes will need
Derived classes: (more specific class)
– inherit functions and variables from base class
a class can be both a base class or a derived class

encapsulation: the hidden nature of classes (e.g., protected & private)

Restriction keyword (level of data hiding):
1. Public (variable & function) –> the most open
– inheritable by derived class
– accessible to outside functions & code, when they are elements of a specific instance of a class
– usually to give and take information to the outside world (interface)
– a well-designed will have no public fields, everything should go through the class’s functions
– getters: functions that retrieve variables
– setters: functions that change values

2. Protected
– variables: not accessible by functions and code outside the class
– but are accessible to their derived classes
inherited but hidden from outside
– access control for important aspects to a class that must be passed on without allowing it to be accessed

3. Private -> highest level of data-hiding
– not accessible by functions and code outside the class
– not accessible to their derived classes
– if you do not wish derived classes to access a method, declare as private

Derived class, example

class Cat : public Animal
int fur_color;
void purr();
void fish();
void markTerritory();

– derived class has access to the data members (variables and functions) of a base class
– specific instance of the derived class possessing data
– two different Bear objects:
>> having the same member variables and functions
>> having DIFFERENT information stored in their variables
– if a class Animal with an object, BigAnimal
– two different Bear objects will not have access to the data within BigAnimal
– only posses variables and functions with the same name and of the same type

Class design in C++

– subclasses –> derived class

– a function should be virtual when the implementation is likely to differ from subclass to subclass

Related term:
– polymorphism

Kelas (C++)

disarikan dari sini dan sini
not yetclass design

Ide dasar kelas:
encapsulation: to make programs more modular
– the outside world doesn’t need to know exactly what data is stored inside the class
– the outside world just need to know which functions it can use to access the data
– advantage: allow the implementation to change more easily
>> because nobody have to rely on it (the detail of a class), except the class itself

>> Kelas: koleksi data, related to a single object type [house]
– include information regading real world object –> variables [items inside house]
– include functions [door] to access the data
– posses the ability to inherit from other classes

Make sure to know the difference(s) between:
– instance
– class member
– instance variable vs class variable
– instance method vs class method

Member of a class:
– data / member variable / (instance variable) / class attribute / property / field
– function / method

Other term (please check later):
– instance variable -> similar to class variable (but not the same)
– instantiated object
– instance = object?
– object instance
– invoke an object = instantiate an object/create an instance?
– copies of instance variables

need to consider sentence:
– all instances of an object have their own copies of instance variables
– one object instance can change values of its instance variables without affecting all other instances
– instance variables can be used by all methods of a class unless the method is declared as static
– a class of objects that describes a set of objects

– keyword class
– nama kelas
– open bracket {
>> degree of restrictions: either public, procted, private
— public
— protected: functions outside the class to access the variable
— private (similar to protected, but will be different, related to inheritance)
– restriction keyword, colon :
– variables
– functions (usually prototype –> why?), ended with semicolon ;
>> two basic and need functions (neither return arguments/return value):
— Constructor, className
—– to initialize variables
—– if you don’t need to perform any initialization, the compiler will create a default constructor
— Destructor, ~className
—– to clean up after the class, including freeing any memory allocated
—– if you don’t need to do anything special in the destructor, the compiler will create a default destructor

Why separate /having degree of restrictions?
>> it makes the class easier to use
– the key idea is to separate
— the interface you use
— the way the interface is supported
— the way the interface is implemented

How it works
1. Programmer declares an instance of the class
2. Constructor will be automatically called
3. Destructor is called when the class is no longer usable
>> when the instance of the class is no longer needed, e.g.:
– program ends
– class reaches the end of scope
– memory is deallocated using delete

contoh, diambil dari (diketik ulang)

using namespace std;
class Computer
void setspeed(int p);
int readspeed();

int processorspeed;


Computer::Computer() //constructor --> can accept arguments
processorspeed = 0

void Computer::setspeed(int p)

int Computer::readspeed()
return processorspeed;


int main()
Computer compute; // create an instance
// means that it assign computer.processorspeed (protected)
// calling a public func readspeed who return value from (protected) var processorspeed


  1. Decide the public interface for the class

Mengokohkan yang goyah (C++)

Beberapa konsep dasar C++ yang rasanya belum mantap:
konsep OOP in C++ –> menarik, dari spore
class design in c++
designing a program
– pointer
STL (standard template library)
const (why do we even need?)
debugger and debugging techniques
linked list, recursion, binary trees
– custom data type (enumerated types, structs)

c preprocessor:
>> directive
>> constants
>> macros

list of interesting books

Mixed up:
OOP terminology @ Python
class & instance attribute @ Python
classes (formal reference) @ Python