comp
Last edited August 9, 2008
More by XTL »
Raphaël Slinckx » DBus Activation Tutorial
raphael.slinckx.net/blog/documents/dbus-tutorial
Paste number 45824: python dbus example
paste.lisp.org/display/45824
# simple python-dbus service that exposes 1 method called hello()

import gtk
import dbus
import dbus.service
import dbus.glib

class MyDBUSService(dbus.service.Object):
        def __init__(self):
                bus_name = dbus.service.BusName('org.frankhale.helloservice', bus=dbus.SessionBus())

                dbus.service.Object.__init__(self, bus_name, '/org/frankhale/helloservice')

        @dbus.service.method('org.frankhale.helloservice')
        def hello(self):
                return "Hello,World!"

myservice = MyDBUSService()
gtk.main()

#######################

# consumeservice.py

# consumes a method in a service on the dbus

import dbus

bus = dbus.SessionBus()

helloservice = bus.get_object('org.frankhale.helloservice', '/org/frankhale/helloservice')

hello = helloservice.get_dbus_method('hello', 'org.frankhale.helloservice')

print hello()
Communicating with our application using python and dbus | FlaPer87
www.flaper87.org/2008/06/04/communicating-with-our...

Communicating with our application using python and dbus

Submitted by flaper87 on Wed, 06/04/2008 - 10:32.

Hi!!

I've been programming the httpServer and the dbusServer for mouseTrap and I wanted to share how simple is communicate with our applications using dbus and its python bindings.

The piece of code we are interested in is this:

import dbus
import gobject
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop

main_loop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=main_loop)

DBUS_NAME = "org.myApp"
DBUS_PATH = "/org/myApp"

class myAppdBus(dbus.service.Object):
    """
    Our dbus Class
    """

    def __init__( self ):
        """
        Starting the dbus service.
        """
        global bus
        bus_name = dbus.service.BusName(DBUS_NAME, bus=bus)
        dbus.service.Object.__init__(self, bus_name, DBUS_PATH)

    @dbus.service.method(DBUS_NAME)
    def do( self ):
        """
        Function to execute using dbus service
        """
        print "do function has been called using dbus service"


class myApp:

    def __init__(self):
        self.loop = gobject.MainLoop()
        d = myAppdBus()

    def start(self):
        self.loop.run()


if __name__ == '__main__':
    app = myApp()
    app.start()

It is a simple script with 2 classes. The main class called myApp will call the dbus class (myAppdBus) and will start the applications main loop. The second class (myAppdBus) is the dbus class, it starts the service and register the methods that can be called using dbus.

The script can be executed like this (in my case the name of the script is dbus_script.py):


$ python dbus_script.py

After running the script it is possible to execute the do function like this:


$ dbus-send --reply-timeout=30000 --print-reply --dest=org.myApp /org/myApp org.myApp.do

This last command will show us the information related to the call we just executed. The output is something like:

flaper87@r4-p17:~$ dbus-send --reply-timeout=30000 --print-reply --dest=org.myApp
/org/myApp org.myApp.do
method return sender=:1.6 -> dest=:1.7 reply_serial=2

Ass you can the classes are really simple and show an easy way to communicate with our applications using dbus. There are a lot of options a tweaks that can be implemented so it's all in you hands now.

Rough notes: Python and D-Bus (AMK's Journal)
www.amk.ca/diary/2007/04/rough_notes_python_and_db...

Rough notes: Python and D-Bus

At work I had to figure out how to use D-Bus from Python. GNOME documentation generally sucks, so I'm posting the following notes in case they provide useful to someone (maybe me in six months).

D-Bus is a system-wide message bus used by the GNOME desktop. Python D-Bus bindings are available; in Ubuntu, they're in the python-dbus package.

There are two buses, one that's system-wide and one that's tied to your desktop session. The system-wide bus lets you talk to unique daemons, such as the Avahi server that I'm interested in, and the session bus talks to your current panel, window manager, or whatever.

To start off, you import the modules and get an object for the message bus you want:

import avahi, dbus, dbus.glib

bus = dbus.SystemBus()

Once you have the bus, you need to find an object to talk to; this is done by requesting a particular application and an object path that's a unique identifier within that application. (One application can contain many different objects; consider a window manager that has a number of windows open.) Applications are identified by Java package-style reversed domain names, like "org.freedesktop.Avahi". Avahi happens to contain constants for these identifiers, but you can also just specify them as literals:

raw_server = bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER)
#                        = ('org.freedesktop.Avahi', '/')

An object can support any number of different interfaces. Before calling any methods, you need to specify which interface you want to use. They're also identified by reversed domains:

server = dbus.Interface(raw_server, avahi.DBUS_INTERFACE_SERVER)
#                              = "org.freedesktop.Avahi.Server"

The Avahi developers don't actually document their API anywhere. You have to read some XML files that are in /usr/share/avahi/introspection that describe each interface to find out what methods are available. (Someone should write a man- or pydoc-style tool to format these descriptions.) For example, here's one method on Server:

  <method name="ResolveService">
      <arg name="interface" type="i" direction="in"/>
      <arg name="protocol" type="i" direction="in"/>
      <arg name="name" type="s" direction="in"/>
      <arg name="type" type="s" direction="in"/>
      <arg name="domain" type="s" direction="in"/>
      <arg name="aprotocol" type="i" direction="in"/>
      <arg name="flags" type="u" direction="in"/>

      <arg name="interface" type="i" direction="out"/>
      <arg name="protocol" type="i" direction="out"/>
      <arg name="name" type="s" direction="out"/>
      <arg name="type" type="s" direction="out"/>
      <arg name="domain" type="s" direction="out"/>
      <arg name="host" type="s" direction="out"/>
      <arg name="aprotocol" type="i" direction="out"/>
      <arg name="address" type="s" direction="out"/>
      <arg name="port" type="q" direction="out"/>
      <arg name="txt" type="aay" direction="out"/>
      <arg name="flags" type="u" direction="out"/>
 </method>

Annoyingly, the XML doesn't contain any comments describing the semantics of the methods, so you have to hope that the method names are understandable. I had to figure out legal values for some parameters by looking at Avahi example code. Calling the above ResolveService method looks like this:

output = server.ResolveService(interface, protocol, name, type,
                               domain, avahi.PROTO_UNSPEC, dbus.UInt32(0))
(interface2, protocol2, name2, type2, domain2, ...) = output

Interfaces can also support signals. The following example creates a new ServiceBrowser object

# Call method to create new browser, and get back an object path for it.
obj_path = server.ServiceBrowserNew(interface, protocol, '_durus._tcp',
                                    domain, dbus.UInt32(0))

# Create browser interface for the new object
browser = dbus.Interface(bus.get_object(avahi.DBUS_NAME, obj_path),
                   avahi.DBUS_INTERFACE_SERVICE_BROWSER)

# Connect signals for browser -- they'll be called as new ZeroConf
# services are seen.
browser.connect_to_signal('ItemNew', new)
browser.connect_to_signal('AllForNow', all_for_now)

Here's a small service written in Python:

import avahi, dbus, dbus.glib, dbus.service
import gobject

class Server (dbus.service.Object):
    @dbus.service.method(dbus_interface='ca.amk.Interface',
                         in_signature='', out_signature='si')
    def get_result (self):
        return ('hello', 42)


bus = dbus.SessionBus()
name = dbus.service.BusName('ca.amk.Server', bus=bus)
obj = Server(name, '/')
loop = gobject.MainLoop()
print 'Listening'
loop.run()

And here's the corresponding client:

import dbus, dbus.glib

bus = dbus.SessionBus()

server = dbus.Interface(bus.get_object('ca.amk.Server', '/'),
                        'ca.amk.Interface')
print server.get_result()

The example uses the session bus because an ordinary user can't run services on the system bus; you could spoof system daemons if that was allowed.

programming: Ask Reddit: What's the most beautiful piece of publically available source code you
programming.reddit.com/info/26dyh/comments

Julian Noble's finite state machines in Forth:

http://dec.bournemouth.ac.uk/forth/jfar/vol7/paper1/paper.html

programming: Ask Reddit: What's the most beautiful piece of publically available source code you
programming.reddit.com/info/26dyh/comments

Lua's VM is powerful and fast, but small enough to comprehend in one sitting and is nothing but extremely clean, readable ANSI C.

http://www.lua.org/

Gmail - [Chicken-users] Imlib2 question
mail.google.com/mail/?fs=1&tf=1&view=cv&search=all...
For what it's worth, I *did* convince my boss; I've used Chicken to
write a set of Web applications to supplement one of our campus
systems. None of the apps was supposed to last more than a semester --
we expected that the primary system itself would grow the same
features during that time -- so they were somewhat willing to let me
take a couple risks. But that was two semesters ago, and the Chicken
apps are still in business.

They've only served about 2 million requests so far (about 10,000 per
day right now), which is far from huge, but they can take a heavier
load. Lord knows I've had a couple problems with them (mostly
self-inflicted ones), but overall it's been a tremendous win.

Some of the things I would have used in my elevator pitch for Chicken
(keeping in mind that Web apps are my thing):

- running an application in a REPL (no compilation step; redefine
 anything you want, any time) is the rapidest development environment
 you can get, bar none.

- It's also a great maintenance environment; almost all bugs can be
 corrected live, without restarting a single process.

- works with all major databases (don't use that Fawcett guy's Oracle
 driver, though, it's a piece of crap); works great without them,
 too.

- can use third-party libraries written in C, Java, Python.

- You can compile the stuff that needs to run faster. Web apps don't
 tend to have too many hotspots, though.

- Chicken and Scheme are relatively easy to learn, and there are
 plenty of resources available.

- works great in a Unix environment, where forking processes is cheap:
 you can write small, fast programs that are suitable for Unix-style
 design (forks, pipes, etc.). Try *that* with Java. This is a good
 approach for shared-nothing, highly-scalable apps. Not that I wrote
 mine that way... ;-)

- What the community lacks in size, it makes up for in brain-power and
 supportiveness.

Everyone here knows that stuff, of course. ;-)
Premature architecture can be more dangerous than none at all, as unproved architectural hypotheses turn into straightjackets that discourage evolution and experimentation.
Why I'm not a Sysadmin anymore (reddit.com)
reddit.com/info/1kim5/comments

PHP—paraphrasing someone else—rewards lazy thinking.

Some things, like "magic quotes," reflect the true mindset of the PHP community. Now, of course, this dead horse has been beaten to a featureless blob in the PHP world (I think?), but it bears repeating: rather than focus on educating amateur programmers on learning to separate data and teaching them SQL syntax (no, it is not correct to simply splice arbitrary data into your SQL query), and rather than looking for an elegant technological solution to SQL injection (e.g. prepared statements), they replaced every goddamned apostrophe on input with \'. This legacy still haunts us \'today\'. Prepared statements are now available, but only with a PEAR library for PHP4, or in PHP5.

You cannot write correct PHP software (portable to different server configurations) that takes user input subject to magic-quotes (e.g. from GET/POST/cookie data) without working-around magic-quotes if they're enabled. There is no statement you can use to the effect of "hi, I know what I'm doing, please disable magic quotes for this script." Rather, you have to check whether magic quotes are enabled and un-munge their "encoding" when you read input data. Elegant!

Speaking of data separation and encoding, you'd think a "web programming language" would have excellent support for the W3C DOM. I haven't done much web programming that involves DOM for server-side document generation, but it's certainly an interesting idea, and ought to reduce XSS problems. Sadly, PHP's documentation on DOM is greatly incomplete (as of about one year ago).

PHP tends to be documented imprecisely, because there's only one implementation of the language. For instance, it's really, really hard figuring out what's going on with the reference semantics and the & operator—which comes off as bizarre coming from Python and CL and Scheme—when there's little documentation on the language semantics, and it's all mostly examples or tutorials with crappy terminology. It was really too hard to say "when you assign an object to a variable, the variable takes a reference to a new copy of the given object...The & operator inhibits the implicit copy and ensures the variable takes a reference to the original object."

But that requires having concepts like object identity down. For instance, in Javascript, when (a === b), and a and b are object instances, a and b are the exact same in-memory object. In PHP, === is a recursive comparison, which roughly evaluates to true when the operands are of the same type, and, for primitive data, the same value, or for compound data, their structure is congruent and their constituent data matches with ===. PHP simply has no way to compare object identity—the question "are these two variables holding references to the same in-memory object?" (Unauthenticated reason.)

There's other minutiae that really get under my skin with PHP. This is my therapy:

You can nest function definitions in PHP, but these nested functions are semantically equivalent to if you had simply defined the functions side-by-side. Why is this allowed in the first place? This is confusing when you come from languages with lexical scoping, where it does make sense to create and combine functions in a limited scope.

PHP tried to support the lambda expression of higher-order programming by implementing create_function(). This function takes an argument list and a function body as input, and returns a new function. Reasonable enough, right? Well...

  • PHP lacks a "function" datatype. When you wish to refer to some function f, you write the function name as a string: "f". Likewise, create_function() returns a string.
  • As a consequence of this poor type discipline, the PHP garbage collector has no way to know whether some lambda created with create_function is alive. The space required for each create_function call is never reclaimed before script termination. So don't think about using it in such a way where it might be called repeatedly in a loop.

The syntax alone of trying to do anything with create_function is also painful. Again, the-world-is-a-string thinking at work: the argument list and the code body are taken as strings. Clumsy!

PHP's scoping is also overly simplistic: you have "global" variables, and you have "local" variables. That's it. The local variables of some function are not visible anywhere else—of course. This is highly problematic if you'd like to use create_function to get work done, though—the body of the lambda may not refer to any variables used in the function enclosing the create_function call! You're forced to either use global variables to share the same data, or—if you don't need to modify the data which the lambda accesses (ever)—you can serialize the data with var_export and splice the result into the lambda body. Stop laughing, this probably sounds reasonable to the PHP crowd.

* Edit: magic-quote run-time pain.

James Gosling: on the Java Road
blogs.sun.com/jag/entry/the_black_hole_theory_of
I have somewhat mixed feelings about closures: they are pretty complicated. But they're an instance of what I think of as the Black Hole Theory of Design. I have a really strong memory from years ago of Guy Steele saying roughly "Lisp is a Black Hole: if you try to design something that's not Lisp, but like Lisp, you'll find that the gravitational forces on the design will suck it into the Black Hole, and it will become Lisp". [Guy doesn't actually remember making this remark, but he does say it sounds like the kind of flip comment he would make; I could also be totally mis-remembering who said it, but I haven't found any quote like it through Google].
escm - Embedded Scheme Processor
www.shiro.dreamhost.com/scheme/vault/escm.html
escm is a filter program which takes a text with embedded Scheme exressions, copies it to the output with evaluating the Scheme expressions. You can use the power of Scheme to preprocess various text files, including CGI scripts.
It's not true that CL doesn't have continuations at all. First some terminology: - There are one-shot and multi-shot continuations. The difference is that a one-shot continuations is only called once while a multi-shot continuation is called several times. - There are escaping and non-escaping continuations. If you grab a continuation, for example with call/cc, and during the execution of that call/cc invoke the continuation, this is called an escaping continuation because the continuation escapes from the current control flow. If the execution of that call/cc is already over (either normally or via the invocation of that continuation), and you call that continuation (possibly a second time), then this is called a non-escaping continuation because you are actually returning to a point of execution that was already "escaped." Scheme supports one-shot and multi-shot escaping and non-escaping continuations. Common Lisp provides the pairs catch/throw and block/return-from which are one-shot escaping continuations. Common Lisp doesn't support multi-shot or non-escaping continuations. It seems to me that in a lot of cases, Scheme's continuations are only invoked once if at all and are invoked during the extent of the respective call/cc, so are effectively used as one-shot escaping continuations. In those cases it is relatively straightforward to translate the code to Common Lisp, just replace them with the appropriate constructs (typically block/return-from). Only if they are used as multi-shot and/or as non-escaping continuations, then you need to worry more about them. For example, when continuations are used to simulate threads, or when they are used as building blocks for web applications, then they are used as non-escaping continuations.

(cond

    ((and (you are programming in lisp)
          (you are defining things like
              '(defmacro define (name-and-args &body body)
                 (if (symbolp name-and-args)
                     `(defparameter ,name-and-args ,body)
                     `(defun ,(first name-and-args) ,(rest name-and-args)
                             ,@body)))))
     (you better switch to scheme))

    ((and (you are programming in scheme)
          (you are defining things like
              '(define-syntax defun
                 (syntax-rules ()
                   ((defun name arguments . body)
                    (define (name . arguments) . body))))))
     (you better switch to lisp))

    (t
     (stay with your current language)))

Unix as programming language | Lambda the Ultimate
lambda-the-ultimate.org/node/1282#comment-14584

I haven't thought about xargs in years. It can be used as a poor man's map for infinite streams. In bash, try:

$ alias map="xargs -n 1"
$ echo /pathA/f1 /pathB/f2 | map wc -l

which will give you the number of lines in f1 and f2, like:

212 /pathA/f1
23244 /pathB/f2

Even more useful(?):

alias car="awk '{print \$1}'"
echo /pathA/f1 /pathB/f2 | map wc -l | car

Which will give you just the count for each file.

A long-time Lisp programmer like me would do something like that: (define (flatten l) (cond ((null? l) ()) ((list? l) (append (flatten (car l)) (flatten (cdr l)))) (else (list l)) ) ) which means in short: - if the list is empty, just return the empty list - if the list is a real list, flatten its car, flatten its cdr and append the resulting lists - if the list is not a list, return the "atom" in a list (so "(flatten 'a)" will be "(a)" - don't know if this is what you want...) It should work (but I haven't tested it...). But maybe it isn't in the DSSSL way of thinking...
Unix as programming language | Lambda the Ultimate
lambda-the-ultimate.org/node/1282#comment-14584
I do that sort of scripting all the time, except I write it in Scheme. Example is recursing down directories generating svn logs (svn log doesn't recurse by itself). In PLT Scheme fold-files [To use: (require (lib "file.ss"))] is your friend.
Unix as programming language | Lambda the Ultimate
lambda-the-ultimate.org/node/1282#comment-14584

Try using "find" to unfold your filesystem data, producing (but not necessarily realizing) a nice flat list of files on which to operate. For operations like "cvs add", try using "xargs" as a currying/vectorizing consumer.

If you need not even explicitly iterate, why bother recursing?

:: :: ::

and, apropos another couple of LTU threads:

jot 1000000 1 | awk '{s+=$1}END{print s}'

which, on my system at least, is far more practical than a theoretical alternative:

{ echo "0"; jot -w "%d +" 1000000 1; echo "p"; } | dc

Formatting Compact Flash as Amiga Drive - English Amiga Board
eab.abime.net/showthread.php?t=26860
Take a look at this page http://www.pscience5.net/CFPartition.htm, which *will* make your CF bootable, and install DOS and a partition manager.

Alter your bios settings to boot from USB device and power down. Pull out your main hard disk power cable. Power up, and boot from the CF drive. You can then delete the existing partitions on the CF. Power down, replace hard disk power cable. Power up change BIOS boot settings back to hard disk. Reboot back into Windows which now won't recognise the drive.

Open WinUAE (add the CF drive), and insert an "Install 3.1" adf. Edit the Icon Information for HDToolbox to make SCSI_DEVICE_NAME=uaehf.device (was scsi.device), and run HDToolbox. The drive should now be found and available for partitioning.
Will this CF adaptor work with A600? - English Amiga Board
eab.abime.net/showthread.php?t=26906
Its cool getting an amiga to boot from CF card I have done this many times

What I recomend
I would recomend that firstly you get an IDE interface card... this cost about £10-15 but offer soooo very much more than the standard IDE interface, namely 2 buffered IDE Channels (4xdevices)

you can get these from fleabay or from www.amigakit.com

you should get a cable with it two.. now from here you will have

a 2.5" 44pin port for 2.5" harddisks and two 40pin ide ports (one of these shares the primary channel.

What CF to IDE adapter to get

Now as far as CF adpater goes I would recoemend a standard 40pin IDE device its a lot less messing arround and is quite cheap..

something like this
http://cgi.ebay.co.uk/Dual-CF-2x-Com...QQcmdZViewItem

Once you have your interface, cf to ide adapter and obviously CF card you will need to configure it so the amiga can use it properly.

Installing upon an Amiga

nowdays I install using winuae (on my laptop with a CF pcmcia converter) i then take the cf card a lump it in the miggy and Whoop there it is.

but since not everyone can do this heres how... to do it amiga style

firstly connect the devices: then slap in Amiga Workbench: Install Disk

allow this to load, from here access the tools directory and run the program HDTOOLS

use the read configuration from device option (this may not always work*)

**IMPORTANT NOTICEyou will need to change the hex mask value in MAX TRANSFERS to the following value 0x1fe000

please see this thread http://eab.abime.net/showthread.php?t=25149&page=2 for more info.

now its all done save changes to drive and then exit - reboot - reload hd-tool box and partition the newly found drive to your specifications and then select to install workbench in what ever language you want, from there its all good..

Final Recomendations

I would recomend that you register WHDLoad as its just awsome for gamers with harddsisks (or cf ide cards) )

Notes:

*Get info from device- may not work
From here you will need to get the specifications from this device, a quick way would be to attach it to the PC and check its info in the bios

*you dont actually need a buffered IDE device
Allthough you dont need this (especially to begin with) i would still recomend it as it not only buffered between 2 devices on one channel (making it stable) but more so giving you a further channel for two more devices.

*Maximum boot device size
Maximum supported size for an A600 / A1200 boot drive is 4GB under OS3.0
there are ways arround this (kickflash and the such like but these are big box solutions and not intended for the A600)
The Joel Test: 12 Steps to Better Code - Joel on Software
www.joelonsoftware.com/articles/fog0000000043.html

The Joel Test

  1. Do you use source control?
  2. Can you make a build in one step?
  3. Do you make daily builds?
  4. Do you have a bug database?
  5. Do you fix bugs before writing new code?
  6. Do you have an up-to-date schedule?
  7. Do you have a spec?
  8. Do programmers have quiet working conditions?
  9. Do you use the best tools money can buy?
  10. Do you have testers?
  11. Do new candidates write code during their interview?
  12. Do you do hallway usability testing?

Reading Code is Like Reading the Talmud - Joel on Software
www.joelonsoftware.com/articles/fog0000000053.html
Talmud-reading tactics are, I think, also useful for code-reading:
  1. Work in pairs, thinking out loud to one another.
  2. Argue. If your partner says "this means X", and you either don't understand why or you have another opinion, demand an explanation.
  3. Sometimes, when dealing with a chunk of text, it's easier to figure out the middle *after* you understand what's on both ends. Therefore, if a fragment of text has you stumped, try skipping over it and seeing if you can come back to it later. (But you still have to come back to it eventually.)
  4. Read the text both "inside" and "outside". An inside reading translates the text into English (or whatever your native language is) phrase-by-phrase; an outside reading translates a larger chunk into an idiomatic paragraph. If you only read inside, you can miss the forest for the trees; if you only read outside, you can fool yourself by making broad guesses and not verifying them with details.
The Google Proxy :: MarkTAW.com
www.marktaw.com/technology/The-Google-Proxy.html
Long story short, surf the web from http://www.google.com/xhtml or www.google.com/gwt/n to get a proxied & simplified version of any page you want to visit.
Haskell and Scheme: Which One and Why? (reddit.com)
programming.reddit.com/info/nq1k/comments
Haskell indenting
 
JulianMorrison 12 points 4 months ago*

Indentation rules:

  • where { would go, if ommitted, a block starts at the offset of the next non-space

  • match that indentation, it prepends a ;, so you get new lines

  • exceed that indentation and you get the same line, continued, like backslash-newline in shell

  • fall below that indentation, and it prepends a }, you've ended the block

The content on this page is provided by a Google Notebook user, and Google assumes no responsibility for this content.