hg revert -r 23456 file.txt
Monday, October 17, 2011
Mercurial get a single file
If you'd like to get back a single file (file.txt) from a previous revision (23456) in mercurial, the command is:
Friday, October 7, 2011
make variables
When writing make rules, there's a certain set of vital cryptic syntax that is impossible to remember.
It always takes ages to find the definitions of these damned things which are unaccountably hidden deep in the manual, or remember what they're called, even though they're the one thing you always need when writing a makefile.
Make Automatic Variables
$@ target
$< first prerequisite
$^ all prerequisites
$* the stem from the pattern match in an implicit rule
These are the four that you always use, more can be found at:
http://www.gnu.org/s/hello/manual/make/Automatic-Variables.html#Automatic-Variables
It always takes ages to find the definitions of these damned things which are unaccountably hidden deep in the manual, or remember what they're called, even though they're the one thing you always need when writing a makefile.
Make Automatic Variables
$@ target
$< first prerequisite
$^ all prerequisites
$* the stem from the pattern match in an implicit rule
These are the four that you always use, more can be found at:
http://www.gnu.org/s/hello/manual/make/Automatic-Variables.html#Automatic-Variables
Thursday, September 15, 2011
Making emacs TAGS files for a tree of source code
This command makes an emacs tags file when you've got a tree of many types of file (in this case mixed C and assembler, with makefiles)
$ find . \( -name "*.[ch]" -or -name "*.inc" -or -name "*.s" -or -name "*.mk" \) -print | xargs etags -a
$ find . \( -name "*.[ch]" -or -name "*.inc" -or -name "*.s" -or -name "*.mk" \) -print | xargs etags -a
Tuesday, March 29, 2011
git recover lost commits
Sometimes, if there's no reference to a commit, it looks as though git has thrown it away. (Indeed if you do git gc, it will throw it away).
In this situation,
$ gitk --show-dangling
will give you enough information to save your ass.
You can also use:
$ gitk --all $(git log -g --pretty=format:%h)
to much the same effect.
In this situation,
$ gitk --show-dangling
will give you enough information to save your ass.
You can also use:
$ gitk --all $(git log -g --pretty=format:%h)
to much the same effect.
Thursday, March 24, 2011
Old Ubuntu
I logged into an old version of ubuntu the other day and was struck by how much I preferred it.
Tips to take into a new version. Use droid sans 10 for all fonts except fixed width, which should be monospace 10.
The battery icon used to have an entry called 'Power History' which I think was part of gnome-power-manager. That was really useful but it's gone.
Use the dust sand theme and a plain green background, panels at the side so as not to take up too much space.
Maybe it's time to go back to debian.
sudo apt-get install ttf-droid
Tips to take into a new version. Use droid sans 10 for all fonts except fixed width, which should be monospace 10.
The battery icon used to have an entry called 'Power History' which I think was part of gnome-power-manager. That was really useful but it's gone.
Use the dust sand theme and a plain green background, panels at the side so as not to take up too much space.
Maybe it's time to go back to debian.
sudo apt-get install ttf-droid
Sunday, January 23, 2011
Ubuntu Install (10.10 Maverick Meerkat)
I've just made a new install of Ubuntu 10.10 on my desktop.
At first, I couldn't get my computer to boot off a CD or usb drive. This turned out to be because I'd disabled USB in the BIOS. Apparently for stability reasons. http://johnsunixtips.blogspot.com/2010/09/ubuntu-10041-lts-usb-boot-conflict.html
After that, I could get the computer to boot of a usb drive, although not off a CD. Even when it did boot, it seemed to freeze forever at a purple screen of death with a stupid little picture of a keyboard being equal to a man. Go figure.
I assume it was trying to load the linux kernel. Pulling out all usb devices except the usb stick it was actually booting from seemed to help.
But even then you just have to wait it out. It seems to take about five minutes, with no progress bar or anything. During which the only indication that it hasn't crashed is that the light on the usb drive is flashing. It's very difficult to wait that long, especially when you've seen it crash ten times already. But eventually it may switch to a different purple screen, on which orange dots move incomprehensibly.
All of this would be much more tractable if there was some indication what the damned thing was doing. I bloody hate the sort of cretins who turn off progress reports. Presumably for 'aesthetic' reasons. As if wasting half a day because you can't see what's going on will make you feel better about linux.
Eventually though, it becomes a friendly graphical installer, and everything gets much less worrying.
Once you're there, it's safe to put in the wireless USB dongle, which the installer recognises and configures immediately. That allows it to download updates as part of the install, which worked flawlessly.
Unfortunately, when the machine reboots, the wireless has stopped working. This turns out to be a problem with bad kernel modules that need blacklisting. See http://johnsunixtips.blogspot.com/2010/08/sitecom-wireless-wl-608-54g-usb-dongle.html, but essentially the fix is to add:
# To stop bad drivers blocking the correct driver for usb wireless dongle
# See http://johnsunixtips.blogspot.com/2010/08/sitecom-wireless-wl-608-54g-usb-dongle.html
blacklist rt2800usb
blacklist rt2x00usb
blacklist rt2x00lib
to the bottom of /etc/modprobe.d/blacklist.conf:
(On a Dell Mini install the Broadcom STA driver, which works fine.)
(On a Dell Mini 1018 with the Realtek Driver, do:
$ sudo add-apt-repository ppa:lexical/hwe-wireless
$ sudo apt-get update
$ sudo apt-get install rtl8192ce-dkms
and reboot and everything is fine.
And you should also turn off intel speedstep in the BIOS,
since otherwise the netbook won't wake up from suspend
)
The boot process also becomes rather more reassuring if you get rid of the purple screens of maybe-death, and let the kernel explain what it's doing as it boots:
$ sudo vi /etc/default/grub
change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT=""
then run
$ sudo update-grub
Sheesh. That was far too hard, and took hours. I'd never have managed it if I were a newbie, or even if I'd failed to write all that stuff down during previous encounters. Installing ubuntu used to be dead easy. On this machine I'd now say it was impossible even for an expert unless he was already familiar with the quirks of running it on this machine.
Anyway. All fine now.
The first thing I noticed about the new system was that it doesn't play youtube videos.
As long as you don't care too much about software purity, the first thing to do after installing a new ubuntu is:
$ sudo apt-get install ubuntu-restricted-extras
which is a huge metapackage that adds all sorts of goodies. At one point it asks to agree to some sort of microsoft font licence. Sigh....
Then do:
$ sudo /usr/share/doc/libdvdread4/install-css.sh
to give your new system DVD reading abilities.
You should add the medibuntu repository, instructions here: https://help.ubuntu.com/community/Medibuntu. What they say to do is:
$ sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
This page has many more tips for interesting stuff to install:
http://www.my-guides.net/en/guides/linux/193-ubuntu-lucid-lynx-1004-post-installation-guide
More things to do in case I need to do this again soon
Lots of things need installing:
You can make a cup of tea while this is happening. It takes about ten minutes.
$ sudo apt-get install w32codecs gitk epiphany-browser chromium-browser mplayer smplayer emacs maven2 xxdiff emacs-goodies-el tree git-gui mercurial rlwrap vim-gnome nautilus-open-terminal loop-aes-utils xclip filelight htop gparted idle-python3.1 unison build-essential gparted imagemagick fail2ban kate vlc openjdk-6-jdk xine-ui
Turn the firewall on:
$ sudo ufw enable
to check:
$ sudo ufw status
If you want to run an ssh server (client is already installed)
Then go fix the config file
$ sudo passwd root
And change the default umask so that files are private for all users
$ sudo vi /etc/profile
change umask from 022 to 077
Encrypt the swap partition:
$ sudo vi /etc/fstab
Change /dev/sda5 none swap sw 0 0 to:
/dev/sda2 none swap sw,loop=/dev/loop7,encryption=AES256 0 0
and add cryptoloop to /etc/modules
The version of hplip in 10.10 is not new enough to support an HP Deskjet 3050, latest driver is here: http://hplipopensource.com/hplip-web/index.html
Or it can be fetched directly with:
$ wget http://sourceforge.net/projects/hplip/files/hplip/3.11.1/hplip-3.11.1.run
either way you then need to run an install script and give it your password:
$ chmod +x hplip-3.11.1.run
$ ./hplip-3.11.1.run
the last gasp of this little script is to run $ hp-setup which should discover the printer if it's turned on. If it can't find it the network address is 192.168.1.6 usually.
The system is now set up.
Remaining problems:
DVD playback with 'movie player' is very slow, even though it was (is) fine in the 10.04 installation. VLC works OK once you change the video to GLX video output, using just under all the CPU to play in 1920x1600 full screen.
xine and smplayer seem to work best of all, but needs a symbolic link from /dev/dvd to wherever your dvd drive is:
$ sudo ln -s /dev/sr1 /dev/dvd
Tweaks to a new user account:
Install elpa by evaluating this code in emacs:
Then use elpa:
M-x package-list-packages then i to mark packages, and x to do it.
to install clojure-mode, slime, slime-repl and htmlize
In firefox install adblock plus, xmarks, and video download helper
At first, I couldn't get my computer to boot off a CD or usb drive. This turned out to be because I'd disabled USB in the BIOS. Apparently for stability reasons. http://johnsunixtips.blogspot.com/2010/09/ubuntu-10041-lts-usb-boot-conflict.html
After that, I could get the computer to boot of a usb drive, although not off a CD. Even when it did boot, it seemed to freeze forever at a purple screen of death with a stupid little picture of a keyboard being equal to a man. Go figure.
I assume it was trying to load the linux kernel. Pulling out all usb devices except the usb stick it was actually booting from seemed to help.
But even then you just have to wait it out. It seems to take about five minutes, with no progress bar or anything. During which the only indication that it hasn't crashed is that the light on the usb drive is flashing. It's very difficult to wait that long, especially when you've seen it crash ten times already. But eventually it may switch to a different purple screen, on which orange dots move incomprehensibly.
All of this would be much more tractable if there was some indication what the damned thing was doing. I bloody hate the sort of cretins who turn off progress reports. Presumably for 'aesthetic' reasons. As if wasting half a day because you can't see what's going on will make you feel better about linux.
Eventually though, it becomes a friendly graphical installer, and everything gets much less worrying.
Once you're there, it's safe to put in the wireless USB dongle, which the installer recognises and configures immediately. That allows it to download updates as part of the install, which worked flawlessly.
Unfortunately, when the machine reboots, the wireless has stopped working. This turns out to be a problem with bad kernel modules that need blacklisting. See http://johnsunixtips.blogspot.com/2010/08/sitecom-wireless-wl-608-54g-usb-dongle.html, but essentially the fix is to add:
# To stop bad drivers blocking the correct driver for usb wireless dongle
# See http://johnsunixtips.blogspot.com/2010/08/sitecom-wireless-wl-608-54g-usb-dongle.html
blacklist rt2800usb
blacklist rt2x00usb
blacklist rt2x00lib
to the bottom of /etc/modprobe.d/blacklist.conf:
(On a Dell Mini 1018 with the Realtek Driver, do:
$ sudo add-apt-repository ppa:lexical/hwe-wireless
$ sudo apt-get update
$ sudo apt-get install rtl8192ce-dkms
and reboot and everything is fine.
And you should also turn off intel speedstep in the BIOS,
since otherwise the netbook won't wake up from suspend
)
The boot process also becomes rather more reassuring if you get rid of the purple screens of maybe-death, and let the kernel explain what it's doing as it boots:
$ sudo vi /etc/default/grub
change
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
to
GRUB_CMDLINE_LINUX_DEFAULT=""
then run
$ sudo update-grub
Sheesh. That was far too hard, and took hours. I'd never have managed it if I were a newbie, or even if I'd failed to write all that stuff down during previous encounters. Installing ubuntu used to be dead easy. On this machine I'd now say it was impossible even for an expert unless he was already familiar with the quirks of running it on this machine.
Anyway. All fine now.
The first thing I noticed about the new system was that it doesn't play youtube videos.
As long as you don't care too much about software purity, the first thing to do after installing a new ubuntu is:
$ sudo apt-get install ubuntu-restricted-extras
which is a huge metapackage that adds all sorts of goodies. At one point it asks to agree to some sort of microsoft font licence. Sigh....
Then do:
$ sudo /usr/share/doc/libdvdread4/install-css.sh
to give your new system DVD reading abilities.
You should add the medibuntu repository, instructions here: https://help.ubuntu.com/community/Medibuntu. What they say to do is:
$ sudo wget --output-document=/etc/apt/sources.list.d/medibuntu.list http://www.medibuntu.org/sources.list.d/$(lsb_release -cs).list && sudo apt-get --quiet update && sudo apt-get --yes --quiet --allow-unauthenticated install medibuntu-keyring && sudo apt-get --quiet update
This page has many more tips for interesting stuff to install:
http://www.my-guides.net/en/guides/linux/193-ubuntu-lucid-lynx-1004-post-installation-guide
More things to do in case I need to do this again soon
Lots of things need installing:
You can make a cup of tea while this is happening. It takes about ten minutes.
$ sudo apt-get install w32codecs gitk epiphany-browser chromium-browser mplayer smplayer emacs maven2 xxdiff emacs-goodies-el tree git-gui mercurial rlwrap vim-gnome nautilus-open-terminal loop-aes-utils xclip filelight htop gparted idle-python3.1 unison build-essential gparted imagemagick fail2ban kate vlc openjdk-6-jdk xine-ui
Turn the firewall on:
$ sudo ufw enable
to check:
$ sudo ufw status
If you want to run an ssh server (client is already installed)
$ sudo apt-get install ssh
Then go fix the config file
$ sudo vi /etc/ssh/sshd_config
Change UsePAM, PasswordAuthentication, PermitRootLogin to no
Also allow Port 443 for login over https port through captive portals
Then allow it through the firewall:
Also allow Port 443 for login over https port through captive portals
Then allow it through the firewall:
$ sudo ufw allow 22
(also 443, also fix the router to forward appropriately)
(also 443, also fix the router to forward appropriately)
Enable the root account, which always seems to come in handy.
$ sudo passwd root
And change the default umask so that files are private for all users
$ sudo vi /etc/profile
change umask from 022 to 077
Encrypt the swap partition:
$ sudo vi /etc/fstab
Change /dev/sda5 none swap sw 0 0 to:
/dev/sda2 none swap sw,loop=/dev/loop7,encryption=AES256 0 0
and add cryptoloop to /etc/modules
The version of hplip in 10.10 is not new enough to support an HP Deskjet 3050, latest driver is here: http://hplipopensource.com/hplip-web/index.html
Or it can be fetched directly with:
$ wget http://sourceforge.net/projects/hplip/files/hplip/3.11.1/hplip-3.11.1.run
either way you then need to run an install script and give it your password:
$ chmod +x hplip-3.11.1.run
$ ./hplip-3.11.1.run
the last gasp of this little script is to run $ hp-setup which should discover the printer if it's turned on. If it can't find it the network address is 192.168.1.6 usually.
The system is now set up.
Remaining problems:
DVD playback with 'movie player' is very slow, even though it was (is) fine in the 10.04 installation. VLC works OK once you change the video to GLX video output, using just under all the CPU to play in 1920x1600 full screen.
xine and smplayer seem to work best of all, but needs a symbolic link from /dev/dvd to wherever your dvd drive is:
$ sudo ln -s /dev/sr1 /dev/dvd
Can't get this to mount on boot
Encrypted /home
add cryptoloop to /etc/modules
add to /etc/fstab:
/dev/sdb1 /home ext3 noauto,loop=/dev/loop6,encryption=AES128 0 0
Tweaks to a new user account:
System/Preferences/Keyboard/Typing Break to turn on typing break
System/Preferences/Keyboard/Layouts/Options/Ctrl key position/Make CapsLock an additional Ctrl
Use United Kingdom keyboard, with United Kingdom International with dead keys to type foreign.
Disable all the Ctrl-Alt- shortcuts in GNOME using System/Preferences/Keyboard Shortcuts
Make Alt+F11 mean 'toggle fullscreen mode'
Install elpa by evaluating this code in emacs:
(let ((buffer (url-retrieve-synchronously
"http://tromey.com/elpa/package-install.el")))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(eval-region (point) (point-max))
(kill-buffer (current-buffer))))
Then use elpa:
M-x package-list-packages then i to mark packages, and x to do it.
to install clojure-mode, slime, slime-repl and htmlize
Clone your repository from github:
$ ssh-keygen -t rsa -C "john@woc-desktop.aspden.com"
$ cat ~/.ssh/id_rsa.pub | xclip -sel clip
$ git clone git@github.com:johnlawrenceaspden/hobby-code.git
Make links to .bashrc etc
$ ~/hobby-code/makelinks.bash
In firefox install adblock plus, xmarks, and video download helper
Friday, January 21, 2011
Surround Sound (Ubuntu Lucid 10.04 Creative Soundblaster 5.1 emu10k)
It turns out that sound under Ubuntu is bewilderingly complex, and no one understands it.
However, it does work on my system, for some arbitrarily complicated definition of 'work'.
Trying to play back an mp3 the other day, I noticed that my speakers were making a terrible hissing noise.
This turned out to be coming from the central speaker only, and I thought it was because only the front left and front right speakers were being driven at all. Others seemed to be floating and making horrible noises.
To check this:
$ speaker-test -Dplug:surround51 -c6 -twav
A nice young lady will speak over all 6 speakers. That will tell you which ones are working.
At first, I only had the front left and front right working.
To get some more working I used:
$ alsamixer
Which is an arrow-keys and cursor terminal program.
The crucial piece of information was that MM stands for mute. If you go to a thing marked MM and press the m key then it becomes unmuted/unmuted.
I just ran up and down all the controls, randomly increasing volumes and muting/unmuting things.
This was enough to get all the speakers working as witnessed by the young lady. Although at first when she said 'front left' I could hear that over both front left and front center, and there were other interactions too.
A second breakthrough was when I noticed 'press F5' to show input sources as well as outputs.
It turned out that 'SB Live', or as it says above 'SB Live Analog/Digital Output Jack' is what's producing most of the hiss. Mute that, and everything gets much clearer.
There are a vast number of volume controls and things to mute and unmute.
As far as the young lady's voice goes, it seems that:
'Surround' controls the two rear speakers.
'PCM' controls the front left and right but not the centre
Center controls the front centre
LFE makes 'rear centre' come out over the front centre speaker.
'3D control, and two associated volume sliders' appear to control whether 'rear centre' gets put out over the other speakers.
'Sigmatel Surround' seems to mix some of the channels in with some of the others. Presumably for a 4-speaker set-up?
When I'd finished playing, I had each of the young lady's sayings coming over one and only one speaker, and could verify that they were all working. Presumably that's how it should be set up?
But at that point, I noticed that I'd completely lost the ability to play music, either through mplayer or totem.
Christ knows why, but they seem to work through some other related but different system which interacts with the ALSA thing in unpredictable ways.
Logging in and out cured the 'no music' problem. Don't know why.
It also turns out that the main volume control on the desktop/taskbar buggers up the settings in alsamixer. If you turn it up too high, then all sorts of distortion effects start happening, but when you turn it back down, they don't go away!
If you then go back to alsamixer, you find that a lot of the volume controls there have been moved into the red. Put them back to sensible values and the horror stops.
Anyway, whatever. I don't understand it at all, and I really can't imagine that this is how it's supposed to work. But at the moment I'm listening to Vaughan Williams in what appears to be stereo, over all 5 speakers and the woofer, and the speaker test can control all the little ones individually.
The situation seems roughly the same in 10.10, but it all seems to work a bit better, with speaker tests built in to the volume control icon, better default settings, and turning the volume up too high doesn't seem to permanently derange the alsamixer settings. Maybe I'm just getting used to it.
However, it does work on my system, for some arbitrarily complicated definition of 'work'.
Trying to play back an mp3 the other day, I noticed that my speakers were making a terrible hissing noise.
This turned out to be coming from the central speaker only, and I thought it was because only the front left and front right speakers were being driven at all. Others seemed to be floating and making horrible noises.
To check this:
$ speaker-test -Dplug:surround51 -c6 -twav
A nice young lady will speak over all 6 speakers. That will tell you which ones are working.
At first, I only had the front left and front right working.
To get some more working I used:
$ alsamixer
Which is an arrow-keys and cursor terminal program.
The crucial piece of information was that MM stands for mute. If you go to a thing marked MM and press the m key then it becomes unmuted/unmuted.
I just ran up and down all the controls, randomly increasing volumes and muting/unmuting things.
This was enough to get all the speakers working as witnessed by the young lady. Although at first when she said 'front left' I could hear that over both front left and front center, and there were other interactions too.
A second breakthrough was when I noticed 'press F5' to show input sources as well as outputs.
It turned out that 'SB Live', or as it says above 'SB Live Analog/Digital Output Jack' is what's producing most of the hiss. Mute that, and everything gets much clearer.
There are a vast number of volume controls and things to mute and unmute.
As far as the young lady's voice goes, it seems that:
'Surround' controls the two rear speakers.
'PCM' controls the front left and right but not the centre
Center controls the front centre
LFE makes 'rear centre' come out over the front centre speaker.
'3D control, and two associated volume sliders' appear to control whether 'rear centre' gets put out over the other speakers.
'Sigmatel Surround' seems to mix some of the channels in with some of the others. Presumably for a 4-speaker set-up?
When I'd finished playing, I had each of the young lady's sayings coming over one and only one speaker, and could verify that they were all working. Presumably that's how it should be set up?
But at that point, I noticed that I'd completely lost the ability to play music, either through mplayer or totem.
Christ knows why, but they seem to work through some other related but different system which interacts with the ALSA thing in unpredictable ways.
Logging in and out cured the 'no music' problem. Don't know why.
It also turns out that the main volume control on the desktop/taskbar buggers up the settings in alsamixer. If you turn it up too high, then all sorts of distortion effects start happening, but when you turn it back down, they don't go away!
If you then go back to alsamixer, you find that a lot of the volume controls there have been moved into the red. Put them back to sensible values and the horror stops.
Anyway, whatever. I don't understand it at all, and I really can't imagine that this is how it's supposed to work. But at the moment I'm listening to Vaughan Williams in what appears to be stereo, over all 5 speakers and the woofer, and the speaker test can control all the little ones individually.
The situation seems roughly the same in 10.10, but it all seems to work a bit better, with speaker tests built in to the volume control icon, better default settings, and turning the volume up too high doesn't seem to permanently derange the alsamixer settings. Maybe I'm just getting used to it.
Subscribe to:
Posts (Atom)