Getting Big Brother to monitor custom processes
This is very easy to do - and the documentation is bang on the money… but as always, there are no examples!
So without further a do…
Create a bb-proctab file in the etc folder in your Big Brother’s home folder with the following syntax:
<host name>: <yellow alert processes> : <red alert processes>
Processes are space delimited (enclosed in quotes where necessary) and can be followed by a semicolon if you want to specify a minimum or maximum of times it should be running.
The example below will issue a yellow alert if myscript.pl is running more than 8 times (to check for over forking or excessive load) and then a red alert if cron, bbrun or myscript.pl stop running.
localhost: "myscript.pl;<8" : cron;>=1 bbrun;>=1 “myscript.pl”
Developing for iPhone (and UIScrollView Example)
So, what have I been doing lately? Well I’ve been wrestling with my first Mobile App in Objective C and the Cocoa Touch frame work for every bodies’ favourite mobile platform!
Between a day job, a social life and a couple of other projects, I haven’t really had the time I need to really get to grips with iPhone as a development platform yet… one of the biggest things that is holding me (and I’m sure a lot of other developers) back is the limited documentation that’s available.
What you get from Apple with the SDK (both actual documents and help given by XCode’s research assistant) is very good but it suffers from being single sourced. That is to say that there are no other contributors in the periphery giving comments, suggestions or even pointing out mistakes with the official docs. This is partly because of the infamous iPhone SDK NDA (which fortunately as now being lifted) but it’s also down to the fact it’s a relatively new and proprietary technology…
A good example of this is the problem I had getting the UIScrollView class to work. The documentation was accurate to a ‘T’ and Apple even provided some fairly complex implementations to demonstrate how to use it with paging and zooming… but there was no example or explanation of how the fundamentals worked. I was left with the impression by the sample code that I needed to set up a delegate to handle all the events that the class actually does straight out the box! An hour later I was still playing around with implementations of the UIScrollViewDelegate protocol, trying to get my scroll bars to work when, all the while, all I needed to do was tell my UIScrollView the full dimensions of its content!
All I’d have needed to see was the 4 line example I’ve drawn up below, in the absence of Head First iPhone Development, I’ve even made a simple colour diagram showing the relationship between the two areas you have to specify! I doubt something so simple will help many people in the future, but you never know… and I hope this will be just the first example I write up for my blog!
//all variables are of type CGFloat, unless named otherwise!
UIScrollView *myScrollViewObj = [
[UIScrollView alloc] initWithFrame:
CGRectMake(frameX, frameY, frameWidth, frameHeight)
];
[myScrollViewObj setContentSize:
CGSizeMake(contentWidth, contentHeight)
];
[myParentViewObj addSubview:myScrollViewObj];
[myScrollViewObj release];
PS. Hey Steve, please don’t sue me! The NDA’s being lifted anyway right?
Great Interview Question
So, how this for an interesting interview question:
You have two variables with integer values, without creating a third variable exchange their values.
At first it sounds fairly simple, but then it hits you that it’s actually not… there’s no simple ‘exchange value’ function. Here’s how I solved it:
list($a, $b) = array($b, $a);
My answer provoked a surprised (if not bemused) Yeah, that’d work… I’ve never heard that one before look. After a little conversation it turned out that the answer they were expecting but rarely got was:
$a = $a + $b;
$b = $a - $b;
$a = $a - $b;
My answer is of course better, because it works with any type of variable, but what they were actually testing for was a logical brain that would solve the problem with simple maths… The fact that most candidates don’t even try answering the question goes to show how dastardly it is!
The Royal Academy’s Summer Exhibition 2008
Saturday morning I attended the Friends and Members preview of the Royal Academy’s Summer Exhibition and was faced with my annual choice between spending £12 on two glasses of Pimms or going whole hog, spending £18 on a jug and getting sloshed.
The Summer Exhibition is something I always approach with some trepidation as it can get quite overwhelming. With two or three galleries crammed full of paintings and people it is very easy to tire yourself out trying to see everything or just get frustrated and steam on through to larger stuff at the end. Although, I’m pleased to say that this wasn’t the case this year.
The standard at the ‘low end’ was phenomenal, not that I’ve ever seen any bad work before but there has been a lot of unremarkable paintings in the past. What was missing this year was the celebrated ‘high end’ work, there was no naked Tony Blair getting expelled from paradise or anything that you could really latch on to as being the centre or highlight of the exhibition.
I think what will stick out for people is Tracy Emin’s gallery. The very fact that it’s darkened sets it apart from the rest of the bright Summer Exhibition, then there’s the rather understated notice (pictured above) out side… and then there’s its content. This is not a collection of Emin’s work but rather her personal choice of things she wanted included (mainly from her friends and colleagues.) The content is definitely shocking and a few a pieces are definitely not for the faint hearted!
Friday Night at Cafe Oto
This Friday I went to see my good friend Isnaj Dui perform at a relatively new arts venue, in a rather overcast Stoke Newington, called Cafe Oto.
Despite a slightly awkward journey I was very impressed with the venue. Its white brick walls and concrete floor gave it a blank canvas feel that made it seem anything was possible in its confines (although I’d imagine this might be an acoustical nightmare for anything in the direction of a drum kit.) On the menu was the usual selection of bottled organic beers and wines, although I seemed to drink the ginger beer for most of the night - it was really amazing ginger beer, after all.
Isnaj Dui gave a beautiful recital of haunting flutes and electrodulcimer which caused quite a stir amongst the audience. On second was Suzy Mangion whose melancholy vocals and sombre rendition of Down Town sent many a shiver down my spine.
All in all a very interesting if not off beat evening.
Setting and Getting Cookies in Google’s WebApp
Here’s the disclaimer: I’m currently teaching myself Python for use with Google’s App Engine and (unlike my PHP or Perl) I’m not entirely sure if the below is best practice or even remotely sane, but that said, it does seem to work for me!
Setting a Cookie
Notes: Obviously the code is running in a controller (or rather a Request Handler) that extends webapp.RequestHandler and you’ll notice that I had to use a Regular Expression to remove the header name from Cookie.SimpleCookie’s output so I could tie it in to webapp’s header frame work which should stop any output buffering issues in the future.
import Cookie
import re
import base64
class YourHandler(webapp.RequestHandler):
cookieName = 'MyCookie'
domain = ''
expires = 360
value = 'Some value or something...'
def get(self):
simpleCookieObj = Cookie.SimpleCookie()
simpleCookieObj[self.cookieName] = str(base64.b64encode(self.value))
simpleCookieObj[self.cookieName]['expires'] = self.expires
simpleCookieObj[self.cookieName]['path'] = '/'
simpleCookieObj[self.cookieName]['domain'] = self.domain
simpleCookieObj[self.cookieName]['secure'] = ''
#Cookie.SimpleCookie's output doesn't seem to be compatible with WebApps's http header functions
#and this is a dirty fix
headerStr = simpleCookieObj.output()
regExObj = re.compile('^Set-Cookie: ')
self.response.headers.add_header('Set-Cookie', str(regExObj.sub('', headerStr, count=1)))
Getting a Cookie
Notes: This is much easier, we just have to make sure that it exists.
import Cookie
import base64
class YourOtherHandler(webapp.RequestHandler):
cookieName = 'MyCookie'
def get(self):
try:
cookieValue = str(base64.b64decode(self.request.cookies[self.cookieName]))
except KeyError:
#There wasn't a Cookie called that
cookieValue = ''