Sam Croft

Full-stack developer

Loading JSON data into an Ionic app using Angular JS’ $http service

  • 14 comments

Filed in: angular, api, cordova, ionic, javascript

Ionic Framework and Angular JS logo

Several years ago I wrote an article about loading data into a PhoneGap app. The article detailed using jQuery’s $ajax method to load JSON data into a simple PhoneGap app. People are still commenting on this article today, so I figured I’d write an up to date version on the same subject, but based around Ionic.

I’ve been working with Ionic a lot of last couple of months. I love it. Using it has gotten me all excited again about hybrid app development. So I thought I’d get back into writing and talk about how I use Angular JS’ $http service to load data into an Ionic app.

(more…)

Quick tip: return from functions as soon as possible

  • 0 comments

Filed in: best practices, coding, programming

Programming: always return as soon as possible

I wish I could recall where I first read about this programming approach, it’s something that has made my code much more readable over the last few years and I’d love to credit the author.

Avoid heavily indented/pointy code, return as soon as possible

The idea is simple; whenever you’re using conditional statements, always return (or throw an exception) as soon as possible to avoid complex nested if/else blocks.

(more…)

A git and GitHub strategy for forking your own repository to create customer versions of a core application

  • 0 comments

Filed in: git, github, librarygame, productivity

git forking a core application to create custom versions for customers

When I first started writing the specification for and developing Librarygame in late 2011 I had only been using git and GitHub for about a year. Although I was pretty new to source control I had read Vincent Driessen’s fantastic write up on A successful Git branching model. It’s a superb read and something I still refer back to, and recommend to new git users, today. I became very comfortable using branches for features, hotfixes and releases but I was a bit confused how this could work with multiple forked repositories of the same application.

Skip the story: show me the solution

To give a little bit of background; Librarygame, a web application devised and owned by my company Running in the Halls, is a gamification platform for libraries. It takes a user’s activity in the library (after they have signed up and agreed) and awards them points and achievements depending on how often/when they have visited, the number of books/type of books they borrow and if they return books on time. It does a fair bit more than that, but that’s the basics.

(more…)

Tutorial: Using PHP’s JSON encode and decode functions to handle data sent to and from your app

  • 6 comments

Filed in: api, apps, JSON, PhoneGap, php

JSON makes dealing with data in your app exceptionally easy and manageable. The best part about JSON is you can look at it and understand it. It’s not like the confusing spaghetti DOM that you get with XML, it’s a lean minimal representation of your data. If you’re dealing with chunks of data in your app, you want to be using JSON.

So while your app will happily eat up all the JSON you can throw at it, you still need to make it in the first place – and/or have a server side app that is capable of reading it. If, like me, you use PHP to handle things on a server then things are pretty straightforward. You can use PHP’s json_encode and json_decode functions. Encode will take your arrays, or objects, and create a JSON string of your data. While decode will take a JSON string, sent from your app, and turn it into an array or object.

(more…)

Quick tip: using HTML5 localstorage to store JSON objects on a device in your PhoneGap app

  • 34 comments

Filed in: android, cordova, iOS, javascript, JSON, PhoneGap

I’ve written a couple of articles about loading remote data into PhoneGap apps (sans framework), but I haven’t mentioned a good little method of storing that data on the device so you don’t need to request it from a server again. This is a quick tip for how you can do that.

Of course, it depends on the type of data that you are loading from your server in the first place. You wouldn’t necessarily want to store data that would be out of date quickly – such as share prices or live sports scores. But there will certainly be times when you want to save the data you’ve just loaded for use at a later time, without having to load it again.

(more…)