Re.Mark

My Life As A Blog

Apache Cordova #4 : A few simple steps on

leave a comment »

Last time out, I started a simple Cordova project. Having got the default project, it’s time to start making some changes. I should probably note that for some not very exciting reasons to do with where I am today and the dev machine to hand, I have used Visual Studio 2013 with Update 4 for this post.

I thought I’d start with something simple. so I added an <h1> tag and put “Starting the Cordova project” inside it. Next thing is to see if it works. That means running the project. With this being a cross platform app, there are several options. The first thing to choose is the platform you want to run the project on:

image

If, like me, you found that you cannot see the box on the right hand side, you can add the Solution Platforms drop down selector from the Add Or Remove Buttons menu. There are all the familiar Windows Phone Emulators as well as a selection of Android emulators – the simplest being the Ripple emulators that use Chrome to emulate Android. And remember there is a Visual Studio Android emulator that you an install and use, too.

I started with the Ripple emulator, then used the Android emulator, then used a Windows Phone emulator and the app runs on all of them. Here it is on a Windows Phone emulator:

image

That’s a working – albeit not especially useful or impressive – app running on multiple platforms. Next time I will look at adding some functionality.

Written by remark

March 31, 2015 at 12:00 pm

Posted in Cordova, Mobile, Open Source

Apache Cordova #3 : Beginning the project

leave a comment »

It’s time to break out Visual Studio and start a Cordova Project. I was using Visual Studio 2015 Preview and updated to the CTP just before writing this post, although Visual Studio 2013 also has Cordova tooling. Under JavaScript, which is in the Other Languages section in my installation if Visual Studio 2015, there is an Apache Cordova Apps section:

image

That section has a template for creating a Cordova app:

image

You can do the same thing in TypeScript if you prefer. When the project is created, Visual Studio shows a helpful Getting Started page. If, like me, you need to find that page again, have a look in the project folder: the file is called Project_Readme.html.

The brand new project contains a number of folders:

image

I figure I don’t need to understand what they all do know, but it’s good to know they’ve been created in the right structure.

The thing I am interested in is index.html, which is the starting page of the app. Without any changes, it looks like this:

image

That looks like something I can understand. Next time out I’ll see if I can make some simple modifications to it.

Written by remark

February 17, 2015 at 7:39 pm

Posted in Cordova, Mobile, Open Source

Apache Cordova #2. Next steps

leave a comment »

A slightly bigger gap between the first and second posts than I had planned, so having to go back to basics a bit.

A good place to start is this article, which gives a good introduction to Cordova. I’m interested because if you’re building apps, you’re likely to be facing the challenge of writing code to run across a variety of platforms. If you have web development skills, Cordova provides a way to address that challenge.

A couple of other links that look useful are:

Visual Studio Tools for Apache Cordova and the remote Mac agent

msopentech.com – apache-cordova

And if you have started to look at Cordova, why not provide some feedback?

My next step is to start a simple app.

Technorati Tags: ,,

Written by remark

February 6, 2015 at 5:10 pm

Posted in Cordova, Mobile, Open Source

Getting Started with Apache Cordova

leave a comment »

It’s been a little while since I wrote on this blog. I’ve just started to get to know Apache Cordova, so I figure it’s in order to blow away the virtual dust and post occasional blog entries to document progress and keep notes.

But first a quick side note: once I get some more momentum I will need a better name for this series of posts. I have already rejected Cutting the Cordova and They Think It’s Cordova. Suggestions welcome.

Anyway, what’s this Cordova thing all about? Well, I speak to a lot of people about apps and for a good number of them, having a cross platform strategy is important. Some of them are looking to things like Xamarin, others to Apache Cordova. Those looking to Cordova are doing so because of the ability to write cross-platform apps in HTML, CSS and JavaScript.

One more thing that’s worth noting is the tooling that is available for Visual Studio 2013 for writing Apache Cordova apps. It’s also part of Visual Studio 2015 – preview available here. When you install the tooling, there’s a bunch of other stuff you can install, like the Android SDK and Java SDK, so you can build, debug and deploy cross platform (more info on that here.)

Once you have the tools installed and you’re ready to go, here are a few good resources to ready you for the first steps:

Getting Started with Visual Studio Tools for Apache Cordova

Cross-Platform Mobile Development with Visual Studio

Build Mobile Apps for iOS, Android and Windows with Visual Studio Tools for Apache Cordova

Written by remark

December 5, 2014 at 4:01 pm

Posted in Uncategorized

TF#I Friday #7 Part 2 : In which it still isn’t Friday

leave a comment »

Looking at how to call F# from C#, I thought I should share this link.  I have 2 projects in one solution (one in F# and one in C#.)  The C# project (a console application) references the F# project (a library) and that works.  Doesn’t do anything useful yet, but one step at a time…

Written by remark

June 29, 2011 at 3:09 pm

Posted in .NET, c#, Development, F#

TF#I Friday #7 : In which it isn’t really Friday but there is some F#

leave a comment »

After my simple start to an anagram solver in C#, I have a simple equivalent in F#:

let generateKey (chars : char[]) = new string(chars)
let lookup =  words |> Seq.groupBy(fun x -> generateKey(x.ToCharArray() |> Array.sort))
 

The lookup function expects a list of strings.  It works – although I’ve only tried it with fairly short lists of words.  Next exercise is to try calling this (or something like it) from C#.

Written by remark

June 29, 2011 at 11:45 am

Posted in .NET, Development, F#, Languages

TF#I Friday #6 : In which I write no F# at all

leave a comment »

I’ve been spending a little time recently writing a simple Windows Phone 7 app and I’ve been impressed with how easy it has been.  I’ve been thinking of writing an anagram solver as an exercise in F# – and it might make for another simple phone app – so I thought I’d start with a few simple steps.

The first step is to try (part of) a potential solution – given a list of words, group the words by the constituent letters (so that, for instance, horse and shore would be grouped together.)  That way, I won’t have to try every single combination of letters and compare against a list of words.  My intention this week was to write a simple program in C# to do this.  Here’s the method that does the work:


private Dictionary<string, List<string>> ProcessWordList(string[] words)
{
    Dictionary<string, List<string>> result = new Dictionary<string, List<string>>();

    foreach (string word in words)
    {
        IOrderedEnumerable<char> ordered = from char a in word.ToCharArray()
                                           orderby a
                                           select a;
        string orderedString = new string(ordered.ToArray());
        if (result.ContainsKey(orderedString))
        {
           result[orderedString].Add(word);
        }
        else
        {
            List<string> list = new List<string>();
            list.Add(word);
            result.Add(orderedString, list);
        }
    }

    return result;
}

Next exercise is either to extend the program towards solving anagrams or to write the method above in F#.

Written by remark

May 27, 2011 at 5:31 pm

Posted in .NET, c#, Development, F#, Languages

TF#I Friday #5 : In which I return to C# for a bit

leave a comment »

In my last post I counted some words using F#, which turned out to require a single, simple line of F#.  When I’d done the same thing before in C# i had iterated over the words and kept a count as I went, which is a typically imperative approach.  So, I wondered if you could apply the functional approach to C# – perhaps using LINQ.  Turns out you can.

Firstly, it’s helpful to have some words to count.  Here’s a simple approach:


string test = "The cat sat on the mat.";
string[] words = test.Split(' ');

(In F# I populated a list of words directly, so there’s an extra line of C# here – largely because I started with my previous C# code.)  Right, now to the counting in one line:


var result = from word in words
             let strippedWord = StripPunctuation(word).ToLower()
             where strippedWord.Length > 0
             group word by strippedWord into grouped
             select new { Word = grouped.Key, Count = grouped.Count() };

You  may have noticed a call to StripPunctuation – a utility function I had in my previous C# code.  Here it is (declared static as I was running it in a console application:


private static string StripPunctuation(string word)
{
    string result = word;
    if (result.Length > 0)
    {
        if (char.IsPunctuation(result[0]))
        {
            result = result.TrimStart(result[0]);
        }
        if (result.Length > 0)
        {
            if (char.IsPunctuation(result[result.Length - 1]))
            {
                result = result.TrimEnd(result[result.Length - 1]);
            }
        }
    }
    return result;
}

And now, with a little sprinkling of dynamic capability, outputting the results to the console:


foreach (dynamic entry in result)
{
    Console.WriteLine("{0}\t{1}", entry.Word, entry.Count);
}

So it is possible to apply the more functional approach courtesy of LINQ, although there’s still more code than I had in F#.  The C# is doing a couple of extra things (it strips out punctuation and is case insensitive) – but the point isn’t really the comparison between the two examples so much as the fact that by grasping some functional concepts can result in a change to your C# – which is a good reason to learn some F#.

Written by remark

March 25, 2011 at 5:43 pm

Posted in .NET, c#, Development, F#, Languages

TF#I Friday #4 : In which I count some words

leave a comment »

For a recent MSDN Flash article I wrote some simple code to calculate word frequency in C#.  As I get to grips with F#, I’m learning that the most rewarding but also the most difficult aspect is to think in a more functional way.  To count words in an imperative style (as I did in my C# example) I would iterate through a collection of words and keep a running count.  And, of course, you could write code in F# to do that.  But what would be the point?  How about approaching it in a different fashion?  So, with those questions in mind, I fired up Visual Studio and went about trying to bend my brain into a more F# like shape.  One of the things I like about F# is F# Interactive – a REPL which makes trying out and learning F# (as well as prototyping) easy – so that was where I started.  First thing I needed to do was to create a list of words (since at this stage I’m concerned simply with calculating frequency and not reading files or strings.)  It’s fairly simple to do that in F#:

let words = ["the"; "cat"; "sat"; "on"; "the"; "mat"];;

(the double semicolons are signal to F# Interactive the completion of a statement.)  After reading a bit about processing sequences in F#, I spotted that there is a function to count elements in a list – it can easily be used against the whole list like this:

let count = words |> Seq.countBy(fun x -> x);;

The countBy function takes a function to generate a key – in this case we can use each individual word.  To see if that has worked, we can print out the contents of the result:

printfn "%A" count;;

And in this case, I got the following result:

seq [("the", 2); ("cat", 1); ("sat", 1); ("on", 1); …]
val it : unit = ()

Which means it worked as intended.  There’s work to be done to make it the equivalent of the C# code, but the core counting is implemented in one line of code.

Written by remark

March 4, 2011 at 5:09 pm

Posted in .NET, c#, Development, F#, Languages

TF#I Friday #3 : Still getting started

leave a comment »

After mentioning in my last post that my initial exposure to F# was negative, I’ve just had a similar reaction looking around the web.  I think that’s because there’s two things to learn – the functional paradigm and a new syntax – and many of he posts out there assume that you’re familiar with at least one of the two.  Which is why of the two books I mentioned before, I prefer Functional Programming – it gives examples in both C# and F#, which means you can separate the paradigm from the syntax and still learn about both.

Written by remark

February 11, 2011 at 6:57 pm

Posted in .NET, Development, F#, Languages