04 December, 2006

Linux Hacks

Tike these.
For instance,

Get faster file transfer by using 32-bit transfers on your hard drive
Just add the line:

hdparm -c3 /dev/hdX

to a bootup script.

If you use SuSE or other distros based on SYS V,

/sbin/init.d/boot.local
should work for you.
This enables 32-bit transfer on your hard drive. On some systems it can improve transfer performance by 75%.

To test your performance gain, type:

hdparm -t -T /dev/hdX

CPU Scaling

And more
Thanks to Larry Reeder

When I got my 600m, the CPU speed never went above 600 MHz, as shown by cat /proc/cpuinfo, or Gnome's CPU Frequency Scaling applet. I couldn't set the CPU frequency manually, and it wouldn't go up automatically when I was doing a long build. I was beginning to think that the 600m in "Inspiron 600m" stood for 600 MHz.

I was getting a "No speed steps could be determined" error every time I tried to run /etc/init.d/cpuspeed. After trying many things, I noticed that both scaling_max_freq and scaling_min_freq in /sys/devices/system/cpu/cpu0/cpufreq were set to 600000 (600 MHz).

I did: echo 2100000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq and then /etc/init.d/cpuspeed restart

After that the CPU would throttle up to meet demand, and I could also change the speed manually with the Gnome CPU frequency applet.
If you're trying to set various cpuspeed options, I recommend running the commands in /etc/init.d/cpuspeed manually, instead of using the cpuspeed script, which hides many possible error messages when the script has problems. Once you have the options you need, you can go back to using the cpuspeed script.

03 December, 2006

NVidia and FC6

For some reason Anaconda likes i586 kernels, and installs them by default. This upsets the system, and the NVidia compatibility in particular. I attempted to install a new driver (9629 or 9626) after installing a new kernel (2.6.18-1.2835) . There's a day of my life I want back. 9629 later turned out to have a bug that causes a "segmentation fault" upon any glx-related call. 9626 was reputed as one that should work, but refused to install (i.e. compile the kernel source). This glitch was finally fixed by touching a file called config.h (sought by the NVidia code in the kernel source tree). Namely : /usr/src/kernels/$(uname -r)-i686/include/linux/ .

Suspend to RAM

Apparently this feauture tends to break once new NVidia drivers (for 3-D support, on FC6 in my case) are installed. Here's the workaround.
(Courtesy of Firewing1)
1) Make backups of files we're going to edit and install pm-utils:
Code:

su -
yum install pm-utils
cp /etc/pm/functions-nvidia /etc/pm/functions-nvidia.backup
cp /boot/grub/grub.conf /etc/grub.conf.backup

Now, edit the /etc/pm/functions-nvidia and commend out this line:
Code:

/usr/sbin/vbetool post

in the resume_video() so that the line ends up looking like this:
Code:

### /usr/sbin/vbetool post

NOTE: I don't even own a ATi card so I can't test, but if you're seeing similar black screens on a suspend resume, then try editing all the files in /etc/pm and commenting out that line.

2) Next, we have to remove the built-in AGP support and use Nvidia's AGP driver. So, let's edit the /boot/grub/grub.conf, and add agp=off to the kernel line.
See a line like this:
Code:

kernel /vmlinuz-2.6.16-1.2096_FC5 ro root=LABEL=/ quiet

agp=off should be added to the end to look like:
Code:

kernel /vmlinuz-2.6.16-1.2096_FC5 ro root=LABEL=/ quiet agp=off

Your line may look a little different or the kernel version in the /vmlinuz-... path may not be the same. Please don't change that part, like last time this is just to show where to add the text.
3) Reboot, and you're good to go. Hitting the "suspend" button will put the computer into power-saving mode, and all your previous windows and applications will return to their previous state on resume. I tested with gnome-power-manager:
Code:
yum install gnome-power-manager --enablerepo=development
yum update gnome-power-manager --enablerepo=development

That will install / update it to the version I used successfully.

07 October, 2006

OO Browser in XEmacs

Use OOBR(OO-Browser)

OORB shows class structures etc., when you make a program with the language which has classes like C++.

After you execute M-x oobr, you should answer the following questions. The directory under which source (header) files are, the directory under which library header files are, and the path of files such as OOBR, OOBR-FTR. The emacs window is divided after OOBR file is made. Frankly speaking, I am not familiar with OOBR yet. But I think you can use it with the following commands.

  • v : Show the definition of class.
  • e : Edit class.
  • m : Search class with the regular expression.
  • c : Show the list of child classes.
  • p : Show the list of parent classes.
  • t : Show the list of top classes.

narrowing

  1. Select the function
  2. Do narrowing.(C-x n n)
  3. Return to the top.(C-x C-x)

Then, you can see only this function. By typing C-x n w, you reset the state.

using emacs tags

etags source.cc
  • M-. [symbol-name] : Jump to the definition of the symbol.
  • C-x 4 . [symbol-name] : Show the definition of the symbol on another window.
  • M-, : Show the next matching.
  • M-? [symbol-name] : Show the declaration of the symbol on the mini-buffer.

04 October, 2006

Secondary Mark in Emacs

(global-set-key [(control shift down-mouse-1)] 'mouse-drag-secondary)

01 October, 2006

30 September, 2006

Add extra types to emacs c++ mode (e.g. Root)

(setq c++-font-lock-extra-types
'(
"TFile"
"TProfile" "TH1D" "TH1F"
) )

02 August, 2006

seek and replace

sed -i 's/prima/dopo/g' filewithsomethingtobereplaced

# delete ALL blank lines from a file (same as "grep '.' ")
sed '/^$/d' # method 1
sed '/./!d' # method 2
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'

# remove all non-consecutive duplicate lines
awk '!x[$0]++' new > newfile

more here

13 July, 2006

Better Goto-line and Other-Window shortcuts

  • (global-set-key "\M-l" 'goto-line)
  • (global-set-key [(control tab)] 'other-window)

25 May, 2006

Slow Font Change in Emacs

As the title implies my emacs would always take its sweet time changing the font from courier 12 (default) to adobe-courier--...20 *** etc. Apparently, it's much quicker if you keep that option out of .emacs and create an alias with a -font option. E.g.
  • alias emacs='emacs -font -adobe-courier-bold-r-*-*-20-*-*-*-*-*-*-*'
Graças a Deus!

05 May, 2006

Fixme Comments in emacs

  • C++

(font-lock-add-keywords

'c++-mode
'(("\\<\\(FIXME\\)" 1 font-lock-warning-face t)))
(modify-face (quote font-lock-warning-face) "Red" "yellow" nil t nil t nil nil)

  • Perl
(font-lock-add-keywords
'perl-mode
'(("\\<\\(FIXME\\)" 1 font-lock-warning-face t)))
(modify-face (quote font-lock-warning-face) "Red" "yellow" nil t nil t nil nil)

  • Also the more decorations - the merrier
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(setq font-lock-maximum-size nil)
(setq font-lock-support-mode 'jit-lock-mode)
(setq jit-lock-stealth-time 0)

Skip a word with Ctrl right/left arrow

Brillant!! Finally found out how to make this work in xterm.
Put the following in your .inputrc

## rxvt
"\eOd": backward-word
"\eOc": forward-word

## xterm
"\e[1;5D": backward-word
"\e[1;5C": forward-word

"Less is more" and other useful exports and aliases

alias any='find . -iname *$1*'
alias grep='grep --color'
alias purge='rm *~ ; rm \#*'
alias nemacs='emacs -nw'
alias pico='nano'
alias pss='ps -ef |grep'
alias more='less'
alias bc='bc -ql'
alias lprodd='lpr -o page-set=odd'
alias lpreven='lpr -o page-set=even'

export PS1=" \u \w $ "
export today=$(date +%d%b%y)

22 April, 2006

Mplayer and framedropping

mplayer -framedrop helps when the image falls behind the sound.
I also had to change -vo x11 to -vo xv, in so that the animation would become smoother.

12 April, 2006

Font Server

After an improper restart (x-server hung up) the X-server wouldn't start, saying something about FontPath being specified as user:/ 7100 (which it is, in xorg.conf), and that it can't find font 'fixed'. Turns out it was caused by the xfs server. It hadn't started despite a couple of reboots. Doing
    • /etc/init.d/xfs start
seems to have fixed the problem. Brilliant!

08 April, 2006

Fix the sound problem with the firefox flash plugin

This is something that keeps recurring every other linux upgrade or reinstallation. The solution is to simply change the permissions on the plugins directory:
  • chmod a+rwx /usr/lib/firefox-xxx/plugins

Putting Nvidia to Sleep

Turns out Hibernation (which now comes with the FC package) can coexist with the NVIDIA drivers. One of the biggest hurdles in the process was the fact that online posters kept referring to 8178 as the latest Nvidia driver. It's not, as I found out by visiting their official website. There, in the download section
  • get the driver version - NVIDIA-Linux-x86-1.0-8756-pkg1.run (if you have a 32 bit architecture) and run it as usual.
  • In my case I had to downgrade from kernel version 2.6.16-1.2084_FC5 to 2.6.16-1.2080_FC5, since 1) I couldn't find the source package for the 84-version, and 2) because I vaguely recalled somebody claiming to have less headache with hibernation after going through the analogous downgrade.
  • One more thing - not sure if this played any role in making everything work, but following some other guys suggestion I added
Option "NvAgp" "1"
to my /etc/X11/xorg.conf. Probably not, because I put it in the "Screen" section, instead of "Device", where chances are it's ought to be.
    • BY THE WAY, installing FC5 onto LVM's doesn't change a thing. Although smartd service stopped complaining. But hibernation is ok.

27 March, 2006

Wi-Fi

  • get WG511DCB.arm from prism54.com or somewhere else (not as easy to find as you'd think) [1.0.4.3.arm?]
  • rename it into isl3890
  • copy it into /lib/firmware
  • add "alias eth1 islpci_cb" to you /etc/modprobe
  • bring up the interface after instering the PCMCIA card - "/sbin/ifconfig eth1 up" (/sbin/ifconfig/ eth0 down)
  • it helps to have wlassistant installed (yum does it for you painfully enough)
  • Try to connect to the network of choice. Don't forget to select DHCP in the network config.
  • Cross your fingers and wait
  • Alternatively
http://sourceforge.net/projects/ndiswrapper
Unfortunately this involves patching and recompiling the kernel, which is always fun.

Check your architecture

rpm -q --qf '%{ARCH}\n' kernel

24 March, 2006

Further Emacs Improvements

    • (setq-default line-spacing 2)

23 March, 2006

Mounting NTFS (Fedora)

Get the module rpm from here (see step 2 first)
  1. Become a root
    • su
  2. Check your kernel version (do this before you download the rpm)
    • uname -r
  3. Go to where you saved the rpm and install it
    • rpm -ivh ntfs-blah-blah-blach.rpm
  4. Create a mountpoint for your windows partition
    • mkdir /mnt/win
  5. Check the device identifier (look for ntfs in the output)
    • /sbin/fdisk -l
  6. Add following to your /etc/fstab
    • /dev/hda1 /mnt/windows ntfs ro,defaults,umask=0222 0 0
  7. Enjoy
Read this and more useful FC5 instructions here

ALSA

The Alsa sound mixer helps xmms and multiple instances of mplayer etc co-exist peacefully. It comes standard now with Fedora 4 and 5.
  • In ~/.mplayer/config (vo=x11 is good for tranlucency, xv- for screen captures) add
    • ao=alsa
    • softvol = "yes" # this line may also be added to ./mplayer/gui.conf in case you like gmplayer
  • xmms
    • output plugins menu - Set to Alsa
      • Under "Configure" select software mixing
  • In Dell 8500 in particular the shortcuts for master and headphone volumes are separate . You can set up you r own and bind it to a command such as the following
    • $ amixer set Headphone 5%+
Here's my ~/.asoundrc:
pcm.ossmix {
type dmix
ipc_key 1021 # must be unique!
slave {
pcm "hw:0,0"
period_time 0
period_size 1024 # must be power of 2
buffer_size 8192 # dito. It
#format "S32_LE"
#periods 128 # dito.
rate 48000
}

# bindings are cool. This says, that only the first
# two channels are to be used by dmix, which is enough for
# (most) oss apps and also lets multichannel chios work
# much faster:

bindings {
0 0 # from 0 => to 0
1 1 # from 1 => to 1
}
}

# Redirect to ossmix
pcm.!default {
type plug
slave.pcm "ossmix" # use our new PCM here
}

# Redirect to ossmix
pcm.dsp0 {
type plug
slave.pcm "ossmix" # use our new PCM here
}

# mixer0 like above
ctl.mixer0 {
type hw
card 0
}

21 March, 2006

Ha-le-lu-ja! Ha-le-lu-ja! Hibernation! Hibernation! Hi-be-e-rna-tion!

Hibebrnation finally works in Fedora 5. NVIDIA divers installed the way described below, however, seems to dislike the hibernation, especcially the wakin up part. Anyway, here is a way to enable the NVIDIA drivers under Fedora 5. (Note: Fedora 5 came with kernel version 2.6-15-2669_FC5, but was upgraded using yum to 2.6.16-1.2069_FC5)
su -
cd /etc/yum.repos.d/
wget http://people.redhat.com/davej/kernels/Fedora/FC5/kernels.repo
yum install rpm-build
yum install kernel-devel -y
yum update kernel kernel-devel -y
mkdir /root/nvidia
cd /root/nvidia
wget http://www.leemhuis.info/files/fedorarpms/MISC.lvn/graphics/xorg-x11-drv-nvidia-1.0.8178-0.lvn.5.i386.rpm
wget http://www.leemhuis.info/files/fedorarpms/MISC.lvn/graphics/nvidia-kmod-1.0.8178-0.lvn.3.2.6.15_1.1881_FC5.src.rpm
reboot
select the new kernel, then:
su -
cd /root/nvidia
rpmbuild --rebuild --target `uname -m` nvidia-kmod-*.src.rpm
cp -a /usr/src/redhat/RPMS/`uname -m`/kmod-nvidia* ./
rpm -Uvh kmod-*nvidia-1.0.8178-0.*.rpm xorg-x11-drv-nvidia-1.0.8178-0.lvn.5.i386.rpm
modprobe nvidia
chkconfig nvidia-glx on
service nvidia-glx start
nvidia-xconfig
reboot

19 March, 2006

Cette putain de "3d Modeline" est vraiment chiante, hein!

(set-face-attribute 'mode-line nil :box nil)

12 March, 2006

Loads of interesting rants on programming languages and stuff in general from the Amazon Guy

http://www.cabochon.com/~stevey/blog-rants/index.html

More Emacs - get rid of the usless GUI Stuff.

Add to .emacs


(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))


(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))


(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

03 March, 2006

To swap or not to swap?

In

/proc/sys/vm/swappiness


the paramter can be set to a value from 0 to 100.

See discussion here:
http://kerneltrap.org/node/3000

my .emacs

;; .emacs

;;; uncomment this line to disable loading of "default.el" at startup
;; (setq inhibit-default-init t)
(eval-after-load "perl-mode"
'(define-key perl-mode-map "\C-c\C-c" 'comment-region))

(show-paren-mode 1)
;; define function to match a parenthesis otherwise insert a '~'
(defun goto-match-paren (arg)
"Go to the matching parenthesis if on parenthesis otherwise insert '~'."
(interactive "p")
(cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
(t (self-insert-command (or arg 1)))))
(global-set-key (kbd "~") 'goto-match-paren)



;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))

;; enable visual feedback on selections
;(setq transient-mark-mode t)

;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" system-name))

;; default to unified diffs
(setq diff-switches "-u")
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(auto-compression-mode t nil (jka-compr))
'(case-fold-search t)
'(current-language-environment "UTF-8")
'(default-input-method "rfc1345")
'(global-font-lock-mode t nil (font-lock))
'(pc-selection-mode t nil (pc-select))
'(save-place t nil (saveplace))
'(show-paren-mode t nil (paren))
'(transient-mark-mode t))
;;(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
;; '(default ((t (:stipple nil :background "ivory3" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 90 :width normal :family "adobe-courier")))))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(default ((t (:stipple nil :background "ivory3" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight bold :height 90 :width normal :family "adobe-courier")))))

27 February, 2006

.initrc, bash_complete and other intersting tidbits

www.ukuug.org/events/linux2003/papers/bash_tips/Link
  • Separate basename
    • function fig2ps
      {
      fig2dev -L ps "$1" "${1%.fig}.ps"
      }
      export -f fig2ps
  • Ignore typos in cd
    • shopt -s cdspell
  • .inputrc
    • set match-hidden-files off
    • set visible-stats on
    • set completion-ignore-case on
    • set show-all-if-ambiguous on
      • Make Meta+S cycle through the list:
        "\M-s": menu-complete


function fig2ps
{
fig2dev -L ps "$1" "${1%.fig}.ps"
}
export -f fig2ps

23 February, 2006

Mouse Pad Speed

Simple:


/etc/X11/xorg.conf


under Synaptic (input device)


Option "AccelFactor" "0.03"

19 February, 2006

Check this out

kill $(pidof xmms)

ls color

For when there is no color in ls
ls --color

m4a to mp3

#!/bin/bash
#
# Dump m4a to mp3

for i in *.m4a
do
if [ -f $i ]; then
rm -f "$i.wav"
mkfifo "$i.wav"
mplayer -ao pcm "$i" -aofile "$i.wav" &
dest=`echo "$i"|sed -e 's/m4a$/mp3/'`
lame "$i.wav" "$dest"
fi
done


FAAD

# m4a to wav
for i in *.m4a
do
faad "$i"
x=`echo "$i"|sed -e 's/.m4a/.wav/'`
y=`echo "$i"|sed -e 's/.m4a/.mp3/'`
lame -h -b 192 "$x" "$y"
rm "$x"
done

Animated gif

mplayer -frames 10000 -vo jpeg outdir=.:quality=75 ./CoinWalk_Pendulum.wmv
convert -delay 5 *.jpg pendulum.gif
convert -size 320x240 pendulum.gif -resize 160x120 small_pendulum.gif

MIME Types (Mplayer)

Example: MPlayer should start WMV by Double-Click
I've uninstalled Xine and Totem, cause i only use MPlayer. After uninstalling them, I saw a disaster: Totem used to be the default player. And now there was ... nothing!
After two days of internet research, this essay was created ... so that you don't waste your time the way I had to.

Creating the desktop file
If it is not already existing, create the file "/usr/share/applications/mplayer.desktop" like this:
Code:


[Desktop Entry]
Name=Movie Player
Comment=Play multimedia files and media
Icon=mplayer.xpm
Exec=gmplayer %f
Terminal=false
MimeType=video/mpeg;video/x-msvideo;video/quicktime;video/x-ms-asf;video/x-ms-wmv
Type=Application
Categories=Application;AudioVideo;
Encoding=UTF-8


The mime types for asf and wmv already exist and are stored in the mime type database (/usr/share/mime/packages/freedesktop.org.xml)

Modify defaults.list
This file will init our DEFAULT application. It ONLY contains ONE desktop file for EACH mime type:
Code:


video/x-ms-asf=mplayer.desktop
video/x-ms-wmv=mplayer.desktop



Modify mimeinfo.cache
To take effect as default application and init the double-click feature, we need to modify the mimeinfo.cache also:
Code:


video/x-ms-asf=mplayer.desktop
video/x-ms-wmv=mplayer.desktop


This file can use MORE then ONE desktop file. If you want to be able to handle - for example - WMV files with different players, a line like this is also acceptable:
Code:


video/x-ms-wmv=mplayer.desktop;realplay.desktop


This will change the right-click-menu and insert Helix-Player, while mplayer is still default (with double-click)

After modification, log out from gnome and log in again...

Zip Pipe

FILE* TCodaEvio::Open(const char* filename, const char* mode)
{
fIsPipe=true;
static char buf[256];
TString fstr(filename);
if (fstr.EndsWith(".bz2")) {
sprintf(buf,"bunzip2 -c %s",filename); Form("bunzip2 < %
s",filename)
return popen(buf, mode);
} else if (fstr.EndsWith(".gz")) {
sprintf(buf,"gunzip -c %s",filename);
return popen(buf, mode);
} else {
fIsPipe=false;
return fopen(filename, mode);
}
}

int TCodaEvio::Close(FILE* fp)
{
if (fIsPipe) {
//fseek(fp, 0L, SEEK_END);//doesn't work?
char buf[256];
while(fgets(buf,256,fp)) {};
return pclose(fp);
} else {
return fclose(fp);
}
}

PERL: Read To Colums

$file = 'input.csv';

open (F, $file) || die ("Could not open $file!");

while ($line = )
{
($field1,$field2,$field3,$field4) = split ',', $line;
print "$field1 : $field2 : $field3 : $field4";

}

close (F);

Setting and unsetting desktop image

#/bin/bash

filename=/home/mushonti/pictures/mozilla1280.jpg

gconftool-2 --unset /desktop/gnome/background/picture_filename
gconftool-2 --type=string --set /desktop/gnome/background/picture_filename $filename

SSH cygwin


http://pigtail.net/LRP/printsrv/cygwin-sshd.html

say "yes" to Xforwarding

In order for the "Y" flag to work in "ssh -Y" and forward X, edit /etc/ssh/sshd_config and change

X11Forwarding no
to
X11Forwarding yes

customized shortcuts

gconf-editor>apps>metacity>global_key_bindings / commands. Great stuff.

Remove Icons from Desktop (GNOME)

gconf-editod > apps>nautilus>preferences>show_desktop

Sudo is great

/etc/sudoers

Opening Ports Linux

To open ports to TCP access 6881 to 6999
/sbin/iptables -I INPUT -p tcp --destination-port 6881:6999 -j ACCEPT
Save settings
/sbin/iptables-save > /etc/sysconfig/iptables
See what's going on
netstat -anp --tcp

See if settings were saved
/sbin/iptables -L