Blogs

Upgrading your hard drive using PartImage

roland's picture

PartImage is a pretty good tool for clonning computers, however, it may be used for migrating your hard drive.

To upgrade to a new hard drive, which has more space, you will encounter some problems. (I dual boot windows and Gentoo on mine.) I used SysrescueCD which comes with partimage, partclone and ntfsclone. I haven't tried partclone yet. Some gotchas:

  • The target partition must be of the same size or bigger
  • The partition numbers /dev/sdaX should match to make the job easier. Otherwise you'll have problems with booting linux, however, you can always modify the /etc/fstab file to assign the new device letters.
  • Reshuffling partitions may cause other problems. For instance my windows partition was first because it came with the laptop, and my linux partition followed. Since, I use linux more I figured I'd put it first.
  • Once you restore a partition from say a 100GB partition into a 200GB parition, the filesystem will assume there's only 100GB.
    You need to use GParted and resize the 200GB partition a little  and then resize it back to 200GB. It worked fine for both windows and linux.
  • If you run Windows 7, you will most likely not boot. Here's what I did:
    • I installed windows 7 using its DVD. It will create 2 new partitions. One is the boot partition, the other is the OS.
    • The used partimage to load the new image into the OS partition. 
    • Loaded GParted to resize down and the expand back the windows partition.
    • Installed grub again
    • Changed grub.cfg according to the new drive letters

It all works well.

 

A Knight's Problem v2

roland's picture

I wrote sometimes ago a post about the Knights Problem.

Among the lessons learned were:

  • C/C++ is really fast.
  • Arrays in dynamic languages are slow.
  • Resizing arrays HAS a significant cost.
  • Linked implementation in dynamic languages competes with Java/C++/C#.

An Analytical Solution

Using experimental data one cannot miss the pattern that arises. The survivors are repeated with in an interval 2^(i-1) ... 2^(i) where 2^(i-1) <= N < 2^(i) is the number of knights, and the s = 2*n - 2^i + 1

In ruby this means:

nr_knights = 50000
i = 0
while nr_knights >= 2**i do i += 1 end
survivor = 2*nr_knights - 2**i + 1

print "#{survivor}\n"

 

The algorithm is clearly O(log(N)) and you can't do much better than that with other approaches.

Gtk Screenshot in linux

roland's picture

I was trying to get a simple screenshot of my desktop (GNOME) for research, and it turned out to be a little more difficult than I thought, mainly because I don't know much about the gtk/gdk environment.

So, I tried looking at the the gnome-utils package as the gnome-screenshot package contained similar code. Anyways, its a bit convoluted to figure out how the code is partitioned, so I started my digging in the API.

Someone seems to have coded php bindings for gtk  http://php-gtk.eu/code-hints/grabbing-a-screenshot-with-gdk However, php is not a very attractive language for doing this sort of thing unless you want to take screenshots. However, to save the a the jpg you can modify the code:

while (Gtk::events_pending()) {
  Gtk::main_iteration();
}
$root = Gdk::get_default_root_window();
list($width, $height) = $root->get_size();
$pixbuf = new GdkPixbuf(Gdk::COLORSPACE_RGB, TRUE, 8, $width, $height);
$pixbuf->get_from_drawable ($root, $root->get_colormap(), 0, 0, 0, 0, $width, $height);
$error = array();
$pixbuf->save("screenshot.jpg", "jpeg", $error);

So, okay now, back to C++/C and do this right (well faster).

Vpn Client for Ubuntu Lucid

roland's picture

If you follow the directions from http://www.lamnk.com/blog/vpn/how-to-install-cisco-vpn-client-on-ubuntu-jaunty-jackalope-and-karmic-koala-64-bit/ you can get the same files for Cisco's VPN client in Lucid.

Download the zipped patched version: vpnclient-linux-x86_64-4.8.02.0030-k9.zip.

Gentoo Perl and Apache

roland's picture

Best configuration, I've found to emulate the way php works on linux. If you use SetHandler perl-script, you'll have  a great deal of problems to deal with.

<VirtualHost *:80>
  ServerName perly
  DocumentRoot /var/www/perl/perly

  <Directory /var/www/perl/perly>
    AddHandler cgi-script .pl
    Options Indexes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from All
  </Directory>
</VirtualHost>

The above configuraiton simply treats the pl files as executable ones, which may not be optimal. To use the perl-srcript handler the following also works:

<VirtualHost *:80>
  ServerName perly
  DocumentRoot /var/www/perl/perly

  <Directory /var/www/perl/perly>
    AddHandler perl-script .pl
    PerlOptions ParseHeaders
    PerlHandler ModPerl::Registry
    PerlSendHeader On
    Options Indexes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from All
  </Directory>
</VirtualHost>

Fade Effect in Flex 4

roland's picture

This is a tutorial on how to get fading images going with Flex 4. Some articles say to use the CrossFade, but in my experience it is quite a pain to work with it, mainly becuase it requires ImageBitmap for the from and to transition.

The idea is to:

1. Load all images into a group and align them centrally.

2. Once images have been loaded, fade one out, and fade the next one

Enough talk, here's the code:

Comcast is a Crappy Provider - They need to be sued for with an AntiTrust suit.

roland's picture

My cable modem which I purchased from Insight Communications, the company Comcast took over from, stopped working. I had no way of knowing it was the modem because it was indicating as if it was trying to connect to the internet.
A technician came and said that it was probably the modem. After buying a new one, all worked fine.

There was no information about a fee of service because Insight never charged us a fee. Comcast never informed me that the service would cost us $50.

Apparently we were supposed to pay about $2 more per month for their "Wire Service Insurance" which makes no sense. It wasn't my fault the equipment stopped working. All, the technician did was test their cable system.

Comcast, also jacked prices up. For a long while Insight prices were $40/month. It was so for a while as Comcast took over. then they increased the prices in October to $42.95 without any reason for it.

Now, they are jacking up prices again to $59.99 + ($1.99 for insurance) to some $60/month. That's a 50% price increase in less than a year and it is totally unfair and unreasonable.

My main concern is with their shady practices, and not informing a customer about the service charge for anything. That's something I haven't agreed to.

------------------------------------------------------------------------------------------------------------------------------
Update: 05/10/2010 (After submitting a complaint to the BBB, here's their response)
05/05/2010

Dear Roland Mai :

Thank you for contacting the Central Indiana BBB. Unfortunately, the BBB will be unable to assist you with your complaint. Although our office is not a legal agency, it is our understanding that companies have the right to charge whatever prices they deem appropriate for their company. We cannot force a company to do business outside of their policies. We are sorry we could not be of further assistance to you in this matter.

Regards,

Theresa Davis
The Better Business Bureau

ProjectEuler.net - Problem 3

roland's picture

Problem:

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Solution:

Again the solution to this problem is programmatic. First, you need a way of generating prime numbers, so you need an array of primes. Then, you'll need another array to keep your factors.

number = 600851475143
reduct = number
@primes = [2, 3, 5, 7]
@factors = []

def is_prime nr
  @primes.each do |prime|
    if nr%prime == 0
      return false
    end
  end
  true
end

def next_prime
  start = @primes.last + 1
  while true
    if is_prime(start)
      @primes << start
      return start
    else
      start += 1
    end
  end
end

while reduct != 1 do
  @primes.each do |prime|
    while(reduct%prime == 0)
      reduct = (reduct/prime).floor
      @factors << prime #unless @factors.include? prime
    end
  end
  next_prime
end

p @factors.inspect

Result: [71, 839, 1471, 6857]

Time is about 1.6 seconds, and I wonder if it can be done faster.

Syndicate content