Kenno’s OpenNote

Linq Read Inserted Id of a Record

Posted in C# by kenno on August 4, 2009

Suppose we have the following code sinppets:


private BlogDataContext db = new BlogDataContext ();
...

article.Created = DateTime.UtcNow;
article.Modified = DateTime.UtcNow;

db.Articles.InsertOnSubmit(article);
db.SubmitChanges( );

The ID of the article is automatically generated. How do we get the Id of the newly inserted record?

It turns out that the article is updated with the value of Id after the method SubmitChanges( ) is invoked. So, we can just get the Id this way:


int id = article.Id;

Credit: Read inserted Id from LINQ

Tagged with:

Convert wav to m4a with GNU/Linux

Posted in Debian, Unix/Linux by kenno on July 27, 2009

There are probably a gazillion ways to do this. I use FAAC, Freeware Advanced Audio Coder, to do this job.
It works very well:


faac originalfile.wav -o outputfile.m4a

Tagged with: , , , ,

FIXED: extconf.rb:8:in `require’: no such file to load — mkmf (LoadError)

Posted in Debian, Ruby, Unix/Linux by kenno on July 25, 2009

While reading Linux Journal Issue 181 today, I stumbled upon a section explaining about running Ruby on Rails on Apache using an Apache module called Phusion Passenger, also known as mod_rails.

To install Passenger, I followed the instruction provided in the magazine:

sudo gem install passenger

Unxpectedly, I got the following error:

Building native extensions. This could take a while...
ERROR: Error installing passenger:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:8:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:8

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.7 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/fastthread-1.0.7/ext/fastthread/gem_make.out

What’s happening? What did I do wrong?

According to a blog post by Al Hoang, a Ruby dev package needed to be installed. Well, I wouldn’t have a clue about this!

So, to FIX this, I need to install ruby1.8-dev:

$ sudo apt-get install ruby1.8-dev
...

Now, I’m ready to install Passenger gem:

$ sudo gem install passenger
Building native extensions. This could take a while...
Successfully installed passenger-2.2.4
1 gem installed
Installing ri documentation for passenger-2.2.4...
Installing RDoc documentation for passenger-2.2.4...

Credit: Fixing ‘mkmf’ load error Ruby in Ubuntu

Tagged with: , ,

Copy hard disks or partitions using dd

Posted in Unix/Linux by kenno on July 14, 2009

Warning: The following is for personal note only, and is not meant to be a tutorial or guide.

On Debian server at work, we have /home reside on /dev/hda6 and I want to move to a new hard disk /dev/hdb.

First, I need to format /dev/hdb using fdisk. Then use dd to copy the content from /dev/hda6 to /dev/hdb1, the newly createdd ext3 partition.

# dd if=/dev/hda6 of=/dev/hdb1 bs=1024

The above commands instruct dd to read the content from /dev/hda6 and write it to /dev/hdb1. bs=1024 sets the block size to 1024 bytes.

dd takes a while depends on how big is your hard disk. Then, there is one final step to do — to re-size /dev/hdb1 to its maximum capacity.

# e2fsck -f /dev/hdb1

Now we can resize the file system in /dev/dhb1 partition. If we don’t specify the size, then resize2fs will assume the largest:

# resize2fs /dev/hdb1

# fsck -n /dev/hb1

Tagged with: ,

Pidgin – old version of libpurple and unknown protocol

Posted in Debian by kenno on July 10, 2009

Aaaahhh… I fixed the Pidgin problem with Unknow protocol just 5 minutes after the previous post was made. I’m going to write how I found out the problem and how it has been fixed. If you’re interested, keep reading.

In the previous post, I mentioned that I would removed the Pidgin package completely including its configuration file (# apt-get –purge remove pidgin.) I did and followed by re-installation of Pidgin, unfortunately, it didn’t fix anything.

Then I checked the About dialog (Help -> About), and I noticed the libpurple 2.5.4 under Pidgin 2.5.6. This must be the source of the problem! But I remember libpurple has been upgraded to 2.5.6 and it said so in Aptitude. So what could be possibly wrong?

Screenshot-About Pidgin

A while back, I have installed Pidgin from source code, however I was quite sure that it has been properly removed — I went into the Pidgin source and execute # make uninstall.Well, according to this Bug #385639, libpurple is still present in /usr/local/

kenno@san7:/usr/local/lib
$ ls
finch                      libpurple.so.0      pkgconfig  site_ruby
gnt                        libpurple.so.0.5.4  purple-2   xemacs
libpurple-client.so.0      perl                python2.4
libpurple-client.so.0.5.4  pidgin              python2.5
kenno@san7:/usr/local/lib

So, I need to remove these unwated libraries manually:

kenno@san7:/usr/local/lib
$ sudo rm libpurple*

Now, let’s run Pidgin again…and… that’s it. The problem has been fixed!
Screenshot-Add Account2

For the record, I have upgraded Pidgin to 2.5.8 (unstable package at the time of this post is written) and everything works as expected. Now, I’m back to a happy Pidgin user.

Tagged with: ,