GET ME THE **** OUT OF HERE !

I’m sitting here across the building…

Trying to build a working mockup of my main widget that’ll handle searching ports for the entered string through the GUI and volia !

Family is driving me out of my fsck’ing mind.

Just for once in my life, I would love it if I didn’t have to stay up to after 4 in the damn morning just to get stuff done because I can’t be left alone during the afternoon !!!!!

Every one else asleep == I can get stuff done

Any one else awake == 75% less chance of being able to hear my brains internal dialogue, let along get work done (much lower chances).

Some where between merryment and torment, there lays the occasion =/

I’m definitally not looking forward to the holidays… but time stops for no man.

Not really in the mood for coding tonight, I’m tired.. Started work at like 0130 last night, finished and started reading about QT, then logged off for bed ’round 0400… And fell asleep after 0600 !!!

Looking over some of the first things I ever wrote programming wise. The creation dates are mostly november 2005 although the binary of dev-cpp is marked as feburary 2005 on my moms PC. To be honest, I have no real idea why I started learning programing =/ And it’s been at least 2 years since day one with C++.

I probably decided, I’d been around PC’s long enough and wanted to try taking it to the next level, maybe that is why… I don’t really know but I am glad I did. I know what pushed me into the level of computer studies I have, was a little trip through the WWW in that direction and the fish, ehh spider was hooked. I think it was The Unix and Internet Fundamentals HOWTO that hooked me, I wanted to learn more.

It’s December 2007 and I’ve come a long way. From a Windows XP user with no love of DOS. To practically living in a shell and thriving on *BSD systems. C++ I have not used in a long time, snored through Perl… nice tool but not my style. Java, from a book but never cared much for writing in it. C, because I wanted to see the differences between C++ and C, and what I found was a language I liked 10,000 * more lol. Always hated shell script… but came to value it as a great tool once I got used to it. Python and I didn’t hit it off and Ruby I had scoffed at early on before I decided on C++ as my first language.

One day, out of boredom I sat down and said, “Ok I’m learning Ruby” and a love affair was bourne. For my current task, I’ve been cramming the Python and QT like a mad hatter!

HTML, I also muddled with fromtime to time but rarely used. Eventually, writing in XHTML kind of replaced my need for a word processor haha! I’ve also had a longing to learn Ada but have never had the time :@, Scheme syntactically I find a bit strange but I guess I’m not used to lisp like languages.

I wonder, where the next couple of years will lead me, GOD only knows.

Thinking…

A few concept drawings of what I have in mind

Style #1: simple interface (emphasis on searching and ease of performing common actions)

Free Image Hosting at www.ImageShack.us

Style #2: orthodox interface (commander like with toolbar, I like this one xD)
Free Image Hosting at www.ImageShack.us

Style #3: balanced interface (I think it would be better with the left being a |installed software | build messages | tab-thingy).

Free Image Hosting at www.ImageShack.us

Personally I think the first style is easier to use if your not familiar with what your doing, can you get more simple then ‘search, click, click’ with a big set of buttons?

The second I really like because I think it makes best use of space and presents the most important information quickly.

The third, I think is probably a better choice since it combines #1 and #2’s ways of doing things into a fairly simple yet compact amount of space.

To be honest, I would kind of love docking / undocking elements and a very ‘cool’ look, like XFire or XMMS L&F with a Gimp or Designer style of operation but I think that would probably be a lot of work and a bit confusing to new people =/

searchlet prototypes

Oy’vey why does it have to be so easy to take a nap after chow with that dang couch =/

I suppose it is just as well that I’m finishing Dune tonight as I work because in this case the sleeper must awaken 😉

I’m trying to finish work on a routine to search the ports tree and generate the necessary stuff for a widget to display. The next phase is to experiment with how signals and slots workout through Python. Then build a more complete ‘searchlet’ module that can be integrated once the rest of work on the GUI is done. When I get a chance I’ll try to post a screen shot of the minimal searchlet in some portion of completion.

I’d also like to work on a few mock ups in designer or a few drawings in kolourpaint of possible configurations of the GUI.

edit:

I’ve basically finished the routine for searching the ports tree via psearch and getting it to display:

click to enlarge
Free Image Hosting at www.ImageShack.us

I think I’ve also figured out how to connect a C++ signal to a slot in the Python code but I’m still testing with that. The Signals & Slots mechanism is one thing that I do like a lot about QT. I’ve yet to use the Designer tool for any of this but for ease of use I probably will beyond test modules like the one pictured above.

I am using C++ documentation for most of this, so I am pretty dang glad that the best docs I’ve ever found in my time aroung computers has been the OpenBSD Manual, Vim’s :help stuff, and Trolltechs excellent offerings on qt documentation through the assistant program and the WWW. I also love that konqueror has qt, qt3, kde, and kde3 time saving web shortcuts like the wp (wikipedia) one I use so often.

Enter the Dragon

Well, so for work goes well for day one.

I’ve spent most of the day working on the configuration system, at this point it would be a lot easier to have a configuration file, so I set about to work with Pythons SafeConfigParser class and the format of the config file and options, e.t.c. There is still more to do but it is a great start, especially considering that I am not entirely comfortable with OOP under Python

I’d say greater then half the code for installing and updating the ports tree is done enough for further testing, the only issue right now is the reaction to errors sup’ing or portsnaping.

I am some what tempted to try and have a wrapper of sorts that will abstact the issue of using QT or KDE specifics but I don’t think there would be any point. I need to dig deeper into the PyQT/PyKDE, QT, and KDE documentation soon so I can work more gui_error.py.

widets ? qt : kde;

It would be nice to use as many elements of the KDE bindings as possible, so it fits better with systems running KDE, yet it would also be nice to keep to the QT bindings more strongly so it is less tied to KDE.. In the end it will probably be which ever I’m more comfortable with.

My primary goals in the coming days is to finish the options and errors modules while I start work on the ‘searchlet’, which should handle searching through ports. Until a concreate mock-up can be made of the entire main window, I think I should keep the search stuff as far away from the rest of the program as I can.

Work on the searchlet as I call it, shouldn’t be to hard to keep self-contained since I prefer to work on smaller pieces and properly prototype things when I can, I’m not a real fan of monolithic masses =

Basically 7 tenths of that battle will be wrapping my head around working with the KListView and QListView widgets. Once I’ve figured that out, it’ll be simple enough (I hope) to figureout how to make it work with displaying a search through ports. It’s just I need to get a grip on the ListView widgets before I can do that lol.

Either way, I think I have done enough for one day… 0700 Zulu Time and it would probably be nice to have a little sleep before work tomorrow 0.o

A little horsing around before bed, not pretty but considering I don’t know QT from a hole int he ground… And I’m doing this with C++ documentation for Python, I think it’s a nice ‘Hmm, how do you make a QListView object?” test:

#!/usr/bin/env python
# Neo Ports Manager (NPM) -- refer to the LICENSE file for terms and conditions

"""

"""
import sys, os
from qt import *


def main( argc, argv ):
a=QApplication( argv )
listViews=QListView()
listViews.resize(640,480)
listViews.setCaption("Qt Example - Listview") # Sets window title
# Add some columns to the list view
listViews.addColumn('Qualified name')
listViews.addColumn('Namespace')
# element is how to create a new list view item for display
element = QListViewItem(listViews, 'qName', 'namespaceURI')
# Now lets populate an array of items into view
els=[ [listViews, 'dir1', 'descr1'], [listViews, 'dir2', 'descr2'],
[listViews, 'dir3', 'descr3'] ]
for j in els:
QListViewItem(j[0], j[1], j[2])
# And sort it descending by col 1
listViews.setSorting( 1, False )


a.setMainWidget(listViews)

# draw & exec
listViews.show()
a.exec_loop()


if __name__ == "__main__":
main(len(sys.argv), sys.argv)

I don’t like that QListViewItem(j[0], j[1], j[2]) line but I was trying to translate from the C++,

for ( int i = 0 ; i < attributes.length(); i++ ) {
new QListViewItem( element, attributes.qName(i), attributes.uri(i) );
}

And I’ve yet to figure out how to better cook this up, still reading the docs here…

Some how, I think if I was the type for it, I would be stone cold drunk tonight… but as it is, I am sober as a codfish =/ Getting lit never helped any thing and my Families history is enough that it is not a fond concept. Although I must admit, a nice mixture of wodka, rum, and a little lemon juice does sound like an interesting idea.. Oh well, a spider can think lol.

trying to see if I can get QT (and possibly KDE) bindings for Ruby installed, I’ve had no luck with qtruby yet but so far korundum-3.5.5 is doing good, hope I don’t jinx it =/.

That’s not why I feel like getting drunk though, but even if I was that kind of person I’ve got to much crap to get done then to worry about it.

It is strange, how being busy is a two edged sword, in that it does have it’s advantages but it can be so damn exhausting some days !

damn, the build just blew, would be bloody nice if it would tell me *which* library is missing. Oh well, it’s not important. Hmm, what else to work on…

Wasting time with the Euclidean Algorithm

The other night, I was very bored so… When I remembered reading about the Euclidean Algorithm on Wikipedia, which is a method of finding the greatest common denominator (gcd). I fed several implementations through ye ol’time(1) to get a rough idea of what differences they made.

At first I did it in Ruby and C for comparison, then I recompiled the *.c files with maximum optimization. Tonight I added a set of Java and Python files to the setup, I’ll probably include Bourne Shell and Perl later for fun.

For any one interested,

C // no optimization
./iteration 0.00s user 0.00s system 50% cpu 0.003 total
./recursion 0.00s user 0.00s system 66% cpu 0.002 total
./original 0.00s user 0.00s system 57% cpu 0.003 total
Ruby
./iteration.rb 0.01s user 0.00s system 59% cpu 0.014 total
./recursion.rb 0.00s user 0.00s system 79% cpu 0.010 total
./original.rb 0.00s user 0.01s system 75% cpu 0.010 total
C // optimized, -O3
./iteration-o 0.00s user 0.00s system 48% cpu 0.003 total
./recursion-o 0.00s user 0.00s system 32% cpu 0.005 total
./original-o 0.00s user 0.00s system 37% cpu 0.004 total
Java
java EuclideanIteration 0.39s user 0.38s system 66% cpu 1.165 total
java EuclideanRecursion 0.48s user 0.30s system 72% cpu 1.066 total
java EuclideanOriginal 0.36s user 0.42s system 67% cpu 1.155 total
Python
./iteration.py 0.01s user 0.01s system 59% cpu 0.034 total
./recursion.py 0.01s user 0.01s system 65% cpu 0.032 total
./original.py 0.01s user 0.01s system 65% cpu 0.031 total

done with:

ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]
gcc version 3.4.6 [FreeBSD] 20060305
javac 1.5.0
Python 2.5.1

The C versions were the same sources but compiled with -O3 for the optimized
version.

I’ve assigned each outcome a score, 3 for what I feel is fastest, 2 for the intermediate (often close) and 1 for the worst and totalled it:

method  C RB C(-O3) Java Python Total
iteration 2 1 3 2 2 10
recursion 3 2 2 1 1 9
original 1 3 1 3 3 11

And the code, which I tried to keep similar. Also the gcd()/mygcd() routines were always implemented as a function because of the recursive version in the tests.

#include <stdio.h>

#define A 1071
#define B 1029

int
mygcd( int a, int b ) {
int t = 0;
while ( b != 0 ) {
t = b;
b = a % b;
a = t;
}
return a;
}

int
main(void) {
mygcd(A, B);
return 0;
}


#include <stdio.h>

#define A 1071
#define B 1029

int
mygcd( int a, int b ) {
if ( b == 0 ) {
return a;
} else {
return mygcd( b, a%b );
}
}

int
main(void) {
mygcd(A, B);
return 0;
}


#include <stdio.h>
#define A 1071
#define B 1029


int
mygcd( int a, int b ) {
while ( b != 0 ) {
if ( a > b ) {
a = a-b;
} else {
b = b-a;
}
}
return a;
}

int
main(void) {
mygcd(A, B);
return 0;
}

#!/usr/local/bin/ruby -w

def gcd(a, b)
while b != 0
t = b
b = a % b
a = t
end
return a

gcd( 1071, 1029 )
#!/usr/local/bin/ruby -w

def gcd(a,b)
if b == 0
return a
else
return gcd(b, a % b )
end
end

gcd( 1071, 1029 )
#!/usr/local/bin/ruby -w

def gcd( a, b )
while b != 0
if a > b
a = a - b
else
b = b - a
end
end
return a
end

gcd( 1071, 1029 )

class EuclideanIteration {
static final int A = 1071;
static final int B = 1029;

public static int
mygcd( int a, int b ) {
int t = 0;
while ( b != 0 ) {
t = b;
b = a % b;
a = t;
}
return a;
}

public static void
main( String[] args ) {
mygcd(A, B);
}
}



class EuclideanRecursion {
static final int A = 1071;
static final int B = 1029;

public static int
mygcd( int a, int b ) {
if ( b == 0 ) {
return a;
} else {
return mygcd( b, a%b );
}
}


public static void
main( String[] args ) {
mygcd(A, B);
}
}


class EuclideanOriginal {
static final int A = 1071;
static final int B = 1029;

public static int
mygcd( int a, int b ) {
while ( b != 0 ) {
if ( a > b ) {
a = a-b;
} else {
b = b-a;
}
}
return a;
}


public static void
main( String[] args ) {
mygcd(A, B);
}
}

#!/usr/local/bin/python

def mygcd(a, b):
while b != 0:
t = b
b = a % b
a = t
return a


mygcd( 1071, 1029 )
#!/usr/local/bin/python

def mygcd( a, b ):
if b == 0:
return a
else:
return mygcd( b, a %b )


mygcd( 1071, 1029 )
#!/usr/local/bin/python

def mygcd( a, b ):
while b != 0:
if a > b:
a = a-b
else:
b = b-a
return a


mygcd( 1071, 1029 )

An interesting Apple

Could this bring the power of the command line, to the GUI?

An interesting idea, I wonder how it works from a security and flexibility point of view.

One reason I enjoy the Unix Shell is it is very easy to solve problems with the vast and expandable workbench provided. And to automate various tasks quickly, not to mention many good programs are extensible/scriptable 🙂

The only sad thing for new users of traditional unix-likes is that the interfaces are often different, such as Emacs Lisp Vs Vim Script, Various Shell scripting languages vs DOS/Windows batch files e.t.c. Although most of the best programs I’ve used do run on many different platforms hehe.

New toy..

Managed to get some nice time off today, read some of the library books, watched Tron, Ghost Busters I, and Spaced Invaders, but most of all got to relax. I’ve also placed my VIMRC file into a cvs repository on my OpenBSD box, that should make syncing changes with my Desktop/Laptop easier, plus allow me to see what I’ve changed hehe.

Had an interesting idea and started playing with some Ruby today also.

Normally when I start a new program I make a new directory in ~/code/Lang/src/ and copy a template makefile over from ../../makefiles/ and edit it to my needs. In one of the library books, I found a GNU Makefile that essentially automates building a C/C++ program where by all C/C++ source files (subject to make handling the dependencies) are compiled into corresponding files and get linked together into the binary, nice little thing when you look at it. With a little tinkering it could probably be made semi-language independent but I don’t really have time to dig into GNU Make’s syntax and features to do that.

I’ve basically written makefiles in the past that should work with just about any ol’make program. For much the same reason I write shell scripts that should run on most any /bin/sh, because I don’t want to edit the freaking thing if I ever meet a Unix like OS it won’t run on lool.

The idea I had was a enlazynating program that by knowing a fair bit about a given languages normal build process (such as C, C++, and Java), it could then automate the process of building it without having to generate a makefile, kind of like a ‘smart-makefile’ of sorts. I’ve got a alias set in my shell so that gcc is called on the command line with my usual settings. I also tend to include a few more once the things done.

It’s probably a stupid idea to do this, a decent BSD or GNU Makefile would likely serve much better (and be worth the learning of each ones extensions to make). But I rather like to be able to just ‘have fun’ playing with and testing stuff.

Right now, it seems to be able to handle a simple compile/link of files in one directory but needs some work to properly link files in subdir’s, lots of other stuff to do. But working on it has been a good way to pass the time.

Currently I classify this as a toy rather then a program for serious usage. But if I ever finish it, I might use it just for the sake of keeping a fairly fast build/test cycle.

If I could, I would’ve made a machine to manage VHS-Tape/DVD-Disk changing but hey, I’m not an inventor when it comes to to building some thing out of thin air…

Here is what I’ve done over the past couple hours, it’s not very good but it’s a starting point for later play.

#!/usr/local/bin/ruby -w
# usage: make [opt] project [dir]
# TODO:
# rdoc...
# handle header files and linking properly in C
# support more then C
# implement a way to set lang opts/debug/profiler stuff correctly
# reduce usage of $globals
# clean up code... looks like sludge

require 'getoptlong'
require 'rdoc/usage'

$lang=nil
$project=''
$startdir=Dir.pwd
$debug=false
$profiler=false
$verbose=false

def main()

opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--lang', '-l', GetoptLong::REQUIRED_ARGUMENT ],
[ '--lang-opts', '-o', GetoptLong::REQUIRED_ARGUMENT ],
[ '--debug', '-d', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--prof', '-p', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--clean', '-c', GetoptLong::NO_ARGUMENT ],
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ]
)

begin
opts.each do |opt, arg|
case opt
when '--help'
RDoc::usage()
when '--lang'
proc_lang( arg )
when '--lang-opts'
puts "#{arg} -> --lang-opts not implemented!"
when '--debug'
$debug = true
when '--prof'
$profiler = arg
when '--verbose'
$verbose=true
end
end

if ARGV[0]
$project = ARGV[0]
end
if ARGV[1]
$startdir = ARGV[1]
end
puts ARGV #debug
puts "nn"
n=LangC.new()
n.make()

unless $lang
$stderr.puts( 'WARNING: --lang not set!, defaulting to ISO C99' )
end

# call usage() on *any* error and print the problem
rescue StandardError
puts( $! )
RDoc::usage()

end

end

def proc_lang( str )

case str
when 'c','C'
# set up for C
$lang=str
when 'c++','cpp','C++','C++','cc','CC','cxx','CXX'
# set up for C++
when 'java','Java'
# set up for Java
when 'Perl','pl', 'plx'
# Setup for Perl
when 'Python','py'
# Setup for Python
when 'Ruby','rb'
# set up for Ruby ;-)
end
end

class Lang

def make()
end

def each( startdir, &block )
dp = Dir.open(startdir) do |dir|
dir.each do |node|
if node == '.' or node == '..'
next
end
p = File.expand_path( node, startdir )
yield( p )
if File.directory?( p )
self.each( p, &block )
end
end
end
end

end # !class Lang


class LangC < Lang

@@compiler = 'gcc'
@@cflags = "-Wall -Wpointer-arith -Wcast-qual -Wcast-align " +
"-Wconversion -Waggregate-return -Wstrict-prototypes " +
"-Wmissing-prototypes -Wmissing-declarations " +
"-Wredundant-decls -Winline -Wnested-externs " +
"-std=c99 -march=i686 -pipe "
@@ldfags = nil
@@debug = '-g'
@@prof = nil
@filelist = Array.new()

# The very bloody boring constructor which serves only to override the
# defaults for our static class variables.
#
def initialize( compiler=false, cflags=false, ldflags=false,
debug=false, prof=false )

if compiler then @@compiler = compiler end
if cflags then @@cflags = cflags end
if ldflags then @@ldfags = ldflags end
if debug then @@debug = debug end
if prof then @@prof = prof end
@@ldflags=nil;@@prof=nil#debug

end

# Assemble project
def make()

@filelist = Array.new()
self.compile()
self.link()

end

# Walk the directory tree and compile all .c files into .o
#
def compile()

$stdout.puts '------- COMPILING -------' if $verbose

self.each( $startdir ) do |file|
if file =~ /.*.c$/
p = file.to_s.gsub( File.extname(file),".o" )
@filelist.push( p )
# Don't compile unless the source is newer then the object files
if File.exists?( p )
next unless timecheck(file,p)
end

system( "#{@@compiler} #{@@cflags} #{@@debug} #{@@prof} " +
"#{file} -c -o #{p}" )
end
end
end

# Walk the directory tree and link all object files
def link()

$stdout.puts '------- LINKING -------' if $verbose

@filelist.each do |obj|
system( "#{@@compiler} #{@@cflags} #{@@ldflags} #{@@debug} " +
"#{@@prof} #{obj} -o #{$startdir}/#{$project}" )
end
end

# Return true if first filename has a newer time stamp then the second
#
def timecheck( f1, f2 )
File.mtime( f1 ) > File.mtime( f2 ) ? true : false
end

end

if __FILE__ == $0
main()
end

Late night wise-cracks

“It’s 5:50 a.m., Do you know where your stack pointer is?”

I saw this one and I couldn’t help but smile 🙂

Especially since if I get any decent edits done, it’s usually after 0500 when I get to sleep.. and a fair bit of time using GDB hehehe.

“Programming is a lot like sex. One mistake and you could have to support it the rest of your life.”

“You can’t make a program without broken egos”

“There are two ways to write error-free programs; only the third one works. “

“You never finish a program, you just stop working on it.”