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:



Update: It's also on GitHub here : https://github.com/davidsinfield/ansilib

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.

Monday, March 2, 2015

Is it time to dump Left and Right in discussing poilitics?

The terms left and right are bandied about and arguments still rage about Hitler being extreme right or extreme left. Pol Pot, extreme left or extreme right? Mao? Tsian Kai Check? Ciaucescu

What if it doesn't matter?

What if it is not a continuum with left at one end and right at the other? A one dimensional view.

What if it is more like a circle with extreme left and extreme right pretty well aligned in their dogmatism and desire for control? The two dimensional view.

So what is the on the other end of the diameter of the circle from extreme left and right? A lack of alignment. Apoliticism. The ultimate freedom from dogma and tribal politics. Once upon a time the distinction could be drawn because the left want state control of commerce. What if the right do to but by a different means. By regulation rather than ownership?



Just saying.