PAF #3 Svenska Ord

It’s been just over two months since we moved to Stockholm. It’s been relatively smooth sailing so far, largely thanks to our awesome housemates and the general hospitality of the Swedes we’ve met. Almost all Swedes can speak perfect english, save a number of migrants. Ironically, it turns out that you usually get better service at shops if you speak proper english as opposed to attempting to speak Swedish.

Which unfortunately turns out to be a massive problem if you’re actually tring to learn Swedish. I’ve not felt it as much since I’ve been doing stuff by myself for the most part and haven’t had to converse in Swedish very much, but it’s alot more tricky for Marty since the default conversational language at work is Swedish. It’s particularly bad when they have Fika, or coffee break, where they gather round and have coffee and cake…and speak mostly in Swedish.

One of our goals coming over was indeed to learn Svenska (that’s Swedish in Swedish) in the time we were here and we made some good headway initially. As things got busier, Marty with work and me doing PAFs we’ve put aside less and less time to actually try and pick it up. Marty keeps going on about the previous app she used for learning chinese and how there wasn’t an app with the features she wanted for learning Swedish. And so, therein lay PAF #3, Svenska Ord or Swedish Word, an Android flashcard app. It’s somewhat of a cop-out because it’s in Java/Android, and I’d like to justify it by seeing it’s the first project that will actually provide some actual practical benefits to us 😛 I’ll be attempting to do as much TDD as possibly, so we should have a nice set of tests at the end. Realistically I think the coverage will be mostly at the back-end rather than the front.

Here’s a copy of the spec Marty put together when we were planning for PAF #3:

On a side note I’ve gotten annoyed that I don’t get notified when folks reply to my comments on other blogs, so I’ve installed subscribe to comments reloaded on my instance. Let me know if you run into issues with it. 

PAF #2 Show and tell

Download a copy from here – https://www.copy.com/s/Vll48QtmIRDp/BishiBashi.apk Do give it a shot with a friend or two and let me know what you think!

Horrendous code is available at https://bitbucket.org/minantan/bishibashi

It’s basically a port of the first level of Hyper Bishi Bashi, Karate Master! (See this video , approx 16s in) with various tweaks and omissions

Main features:

  • 2p over a network
  • 1p easy, medium, hard, high scores and how to play

Issues:

  • If using WiFi tethering, the WiFi provider needs to be the client. Didn’t have time to find out why :/
  • Only one game can be played on the network. I’ve set the client to auto connect to the first available server 🙂
  • The random seed is not so random
  • Various exciting bugs and clipping/alignment issues

Here’s some pictures from the simulator:

I wrote it using the Corona SDK , which should mean someone with an Apple Dev license would be able to take my code and compile it straight for iOS devices and play with someone using an Android device. I’m not as happy with this fortnight’s project though, mainly because I didn’t do very much up front planning and the development suffered, both from a lack of clear direction and a lack of understanding some basic ideas behind the SDK. I wasted much time flip-flopping between what to use, and the design / what passed for architecture grew organically, which made for some pretty horrendous code.

Main takeaways:

  • Enough upfront planning needs to be done before starting on a PAF. At the very least this should include:
    • A clear idea of what I’m actually building. It doesn’t have to be detailed, something like this napkin should be sufficient
    • Commitment to a base technology stack
  • The development loop with Corona is pretty cool. Its promise is you can write your code in lua, and it will compile down to iOS and Android. They’ve built their own simulator for the devices that loads, refreshes and is playable in a fraction of the time (not sure about iOS devices, but the native Android simulator takes a while between app restarts). My loop was effectively change -> refresh -> play in less time than a page refresh. That said

    • There is no support for key presses in the simulator. Android’s back soft key button usually needs special handling
    • The simulator is not always accurate, there were a number of clipping and scaling issues between what was shown on the simulator and what was shown on bigger screen phones like an S4
    • You need at least Corona Enterprise (non-free) to access platform-native components not provided by the SDK, e.g. if you wanted to use WiFi direct that’s not provided out of the box by Corona, you’ll need to fork out some moola.
    • Lua feels clunky and immature next to Java or javascript. There is less depth and variety of libraries available for it, and its data structures are somewhat primitive. Seriously, it doesn’t have native support for finding an element within an array. Its arrays aren’t even strictly arrays, they’re tables (approx. a map) that have indexes as keys. Its array indices also start at 1  not 0 which tripped me up numerous times. On the flip side, it’s a small, compact javascript-like language that’s easy to pick up and get started with
    • (Free) IDE support  and native device debugging is non-existent
    • The SDK is also only available on Mac and Windows. Wine on Ubuntu works for the most part till you have to generate an APK. I ended up using wine for my dev loop, but running a windows virtualbox for doing the APK generation. On a side note, I was floored to find IE VMs being supported, maintained and made publicly available by Microsoft for testing.
    • Far and away though, the most troubling thing about using Corona is builds are done by  the Corona cloud. To generate an APK, it submits a request to the Corona build servers and hands you back an APK after voodoo. As far as I can tell, iOS devices have a similar process. Users of the free version SDK have to wait ~20s before their build starts. It also means if their build servers have a problem, you’re pretty stuck :/ There’s also a 100K revenue limit, but I’d be pretty happy with 100k 🙂
    • Despite all this, prototyping something simple in Corona is quick and easy because of the quick loop and small language. Which also means it’s really, really easy to write spaghetti code.

This post probably sums up much of the problems with the SDK itself and provides suggestions for a way forward from someone who has been using the SDK extensively. At the end of it, my feeling is if I needed to write something that would work on iOS and Android quickly, I would probably go with Corona today. If I only needed to support Android, I would probably go with a native Java stack.

 

PAF #2 – Bishi Bashi

Best explained with pictures as I’m not even sure how I’m going to make it work yet

Hyper_Bishi_Bashi_Champ_-_1999_-_KonamiAndroid-4-finalmente-sobrepasa-a-Gingerbread1 

I wanted to try Corona and Lua but it didn’t seem to have good Linux support and its access to native Android APIs seemed too restrictive for my liking. I decided to try Titanium as a mini-copout as it’s in javascript. Scratch that, Titanium is worse. I really want try and work on something non-java so I’m going with Kivy for now.

After some time playing with them, I’m back to Corona and Lua.

While playing with Corona’s physics samples, here’s an idea for a game: how about a sandboxed physics world with a loophole, like a crate on screen you have to get offscreen somehow. Touching and dragging the crate makes it move and imparts velocity, but the walls prevent the crate from bouncing out. But you can drag the crate out of the screen 🙂

Börsen för alla

Several months ago I watched a TED talk by Wingham Rowan. The talk was about a “new” kind of job markets where employers were able to advertise job opportunities right down to the specific time they required, such that employees were able to fill the timeslots flexibly without committing more than necessary. He gave an example where a coffee shop owner can advertise four hour job vacancy for Wednesday next week, and then to get the position filled in time before the day arrived. Because the job advertised was very specific for its requirement (i.e. waitering), time (four hours on Wednesday) and pay ($25/hour), Wingham argued that people who could only work casually would be able to contribute, for example parents with small kids who will not be able to fill full time position. In turns, this supply of workers would be good for the workforce where the baby boomers have been retiring at a very fast pace. Wingham argued that sophisticated mechanism of market could be used to allow this job matching process to happen. Thus he insisted that market mechanism such as displayed at stock exchanges, should not be left only to the financial industry alone, but could be, and should be utilised for the benefit of the general public.

Although the idea is awesome, the practicality of securitising job markets is not that high in my opinion. However, I like his idea of utilising market mechanism to the benefit of the general public. In fact, I am not very sure why it has not been done, for the reasons I will elaborate on further.

 

The process of securitisation

Amazingly enough, it is hard to find definition of securitisation that is not related to financial assets. So here is one from a presentation from NYU mixed with my own wordings:

“Securitization is the transformation of an illiquid [material] into a security.”

So what is a security? By the same presentation, it is defined as below.

“A security is [a] tradable [product], and therefore more liquid than the underlying [materials]. Securitization of [material] can lower risk, add liquidity, and improve economic efficiency.”

The keywords here are the process of transformation of a non-tradable material into tradable products. Securitisation does not have to involve only financial assets. If, for example, my mum makes too much noodle for dinner, I can, by the process of boxing the noodles into takeaway containers, sell the noodles to my colleagues at work the next day. A big bowl of noodle that is sitting in my kitchen may not be easy for someone to eat, but once I package it nicely (yummy sauce included) to suit my colleagues’ lunch size appetites, it will be very easy for someone to buy it from me. I have successfully securitised my mum’s leftover noodle dinner in this example. I also wish my mum still cooks me dinner :(.

Some materials lend themselves very well to the securitisation process. In fact, most consumer goods are already in some sense, securitised. A normal size shampoo we typically find in the supermarket is about 500 ml, it is unlikely you will find a 2 liter bottle of shampoo. Similarly with a packet of peanuts, it does not get much bigger than 500 gr packets.

There is another key definition that was assumed in a securitised product, hence it was not even mentioned in the above definition. Securitised products have to have passed a certain quality check to be of the same standard. A government bond of 3% yield will give you half the income of two government bonds of 3% yields, as long as they are sold as the same “security”. It doesn’t matter whether you bought the bond through the government, or whether your spouse bought it through his friends. It will give the same amount of interest as they mature.

Large exchanges such as CME Group have some products that at first sight, may not fit into this homogenous quality standard. CME Group sells livestock, which are animals such as cows and pigs. This is the product description on what you can expect when buying the securitised hogs (pigs) from them:

“Stages of hog Production

The life cycle begins with the baby piglet. Each gilt (young female that has not given birth) and sow (mature female that has given birth) is generally bred twice a year, on a schedule to provide a continuous flow of pigs for the operation. To obtain the breeding stock, operators retain gilts that show superior growth, leanness, and reproductive potential as seen in their mothers. Boars (sexually mature males) used for breeding are generally purchased from breeding farms and have a working life of approximately two years.

Typically, it takes 6 months to raise a pig from birth to slaughter. Hogs are generally ready for market when they reach a weight of approximately 250 pounds. In 2009, the average federally inspected slaughter weight was 270 pounds with a carcass weight of 200 pounds. The weight at which hogs are marketed is affected by feed and hog prices. High feed prices and low hog prices may cause producers to sell hogs at a lighter weight while low feed prices and high hog prices might induce producers to feed hogs to a heavier weight before they are sold.”

The document then continues to explain other things such as the inventory of hogs:

“Hog Pipeline

One of the first pieces of information needed to study the hog pipeline is the size of the hog inventory. Hog inventory data can be obtained from the Hogs and Pigs report published by USDA’s National Agricultural Statistics Service (NASS). On a quarterly basis, this report provides information for all fifty U.S. states on the pig crop and total inventory as well as other relevant information regarding hogs and pigs. It also publishes a report on the litter size, breeding herd size, and the number of sows and gilts bred on a monthly basis.”

On this document, CME does not state that the pigs you get from them are clones of each other, but yet the exchange has gone a long way to ensure that at least each batch of securitised pigs are of the same homogenous standard: pigs that are of the same age, and size. The Hog Pipeline provides the crucial information of supply. If there are diseases infecting pigs, both buyers and sellers will be able to take that into account and react accordingly (prices will go up naturally, assuming no change in demand). Another thing to notice is that because the hogs are of the same quality, it does not matter which seller transacts with the buyer.

 

Let’s securitise mobile phones

It occurred to me that there are a lot of products around us that can be securitised, but sophisticated exchanges for them are not available yet. Consumer products such as mobile phones are very suitable to be securitised and to be offered as a “security” in an exchange ala CME style. The mobiles are already available in batches and of the same quality standard. A new iPhone you buy in JB Hi-fi is the same as an iPhone you can buy at Big W. Yes, there can be defects in the manufacturing process, but as the hogs example shown above, this should not stop mobile phones from being securitised. I also think it is far easier to make uniform mobile phones than raising pigs to the same weight range.

The main function of a market, is to assist the process of price discovery. Price discovery is a process to determine how much an item should be traded for. To do this, intention of both buyers and sellers are recorded in the form of orders. “Limit” orders allow people to specify the price to buy/sell, where as “market” orders are used as a shortcut to transact, similar to how people can click on the buy-it-now button on ebay if they do not want to participate in the auction. Whenever the price given by the buyer matches that of the seller, a trade happens, and it is recorded so that other buyers and sellers can use it as a baseline for future transactions.

Wait a minute, you might say, we have ebay, why do we need exchanges for new mobile phones? Ebay records the seller’s intention to transact at any point in time, but the same cannot be said for the buyer’s intention. If I want to buy a mobile phone, I have to do it when someone else is selling it by bidding in that’s seller’s auction, the more buyers, the more I lose out because the price is more likely to be higher. It would be nice if I can declare that I want a Samsung Galaxy S4 for $500 and then several sellers can outbid each other to give me the cheapest price for the mobile (rather than the other way around).

Recording the buyer’s intention is needed to make the market transparent. The current retail market is dominated by the large electronic stores that spend millions in advertising alone to reach the mass consumers. If I can broadcast how much I want to pay for the phone, maybe a much smaller retail shop will be able to match my price instead because they do not have to spend the money in advertising. Without knowing who the buyers are, the smaller retail shops cannot compete because their prices cannot be easily discovered by the masses.

Another characteristic of a sophisticated market is having anonymous sellers. In contrast to this, the seller reputations matter a lot in ebay. This is because ebay does not arrange settlement to guarantee that the transaction will be executed without fraud. Ebay does some of this, but only for big items such as automobiles, through its escrow services. In an exchange such as CME, this settlement service is usually assumed because all trades that have happened in an exchange has to be honoured. This is done in several ways, either by having escrow services, or having some margin account where the exchange can draw cash from the sellers in if the goods cannot be delivered to the buyer. Anonymous sellers (and buyers for that regard) are needed as without them, the product are not truly a “security”, as the reputation is not standardised. An escrow service may look like an overkill if you are just trying to buy an item for $5, but it is not necessarily so. It can be solved by having a margin paypal account of $10 for example.

Also, a market is usually region base. Australia has ASX, Singapore has SGX, UK has LSE, and so on. We can apply the same regional structure to this mobile phone exchange. Same region transactions allow more uniform shipping cost, and hence will be very beneficial for the buyers.

Of course this means that more people need to know how market operates, which I think is a good knowledge to know anyhow. I think the fact that the finance world is now so distant to the rest of the society is partly because the mechanism of how markets work is not as widely known as it should have been.

Right now the solution can already include one side of the coin. The sellers are already declaring their intention to sell on their websites, so those prices can be garnered and aggregated. It is then about recording the price that buyers want to transact on. Once that can be recorded reliably, smaller sellers will have easier time to reach the buyers and will have better chances at undercutting the larger stores. We, as the consumers, will be happier because we get better deals.

So why not? Why hasn’t someone come up with this*? Am I missing something obvious?

 

  • I have googled hard… The closest one I’ve found is camel camel camel. It shows some pricing graph, and treat each amazon item as a security. You can track and get yourself emailed on when the price gets to a certain point, but it stops there.

 

PAF #1 Show and Tell

Here are the results of my first PAF#1 in pictures and short words:

I learnt much, but a TL;DR:

  • It’s mind boggling how easy it is nowadays to pick up front end components and put a webapp together. Things like AngularJS lower the barrier to entry significantly, at the cost of magical complexity. Bootstrap makes everything nicer.
  • Good design is hard. You can spend hours and days tweaking how things look, it’s easy to get caught up with something small not aligning right, or CSS craziness.
  • Javascript is crazy/awesome, asynchrony is a core requirement but not built into the language. Consequently, many tools and techniques (callbacks, promises) developed to handle this. I tried to use pure callbacks throughout the project, I’m very very tempted to rewrite everything using promises because it sucked so hard.
  • It was nice only needing to work with a single language for backend and frontend. Only used Sublime throughout. That said, the cycle for frontend was still better than the nodejs backend (yes, i probably could have used nodemon but didn’t). As an added bonus of working with interpreted languages, all sources are available for the libraries you use!

Even though at the end of the day I only produced a grand total of…two pages, I’m pretty stoked that it took only two weeks. I’d like to spend much more time than I have to fix some bugs, improve the UI, clean up the code, and write about the details of setting up Express, NodeJS callback conventions, AngularJS anchorscrolling hell, but that could take another fortnight to get right. And I don’t want to break my rules too early.

It’s now available publicly at https://bitbucket.org/minantan/ebooker/ . The code in there is pretty nasty but does the job. I did feel dirty and thought long and hard about making it public, but decided to with warts and all anyway since clean code was not an express requirement 😉

The requirement of having poppler-utils installed makes it difficult to host as a demo, but ping me if you run into problems getting it working.