Saturday, October 15, 2011

Right! Kornitop PyGTK works for Mac OS X, Linux and Windows too.

Good news for me! Way Python GTK! I know all about wxPython and PyQT plus plus.

My small clipboard and dumb note page Python program works on Lin/Win/OSX without any source changes using GTK!

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

Herewith the dump.

Kornitop : Clipboard Notes Manager
Copyright: (c) 2011, Pieter Greyling (http://www.pietergreyling.com)
License : Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

Simple and corny cross-platform clipboard tracker (to start with...)
Currently built with Python and PyGTK.

You should only need these PyGTK runtimes:
For Mac OSX - http://sourceforge.net/projects/macpkg/files/PyGTK
For Win GTK - http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/
For Ubuntu - already there
Others - please check

BEWARE: By design, text entries from the system clipboard are persisted
to a file and reloaded upon restart of the application.

Kornitop began life as Kornitop for Windows programmed in Delphi:
http://www.chileserve.net/component/option,com_joomlaboard/Itemid,73/func,listcat/catid,3/lang,en/
http://www.chileserve.net/component/option,com_joomlaboard/Itemid,73/func,view/id,18/catid,4/lang,en/

I wanted to build an open source version using a cross-platform dynamic language and GUI toolkit.
After much messing around I picked on Python with PyGTK. So far I am pretty happy with this decision.

To get going I used the PyGTK 2.0 Tutorial, section 15.1.5. A Clipboard Example, as a starting point:
http://www.pygtk.org/pygtk2tutorial/
http://www.pygtk.org/pygtk2tutorial/ch-NewInPyGTK2.2.html#sec-ClipboardExample
http://www.pygtk.org/pygtk2tutorial/examples/clipboard.py

==Simple and corny cross-platform clipboard tracker (to start with...)==
Currently built with Python and PyGTK.

Saturday, September 17, 2011

Philosophy and Programming - Trapped between a static rock and dynamic hell

If you understand this, I hereby document it for you.

Here I am, sitting in yet another "technical management"-driven software design meeting.
(It got signed-off and it is being dumped on the monkeys and organ grinder(s))

I am a gonner.

Types or not ? Is this a proper question? What is "not" a type? What is a "type" anyway? (the teddy bears we make up to comfort us?)

A person must write a program that does the job and write it quickly.

The program must work - first strong hint of disaster.
What is the meaning of "does the job"?
Oh golly I am lost already... Nobody has a clue of what they really want in this meeting.

Second strong hint of disaster: They look at me expectantly. (WTF?).

"Design specification" after-breath: "Please be ready to change the program whenever I say so.".

I smile cunningly.

Bugger, now the design includes entropy (BTW. In secret, I think of this).
Entropy has something to do with chaos, right!. Sure, I like thinking.

This makes me think about how this situation potentially contributes to declining cosmic order (I like thinking big). This must slot in somewhere cosmic, right? Perhaps this clear lunacy has side-effects that bolsters both madness and coherence. (I am losing it - flashback)

OK, so, this situation is nothing more than growing chaos cascading into irreversible and predictable final chaos. Right? Oh no, more like a guaranteed spiral into escalating less-meaning and less-order.

Right, Persistent Entropy. I get it.
(What is the meaning of the word "Job"? The kids? Not being labeled a failure?)

How do I coast myself through this meeting? Smiling? Nodding?
Aahh! I am a techie so I can hide behind a facade of apparent comprehension.

Yes! "We" can do anything I say.
(After all, I write in MonoFont (crucifixion by meeting madness re-approaches)).
((It dawns on me that we are all globally and irrevocably insane)
(Our fellows are scrabbling and dying as we speak and we are still trapped right here))
Get a firm grip. Grasp or drink something.

What!?
"Please communicate this design and build the architecture"?
"Build a team from the peers in your team"?
WTF is a "Peer"? No way are you touching my keyboard!
(I take it home anyway)

I would give a kingdom for a diagram right now.

I drift into deep-thought (numbness is sure to follow) I imagine myself from space.
Where did my youth go? And I am still so young.

As nuclear coherency encroaches, I find a pivot.
Dynamic typing makes us write programs faster. I drift further.
"Dynamic typing"? I am desperate.
Static typing makes us write programs that allows compilers to scrutinize our code for errors that static typing disallows us from committing.
(Sort of like things before they happen)
So static compilers are written to be rigid about our predictions. (Cool!)

Bugger. Am I in so much crap.

Sunday, September 11, 2011

Philosophy and Programming - Unpleasant Lesson Three

We can fight as much as we want. Our shine is always a reflection of our special enemy.
Myself.

Philosophy and Programming - Unpleasant Lesson Two

Programming Languages deserve no more respect than natural languages.

Programming languages enable immense power. Programming languages are not fully comprehended by modern global society.

Since the natural world is falling apart thanks to human stupidity, what can immensely powerful programmers do?

Programmers are clever. Programmers can help to fix the world.

Philosophy and Programming - Unpleasant Lesson One

So, by being programmers we believe and behave as elite intellectuals and are apparently by-default exempt from the implicit side-effects of our behaviour?

Have we as implicit white-collar workers easily been suckered into offering services without social protection? Have we signed our intellectual property over to short-term rhinos for the sake of peace? How many clever programmers care about ethics? I say so many care about reflection yet few about projection.

Reflection implies staring into oneself. Projection implies throwing oneself into the unknown.

I strongly do not believe that people who can write intricate meta-programs in the convoluted crappy programming languages we have re-designed over and over for the last 60 years were and are stupid enough not to comprehend the crate load of social side-effects they are responsible for. If geeks are not capable of projecting the consequences of their own labour and existence into society then they are either in a superior state of self-denial or stupid.

Our best programmers claim that a programming language designed in the image of man is the best programming language to solve real-world problems with. So much for evolution. We can do better.

As programmers we have relentlessly and by default continued to distance ourselves from society whilst desperately trying to impress and belong to it.

Society has inevitably detected the Catch-22 enforced by co-existing with nerds like us; The more nerd you are the less you belong yet the more you are required. You need to fix the crap you create.

Nerds continue to design abstruse programming languages. We continue to re-define corresponding real-world practical challenges in the light of our programming languages. We delight in justifying our new designs upon our new-found and convenient re-interpretations of age-old problems.

Computer nerds (almost) never fully gang together for the benefit of society but instead act like a bunch of selfish television actors. Nerd compromises are dimly lit for the sake of the non-programmer public. Considering the wealth of intellectual power behind programmers, a concentrated effort targeted towards global better well-being is not beyond imagination.

Computer programming is no longer singularly applied science. It has become a victim of social awareness and thus from now on belongs partly to the study of social science.

Thursday, July 28, 2011

Configured and tested Alex Gorbatchev's open source syntax highlighter with Blogger

I configured Alex Gorbatchev's SyntaxHighlighter in my Blogger Template according to the instructions on the following pages:

http://alexgorbatchev.com/SyntaxHighlighter/manual/installation.html
http://alexgorbatchev.com/SyntaxHighlighter/hosting.html
http://mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html

Here follows some test code that appears to render mostly OK (except line numbering gets out of sync with some brushes). My system setup is:
Ubuntu 11.04 Natty Narwhal (GNU/Linux i686, 2.6.38-10-generic)
Chromium 12.0.742.112 (90304)
Opera 11.50 Build 1074
Firefox 5.0 / Canonical - 1.0

Using the SQL brush:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
SELECT *
FROM users
WHERE user_id = 122333;

Using the JavaScript brush with the "pre class="brush: js"" method:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
/**
 * SyntaxHighlighter for JavaScript
 */
function foo() {
    if (counter <= 10)
        return;
    // it works!
}

Using the JavaScript brush with the "script type="syntaxhighlighter" class="brush: js"" method:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK

Using the Lua brush from:
http://www.undermyhat.org/blog/wp-content/uploads/2009/09/shBrushLua.js
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
--
-- SyntaxHighlighter brush for Lua
--
-- make a function the traditional way
function func(a)
    print("-- func: "..a)
end
-- make a function the functional way
local func2 = function(a)
    print("-- func2: "..a)
end
-- call them
func  ("test argument")
func2 ("test argument")
-- anonymous function called immediately
local oneplustwotimesfourisnine = 1 + (function(n) return n*2 end)(4)
-- generate random numbers/simulate a dice throw
local r = newrandom()
for i=1,6 do
    print("dice "..i.." rolled "..r:random(6))
end
-- an if
if android_sdk() == "9" then
    print "Gingerbread"
end

Some Java code:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
/**
 * SyntaxHighlighter for Java
 */
@LuaMethod(global = true)
public String android_sdk() {
    String sdk_level = String.format("%s", VERSION.SDK_INT);
    return sdk_level;
}

A touch of Groovy:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
/**
 * SyntaxHighlighter for Groovy
 */
import groovy.swing.SwingBuilder
import javax.swing.*

def swingBuilder = new SwingBuilder()
swingBuilder.frame(title:"Groovy SwingBuilder", 
                   defaultCloseOperation:JFrame.EXIT_ON_CLOSE, 
                   size:[444,333],
                   show:true) {
  panel(){
    label("Swinging with Groovy!")
  }
}

Using the Python brush:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
#!/usr/bin/env python
import sys

#-- some test functions -----------------------------
def fa(): pass
def fb(): pass
def fc(): pass

#-- a dull class ------------------------------------
class Skeleton():
    def __init__(value1, value2):
        self.field1 = value1
        self.field2 = value2
 
sl = str.lower # function alias ---------------------
print(sl("I_USED_TO_BE_UPPERCASE"))

av = sys.api_version
aa = sys.argv
print("-- testing 1 2 3...")    
print("-- version: %s" % av)
for a in aa: print a

The Perl brush:
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
#!/usr/bin/perl
# split path into seperate lines for easy viewing
print "\n>>\n>> $0: splitting PATH...\n>>\n";
my $i=0, $l=0, $t=0;
foreach ( split(/:/, $ENV{PATH}) ) {
  $i++; $l=length; $t+=$l;
  print "\n[$i]\t[$l]\t[$t]\t$_" ;
}
print "\n\n>>\n>> $0: DONE!.....\n>>\n";

AND! Getting totally carried away with some cool (Google) Go language GTK sample code using the brush at:
http://d.allistersanchez.com/js/shBrushGo.js
See the following post for more info:
http://hackgolang.blogspot.com/2010/05/syntax-highlighting-for-golang.html
Chromium: line numbers misaligned / Opera: OK / Firefox: OK
//
// SyntaxHighlighter for the Go programming language
//

package main

import (
  "os"
  "github.com/mattn/go-gtk/gtk"
  "strconv"
)

func main() {
  gtk.Init(&os.Args)
  window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
  window.SetTitle("GTK Notebook")
  window.Connect("destroy", gtk.MainQuit)

  notebook := gtk.Notebook()
  for n := 1; n <= 10; n++ {
    page := gtk.Frame("demo" + strconv.Itoa(n))
    notebook.AppendPage(page, gtk.Label("demo"+strconv.Itoa(n)))

    vbox := gtk.HBox(false, 1)

    prev := gtk.ButtonWithLabel("go prev")
    prev.Clicked(func() {
      notebook.PrevPage()
    })
    vbox.Add(prev)

    next := gtk.ButtonWithLabel("go next")
    next.Clicked(func() {
      notebook.NextPage()
    })
    vbox.Add(next)

    page.Add(vbox)
  }

  window.Add(notebook)
  window.SetSizeRequest(400, 200)
  window.ShowAll()

  gtk.Main()
}
For intrigued parties, check out Go-GTK at: http://mattn.github.com/go-gtk/