Archive

Archive for the ‘linux’ Category

Bash script to fix indentation for C++ code

28 November 2012 Leave a comment

This small scripts allows me fix the indentation of C++ source files with very little effort.

Usage:

  1. Drop one or more C++ source files in the “toindent” folder
  2. Run the script “./indenter.sh toindent” (this calls the bcpp indenter to indent all files in the ‘toindent’ folder)
  3. Done

There are some options for step 2:

  • Select one file to indent: “indent.sh file.cpp”
  • Select all files in the ‘toindent’ folder: “./indent.sh toindent/”
  • Select only files with a certain extension in a folder (e.g. “.h”):  “./indent.sh toindent h”

Download

Indentations options can be changed in the “bcpp_indenter.cfg” file.

Advertisements

Kate/KDevelop syntax highlighting style for Arduino code

16 January 2012 Leave a comment

Kate, my favorite text/code editor has no native support for Arduino code syntax highlighting.

Because Arduino code is very similar to c++ code I made some adjustments to an existing C++0x Kate highlighting style by adding some Arduino specific settings and keywords.

The colors are loosely based on the original Arduino IDE syntax highlighting style.

Code available at: Google Code

The result can be seen in the screenshot:

Kate screenshot

Build script: course handouts from latex-beamer slides

4 December 2011 1 comment

As a lecturer, a part of my job consists of giving presentations using some kind of presentation software.

In the past, I uploaded a pdf file for each presentation to the  educational learing platform we use at our university. Typically 12+ files for one semester. Because some students prefer to print out the handouts, I provided a printer friendly version (8 slides per page), instantly doubling the number of files.

During the semester, I tend to adjust/tweak/update these files from time to time, making it dreadfull for me to update the files, and making it difficult for the student to ensure they have downloaded the last version of each file.

When I switched from OpenOffice.org to Latex beamer to prepare my presentations, I also decided to resolve this annoyance and add some extra features to my handouts.

This resulted in a build script.

What is it does:

  1. Build two pdf version for each lecture: presentation version and handout version (printer friendly colors, no slide transitions)
  2. Build a 8 slides per page (8pp) version starting from the handout version
  3. Create a nice handout document by joining all the 8pp files + include title page, introduction, table of contents
  4. Create a .zip archive file with all these documents

The end result is an updated .zip archive, with the last version of all the slides.  About once a week, I do a full build and upload this one file to our learning platform.

Sample commandline output:

$ ./build
Now processing: 0-hfdst0
Latex build succesfull
PDF 8pp build succesfull
Now processing: 7-hfdst7
Latex build succesfull
PDF 8pp build succesfull
Now processing: 8-hfdst8
Latex build succesfull
PDF 8pp build succesfull
Now joining all documents
Latex build succesfull
Build took 6 seconds.
done

Sample files:

(remove ‘.doc’ from the file extension, wordpress does not allow .zip/.sh)

Automated multiple choice exam grading

6 June 2011 4 comments

I wrote a little tool for automated multiple choice exam grading.

The idea:

  1. Students receive two sheets: one questions sheet and one answer sheet
  2. They indicate their correct answer by erasing the wrong answers (letters) on the answer sheet (see scan on the right)
  3. When all students have finished their exam, the answer sheets are batch-scanned and send to some email address.
  4. The server receives this email, starts processing the scans, calculates the grades and sends out a report to the lecturer

Read more…

Backup script: encrypted, offsite, incremental backup (rsync, rdiff-backup, encfs)

17 January 2011 2 comments

In this post I will explain a small (~100 lines) backup script I use to make offsite automated backups of several computers.

Overview of the scripts’ actions

  1. Mount a local folder using encfs (the backup files are written in this folder)
  2. Do an incremental backup with the local encfs folder from step one as the destination. Using rdiff-backup with a remote location as the target sometimes resulted in failed/broken backups on systems that frequently go offline. (laptops)
  3. Send the encrypted files to an off-site server (any server with ssh access will do, I use the quite cheap datastorageunit.com servers.
  4. Send all logged events and an overview of the incremental backups over email

Read more…

BackupPC

6 January 2011 1 comment

I have recently been testing BackupPC, a high-performance, enterprise-grade system for backing up Linux, Windows and MacOSX PCs and laptops to a server’s disk.

Initial configuration is a little bit daunting, you should (must) read the documentation and the self explanatory config files…

Interesting features:

  • autonomous system: no client-side software or user interaction is needed
  • the intelligent pooling system mimizes disk usage by detecting duplicate files (+bzip2 compression)
  • very flexible configuation files

I added one small “feature” based on the following blog post by Ted Carnahan: only run backup when laptop is running on AC-power. (the following works on a Lenovo Z61m Thinkpad and can be adapted to work on any other linux system)

Add this to the config file:
<code>$Conf{RsyncClientCmd} = '$sshPath -q -x -l backuppc $hostIP grep -q on /proc/acpi/ac_adapter/AC/state && $rsyncPath $argList+';</code>

When the laptop is on AC-power, the return value for the code in bold is 0, and the backup continues. When on battery power, a non-zero return value results in an aborted backup.

Categories: linux, system administration Tags: , ,

Arch Linux & Pacman

1 November 2009 Leave a comment

A week ago I switched from Debian 5.0 to Arch Linux. The initial learning curve was not that challenging as everything is perfectly documented in the ArchWiki.

The result is a snappy new system with very up to date packages, especially compared to Debian Stable.

One thing that kept bugging we was the syntax for the “Pacman” package manager. To resolve this small issue I added some aliases to $HOME/.bashrc

alias pacup="pacman -Syu" %(system update)
alias pacin="pacman -S" %(install packages)
alias pacinfo="pacman -Si" %(show package info)
alias pacrem="pacman -Rn" %(remove package)
alias pacmirror="reflector -l 8 -r -o /etc/pacman.d/mirrorlist" %(update repository list & rank fastest mirrors)
alias pacsearch="pacman -Sl | cut -d' ' -f2 | grep " % (search package database)