Browsing the archives for the terminal tag.

Ohcount and Count Lines of code

Coding

Ohcount and Count Lines of Code (CLOC) counts size of code project. Mostly these aren’t very useful applications, but it is fun to see that I have written 300 lines of code in couple of days.

Ohcount is used Ohloh to generate source code reports. I was disappointed to found that i can’t use Ohcount to scan whole history of my repository, it only scans current status of code.

CLOC is written in Perl and Ohcount in Ruby. It maybe little annoying to compile Ohcount from source, but it is much faster than CLOC. If you want something that is easy to install, take CLOC. But if you are going to analysis more often than once, try Ohcount.

Here is example output from CLOC:


96 text files.
83 unique files.
33 files ignored.
http://cloc.sourceforge.net v 1.08 T=7.0 s (8.9 files/s, 547.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code scale 3rd gen. equiv
-------------------------------------------------------------------------------
PHP      49    588   172     1950 x 3.50    = 6825.00
SQL      1     58    87      277  x 2.29     = 634.33
BASH     10    54    133     261  x 3.81     = 994.41
CSS      1     46    5       192  x 1.00     = 192.00
Python   1     2     1       6    x 4.20       = 25.20
-------------------------------------------------------------------------------
SUM: 62 748 398 2686 x 3.23 = 8670.94
-------------------------------------------------------------------------------

And here is Ohcounts output from same file:

Examining 555 file(s)......

Ohloh Line Count Summary

Language Files Code Comment Comment % Blank Total
---------------- ----- --------- --------- --------- --------- ---------
php      58    2146 219     9.3%      716  3081
sql      1     277  87      23.9%     58   422
html     60    242  1       0.4%      38   281
css      1     192  5       2.5%      46   243
python   1     6    1       14.3%     2    9
---------------- ----- --------- --------- --------- --------- ---------
Total 121      2863 313     9.9%      860  4036

- Gestalts -------------------------------------------------------------------
Platforms: PHP, SQL, Scripting

Yep. There is some difference on results. I don’t know which one is more accurate.

I haven’t posted for a while because I have coded my main project. It isn’t public, but I will blog about it when it is ready. :) I try to blog more often.

No Comments

How to do a quick backup at console

Linux, Tutorial

So, you are coding your project and you realize that you haven’t done any backups! What is the easiest and fastest way to do backup (I don’t know about speed and difficult of this method, but it works and I like this.)

Dump your databases! (if you have any)

Mysqldump --databases dbname > dump.SQL

Then move to parent directory

cd ..

And do a tar archive

tar cvvf project.tar project/

And voilà! Local backup is ready, let’s move it to safe place in your ftp server…

ftp ftp.example.com

Use ls and cd to find right folder on your server, then move local file with:

put project.tar

Whee! Now you have backups safely on your server! It is possible to write a cron script that backups and uploads your project every hour.

No Comments

Git, simple source control system

Applications, Linux, Tutorial

If you project is bigger than 20 lines or it has over 1 user, you need source controlling system. If you are doing something very complex or you have many users it’s good to choose services like Google code or Beanstalk. (or something else)

But if you only need a source control system for your self, it’s not so clever to take remote source reporisity, because you can have your own source control system on your local machine!

Setting up svn server is much more difficult than setting up local git repository. I recommend to use git for every small local projects, because it is extremely easy to set up and it doesn’t require server to run.

So, install git (apt-get install git git-core) and then go to your projects directory and type:
Git init
Git add .

First command initializes git repository on .git folder and second command adds every file to new repository. In future when you add more files to project, just use “git add “.

Then do the first commit to get it working.

Git commit -a

Commit command opens default editor on your system. If you want to change it to another editor, add next line to your .bashrc file. (and reload bash to get it working :) )

export EDITOR=vim

Then just continue coding your project. When you want to commit more, just use previous command to do it. After you have done couple of commits you may want to see what you have done. Use “git log” to view latest commits.

When you type just “git” you will get list of sample commands that you will need later. More documentations can be found from gits website.

I recommend to try graphical git application: giggle. It makes it easier to understand branches.

Happy coding :)

No Comments

Htop

Applications, Linux

Htop is similar to top, but it has much more features than top. In my opinion, htop is the best process manager software ever.

  • Cool ASCII graphs
  • Customizable view
  • Searching of process
  • Easily send kill signal, or some other signal.
  • Process tree view
  • Mouse support!
  • Nice ncurses interface
Cool ASCII-graphs!

Cool ASCII-graphs!

No Comments