Showing posts with label Software Tips. Show all posts
Showing posts with label Software Tips. Show all posts

Tuesday, January 13, 2015

Getting your local IP address in the GNU Screen status line

So I have this Digital Picture Frame made from an old laptop at work. It doesn't have that many uses other than to amuse myself and others in the form of a music player and an overpowered clock.

When I use it as a music player I use GNU Screen and Camp, the latter in combination with cp437 of course. This gives me the ability to log in remotely from my work computer to change track, volume and whatnot. The problem is having the correct local IP address of the machine since it gets updated every 8 hours. First I wrote a script that will check the local IP and send me an e-mail with the new one if there has been any changes. I run this script via cron once an hour.

But what I really wanted was to have it display in the status line of GNU Screen. It took some digging but I found this article which mentions an option called "backtick" in GNU Screen. In short backtick allows you to run a command from .screenrc and have it's output displayed in the status line.

An almost 20 year old laptop chugging along on Debian Wheezy playing
music and pulling of a look that might induce wet dreams to retro nerds.  

How to do it

I've added the following to my .screenrc
backtick 101 600 600 hostname -I

101 is the identifier of this particular backtick that will be used in the status line string, it could just as well be 1 or whatever number I choose.
600 and 600 determines how often to run the program and how often to refresh the line. I use the same number on both mainly because that's what the author of the article did and I don't see any reason to go beyond that. If you're curious read more about it here.
hostname -I this is the command I run to get my local IP address.

That's it for the command but you need to add want to display the output in the statusline:
hardstatus alwayslastline "%{= g} %{= w}%-Lw%{=r}%n%f* %t  %{-}%+LW %-=%| %101` | %D %M %d %Y %c:%s"

So really I just added %101` (yes the ` is required) to the string in order to display the output. That and two | and a couple of spaces to act as dividers.   

Now don't come around asking me questions on GNU Screen's status line because that is a whole other story. I barley know what mine does. 

Tuesday, December 16, 2014

cp437 - bringing high ASCII order to the fucked up world of UTF8

Let's get one thing straight, I absolutely love ANSI graphics. But lately, and by lately I mean since 200X, getting my daily fix of this Graffitti-esque artstyle that had it's glory days in the early 90's has become a bit of a hassle. Sure you can mess around with your charset settings and fonts like I've done, but that will probably affect the usability of the rest of your system... in a negative way.

So when I, as a newcomer to reddit, asked for help in the /r/commandline subreddit I got the answer: cp437 an app so easy to use it's almost painful to think of all the headaches I've had trying to get ANSI to display properly in Linux virtual console and assorted terminal emulators.

After installation it's merely a matter of typing "cp437" followed by the app of your choice for instance:

$ cp437 camp
$ cp437 duhdraw

It even works under GNU screen, to some extent. To be honest I had trouble with getting DuhDraw to paint properly under GNU screen the first time I tried it.

Camp, in all it's properly rendered ANSI glory.
The image is a bit offset because my virtual console is
larger than 80 columns and 25 lines.

CAMP file selection menu.
No there's no little "screen;" thing in the corner. ;)

Quick Ansi doodle in DuhDraw.



Tuesday, October 15, 2013

Apparently I write game reviews now

Today I posted my first game review ever. It's a review of C64anabalt, a Commodore 64 port of the 2009 indie platform game. 


Could very well be the first C64 game I've bought with my own hard earned cash.
After flaunting my purchase of C64anabalt on Google+ I was approached by the owner of the blog My Commmodore 64 and asked to write a review. So I did.

So what are you waiting for, off to My Commodore 64 you go!

Sunday, April 21, 2013

Official update of CAMP time to rejoice!


Today (yesterday) I got an email from the author of CAMP who had found my efforts on getting his old software to work on newer systems. Much to my delight he also offered to do the updates required to get CAMP to work or rather play nice with modern compilers.

Anyway here's a link to the latest version: 

This version compiles without any issues on my Crunchbang Waldorf system. Happy Camping!

Wednesday, March 13, 2013

Breathing new life into a sluggish iBook G4

Well maybe not as much new life. Let's call it an iBook G4 on dialysis, anyway the main objective was to erase and reinstall OSX 10.5 Leopard on my 12" iBook G4 1,33 GHz . Unfortunately my original DVD was "lost" so I had to go and find another solution.

Failure 1 - Burned image on DVD

I did try to burn a new DVD using an image of the original but that didn't pan out very well as the installation process got stuck in the verification phase. I did try to skip the verification process but that just left me with a totally unusuable system.

Failure 2 - External USB DVD 

I moved on to trying to boot from an external USB DVD reader/writer using instructions I found at Ben Collins blog. But for some reason my external USB DVD reader/writer just wouldn't show up in Open Firmware.

Success - Image on USB stick

When I was busy googling for options to get my external DVD functioning I briefly read something about USB sticks being friendlier in this scenario than a USB drive of some sort. So I used OSX's "Disk Utility" to write the aformentioned ISO image to a USB stick and went back to step 1 of Ben Collins instructions and success showed its pretty little face at step 4 i.e typing boot ud:,\\:tbxi in open firmware. From there on everything worked flawlessly. To get to open firmware press and hold Command+Option+O+F as soon as you power up your iBook.

Apps?

The only problem was that many of the apps I had installed on my iBook now only supports Intel architecture. But I quickly realized I'm not alone! I found the Power PC Software Archive a great collection with the latest release of many PPC apps on local mirrors. This means I that I once again can run Spotify on my iBook G4. Also I found the Mac PowerPC blog, and the great great great app MacTubes. Normally YouTube is out of the question on the old iBook, ok so I might get it to start but viewing pleasure is out of the question. MacTubes changes all that, now I can search, browse and play videos to my hearts desire with out any lag or out of sync audio what so ever.

Tuesday, March 5, 2013

shairport on 233 MHz, a success story

Well like the title says shairport works quite nice with really old hardware and I do think 16 years qualifies as really old when it comes to computers.

Here's the specs:
Toshiba Satellite 320CDS
CPU
: 233 Mhz Pentium MMX
RAM: 96 MB
HDD: SandDisk Compact Flash 8 GB Extreme IV via Lycom CF 2 IDE Bridge
OS: Debian Gnu/Linux Squeeze

When streaming music from iTunes shairport uses about 38% CPU, quite a lot compared to mpg123 that only draws 10 % CPU. But really I'm just impressed that it works. When it comes to RAM shairport uses roughly 4 % of my available 95 MB.

The output of shairport isn't really that much fun
to look at so here's a screenshot of top instead. 

I'm not going to tell you how to do it. That's pretty much covered here.


Thursday, February 28, 2013

CAMP - Console Ansi Mpeg3 Player


PLEASE NOTE: An official update of CAMP as of April 20 2013 is available here.



CAMP 1.5.3489 Console ANSI Mpeg3 Player (Rawlock skin).

Years ago I came across a really nice front end for mpg123 called CAMP by Sector7's inm. I fell in love with it at first sight. Why, well because I love ANSI art! So recently when I started drifting towards creating a console only GNU/Linux system I had this little gem in the back of my head.


CAMP File selector (Rawlock skin).

CAMP Description editor (Rawlock skin).

CAMP Forked to background.


 I had to think hard (google) to actually remember the name of the app but luckily enough the website was (and is) still alive. Sadly the last update was in 2002. But hey! Maybe it didn't need more coding?

Or did it? Compilation gave me heaps of errors. Errors I first regarded as something way above my level of competence. Here's a few lines:

fork.c:120: error: too few arguments to function ‘exit’

fork.c: In function ‘stealback’:
fork.c:137: warning: incompatible implicit declaration of built-in function ‘exit’
fork.c:137: error: too few arguments to function ‘exit’
fork.c:146: warning: incompatible implicit declaration of built-in function ‘exit’
fork.c:150: warning: incompatible implicit declaration of built-in function ‘exit’
fork.c:188: warning: incompatible implicit declaration of built-in function ‘exit’
fork.c:188: error: too few arguments to function ‘exit’


I started out by mailing the author but as of now I've still haven't heard from him or her. Then again I'm not really expecting someone to jump at troubleshooting their eleven year old code as soon as random idiot from the internet e-mails them about it. So I turned my questions to the mighty google instead.

I quickly learned that the errors were quite easily remedied:
error: too few arguments to function ‘exit’
All the instances of exit() in fork.c needed to be replaced with exit(0).

warning: incompatible implicit declaration of built-in function ‘exit’
Add #include <stdlib.h> to the top of fork.c

After this the code will compile but still generates heaps of warnings. I've compiled a list of errors and remedies if you want a warning free compile, or you could just download my pre-fixed package further down.

How to download, make and install CAMP:

0 Install the dependencies
$ sudo apt-get install zlib1g-dev mpg123
Note: First time I tried to compile CAMP on my Debian box I never had any issues with dependencies. Well except mpg123 since that is what CAMP is a front end for. If you do find any missing deps please comment and I'll add them to the list above. 

1a. Get the latest code :
$ wget -c http://sector7.nu/camp/camp-1.5.3589.tar.gz

PLEASE NOTE:  An official update of CAMP as of April 20 2013 is now available. 
$ wget -c http://www.sector7.nu/camp/camp-1.6.3744.tgz

1b. Alternatively download my updated code that works for me.
$ wget -c https://www.dropbox.com/s/510hdr4g3mutb5p/camp-1.5.3589_makkan.tar.gz

2. Unpack the downloaded file.
$ tar xvzf camp-1.5.3589.tar.gz

3. Configure CAMP
$ ./configure

4. Compile and install CAMP
$ ./make && sudo make install

5. Install the skins
$ ./make install-skins 
Note: This installs the skins in ~/.camp/skins but for some reason the individual skin dirs are not executable i.e not possible to cd into. But it can easily be fixed by issuing:
$ chmod ug+x *  
in HOME/.camp/skins/

6. Configure CAMP, start by copying camp.ini from the source code directory to your home .camp/ dir
$ cp camp.ini ~/.camp/camprc
Then edit the camprc according to your preferences e.g location of mpg123, audio output etc.

7. run CAMP!
$ camp

Hey! Why does everything look like crap in Virtual console?


CAMP in console with $TERM Linux and locale sv_SE.ISO-8859-15
CAMP in console with $TERM Linux and locale sv_SE.ISO-8859-15

CAMP in console with $TERM Linux and locale sv_SE.UTF-8
CAMP in console with $TERM Linux and locale sv_SE.UTF-8

Well I've found a way to temporarily remedy this. Although I'm still researching better solutions. The one I have right now is to use one of the following settings: 
$ charset G0 cp437
$ charset G1 cp437

If for some reason your console turns out unreadable you can always go back with. Se more in the charset manpages.
$ charset G0 iso01
$ charset G1 iso01



CAMP in console with $TERM Linux, locale sv_SE.UTF-8 and charset cp437
CAMP in console with $TERM Linux, locale sv_SE.UTF-8
and charset cp437

Hey! Why does everything look like crap in PuTTY?


This one's easy. Just set the remote character set to the ISO-8859-X that suits you or type in CP850. It's under Window>Translation

Hey! Why does everything look like crap in PuTTY when I use GNU screen?


This one's easy. Just set the remote character set to the ISO-8859-X that suits you or type in CP850. It's under Window>Translation
And do the following:

set $LANG to C
$ export LANG=C

In screen set c1 to off: 
Press crtl+a+: and type c1 off 

and set UTF8 to off: 
Press crtl+a+: and type utf8 off off

Found these GNU Screen tricks in the amnesia/epic documentation here. 


Hey! Why does everything look like crap in xterm?


Don't know haven't had this problem yet. Hint might be to try something of the above.


Short description of warnings and remedies when trying to compile CAMP: 

warning: incompatible implicit declaration of built-in function ‘strcpy’

warning: incompatible implicit declaration of built-in function ‘strlen’

warning: incompatible implicit declaration of built-in function ‘strncat’

warning: incompatible implicit declaration of built-in function ‘strchr’
Add #include <string.h> to the top of the offending file.


warning: incompatible implicit declaration of built-in function ‘exit’
Add #include <stdlib.h> to the top of the offending file.

warning: incompatible implicit declaration of built-in function ‘printf’
Add #include <stdio.h> to the top of the offending file.


Wednesday, February 27, 2013

Reducing disk writes by putting /var/log in RAM (tmpfs)

**UPDATED 2013-03-01

I've recently grown quite fond of my old Toshiba Satellite* that currently exists in the form of a digital picture frame. I'm still not sure what to do with it but I've started exploring the possibilities of removing xorg completely and focusing solely on a command line interface.

First thing is that I want to make it more robust, i.e. protect the CF-card from excessive disk writes and possible power failure. I could go with a dedicated dist such as Slitaz, Puppy or Tiny Core but I kind of like my own debian system. So I decided to go with reducing disk writes.

I've taken a few steps to reduce disk writes already. But then there is the never ending logging. So I took some of my precious RAM and put /var/log in it. I found some instructions on that here.

To accomplish this I added the following line in /etc/fstab
tmpfs  /var/log  tmpfs  size=4M,defaults,noatime,mode=0755  0  0

So far I'm only using 4 MB but I could probably lower this. I just need to keep it running for a while and see how logrotate works.

To prevent the 4 MB of log space to fill up uncontrollably I've configured logrotate from the default weekly rotation of logs to daily rotation and keeping only 1 day of backlog. I also added a size limit to each log file to 100k. But as far as "man logrotate" tells me this won't affect the logs more than once daily as the logrotate cron job only runs once each day.

As of now I've edited /etc/logrotate.conf accordingly.

# rotate log files daily

daily

# keep 2 days worth of backlogs
rotate 2


**PLEASE NOTE!

The above had little effect on my running system. Turns out many of the logs had separate instructions in:/etc/logrotate.d
Update them accordingly and you should be in business.


* Toshiba Satellite 320CDS
CPU: 233 Mhz Pentium MMX
RAM: 96 MB
HDD: SandDisk Compact Flash 8 GB Extreme IV via Lycom CF 2 IDE Bridge
OS: Debian Gnu/Linux Squeeze

What time is it?

For some reason I can't use PTT Twitter anymore so I started to look around for another console based twitter client. I found TTYtter. However I ran in to problems with the time being way off on my Digital Picture Frame. Probably because I haven't bothered to set it at all.


http://www.linuxselfhelp.com/quick/clock.html
http://wiki-old.unix.se/NTP.html

http://wiki-old.unix.se/Cron.html

Tuesday, March 23, 2010

Super simple rsync howto

This little howto contains pretty much everything you need to use rsync to back up and or synchronize two folders locally. I decided to do this writeup after after reading this article on lifehacker. I wasn't completely satisfied with the article so I did some digging to get the answers I needed. I know there's alot of rsync tutorials out there but I wrote this for my own personal use and also I tried to keep it as short as possible while explaining what's being done.

Oh, by the way rsync is really powerful and this only scratches the surface of what rsync can do. But you don't need more info to do local back ups.


Syntax:
rsync -options /source /destination 


Compare two folders
This command uses the "-v" and "-n" option to do nothing. Instead rsync prints out what would have been copied from a source folder to a destination folder. To delete files from the destination folder see notes on "--delete" below.

rsync -rvn /source /destination 

-r, --recursive recurse into directories
-v, --verbose increase verbosity
-n, --dry-run perform a trial run with no changes made


Back up one folder to another
This is all you need to back up a source directory to a destination directory. If unsure try it out with the "-n" dry run option first. To delete files from the destination folder see notes on "--delete" below.

rsync -av /source /destination 

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
    -r, --recursive recurse into directories
    -l, --links copy symlinks as symlinks
    -p, --perms preserve permissions
    -t, --times preserve modification times
    -g, --group preserve group
    -o, --owner preserve owner (super-user only)
    -D same as --devices --specials
        --devices preserve device files (super-user only) 
        --specials preserve special files


Additional tips n tricks

Test with the "dry run" -n option first to see what files would be deleted and copied.
-n, --dry-run perform a trial run with no changes made

Delete files in the destination folder that does not exist in the source folder.
--delete delete extraneous files from dest dirs

Exclude files that you don't need for instance system files.
--exclude=PATTERN exclude files matching PATTERN
example: --exclude '.DS_Store'

Compress files during transfer to save bandwidth
-z, --compress compress file data during the transfer 



Credits
rsync - man page 
techgage.com - Backing Up Your Linux

Wednesday, January 6, 2010

How to start Kazehakase in full screen mode

The long story:
I've been thinking about changing my Digital Picture Frame / Twitter frame to use/be browser instead. Partly to be able to get a useful outlet while practicing PHP-coding but also to be able to use services such as Twitter and Tom Scotts Star Wars weather.

My browser of choice is Kazehakase, a small foot print browser that can use either the Webkit or the Gecko rendering engine. It can handle alot more than Dillo but uses way less resources than Firefox. I found out about Kazehakase while reading the blog of K. Mandla.

However there is a problem. Kazehakase is not a very well documented browser. In it's manual there is a reference to using "Actions" with the browser, but the actions themselves aren't documented. Luckily enough I found out how to start Kazehakase in full screen mode by some trial and error.

The short story:
kazehakase -a "ToggleFullScreen" your_url_here

Wednesday, December 16, 2009

Software tips: Ninite - excellent tool for installing multiple freeware apps



My harddrive started to make lot's of wierd noises the a while back so I took the preemptive decision to buy a new one. And luck has it I was following Macegrs twitter-feed, where he tweeted about how terrific Ninite was when he had to reinstall Windows 7. I gave it a shot yesterday and I can do nothing more than to agree with him. I got all my apps installed quickly and effortless - just as advertised.

Wednesday, December 2, 2009

Trying to recover data from a failing hard drive

My brother in-law asked me to take a look at his girlfriends computer (a laptop) that wouldn't boot up. Quite soon it stood apparent that the computer failed to find a bootable hard drive. I had a similar issue after trying to install Fedora 11 on my laptop.
This issue, I found out, had something to do with the SATA controller being set to AHCI- or Legacy-mode. I got my drive bootable again by fiddling with this setting a couple of times and rebooting the computer. When I got the drive to boot again, I set it to AHCI-mode which is the default.
But that was my fully operational drive, not the one in question here.

Trying it on another computer

This drive wouldn't even show up in BIOS. Since it is a laptop there's really not much I can do but remove the drive and hook it up to another computer. So I bought a SATA/IDE adapter kit from Deltaco, a small device that let's me connect any 2.5" and 3.5" PATA or SATA drive to a USB-port.
I hooked the drive up and connected it to my own laptop. I could hear the drive spin up and make some other noises before it showed up in both Windows Vista (not as a regular drive, but visible in the administrative tools disk management) and Ubuntu Linux. Since it's far easier to find freeware resuce applications under Linux I went with Ubuntu.

Tools of rescue

From what I found from googling hard drive resuce under linux there seemed to be two main applications to use. GNU ddrescue and TestDisk both available in the default Ubuntu repositories under the names gddrescue and testdisk.
First it gave TestDisk a try, but since it didn't even list the drive I resorted back to a tutorial on the TestDisk site on how to recover data from a damaged hard disk using GNU ddrescue. But unfortunately this seemed to have quite little effect. All I got was that the rescue was done but no data what so ever was copied. I tried fdisk, cfdisk and gparted to access the drive directly but all of them reported failure. As I'm writing this I'm starting to wonder wether or not the "visible" drive is in fact the USB-controller and not the drive itself? (edit: It is!)

The last resort: Stick it in the freezer
So now I was stuck with the quite annoying feeling that the drive was broken beyond my ability to resuce it. And I wanted so to be the hero here and let the others bask in my geeky glory. However after a good nights sleep I started to recall another more unorthodox way of getting data from a failed drive by sticking it in the freezer.
Again I went to the great oracle of google and found many different success testimonials using this procedure. The important part seemed to be to protect the drive from moisture by bagging it in a zip lock bag before sticking it in the freezer. There were also some methods involving sticking the drive in the oven to dry it out then freezing it again, but that seemed a bit to tedious.
To protect the drive from static I first put it in a anti static bag then in a plastic freezer bag (I guess that's the swedish equivalent to a zip lock bag, minus the zip lock) then I sucked all the air out of the bags, just like my mother tought me to do when freezing freshly baked bread. Then I took another freezer bag and put the bagged drive in and sucked the air out of that one too. Then it was freezer time for the drive. My freezer is set to - 18 °C and the drive will be in there for about ten hours before I do the first test.

Conclusion
Well the freezing didn't help. My guess is that it is a mechanical problem and the only hope now is to pay the big bucks to get a specialized disk recovery firm to take a look at it.

Wednesday, May 13, 2009

Automated notification of updated of external IP

Updated 2013-03-16

Script stopped working due to changes in html2text this was resolved by adding curl as a dependency.

For my DSL line I get a dynamic IP address. On the inside it's quite easy to find out what the external IP is, but on the outside damn near impossible to find out what the IP might have changed to.
To get around that problem I wrote a little script that checks the external IP and sends me an e-mail if there has been any changes.
Dependencies: curl, html2text and ssmtp.
Source formatted by formatmysourcecode.blogspot.com and available for download on github here.
# /bin/sh

# ipquery.sh
# IP checker and updater by Markus Ulfberg 2009-05-12 

# Variables
# Path where ip.txt resides or will be created if it doesen't exist already
DIR=youdirhere
# E-mail address, both from and to
ADDRESS=your@emailadress.here
# E-mail Subject
SUBJECT="New IP number"

# Check for ip.txt and create if it doesn't exist. 
if [ ! -s $DIR/ip.txt ] 
    then 
        # Create ip.txt
        echo "ip.txt doesn't exist. Creating ip.txt ..."
        echo "0.0.0.0" > $DIR/ip.txt
    else
        echo "ip.txt exists. Continuing ..."
fi

    # Get current IP
    currentIP=`curl http://checkip.dyndns.org | html2text | grep Current | awk '{print$4}'`
    echo "Current IP: $IP"

    # Read old IP from file
    oldIP=`cat $DIR/ip.txt`
    echo "Old IP: $oldIP"

    # Compare current and old IP
    if [ $oldIP != $currentIP ]
        then
            echo "IP has changed to: $currentIP"
            # Write new IP to ip.txt
            echo $currentIP > $DIR/ip.txt
            # Set e-mail content to new IP
            CONTENT=$currentIP
            # Send the e-mail notification
            echo -e "FROM:$ADDRESS\nTO:$ADDRESS\nSUBJECT:$SUBJECT\nContent-type:text/plain\n$CONTENT\n" | `/usr/sbin/ssmtp $ADDRESS`
        else
            echo "IP is still: $currentIP"
        fi
exit 0