Saturday, March 25, 2017

Optimists, rationalists and pessimists

Thing change. It's the only constant.

And as things change we like to guess outcomes.

Optimists like to guess things will be fine.

Pessimists guess at bad outcomes.

Rationalists recognise that of the outcomes some are better than others.

On this continuum I sit between rational and optimistic. What steers me from pure rationalism?

1. Faith in human ingenuity to steer the outcomes towards the good.

2. The fact that from a historical perspective optimists are more often proved right. Unless you believe a nasty Brutus and short life is better than we have now, overall things improve.

Tell me I'm wrong.


Tuesday, March 14, 2017

ANSI formatter for python

ANSI formatter

I have been playing around with python and needed something that formatted the terminal output using the ansi codes as described here:

http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html

Except I can't remember all the escape sequences any more. The last time I used them was about 35 years ago when I was working with serial terminals at Philips in Holland.

I thought it might be useful so here it is. I've put a listing at the end of the post. Feel free do do with it what you will within the terms of the GPL. I'll update this when I get round to putting it on GitHub.

The code has been tested on LXTerminal and xcfe4 on the pi and xterminal on ubuntu and gives expected results on all of them. It won't work if your terminal doesn't recognise ansi codes.

Here's the sample output:



And here's the function and a bit of sample usage:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  ansidemo.py
#  
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  https://www.gnu.org/licenses/gpl-3.0.en.html
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  


dictForeBack={
'fore' : 3,
'back' : 4
}
dictColour={
'black' : 0,
'red' : 1,
'green' : 2, 
'yellow' : 3,
'blue' : 4,
'magenta' : 5,
'cyan' : 6,
'white' : 7
}
dictStyle={
'normal' : 0,
'bold': 1,
'italic' : 3,
'underline' :4,
'inverse': 7,
'strikethough' : 9
}
#========================================================================
#GetANSI(text,foreback,colour,style)
#text - text to print
#forecolour - [black|red|green|yellow|blue|magenta|cyan|white]
#backcolour - [black|red|green|yellow|blue|magenta|cyan|white]
#style - [normal|bold|italic|underline|inverse|strikethough]
#
#Returns a string with ansi precursors to set foreground and background
#colours and style. Set to normal after printing.
#
#Out of range parameters throw a dictionary error
#
#Example: set foreground to red
# print GetANSI('this is red text','red','none','none')
#Example: set foreground bold red, background cyan
# print GetANSI('set properties','red','cyan','bold')
#
#Update
# empty string in a parameter is now the same as none.
# Example:
# GetANSI('text','','','bold')
#=========================================================================
def GetANSI(text,forecolour,backcolour,style):
pre="\033["
post="m"
tonormal=pre+'0m'
retval=""
if forecolour != 'none' and forecolour != '':
retval=retval+pre+str(dictForeBack['fore'])+str(dictColour[forecolour])+post
if backcolour != 'none' and backcolour != '':
retval=retval+pre+str(dictForeBack['back'])+str(dictColour[backcolour])+post
if style != 'none' and style != '':
retval=retval+pre+str(dictStyle[style])+post
return (retval+text+tonormal)

def main():
print GetANSI('red text','red','none','none')
print GetANSI('red text cyan bg bold','red','cyan','bold')
print GetANSI('inverse of above','red','cyan','inverse')
print GetANSI('black on white','none','none','inverse')
print GetANSI('black on green','green','none','inverse')
print GetANSI('non explicit green','green','','')
print 'normal text'
return 0

if __name__ == '__main__':
main()

Friday, July 8, 2016

Forest Tweetup 26-28 August

So here's the thing...

I posted on twitter some pictures of the events we put on in the woods. We have a bit of a laugh throwing knives, tomahawks and setting fire to things. A couple of people expressed an interest and so I thought I'd throw out an invitation. A sort of open woods weekend.

The weekend will be wild camping; We do have a composting toilet but otherwise it's a forest. No electricity, no running water. It's near Arundel in West Sussex. I'll give exact location nearer the time.

I'm thinking:


  • Some game prep. I can order a skin on deer to be butchered or get my mate to shoot us some rabbits.
  • Loads of projectile weapons. Catapults, spears, bows and arrows etc
  • Fire challenge. One match. One cotton wool ball. Boil a litre of water.
  • Knife and axe skills. We'll make a spoon or a spatula. We might even take down a small tree for materials.
  • Make a bow and arrow. We'll do the nepalese/butanese style bamboo bows. These cab be turned out in under a day but will chuck an arrow 100 paces
  • Campfire cookery. 
  • A few drinks around the fire in the evening
For accommodation we have 5 big wing tarps. 3 of them have slept 9 people. You can get more in if you want to get cosy. Or you can bring a tent. I'll be in my hammock.

All you'll need is some sleep kit, plate, spoon, fork and cup.

Bear in mind everything you bring will have to be carried in and out. It's about 3/4 of a mile down a muddy path.

We usually cater, you eat very well and can get involved with the preparation or chill and be waited on. Menu is usually full cooked breakfast, buffet lunch, proper dinner. The kettle is always on.

I've been thinking hard how to finance it. Getting in a deer costs about £100. The materials for the bowmaking is about £30. I don't intend to charge for my time because I'm planning on having fun. I will be bringing in a couple of the other Forest Knights team and it would be nice to bung them some petrol money and a drink. The fact is that a weekend would normally cost you a couple of hundred quid but for this one I'm interested in having a laugh and meeting with a few like minded people. The way I want to do it is see how many people are interested and sort it out from there. Some might not want to do Friday night...I know some people do proper jobs so we can do something proportionate. 

So far I know there are two people interested.

Discuss...

Some pictures. There might be more if I can find where I put them...
(the royals are to show the type of himalayan bows we make)









Wednesday, March 23, 2016

Alison Sinfield 15-10-57 to 1-3-2016

Any of you that know Alison well know that things haven't always been plain sailing between us.

But I have to tell you that over the last couple of years I could not have been more proud of her.

She had her setbacks and we cried together a bit and then she went back to making her plans.

And talking of plans, most of what has happened here today was planned by Alison a couple of months ago.

I'll tell you why...because whenever we discussed her funeral, I said I'd put her on a skip, or chuck her off the channel ferry, or feed her to the cats.

So she thought she'd better make sure she got a proper send-off. I hope she approves as she looks down at us as she takes a break from hoovering her little corner of heaven.

I'll miss you Alison. Goodbye.

Saturday, May 23, 2015

Microsoft Dynamics CRM Mindmap (WIP)

I'm working on a mindmap to help a customer understand what is inside MS Dynamics CRM 2013. It is coming from multiple sources and the aim is that it becomes a usable reference for describing the possibilities of the product.

It might help you. Please feel free to share and adapt but I'd ask that the originator and disclaimer attributes remain intact. If you want to feed anything back to me or share your edits, that would be nice.

Here's jpg preview. I'll try to remember to update it as I change the map.


The .mm file is here. Mindmap file.

You will need freemind. It's available for windows and linux and there's a viewer for Android. Apple muffins, you are on your own.

It is very much a work in progress. The sales and marketing nodes a pretty well complete but there is loads more to come. Bookmark it and come back. I'll be updating it as I get time.


Tuesday, May 19, 2015

Readable jquery



I'm doing some JQuery stuff and for a person of simple tastes the readability of nested function() definitions all written on one line is very poor. Debugging is a pain in the arse. So here's some modest proposals for maintanable code:

  • Assign callback functions to variables
  • Use the variable in place of the function (){...}
  • Format them as you would if it was a function with all the relevant curly braces and indents
This adds a few characters of 'weight' to the page, but these can be minified away for production code.  

Here's how I would do it:

<html>
<head>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script>
var showmess="Show";
var hidemess="Hide";
var show=function()
{
$('p').toggle();
if($('#showlink').text()==showmess)
{
$('#showlink').text(hidemess);
}
else 
{
$('#showlink').text(showmess);
}
}

$(document).ready(
function()
{

$('p').hide();
$('#showlink').text(showmess);
$('a').click(show);
})
</script>
</head>
<body>

<h1>Hello</h1>
<p>You can't see this</p>

But you can see this.

<a href="#" id="showlink">&nbsp;</a>
</body>
</html>

As you can see I'm a bit of a traditionalist with my curly braces. My training manual when I started c programming was K&R C Programming Language and I've never really got out of the habit of matching brace indents.

Saturday, May 9, 2015

Romania and the Ceaucescu thing

I've been having an extended stay in Bucharest. I have got a smattering of the language, though it is a bitch, using no personal pronouns and definite and indefinite articles seemingly at random. And the gender thing is a bigger mess than an explosion in a jelly factory.

I've been drinking in a couple of bars and am sort of accepted into the conversation. A lot of people speak English and it's they are in general a friendly bunch. My favourite drinking place is the cafe at Cismigiu park.

When I arrived in mid-April the talk was all of the imminent Russian invasion of Moldova, which the Romanians would be obliged by various ancient alliances to defend. It didn't happen and it is no longer the topic. When the threat lessened we talked about Ceaucescu. There is a surprising amount of respect here still among some of the older people who remember what it was like.

Here's the perception of him I was given:

He was a bit of a peasant and culturally ignorant. He very hostile to non-ethnic Romanians, at his 'trial' he was accused of genocide, with reference to the putting down of the revolution. (There doesn't seem to be any evidence to support genocide* in the true definition IMO.) He suppressed all worship except that for the state. He destroyed much of the cultural heritage of the country. He was corrupt and lined his pockets. He did not tolerate opposition and was implicated in disappearing people who he didn't like. Looking at most political systems that all seems an extreme form of normal behaviour.
All sounds pretty grim until you compare the Ceaucescu years to now. The poverty here is astounding. The biggest industry seems to be collecting plastic bottles from bins into massive bin bags and getting a few lei for recycling them. The number of presumably homeless people living on the streets is  growing and there are slum areas. I mean proper shanty towns that were mainly cleared but are creeping back. The perception here is that homelessness and joblessness were both less under Ceaucescu. There was no greater wealth but people had jobs and roofs over their heads.

He achieved this by massive building and infrastructure projects created by what we would now call slave labour. If you were jobless or homeless you were drafted in to building one of Ceaucescu's follies. Some of which are still not finished and remain as monuments to the 'bad times.' The fact of the matter is though that the revenue generated by using poorly or unpaid (my informants were ambiguous) paid for them all and their families to be fed and housed. Not to great luxury but warmish, dryish and fed.

He also over a period of 10 years stopped international borrowing and upped exports (at some cost to the population) and cleared the national debt.

The student revolution in Timisoarena objected to a lot of the bad stuff he was doing, quite rightly. Particularly the poverty and food shortages brought about by the export of agricultural produce. Their big gripe was the slavery that was at least generating cash to keep people fed and housed. They bought into the magic money tree theory of economics. The turning point was the possible suicide of an army general which was widely speculated to be an execution and this caused the army to defect to the revolutionaries.

The current perception is that things were better with him than without him. I was drinking with people who could afford to drink in the park so this is not a fair sampling of the population.

All the preceding is culled from conversations over coffee and beer. I have no idea of the facts and some of the people I was speaking were not contemporaries of Ceaucescu.

Incidentally the graves are well tended and always seem to have flowers.

And now the payback is a country (or at least the capitol city) in real trouble. The second biggest industry is security guards. Shops, supermarkets, hotels, everywhere. And all ground floor windows are generally barred and or shuttered. There is a sense of desperation. Begging is a way of life. So is stealing. I walk with my "no, fuck off" face permanently set in place. It's still mainly safe, I was only subjected to aggressive begging once but he was drunk and is probably still wondering how he ended up on his arse, but there are some areas, like around the Gare de Nord that made me just a bit nervous. There is a big solvent abuse problem here. And used hypodermics litter the streets in the shadier areas. It was a big shock to have on of the street cleaners beg from me but she took a break from sweeping and stuck her hand out.

If you can live with the grinding poverty everywhere and the Romanian way of doing things it's still an interesting city to visit. It feels different to London, Paris, Amsterdam and even Prague. And the country is even better.

So my questions are:

  • Could he have achieved what he did without all the bad stuff?
  • If he could, how would history perceive him?
  • If you can only support your population by paying them in housing and food for civic projects, is that an acceptable thing to do?


I don't have any answers. However, I think the last question is a question a lot of countries might have to consider in the not too far distant future.

Genocide:the deliberate killing of a large group of people, especially those of a particular nation or ethnic group.