Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, July 16, 2009

Visualizing the Source Tree of a Project with the Command `tree'

The Unix command `tree' is nice for visualizing a project that spans multiple directories.

I use the following to get the tree structure for a MATLAB project:

tree -P "*.m" > lstree.tex

This creates a file lstree.tex with the tree structure. Then, to give it a XeLaTeX structure, prepend with the following:

 \documentclass[twocolumn]{article}
\usepackage{verbatim}
\usepackage{fullpage}
\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont[Mapping=tex-text]{Gentium}
\setmonofont[Mapping=tex-text]{Gentium}
\begin{document}
\begin{verbatim}

and append the following:

\end{verbatim}
\end{document}
 

Compile with the command xelatex.
You will need xelatex, tree and gentium packages installed for these to work.

Wednesday, July 01, 2009

Latest version of MATLAB.el for Emacs

The file in the goodies package in Debian is old, and doesn't support parfor. The latest is here: http://sourceforge.net/scm/?type=cvs&group_id=154105

Saturday, June 20, 2009

Elisp Codebook

Snippets from the emacswiki are here

Tuesday, May 12, 2009

Improve Focus-Follows-Mouse Behaviour under Emacs

Just use the file here so that focus follows the window the pointer is on.

Saturday, April 25, 2009

youtube-mp3

I have written a Python script that converts Youtube videos to mp3's using youtube-dl, ffmpeg and id3v2.

Details are on the youtube-mp3 website here

Saturday, March 14, 2009

MATLAB'da Anonim Fonksiyonlar

Az bilinen MATLAB özelliklerinden biri anonim fonksiyonlar.

Normalde betikler (script) içinde ve komut satırında fonksiyon tanımlaması yapılamaz. Bu kısıtlamanın üstesinden gelmek için anonim fonksiyonlar kullanılabilir.

Anonim fonksiyonlar sayesinde tek ifadeli fonksiyonlar oluşturabilirsiniz.

Anonim fonksiyon taslağı şu şekildedir:

fonksiyon adı = @ (giriş parametreleri) ifade; Örneğin: myfun = @(x) log(x) + x; myfun(3) Böyle bir fonksiyonu, giriş parametresi olarak fonksiyon handle'i alan fplot, quad gibi fonksiyonlarda kullanmak mümkün. Örneğin: a = 1; b = 2; c = 3; myfun = @(x) a*x.^2 + b*x + c; fplot(myfun, [-10 10]) Anonim fonksiyonlar içerisinde, üst kapsamda (betik içerisinde daha yukarıda) tanımlanmış değerleri kullanabiliriz; ancak bu değerler fonksiyon tanımlandıktan sonra değiştirilirse fonksiyona etki etmezler. Fonksiyonun yeni değerleri kullanabilmesi için bir kez daha tanımlanması gerekmektedir.

Friday, April 25, 2008

Sample Doxygen File

Doxygen is nice for creating documentation from source files. Here is a sample Doxyfile: Usage: 1. Document a file

/**
  \file
  \brief File description */
2. Document a function

/**
  \param msg Message to be encoded
  \param G Generator matrix for the (n,k) non-extended Hamming encoder
  \return Encoded matrix
  \author Ustun Ozgur
*/
3. Document a struct/class etc.

/**
  \struct Params_Chase
  \brief Structure holding all the Chase-II decoder variables
  \param alpha Extrinsic info weight
  \param beta Reliability multiplier for bits with no competing codeword available
  \param btc_iter Number of iterations
  \param s Unreliable bits
*/
4. Change the main page

/*! \mainpage Block Turbo Coder
   \section ...
*/

Sample Makefile

Some Information about Makefile's =================================
  1. Type "make" on the command line to make the project.
  2. You need to install the GNU make utility.
  3. Type "make clean" to remove object files.
  4. @ suppresses output.
  5. pkg-config automatically finds the required compiler and linker flags for developing against a library.
  6. Issue "export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/" if pkg-config can't find the libraries This directory contains *.pc files.
  7. $< : an element of the dependencies (to the right of : ) $^ : all dependencies $@ : target (to the left of : )
  8. Command prototype is : targets : prerequisites TAB command
  9. Tabs must be used for indentation; not spaces.
  10. CPPFLAGS are preprocessor flags, CFLAGS are flags for the C compiler (also to be supplied at linking time), CXXFLAGS are flags for the C++ compiler (also to be supplied at linking time)
  11. If you have a single C++ file, compile using (no need for a Makefile): g++ `pkg-config --cflags itpp` -o my_prog my_prog.cpp `pkg-config --libs itpp`
Tabs are important for Makefiles; copying-pasting the following won't work since tabs are gone in blogger. (or download it here)

CXX=@g++
CPPFLAGS=$(shell pkg-config --cflags itpp)
CXXFLAGS=-Wall
LDFLAGS=$(shell pkg-config --libs itpp)

SOURCES=  $(wildcard *.cpp) # Or manually list the source files here
OBJECT=$(SOURCES:.cpp=.o)
OBJECT_DIR=obj
OBJECTS= $(patsubst %,$(OBJECT_DIR)/%,$(OBJECT))
EXECUTABLE=../btctest

all: $(SOURCES) $(EXECUTABLE)
INSERT TAB HERE@echo Finished without errors.

$(EXECUTABLE) : $(OBJECTS)
INSERT TAB HERE @echo Linking...
INSERT TAB HERE$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@

$(OBJECT_DIR)/%.o: %.cpp
INSERT TAB HERE @echo Compiling $^
INSERT TAB HERE $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $< -o $@   dist : $(SOURCES) $(EXECUTABLE) $(OBJECTS)  INSERT TAB HEREcd ../.. && tar -cjf a.tar.bz2 btc_itpp/src/ btc_itpp/btctest btc_itpp/Makefile
.PHONY: clean
clean:
INSERT TAB HERE @echo Cleaning object files...
INSERT TAB HERE @rm -rf $(OBJECTS)


To call it from parent dir:

# This file calls the other Makefile inside the src/ 

all:
INSERT TAB HERE@$(MAKE) -C src

clean:
INSERT TAB HERE @$(MAKE) -C src clean

dist:
INSERT TAB HERE @$(MAKE) -C src dist

doc: src
INSERT TAB HERE /Applications/Doxygen.app/Contents/Resources/doxygen Doxyfile