As to why my email broke!
Today I found out that I wasn’t receiving email correctly. This was pretty distressing given I was awaiting the result from the first round of SVIP (Silicon Valley Internship Programme) interviews.
Over the weekend I switched my blog over to Ghost running on Red Hat’s awesome OpenShift platform. Before this, my domain name, ‘prydoni. us’, used to point to my VPS’ static IP and I had MX records set up for Google Apps Email.
To point my domain to its new home on OpenShift I needed to change canada goose gear up outlet to a CNAME record pointing at my sub-domain, since OpenShift doesn’t have static IP addresses. It turns out though, that CNAME records don’t play nice with MX records.
If a CNAME RR is present at a node, no other data should be present; this ensures that the data for a canonical name and its aliases cannot be different.
What seems to happen is the lookup ignores the MX records set up on the root domain, and instead looks for MX records on the host domain (in this case, the OpenShift sub-domain).
A simple enough workaround is to setup the root domain as a 301 redirect to a sub-domain that has the CNAME record. I already had http: //blog. prydoni. us with this setup, so redirected http: //prydoni. us to that and voila! Emails started coming in again! Looks like I am going wake up to a whole load of missed emails tomorrow though, awesome…
On the bright side, I got through the first round of SVIP interviews! Looking forward to hearing from the awesome startups I’ve been matched with!
I recently had an interview where I was asked to implement a key-value store with a twist, in a language of my choice. For straight-forward programming tasks like this, I like to use Ruby.
Since I can’t mention the actual problem I was given, I will describe a different, simpler problem to illustrate the power of syntactic sugar in Ruby. Let’s implement a key-value store that capitalises values (assuming all values are strings). We can make use of the built-in Hash library so that we don’t have to fuss around with hash functions and the like.
A simple implementation of the problem would be like so:
We simply keep an internal hash table, whilst adding our own accessors to handle the capitalisation of values. Again, we’re assuming that all values will be strings, so we can omit a type check.
We can now use the capitalised key-value store like so:
This is the general solution that one could implement in most languages. However, we can leverage Ruby’s syntactic sugar to make this more interesting. I’m just going to throw some code at you:
All we have changed are the method names. Hold on though… can square brackets really be the name of a method? How odd.
Let’s take a look at Ruby method naming conventions to understand a little more about what we’re doing here.
Method names may contain letters, numbers, an _ (underscore or low line) or a character with the eight bit set.
— Methods – Ruby Doc
The documentation goes on to say that method names may end in either:
An exclamation mark — to indicate that the method modifies the receiver
A question mark — to indicate that the method returns a ‘truthy’ or ‘falsey’ (All objects can evaluate to true or false) value
An equals sign — to indicate an assignment
In addition to this, method names can also be standard operators (+, -, *, / etc. ), but these only accept one argument. Unary operators can also be defined and are suffixed with an @ symbol. For added fun, we are also allowed the array lookup non-operator (), which is what we’ve used above.
All of these conventions can be seen in the built-in Ruby libraries.
The receiver, a, is modified directly. The non-exclamation version of String#capitalize will return a capitalised version of a without modifying it.
Returns a true or false value we can use in Boolean expressions.
Provides a setter for the default value returned when a key doesn’t exist in the hash table.
The binary addition operator with one argument.
So where does all the syntactic sugar come in? If we think about the way normal instance methods are called, we can start to see that Ruby is doing something magicky under the hood for us.
Taking the last two examples, we can call these functions like so:
Ruby implements an object-message protocol such that method calls are actually messages to another object. These messages consist of a name and an (optional) payload. The payload is the list of Ruby Objects that are the arguments of the method.
Since method calls are actually messages, the methods themselves must then be the message handlers — the action that is performed when a message is received. Ruby provides the send method to invoke a message handler in an object.
So the above methods, can also be expressed like this:
However, doing canada goose gear up outlet this way can easily lead to some confusing code, and is not analagous to the way of doing canada goose gear up outlet in other languages. This is where Ruby’s syntactic sugar comes in, allowing us to transform the above into something more natural:
This is more in line with what we see in most other languages, but the important point to take away from this is that Ruby gives us the power to define our own methods that can take advantage of special syntax.
This is an extremely important and useful feature. It allows the programmer to build an API for their objects that conforms to the overall language design. In the FancyCapitalHash example, we can expose the same syntax as the built-in Hash class so as to provide a drop-in replacement.
In more traditional languages, one could implement the assignment syntax using properties (setters), much like attr_accessor does. However, we can apply the assignment syntax to any arbritary method in Ruby — even ones that don’t actually assign anything if we wanted to! This flexibility is one of the reasons why Ruby is home to many DSLs (Domain Specific Languages).
Ruby is simple in appearance, but is very complex inside, just like our human body.
The importance of creativity in web development was emphasised recently in one of my Web Technologies lectures.
You need technical skills for web work, to know how to do things. But you also need creative skills, to know what looks and feels good.
Complement this with the multitude of CSS frameworks available to us now, making it easier for developers to design semantic websites by conforming to well thought-out standards. This is more in line with traditional desktop/mobile application development paradigms; standard libraries with standard components. I have already spoken about how useful this can be for developers, standards are a good thing. They allow users to become familiar with the components of a web page through uniformity. However, does this not impact our creativity?
It’s not fair to say that every website built using a framework will look like the scaffolding the framework provides. The point is to customise to the look and feel you want, whilst still making use of a set of standard components. Going back to the mobile/desktop application analogy, all apps use the same user interface APIs whilst also being visually different from other apps. However, it makes it very easy to fall into a trap where it’s easy to ignore customisation of the look and feel. It already looks great with little to no effort, why s.