[NJS] Dropbox syncing

:  ~ 7 min read

For Dropbox handling I chose a pretty small library, node-dropbox. To use it, I went in Dropbox's developer dashboard and created an access token (instead of using secrets and keys) and saved that in my .env. Then onto the helper:

const dropbox = require('node-dropbox').api(process.env.ACCESS_TOKEN)

function Dropbox() {}

Dropbox.getFolder  […]

Continue reading →

[NJS] Database handling #3

:  ~ 2 min read

Last time we created a basic database handling functionality, but it was clear we can improve it: posts aren't the only ones that need fetching, and requiring the dbconfig file everywhere (and configuring the object) will become cumbersome. So, a first step would be to create specialized DbConfig objects:

DbConfig.page = function(page) {
  const  config  […]

Continue reading →

[NJS] Database handling #2

:  ~ 5 min read

Last time I was talking about the DbConfig model and the fetchPosts function, so let's dive in. First, a few examples of using the config:

const Db = require('../lib/db')
const DbConfig = require('../models/dbconfig')

// Fetching one post
const config = new DbConfig()
config.fields      = ['link']
config.fieldValues = [req.baseUrl.substring(1)]  […]

Continue reading →

[NJS] Database handling #1

:  ~ 4 min read

With Sinatra, I was using DataMapper as ORM (Object Relational Mapper) for Postgres, and I got a bit spoiled, because it makes things really easy. You first have to define your data mapping:

class Post
  include DataMapper::Resource
  # Set the number of characters for these types of fields, if the DB supports it
  DataMapper::Property::String.length(255)
   […]

Continue reading →

[NJS] Project structure and layout tips

:  ~ 3 min read

In the previous posts I mentioned file locations, but I haven't been explicit on what my structure is, so let's go through it:

- assets
    |___ javascripts (3rd party js)
    |___ stylesheets
    |___ images
    |___ files (random files I want to serve, like my resume)
- lib (let's call them helpers)
    |___ tasks (anything I want to run on Heroku)
    |_ db.js  […]

Continue reading →

[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 →