The intersection of technology and leadership

Category: Development (Page 5 of 18)

Resetting grant privileges on mysql root

We had a root mysql user account given to us for a MySQL database but somehow that account did not have the ability to GRANT others any privileges. Running:

select user, grant_priv from mysql.user

showed us that no users had that. A bit of searching around and I stumbled across this blog that demonstrated how. Running the following seemed to work:

update mysql.user set grant_priv = 'Y' where user = 'root'; commit; flush privileges;

Rerunning:

select user, grant_priv from mysql.user

now showed us that the root user had the GRANT ability. The following command also confirmed it:

show grants

USB Programming with Ruby

I have a current side project of looking for a simple to construct build radiator that is reasonably affordable from a hobbyist’s point of view. I came across this blog post, that used a sub £10 USB device for displaying the state of monitors. Although good, the drivers only appear to work on linux (not on my mac!) but I decided to not let that stop me.

I spent a couple of hours yesterday reading up on USB, the options around ruby (my current project’s development language of choice) and then the source code for the linux drivers written in C++. Here’s proof that I managed to learn a few things:

Outlining some of the things that I learned:

  • Two ruby libraries exist for wrapping the generic libusb library that vouches to be cross platform (win, linux, mac). The first “ruby usb” is one that I couldn’t get working on my machine partly because I couldn’t configure it properly to read my installing libusb. I went for the libusb (for ruby) library. This proved easier as they already had a gem for it.
  • The generic USB interface is pretty well documented. This website gives a good overall introduction. The concepts translated into the library quite easily.
  • At the heart there are some simple steps, but if you plan on controlling a device, you need to know the special “byte” messages to send as instructions. I don’t have an electrical engineering background, but I’m guessing this is similar when they write device drivers. Having documentation helps (this is where looking at the device driver code helps).
  • The libusb gives some pretty reasonable error codes, and because my device simply does not respond, I didn’t have to worry so much about any other processes controlling it at the same time.

Generic steps for interacting with a USB device:

  1. Create a new USB context to discover all the devices
  2. Find the device you care about. For this device, the property idVendor is set to 0x1d34 for Dream Cheeky and the idProduct set to 0x0004). They also had some string descriptions you could use. For example, the manufacturer property returned "Dream Link" and the product returned "DL100B Dream Cheeky Generic Controller"
  3. Once you have the device you first “open” the device to get a “handle”. Your system may already have a reference to it. If so, you need to “detach the kernel driver” before claiming it. As I said, I didn’t need to although the linux driver has that code in it.
  4. With the handle, you can now send/receive information to it. The USB property “bmRequest” prepares the device for communication. This page really helped me understand more, although I simply followed what the linux driver did to know what values to set.
  5. Make sure you close the handle when you’re done.

I learned way more than I needed to about USB devices such as devices hosting several configurations (though only one at a time) and they have a concept of endpoints, but wasn’t particularly relevant. Debugging the device with irb was great fun as I could dynamically query the device as long as it was connected. I’ll write about the ruby code in a different blog post.

Updating a Dynamics CRM Customer Record via HTTP

My current project integrates with the Microsoft Dynamics CRM system for managing customer records. We already spiked out authenticating and our next step was attempting to update a record via its “REST Endpoint“.

On retrieving a record, you follow the OData style for finding something of relevant. Updating a record is interesting as we only want to send the fields that need to change remotely. Looking at their sample code, you need to:

  • Create an authenticated POST request
  • Set the X-HTTP-Method to MERGE
  • Set the appropriate content type for the content you intend on sending. In our case, set the header Accept to application/json and the Content-Type to application/json; charset=utf-8

Our end point for a contact looked something like:

https://crm.thekua.com/xrmservices/2011/organizationdata.svc/ContactSet(guid'867dc3f2-909e-e111-9912-0050569c2d72')

.

Updating simple fields off a contact is easy. We post something like:

{
  "EMailAddress1":"spike.jones4@gmail.com",
  "MobilePhone":"33335"
}

We receive a HTTP 204 (No Content) on a success. Posting an invalid attribute (i.e. one that does not exist on the ContactSet such as “EMailAddreXXXs1”) results in a HTTP 400 (Bad request) and a nice description about what’s wrong. You will also get a HTTP 400 if you post the wrong datatype such as sending a string where they expect a number. If you pass invalid values (but of the correct datatype) for a field, your response is a HTTP 500 with a message like The value of 'gendercode' on record of type 'contact' is outside the valid range."

Updating Option Set Values

Updating simple datatypes is easy and obvious from a JSON point of view. You have a couple of complex datatypes, such as the standard GenderCode. When you query for a record, you get back something that looks like

{"GenderCode"=>{"__metadata"=>{"type"=>"Microsoft.Crm.Sdk.Data.Services.OptionSetValue"}, "Value"=>1}}

To update something like this, you need to send a nested JSON object. The example follows

{
  "EMailAddress1":"spike.jones4@gmail.com",
  "MobilePhone":"33335",
  "GenderCode": { 
    "Value" : "1"
  }
}

A HTTP 204 (No Content) response indicates a success. Viola!

Time Configuration Values for Nginx

A lot of the documentation for the configuration values for Nginx keep referring to the time value. These pages don’t directly link to the right page (so not helpful if you come in via a search engine) but you’ll find the documentation under the “References” section titled generically “Configuration Notation Reference”.

I’m saving this link here for my own future reference.

Constructor work in Scala

In the java/ruby world, I am used to ensuring my objects are created in a valid state. This often means validating/converting constructor arguments into a format necessary for the rest of the class to do its work. In java, the code (non-compilable) might look like:

public class MyObject {
  ...

  public MyObject(Set<String> values) {
     this.internalRepresentation = convertToLowerCase(values)
  }

  ...
}

In scala, most examples out there seem to only chain constructors, and not necessarily do any work to that. I looked on stackoverflow and found this answer although it doesn’t feel particularly clean to me for some reason. My scala code now looks like this:

class MyObject(var values: Set[String]) {
  values = values.map(s => s.toLowerCase)
  ...
}

What I don’t like about this is that I had to elevate my field to being mutable, or had to have two immutable fields on the class (the temporary one for the constructor, and the one that I really want to use). The tests are passing, but I’m sure there is a better way.

OOP Conference 2012

OOP Conference is the longest running conferences I’ve ever presented at. This year was it’s 21st year of running, and although coming from Object-Oriented programming roots, the contents of OOPConference have evolved with the times to represent so much more – just like JAOO has over the years.

This is the second conference I’ve presented at where the talks were in a mix of languages – obviously German, since the conference is based in Munich, and the other language being English. As a result, the number of sessions I attended was much lower than I normally would and I was able to catch up with a number of other speakers such as Johanna Rothman, Michael Nygard (author of Release it!), Kevlin Henney (97 Things curator) as well as meeting many new speakers.

I was also surprised at how many German speakers I’d met previously and got to practice a little bit of German. I did try sitting in on one session with a former colleague, Gregor Hohpe where he talked about (auf Deutsch) the Near-Field Communication technology the Japanese have. He talks pretty fast in English, let alone in German. I thought I was doing pretty well understanding the gist, but at probably half an hour into the talk, I think my brain seemed to explode and couldn’t take any more. A good way to test your limits 😉 Fortunately he also used lots of photos in the slides so I could follow along.

I attended a number of other talks in English, one on the latest going on in the NoSQL space (reminding me of a news commentary on what was going on) as well as one of the keynotes by David Parnas. I’ll admit that none of the keynotes blew me away. They all had good solid points they wanted to get across but the message not really new to me. I appreciated listening to Parnas’ talk because of his significant impact to the way OO-Programming is done, although his focus on documenting and enforcing contracts meticulously (whilst having its place) isn’t necessarily as relevant in the internet applications of today (but highly relevant in embedded systems that last for 25 years!).

Something I learned from his keynote was a new tool for better thinking about object oriented design, providing a table to help people classify what sort of information they want to hide and some recommendations to do so. Although probably not a very new tool, I think it has been forgotten through the passage of time and I know plenty of developers who could learn more about real encapsulation who’d benefit from it.

I had two sessions presented at OOP Conference. The first, “Learning to see, A Systems Thinking Primer” gave people a focused introduction to systems thinking concepts, the ideas of archetypes and applying it to situations in software. I’m really glad that a German audience proved much more interactive than I’d hope and I think it proved some interesting insights into topics such as Mental Models and such.

The other sesison was working with my Hamburg-based colleague, Ken Fassone on a “Night School” lecture/workshop Pair Programming: Good, Bad and Ugly (which I have to give credit to another colleague, Rachel Laycock for). I’m not sure some some people anticipated a workshop, but I’m pleased at how some people enjoyed it. We swapped exercises after a mishap with some supplies and shipment, but afterwards, realised how difficult it was for some attendees to do some sentence writing, with a new group, in a language that is not their mother tongue. They did way better than I ever could, and from the enthusiastic thanks from some of the participants at the end of the workshop, proved to be an enjoyable exercise as well.

Book Review: Continuous Delivery

I just came off my last holiday where I got through reading two books that I wanted to. One of these was the heavy but insightful tome, that I dragged in my suitcase, Continuous Delivery. Before I begin, I should warn you that I work for ThoughtWorks, and that both Jez and Dave (the authors) are and were my colleagues so take this into account with my review.

What I enjoyed

Continuous Delivery is a very practical book that covers a huge range of topics from cover to cover. I feel that they found a good balance between giving just enough advice (and more importantly why) with plenty more references for those who want to find a topic to delve deeply. I felt it really lays down the ground work for many projects (but not all) that need to see the light of day.

I think it’s also great that they not only outlined the practices and tips, but also outlined the principles. It gives the book much more merit and will make sure it stays relevant as tooling and new techniques are invented. On the flip side, they do give enough advice on tooling, and, at least, current up to date advice on how one might achieve things.

I like that the authors expressed their opinons strongly on some of their tooling such as, if you’re going to use a commercial source control system, how it should be used and why, or what the problems with the build process in maven or the limitations of various toolings are.

The book is peppered with war stories. I think I know some of the examples they cite, or at least, heard about it from other people and I think some of them are really strong stories about some of the ways people approach deployment.

What would make it perfect (for me)

I’m not sure if they framed the context of Continuous Delivery enough in terms of the types of applications it’s appropriate for. I know that there’s a current (constant) movement in the startup community of “just putting out there.” I think that is an alternative approach that works for some amount of time (or at least changes some of the testing/feedback process). I think for throw away apps (this one is always hard to judge), it may not be worth investing in the same degree of how much effort you put into the process. I think probably the closest advice but should have been expanded upon was, “be pragmatic about how much you automate.”

One particular headline (out of the very many) grabbed my attention, “Test targets should not fail the build.” After reading that section I think I understood what they meant, but it should have been relabelled, “Failing test targets should not immediately *halt* the build” -> it should still fail the build at the end.

Finally almost all of the chapters, for me, had lots of great advice and in working reaffirmed many of the conversations and thoughts I’ve had over my career. I did find the final chapter about “Risk Management” a bit thin, feeling like it was added at the end and either deserved much more attention or should have been dropped. It felt like it had a different tone, or was written at a different time and couldn’t quite see how it would fit in.

Having said that, these last bits are only minor points in a huge volume of rich information and is essential reading for anyone who cares about their profession.

Putting this into practice

For most of the clients I work on, the clearest and most difficult part of the organisation will be the (im)maturity of the operations side of the organisations. Most are already not set up for success with completely different parallel hierarchies from development and competing goals that go against constant change. I still see this, “last mile” problem being the hardest (at least for me to solve). I am hopeful about the DevOps movement and hope that the IT parts of an organisation can only take it much more seriously. I’m hoping this book shows how more companies can achieve this.

International character encodings and Winstone

I’m writing a little web application to help me learn some German (yeah, a bit of yak-shaving) and I wanted to deploy it locally using an executable jar. I wrote about how to do this previously using winstone and that worked pretty well. Unlike dealing with a normal English character set, dealing with letters like ß, Ä, Ü and Ö are pretty important.

It looks like, by default, serving static HTML from winstone doesn’t seem to work unless you explicitly specify the character encoding as UTF-8. A simple web-filter applied to all URLs helps us here. Here’s an example in scala:

import javax.servlet._

class ForceUtf8EncodingFilter extends Filter {
  def doFilter(request:ServletRequest, response : ServletResponse, chain: FilterChain) {
    response.setCharacterEncoding("UTF-8")
    chain.doFilter(request, response)
  }

  def init(config: FilterConfig) { }

  def destroy() { }
}
« Older posts Newer posts »

© 2024 patkua@work

Theme by Anders NorenUp ↑