Skip to main content

Posts

Optional types in Swift

At work, I code in either Java, Javascript (AngularJS, Node.js) or CSS via bootstrap, so when I am coding in Swift, it is strictly something I do in my free time. Hence I make a point to keep notes of stuff that I learn which can potentially serve as a future reference for me. Swift (Apple's new programming language), allows for the presence  optional type or optionals . This concept is very well explained in this Ray Wanderlich podcast , at time 27:03 (mins:secs). As mentioned in that podcast,  the designers of Swift decided to ensure that you have no null ( nil ) references in your code. So in languages such as Java, say you have an object called person which represents a person , that has information about where the person lives i.e. address property. There is some more detail in where the person lives i.e. the name of the street i.a. street property. So now if we want to what street the person lives on, you would do person.address.street . That way you tr...

Serving HTML content in an iOS app that works in iOS 7 and later (using Swift)

As I have mentioned in an earlier post , I really enjoying coding in Swift. Now what am I doing with it? Well I am trying to build an HTML5 app that must work on devices with iOS 7. So in iOS8 apple has introduced a whole bunch of features that facilitate easy communication between web content and lets just call it back-end Swift code, but those features are not in iOS 7. So why do I want to build something that would work in an older OS? well I do not expect existing iOS users to upgrade to iOS 8 straight away and i also know a couple of people who would be very reluctant to upgrade their iPhones to iOS 8. Now in case you do not, you can have a read of the "Working with WebViews" section of this post , to know how to serve HTML content with WebViews. So when I started building my app, I wanted to know: How do I invoke some Swift code from my HTML content? Well the solution to this may feel a little bit "hacky" but it is a solution to achieve this.  The followi...

Getting started with iOS programming using Swift (Part 1)

I have not been too fond of Objective-C, which was the primary reason for me to stay away from making iOS apps till now. So what changed? Well Apple has done something very interesting recently and that is the introduction of a new programming language i.e. Swift. Swift is awesome, it almost feels like Python, C++ and Objective-C had a baby with some of their good parts in them. So I have been getting to know Swift and it is an awesome language to program in. What I am going to share with this and a series of blog posts are solutions to some problems that i have encounter while i am trying to finish my first iOS app. The one hurdle that I have encountered while getting started on developing an iOS app is that a majority of the solutions for iOS specific problems provide solutions to them using Objective-C. Which is fair, because Swift has not been around for that long. Anyway let us get started with a few basics, A few basics I would highly recommend having a read of this book...

Sending browser independant notifications from a web-app

So I came across a data-mining product that presents very useful information via a web-app. What gets delivered to the users of the product is new information  in the form of reports at regular intervals. So the process is, new data is acquired  all the reports are run again on newer data a manager overseeing the product sends an email to the users that notify them that the reports have been updated. Motivation So this process is great and it requires very little effort on part of the manager emailing the users. So the question is "why make that manager use even little effort, when the manager's time could be better utilized?". While the manager can add some more personalized info in the email, the entire process can potentially have the following disadvantages human error: the manager may get busy and may forget to notify the users of the updated reports distractions: if the user has to navigate away from the web app and check their email, this could potent...

Open source HTML5 visualisation library to draw charts on the web (morris.js)

At work(ongoing,full-time contract) we use the Google Visualizaton  library for our various data visualisation needs. So naturally when I was building this tool to streamline the process of Post Traumatic Amnesia(PTA) assessment, my first thought was to use Google Visualization library for the tool's data visualisation needs. However that was only till I realised that the tool needs to work offline. Google Visualisation is a very good library but it only works when the the web app is online, so after some looking around I found a tool that works offline too i.e. morris.js . It uses the fantastic Raphael.js  library to render beautiful SVG based charts, on the web. Problem The objective is to visualise data in a web application, so it can be easily interpreted without having to go through raw numbers. The web application needs to be demoed on....say a laptop and the places where it could potentially be demoed may not have internet connectivity. It could also be in a plac...

Reading a Sqlite database using client-side javascript

Ever had one of those problems at work that seems almost impossible (i.e. very hard) to solve at first? well i did and not so long ago, and tuns out that there is a solution to it. Problem Read the contents of a  Sqlite  database client-side and present them in an HTML based GUI. So my first reaction was, even if there is a solution to this, it surely cant be very efficient reading an entire Sqlite database client-side? well those were the requirements and there were some genuine reasons to back up those requirements, so i had to stop whinging and direct my efforts towards an actual solution. Solution Turns out that there is a solution for this! Ever heard of  emscripten ? Funnily enough i had used it while doing my research to port the  OpenCV  library to javascript. Anyway there is  sql.js , which is a javascript port of the Sqlite database, which could do what i wanted it to do. The problem is the documentation of ...

Getting to know a completely new programming project

So since Feb this year, i have been assigned on a new project at work. This new project involves working with a variety of independent sub-projects for this client and the sheer variety of the sub-projects can sometimes be overwhelming. What has happened a few times is that, the client starts a new sub-project, hands it to us and says we need this application to do "X". Can you make it do that? So the task is assigned to me and I have a project with no documentation, no instructions but I need to get on with it and solve the issue as soon as i can. So how do i approach this? Since i work on a mac,  which basically has the very awesome terminal that amongst others, has this useful tool called grep.  How do i use it for my needs?  well say i have an  AngularJS  project, stored in a folder projFolder,  and i have no prior knowledge of how it is structured and i have to figure out why a controller does not navigate to route blog after a certain function ca...