Getting to grips with the Ruby OAuth gem and the Twitter API

Wednesday, 29th February 2012 - Michael Halls-Moore - 0 Comments

I'm a relative newcomer to the Ruby/Rails world. I'd not had the need to add Twitter to a site before, but I had an interesting scenario yesterday trying to Tweet from one of my project sites via Twitter/OAuth. Here's how I did it.

I spent a good deal of my afternoon yesterday ploughing through the Twitter API documentation as well as figuring out OAuth. Hopefully this brief tutorial will stop you having to pull your hair out if you want to start allowing users to Tweet from your web page.

The first thing you need to do is register your app with the Twitter API at https://dev.twitter.com, making sure to select read and write access when creating an app. I missed this at first, having selected read only. The important parts here are to make sure that your callback URL is correct. It needs to be of the form:

http://yourdomain.com/auth/twitter/callback

For local testing you may need to replace yourdomain.com with 127.0.0.1:3000 (for local Rails apps started on the Rails server with the default port). Make sure you do NOT use localhost:3000, it does not work.

You will need to install the OAuth Ruby gem in your project/gemset:

sudo gem install oauth

Note: Better installation instructions can be found here.

Once that is installed, you need to go through the token preparation process in your Ruby code. This means obtaining the Consumer token and secret keys from the Twitter Developers site for your application, then adding them into the following code:

require 'oauth/consumer'
 
# Exchange your oauth_token and oauth_token_secret for an AccessToken instance.
def prepare_access_token(oauth_token, oauth_token_secret)
  consumer = OAuth::Consumer.new("APIKey", "APISecret",
    { :site => "https://api.twitter.com",
      :request_token_path => '/oauth/request_token',
      :access_token_path => '/oauth/access_token',
      :authorize_path => '/oauth/authorize',
      :scheme => :header
    })
 
  # now create the access token object from passed values
  token_hash = { :oauth_token => oauth_token,
                 :oauth_token_secret => oauth_token_secret }
  access_token = OAuth::AccessToken.from_hash(consumer, token_hash )
  return access_token
end

The above function will need to be included into an app/helper or similar include file if you are using a web framework such as Rails. The parameters to the function are the OAuth tokens given to you by the user when authenticated to your service (via Omniauth or some other mechanism). The "APIKey" and "APISecret" are your application's consumer keys which you obtain from the Twitter Dev site.

In order to actually Tweet as an authenticated user who is signed into your service you will need to prepare a token and then perform a request again the Twitter API. Here is the correct request to use to post a Tweet, via an account of an authenticated user:

update_hash = {'status' => 'Hey look I can tweet via OAuth!'}
access_token = prepare_access_token(token, secret)
response = access_token.post('https://api.twitter.com/1/statuses/update.json',
    update_hash, { 'Accept' => 'application/xml' })

Where the token and secret are, as stated above, the user's Twitter OAuth keys that you will obtain on sign in to your service.

At this point, you can start experimenting with additional parameters to your update_hash, such as entities (images, links etc) and in reply to links. The following provide some good docs/tutorials on the subject:

Releasing an open source compressible flow solver

Wednesday, 29th February 2012 - Michael Halls-Moore - 1 Comment

This is a quick post for those of you who are interested in Computational Fluid Dynamics (CFD). I've decided to construct an open source compressible flow solver based on the method of Godunov and smoothed particle hydrodynamics (SPH). This will allow the software to be used in a broad set of applications across aeronautics, astronautics and astrophysics. It is early days yet, but I'll be building out the solver in the months to come.

You can check out GodunovSPH on the Github page.

If anybody wants to get involved, feel free to get in touch.

Some Advice On ISAs, Spread Betting and eBay Trading

Saturday, 11th February 2012 - Michael Halls-Moore - 0 Comments

I was emailed by Robin today, who asked for advice on regular smaller sum investing:

"...I would be very interested to see an article discussing some of the best investment opportunities for those with a very limited sum to invest. For instance, I currently put £200 a month into a Halifax medium risk share pool - given the overheads with each transaction this seems a better approach than investing in my favourite companies directly. For my situation is this the best approach, or would a better strategy be direct investing, spread betting, trading on eBay, or any number of other opportunities? An article comparing the myriad of investment opportunities at this scale, and a discussion of longer term strategy and investment diversification would be very interesting..."

Thank you for the message, Robin. It's always great to hear from people that are starting their journey towards financial freedom via intelligent investing.

Firstly, I want to make it clear to others that it is not beneficial to begin investing until you have cleared off all debts (excluding a mortgage), have started to budget properly and have saved up a 'rainy day' liquid cash reserve. There are two reasons for this. 1) As an early investor it will be tough to invest in a manner that will outperform the interest payments on any debt currently held. In addition, 2) If you need access to cash quickly for an emergency or other unexpected reason, it may be a poor time or difficult to sell out of your investments to fund the cash shortfall. Therefore eliminate your debts and have some cash saved first!

Once you are in this position it makes perfect sense to allocate additional spare cash towards investments. As Robin pointed out though, there are so many choices it makes it difficult to decide what to do.

The first consideration is taxation. It will be your largest cost as an investor and so it is necessary to find a tax efficient means of investing your cash. For those resident in the UK, the best vehicle to begin with is a 'Stocks and Shares ISA'. At the time of writing it will allow you to invest up to £10,680 per annum in a tax-sheltered manner, but this is rising to £11,280 for the next tax year. Any gains generated in the year from your investments will not be taxed either as income or capital gains. This is because contributions are made to an ISA with after-tax income, which would otherwise be taxed twice.

ISAs give you a broad choice of investment possibilities, including stock in individual companies, UCITS regulated funds such as unit trusts and 'open ended investment companies' (OEIC) as well as corporate and government bonds ('gilts' in the UK). As a consumer investor, ISAs provide a great choice of investments. There are many firms who provide ISAs, including retail banks as well as fund entities such as NS&I, Fidelity and Hargreaves Lansdown.

However, at Robin's scale of £200 per month, it will be challenging to avoid having any gains in individual company stock eroded by transaction costs. Thus it makes more sense to invest in a collective-scheme, not unlike what Robin is doing now. Depending upon what you believe is likely to perform this year, you could invest a sector-based fund, a bond fund or even gain exposure to the whole market via an 'index tracker'. The annual Total Expense Ratio (TER) is likely to be far cheaper than the sum of all transaction costs that could be incurred by individual corporate stock investing over a year.

Robin also asks about Spread Betting and ebay Trading. Let's start with the former. Spread Betting is a form of leveraged speculation, which allows one to take viewpoints on the direction of a wide range of financial assets and leverage up this view. It is actually a form of financial derivative, but we will concentrate on its importance to a consumer investor.

The three main advantages of Spread Betting are 1) That it is completely tax free (both from income and capital gains), as it is considered a form of gambling under UK law, 2) Positions can be leveraged in order to achieve higher returns and 3) There is a substantial choice of financial instruments to bet on. However, I do not recommend it as a beginner investment activity. This is because it carries the risk of significant downside loss, which can greatly exceed the initial investment if leverage is used incorrectly. It requires an incredibly disciplined and analytical approach in order to make a consistent return over the long run, as well as a great deal of time dedicated to research. Many people gravitate towards it because it is easy to get started with limited capital and provides the potential for large upside. As a beginner investor it is better to stick to simple straightforward methods as a 'first go'.

Note: I will be discussing techniques to become a sophisticated spread trader in a later set of articles.

Robin finally mentions eBay trading. The basic idea here is simple: Buy or obtain items and sell them on for more than they were purchased for, minus expenses such as advertising and postage. eBay trading is nowadays quite saturated so it is best to concentrate on a niche market. Make sure there is demand for any products that might be offered and that after purchasing the items, usually via wholesale, there is still room to make a profit after delivery, packaging and advertising expenses have been taken into account.

The major benefit of eBay is instant distribution availability - the same reason that many people are currently developing iPhone and Facebook applications. The flipside is that all trading has to be carried out with their platform with any associated restrictions or changes. Hence you are 'not in control of your store'. As an entrepreneur, I think eBay trading has a lot of mileage, but it is certainly not a get-rich-quick scheme. It will take a few months, maybe a year, to get up and running towards a consistent profit. As an alternative to traditional share investing, it is attractive, but it does require some time.

In summary I suggest that an index-tracker or a sector fund is a good means of testing the investment waters as the transaction costs, and taxation through an ISA, will be low. In later articles I will answer Robin's questions on diversification and longer term strategies.

Thanks again for your email, Robin. If anybody else has any investing questions, do not hesitate to get in touch.

Why Shared Working Spaces Make Sense For Startups

Friday, 10th February 2012 - Michael Halls-Moore - 0 Comments

I've recently become a member of a new shared working space called Hub Westminster. It has been hugely beneficial for me, both from a contracting point of view and for running my new business.

Shared working spaces are fantastic for new startups. Here's why:

1) Financial savings. Startups are invariably cash-poor in the beginning. After the usual seed-funding round one of the first expenses that a pre-revenue startup incurs is office space. However, upon reflection I do not see an immediate rationale for this decision. An office for a typical startup requires a number of recurring payments such rent, heating, lighting, water, internet connectivity, council tax and a myriad of other one off costs such as furniture, a printer/scanner (and toner!), fridge, cutlery etc. This is a large initial set of outflows to make for a fledgling firm, especially when there is little to no cashflow. A shared working space has already spent these costs and can gain better rates at volume than you could individually. These savings are invariably passed on to you keeping your outgoings leaner in the early stages.

2) Time savings. Another commodity that should be spent wisely is time. At the outset there are likely to be no employees and a handful of founders. At this stage, everybody does everything. Renting an office requires sorting out accounts for the costs outlined above. Landlords, energy suppliers, ISPs, local councils and water firms all require time to communicate with. Not only that but furniture must be constructed, drivers installed, walls painted and computers set up. Why waste all this time when you have so little in the early stages? A shared working space provides all of this, ready to go, on day #1.

3) Meeting users/testers/customers/clients. Being a member of a collaborative hub gives you immediate access to a large group of willing users who will be happy to test your site. You are getting out of the building while being in the building. I've not yet met anybody working in a hub environment who isn't willing to take a look at a web service or hobby site I've just built, usually offering incredibly helpful feedback. Some of these people will convert to early customers or key influencers - who will be available most of the time very nearby. This saves a huge amount of time at the customer development stage.

4) Meeting co-founders/employees/freelancers Another benefit of being part of a community is the availability of people who are skilled in specific areas. At the Hub Westminster I've already met (and am working with) great coders, designers, testers and communicators. These people are the sort of folks who end up becoming co-founders. Not only will you get to know them over a reasonable time period, but you don't have to suffer through 'founder dating' or other contrived forms of pre-funding collaboration while you get your startup off the ground.

5) Events. One attractive feature of a strong community are the frequent events. I myself have started the Hub Hack Night with James Arthur, which aims to bring together coders, designers and entrepreneurs to build technology in the social enterprise space. It is already proving beneficial to both of us, as we are now able to speak from a position of thought leadership, in essence, providing a means of indirect marketing for our projects.

The mechanics of most shared working spaces are simple. Monthly pay-as-you-go membership, volume discounts for multiple stakeholders of the same firm, fantastic internet connectivity, clean environments, centralised and shared resources as well as great people. There are few disadvantages.

Having an office with expensive chairs, beanbags and pool tables may make you feel warm, fuzzy and 'startup-y' inside, but in reality you've just wasted a month's payroll or marketing budget on items you really don't need at this stage. Next time you plan to start a business, give serious consideration to a shared working space - it will save you a lot in the early stages, right when you need it the most.

Eliminating Time-Wasting Activities

Wednesday, 8th February 2012 - Michael Halls-Moore - 2 Comments

Another major reason why most people aren't wealthy is that they spend their spare time carrying out activities which are, at best neutral in their utility, or harmful to their health and financial well being.

Freeing up your time is absolutely crucial towards becoming wealthy. It allows you to perform a task that most people in adulthood do not bother with - actively learning on their own. My favourite motto is 'Knowledge Is Freedom'. In this sense I mean that knowing more will grant you natural leverage and a far greater decision making capability, which will ultimately lead you to becoming more wealthy when dealing with financial affairs.

Let's briefly discuss how to cut out television from your life, as an example. If you get home and watch 3 hours of TV a night on average, over 30 years you will have watched just under 4 years of TV. That is 4 years of your life sitting in front of mindless commercialism, not really learning. If it is broadcast TV, then you will have spent approximately 1 year of your life watching commercials. Scary? If you have a Sky+ multi-channel subscription type package, then with the extras, this will cost you approximately £23,000 over your lifetime. In fact, the opportunity cost is far higher, as that money could have been invested.

What else can be eliminated? Commuting is another time-killer. If you spend an hour each way commuting to and from work, you will spend approximately 20 days of your life a year in a commute. That means over 30 years you will spend over 1 1/2 years of that time commuting. So far, we've determined that TV and commuting take just over 5 years of your life out of a 30 year period. There is so much more to do in life than sit in a car, train or in front of the Idiot Box.

In the early stages of becoming financially independent, time can be thought of somewhat like money. Later on you will realise that time is a much more important commodity as money can be generated from money, whereas time cannot. Time is finite and thus is the most important commodity.

Time is the most important commodity you possess. Spend it wisely.

What do you do with that extra spare time? Easy. Spend it with your children, spouse or partner. Learn a new skill, such as healthy cooking. Play a sport, an instrument or learn how to invest better! Remember, the whole point about investing is to free up your time. Give it some thought.