Reviving a Clickfree backup drive with dd

Visiting family over the holidays of course means tuning up various computers; converting one over to linux, and doing standard OS maintenance on another. While cleaning up the system on my mothers computer, she explained that she missed her clickfree backup; following a report of disk errors, it had requested retirement, and so it was replaced by a MyPassport drive. However, it was not as simple to use as the old clickfree drive it had replaced; a common complaint from former owners of clickfree drives. Continue reading

TicTacToe

I thought that now that I am back in a couple of programming courses, I would be posting here more often. However, most of the course work I end up doing is pretty tame, and not really worth writing about. But I finally ran into a fun little puzzle with the tic-tac-toe challenge. Not with the game of course, but with the AI. It is easy enough make an AI that cannot be beat, but I wanted to make one that would intelligently try to win as well. I went with a move-weight model, scanning every possible move adding up weights, and then taking the highest weighted move.

The following is the code for the AI;

Continue reading

a better date range picker

I was unhappy with the range-datepickers I had seen so I made my own. I needed a date range picker that could select ranges of years, quarters or months, and I couldn’t find one that worked in this way. I had been using the jquery datepicker, but it didn’t have a “quarter” option; although it may have been possible to extend the datepicker to allow for this. at any rate, this is still a little rough and a little long in the code, but it works the way I wanted it to; the available months/quarters and years change in logical ways depending on the current selection in each of the other select menus. It also preserves the selected date through aggregate mode changes; a setting of March is still there when switched to “quarterly mode” and back to “monthly mode”.

date-range-picker
the date-range-picker in Google Chrome

Here’s the date-range-picker in chrome; appearance will vary depending on the browser and the implemented formating. This may be a reason to switch over to hidden select elements mirrored by styled divs in order to have cross-browser consistency and for increased visual adaptability.

Continue reading

netbeans 7.0.1 is broken

I just spent way too much time figuring out that Netbeans 7.0.1 (from the repos) is broken. If anybody else is struggling with it, stop and upgrade to the 7.1.2 version at netbeans.org. In particular, it was silently failing to integrate with Mercurial. Additionally, many of the configuration dialogs were malfunctioning. Hopefully this helps somebody.

python approximate intetegrator 2.0

A guy in calc class was working on a more complicated solution to the approximate integration problem, and so I felt inspired to make a few improvements:

#!/usr/bin/python

import sys
from math import *

def main(argv):
        try :
                if argv[0] == '-h':
                        print 'usage: apxint.py <function_of_x> <lower_bound> <upper_bound> <subinterval_width>';
                        sys.exit();
                else :
                        function_of_x = argv[0];
                        a = float(eval(argv[1]));
                        b = float(eval(argv[2]));
                        n = float(eval(argv[3]));
                        dx = (b-a)/n;

                        # trapezoid Rule
                        def f(x) :
                                return eval(function_of_x);
                        x = a;
                        t = 0.0;
                        while (x < b) :
                                t += f(x);
                                x += dx;
                                t += f(x);

                        ft = (dx/2)*t;
                        print ("Trapezoid Rule = " + str(round(ft, 6)));

                        # midpoint Rule
                        x = a + (dx/2);
                        m = 0.0;
                        while (x <= b) :
                                m += f(x);
                                x += dx;
                        print ("Midpoint Rule = " + str(round(dx*m, 6)));

                        # Simpsons Rule
                        x = a;

                        s = 0.0;
                        while (x < b) :
                                s += f(x);
                                x += dx;
                                s += 4.0*f(x);
                                x += dx;
                                s += f(x);

                        fs = (dx/3)*s;
                        print ("Simpson's Rule = " + str(round(fs,6)));
                        sys.exit(1);

        except IndexError:
                print 'usage: apxint.py <function_of_x> <lower_bound> <upper_bound> <subinterval_width>'
                sys.exit(2);

if __name__ == "__main__":
        main(sys.argv[1:])

calculator fatigue

tired of tediously punching away at my calculator doing approximate integration I was inspired to whip up a little python script for computing Trapezoid rule, Midpoint rule and Simpson’s rule:

import math
from math import sqrt, log
a,b,n = 0.0,1.0,4.0;
dx = (b-a)/n;

# trapezoid rule
def f(x) :
        return 34*(math.cos(x**2));
x = a;
t = f(x);
x += dx;
while ((x + dx) <= b) :
        tt = f(x);
        t += 2*tt;
        x += dx;
tt = f(x);
t += tt;
ft = (dx/2)*t;
print ("T = " + str(round(ft, 6)));

# midpoint rule
x = a + (dx/2);
m = 0.0;
while (x <= b) :
        mm = f(x);
        m += mm;
        x += dx;

print ("M = " + str(round(dx*m, 6)));

# Simpsons rule
x = a;
s = f(x);
x += dx;
while ((x + 3.0*dx) <= b) :
        ss = f(x);
        s += 4.0*ss;
        x += dx;
        ss = f(x);
        s += 2.0*ss;
        x += dx;

ss = f(x);
s += 4.0*ss;
x += dx;
ss = f(x);
s += ss;
fs = (dx/3)*s;
print ("S = " + str(round(fs,6)));