[NJS] Layouts

:  ~ 2 min read

Express 2.0 apparently had layouts and partials included, but they were removed in 3.0. Luckily, ejs-mate has us covered.

Let's quickly cover partials, because it feels a bit easier. First, the partial, inside an example.ejs file, located in the same views folder where all your views are kept (preferably inside a nested partials folder):

<p>I […]

Continue reading →

[NJS] Routing

:  ~ 2 min read

Express offers a really easy routing system, which is the main selling point:

var app = require('express')()
app.use('/', require('./routes/routes'))

This will delegate all routing to the routes.js file, inside the routes folder, at the root level. Here, we delegate individual routes to their specific files, but declaring routes […]


Continue reading →

[NJS] Server, templates and the pipeline

:  ~ 2 min read

As I said in my previous post, I will do a suite of posts regarding the migration of my website from ruby to Node.js, and to make them easier to spot, I will prefix them with [NJS]. Small warning: I'm not a semicolon user. I've read quite a bit about it, and I made my choice knowingly.

So, the first thing I picked was Express, a really nice […]


Continue reading →

Node.js

:  ~ 25 sec read

Recently I started working on a Node.js project, but since I barely wrote like 50 lines of JS code, ever, I decided to migrate my current ruby based website to a Node.js one, to familiarize with it a bit. In my upcoming posts I will write about how everything goes.

I'm pretty pro null and type safety, so the main thing I'm wondering right now is how I'll feel after writing JS for a while, since it's at the other end of the spectrum compared to Swift: none vs 100% strictness.

Default UIBarButtonItems with protocols

:  ~ 2 min read

Having to create the same set of buttons over and over can become cumbersome. We'll try to make use of protocols and implement some default ones. Let's start with that:

protocol CanGoBack { // Sounds better than Backable :)
  func back()
}
extension CanGoBack where Self: UIViewController {
  func back() {
    if presentingViewController != nil &&  […]

Continue reading →

Easier interaction between UIImage and assets

:  ~ 45 sec read

We all hate explicitly typed strings, especially for creating UIImages, but we can surely improve on that. Let's start with an enum, that has a var, to transform its raw value into an UIImage:

enum Asset: String {
  case back = "leftArrow"
  case logo
  case email
  case briefcase

  // Theoretically, a bang wouldn't be that bad here, 
  // as we  […]

Continue reading →

CAShapeLayer fill rules

I was reading Shannon's post about shape layers, and one of the resources he links to is this page about fill rules. It was interesting to see the inner workings of them. Go and bookmark calayer.com, as well!

UICollectionView snap scrolling and pagination

:  ~ 2 min read

This is a pretty straightforward snapping logic for a collection view with cells of same size, and one section (logic for more sections can be easily added).

scrollViewWillEndDragging has an inout targetContentOffset parameter, so we can read, calculate and modify the end position of the scroll. Luckily, we don't need to take into consideration […]


Continue reading →

Writing is hard

:  ~ 45 sec read

I think that what I do here can't really be called writing; it's more like scribbling, my posts are rather small and rare. But I try to be consistent, even if what I'm going to write about seems to not be of a big deal, because I believe that any info, no matter how big or small, might turn out to be useful to someone.

On the other hand, despite all these facts, I have weeks when I have absolutely no idea what to write about; there's zero inspiration. I can't even imagine how hard it is to consistently write posts of 500, 1000 or more words. Hats off.

NSDate operators

:  ~ 45 sec read

I personally find this a bit of a mouthful, especially if you have to type it a lot:

if someDate.compare(otherDate) == .OrderedAscending {
  // Do stuff
}

But we can have a few operators to make our lives a bit easier:

func <(lhs: NSDate, rhs: NSDate) -> Bool {
    return lhs.compare(rhs) == .OrderedAscending
}

func <=(lhs: NSDate, rhs: NSDate)  […]

Continue reading →