In order to run your applications in an android simulator, you’ll need the android sdk installed. For the next steps, you’ll need to ensure that multilib is enabled in your /etc/pacman.conf file.
You’ll need the following packages installed from AUR:
After these have been successfully installed, using the suggested installation procedure guidance on the wiki, you’ll need to put these tools on your path:
Before you can run any applications, you’ll need to setup a device. No cpu images are installed by default, so you’ll need to install these first using the android command.
After installing the appropriate images, you can create a device using androidavd.
The C++ Standard Library provides an extensive library for working with streams. These are abstract classes designed to work with data that is in a stream format. There are comprehensive concrete implementations for working with files and strings, however I’m still yet to find an implementation that will take a plain old c-array and allow you to treat it as a stream.
In today’s post, I’ll present a small std::istream implementation that will consume these plain old c-arrays so that you can keep the rest of your APIs uniform to using stream objects.
A brief explanation
We’ll actually be developing two classes here. We’ll need a class to derive from std::istream which is what we’ll pass around to other parts of our program, but internally this std::istream derived object will manage a std::basic_streambuf<char> derivative.
Looking at the definition of a std::basic_streambuf we can see the following:
The class basic_streambuf controls input and output to a character sequence.
It would appear that most of the work here has been done for us. basic_streambuf will take care of the I/O from our character sequence, we just need to supply it (the character sequence, that is). I did say byte array in the title of this post, so the actual data type will be uint8_t* as opposed to char*.
Our implementation of basic_streambuf must abide by the char_traits type definition, so we get as close to our byte definition as possible with char. You can see that the constructor has a little bit of cast work going on to get setg to operate correctly.
Finally, we just create an istream derivative that uses this membuf object under the covers:
We set the internal buffer that memstream will use by making a call to rdbuf. The constructor performs some initialisation of the stream itself (to use a membuf) implementation.
In Use
You can now treat your plain old c-arrays just like an input stream now. Something simple:
That’s all there is to it. From the snippet above, you can pass s around just like any other input stream, because, well, it is just any other input stream.
JSON is a common interchange data format used across the web these days. It’s so popular because it’s easy to work with, marries directly with Javascript(really helping out the web guys) and its structure allows you to specify complex information in a simple, readable format.
In today’s post I’m going to walk through some basic usage of the Haskell library aeson which provides some tools for working with JSON.
Getting started
First of all, you’ll need the aeson library installed locally to work with it. You can install this with cabal:
This is pretty simple. Just a 2d co-ordinate. The example goes on to define instances of ToJSON and FromJSON to facilitate the serialization and deserialization of this data (respectively).
The only really curly bit about this, is the use of the (.=) and the (.:) operators. These will pair-up or extract data in context of your JSON object.
Simplify
With all of this said, now take a look at Generic.hs. This file makes use of the DeriveGeneric language extension to write the ToJSON and FromJSON implementations above. Those type class instances now read as follows:
instanceFromJSONCoordinstanceToJSONCoord
The type of Coord needs to be augmented slightly to include the Generic type class.
Lazy languages provide a way for developers to define expressions without necessarily forcing them to evaluate immediately. Rather than provide an immediate value, these languages will generate a thunk instead.
Show me
If you load up GHCi and bind an expression to a name:
λ>letfive=2+3::Int
We can check if this expression has been evaluated or not by using sprint. If the expression hasn’t been evaluated, sprint will show us an underscore _. This is how GHCi tells us that an expression is unevaluated.
λ>:sprintfivefive=_
five is currently a thunk.
If we do force the expression to evaluate and then re-run this test, sprint tells us a different story:
λ>five5λ>:sprintfivefive=5
five has now been evaluated and as such, sprint is telling us the value.
Weak Head Normal Form
With some knowledge of thunks under our belt, we can move onto Weak Head Normal Form or WHNF. If we take our five example back to unevaluated, and use a mixture of take and cycle to generate a list of five, we’ll end up with another thunk:
This post is really just a short-cut bookmark to the Arch documentation on the topic. This post will walk through the steps required to mount your Android phone using FUSE.
Install the package mtpfs if you don’t already have it on your system. After that’s installed, you’ll need to uncomment the line user_allow_other in your /etc/fuse.conf file.