Tutorial: How to create and use a D package

To create a D package, you first need to have dub utility (plus D compiler, dmd). You can download pre-compiled dub binaries from here.

Creating a D package

cd ~

mkdir dlibs

cd dlibs

dub init mypack  #this will create a skeleton for your package: mypack

cd mypack

cat dub.sdl  #below is contents of your package

name "mypack"
description "A minimal D application."
copyright "Copyright © 2016, mahdix"
authors "root"
version "1.0.0"
targetType "library"

#the package will have only one source file, located inside source directory

cat source/myfile.d

int add(int x,int y) {
return x+y;

#this will compile your package

#although its not necessary but ensures that everything is allright.


Performing "debug" build using dmd for x86_64.
mypack ~master: target for configuration "library" is up to date.
Target is a library. Skipping execution.

Using a D package

To use a D package, we will create an application (which is itself a D package) and define the package we need as it’s dependency. But before that, we need to inform dub where the packages are (which is inside ~/dlibs).

dub add-path ~/dlibs

dub list #this will list all known packages to dub, which will include mypack too

Now lets create a basic project that uses the package:

cd ~

dub init project1

cd project1

cat dub.json #config file can be either sdl, they are equivalent

"name": "myproject",
"description": "A little web service of mine.",
"authors": ["Mahdi Mohammadi"],
"homepage": "http://myproject.example.com",
"license": "GPL-2.0",
"targetType": "executable",
"dependencies": {
"mypack": "*"

#as you notice, we specify "*" as version number of mypack which means: any version

cat source/test.d #this is our only source file which uses add method of mypack

import std.stdio;
import myfile;
void main() {
int x = add(1,4);
writefln("%d", x);

#now lets build project1




Performing "debug" build using dmd for x86_64.
mypack ~master: target for configuration "library" is up to date.
myproject ~master: target for configuration "application" is up to date.
To force a rebuild of up-to-date targets, run again with --force.
Running ./myproject

#5 is output of the call to add function in mypack



TIOBE Index for February 2016

Here you can view the list of programming languages by popularity.

The list of somehow suspicius for me, because there are a lot of jumps in it during past one year and none of them can be justified easily. For example Objective-C is down from 14 to 4! or Perl is up from 12 to 8! Assembly is up from 26 to 13!

These things cannot happen during one year. Maybe to measurement method is not accurate, but anyway this ranking is not accurate, I think.


How to install D compiler on Ubuntu

The problem is, on Ubuntu you cannot simply run

apt-get install dmd

to install D compiler. I hope they add it to official repositories someday but till then you can try this:

First you will need to download appropriate .deb file from D official website: link


apt-get install gdebi-core

sudo gdebi dmd_2.070.0-0_amd64.deb

Then you can compile any .d source file using

dmd file1.d

How to use vim non-interactively

If you want to use some feature of vim non-interactively, you can use `-c` command argument. This will accept a vim command and will execute it on the input file.
You can use multiple -c arguments. For example:
vim -c '%s/data/DATA/g' -c 'wq' myfile
This will replace all occurrences of `data` with `DATA` in `myfile` automatically.
Tip: You can combine this with `find` command and have an automated find-and-replace script which acts on a set of files.



How to compile Hadoop from source

Hadoop is a great (and complex) software framework with a lot of dependencies and configurations you need to make. One way to get up to speed with it is to download ready-made release binaries and just install them (You can find related links at http://hadoop.apache.org/releases.html).

But if you want to have the latest source code (and probably work on it), you will need to check them out from Apache Hadoop's git repository. Before you can run Hadoop this way, you will need to set-up your system. This setup will include:
1. Installing required OS packages (autoconf, cmake, libtool, …)
2. Installing JDK and Maven
3. Installing protocol buffers with the correct version
4. Installing Hadoop maven plugins
5. Compiling and installing Hadoop
6. Setting up password-less SSH and some environment variables

I have prepared a 'Vagrantfile' with instructions to provision the vagrant machine to do above steps. All required steps are explained in README file of the repository: https://github.com/mm-binary/hadoop-src-getting-started

Git grep tips

If you are working with terminal-based editors like vim, you will need
to search for a text pattern a lot of times. This can be required when
you want to re-factory a symbol and want to find all references to
that symbol in the code.

In order to search for a text in a git repository you can use

git grep

command. This command will search for given text
across all source files in the current repository.


git grep Keyword   #will find all lines of code which mention `Keyword`
git grep -A 3 ABCD #same as above but will include 3 lines after each match
git grep -B 3 ABCD  #display 3 lines before each match
git grep -C 3 ABCD   #display 3 lines before and 3 lines after each match
git grep --line-number ABCD #show line-number of each match too
git grep --break ABCD  #put a line break between matches for each file

I normally define this line in my ~/.bashrc file:

git config --global alias.fn    "grep --break --heading --line-number"

So you can simply write

 git fn TEXT 

and it will show a
tidy output separated file by file and will group matching in each
source file.