Wednesday, October 31, 2007

Factor screencast, take 2, basic Factor usage with the tty listener


(Image of the Factor UI, edited by Elie)

(Images taken from Elie's blog at http://fun-factor.blogspot.com/ he created them, I didn't)

The following screen cast was developed to show basic factor usage including analysis of the data stack, how one would go about looking up help on words, etc.

Also, working with the stack takes a little getting used to, that is why I went it over in the screencast. Elie has some great images that I want to show here of some basic operations. I go over a couple of them in the screencast.

"Let's take our rot example from above and practice it with the help of the illustration. Write 1 2 3 4 in your input area and hit Enter (the Return key) on your keyboard. You should see the start stack displayed in your stack area. Notice the position of the top and bottom of the stack in your stack display area. Now write "rot" (without the quotation marks) in your input area and hit Enter. You should see the rot stack displayed as above because the "rot" word caused the 3rd stack item to be moved to the top while the 1st and 2nd stack item were pushed down." -- quote from Elie's blog on stack manipulation

In the second video (part two), I demonstrate the new vocabulary modules for structuring your factor application and a short demo on what your code would look like in emacs.

Screencast (1)





Resources

Screencast

This screen cast was created gtk-recordMyDesktop. And then encoded with mencoder (ffmpeg could also be used).

  • bbrown@houston:~/tmp/capture$ mencoder factorcaptureA.ogg.3 -o f4_part2.avi -ovc lavc -ss 09:58
  • bbrown@houston:~/tmp/capture$ ffmpeg -i factorcaptureA.ogg.3 -t 00:09:58 factorscreenlin1.avi

Monday, October 29, 2007

How to post to blogger through gdata API (example in Scala Language)

In some earlier posts, I was ranting about the inadequacies of the blogger wysiwyg interface.
Actually, I have ranted a lot about this system in the last couple of days.
So, the next logical step was to create a simple blog client that could connect with the blogger/gdata API.
It actually wasn't that complex. Envision an API for posting a blog entry to blogger, and
the operations shall include: Authenticating to the service, provide a post URL to connect to,
provide the actual content and title to post. That is basically all that is required to use
the API. The documentation does a much better job of explaining the overall functionality
available through the service. And it is freely available and fairly easy to use. I created
the source below in a couple of hours. When using the API, just make sure to secure
your google username and password as it is probably use to access all of the google services.


Most of the scala source can be found below.



class ContentReader(filename: String) {
import java.io._
def readFile(): (String, String) = {
val file = Source.fromFile(filename)
var counted = file.getLines.counted
val fileData = new StringBuilder()
var title = ""
counted.foreach { (line: String) =>
if (counted.count == 0) {
title = line.substring(6).trim()
} else {
fileData.append(line)
}
}
(title, fileData.toString())
}
} // End of Class //




def createPost(service: GoogleService, blogid: String, title: String, content: String,
authorName: String, userName: String): Unit = {

// Create the entry to insert
val myEntry = new Entry()
myEntry.setTitle(new PlainTextConstruct(title))
myEntry.setContent(new PlainTextConstruct(content))
val author = new Person(authorName, null, userName)
myEntry.getAuthors().add(author);
// Ask the service to insert the new entry
val postUrl = new URL("http://www.blogger.com/feeds/" + blogid + "/posts/default")
val res = service.insert(postUrl, myEntry)
Console.println("INFO: create post");
}
def publishEntry(googleUsername: String, googlePwd: String): GoogleService = {
val myService = new GoogleService("blogger", applicationClientId)
myService.setUserCredentials(googleUsername, googlePwd)
return myService
}

Sunday, October 28, 2007

Firefox (2 and possibly 3) are unusable on Linux

This will be a short entry but Firefox on Linux is not doing the Linux community any favors. Firefox is really buggy software. At first I thought maybe I was doing something wrong like visiting websites (you know, typical web browsing tasks) but after yet another memory upgrade and yet another Ubuntu release, I am convinced there is something seriously wrong with the Firefox/Mozilla engine on the linux platform. Maybe the FF community grew too fast and the FF group were unable to adequately handle the demands of the modern web user.

There are a couple of problems that plaque my internet use. Slow startup (at least with FF2). Heavy javascript oriented pages wreak havoc on FF and the operating system.

Don't you find it a little odd that Ubuntu just recently upgraded to Firefox 2.0.0.8 only 2 weeks (or so) after the Gutsy (Ubuntu 7.10) release. I bet it was yet another Firefox memory fix or something along those lines. The worst part, as far as I can tell it works fine on the win32 platforms. Never have a problem with it. But once I start using FF on a Linux platform, I start praying to the gods I can do basic tasks like check my email or visit one of the three sites I frequently visit. It is really tragic.

My Solutions

I am trying my best to move away from FF, at least FF2. I am currently writing this blog entry under Firefox Granparadiso (FF3). But it is kind of difficult when you have been using some variation of Firefox for so long. Firefox on windows. Firefox on Redhat. Also, FF shares so many properties with Internet Explorer. I use the latest Opera on occassion and so far it seems to be very stable.

Plugins: Some articles on the web mention that Firefox doesn't work well with various plugins. I only really use Firebug and the non-commercial Flash plugin.

Tuesday, October 23, 2007

Project Diary Update: JVM Notebook

I have made the initial import of jvm language notebook source. Basically just a collection of source related to programming languages that run on the jvm. People are always curious about how one should get started working with for example Jython. Hopefully these notebook projects will show one how to do so. Here is a blurb from the project:

"The Java Virtual Machine ( Sun's JVM is called HotSpot? ) is a java bytecode intepreter which is fast, portable and secure. Jython, JRuby, Scala, ABCL (Common Lisp) are popular language implementations that run on the JVM that allow for the syntatic sugar of their particular languages. This project contains multiple subprojects and code demos related to those jvm language implementations. "

http://code.google.com/p/jvmnotebook/wiki/projectdiary

Monday, October 22, 2007

Random Ramblings: Haskell OpenGL on Win32 doesn't work at all?

Random Ramblings

I can't tell if it is a failure on the part of the Haskell OpenGL testing team (open source developer volunteers) or on my part for not doing enough research? Whatever the case may be, there seem to be a lot of issues with writing Haskell OpenGL code on the Win32 platform. If you read the mailing list, you will get 100 steps on how to either compile with FreeGLUT or get the opengl haskell source from darcs or both. With that being said, my issue is that I will compile some code and then attempt to launch the application and you can tell that the window launches but no 3D graphics and the window does not stay open.

Typically in a win32 environment. The runtime OpenGL DLL is resident on the system and the developer will only have to compile against a particular set of libraries. The Glut DLL is normally not installed but hardware vendors typically are supporting it now. I don't know if Haskell uses a FFI interface to connect to those DLLs or is it compiled against FreeGLUT. If your code is compiled against FreeGLUT that is normally more difficult to address because those libraries are needed at compile time.

Hopefully, in the near future I will write a wiki entry on how to really get OpenGL working on the win32 platform.

Friday, October 19, 2007

Why contractual oriented programming is the only way to program in java

Java, by and large is a mess. The applications and the need for java systems is not a mess. At least for the time being there is still going to be a need for java applications and developers. With that being said, there are a couple of steps that can be taken to ensure a robust system with a limited number of bugs if you abide by a couple of rules and don't get caught in some java development traps. I don't go over the most obvious ones but I have gotten interested (again) into Contract oriented programming. Contract oriented programming, design by contract; ensures a true object oriented model, allows for better testing. Here is a quote from an Eiffel document, "In human affairs, contracts are written between two parties when one of them (the supplier) performs some task for the other (the client). Each party expects some benefits from the contract, and accepts some obligations in return". Basically, with design by contract, you limit the number of side-effects that can occurr when an operation is invoked. When call a method, passing a message, you want that result to return the value you would expect. If the method returns a String, you want it to return a string. Not a generic Object or Numeric. If you have a List of elements, and there are 5 elements in that list and you expect 5 elements returned. You want a list with 5 elements.

Tony Morris, a former(?) Java developer is very fluent in the ways of Design by Contract; he created the ContractualJ framework and had this to say:

"ContractualJ is an open source project that is aimed at providing a robust API specification for the Java programming language. The ContractualJ API Specification is independent of any given context, except that it either replaces an existing core J2SE API Specification that is poorly designed, or adds a feature that does not exist in the core API. ContractualJ serves as an example of writing software using Contractual Oriented Programming, while also highlighting the flaws of the dependent tools (e.g. Java) and exemplifying the optimal workaround to the existence of these flaws. "

Here are some more quotes from Tony and as of now I don't have much to say on the subject.

"1) Interfaces define a contract for *how a class may be accessed*, but don't provide ANY information about what the class does, or how it does it.

2) Abstract classes allow (among other things) *commonly implemented processes to be encapsulated"

* All classes are declared final. Concrete behaviour inheritance is not permitted.

* All local variables and fields are declared final, unless otherwise required not to be by the context. A local variable or field that is assigned once must be declared final.


Resources

http://archive.eiffel.com/doc/manuals/technology/contract/
http://www.freepatentsonline.com/6442750.html

Tuesday, October 16, 2007

Happiest day of my life, playing FFT on Linux


When several magazines call it the best game ever, there must be something to that. I knew it was the best game 10 minutes after playing it. Also, people always ask me why my screen name on freenode is ramza; where there you go. Ramza is the main character in FFT.

http://en.wikipedia.org/wiki/Final_Fantasy_Tactics

Anyway, I am playing through the psx emulator. Awesome. Thanks linux.

Tuesday, October 9, 2007

Last Java Reader Writer Utility you will need (especially for Log Analysis)

It is actually kind of funny, it is amazingly hard to write Java classes/utilities that you can really use over and over again. The requirements of a particular project may change to where code changes to your base library are always required. Your initial library may be too slow or to cumbersome to work with. Whatever the case may be, code-reuse in the Java world is hit or miss in my opinion. Sure it happens, libraries like the Jakarta commons provide useful libraries for common tasks. But, I see way more reuse in functional programming libraries; for example, there are some common data structure libraries that have been in use for a decade. With that being said, I found this first cut at a simple read writer utility reusable.

The goal is simple; given a input file, read the file and then rewrite the output based on that file. I am using this particular code for log file analysis.

Python pseudo code:
f = open(filename)
fw = open(filename, 'w')
data = f.read()
for line in data:
fw.write(line)

The java version is just that, but I wanted to do the iteration around reading a line through callbacks (anonymous inner subclasses). I designed the following loadFile routine to use an implementation of some ReaderWriter class because you certainly want to control how you iterate through each line of the document and only to focus on that particular task as opposed to the inner details of how the file gets opened or closed. For example:

FileUtil.loadFile(filename, (new HtmlFileUtilReaderWriter()
public void read(BufferedReader bufInput, List resultList) :

while ((feed = bufInput.readLine()) != null
this.write(processLineSystemOut(feed))

That is basically it, I know it is simple but it is pretty useful idiom. You can download the full source from my googlecode repository. In the future, I hope to create a similar set of libraries in Haskell and compare and contrast between the two languages.

Download

http://haskellnotebook.googlecode.com/files/javautil_filereaderutil.zip

Sunday, October 7, 2007

Imperative Haskell OpenGL development and demo



I have finally created the camera component for the Octane Mech game. It is pretty basic, but is a basis for the camera movement. The camera, as you would expect, is a n important aspect of a 3D game.

You can read more about the source and download the demo by going to the project wiki. I would have posted it on blogger.com but the code formatting here is terrible so I will only post to the wiki now and in the future.

http://code.google.com/p/octanemech/wiki/MechProjectDiary

Monday, October 1, 2007

Haskell Cookbook(Notebook) Released on Google Code

It is always difficult to save a repository of code snippets that you consider useful. Sure, you could keep them in a blog or post them on some random wiki. These both work, but in my case, I will be hosting a Haskell cookbook including useful Haskell full source and snippets. It may include the "wrong" way to do things in Haskell and the "right" way but I will let you decide. And all examples will compile with a modern Haskell (GHC is the target system).

http://code.google.com/p/haskellnotebook/