Categorized under: Linux

[Ubuntu 12.04] The action would require the installation of packages from not authenticated sources.

I tried to install Thai language on Ubuntu 12.04 and got this error:

The action would require the installation of packages from not authenticated sources.

I googled and got the answer from here with some modifications. In summary:

  1. Go to Ubuntu Software Center
  2. Edit > Software Sources…
  3. In tab ‘Ubuntu Software’, untick ‘Software restricted by copyright or legal issues (multiverse)
  4. In tab ‘Other Software’, tick ‘Canonical Partners’, and maybe also ‘Canonical Partners (Source Code)’ if you’ll ever install from source.
Categorized under: Uncategorized

Counting #Source Files and #Lines of Code

I needed to count the total number of source files and lines of code of a code project.
So I wrote a Python script based on this blog post. Here’s the script.

import os
import sys

fileList = []
extList = ['.c', '.cpp', '.ChF', '.H', '.H.transdim']
rootdir = sys.argv[1]
for root, subFolders, files in os.walk(rootdir):
	for f in files:
		for ext in extList:
			if f[-len(ext):] == ext:
				fileList.append(os.path.join(root, f))
				break
print "Total number of source files: ", len(fileList)

# Now we have all the files we need.
# Start counting line number
numLines = 0
for f in fileList:
	lines = open(f).readlines()
	numLines = numLines + len(lines)
print "Total lines of code: ", numLines

Note: Change extList according to your source file extensions.

Categorized under: CUDA, Linux, Programming, Windows

Making Code:Blocks highlight CUDA syntax

I just formatted my notebook and installed a fresh copy of Windows and Ubuntu. And then I noticed I forgot to backup my CUDA lexer file for Code:Blocks. So I created a new one and thought I’d share it in case anyone needs it. :)

To make your Code:Blocks highlights your CUDA syntax, simply download my lexer_cuda.txt (1377) file, rename it to lexer_cuda.xml (apparently wordpress didn’t allow me to upload .xml file extension), and put it in:

  • [Windows] C:\Program Files (x86)\CodeBlocks\share\CodeBlocks\lexers
    • Or <Code:Blocks installation path>\share\CodeBlocks\lexers if you installed it to different folder.
  • [Linux] /usr/share/codeblocks/lexers

It works for Code:Blocks 10.05 and file extensions .cu and .cuh. You can add more extensions by yourself either by

  • Editing the line filemasks=”*.cu, *.cuh” in my lexer_cuda.xml file, or
  • Opening Code:Blocks
    • Go to Settings >> Editor >> Syntax Highlighting
    • Select CUDA in ‘syntax highlighting for’
    • Click Filemasks button, add the new extension, and click ok.

Credit: I used CUDA keywords from cuda.lua file.

Categorized under: Windows

Notepad++: Change Print Font Size

Notepad++ doesn’t have a menu to configure print font size.. How inconvenient, I really think this is a must-have feature!

This link tells me there are two ways to do it: by macro, or NppExec. The macro method didn’t work for me (I added the code in shortcuts.xml but the macro doesn’t show in Notepad++ so I couldn’t run it) The NppExec method has very brief explanation I don’t know how to do it.. And I couldn’t find a quick link that tell me exactly on how to do that method either. It was frustrating. A user who just wants to change print font size shouldn’t have to learn details about NppExec and Scintilla. So I think I would share here.

This is my take on it: Basically Notepad++ runs on a backend called Scintilla. And we can change print font size by sending a message to Scintilla to change its  SCI_SETPRINTMAGNIFICATION parameter. We can send a message to Scintilla by either running a macro, or via NppExec. Below is how I do it using NppExec.

  1. Plugins -> Plugin Manager -> Show Plugin Manager
  2. Select NppExec and click Install
  3. Restart Notepad++ after finish installing
  4. Press F6 or click Plugins -> NppExec -> Execute
  5. Type in SCI_SENDMSG 2146 -2
    • SCI_SENDMSG is a command to send message to Scintilla
    • 2146 is a code for SCI_SETPRINTMAGNIFICATION
    • -2 is a parameter, telling Scintilla to reduce the font size by 2 level
  6. Click OK
  7. Done.
Categorized under: Linux, Programming

My Linux Quick Reference

Just some commands that I tend to forget..

Screen

Terminate: Ctrl+D if Ctrl+A Ctrl+\ or Ctrl+A Ctrl+4 doesn’t work

Stop Beeping

Needs root permission.

Temporarily

modprobe -r pcspkr ->Disable
modprobe pcspkr -> Enable

Permanently

Add this line to the end of /etc/modprobe.d/blacklist
blacklist pcspkr

Piping stderr

foo 2>&1 | bar

To see only error messages (from compiler)
make sth 2>&1 | grep error

Useful Commands

/usr/sbin/dmidecode -t memory : Get mem details
. .profile or source .profile
ulimit -s unlimited
hid2hci
dhclient eth0
ip a
visudo
ln -s <target> <link name> : Symbolic Link