linux Syndicate content

» Attack of the shell helpers

Mon, 03/02/2009 - 02:46

Everyone who uses the command line regularly has a bunch of (at least for him) useful helper scripts. I now took the liberty to put mine on github for general consumption.

You can find them at: http://github.com/milianw/shell-helpers/tree/master

Some of these might be more useful than others, you decide :) Personally, I can’t live without the following:

apupgrade
a shortcut to update your Debian system with one command - no questions asked
openurl
opens a given URL in an already opened browser instance or starts a new browser session. Not only one browser is checked. I use it because firefox is slow to start and konqueror is blazingly fast to start. But when firefox is already open I want to use that.
xerr
shortcut for fast error checking in your Xorg log
clipboard
makes KDE4 Klipper contents available on the CLI (read and write access!)
debug

shortcut to start a GDB session: debug APP APP_ARGS is all you have to do. Its basically the same as doing:

  1. $ gdb APP
  2. > run APP_ARGS

» Take 2: Download script for springerlink.com Ebooks

Tue, 02/24/2009 - 22:58

NOTE: This script is apparently against the licensing contract between universities and Springer, see: http://www.bib.hm.edu/aktuelles/news/newsdetail_9984.de.html

NOTE 2: I do not maintain this script anymore. Please look for an alternative.

Seems like quite some people are interested in my bash script for downloading ebooks from http://springerlink.com.

That script has some quirks, the greatest of all that it was written in bash which makes it kind of hard to implement new features. And one which was requested was support for books which span multiple pages on SpringerLink.

So here I present springer_download.py - a Python rewrite which should handle all the old links and some more. This is the very first program I’ve written in Python. And since it has to run on the Zedat servers it’s limited to Python 2.4.x without any fancy shmancy additions (a pity, since I’d love to use urlgrabber or pycurl).

the script

You can find the sources on GitHub: http://milianw.github.com/springer_download/

I plan to put all my future code snippets in public repositories on GitHub. That way you can easily track changes and stay up to date. GitHub also has a nice “download” feature which you can use to get the current version. You can find my profile and my repositories at http://github.com/milianw

Note: This script is intended to be run under Linux or other *nix’es which fulfill the requirements (Python 2.4.x, iconv and pdftk). Windows is not supported.

TODO
  • introduce multithreading for faster / simultaneous downloads
  • add speed to progressbar
  • use progressbar in source-downloader
  • use one git-repo per project (makes links work properly)

» Kate linter plugin

Thu, 01/15/2009 - 18:58

Just a quicky: I wrote a little plugin for KTextEditor which supplies you with basic error checking when you save documents. Currently only PHP (via php -l) and JavaScript (via JavaScript Lint) are supported.

» Download script for springerlink.com Ebooks

Sat, 11/08/2008 - 17:28

After a long period of silence I present you the following bash script for downloading books from http://springerlink.com. This is not a way to circumvent their login mechanisms, you will need proper rights to download books. But many students in Germany get free access to those ebooks via their universities. I for example study at the FU Berlin and put the script in my Zedat home folder and start the download process via SSH from home. Afterwards I download the tarball to my home system.

Read on for the script.

» Access klipper clipboard on CLI under KDE4

Wed, 08/13/2008 - 23:12

NOTE: find most recent version on github: https://github.com/milianw/shell-helpers/blob/master/clipboard

Here’s a little script you can save in your path and do things like

  1. # paste current clipboard into file
  2. clipboard > "some_file"
  3. # copy some file into clipboard
  4. cat "some_file" | clipboard

Actually I find it rather useful so I thought I should share it.

  1. #!/bin/bash
  2.  
  3. # Access your KDE 4 klipper on the command line
  4. # usage:
  5. # ./clipboard
  6. # will output current contents of klipper
  7. # echo "foobar" | ./clipboard
  8. # will put "foobar" into your clipboard/klipper
  9.  
  10. # check for stdin
  11. if ! tty -s && stdin=$(</dev/stdin) && [[ "$stdin" ]]; then
  12. # get the rest of stdin
  13. stdin=$stdin$'\n'$(cat)
  14. # oh, nice - user input! we set that as current
  15. # clipboard content
  16. qdbus org.kde.klipper /klipper setClipboardContents "$stdin"
  17. exit
  18. fi
  19.  
  20. # if we reach this point no user input was given and we
  21. # print out the current contents of the clipboard
  22. qdbus org.kde.klipper /klipper getClipboardContents

As usually, save the file (attached below) in your $PATH and make it executable.

PS: Thanks to Martin Vidner for his article on D-BUS btw. - it gave me the proper dbus commands. PPS: Thanks the the various comments below!

» recent GeSHi contributions (apache, xorg, apt, performance, ...)

Wed, 06/18/2008 - 22:46

Your favourite syntax highlighter for web applications, GeSHi, recently got some new features and bug fixes. By yours sincerely. A rough summary of what I contributed:

  • various performance improvements, i.e. some speed optimizations and reduced memory consumptions (especially peak memory usage is down by roughly 1MB when highlighting geshi.php by itself)
  • minor bugfixes, including one which prevents some nasty PHP notices on PHP 5 systems to contaminate your precious log files
  • improved language files: bash, apache
  • added language files: GNU Gettext, Xorg configuration and Apt sources.list

Some of those features were already shipped with the recent 1.0.7.22 release. But the two new language files and the improvements to the existing apache language file are currently only available via SVN. Wait for the next stable release which should be 1.0.8.

To see two pretty examples, read on after the break:

» LinuxTag Day One

Wed, 05/28/2008 - 15:29

Like last year I’m again standing at the Kubuntu Community booth at this years LinuxTag. Just now I’ve attended the keynote held by Aaron Seigo, ambassador of the KDE project. It was a very interesting talk which covered topics like Internet-Mobile-Desktop interaction, security, effects, Nokia and more. The most important parts roughly listed are:

  • you’ll one day be able to use the same (KDE) applications everywhere - Marble and Plasma for example already just compile and work on mobile devices
  • the internet will get much more embedded into your everyday applications. Marble with OpenStreetMap & Wikipedia support or Amarok with its storage backends (Lastfm, Jamendo etc. etc.) are good examples in this regard.
  • KDE4 is much more accessible than KDE3 thanks to QAccessible
  • security and privacy is not forgotten! This is free software, don’t forget that. Plasma Applet packages will get GPG signed (just like the DEB packages in Apt). And you have control over what data is send where - no Stasi 2.0 here!
  • Nokia is actively supporting KDE, fear not! And of course never underestimate the power of the Free Qt Foundation.

All in all it was a very good presentation with good questions - very informative! I’m totally going to check out kde4daily now - KDE 4.1 is impressive!

Just on a sidenote: LinuxTag is going well but Kubuntu and Ubuntu did not get any CDs shipped by Canonical which is a shame of course… Nevertheless the social aspect of this fair is awesome again - you get to know so many people and meet some which you’ve talked to over IRC for ages. Yesterday we went to a bar at Hackescher Markt with the KDE and Amarok guys and had a few beers, tomorrow will be the social event, which was absolutely humongous (to use a word Aaron teached me yesterday ;-) ) last year. And on Friday we’ll go to a restaurant with the Trolls (just like last year - thanks for the invitation!) and maybe go into a Karaoke Bar afterwards. Great! And of course on Saturday there is a Ubuntu Grill at the C-Base, organized by Ubuntu Berlin - neat! Last year that was a great finishing to a good fair.

If anybody wants to drop by we are in hall 7.2b, booth 124 (together with Amarok). If you need a free ticket, just send me an email (mail@milianw.de). See you here!

» How to generate proper DIN A4 sized plots with Gnuplot

Fri, 05/16/2008 - 21:04

I’ve had a major annoyance today: The plot generated by gnuplot looked good inside the wxt terminal but I simply couldn’t get a proper fullsized DIN A4 postscript exported. This is how I’ve done it now:

  1. Inside gnuplot:
    1. set size ratio 0.71 # this is the ratio of a DIN A4 page (21/29.7)
    2. set terminal postscript enhanced landscape "Arial" 9 # you can change landscape to portrait and the fontname and -size
    3. set output 'yourfilename.ps' # this is your export file
    4. replot # or put your custom plot command here
  2. In a shell:
    1. ps2ps -sPAGESIZE=a4 yourfilename.ps new_dina4_file.ps
  3. Now you can simply print `new_dina4_file.ps` from within KGhostView for example. Have fun!

» mp3dump take two - better audio quality

Sat, 03/29/2008 - 16:29

So just yesterday I’ve published a bash script which rips the audio stream of Flash Videos (*.flv) to mp3 format. It’s nice, fast and imo all-purpose. But I didn’t like the audio quality. Thus below you can find a second version of the script which is using mplayer and lame instead of ffmpeg. Usage and behaviour should be pretty much the same. Only the audio quality should be better on cost of a bit more computing.

Since it relies on the fact that the input *.flv video already uses MP3 encoding for its audio stream this might not work for every flash file! Youtube works just fine though. You can find the script after the break, it’s also attached below. For usage / installation / more information read the old article.

If you wonder why I reencode the audiodump with lame: The dumped mp3 file is considered by most (all?) audio players to be ~10x the length. A five minute video gets a 45 minute audio dumpfile. It plays fine but seeking is a mess. Reencoding fixes this. If you know an alternative which does not require reencoding or is generally faster - please drop a comment!

» Patching Kirocker Music Display for volume control via mouse scrolling

Fri, 03/28/2008 - 16:32

Kirocker is such a great application, it’s a pity the developer Sébastien Laoût has given up on it and is using Windows now!

Usually I only use the kicker applet, the full screen window is nice for parties though. But I didn’t like the way the applet handles scroll events: It seeks (if possible). Since I rarely seek when listening to music I’d rather have the behaviour of the Amarok tray icon: volume control!

I had a look inside the sources and found this part in src/coverdisplay.cpp:

  1. void CoverDisplay::wheelEvent(QWheelEvent *event)
  2. {
  3. if (areControlsShown()) {
  4. if (event->orientation() == Qt::Vertical) {
  5. PlayerInformation *infos = PlayerInformation::instance();
  6. if (infos->canSeek()) {
  7. int deltaSeconds = 10 * (event->delta() > 0 ? 1 : -1);
  8. m_infos->seekRelative(deltaSeconds);
  9. }
  10. } else {
  11. if (event->delta() > 0)
  12. AmarokApi::volumeUp();
  13. else
  14. AmarokApi::volumeDown();
  15. }
  16. }
  17. }

As you can see it already supports volume control via scrolling! The thing is I’ve disable four-way scrolling for my MX1000. Thus I’ve simply swapped the if statements and now I’m really happy with Kirocker. Here’s the updated snippet:

  1. void CoverDisplay::wheelEvent(QWheelEvent *event)
  2. {
  3. if (areControlsShown()) {
  4. if (event->orientation() == Qt::Vertical) {
  5. if (event->delta() > 0)
  6. AmarokApi::volumeUp();
  7. else
  8. AmarokApi::volumeDown();
  9. } else {
  10. PlayerInformation *infos = PlayerInformation::instance();
  11. if (infos->canSeek()) {
  12. int deltaSeconds = 10 * (event->delta() > 0 ? 1 : -1);
  13. m_infos->seekRelative(deltaSeconds);
  14. }
  15. }
  16. }
  17. }

Replace the old code, compile Kirocker, install it. Then restart kicker (killall kicker; sleep 1; kicker;) and Kirocker should accept scroll events in the way the Amarok tray icon does!