A default Ubuntu install doesn't come with many compiling tools like GCC, G++, libc6-dev, and Make that you need to compile programs from source. To get all those packages, type in:
sudo apt-get install build-essential
You will need the Ubuntu CD for this.
Saturday, November 24, 2007
Compiling packages from source on Ubuntu
Posted by
Boris
at
12:39:00 PM
0
comments
Jump words with Control-Arrow in the Ubuntu terminal
On a fresh install of both Ubuntu 7.04 and 7.10, pressing Ctrl-[Arrow Key] does not jump words but instead writes a control code onto the screen such as ;5C or ;5D.
To fix this, add export INPUTRC=/etc/inputrc to /etc/bash.bashrc.
Make sure /etc/inputrc has these lines in it:
# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
Posted by
Boris
at
11:48:00 AM
0
comments
Tuesday, September 4, 2007
Make gnome-screensaver opaque with Compiz
If you use Compiz and GNOME, you might have noticed that you can still see your screen after you lock it. This is because, Compiz allows gnome-screensaver's window(the window that normally turns your screen black) to be slightly transparent. To fix this, go to the CompizConfig Settings Manager (most likely in System > Preferences), click on General Options and go to the Opacity Settings tab. You will see something like ((type=Menu | PopupMenu | DropdownMenu | Tooltip | Notification | Combo | Dnd | name=sun-awt-X11-XWindowPeer) | (type=Normal & override_redirect=1)) & !(name=sun-awt-X11-XFramePeer | name=sun-awt-X11-XDialogPeer)
This is a conditional statement which tells Compiz which windows to make transparent. You can either add name=gnome-screensaver to the opacity windows listbox and change the opacity to full or you can add it to the original item in the listbox to change it into:((type=Menu | PopupMenu | DropdownMenu | Tooltip | Notification | Combo | Dnd | name=sun-awt-X11-XWindowPeer) | (type=Normal & override_redirect=1)) & !(name=sun-awt-X11-XFramePeer | name=sun-awt-X11-XDialogPeer | name=gnome-screensaver)
[via www.tedcarnahan.com]
Posted by
Boris
at
1:01:00 PM
1 comments
Wednesday, August 22, 2007
Text to HTML Table Converter 1.2
Now has unbuffered reads and better flag support
Unbuffered Input Reading
I added an pseudo-unbuff_read() function to the program (pseudo because it is really a sentinel-terminated loop concatenating a buffered read to a string)
def unbuff_read(END):
""" Reads one char at a time from stdin until reaches a "stop" character """
str = ""
while 1: # no do-whiles or assignments-in-conditionals in python :`(
# Compare the end of the string (same length as END) to END
if str[ len(END) * -1 :] == END:
break
str += sys.stdin.read(1)
return str
The parameter that you pass into this function called END breaks out of the read loop and returns the str read in up to that point. The default END is '\n.\n' which is a newline followed by a period and then another newline. This syntax is the same as the one used to stop reading the message body(DATA) when talking to smtp mail servers.
To quit the program just type in the END variable by itself.
Better flag support
Function argsContain():
def argsContain(flag):
""" Flag is the letter/word/etc that follows the '-' or '--' in the options """
# search for flag in options part of args i.e. before filename
for arg in sys.argv[1:len(sys.argv)-1]:
if arg.find(flag) != -1:
return True
else:
return False
This function goes through each argument before the filename and searches for a specific flag like "f" or "v". The two instances that used to search for flags have been replaced with a call to this method enabling syntax like
$ python txt2html-table-1.2.py -vf input.txt and
$ python txt2html-table-1.2.py -fv input.txt Download
This program is Copyright 2007 to Boris Joffe and licensed under GPL 3.0. Open the file to read more of the terms that I released it under. Download Text to HTML Table (txt2html-table) Version 1.2
Debugging
I kept my debugging code which consists of a function called debug() and a commented call to it after main() to make it easier to play around with the code by just uncommenting the call(and maybe commenting main()) and putting code in the debug() function.
Posted by
Boris
at
9:21:00 PM
0
comments
Friday, August 17, 2007
Text to HTML Table Converter 1.0
Background
I was recently creating an description for a videogame I was selling on eBay and I needed to convert some text into an HTML table. Since I also was learning Python at the same time, I figured I would make a Python program that would do the job.
Input text format
The input text needs to be at least one line of text or more(seperated by a newline '\n') with a colon seperating the <th> element on the left and the <td> element on the right. You could also have another delimiter separating the two elements by changing the
tList = eachLine.split(':') line to split based on whatever character you want.The general format of the input text file should be:
thElement1: tdElement1
thElement2: tdElement2
...
where the <th> and <td> elements can have spaces, tabs, and other characters in them as long as they aren't '\n' or ':'.
Output HTML Format
The output which is displayed in the console (stdout) and which can optionally be saved to a file has this general format:
<table>
<tr>
<th>thElement1: </th>
<td>tdElement1</td>
</tr>
<tr>
<th>thElement2: </th>
<td>tdElement2</td>
</tr>
</table>
Download
This program is Copyright 2007 to Boris Joffe and licensed under GPL 3.0. Open the file to read more of the terms that I released it under.
Download Text to HTML Table (txt2html-table) Version 1.0
Usage Instructions
First of all, you need to download Python on your computer. If you're using a *NIX system, it should already by installed. The basic syntax is
python txt2html-table-1.0.py [-f] [-v] input.txtIf you don't include any of the optional flags (-f or -v), it will output the text in the file and confirm if you want to convert it. Type "y" or "yes" without the quotes to confirm or any other character(s) to exit. Upon confirmation, it will convert it to an HTML table and output the results.
Example: With no extra options
$ python txt2html-table-1.0.py input.txt
Would you like to convert the text below into an HTML Table?
=======================
thElement1: tdElement1
thElement2: tdElement2
=======================
< Yes | No >: y
Converted successfully to:
=======================
<table>
<tr>
<th>thElement1: </th>
<td>tdElement1</td>
</tr>
<tr>
<th>thElement2: </th>
<td>tdElement2</td>
</tr>
</table>
=======================
Other command line options/flags
Use:
$ python txt2html-table-1.0.py -f input.txt
to prompt for a filename at the end of a conversion to save the html output to. If you decide to not save the output, press ENTER when it prompts for a filename in order to quit.
Example: Use of -f flag
$ python txt2html-table-1.0.py -f input.txt
Would you like to convert the text below into an HTML Table?
=======================
thElement1: tdElement1
thElement2: tdElement2
=======================
< Yes | No >: y
Converted successfully to:
=======================
<table>
<tr>
<th>thElement1: </th>
<td>tdElement1</td>
</tr>
<tr>
<th>thElement2: </th>
<td>tdElement2</td>
</tr>
</table>
=======================
Enter a filename (Hit ENTER to quit): output.html
Output saved to: output.html
Use:
$ python txt2html-table-1.0.py -v input.txt
for verbose output. It shows you what elements each line was split into.
Example: Use of -v flag
$ python txt2html-table-1.0.py -v input.txt
Would you like to convert the text below into an HTML Table?
=======================
thElement1: tdElement1
thElement2: tdElement2
=======================
< Yes | No >: y
' thElement1: tdElement1 ' was split into ['thElement1', 'tdElement1']
' thElement2: tdElement2 ' was split into ['thElement2', 'tdElement2']
Converted successfully to:
=======================
<table>
<tr>
<th>thElement1: </th>
<td>tdElement1</td>
</tr>
<tr>
<th>thElement2: </th>
<td>tdElement2</td>
</tr>
</table>
=======================
You can combine these two flags in either order as long as they're between the python file (.py) and the input filename. However, you cannot type in "-fv" or "-vf".
Errors you might receive
- "Please pass a filename to me" if you didn't supply any arguments to the program.
- "File does not exist." if the last argument you gave was not a valid file. Could occur if you added the flags after the input filename.
To avoid other errors, make sure that the python interpreter is in your OS's path, the program is in the current directory, and each line in your input file has one colon separating the <th> and <td> elements.
Todo: Possible features in future versions
- Allow for specifying the output filename as a parameter i.e. python txt2html-table-1.0.py -f output.html input.txt
- Allow more than two elements per line i.e. all elements after the first would be extra <td> elements in the table
- Allow unbuffered reading in of text from the command line(stdin)
- Add better support for flags (allow -fv or -vf)
Alternatives
Use the Python DOM library to build the table instead of raw HTML-holding variables like tHead, tBody, and tTail
Tools
Used Quick Escape to escape the html output for inserting into this post.
Posted by
Boris
at
8:59:00 PM
0
comments
Sunday, July 22, 2007
Re-install GRUB after Windows install deletes it
Dual booting Windows and Linux gone wrong
When websites have tutorials about dual-booting Windows and Linux, they usually say to install Windows first and then install Linux after it. The reason for this is because Linux's bootloader detects your Windows partition and allows you to boot into it whereas Windows overwrites Linux's bootloader and replaces it with its own which only allows you to boot Windows. So that's why I install Windows first.
However, my Windows installation started acting unstable and I decided to reinstall it. Afterwards, I couldn't boot into Ubuntu (and Windows couldn't connect to the Internet, have the right resolution, etc. because I needed to reinstall the drivers...and everyone always talks about how everything "just works" after an install).
Reinstall GRUB
So this little tutorial tells you how to reinstall GRUB so you could choose your OS instead of being locked into one (and so you could reinstall Windows as necessary without worrying about breaking Linux).
If you use LILO or another bootloader, you could probably just google it. However, some suggestions don't work if you're repairing the MBR (Master Boot Record) from a LiveCD.
The Code
The following steps worked when I booted off the Ubuntu 6.10 LiveCD to repair the MBR but they should work on any CD that has GRUB.
Open a terminal and type the following in. The "#" is the prompt for root.
# grub
> find /boot/grub/stage1
(hd0,1)
> root (hd0, 1)
> setup (hd0)...
> quitHow it works
The grub command takes you into the grub shell
- the first line finds out on which hard drive and partition grub is installed on. In my case (hd0, 1), grub is installed on the first (and only) hd0 hard drive on the second partition (0 is the first)
- the second line switches to the hdd and partition where grub is installed
- setup tells grub to install itself onto the MBR so that grub becomes your default bootloader when booting off that hard drive
[via ubuntuforums.org]
Posted by
Boris
at
9:41:00 PM
0
comments
Turn off system beep in Linux terminal
There are a variety of ways to turn of the system beep. I have tried three of them on my Ubuntu Feisty laptop and they both work in terminal emulators like gnome-terminal, etc. and in the virtual terminals.
Temporarily turn it off $ xset b off
OR $ setterm -blength 0
Permanently (although you could change it later) turn it off
- uncomment(as root) "# set bell-style none" in /etc/inputrc
- Or to change it to a visual bell (blinking the screen), change it to "set bell-style visual"
- If you only want to do it for the current user instead of for everyone, create an "~/.inputrc" file and add the set bell-style line to that file.
Some of the other ways include deleting or blacklisting your internal speaker. Or if you prefer the hardware/cross-platform approach, take it out manually. :)
Posted by
Boris
at
3:09:00 PM
0
comments