Friday, July 13, 2012

ubuntu 12.04 precise: automated installation, preseeding

To get you started: https://help.ubuntu.com/12.04/installation-guide/i386/appendix-preseed.html

I had never done this before, and had great fun getting it to work. I was installing from a USB thumb drive. So I made of those guys per usual. The help page then says

"... you need to tell the installer what file to use when you boot it. This is normally done by passing the kernel a boot parameter, either manually at boot time or by editing the bootloader configuration file (e.g. syslinux.cfg) and adding the parameter to the end of the append line(s) for the kernel."

Since we're automating this, editing syslinux.cfg seemed to be the way to go. However, taking a look at that guy, there was no append line. Sad face. I added a kernel and append line, but it wasn't changing the boot parameters. I then came across /syslinux/txt.cfg, which had what looked like the boot prompt being used. So I changed the append line there to include "preseed/file=/hd-media/preseed.cfg". Error, "Failed to retrieve the preconfiguration file". I changed this to "preseed/file=/cdrom/preseed.cfg".. and voila!

Some other newb notes:

  • If the installer stops to ask you a question, you can press escape and a menu with lots of options will popup. You can abort the installation from here.

Thursday, January 5, 2012

print urls in a css file

Print the URLs in a css file:

sed -rn 's/^.*url\((.+\.[a-z]+)\).*$/\1/p' file.css

I had a css file that referenced a some images in a directory that contained lots of images and wanted to move just the images referenced in the css file to a new directory, so ended doing something along the lines of:

for p in $(sed -rn 's/^.*url\((.+\.[a-z]+)\).*$/\1/p' file.css); do cp ~/old_path/css/$p new_path/$p; done

Tuesday, January 3, 2012

ubuntu chromium flash killing tabs

So sometimes when flash dies, like any good gift, it continues giving in the form of freezing any subsequent page that has flash. I tried killing the flash plugin process via the browser but that didn't seem to help; however, when killing the process from a terminal my browser was back to normal! Huzzah!

ps -ef | grep chromium-browser | grep flashplugin | awk '{print $2}' | xargs kill

Wednesday, December 28, 2011

jquery reverse order of children

Reverse the order of children:

(function($){
 $.fn.reverse = function(){  
  return this.each(function(){
   var i,
    $this = $(this),
    children = $this.children(),
    last_index = children.length - 1,
    last_child = $(children[last_index]);
   
   for (i = 0; i < last_index; ++i)
   {
    last_child.after($(children[i]).detach());
   };
  });
 };
})(jQuery);

Thursday, December 22, 2011

download jquery

Once or twice a month I'll find myself working on some random little project with a web UI and so of course I need jquery at which point I wonder if I have the latest version.. hence, a little script to get the latest and greatest:

#!/bin/bash

wget $(\
 wget -qO - http://docs.jquery.com/Downloading_jQuery |\
 sed -rn 's#^.*(http://code.jquery.com/jquery-[[:digit:]]+.[[:digit:]]+.[[:digit:]]+.min.js).*$#\1#p' |\
 head -n 1
 )

todo: check local jquery copy to see if there actually is a new version we need to download

Monday, December 5, 2011

string find and replace in files

The -i option to sed does in place file editing, however it "modifies" each file it touches whether it actually does any replacing or not (so the file mod time is updated). By filtering through grep first, we can be sure we are only messing with files we actually want to. Replace "happy" with "blammo":
find . -type f -print0 | xargs -0 grep -lZ "happy" | xargs -0 sed -i 's/happy/blammo/g'
The -l option to grep prints file names only and stops with the first match (so no duplicates). -Z uses null byte for separator instead of newline.

Tuesday, November 22, 2011

adding syntax highlighting on blogger

This of course started because I wanted to add syntax highlighting to this blog. That led me to an excellent post

http://heisencoder.net/2009/01/adding-syntax-highlighting-to-blogger.html

by Matt Ball about the subject; it worked, and all was well. However in a later bash script post, I noticed it was incorrectly treating a variable as a comment because it had a # in it. This led me to the git project of the syntax highlighter Mr Ball had used (and everyone seems to use), the excellent and excellently named SyntaxHighlighter by alexgorbatchev:

https://github.com/alexgorbatchev/SyntaxHighlighter

After playing around with it a bit, I updated the single line comment code for bash syntax highlighting as well as the auto-loader to allow it to take a path to a directory rather than having to specify the URL of every script that can be used. I created a git project on google code to host the files and and all seems well again. The only thing I had to do on blogger was add these lines to the end of the head section of the template


And then whenever you want to add some syntax highlighting to your post, simply edit the html to include the wrapper for the brush


here is my xml

or


console.log('hello javascript syntax highlighted world');

The idea to use google code to host the static files came from this post

http://blogazor.blogspot.com/2011/06/freely-host-css-js-other-static-files.html

by the good people at blogazor. They use svn so if you would like to use svn that howto is a great read.