Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, July 10, 2010

Painless inserting of nicely highlighted code block to my blog

If u happen to like the way i display code blocks in this blog & have read my previous post abt how i have given this blog a face-lifting, here are some extra steps i've taken to conveniently allow me to:

# 1. edit whatever code i want to display in vim

# 2. use a user-defined command (while still in vim) :Xc to process the entire (or selected lines) of the current buffer to yield nicely-highlighted code block & load it to the X11 clipboard (using xclip)

# 3. use middle mouse click (hehe, i'm using thinkpad, anyway, this can be done by doing left & right click together on mouse) to paste it to whereever i like (eg. the textarea i'm typing in right now)

Enough said, let's get into action:

# S1. Installing the required packages:

pacman -S xclip

# S2. Inserting the user-defined command :Xc to ~/.vimrc
1
2
3
4
5
func! Xclip() range
execute ":!~/bin/code2html.rb " . bufname('%') . " " . a:firstline . ":" . a:lastline . " | xclip"
endfu

com! -range=% -nargs=0 Xc <line1>,<line2>call Xclip()

# S3. Revising the existing ~/bin/code2html.rb to accept extra args
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
#!/usr/bin/env ruby

require 'rubygems'
require 'coderay'
require 'tempfile'

file = ARGV[0]
range = ARGV[1].split(':').map(&:to_i).map(&:pred) rescue nil

if range
basename = Time.now.to_i.to_s
extension = file[/\/.*?.(\.[^\.]*?)$/,1]
Tempfile.open(extension ? [basename, extension] : basename) do |fh|
fh.write(File.readlines(file)[range[0] .. range[-1]].join)
file = fh.path
end
end

puts %|#{coderay.scan_file(file).html(:line_numbers => :table)}|.
gsub('coderay','coderay').split('<pre').map{|s|
!s.include?('</pre>') ? s.gsub("\n",'').squeeze(' ') : (
parts = s.split('</pre>')
[parts[0], parts[1].gsub("\n",'').squeeze(' ')].join('</pre>')
)
}.join('<pre')

To try out, restart ur vim to edit any file, to convert the entire file, run the following command in vim:

:Xc

Alternatively, if u want to convert the selected lines (in visual mode, using Shift-v to select the specific lines):

:'<,'>Xc

And to do the pasting, just do middle (mouse) click on any textarea u are working on.

Turning off the irritating beep

# 1. Console beep:

xset b off
xset -b
xset b 0

# 2. Firefox Beep

Goto ‘about:config’, search for ‘accessibility.typeaheadfind.enablesound’ & set it to ‘false’.

Hand-rolling screenshot taking solution

Here's my handrolled solution for taking screenshot on my arch linux, using imagemagick, feh & xbindkeys for taking & displaying the just-taken screenshot on my arch linux:

# 1. Installing the required packages

pacman -S xbindkeys feh imagemagick

# 2. Scripting ~/bin/take-screenshots
1
2
3
4
5
6
7
8
#!/bin/bash

dir=~/pictures/screenshots
[ -d $dir ] || mkdir -p $dir

file=${dir}/`ls ${dir} | wc -l`.png
import -window root ${file}
feh $file

#3. Inserting the <PrtSc> key binding in ~/.xbindkeysrc
1
2
3
"~/bin/take-screenshots"
m:0x0 + c:107
Print

Restart ur X server & pressing <PrtSc> should pop up the just-taken screenshot.

Friday, July 9, 2010

Running Balsamiq on ArchLinux

Finally spent sometime to get balsamiq running on my archlinux today, after referencing this guide, these are the steps i've taken with the downloaded adobeair sdk:

# Unpacking the sdk:
sudo mkdir /opt/AIR-SDK
cd /opt/AIR-SDK
sudo tar jxvf <PATH_TO_DOWNLOADED_ADOBE_AIR_SDK>

# Unpacking the balsamiq package:
sudo mkdir -p /opt/AIR-apps/MockupsForDesktop
sudo unzip <PATH_TO_DOWNLOADED_BALSAMIQ_PKG>

But the above is not enough for my 64bit system, i need to pacman install the following as well:

sudo pacman -S lib32-gtk2 lib32-libxml2

And the very verbose command to launch balsamiq is:

export BALSAMIQ_DIR=/opt/AIR-apps/MockupsForDesktop
/opt/AIR-SDK/bin/adl -nodebug ${BALSAMIQ_DIR}/META-INF/AIR/application.xml $BALSAMIQ_DIR

Of course, i can always throw in an alias (eg. balsamiq) to make everything short & sweet !!

Friday, March 12, 2010

ck-launch-session & wallpaper

In order to allow auto mounting to work in thunar, i have to start my openbox (in ~/.xinitrc) using:

exec ck-launch-session openbox-session

So far, the problem with this approach is that the wallpaper set prior this command is lost. Meaning when launching X, i see the wallpaper for a split second, and then, it disappears altogether, and i get a plain grey background. To work around this, i added a customized X startup script ~/bin/startx:
1
2
3
#!/bin/bash
feh --bg-tile ~/pictures/wallpaper/current.jpg &
openbox-session

And amend the line in ~/.xinitrc to:

exec ck-launch-session ~/bin/startx

That's all !!

Saturday, February 6, 2010

Concatenating pdf files

Very frequently, i have to scan documents for my family. I do it using xsane, yet i always end up with many separate pdf files, one for each page of the document. A simple and sweet way to concatenate pdf files (assuming they are sequentially named, eg. 01.pdf, 02.pdf, etc) is:

for f in `ls *.pdf` ; do pdf2ps $f ; done
cat `ls *.ps` > final.ps
ps2pdf final.ps

Yeah !!

Thursday, December 24, 2009

Scanning for badblocks in a a harddisk

Just bought a new harddisk, did scanning of badblocks with:

sudo badblocks -svwf /dev/sdc1

Amazingly, for 320GB, it takes 30:33:41.35 hrs to complete.

Tuesday, October 27, 2009

Saturday, October 24, 2009

Fixing Gnome Tooltip

I've accidentally screwed up my gnome's config, as a result, all tooltips in my gnome desktop appear as meaningless black blocks. After some playing round & trial & error, i fixed the problem by replacing the following lines in ~/.gconf/desktop/gnome/interface/%gconf.xml:
1
2
tooltip_fg_color:#000000000000
tooltip_bg_color:#000000000000

With the more meaningful:
1
2
tooltip_fg_color:#000000000000
tooltip_bg_color:#ffffffffffff

That's all !!

Wednesday, September 16, 2009

m1's 3g mobile broadband on ubuntu jaunty

It turns out that getting M1's 3G mobile broadband (with Huawei's E1550) to run on ubuntu jaunty seems easier than expected, here's what u can do to get it running:

1. Since usb-modeswitch is not yet available from the ubuntu repositories, download *.deb from http://www.debian.org/distrib/packages (the 'testing' distro is good enough)

2. Download the latest usb_modeswitch.conf from http://www.draisberghof.de/usb_modeswitch/ and replace the /etc/usb_modeswitch.conf generated by the above *.deb

3. Update /etc/usb_modeswitch.conf to uncomment the section section corresponding to the brand & model for ur usb stick (for my case, it is Huawei E1550)

4. Run "sudo usb_modeswitch", and waited for a few seconds

5. Right click on the desktop's NetworkManager to select "Edit Connections"

6. Select "Mobile Broadband" tab to add a new M1 connection (the rest is pretty intuitive)

And that's all :]

Labels