Monthly Archives: October 2013

Install WordPress in the hard way

Install LAMP (mysql, apache, php)

refresh the linux repository
apt-get update

Install apache2
apt-get install apache2
test apache2 by going to localhost:80

install php with apache2 support
apt-get install php5 libapache2-mod-php5
test php by writing info.php in /var/www/ folder.
restarting apache2 is needed.

install mysql
apt-get install mysql-server mysql-client libapache2-mod-auth-mysql php5-mysql
restarting apache2 is needed to find mysql module installed.

Install WordPress

using virtual host
locate the default file in /etc/apache2/sites-available.
copy it to a the site name “wordpress”
Change the document root to the wordpress unzipped directory.
change accordingly.
disable default and enable the created.
a2dissite default && a2ensite mysite

Continue reading

[Day 2] Get to Know Assembly

[Day 2] Get to Know Assembly

I was curious to know the relationship between Assembly (by NASM) and the generated binary.

Findings are summarized as follows, note: guidelines only, it seems not correct for one parameter takes 2 bytes at least.

  • ORG generates no binary code. Actually like labels, it is only considered at compile time.
  • One label in the operand takes 2 bytes.
  • JMP takes 1 byte, 0xeb
  • BD, DW, DD takes no bytes, but they generate space for holding 1, 2 and 4 bytes respectively
  • MOV takes no bytes, but registers AX, pointers SP etc takes 1 byte each
  • MOV AX,0; where parameter 0 take 2 bytes
  • One register (e.g AX) can hold 32 bit (for 32-bit CPU) = 4 bytes. There are 8 registers (AX, BX, CX, DX, BP, SP, SI, DI), 4 bytes x 8 = 32 bytes in total, too little storage
  • [SI] from memory takes 1 byte

“30 Days to Make Your Own OS” on Ubuntu

By far, it is the only English version of recording steps taken to follow the Japanese book.

This post serves the purpose of recording and discussion of my own progress of self-learning. The code is synchronized with my Github repository.

Day 1

———————-

Install Image on QEMU on EC2 Ubuntu

Testing images on QEMU is a common task. This section talks about how to install images on QEMU in the linux environment.

Qemu is a visualization emulator running on hosting os (ubuntu in my case). Qemu has a universal distribution with ubuntu. Type qemu- will list a batch of qemu related binaries, however qemu commend itself is not enlisted.

P.S. I tried to install from qemu official git. It ended up with configuration failures with my EC2 ubuntu.

Turing to the default qemu with Ubuntu, use qemu-system-x86_64 to replace qemu.

qemu-system-x86_64 -fda workstation/OSASK-Linux/src/helloos.img

return error

Could not access KVM kernel module: No such file or directory
failed to initialize KVM: No such file or directory
Back to tcg accelerator.
Failed to allocate 402653184 B: Cannot allocate memory
Aborted (core dumped)

There are two errors, no KVM and no enough memory.

Continue reading

Get to know the Java Best Practice

Although it should be learnt the other way around, I find it interesting to get to know some bits of enterprise best practice before I can appreciate.
It is true that I can only know the real benefit after I pay the price, but it won’t stop me from knowing those rules of thumb beforehand.

Reference:

Maven Configuration

  • Create a project pom.xml  as <packaging> pom, which is defining all the project dependencies for modules, specified in <modules/>
  • Specify all version numbers in parent’s pom file’s properties
  • Specify <dependencyManagement>, and inside <build> specify <pluginManagment>, if sub modules exist. It is used for child pom to transitively use parent pom configurations. Outside <*Management>, Sections <dependencies> or <plugins> must exist for maven to download actual jars.
  • Fix java compiler version by maven-compiler-plugin as 1.6
  • Enforce maven version between 2.2.1 to 3.1.1 by  maven-enforcer-plugin
  • Replace common-logging and log4j by slf4j, and don’t use logging utility either in the code. Q: Why is that. The reason is here.
  • Ensure no SLF4j 1.5 or 1.6 Q: Why? Since they do not work together?
  • Don’t allow spring framework 2.x and 3.0. Q: What is the difference from 3.1?
  • Add SLF4j 1.7 for Logging, and prefer logback over log4j, and enable root exception logging.  Q: Why prefer? Reason is here
  • Ensure source encoding across developing environments <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>, as well as <project.reporting.outputEncoding>UTF-8 for reporting plugins like surefire, failsafe
  • Solving maven dependency conflicts by explicitly defining in <dependencyManagement> after analyzing dependency conflicts using IntelliJ diagrams marked in red.
  • Make developer environment loaded from ./config directory instead of module’s resource folder resource folder is supposed to load more static configurations like logger configs. Since developer environment is changing more likely between individual developers, like test host url, password, or temporary data folder, these configs should be put inside config directory and make it ignored by git. Therefore, static resource is loaded by class().getClassLoader().getResourceAsStream(), while for config directory, make maven look for project.home property (by -Dproject.home=…) and put ${project.home}/config into class path before calling with getResourceAsStream(). The additional classpath can be added by surefire’s additional classpath element.
  • Pay attention to transitive conflicts if during runtime you encounter error like no such method. It is a highly chance that one lib is using a common transitive dependency with different version. Finding the bugs by looking
    mvn dependency:tree -Dverbose //with keywords google which jar has classes related to the error "no such method"

Test-Driven Design

  • Class naming: ClassNameUnderTest+Tests, i.e. EventDaoTests
  • Method naming: UnitOfWork_StateUnderTest_ExpectedBehavior; reference
  • Naming practice for Junit
  • Using Junit for unit test; examples (testNG across class dependencies is too messy for unit test)
  • @BeforeClass/@AfterClass static method for creating/releasing expensive objects, like DB connection objects.
  • @Before/@After for creating/releasing common test objects, usually private fields for test class. To ensure no dependency over test methods (each test method is running on a separate test class instance, and releasing by assigning null to objects and Garbage collector will collect them. It is not needed maybe.)
  • Declare private static final SLF4J Logger at the beginning of test class
  • Separate integration test with unit test. Referred organization of IT with original blog and useful practice. I prefer the use of systest, and in maven I need to configure surefire (rather than failsafe) with profiles (profile flags -P must be enabled when mvn verify. Details can be found in the comments of codehaus)

Design Patterns and Packaging Concepts

Code Reference

      • Integration Test Profiles
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
<excludes>
<exclude>**/systest/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>itest</id>
<activation>
<property>
<name>itest</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>surefire-it</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>none</exclude>
</excludes>
<includes>
<include>**/systest/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>