If nvidia-settings cannot save to xorg.conf, do this

If you’re using ubuntu and having trouble with nvidia-settings saving to the /etc/X11/xorg.conf file, you may find the following tip helpful in relieving that annoyance.
Looking for something interesting when I login to one of my servers, I decided to whip up the following script I appended to my ~/.bashrc file.

close nvidia-settings

in terminal:

sudo mv /etc/X11/xorg.conf /etc/X11/xorg.conf.backup
sudo gedit /etc/X11/xorg.conf

paste the following:

Section "Device"
    Identifier     "Configured Video Device"
    Driver         "nvidia"
EndSection

save and close.

back to terminal:

sudo nvidia-settings

and save the file.

Random cow(ish) animals preaching quotes on Ubuntu 9.10

Looking for something interesting when I login to one of my servers, I decided to whip up the following script I appended to my ~/.bashrc file.

# fortune and cowsay are needed for the snippet to work, I had to install these first
sudo apt-get install fortune cowsay
COWDIR=/usr/share/cowsay/cows/; COWNUM=$(($RANDOM%$(ls $COWDIR | wc -l))); COWFILE=$(ls $COWDIR | sed -n ''$COWNUM'p'); fortune | cowsay -f $COWFILE

UPDATE:

Suggested by MrBougo, a shorter but perhaps more process intensive method:

fortune | cowsay -f $(ls /usr/share/cowsay/cows/ | shuf | head -n1)
random cowsay fortune

random cowsay fortune

Breaking down the script, the first 3 parts create variables and the last command executes the cowsay and quote.

# defines the directory of the cow files
COWDIR=/usr/share/cowsay/cows/;
 
# Get a random number limited to the number of files in the directory, making clever use of % (mod) and adding 1 to make sure it doesn't return 0
COWNUM=$(($RANDOM%$(ls $COWDIR | wc -l))+1);
 
# list the contents of the cow dir again, pipe to sed and use the number as a random line to get the name of a file
COWFILE=$(ls $COWDIR | sed -n ''$COWNUM'p');
 
# use fortune to get a quote, pipe to cowsay and use the file as defined above
fortune | cowsay -f $COWFILE;

Using Nautilus Scripting Abilities to Integrate Right Click File Enqueues with mocp

Using moc player can prove to be both beneficial and challenging. I’ve found myself going back to exaile for a few hours on random days for the simplicity in file management via a GUI. Since I prefer to use a single media player and mocp is light weight and helpful in so many other ways to me… I knew I needed a solution. It dawned on me just today how simple that solution could be with nautilus scripts.

#!/bin/bash
# Enqueue with mocp
# by Tyler "-z-" Mulligan
#
# This is a nautilus script.  When placed in ~/.gnome2/nautilus-scripts
# and chmod +x you will have the ability to right click >> enqueue files
# or directories in mocp.
#
 
mocp -a "$@"

Some other tips… [ and ] silently skip back and forward respectively at a rate of 5sec per second held… this beats the left and arrows which work interactively at 1sec per sec.

? and h bring up the help, don’t forget this. Use this, learn the commands that work for you and happy listening.

Thanks to MrBougo again for helping me simplify the script further… I was originally using a for loop which is unnecessary as the quotes will help the variable expansion and mocp -a can accept multiple files/folders.

Reducing pageweight by compressing production css and js files

I’ve been a little obsessed with improving the speed of web pages via minified javascript and css files. YUI’s team not only agrees with this, they recommend gzipping your minified js and css files. For a while I’ve been calling YUI Compressor inside my push to production scripts to do the deed. However, with this new mention of gzipping, I think might be exploring other options such as the method mentioned on the page which originally linked me to that awesome YUI writeup; minifying and gzipping javascript and css on the fly using php.

Installing Firefox 3.5.2 (Shiretoko) on Ubuntu using the default repos and customizing the icon to be more recognizable

When Firefox 3.5 came out, I along with many others, was eager to try it. For a while I ran it out of the archive directly but this caused minor issues as it’s a messy solution. At some point I noticed firefox-3.5 in the repository:

tyler@quadjutsu:~$ apt-cache search firefox |grep 3.5
abrowser-3.1 - dummy upgrade package for firefox-3.1 -> firefox-3.5
abrowser-3.1-branding - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1 - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-branding - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-dbg - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-dev - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.1-gnome-support - dummy upgrade package for firefox-3.1 -> firefox-3.5
firefox-3.5 - safe and easy web browser from Mozilla
firefox-3.5-branding - Package that ships the firefox branding
firefox-3.5-dbg - firefox-3.5 debug symbols
firefox-3.5-dev - Development files for Mozilla Firefox
firefox-3.5-gnome-support - Support for Gnome in Mozilla Firefox

and proceeded to install it with the following command:

tyler@quadjutsu:~$ sudo apt-get install firefox-3.5

It runs along-side Firefox 3.0 without a hitch. I often use the two in tandem while testing web applications.

Something that bothered me about this was the default icon isn’t as recongnizable to me as I’d like it to be.

screenshot-about-shiretoko

As such I looked into a way to replace it.

First, I found a replacement icon I liked

hp-firefox-128x128

from the following website (where other nice replacements exist).

Then I went to find the logical location of the files to replace. First I updated my ‘locate’ database file because this software is new, so it’s not yet known. This is done automatically daily on a cron but you can update it any time you’d like as follows:

tyler@quadjutsu:~$ sudo updatedb

Then I probed for icons I might think would be responsible.

tyler@quadjutsu:~$ locate firefox |grep lib |grep icon |grep 3.5
/usr/lib/firefox-3.5.2/icons
/usr/lib/firefox-3.5.2/chrome/icons
/usr/lib/firefox-3.5.2/chrome/icons/default
/usr/lib/firefox-3.5.2/chrome/icons/default/default16.png
/usr/lib/firefox-3.5.2/chrome/icons/default/default32.png
/usr/lib/firefox-3.5.2/chrome/icons/default/default48.png
/usr/lib/firefox-3.5.2/icons/document.png
/usr/lib/firefox-3.5.2/icons/mozicon128.png
/usr/lib/firefox-3.5.2/icons/mozicon16.xpm
/usr/lib/firefox-3.5.2/icons/mozicon50.xpm

The first set in the ‘/usr/lib/firefox-3.5.2/chrome/icons/’ folder will replace the icons used by the application itself (i.e. the icon in the top of your window). The latter, ‘/usr/lib/firefox-3.5.2/icons/’ will replace the ones used by shortcut icons.

Here are all the files for the icons I resized if you’d like to use them.

firefox-3.5_replacement_chrome_icons.zip
firefox-3.5_replacement_shortcut_icons.zip

bash pro-style:

cd Desktop/ && mkdir firefox_replacement_icons && cd firefox_replacement_icons
wget http://www.doknowevil.net/files/firefox-3.5_replacement_chrome_icons.zip && wget http://www.doknowevil.net/files/firefox-3.5_replacement_shortcut_icons.zip
for file in *.zip; do unzip $file; done
sudo cp chrome/* /usr/lib/firefox-3.5.2/chrome/icons/default/
sudo cp shorcuts/* /usr/lib/firefox-3.5.2/icons/

Finding the difference in time between the first and last file in a folder using bash

I was working on running some statistics on log files and it required me to figure out the difference to increase the accuracy. I came up with the following bash script:

#!/bin/bash
# get the dates
start_date=$(date --utc --date "$(ls -Rt --full-time | tail -n1 | awk '{ print $6 }')" +%s)
end_date=$(date --utc --date "$(ls -Rt --full-time | head -n2 | tail -n1 | awk '{ print $6 }')" +%s)
 
# find the difference
difference=$((end_date-start_date))
 
# echo results
echo $end_date - $start_date = $difference seconds
echo $((difference/86400)) days

Which I originally wrote as a one liner:

start_date=$(date --utc --date "$(ls -Rt --full-time | tail -n1 | awk '{ print $6 }')" +%s); end_date=$(date --utc --date "$(ls -Rt --full-time | head -n2 | tail -n1 | awk '{ print $6 }')" +%s); difference=$((end_date-start_date)); echo $end_date - $start_date = $difference seconds; echo $((difference/86400)) days;

I got a little carried away and created this beast, which still isn’t as accurate as I need it to be but it did give me some information:

map_1=nordiccastle;map_2=dance;start_date=$(date --utc --date "$(ls -Rt --full-time | tail -n1 | awk '{ print $6 }')" +%s); end_date=$(date --utc --date "$(ls -Rt --full-time | head -n2 | tail -n1 | awk '{ print $6 }')" +%s); difference=$((end_date-start_date)); echo $... Read Moreend_date - $start_date = $difference seconds; echo logs for $((difference/86400)) days; map_1_ended=$(find -name *00*.log | xargs egrep -A 4 "endmatch|timelimit -1" |grep $map_1 |wc -l); map_1_played=$(find -name *00*.log | xargs egrep "gamestart" |grep $map_1 |wc -l); echo $map_1 endmatched $map_1_ended out of $map_1_played times played; map_2_ended=$(find -name *00*.log | xargs egrep -A 4 "endmatch|timelimit -1" |grep $map_2 |wc -l); map_2_played=$(find -name *00*.log | xargs egrep "gamestart" |grep $map_2 |wc -l); echo $map_2 endmatched $map_2_ended out of $map_2_played times played

It was used to see how many times a map was played and how many times it was voted to end the match.

It should really be a separate script to allow for more organization

feh – lightweight command line image viewer and data tool

While I was looking for a better image viewer than the default ‘eye of gnome’ (eog from the command line), that’s able to play animated gifs, I came across a command line tool called feh

sudo apt-get install feh

feh is is lightweight image viewer that you can call from the command line. It can recursively view files with the following command for example:

feh -r *.jpg

You can navigate through the images with your arrow keys or space bar and backspace. Use the window close button or press esc to quit.

That’s all good and fun and I’ll probably use it from time to time but it’s not what really got me excited about this tool. It has an option for a “list” of image attributes as the screenshot below shows.

screenshot3

By typing for example

feh -l *.jpg

I would list all attributes for jpgs within a specified directory. In my screenshot, I had a text file multiple image extensions, so I did a subshell with an ‘ls’ command piped to ‘grep -v’ which negates whatever pattern that follows it. To rephrase, the command inside $() is run first and that list which has all files minus those ending in ‘.txt’ is called by the ‘feh -l’ command.

I find this very helpful for when I’m slicing images for web pages. When I’m typing out css for example:

#my_image {
  display:block;
  height:25px;
  width:120px;
  background:transparent url('img/my_image.png') 0 0 no-repeat;
}

it’s very handy to have the image dimensions. The nice thing about this raw dimension output is that I can script it further to generate CSS like above.

There are many other tricks this command can do, just type ‘man feh’ to learn more.

By the way, I’ve started using gThumb as my default image viewer, it’s still lightweight and quite powerful. It’s essentially the same as eog with some minor differences and a few major enhancements

sudo apt-get install gthumb

Generating sequences of numbers or characters with bash

If you ever needed to generate a sequence of characters or numbers, the terminal (using bash) is a quick and easy way to do it. Lets explore some examples bash’s brace expansion:

$ echo {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z

by defining a start and end character with the ‘..’ in between, we tell bash to fill in the rest and echo a list for us. Those are all lowercase, what if you wanted uppercase? simple:

$ echo {A..Z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Or both, with a few extra characters in the mix:

$ echo {A..z}
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [  ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z

It doesn’t always have to be a-z though,

$ echo {A..G}
A B C D E F G

This also works with numbers:

$ echo {0..9}
0 1 2 3 4 5 6 7 8 9
echo {0..100}
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

Descending as well as ascending

$ echo {9..0}
9 8 7 6 5 4 3 2 1 0

There is another method to generate a sequence of numbers from the command line, rightfully called ’seq’

$ seq 1 5
1
2
3
4
5

The difference here is that it’s delimited by a new line, however, we can override that with the -s (seperator) flag

$ seq -s " " 1 10
1 2 3 4 5 6 7 8 9 10

The “easy” way to listen to internet radio in Ubuntu

I started with rhythmbox like most new Ubuntu users. It seemed nice enough but not in the area I was concerned with, internet radio. I tried out many players but was disappointed with different areas of different players. From Ubuntu 8.04 to 8.10 I was using the “good” Amarok (for KDE 3.5). Disappointed by the exclusion of that version in Ubuntu Jaunty 9.04 and unimpressed with workarounds like the PPA’s, I decided to play the field. I came across Exaile, which I’ve blogged about in the past. It’s a good enough player… most of the time. It crashed too often for my likings and I’m getting sick of pkilling it.

It struck me today that I needed a simplier more streamlined solution for my simple needs. I needed a console application. Through a little research, I found moc, which happens to play shoutcast streams as I’ve become accustom to.

I then proceeded to set myself the following way:

sudo apt-get install moc
mkdir -p ~/Music/internet_radio && cd ~/Music/internet_radio
wget -r -l2 -nd -Nc -A.pls http://www.di.fm/index.php
for file in *.pls; do mocp -a $file; done
mocp

1) Installed moc
2) created a directory to download all the playlists from di.fm (since this is the station I listen to most often)
3) wget all the playlists
4) add them all to moc
5) start moc and [tab] to the play list side, enter to play

screenshot-detrateshobo-music-internet_radio

  enter  -- starts playing
  s      -- stops playing
  n      -- plays next item from the playlist
  b      -- plays previous item from the playlist
  space  -- pause
  p      -- pause

  S      -- plays at random
  R      -- repeats the same song in a loop,
	    Next (X button below) must be OFF
  X      -- switches to play sequentially
  o      -- plays a file from the Internet
  u      -- moves playlist item up
  j      -- moves playlist item down
  Ctrl+u -- adds the URL to the playlist
  g      -- searches marked string in file names
  /      -- searches marked string in file names

  r      -- rereads the directory
  T      -- switches to the theme selection menu
  f      -- toggles display mode of song titles
  TAB    -- switches marker bar between the playlist
	    and the file manager panels
  l      -- switches between displaying the playlist
            or the file manager panel
  P      -- switches full path in the playlist
  H      -- toggles hidden files view
  Ctrl-t -- toggles song duration time
  Ctrl-f -- toggles format file view
  m      -- moves to directory entered in config file
  G      -- moves to directory with currently played file
  i      -- moves to marked directory
  U      -- moves to upper directory
  a      -- adds a file to the playlist
  A      -- adds a directory recursively to the playlist
  C      -- clears the playlist
  V      -- saves the playlist
  d      -- removes marked item from the playlist
  Y      -- removes all empty items from the playlist

  < -- decreases volume by 1%
  ,      -- decreases volume by 5%
  >      -- increases volume by 1%
  .      -- increases volume by 5%

  x      -- toggles the mixer channel
  ?      -- shows help

  !      -- goes to a fast dir 1 (set in config file)
  @      -- goes to a fast dir 2
  #      -- goes to a fast dir 3
  $      -- goes to a fast dir 4
  %      -- goes to a fast dir 5
  ^      -- goes to a fast dir 6
  &      -- goes to a fast dir 7
  *      -- goes to a fast dir 8
  (      -- goes to a fast dir 9
  )      -- goes to a fast dir 10

  F1     -- executes ExecCommand1 (set in config file)
  F2     -- executes ExecCommand2
  F3     -- executes ExecCommand3
  F4     -- executes ExecCommand4
  F5     -- executes ExecCommand5
  F6     -- executes ExecCommand6
  F7     -- executes ExecCommand7
  F8     -- executes ExecCommand8
  F9     -- executes ExecCommand9
  F10    -- executes ExecCommand10

Above commands from polish linux’s article on moc audo player, great resource.

My Second Article Published on Ubuntu Magazine

My latest article on Accessing your favorite media via the terminal has been published.