HUMBUG logo


HUMBUGers

Feed: rss rdf opml

April 14, 2015

Adrian SuttonPrinting Only Part of a grep Match

It’s not uncommon to want to find a particular line in a file and print just a part of it.  For example, if we wanted to find the total memory on a machine we could use:

grep '^MemTotal:' /proc/meminfo | 
sed -e 's/^MemTotal:\s*\([0-9]*\).*/\1/'

Which does the job but duplicates a bunch of the matching regex. If you’re using a reasonably recent gnu grep, you can use it’s support for perl regex syntax and the \K operator:

grep -Po '^(MemTotal:\s*)\K[0-9]*' /proc/meminfo

The -P is for perl regex, and the o option causes grep to output only what is matched. You can see though that we’re actually matching the MemTotal: at the start of the line yet somehow it doesn’t wind up in the output.  That’s the magic of \K which excludes the token immediately prior to it from the matched text (without rewinding the stream and attempting a different match for that text).

Update

Alexandre Niveau emailed me to point out that in this particular case (and probably most others where I’d be tempted to use \K with grep) grep is completely superfluous and we can just use sed with the -n flag:

sed -n -e 's/^MemTotal:\s*\([0-9]*\).*/\1/p' /proc/meminfo

The -n disables automatic printing of lines and the ‘p’ at the end of the regex prints the matching lines. Definitely good to know – thanks Alexandre.

April 14, 2015 11:02 PM

April 10, 2015

Ben MartinTiny Tim improves and gets Smaller

I finally switched Tiny Tim over to a lipo battery. Almost everything worked when I tested the new battery, the only thing that failed in a major way were the two 2812 LEDs which, either didn't come on or came on for a very quick moment and went dark. So Tim is now smaller again without the "huge" AA battery pack at it's tail.


The 2812 story was interesting. It wasn't going to be happy jumping to the 7.6v of the 2S lipo. So I tried various voltage divider setups which didn't work either. I ended up using a common 5v regulator and the lights work fine again. I think I was maybe using too high resistor values in the divider and the 2812s didn't like it. At any rate, they apparently want a good regulated power source, and I wasn't giving it one before I switched over to using the regulator.

On the whole, going from 5-6v of the AA pack to 7.6v has made it a snappier mover. I tried it initially with the battery on the bench and found it would lift the back off the desk under hard break.

Next up is probably attaching a claw or drop mechanism and ultrasound sensor and then take on the Sparkfun autonomous ping-pong ball into cup challenge. I'll probably control it via wireless from a second on board micro-controller. The drop, ultrasound, and autonomous navigation micro (and additional battery) can all be put into a single "module" that I can then bolt to Tim. All the navigation micro needs to do is control the differential drive like a remote control would. This way, the existing micro etc on Tim doesn't change at all in order for the challenge to be accepted.


April 10, 2015 01:11 PM

Clinton RoyPyCon Australia 2015 Proposal Writing Working Bee

Writing your first conference proposal can be difficult, so we’re running a working bee at UQ on Saturday 11th (in conjunction with Humbug). If you’ve never written a conference proposal before, or you’d like yours given the once over, please come along, register over at meetup.


Filed under: Uncategorized

April 10, 2015 08:57 AM

April 09, 2015

Adrian SuttonEmoji One – Open source emoji designed for the web.

Mostly so I can find this again later when I inevitably need it, Emoji One is a creative commons licensed collection of Emoji and related tools for the web.

April 09, 2015 12:55 AM

March 30, 2015

Blue HackersSleep: How to nap like a pro | BBC Future

March 30, 2015 11:43 PM

March 28, 2015

Clinton RoyPyCon Australia 2015 Call for Proposals is Open!

PyCon Australia 2015 is pleased to announce that its Call for Proposals is now open!
The conference this year will be held on Saturday 1st and Sunday 2nd August 2015 in Brisbane. We’ll also be featuring a day of Miniconfs on Friday 31st July.

The deadline for proposal submission is Friday 8th May, 2015.

PyCon Australia attracts professional developers from all walks of life, including industry, government, and science, as well as enthusiast and student developers. We’re looking for proposals for presentations and tutorials on any aspect of Python programming, at all skill levels from novice to advanced.

Presentation subjects may range from reports on open source, academic or commercial projects; or even tutorials and case studies. If a presentation is interesting and useful to the Python community, it will be considered for inclusion in the program.

We’re especially interested in short presentations that will teach conference-goers something new and useful. Can you show attendees how to use a module? Explore a Python language feature? Package an application?

Miniconfs

Four Miniconfs will be held on Friday 31st July, as a prelude to the main conference. Miniconfs are run by community members and are separate to the main conference. If you are a first time speaker, or your talk is targeted to a particular field, the Miniconfs might be a better fit than the main part of the conference. If your proposal is not selected for the main part of the conference, it may be selected for one of our Miniconfs:

DjangoCon AU is the annual conference of Django users in the Southern Hemisphere. It covers all aspects of web software development, from design to deployment – and, of course, the use of the Django framework itself. It provides an excellent opportunity to discuss the state of the art of web software development with other developers and designers.

The Python in Education Miniconf aims to bring together community workshop organisers, professional Python instructors and professional educators across primary, secondary and tertiary levels to share their experiences and requirements, and identify areas of potential collaboration with each other and also with the broader Python community.

The Science and Data Miniconf is a forum for people using Python to tackle problems in science and data analysis. It aims to cover commercial and research interests in applications of science, engineering, mathematics, finance, and data analysis using Python, including AI and ‘big data’ topics.

The OpenStack Miniconf is dedicated to talks related to the OpenStack project and we welcome proposals of all kinds: technical, community, infrastructure or code talks/discussions; academic or commercial applications; or even tutorials and case studies. If a presentation is interesting and useful to the OpenStack community, it will be considered for inclusion. We also welcome talks that have been given previously in different events.

Full details: http://2015.pycon-au.org/cfp


Filed under: Uncategorized

March 28, 2015 05:31 AM

March 17, 2015

Ben MartinGoogle Breakpad and the post crash experience

Google Breakpad has many components to it, but at the basic level it lets you capture information at the time a crash occurs and upload that to the net. A really cute part of Breakpad is that the binary doesn't need to have the debug symbols in it, you don't even need to have them on the client machine at any location. When you build version $githash then you use a breakpad tool to copy out the debug symbols into separate files. When the user discovers a crash they upload a minidump file to a server of your selecting. Then you can combine the extracted symbols from build time and the minidump file to generate a backtrace with line number information. So software users don't have to know about gdb or lldb or whatnot and how to make a backtrace and where to paste it.



I recently updated FontForge's use of breakpad to use a small server on localhost to report the bug. The application dmg file for fontforge will soon also include the extracted symbols for the build. By telling breakpad to use a local server, that server can lookup the symbols that are shipped and generate a human readable backtrace with line number information. Because its also a web interface and running locally, it can spawn a browser on itself. So instead of getting the Mac dialog supplied by the osx crash reporter app telling you that there was a crash, you get a web page telling you the same thing. But the web page can use jQuery/Bootstrap (or $ui tool of choice) and ask what the user was doing and offer many ways to proceed from there depending on how the user wants to report things. The https://gist.github.com/ site can be used to report without any login or user accounts. It's also rather handy as a place to checking larger backtraces that might be, maybe, 50-100kb.

But once you can upload to gist, you can get a http and other URL links to the new gist. So it makes sense from there to offer to make a new github issue for the user too. And in that new issue include the link to the gist page so that developers can get at the full backtrace. It turns out that you can do this last part, which requires user login to github, by redirecting to github/.../issues/new and passing title and body GET parameters. While there is a github API, to report a new issue using it you would need to do OAuth first. But in the libre world it's not so simple to have a location to store the OAuth secure token for next time around. So the GET redirect trick nicely gets around that situation.


For those interested in this, the gist upload and callback to subsequently make a github issue are both available. The Google Breakpad hands over the minidump to a POST method which then massages the minidump into the backtrace and spawns a browser on itself. The GET serves up all the html, css, js, and other assets to the browser and that served html/js is what I link to at the start of the paragraph which is where the actual upload/reporting of the backtrace takes place.

The only thing left to do is to respond to the backtraces that come in and everybody gets a more stable FontForge out of the deal. It might be interesting to send off reports to a Socorro server too so that statistics month on month can be easily available.

March 17, 2015 04:33 AM

March 15, 2015

Blue HackersDalek Relaxation for Humans

<iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" src="https://www.youtube-nocookie.com/embed/e59guruVL4o?rel=0&amp;showinfo=0" width="420"></iframe>

March 15, 2015 04:08 AM

March 12, 2015

Clinton RoyThursday 12th March

Walked into work fairly early.

Dead tired by the end of the day.

Signed onto sleepio to give them a burl. Looks like they’d like me to get a fitbit..


Filed under: diary

March 12, 2015 07:47 AM

March 11, 2015

Adrian SuttonPatterns are for People

Avdi Grimm in Patterns are for People:
Patterns aren’t tools for programming computers; they are tools for programming people. As such, to say that “patterns are a language smell” makes very little sense. Patterns are a tool for augmenting language: our language, the language we use to talk to each other about a problem and its solutions; the language we use to daydream new machines in our minds before committing them to code. Patterns aren’t a language smell; rather, patterns are by definition, [optional] language features.
There’s so much we can learn if only we stop making everything into a battle between “new” tools or approaches and “old” ones. Patterns are relevant and useful in all forms of programming and we shouldn’t discard them just because they’re not “cool” anymore. Sadly we seem to throw out nearly all our experience and learning each time a new approach comes along rather than learning from and taking advantage of both.

March 11, 2015 10:01 PM

Clinton RoyWednesday 11th March

Awful day.

Sleep was disrupted by neighbours moving their cars around at two thirty am to make way for builders coming. Why two thirty? fucked if I know.

Finally dragged myself out of bed tired and headachy, headed into work.

Did manage to get some stuff done at work before the jack hammering started, and I left immediately in the early afternoon.

Struggling to stay awake till a sensible hour while catching up on a few of these here diary entries.


Filed under: diary

March 11, 2015 08:16 AM

Clinton RoyTuesday 10th March

Walked home.

Conference stuff.


Filed under: diary

March 11, 2015 08:12 AM

Clinton RoyMonday 9th March

Walked into work stupidly early.

Home early, straight to bed.


Filed under: diary

March 11, 2015 08:12 AM

Clinton RoySunday 8th March

Library day.


Filed under: diary

March 11, 2015 08:10 AM

Clinton RoySaturday 7th March

Coder dojo, much to my surprise I was introducing my simplified markov chain generator. It didn’t get much traction, but I felt that was because most of the kids had something they were interested in doing.

Next week I’m apparently talking all about 3D printing…


Filed under: diary

March 11, 2015 08:10 AM

Clinton RoyFriday 6th March

Deliberately didn’t walk to work as I’m giving blood today.

Stuffing myself silly with food and water, and only one coffee. So much water.

Was vindicated when I gave blood in record time with no dramas, and I didn’t get even a minor bruise at the extraction point.

Stuffed myself silly straight after.


Filed under: diary

March 11, 2015 08:07 AM

Clinton RoyThursday 5th March

Walked to walk stupidly early.

Conference work that night.


Filed under: diary

March 11, 2015 08:04 AM

Clinton RoyWednesday 4th March

The monthly Python Users group meeting. There was a great talk about calculating statistics, like variances, in a single pass.


Filed under: diary

March 11, 2015 08:03 AM

Clinton RoyTuesday 3rd March

Walked home.

Conference stuff.


Filed under: diary

March 11, 2015 08:02 AM

Clinton RoyMonday 2nd March

Was on the motorbike for the first time in a while today. Riding into work very early is great, riding home at peak hour is silly however.


Filed under: diary

March 11, 2015 08:00 AM

Clinton RoySunday 1st March

Conference stuff at The Edge.

Dinner with E. that night.


Filed under: diary

March 11, 2015 07:58 AM

March 05, 2015

Adrian SuttonNew Favourite Little Java 8 Feature

Pre-Java 8:

ThreadLocal<Foo> foo = new ThreadLocal() {
@Override
protected Foo initialValue() {
return new Foo();
}
};

Post-Java 8:

ThreadLocal<Foo> foo = ThreadLocal.withInitial(Foo::new);

Nice.

March 05, 2015 10:03 PM

March 01, 2015

Clinton RoySaturday 28th February

A quite full on day.

Woke up early because..that’s what I do. Headed out to Sunnybank library in the morning, CoderDojo, then back to The Edge for minicomicon, where I picked up a few small freebies, but didn’t spot anything that I felt like buying. I spent a little time coding up a simple Markov generator, hopefully simple enough for the coder dojo folks to follow. After all that, out to Humbug.


Filed under: diary

March 01, 2015 04:43 AM

February 27, 2015

Clinton RoyFriday 27th February

I went to bed really early last night due to my weird ongoing headache. I had a little help getting to sleep. This meant I basically had a full nights sleep by three o’clock. So I ended up walking to work stupidly early and arriving before five am. I still had some residual effects of the whatever-the-heck headache in the morning, but it’s gone by the evening.

The internet was really weird today, llamas and dresses for some reason.

Doing some conf stuff at The Edge. See three friends walk past on the walkway :)


Filed under: diary

February 27, 2015 09:21 AM

February 26, 2015

Clinton RoyThursday 26th February

Another weird day really.

The headache from yesterday did not improve, after physio and tablets. I went to bed early and woke up around 2am with my head still banging.

Work has a construction site across the road and it’s still very noisy at times, it was very difficult dealing with both a headache throbbing inside my head and the builders machines throbbing the outside of my head.

I had lunch offsite with H, who is always doing a million and one things and making me feel lazy.

I decided I didn’t want to deal with the headache and noise in the afternoon and headed home.


Filed under: diary

February 26, 2015 06:31 AM

February 25, 2015

Clinton RoyWednesday 25th February

Bit of an odd day today.

Physio appointment in the morning, specifically looking at my right forearm, I was concerned I was seeing the initial stages of RSI, but the physio relieved those anxiety’s at least. They physio used dry needles to  settle down the muscle that was acting up, that was a first and quite an interesting experience.

Next up I went out to the UQ Market day to rendezvous with the UQCS club, to give them some pamphlets describing PyCon Australia  and Humbug a little. Most of our volunteers last year were UQ students, and I’d be delighted if that were the case again this year.

I’ve ended up with a headache at the end of the day, maybe because I didn’t have any coffee till after lunch?


Filed under: diary

February 25, 2015 08:36 AM

Clinton RoyTuesday 24th February

Walked to work.

While doing some conference stuff, discovered that I hate printers. It took something like an hour to print out two pages of basic text and one image. Whatever pdf version every tool was spitting out, was not handled at all well by either printer.


Filed under: Uncategorized

February 25, 2015 08:29 AM

Clinton RoyMonday 23rd February

Did not walk in today.

Did go and see _Juptier Ascending_ which I really quite liked. If the main baddy wasn’t so completely over the top, I would have quite enjoyed it.


Filed under: diary

February 25, 2015 08:27 AM

February 22, 2015

Clinton RoySunday 22nd February

Waking up at two for no discernible reason.

Breakfast with C was a better start to the morning.

Afternoon at The Edge doing conference stuff.


Filed under: diary

February 22, 2015 04:53 AM

Clinton RoySaturday 21st February

Coder Dojo down at Sunnybank Hill library. Quite exhausting after a bad night’s sleep!


Filed under: diary

February 22, 2015 04:51 AM

Clinton RoyFriday 20th February

Walked to and from work, in an attempt to have a good night sleep tonight..

Tropical Cyclone Marcia has degenerated to a tropical low and is hovering around Brisbane today, making for a lot of rain. I quite like walking in the wet, as long as I’ve got my wet weather gear. Most of the work colleagues are cats and stayed home.

Conference planning later at The Edge.


Filed under: diary

February 22, 2015 03:47 AM

Clinton RoyThursday 19th February

Walked to and from work today.

Doing some conference planning later on.


Filed under: diary

February 22, 2015 03:45 AM

Clinton RoyWednesday 18th February

Walked to work.

Caught up with a C after work, as a surprise thing rather than a planned thing.


Filed under: diary

February 22, 2015 03:43 AM

Clinton RoyTuesday 17th February

A bit of a nothing apart from work day.


Filed under: diary

February 22, 2015 03:42 AM

February 18, 2015

Paul GearonTweaking the Power Limit

After posting the power-limit function earlier I found myself thinking about the inelegance of the expression. I like the approach, but the code seems much more verbose than should be required. In particular, the (partial apply not=) expression seemed too long for something so simple.

As a reminder, here is my last iteration on the function:
(defn power-limit [f a]
  (let [s (iterate f a)]
    (ffirst
      (drop-while (partial apply not=)
                  (map vector s (rest s))))))
The first thing that occurred to me here is the use of vector to pair up the values. It's this pairing that makes the predicate for drop-while more complex. Perhaps I should avoid the pair?

The reason for this pair is so that they can be compared for equality in the next step. So why not just compare them straight away? But that would leave me with a true/false value, when I need to get the values being compared when they are equal. What I really needed was a false/value result, and this reminded me of how a set lookup works. For instance (#{2} 1) returns nil, while (#{2} 2) returns 2. This is what I need, so why not try it?
(defn power-limit [f a]
  (let [s (iterate f a)]
    (first
      (drop-while not
                  (map #(#{%1} %2) s (rest s))))))
The anonymous function in the map looks a little like line noise, but it's not too bad.

Now that the result of map is a value and not a pair, we only need first and not ffirst. The drop-while predicate also gets simpler, just needing a not, but it's still verbose. However, the drop-while is just removing the leading nils from the results of the map, so let's move to keep instead:
(defn power-limit [f a]
  (let [s (iterate f a)]
    (first
      (keep #(#{%1} %2) s (rest s)))))
So does this work?
=> (power-limit has-fixpoint 0)
ArityException Wrong number of args (3) passed to: core/keep clojure.lang.AFn.throwArity (AFn.java:429)

Doh! It turns out that keep only has a single arity and does not accept multiple collections like map does. So I'm stuck doing a (drop-while not ...) or (filter identity ...) or (remove nil? ...) to wrap the map operation.

The fact that I can remove all the leading nils, or all the nils (since all the nils are at the head here), made me take a step back again to think about what I'm doing. Once all the nils are out of the picture, I'm just looking for the first item in the resulting list. That's when I remembered some which tests all the items in a list according to its predicate, returning truthy/falsey, but the way it does this is to just return the first non-falsey value its predicate gives. So I still need to wrap the map operation, but I can drop the call to first.
(defn power-limit [f a]
  (let [s (iterate f a)]
    (some identity (map #(#{%1} %2) s (rest s)))))
Not as pretty as the very first implementation (which used loop/recur) but now it's not so verbose, so I'm feeling happier about it.

February 18, 2015 04:45 AM

Paul GearonLife in Clojure

A few months ago I was looking at the Life in APL video on YouTube and it occurred to me that other than the use of mathematical symbols for functions, the approach was entirely functional. This made me wonder if it would be easier (and perhaps clearer) to do it in Clojure. My goal was to show that Clojure was just as capable, and hopefully easier than APL.

I created Life in Clojure to do this, and it worked out pretty well. What I need to do now is to record a REPL session for YouTube, just like the original. However, there are a couple of things that were shown in the APL video that are missing in Clojure, and I needed to fill in the gaps. It's these gaps that I've been thinking about ever since, wondering if I could/should do better.

Since I don't have a video, Life in Clojure is implemented in a namespace that contains a REPL session. Just use "lein repl" and paste in that namespace file and it'll do everything in the same order as the APL video, with a couple of deviations. I've commented each operation with the appropriate dialog from the original APL video, so it should be easy to see the parallels. However, for anyone who wants to see it running, the final program is implemented in the life.core namespace.

Setup

The first change between these Clojure and APL implementations is that Clojure needs to explicitly import things into the environment, while the APL video seemed to demonstrate all operations being available by default. Given that most of these were matrix operations, and APL specializes in matrix operations, then it isn't surprising that these are built in. Fortunately, all the applicable operations are available to Clojure via core.matrix, so this was a simple require, along with a project dependency. I suppose I will need to show these at the start of any video I make (if I ever make it).

Output

The APL video showed the use of a display function that prints a matrix to the console. Clojure's pretty-print will also show an m*n matrix reasonably well, and I could have chosen to use that. However, the APL code is also printing a vector, and then a matrix, where each element is an m*n matrix, and pretty-print just messes that up.

The APL demo seemed to be using a library function to handle this printing, so it didn't feel like cheating to write my own. It's a bit clunky, as it's specialized to only handle 2, 3 or 4 dimensions, but it works.

The bigger issue was showing the current state of the Life playing field. APL was using a draw function to update the contents of a text file, and opened a window that dynamically showed the contents of that file as it was updated. Using a file proxy like this made the display easy in APL, but it's hack that I did not think was worth duplicating. Instead, I created a function to convert the playing field into an image, and sent the image to the display.

Creating an image from the matrix was an easy Swing-based function (just draw filled-in rectangles based on the contents of each matrix cell, and return the image). However, rendering it was a little harder.

Following the APL approach, I wanted a function that would "send" the image to the screen, and forget about it. However, Swing requires an event loop, and several listener objects to allow the window to interact with the environment. These sorts of objects do not fit cleanly into a purely function program, but using proxies and closures does a reasonably good job.

I was able to hide the default window parameters (width/height, etc), but had trouble with the fact that the APL program simply sends the output to the rendered file without defining it as a parameter. The main problem is that the open-window function should return the created resource (the window) and this value should be captured and "written to" each time the life algorithm needs to re-render the playing field. I could do that, but introducing this resource handling into the main algorithm would get in the way of the "clarity" that the demo was trying to express. In the end, I opted to create a global atom (called canvas) that gets updated with each call to draw. I would not usually write my code this way, but it seemed to be the best way to duplicate the APL demo.

Of course, not a lot of programs use Swing these days. The majority of programs I see with GUIs use a browser for the UI. So when a couple of my friends saw this app, they suggested reimplementing it in ClojureScript, and rendering in a web page. Funnily enough, the DOM ends up being an equivalent to the global canvas that I have in the Swing application, so the calling code would not need to change its approach. However, core.matrix does not yet support ClojureScript, so I haven't tried this yet.

Matrix Math/Logic Operations

One minor inconvenience in using the APL approach is that it uses the C-style idiom that the number 0 is the value for "false" and anything else is "true". The APL demo algorithm uses 1 to indicate that a cell is occupied, and then uses addition between cells to determine the values for subsequent generations. This creates an elegant shortcut for determining occupation for subsequent generations in Life, but it isn't as elegant in Clojure.

Of course, Clojure truthy values identify all numbers as "true", and only nil or boolean "False" have a falsey value. Without the zero=false equivalence, then the algorithm gets more awkward. Based on that, I created a function that takes a single argument boolean function and returns an new function that returns the same result mapping false->0 and true->1. This allows matrix addition to be used as the basis of the AND and OR operations, just like in the APL demo. It works fine, but I'm uncomfortable that it currently only handles the 2 argument case for the AND and OR matrix operations. Also, I've since learned a little more about core.matrix, and I think there may be better ways to define these functions. I'll have to look into that a little more.

There is also a convenience function I created which is used to map a matrix to boolean 1/0 based on each cell being equal to a given value. It's a simple one-liner that makes it easier to compare to the equivalent APL code but it always felt a little inelegant. However, this might just be due to the need to map booleans to numbers.

The other APL function that wasn't directly available to me was the "take" of a matrix. This operation allows a 2-D "slice" from a larger matrix, but also deals with the insertion of a small matrix into a larger "empty" matrix. After some examining of core.matrix I discovered that shape provided similar functionality, though it needs help from compute-matrix to handle expansions. I wrapped this in the function takeof to duplicate how the APL demo used it.

Powers and Power Limits

Up to this point, everything was either translating a library from APL (display, the graphics output, or some simple wrappers to smooth out matrix access, and handle the integer/boolean equivalence in APL). But right at the end of the video, the APL demonstration uses a couple of functions that had no equivalents in the Clojure. These are the power function and the power-limit function.

The behavior of the power function is to take a single argument function and apply it to an argument, take the result and apply the function to that, and keep repeating the application of the function as many time as requires. The specific operation of power is to return a function that applies the argument function iteratively like this for the defined number of times.

As an example, the 5th power of clojure.core/inc applied to 0 is:
=> (inc (inc (inc (inc (inc 0)))))
5
So (power-function inc 5) returns a function that applies inc 5 times:
=> ((power-function inc 5) 3)
8
The power-limit function is similar, in that it iteratively applies the provided function, however it does not stop iterating until it reaches a fixpoint value. That is, until the output of the function is equal to the input.

An example function that has a fixpoint is:
(defn has-fixpoint [x] (min (inc x) 3))
This returns either the increment or 3, whichever is smaller. If this is applied iteratively, then it will always reach a value of 3 and stay there.

My first approach to this naïvely executed the provided function n times:
(defn power [f n]  (case n
    0 identity
    1 f
    (fn [x]
      (loop [r x, i n]
        (if (zero? i)
          r
          (recur (f r) (dec i)))))))

This works, but one look at it was enough to tell me I'd gone down a blind alley. case statements always suggest that something is inelegant, and loop/recur often means that the Clojure's laziness and seq handling are being ignored, which implies that I may have missed an abstraction. Both are a code smell.

That's when I remembered clojure.core/iterate. This function applies a function iteratively, returning an infinite lazy sequence of these iterations. The required power is just the nth entry in that sequence, so the power function just becomes:
(defn power [f n] #(nth (iterate f %) n))
Much better.

Similarly, I'd implemented the power-limit function using a loop until the input equalled the output:
(defn power-limit [f a]
  (loop [a a]
    (let [r (f a)]
      (if (= r a)
        r
        (recur r)))))

Unlike the original version of the power function, I like this approach, since it clearly does exactly what it is defined to do (apply the function, compare input to output, and either return the output or do it again).

I already mentioned that loop/recur often suggests that I've missed an abstraction. This, along with neglecting to use the iterate function for power, had me wondering if there was a more idiomatic approach here. That's when I realized that I could pair up the iterated sequence of the function with its successor, and compare them. The result is:
(defn power-limit [f a]
  (let [s (iterate f a)]
    (ffirst
      (drop-while (partial apply not=)
                  (map vector s (rest s))))))
The iteration sequence is captured in the let block so that it can be re-used when pairing the sequences in the map operation. The vector is being used here to capture each iteration with its successor in vectors of pairs. Because iterate is lazy, the sequence of iterations is only calculated as needed, and only calculated once.

The drop-while drops off all pairs of values where the values are not equal. The not= operation can take multiple arguments, so rather than pull each of the two values out, I'm using partial/apply to provide the pair as all the arguments. The result of the drop-while/map is a sequence of pairs of argument/results (which are all equal). The final result is to take the first value from the first pair, hence the use of ffirst.

Conceptually, I like it more, and I think that it fits into Clojure better. However, it's less clear to read then the loop/recur solution. So I'm torn as to which one I like more.

February 18, 2015 04:03 AM

February 17, 2015

Clinton RoyMonday 16th February

Bus to work, after discovering that I had no spare clothes at work, somehow. That won’t be a problem for a couple of weeks now.

Horrible nights sleep meant I had to skip the new software engineering meetup.


Filed under: diary

February 17, 2015 06:56 AM

February 15, 2015

Clinton RoySunday 15th February

Felt rather ill after Humbug, I’m assuming it was the sushi place at Sunnybank yesterday.

Catching up on these here diary notes..


Filed under: diary

February 15, 2015 03:58 AM

Clinton RoySaturday 14th February

My first CoderDojo down at Sunnybank Hills.

I find the connection between shopping centres and libraries rather confusing, for former are loud, commercial and horrible places, very different to the latter.

I think the CoderDojo group went well, with some obvious room for improvement. Don’t try to lecture kids, give them a small, simple instruction and get them doing stuff immediately. One slide, one thing to try. If a kid has interest in a subject, don’t try to teach them something else, and that goes for both parents and teachers.

Have been asked to help with a Python course in the next few weeks..

Humbug later that night, some discussion with Russell around the sponsor prospectus.


Filed under: diary

February 15, 2015 03:56 AM

Clinton RoyFriday 13th February

Early morning walk to work.

A little bit of anatomy work later at The Edge.


Filed under: diary

February 15, 2015 03:51 AM

Clinton RoyThursday 12th February

Early morning walk to work.

Catch up meeting at The Edge, broached the subject of running the PyCon Australia workshops here again.

3D printing induction, which went quite well, except for running out of time. Tinker cad is quite a fun easy tool to get into. I attempted to design a key holder that my key could slide into, it ended up being too short, but the sliding mechanism was perfect.


Filed under: diary

February 15, 2015 03:49 AM

Clinton RoyWednesday 11th February

Worky work. There’s a building site across the road from work, and the three jackhammers are *really* starting to get to me. It used to be the case that I could kind of ignore them until later in the day, and only then would they get on my nerves. Now, ten minutes after I get in and I’m grumpy.

A Humbug member organised an OpenBSD hackathon at UQ this week, and tonight they held a few talks about what they’d been working on. Some of it was interesting, just to get an insight of where BSD is. A lot of it was just complaining about other Open Source projects and standards committees not doing things in the correct way. They are trying to do something things to improve the situation, but I still feel like they’re being arrogant about much of it.


Filed under: diary

February 15, 2015 03:45 AM

Clinton RoyTuesday 10th February

Waking up in Brisbane again.

After work I organised a bowling night for my birthday. It ended up working out quite well I think, except that the dj outside the venue and the constant music inside bore down on me.


Filed under: diary

February 15, 2015 03:34 AM

Clinton RoyMonday 9th February

A very early start for the flight back to Brisbane.

Collapse into bed basically as soon as I get home.


Filed under: diary

February 15, 2015 03:20 AM

Clinton RoySunday 8th February

Melbourne!

Went to a few of the exhibits that had caught my eye when looking for things to do in Melbourne.

The Walkley photography in journalism exhibit at the State Library of Victoria was a small set of high quality, moving photos.

Spent a large chunk of the day at the National Gallery of Victoria, practically everyone else was there to see some Paul Gaultier fashion thing, while I was there to see Alex Prager who does elaborate photography and film work. I was a little surprised that every exhibit, bar Gaultier, was free, so went through pretty much everything there, history, design, jewellery, art, modern.

A nice long dinner with F followed by a cup of tea at her place with M.


Filed under: diary

February 15, 2015 03:16 AM

Clinton RoySaturday 7th Februrary

Melbourne!

Catch up and breakfast with F. Straight after went for a walk with F&M to do a little shopping..and to make sure I got on the right tram for my next appointment.

Coffee and tea and lunch with M followed by a park wedding critique.

Killing some time in a gift store, found a world map covered in scratchy material that you scratch off once you’ve travelled to a place, bought for a Brisbane friend who travels a lot.

Dinner with D&P, then laps of Melbourne looking for a parking spot to grab gelato. Way too many people for me to be comfortable down there.


Filed under: diary

February 15, 2015 03:04 AM

Clinton RoyFriday 6th February

Bringing more stuff into work for this evenings Melbourne flight.

Flew to Melbourne, it was kind of hot! I tried to use the several phone apps to figure out the trams, but despite google maps knowing I was in Melbourne, all the apps still thought I was in Brisbane. With help from a local friend got the tram to the hotel.


Filed under: diary

February 15, 2015 03:00 AM

Clinton RoyThu 5th February

Bringing more stuff into work for the Melbourne trip, bus is easier than walking with all that.

Walked home from work.


Filed under: diary

February 15, 2015 02:56 AM

Clinton RoyWed 4th February

Bringing stuff to work for the Melbourne trip.


Filed under: diary

February 15, 2015 02:52 AM

Clinton RoyTuesday 3rd Febrary.

Walked to work.

Lunch with a friend at her workplace, bumped into another friend who just started working there :)


Filed under: diary

February 15, 2015 02:50 AM

February 14, 2015

Blue HackersWhy the modern world is bad for your brain | Guardian UK

February 14, 2015 07:10 AM

February 11, 2015

Anthony TownsFUD from the Apache Foundation

At Bradley Kuhn’s talk at linux.conf.au this year, I was surprised and disappointed to see a slide quoting some FUD (in the traditional Fear-Uncertainty-Doubt model, a la the Microsoft Halloween documents from back in the day) about the GPL and the SFLC’s enforcement thereof. Here’s the quote:

This is not just a theoretical concern. As aggressively as the BSA protects the interests of its commercial members, [GPL enforcers] protect the GPL license in high-profile lawsuits against large corporations. [FSF] writes about their expansion of “active license enforcement”. So the cost of compliance with copyleft code can be even greater than the use of proprietary software, since an organization risks being forced to make the source code for their proprietary product public and available for anyone to use, free of charge. [...]

The Apache Advantage

However, not all open source licenses are copyleft license. A subset of open source licenses, generally called “permissive” licenses, are much more friendly for corporate use.

The quote/slide is available at about 20m into Bradley’s talk. A quick google reveals the source of this as a page from openoffice.org which is, indeed, an Apache project. The revision history for that page is available via subversion.

The elisions in Bradley’s quote changed “the Software Freedom Law Centre” (Bradley’s employer) to “GPL enforcers”, simplified the reference to the FSF, and dropped off a couple of sentences of qualification:

To mitigate this risk requires more employee education, more approval cycles, more internal audits and more worries. This is the increased cost of compliance when copyleft software is brought into an organization. This is not necessarily a bad thing. It is just the reality of using open source software under these licenses, and must be weighed in considered as one cost-driver among many.

I don’t really think any of that changes Bradley’s point: the Apache Foundation is really saying that the GPL and the SFLC is worse than the BSA and proprietary licenses.

After getting home from LCA, I thought it was worth writing to the Apache Foundation about this. I tried twice, on 22nd January and again on 1st February. I didn’t receive any response.

From: Anthony Towns

I was at Bradley Kuhn’s talk at linux.conf.au 2015 last week, and was struck by a quote he attributed to the Apache Software Foundation which compared the SFLC’s efforts to enforce GPL compliance with the BSA’s campaigns on software piracy, and then went on to call the SFLC worse. The remarks and slide can be found at approximately the 20 minute mark in the recording on youtube:

www.youtube.com/watch?v=-ItFjEG3LaA#t=19m52s

Doing a google search for the quote, I found a hit on the Apache OpenOffice.org website:

http://www.openoffice.org/why/why_compliance.html

which although it’s a (somewhat major) project rather than the apache site itself, doesn’t give any indication that it’s authored or authorised by someone other than the Apache Foundation.

I couldn’t find any indication via web.archive.org that that page predated Apache’s curation of the OpenOffice.org project (I wondered if it might have been something Oracle would write, rather than the Apache Foundation).​ Doing some more searching, I found a svn log that seems to indicate it’s primarily authored by Rob Weir with minor edits by Andrea Pescetti (who I understand is the VP for Apache OpenOffice):

​http://svn.apache.org/viewvc/openoffice/ooo-site/trunk/content/why/why_compliance.mdtext?view=log

Is this really an accurate representation of the Apache Foundation’s current stance on copyleft licenses, the GPL and the SFLC’s enforcement efforts?

Apparently we now live in a world where Microsoft happily releases GPL-licensed software, while the Apache Foundation happily spreads FUD against it.

February 11, 2015 08:01 PM

February 03, 2015

Clinton RoyMonday 2nd February

After a very early start, walked to work.

Had a doctors appointment in the evening.

Basically collapsed into bed quite early. Had half an hour of sleep before waking up from a bad dream.


Filed under: diary

February 03, 2015 08:51 AM

Clinton RoySunday 1st Feburary

Did a few conference things.

Caught up with a dear friend for dinner.


Filed under: diary

February 03, 2015 08:49 AM

Clinton RoySaturday 31st Jan

Humbug day, with both the lca debrief and the election, double excitement! Unfortunately my partner in crime, Russell, had to attend to an emergency situation and couldn’t stay for the debrief, a large part of the enjoyment I get out of the debrief is disagreeing with Russell. Fortunately Tomas stepped in and added a great deal of information including a number of talks that I never would have bothered looking at, which is after all the entire point of the debriefs.


Filed under: Uncategorized

February 03, 2015 08:48 AM

Adrian SuttonMounting a Time Capsule Drive In Linux

Lots of articles out there that have almost the right solution here but nearly all of them miss one critical component, so for my future sanity, here’s what works for me:

sudo mount.cifs //timecapsule.local/Data/ /mnt/directory/ -o “pass=password,sec=ntlm”

If you don’t have zeroconf working in your Linux install you’ll have to use the time capsule’s IP instead of it’s .local name.  The “Data” part is the name of the disk you want to mount as shown in Airport Utility (make sure you escape any spaces with backslash.

Critically, you need to insist on NTLM authentication using the sec=ntlm option.  You may additionally want to specify file_mode, dir_mode and other standard mount options.

If you are using disk or device password based security you only need to specify the password, the username is ignored. However, if you’re using account based security you’ll need to also supply a user= option to specify the correct username.

February 03, 2015 03:25 AM

January 31, 2015

Clinton RoyFriday 30th January

Work.

Got the pyconau15 landing page done, a small yay.

Working on slides for the lca debrief tomorrow.


Filed under: Uncategorized

January 31, 2015 02:35 AM

January 29, 2015

Ben Martinlibferris on osx

So libferris is now compiled and installed thanks to some of my handy work on Portfiles and macports doing the heavy lifting. I've put the Portfile into the distribution for many of the repositories; ferrisloki, ferrisstreams, stldb4, ferris, fampp2. And moved the source control over to the github -- https://github.com/monkeyiq/ferris

It's still a bit of a bumpy compile for ferris itself. Using clang instead of gcc, using the different stdc++ lib, the lack of some API calls on osx relative to Linux and the assumptions I'd made that IPC, advising the kernel on IO patterns, memory mapping and again advising on page patterns, would all be available APIs and contants. I have a patch from the compile which I need to feedback into the main libferris repo, making sure it still works fine on Linux too.

So now I can dig into xml files from the command line on osx too. I have to test out the more advanced stuff and the web services. The later use some of the 'Q' magic dust, qjson, qoauth, qtnetwork et al so they should be fairly robust after the port.

I should also update the primary file:// handler in libferris to use some of the osx apis for file monitoring etc to be a friendlier citizen on that platform. But going from no ferris on osx to some ferris is a great first move. A bundle would be the ultimate goal, /Applications/Ferris install in a single drag and drop.

January 29, 2015 12:43 PM

Clinton RoyThursday 29th January

Work. How is it not Friday yet?

Another day, another late leave time after another late finding bug.

I’ve started updating the pycon 2015 landing page, will get that finished for the weekend.


Filed under: diary

January 29, 2015 09:51 AM

Clinton RoyWednesday 28th January

Work.

Spent a fair chunk of today dealing with the ghost CVE. Although our upstream provided updates, do to the somewhat unique way our machines are installed and configured, the upgrade wasn’t a piece of cake. There’s something about doing security patches that drain all the energy out of me to boot.

I did end up booking some accommodation for my Melbourne trip, centrally located to everyone I want to see.


Filed under: diary

January 29, 2015 09:46 AM


Last updated: April 18, 2015 07:15 PM. Contact Humbug Admin with problems.