Posts filed under 'Tools'

Customize syntax highlighting for CUDA in Kate/KDevelop

CUDA is a minimal extension of C/C++ to support programming on newer NVIDIA GPUs. It introduces dozens of new keywords that are frequently used in CUDA programs. Adding syntax highlighting in KDevelop (Kate) only requires several simple steps:

1. Get keywords from “usertype.dat” provided by any Windows version of CUDA SDK, this is a text file. It should be found under $(NVIDIA_CUDA_SDK)\doc\syntax_highlighting.

2. Under your Linux account, cd ~/.kde/share/apps/katepart/syntax/, there should be two xml files regarding C/C++, cpp.xml and c.xml. Make a copy of both and name them properly, e.g. cpp_cuda.xml & c_cuda.xml.

3. Perform a replace operation on each keyword in “usertype.dat” so they match the keyword format in target xml files, and then copy them into the keyword lists of target files.

4. Modify xml header, which includes language description, file extensions and other information. You probably want to add “*.cu” to the file extension list. Remember to distinguish them from the original C/C++ language tag. Save the xml files after you are done.

5. Open Kate/KDevelop, under Tools->Highlighting->Sources you should see two new entries below C++ and C, respectively.

Enjoy.

3 comments June 6, 2008

Cygwin group/passwd setting

In case anything goes wrong with user accounts, carry on the following steps:

mkpasswd -l -c > /etc/passwd

mkgroup -l -c > /etc/group

mkpasswd -d -u <username> /etc/passwd (optional)

mkgroup -d | grep <username> /etc/group (optional)

1 comment February 17, 2008

More LaTeX Templates

%preamble
\RequirePackage[config]{subfig}

%%%%%%%%%%%%%%%%%figure-Title%%%%%%%%%%%%%%%%
\begin{figure}[hbtp]
\centering
\subfloat{\includegraphics[width=.48\textwidth]{subfig-1}}
\subfloat{\includegraphics[width=.48\textwidth]{subfig-2}}
\caption{Foobar}
\label{fig:foobar}
\end{figure}
%%%%%%%%%%%%End of figure-Title%%%%%%%%%%%%%%

 (to be continued…)

1 comment September 4, 2007

Dah… Get rid of the annoying database lock

There have been several times that I had to kill the package management program while it was not through yet. In this case the lock of the database could not be removed correctly and further access to it is prohibited.

The problem is simple, but annoying. Plus, it is common especially when you have a fragile access to internet. So here is the solution when someone tells you ‘database is locked’ in ubuntu/debian linux using apt to manage packages.

Here it is, quoted from https://answers.launchpad.net/ubuntu/+ticket/2231

Use this command from konsole:
 $ sudo fuser -vki /var/lib/dpkg/lock
This will ask you if you want to kill the process using the file.
Now you can run:
 $ sudo dpkg –configure -a
 to make sure all packages are fully installed.

Add comment March 12, 2007

Notes on beep media player plugins

Introduction

There are several articles around discussing how to add support for several popular audio format (e.g., .wma, .ape) to beep media player. Original posts can be viewed at  wma Howto and ape/wma Howto (in Chinese).

A full list of plugins can be traced at the plugin wiki page. Among them, a less known but appealing plugin (to me) is headphone plugin. Finally the uncomfortable feeling of sounds echoing in my head has gone when this plugin takes effect :)

Below is a summary of plugins I have installed.

Adding MAC (.ape) support

  1. Download required MAC non-Windows port and bmp-mac plugin from sourceforge
  2. Install libraries and development tools for compiling: run ’sudo apt-get install XXX’ and replace XXX with the following packages (follow dependencies and ignore installed packages):
    • beep-media-player beep-media-player-dev
    • build-essential gcc make
    • libgtk2.0-dev yasm
  3.  ./configure –enable-assembly
  4. make
  5. sudo make install
  6. ./configure –enable-local=yes
  7. make
  8. sudo make install

DONE

Adding wma support

  1. Download source package
  2. if there is no gcc-3.3/3.4 installed, run ’sudo apt-get install gcc-3.3′ (or 3.4)
  3. run ‘export CC=gcc-3.3′ (or 3.4, 4.0 will NOT work for this plugin) 
  4. run ‘tar -xzf bmp-wma-0.1.1.tar.gz’
  5. run ‘cd bmp-wma-0.1.1′
  6. run ‘./configure’
  7. run ‘make’ then ’sudo make install’

DONE

Simulate Speaker sound stage on headphone

  1. Download bmp-headphone plugin
  2. run ‘tar -xzf bmp-headphone-0.3.tar.gz’
  3. run ‘cd bmp-headphone-0.3′
  4. run ‘make’ then ‘make install’
  5. run ‘libtool –finish /usr/lib/bmp/Effect’

DONE

Add comment October 18, 2006

Nice Feature of Konqueror

Occasionally, I found a nice feature of Konqueror, which further frees me from mouse browsing.

When you open a webpage in konqueror, pressing ctrl (either left or right) will give you a list of shortcut for all links on that page, so you can follow any of them by entering the character/number appearing at the link location. In a framed webpage, it will capture links in the current frame, so switch focus using tab to your desired region first.

Add comment June 14, 2006

How to recover from a dpkg disaster

I am a newbie about linux and encounter trouble in almost every software I try tune. In the last month dpkg crashed twice on my Ubuntu Dapper LTS. After some apt-get upgrade command and normal downloading process, the installation ended up with such an error message:

dpkg: can’t mmap package info file `/var/lib/dpkg/available’: Invalid argument

OK, so now even package management stops working, what to do?

First I searched for possible reasons for such crash, my /var/lib/dpkg/available and /var/lib/dpkg/status look fine under text editors, and dpkg didn’t complain about any package specificly, soon I find out this may be aroused by an insufficient memory size allocated to dpkg, as reported by some Debian users. So I add this line to my /etc/apt/apt/conf:

APT::Cache-Limit 10000000;

I guess that means apt can use as much memory as it wants.

But it is not over yet. I tried several backups for /var/lib/dpkg/status, none of them work for me, and I simply have no backup for /var/lib/dpkg/available. So I realized I have to rebuild both of them by myself, to some extent at least.

So here is my solution, I borrowed several scripts from the web. Before that you may want to read the last part of this article, and perhaps the Debian apt-howto, they explain what are needed to make dpkg work again.

  • backup you current /var/lib/dpkg/available and /var/lib/dpkg/status files, you may still need them later, for reference at least.
  • Create a new /var/lib/dpkg/available, simply quote out fundamental packages from your backup, such as libc6, locales, belocs etc. Start from libc6 package and follow the dependency it requires.
  • Use this perl script to generate your new status database, if your available file is fine, then you wil be almost done, otherwise this file will look much smaller than it should be.
  • run “apt-get upate”.
  • run “apt-get dist-upgrade”. After the packages are downloaded apt will complain for missing debconf or dpkg, whatever, ignore it.
  • Turn to /var/cache/apt/archives, and install packages manually with command “dpkg -i #package name#” #package name# should be replaced with the following packages, one by one: libncurses* perl-base* libstdc++* dselect* dpkg* . If it complains about extra dependence, apt-get that package and use dpkg to install it.
  • Run this script to reinstall libc6, reinstall the base system and recover your status of other packages you have installed. Unlike the perl script above, this script uses information in /usr/share/doc, rather than /usr/lib/dpkg/available, so it will find back all installed packages.
  • Clear up the mess, run “dselect-update” to rebuild your /usr/lib/dpkg/available and you are up-to-date again!

 If you available package is not corrupted (lucky you), only status runs wild, then simply run this script. It didn’t work for me because my bad available package prevents it from generating the right status file in the first place, but maybe you will save most trouble with it.

Add comment June 2, 2006

Random GRUB Splash Image Selection – a Python Script

Before the script there are two warnings, we all know booting is no kidding:

1. Make sure your GRUB splashimage configuration is compatible to the one introduced in my previous blog entry. My script may crash your boot procedure… or much less severely, garble your screen.

2. Check *EVERY* images you plan to use before the random selection ever takes place, this could be done by entering “ctrl C” at the boot screen, and use some GRUB commands to browse the splashimage directories and try them out.

Ok, let’s go on, here is the random splash python script:

———-START OF SCRIPT ————-

#!/usr/bin/python
import os
import commands
import string
from random import choice
GRUB_PATH = '/boot/grub/'
IMG_LNK = 'splash.xpm.gz'
IMG_PATH = '../images/' #Relative path!
curr_dir = os.getcwd()
os.chdir(GRUB_PATH)
img_str = commands.getoutput(''.join(('ls ',IMG_PATH)))
img_lst = []
while len(img_str):
    try:
        idx = img_str.index('\n')
        img_lst.append(img_str[:idx].strip())
        img_str = img_str[idx+1:]
    except ValueError:
        img_lst.append(img_str.strip())
        img_str = ''
       
img_cand = choice(img_lst)
print "The splash image chosen for next boot is %s" % img_cand
if commands.getoutput(''.join(('ln -s -f ', IMG_PATH, img_cand, ' ', IMG_LNK))):
    "Something Wrong while setting the new splashimage!"
else: print "New splashimage set, enjoy!"
os.chdir(curr_dir)

———-END OF SCRIPT ————-

You may want to add it to your startup script so each reboot will bring a little surprise :)

This piece of code has been tested on Kubuntu Dapper, you should try at your own risk. Good Luck.

Add comment May 28, 2006

Configuration of GRUB splash image

Seeing a nice booting splash image add much fun to using linux… at least to me. Better still you can personalize your booting screen with your favorite (simple) image. There are quite a few nice HOWTOs about this topic, but it still takes me a while to make things work, so I think it is worth some notes here.

For ubuntu users, here is an easy-to-follow guide of adding splash image on ubuntu/debian.

And if you would like to know more about splashimage go to visit a detailed version here.

Step 1: Make sure your grub support splash image, up-to-date versions should. Otherwise try to patch it by googling :P

Step 2: Grab an image, it must be a xpm file, and xpm.gz are more storage-conserving, and usually faster. You can download well-tested splashimages from web to test, (better for the first try) or you can make your own.

Note: this image must be 640*480, indexed with at most 14 colors. Many great pictures just look terrible after the conversion, so you may want to try gif pictures because they’re originally indexed and the compression won’t do as much harm as to color-rich ones. It’s a good idea to paint with 14 colors by yourself.

Tool: I prefer Gimp, because it’s powerful and you know what your picture looks like after each modification. right click the image and choose image->mode->indexed, then fill the color number region with 14, choose None for the Dithering option at the bottom. Save the picture with XXXXXX.xpm.gz, Gimp knows the trick of gzip ;)

Step 3: Now we go back to the GRUB part. On Debian based systems, GRUB will search for splash.xpm.gz automatically in the /boot/grub/ folder when you run ‘update-grub’. It’s a good idea to establish a directory for the images, for example

mkdir /boot/grub/images

Then you can copy your favorite image candidates here. Under /boot/grub, Use the command

ln -s ./images/XXXXXX.xpm.gz splash.xpm.gz

This creates a symbolic link to the actual image you’re using. So what’s left is to inform grub to use the image. For Debian update-grub will do this for you, but you may still want to update by yourself (probably on some other distributuion). Then edit the menu.lst (with sudo of course) to add a line like:

splashimage (hdX,Y)/boot/grub/splash.xpm.gz

or

splashimage (hdX,Y)/grub/splash.xpm.gz (if your /boot has its own partition)

or

splashimage=(hdX,Y)${BOOTPREFIX}/grub/splash.xpm.gz

 before the booting records. (hdX, Y) should agree with the booting entry that provides  GRUB, e.g. (hd0, 0). It seems ‘=’ and ‘ ‘ can be used interchangeably.

Note: By using a symbolic link you can avoid most trouble encountered by poor users like me. Because it has been pointed out in a ubuntu forum thread that when reading the menu.lst grub has some limitations on the length the path/filename. So you may end up with strips and dots if your image filename+path is too long. With a simbolic link it doesn’t matter at all where your pictures are stored, as long as they are visible by GRUB.

Good luck and Enjoy!

2 comments May 26, 2006

Tips of Kubuntu

Q:Where can environment variables be loaded at startup or used by many programs? (e.g. PATH)

A:~/.bashrc  /etc/profile  /etc/environment  /etc/kde3/kdm/.kdmrc  ~/.xsessions  /etc/bash.bashrc …

Add comment May 25, 2006

Previous Posts


Calendar

November 2009
M T W T F S S
« Apr    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Posts by Month

Posts by Category