Bash-off – a way to relieve your self

Bash off!

In our team at work we have this concept which we call a “Bash off” the idea is simple. Take something that you could do very simply in bash in several steps with manual fudging in the middle to end up with a result. The sort of thing that may take you an hour to brute force your way through. Now in your programming language of choice, automate the entire process.

Sounds simple right ? I remember the first task we had which was to grab two unique columns of data and to stream them onto the screen, I think it was originally done with watch, tail and tee, took about 20 mins of playing with bash. As a team we chose our own languages and went for it, an hour later we all had a working prototype, another hour later we all had our programs really efficient.

Obviously these are really pointless, but they do have a couple of benefits that help a DevOps person stay good at what they do. It gets you to do more with your language of choice than you normally would and it also causes you to think about how you’re structuring code to make it more efficient, it also helps bond the team together with a bit of healthy competition.

To clarify just because it is called a bash off that dosen’t mean that a solution can’t be in bash. So if it was a very manual human process that you believe you can fully automate in bash, Go for it :)

The challenge

This weeks challenge came from our friends in finance, they have a spreadsheet with some 14k rows in it, two of the columns have many duplicated fields in them and the have a one to many mapping between them. So the challenge is to get from 14k rows down to just the unique entries in each of these two columns and to then make sure the mapping in the spreadsheet can be looked up from a database (where the spreadsheet results must end up)

Due to some meetings I was late to the game on this task, pesky meetings; we had a bash driven prototype which we excluded because it required the excel spreadsheet to be turned into a csv and a python one that sort of got some fields from the spreadsheet and pushed them into the DB.

This is where I picked it up, sort of working; I’ve not done a lot of python so I forked the code and me and my boss went our separate ways to achieve the task, in the end it took us a couple of hours to get this working and for us to have the same results. All in all it we had achieved the processing of 14k rows of data and the manipulation into a db with the correct data, but was that enough? No We decided that it taking about 1 min was not good enough so we started focusing on making it better, I think my run time was 58 seconds and my bosses 40.

We had both chosen different ways of doing it, I had chosen to use the DB to ensure the fields were unique by checking if that field existed in the DB and if not to create it and returned the id, if it was in the DB it would return the id. My bosses approach was better, he created lists with the data in and then made the lists unique. I decided I had to get mine down to a similar speed so I started hacking it around; I decided I would store the unique entries in a list for each table and then before calling the method that puts the data in the database I would check if that unique value was already there. The first issue with this is I lost the ID number which I needed to add to the lookup table so I had to change the list to a dictionary.

I also found by moving the commit messages for the database out side of any of the methods and just dropping it at the end saved a few seconds, I was also able to remove a couple of additional DB queries all of this helped bring the time down. One of the best changes I did was on the lookup table when doing a query only pulling back one ID, rather than two; I didn’t even need it but I couldn’t see a way of querying sql alchemy with out having a field to bring back that would be quick.

As the night progressed we both made good progress, my Boss got his down to 14.1 seconds I managed to get mine down to 21 seconds so we had both made massive improvements in our codes efficiency. My boss was making use of gevent but when I tried this it slowed my program down so I left it out not understanding it anyway. I kept pluggin away and I made it down to 13.5 seconds.

Summary

I urge you to take an afternoon out in your team and to push your skills forward with a programming challenge and to see what happens, it will make you better, you will learn stuff, it is fun, it does bond the team and you will enjoy it, it is also a waste of time but what else were you going to do ?

Yummy, Jira Jelly Escalations

Who doesn’t like Jelly?

At work we have some SOC2 fun stuff to attend to, one of the areas that I’m looking at is incident management, we’ve been doing incident management and analysis of incidents for a while so this was really about formalising it all. We use a highly customisable ticketing system called Jira which is good at its job although getting to grips with its configuration can be tricky.

One of the areas we have to ensure process is followed is with escalation of incident tickets, our incident tickets are identified with an issue type of “Incident” and we have a special “incident priority” field which is simple P1, P2 or P3

Incident priority

So the challenge for us was how do we make sure that each tier of escalation gets notified and that it is clearly documented the ticket has been escalated?

This is where Jelly comes in, Jira has Jelly which is an XML defined way of doing programatic actions within Jira, a good link to open and read later will be this one all about Jira:Jelly and if like me who only found it afterwards these will be useful docs for Jelly: email http SOAP SQL core

Defining Filters

To get the escalations to work I used filters to show me all tickets that matched a certain pattern, so to do the first tier of escalation the filter looks for all tickets in the project and that are of the issue type “incident” and have an incident priority of “P1” and are older than X mins. To stop this coming up more than once the filter was also given some extra parameters to only show when it wasn’t assigned to the current escalation person or one of the higher up escalations. If it was assigned to anyone else it would then be escalated.

project = PROJECTID AND issuetype = Incident AND
status in (Open, "In Progress", Reopened) AND
"Incident Priority" = P1 AND created <= -30m AND
assignee not in (escalation1, escalation2, escalation3)

I won’t explain this too much, but “PROJECTID” will be the short code for the project in jira, and the escalations at the end are the usernames of those in the escalation tiers.

Here’s tier 2 as well so you can see how it filters for the next tier:

project = PROJECTID AND issuetype = Incident AND
status in (Open, "In Progress", Reopened) AND
"Incident Priority" = P1 AND created <= -45m AND
assignee in (escalation1) AND
assignee not in (escalation2, escalation3)

and the third for completeness:

project = PROJECTID AND issuetype = Incident AND
status in (Open, "In Progress", Reopened) AND
"Incident Priority" = P1 AND created <= -75m AND
assignee in (escalation2) AND assignee not in (escalation3)

As long as “assignee in” has the person of the previous tier in it and the “assignee not in” has those still left to be assigned to it should work okay…

All these filters do is show tickets at various stages of the escalation process, because of that it is possible to associate that with a jira jelly script to actually carry out actions on it.

Jira Jelly

Remember that link earlier? the one to the Jelly page? well that will help with the others above… Now you need to know what to do.

You have a way of filtering out the tickets so you can now write a script to do something at each stage of the escalation as needed. In our case we need to maker sure the user receives a notification and that a comment appears in the ticket so it is clear it has been updated.

The first attempt of this was to simply add a comment with the newish @user mentioning system which then automatically lets the user know they were mentioned. Unfortunately when using the add comment method it simply puts this in as text and when expanding the short hand to the full [~user] it just entered as text which means this method was not viable for us so instead we just simply assigned the ticket which has the affect of also adding the person to the watchers.

To do this sensibly it requires a few steps, a Login, the use of the filter to find the relavent tickets, a comment added and an assignment to happen.

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log" >
  <log:info>Running 'Escalation for Incidents - t1' service</log:info>
  <jira:Login username="escalationuser" password="XXXXXXX">
    <!--  Escalation People -->
    <core:set var="escalate" value="escalation1" />
    <!-- Run the SearchRequestFilter Filter is Open PROJECTID P1's-->
    <jira:RunSearchRequest filterid="FILTERID" var="issues" />
    <core:forEach var="issue" items="${issues}">
      <log:warn>Escalating ${issue.key}</log:warn>
      <jira:AssignIssue key="${issue.key}" assignee="${escalate}"/>
      <jira:AddComment issue-key="${issue.key}" comment="Escalating to ${escalate}"/>
    </core:forEach>
  </jira:Login>
</JiraJelly>

The filterid can be found by simply viewing the filter and copying the number from the end of the URL, hopefully everything else is self explanatory. for each escalation simply copy the file, update the filter ID and the escalation user

Install

1, Copy files to the server and put somewhere sensible that tomcat has access too, ensure the files are owned by tomcat and that tomcat can write to that directory.
2, In Jira, go to Administration -> System -> Advanced -> Services and add a new service, give it a name and select the built in jelly runner. Enter the location of the script and provide a log location.

jelly service config

That’s it. I noticed that having server access was invaluable, mainly because I was using VI and some syntax errors made it in which were hard to spot with out seeing the log, you can test your scripts using the Jelly runner which is also useful.

In short that’s it, hopefully that will be useful for people :)

Time for an idea

Why not

It’s been a while since I’ve thrown myself into an idea and tried to come out the other side, so I’ve spent the last couple of days just thinking about what’s missing. It doesn’t take much to have an idea; but making sure it’s a good idea, making sure it is unique in it’s offering and making sur eit’s better than anything else is not easy.

At work we are working on an idea, a concept of some sort of DevOps tool that takes a lot of what we do already and simplifies it and merges multiple tools into one place, the driving goal is easy of use, take an entire system, data centre what ever you want and within minuets you’ll have the whole thing monitored, feeding metrics back for reporting, performing real time analysis and trending. It’s still very much prototype phase but it’s a very exciting project that wraps up several elements that we as a team are passionate about, ease of use, efficiency, performance, monitoring, measurements and of course, cool technology; but with that said I still have this urge to do something else, I’m not really sure why, I’m busy enough as it is but I feel like the world is missing something that is more than just an amalgamation of parts, or a re-skin of an existing thing, I feel like it’s missing something, the question is as always what?

There’s a saying “All the good ideas are gone” probably true, but that doesn’t stop people striving for new things, look at Glass I’m not convinced it has a long term future in that styling, but wearable tech certainly does, look at this wrist computer from the tv show chuck, just what I’ve always wanted.

Wristcomputer

a lot of the best ideas today are based on things that have come before and re-envisioned, walkman -> ipod; iPaq -> iPad; alta vista -> google

Just because it’s been done in a similar way before doesn’t mean you can’t do it better, or take from their ideas and make it work and half of the battle is the conviction to want to do it better or different. Which is why everyone should try a new idea and everyone should try something new, to make something better.

What to do

This is the bit I’m struggling with, and it’s the hardest bit of the whole thing, for me it’s not good enough to take an idea and make it better, if someone gives you a product and says make it better it wouldn’t take long for a few ideas to bubble up. I’m thinking more along the lines of taking some wacky out there thinking and making it a reality in a way that works and works well.

I think over the next few weeks I’m just going to just write some things down and see which ones stand out, which ones seem stupid/crazy to do and then probably come up with one that works.

I’m not really sure what that is at all, I could take something like sentinel and munge that into something else, but it just doesn’t feel like the right idea. I had an idea a long time ago, probably 3 years ago, which I talked my self out of because it would take me forever to make and I didn’t have the skills, but things have changed, it isn’t even ground breaking it’s just another internet site.

Either way I’ll keep on plodding along for now and see if I can come up with something but until then much more scribbling on paper and throwing things at a wall.

To IDE or not

What’s in an IDE!

Over the last 15 years or so I have used a few IDE’s for programming “proper” applications in Pascal, Delphie, C/C++ or Java but since moving to the darker side of computing, the linux world I never really needed an IDE and they were just bloated text editors. I don’t think much has changed but there are some good points and I’m at a cross roads as to what to do.

Should I spend some time making Vim, the best text editor the world will ever see better or give up and use an IDE, it’s not as straight forward as I would like to think or as anyone else would probably think so I wonder how it will turn out.

The basics

I’m currently, and probably most likely to be doing web based development and Ruby / python. Up until recently I had just used Vim to get any Ruby programming I needed done, and to be honest it worked okay. I typically just opened a new terminal tab and then changed to the repo directory and started opening files, So I had to cd to a directory before opening the file it wasn’t killing me. I was able to just open and get on with making changes with no real hassle and with syntax high lighting it worked out quite well. Recently I have started to do more web based things and have started using an IDE for that and that’s what’s lead to this blog, there’s a few features of an IDE that I think I’m missing from Vim.

1, Being able to see the entire project directory easily and visually navigating to supporting files to have a quick view / edit is nice.
2, Refactoring, simple things like changing a variable name can be a real bugger in Vim, yes you can find and replace but that is not the same as refactoring, to refactor like an IDE does Vim would need to understand to some degree the codes structure and not to treat it all like text
3, Hiding chunks of code, being able to rol up / down sections of code can make it a lot easier to focus on what’s actually going on
4, Word completion, IDE’s know about the libs being used and the other variabels so can offer hints to complete the words being typed which is very handy
5, Short hand, being able to type short hand to do lots of things, like starting a html tag and having it auto completed speeds up development which must be good

I think if I could get the above features in Vim I probably would struggle to justify not using Vim, lets see what happens.

Vim IDE

1, This is seemingly an easy oen to address with something like NERD tree Initially this looks good so I’m saying point 1 is solved, just need some better aliases (:help 40.2)

2, In short, no, I’ve only seen normal find / replace or basically using grep, There does seem to be language specific ones like This but who wants to find a new refactoring plugin (if someone wrote it) for every new language…

3, This is again easy if you know what to look for Folding is not new and from my quick play seems good.

4, Again language specific it seems possible: this one for ruby, but what about python? javascript? etc etc

5, This one is a simple one that vim does do: Here but it’s almost like you have to hand crank it all!

Summary

So from what I can see I can spend some time making Vim do what I need, and no doubt there’s some stuff there for Ruby and Python that would make it a lot more useful to use as an IDE but it still doesn’t make it easy and will be rather language specific in terms of making it work well out of the box. It does seem that IDE’s are better at those specific tasks above, not to mention debugging and break points etc, maybe Vim can do more of that too and I just don’t know how.

Either way it coped better with the 5 original points than I thought it would and I have found some things out that suggest it may be worth tweaking my current vim to make it better. In the mean time I think I will continue to persevere with learning the IDE and it’s short cuts as it appears that it could dramatically speed up my development by just simply using the tools already there.

I wasn’t expecting to find vi to be as good as it was but in my head even though I prefer Vim at the moment I think the IDE will cope better in the long run, time will tell.

Pain and suffering with AngularJS

What a week!

Over the last month or so I have been steadily learning Javascript, Bootstrap, NodeJS and AngularJS well last week added to that mix was D3JS. I must have got to the end of my tether every day last week. I’m pretty sure I was suffering from information overload and before going any further I will say D3JS is really powerful and looks to be a tool I’d like to learn to use, the only downside is even after a week of drawing circles, bar charts and trying line graphs I am still struggling, but hopefully my struggling has not been in vein I learn some good things and if I’d known them before I’d started a lot less pain and suffering would have ensued.

The problems

So I don’t know angular, I also really struggle to read large chunks of text like the APIs, I did do the tutorial which helps but not really… There were a number of issues, not knowing how angular worked interms of where the right place to put things was a big set back, not knowing how to get data between the various components and updated was another. Another area of challenge was the asynchronous nature of Angular, making a $http.get request and not having data available instantly is odd but easily over come once you know how.

In importance order…

Callbacks

A long while a go I wrote a blog called What University forgot to mention about programming, it turns out this was one of those things that would have been really useful to be learning if the course wasn’t dumbed down to cater for those that didn’t come from an IT background at college.

In short I was doing this:

var data = [];

function getData(){
  $http.get('/api/data').success(function(response) {
    data = response;
  });
}
getData();
alert("data is 0!? " + data.length);

The problem with this is that getData is called and initiates the $http.get which does not return data, it returns the promise of having data; When it actually gets a response it moves on to the function declared in then(). Remember the way Javascript works is we passed in that function as an Object which then gets run when the data returns, it passes in the response for us to then handle. Because $http.get returns a promise that function is done, everything executed, the anonymous function we declared is a parameter that has been forked in the browser or language somewhere and is running isolated from everything else.

The way around this is to structure code in a way that allows for the callback to then do what you needed so….

function getData(cb) {
  $http.get('/api/data').success(function(response){
    cb(response);
  })
}

function drawGraph(newData) {
  //some code to draw a graph omitted...
}

//Draw a graph
getData(drawGraph);

By using the above method you only draw the graph when there is data, take this; rinse and repeat and all will be well, except this method is only really good for a one time graph. Controllers only get called once, they can be used to set up functions to be used in the view etc but they are ultimately only run once.

Data Binding

Firstly, read about Data binding. This first mistake I made was trying to do everything in a controller, it’s the most natural as everything in there gets run like when you include a normal js file, but it just makes life harder than it needs to be.

Originally I was doing something like this:

function getData(cb) {
  $http.get('/api/data').success(function(response){
     cb(resp);
  });
}

function updateData(data){
  drawGraph(data);
}

function drawGraph(data){
  //some code to draw a graph omitted...
  getData(updateData);
}

//Draws initial graph and then kicks off an infinite loop of getting data/drawing graphs 
getData(drawGraph);

I was using this to update and draw a graph. This works sort of but I was not able to get it to work because of my understanding of D3Js at the time, I’m sure smarter people than I could make it work but that’s not how it should be done; theres a better way like explained in the link above about data binding.

If you take your partial (template) and put certain triggers in it, even manual like ng-click you can do this a lot simpler, you can even use $watch to continuously update. so if you were to define a function or two like this…

In your controller:

$scope.updateGraph = function() {
  getData(reDrawGraph);
}

function reDrawGraph() {
  //code to RE-DRAW not draw the graph
  //Enter new, Transition, exit... more later...
}

In your partial:

<button class="btn btn-success" ng-click="updateGraph()">

You can make it update as you go. One step further would be to use $scope.data and just have a loop in the controller that sets that when data comes back, combined with a $watch to always re-draw.

Directives

Okay, so directives are useful, Until I learnt about them I was drawing all of my graphs from the controller and by far the must successful graphs I did were all in the directives area. I still think there was a better way because I was struggling to get it to work with $watch either way by having this layer you achieve two things, less crap in the controllers, and a nice location to do the DOM manipulation, which for graph drawing is kind of handy. Because this links right in with the html it is easier to manipulate.

Summary

These are just some of the major hurdles I overcame while trying to get D3JS working, and there’s more to come when I get on to D3JS which I have to admit I only got basic graphs drawn but I do think it’s an area worthy of diving into with more detail. All in all these experiences have made my understanding of Angular a lot better I am now able to quickly and easily make changes to pages to do basic things like looping through JSON data to display lists of data or forms to submit data.

A day of Javascript

Urghh!

Today I’ve been trying, trying really hard to apply some of that JavaScript knowledge to a simple problem, something that if I was doing it in HTML and PHP would have taken about an hour, and I’ve not done PHP for as long as I haven’t done JavaScript, but that’s not a fair comparison as like most people that used JavaScript in the past I did very limited things like pop up a window or an alert when something went wrong. I only had one thing to do today, add some functionality to a web app to upload files and store them locally on the server.

I’ve only spent 12 hours on it so far, and it sort of works if you ignore the fact that Drag and Drop won’t work an the progress bar doesn’t appear / update or that it doesn’t close the upload popup at some point, but if you’re willing to apply some manual intervention it will upload a file eventually and it will (after you’ve closed the upload dialog and refreshed the page…) display the new item.

I think some of the challenge is the many layers to the app, with html, css, javascript, bootstrap, angular, jquery and nodeJS; there’s just a lot of places doing stuff and it’s not all quite settled into my head yet… combine that with only recently having played with all of those and it’s a little confusing. I spent a lot of time trying to steal peoples code to save time from various open sourced git repos, I basically found that after stealing 5 and none working that I was wasting my time so I just took one as an example and went from there, This one in fact.

With in a couple of hours I had most of it down but not working, having dedicated this sprint to button first development I got the UI looking just right before moving on to any code. I then set about making the javascript bits work and I managed to get everything working apart from drag and drop, so it wasn’t posting data but it was showing files. For some reason the drop event I had setup was not getting triggered, every time I dropped something on it it did nothing ad the browser just opened it as a file.

Annoying, I imagine that something I’ve done in bootstrap or angular has had an impact on it but I don’t know and have just had to abandon it for now, maybe it’s the modal? maybe it’s some weird local issue, either way I’ll have to come back to it.

Some lessons learned

What’s the point in wasting a day on various elements of JavaScript if I’m not going to learn anything. Well I learnt loads! I learnt how to use the debugger in Webstorm which was pretty neat, once I’d clicked that button I found my issue in my node code really quickly, next time that will hopefully save me 2 hours :)
I also learnt that at my level of skill, using someone else’s complicated library for stuff is a bit hit and miss, especially if it requires working with multiple technologies that I’m also not familiar with…

In short at least by writing it my self / re-writing it from other’s examples I had some time to digest it and understand it, of course it doesn’t work but I fell better for having a go :) I am still relatively hopeful that in a few months this will all be second nature, but which time I would have probably forgotten all the ruby I know :)

Anyway, a short one today, more programming tomorrow and hopefully after another full day I would have the upload box working.

JavaScript and me

Where did it all go wrong

It must have been about 10 years ago when I first did some JavaScript and at the time I thought it was pretty good, I only used it on and off between then and university but with no real direction. I enjoyed JavaScript that much that I didn’t think twice about using it for my final year project at university, at the time Web2.0 and AJAX was all the craze but no libs existed and everything had to be done by hand. I was struggling to find a project in my final year and I happened across a geospatial professor at university and with google maps not having been out long I set about creating a geoblog that could be updated via email. it was a PHP backend with a Javascript and XML front end, there was just an index and everything, management, logins, maps etc was dynamic.

Cutting edge stuff! and yet I hated it, it took the magic out of the process and after I finished that project I vowed never to touch it again! well until I was forced into it…

Learning from the ground up

Last week I was sort of forced into it, although the week before I took my self to that pain so I am some what to blame.

Either way, I decided that this week would be a learning week so I’ve been going through W3 Schools and Code Academy to re-familiarise myself with JavaScript. I’ve got to say the Code Academy stuff was good and I’d recommend it to anyone that wants to learn how to program.

I found it useful to recap the stuff I could remember and I learnt a few things too, but then I came across This this which does a good job of explaining why certain ways of doing things are better.

I imagine that all of this reading and learning will help a little but I don’t do that good with reading… practicals are always good, so next week will be all about actually doing something with Node.js

Making something good

One of the big reasons for learning a language is to use it, and by having a practical use for it it helps motivate you to do more, luckily there is a project that we started and I have purpose. My role is the web UI / server side of a larger piece of work, luckily I have some help… Hopefully in a month or so i’ll be able to give out some more details but it will be a little while to get it up and off the ground and sort of doing what it’s meant to in a prototype style. If we can pull it off it’s fair to say it will revolutionise how we currently work and provide a good platform the managing what we do, really looking forward to getting it to the basic prototype phase so we can start iterating on each bit until it’s perfect!

When in doubt, use more JavaScript

Oh, gawd, why

Over the last couple of weeks i’ve been playing with some new technology, not to any depth but just enough to get a feel for it. The week before last it was all Python & Django followed by AngularJS, well this week has been a bit more Javascript in the form of Node.js; granted I’ve not done much but I’ve done some.

As always it started in a random planning session where we have decided that we will make our own tool that will replace our current monitoring tools, the architecture was all drawn up, queue services, agents, plugins, a super fast “worker” process for handling the queue and a management console for pushing commands in and displaying results.

Because of my last two blog posts I got volunteered to do the front end, which is good as I will learn more AngularJS which I would like and I will learn more bootstrap which I would like, I also thought I’d get to write a nice backend in the language of my choice; turns out, not so much.

Would it be Ruby now I’m getting proficient with it? maybe Python, the rest is in Python, I could live with python, it’s not too dissimilar to ruby. It turns out it would be in node.js, oh gawd why. I’m not a fan of JavaScript, and here’s why; back in the day for my university final year project, back when AJAX had just come out and there were no libraries to do it I made a GeoBlog, using google maps API’s, JavaScript and PHP. It had over 1000 lines of javascript, there were no debuggers, the best you had was a console to point out syntax errors. Well that was a nightmare, at least now things have improved with proper debuggers in the browser etc etc so this time would be better…

Sort of…

To be honest node.js isn’t that bad to write simple things in, I’ve been getting more confused by having controllers and routes for both angular and node and trying to keep that separation in my head. I’ve so far been keeping good to my promise to do button first development so other than writing a simple api to return json I’ve not had to do much in node yet and only a little angular but at some point i’m going to get really stuck.

For some reason all these moving parts haven’t yet fallen into place and I’m wondering if I need to go back to some basics and re-vist javascript in it’s pure form and start building on that to get int node and angular. At the moment my coding is purely google, copy, paste, edit; not much in the way of understanding and if I’m going to make this thing work I need more of an understanding.

Maybe I should start with my old friend w3schools followed by some Code Academy followed by all of these

Busy week ahead I think, wonder if it will help or confuse me more, either way more updates next week I think :)

Angular.js – starting something new

Why not!?

Last week I played with Python / Django the natural extension of this was to not do python but to look at using something like Angular and bootstrap, the main reason for this is that just using python / django gives you server side manipulation but why do it all on the server? Ideally the server would generate relavent data and sent the data back to the client for processing, this is how the internet is meant to work after all. Think about simple HTML and CSS, HTML is just a data structure and CSS formats that to make it look pretty for you, now, with modern computers being so powerful, why not have it do the formatting in CSS and also manipulate the data into the right structure.
This way the server just generates a response of say JSON and the client takes this and manipulates it into tables / lists or what ever you need. Another advantage to this approach is all of a sudden you have an ajax driven website with not too much effort which is more efficient on bandwidth, combined with local client side caching of information the user experience should be pretty quick and seamless with or with ut the server, as long a sit pulls the dat to start with it should be okay.

So that covers why Angular, Bootstrap on the other hand is more or less just CSS but quite frankly, I can’t do CSS it never looks right so by using bootstrap I can then programatically set out hierarchy and classes etc while leaving the pretty styling to a theme generator Like this or download one Like this

Tasklist

Okay this is not really fully featured.. You can’t delete stuff from the list it just gets bigger and bigger but was only done to use the combination of applications in the right way and see if it worked, well it works, you can add tasks and it displays them so lets have a look at how pretty it is:

TaskList home

I was only able to achieve this level of prettyness because of bootstrap my past sites have all looked terrible…
The home page just includes some example code from the AngularJS website to prove I managed to get Angular working before butchering it with my typos.

Here’s a picture of it listing the tasks…

TaskList list page

So for starters if you’d like to criticise the code the best way of doing that is on GitHub I have no intention of making it any better but if you want to play with Angular, Mongo, Python and Django where python/Django provides a rest api to the DB and Bootsrap/AngularJS provides the front end then this has it all and the set up is pretty straight forward and some brief notes on install / settings in the README. Maybe you could add the ability to edit or delete tasks maybe put a checkbox next to them and track a done status who knows…

Overall…

I quite like Angular and bootstrap as a combo, I think it’s got some real potential to do some powerful stuff and i’m sure people out there are doing some really crazy things with it, hopefully one day that will be me and there will be something worth while coming out of it. I’m not convinced on python/django combination, I’m sure it’s okay but I really need to write some more of it and see how it goes; I’m fairly sure it’ll be better than RoR but that’s not a good framework for ruby anyway.

My next task having played with those is to do something even more whacky, maybe some sort of node.js backend, angular boot strap front end and some sort of queue… The next project I’m working on with a larger team will be pretty good and once we have something up and working it can be shared, the oddest thing will be the “button driven development” approach to development, which is basically top down, where you prototype the interface to look as you want it to and then fill the data with dummy values or hard coded values. Once that’s done write a backend that provides the data. In theory by the time you get to do the technical nitty gritty there’s a very clear idea on what the output should be.

Python – A Django experience

For a little while

The team here have been looking at rapid development of web applications and have been trying python with Django to deliver some nice projects in a short period of time and with good results thus far. Up until the other day I really hadn’t done anything with Python and I had no intention to, but as these little skunk works projects have come to an end and the results look okay I figured it was worth learning a little.

Now, there’s always two approaches to this, start slow, learn python, learn some django and keep building on it until it all works and is fantastic or just dive in, I chose to dive in. The downside of diving in is you end up with some stupid errors where you don’t know the syntax, how the frame work works what should be done etc etc so you spend a lot of time googling! The advantage of this approach is you tend to learn more quicker, especially if you’re like me and struggle to read the doc and then apply, i’m only good with example sand then making mistakes, but with examples you’re on auto pilot.

So I had a bit of a chat today about the structure of Django where to put certain things and it was suggested to do something simple like a task list so that’s what I did, I made a simple task list, I decided to complicated it by using mongo as the database which the only example I had of it did not make use of the models in Django but tbh, I dived in i’m not sure what i was meant to to do there anyway… Although…. I do know that with MySQL I can use the models to outline the database structure and have the manage.py create the db for me, but alas I chose a harder route.

Some bad code

My view’s looks a little like this, I had started out with good intentions of using csfr but it was causing problems so I ended up removing it, in fact I removed quite a bit to simplify this to make it easier to debug, and it worked as this now works…

# Create your views here.
from pymongo import Connection
from django import forms
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse, HttpResponseRedirect
from django.core.urlresolvers import reverse


def add_task(request):
    return render_to_response('add.html')

def add(request):
    if request.POST['task'] and request.POST['detail']:
        databaseName = "test"
        connection = Connection()

        db = connection[databaseName]
        todo = db['tasks']
        task = {"task" : request.POST['task'], "detail" : request.POST['detail']}

        todo.save(task)
        
        return HttpResponseRedirect(reverse('task.views.list'))

def list(response):
    databaseName = "test"
    connection = Connection()

    db = connection[databaseName]
    todo = db['tasks']
    tasks = []
    for task in todo.find():
        tasks.append({ 'task': task['task'], 'detail': task['detail']})
        #tasks.append(task['task'])
    print tasks
    return render_to_response('list.html', {"tasks":tasks})

The template for the add is very simple, it’s just a html form really not templating involved and it posts to the add method (which may have been the issue with the csfr stuff)

<html>
<head>Test</head>
<body>

    <p>Testing django</p>

    <h1>list</h1>
    <table align="centre">
    <th>
        <td>Task</td><td>Details</td>
    </th>
    {% for task in tasks %}
    <tr>
        <td>
            {{ task.task }}
        </td>
        <td>
            {{ task.detail }}
        </td>
    </tr>
    {% endfor %}
    </table>

</body>
</html>

As you can see the template is straight forward, the bigest issue I had with the template is I was generating a json string so

tasks.append("{ 'task': '"+task['task']+"', 'detail': '"+task['detail']+"'}")

Although this looked okay it was really a problem, either way, so far from what I can tell Django is okay, python isn’t too bad and I will do some more over the coming weeks to help me understand it better but it seems okay, nothing to sing about just yet though.