Be a (unit-testing) minimalist

An article, posted about one month ago filed in , , , & .
Be a (unit-testing) minimalist

Still (2013) a great talk by Sandy Metz on testing, and how to do it right, without getting too theoretical. While this talk is on ruby, and it uses a Rails framework for testing, it really is applicable to any other language (only the syntax will probably be a wee bit shittier ;))

Watch Rails Conf 2013 The Magic Tricks of Testing by Sandi Metz on YouTube

(and while unit-testing is between brackets, in general, being a minimalist when writing code really is a good idea)

Continue reading...

Tag descriptor

Rails CMS-systems

An article, posted 5 months ago filed in , & .

When developing full stack webapplications, I typically use Rails. While Rails is the perfect system to create CMS'es, for sites that are less applications and more websites CMS-gems for Rails may help.

Continue reading...

JavaScript & Rails: a `webpacker` evaluation

An article, posted 10 months ago filed in , , , , , , , & .

Webpacker is still opt-in for new Rails projects. But this might change. The JavaScript ecosystem is moving fast and new JavaScript frameworks are pushing customer’s expectations to higher levels. To use these frameworks with your Rails app, you had a few options:

  • Include the JavaScript manually; which requires you to manually copy the files in place
  • Use a gem-wrapper to to install the JavaScript library; but this required quite some maintenance on the Gem-author’s side.
  • Try to mangle npm or yarn into the asset pipeline yourself
  • Use Rails Assets (an automagic Gem-wrapper)

A small praise for Rails Assets

I have been using rails-assets.org the past few years to keep my JavaScript dependencies up to date. It thought it was smart solution; instead of requiring individual developers to maintain Gem-wrappers, Gem wrappers are created on the fly by RailsAssets.org. It was smart and light weight on the developers side and worked perfectly with the Rails' Asset p…

Continue reading...

Niet hier uitgevonden

An article, posted more than one year ago filed in , , , , , , & .

Op m’n verzoek om vooral met vragen te komen in mijn kortgeleden begonnen mailinglijst hierbij een antwoord op een lezersvraag:

> “Ben ook wel benieuwd waarom je gekozen hebt voor het hosten van een eigen mailinglist vs de beschikbare saas oplossingen als mailchimp e.d.”

Het bouwen van je eigen mailing-systeem heeft trekken van het “Not invented here”-syndroom. En ja: ik had deze mailing heel erg gemakkelijk met iets als MailChimp kunnen sturen. MailChimp zou bij de omvang van deze mailinglist gratis zijn, leuke statistieken geven, een grafische editor geven en waarschijnlijk was m'n fout waarin iedereen bij de eerste verzending ‘Rick’ werd genoemd niet voorgekomen. "Niet hier uitgevonden" is dus een hele domme reden om iets niet te gebruiken, maar waarom dan toch eigen mailinglist-tool maken?

Foto door [Kelly Sikkema](https://unsplash.com/photos/r077pfFsdaU?utm_source=unsplash&utm_medium=referral&utm_content=creditC…

Continue reading...

Tag descriptor

murb ♥︎ ruby

An article, posted more than one year ago filed in & .

It may not be the fastest programming language, nor is it the most popular language when it comes to the numbers game, but how can you not fall in love with:

 10.times { print "Hello!" }

(instead of something like for(var i=0; i<10; i++){ console.log("Hello!"); })

Do things with sets like:

["a", "b", "c"] & ["b", "c", "d"] ## gives you ["b", "c"]
[1,2,3] + [4,5] ## gives you [1,2,3,4,5]
["a", "b", "c"] - ["b", "c", "d"] ## gives you ["a"]

Or (with a little (opinions differ on this one ;)) help of Rails):

10.days.ago

That offers you exactly what you would think it would return: the date of 10 days ago.

And no ;'s, only brackets when absolutely needed, everything is an object…

Yes, it's actually a language a human might understand, and still: it is pretty powerful, powering some of the most popular sites on the web, like AirBnB, Shopify, Basecamp (they're the creators of Ruby on Rails), Github, Kickstarter, Twitch, Strava and man…

Continue reading...

Unit-testing your front-end code in a Rails project: Yarn, Tape & Rails

An article, posted more than one year ago filed in , , , , , & .

I like Rails, but one thing that Rails falls short in is Javascript dependency management.

While Rails Assets, a proxy that allows for listing Bower packages in your Gemfile makes managing front-end libraries good enough for most front-end work, RailsAssets itself is mainly addressing asset management; it doesn’t allow for integrated management of additional development tools and binaries, useful for e.g. JavaScript-testing (besides the fact that Bower is kind of considered to be deprecated these days).

There are different ways of bundling Javascript, but since Rails 5.1, yarn is the defacto choice for Rails.

Installing Yarn

You can install yarn either trough npm npm install -g yarn, or if you’re on a mac, using homebrew: brew install yarn. I chose the latter.

To prepare your rails project run rails yarn:install.

Add tape for testing JavaScript & Coffeescript

There are [different testing fram…

Continue reading...

Phoenix’ Channels

An article, posted almost 2 years ago filed in , , , , , , , , , , & .

I started exploring Phoenix for one thing only: Channels (or actually fast real time communication over websockets). In this post I explore how to use them (yes this is a follow up of My first Phoenix-app-post).

Preparing for the authentication problem

Websockets don’t pass session cookies. Because we don't have access to these we need to transfer the user's identity in a different way. One of the recommendations I found was passing a user_token using a ``-tag (adjusting templates/layout/app.html.eex):

We can access this with a simple query selector in javascript:

document.querySelector("meta[name=user_token]").content

But that’s for later. Let’s move to the server side, since we need something to connect to, a Socket.

Socket

In our default project there is alrea…

Continue reading...

My first Phoenix app

An article, posted almost 2 years ago filed in , , , , , , , , & .

Some time ago I actually initiated my very first Phoenix app, but was a bit disappointed by the lack of a rich box of gems (like that of ruby's) and/or I didn't have the time to invest heavily in researching all the possibilities. One of my new year resolution was to actively pursue more knowledge, hence I'm giving it a second shot.

Why Phoenix?

I'm a full-stack Rails developer, but I needed real time messaging. That is not something Rails is typically good at (although it works), but Elixir (with its Erlang base) is well known for, even in the ruby community. Phoenix wraps Elixir in a nice Rails-like package ready for web and API development.

Requirements

  • Authentication
  • Broadcasting filtered messages based on tags
  • Writing messages

Preparation

  1. Install Elixir (macOS & homebrew: brew install elixir) and make sure you have [node.js](https://nodejs.or…

Continue reading...

ActionCable and authentication with Devise (2/2)

An article, posted about 2 years ago filed in , , , , , , & .

This is a short follow up on the previous article in which the ActionCable basics were explained. We can now add some level of authentication. Authentication is a bit harder than simply registering some before_action’s, but it is perfectly doable, especially if you've survived the previous tutorial.

From the official Action Cable guide we can simply reuse the full connection.rb template:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user
 
    def connect
      self.current_user = find_verified_user
    end
 
    protected
      def find_verified_user
        if current_user = User.find_by(id: cookies.signed[:user_id])
          current_...

Continue reading...

Getting started with Rails ActionCable (1/2)

An article, posted about 2 years ago filed in , , , , , , & .

As the lead developer at HeerlijkZoeken.nl I wanted to try the new Rails ActionCable technology for a new feature: shopping lists. The idea is that you can walk in a store or on a market, mark an ingredient as checked when you add it to your (physical) basket and continue shopping. ActionCable can make the experience nicer because it, based on WebSockets, allows for real time notifying other viewers and editors of the same shopping list. No more shouting around in the supermarket: I’ve got the milk! Sure, nothing essential, but I needed an excuse ;)

(Note that we recently migrated from Rails 4, so not everything was in place in our app, just ignore the bits Rails already made for you; everything has been tested with Rails 5.0.0.1)

Getting the basics right

To start: You need a web server that can open multiple threads, so if you’re still using Webrick in development (which can’t rece…

Continue reading...

SocialLinker

An article, posted more than 2 years ago filed in , , , , , , , , , , & .

I had a few projects that I thought could use some share 'buttons', but I didn't like to include the JavaScript loaded and privacy invading share buttons that the networks try to sell you by default. Neither did I like to concatenate the links with all variables required for each project… so I wrote a small rubygem on a back and forth train trip (#ilovetrains ;)): social_linker.

The idea is that you share something about a certain subject, hence you initalize the SocialLinker::Subject and then you'll be able to generate share links from it:

subject.share_link(:facebook)

How it works

Initialize the subject with enough material to generate links from, such as the page's url, maybe the media url (mainly for Pinterest type-shares), a description, tags etc.

For example, initialize the SocialLinker::Subject as follows:

social_linker_subject = SocialLinker::Subject...

Continue reading...

Tag descriptor

PortableRails

An article, posted more than 2 years ago filed in , , , & .

Making Ruby + Rails portable for the Windows platform (in other words, work without command line unfriendly installers). Updates below, code and readme on Github

Continue reading...

Tag descriptor

The `workbook`-gem

An article, posted more than 2 years ago filed in , , & .

workbook is simple ruby framework for containing spreadsheet like data in a datastructure that is known to most programmers: the (multidimensional) Array.

News

Continue reading...

Learning from failures: off-line support in a rails-app

An article, posted more than 2 years ago filed in , , , , , , , , , , & .

As a web-developer you typically assume that your users are always using your app on-line. When asked a year ago to start developing an app for the art-consulting firm QKunst I was, however, specifically asked for a tool that had to work in bunkers. Bunkers where having a solid internet connection was typically the exception. No problem, I read about HTML5 and offline app-cache: I thought I could fix that. More about that soon.

How I face a challenge

When faced a (technical) challenge I typically search for the easiest way out: what would be the slightest change I’d have to make to my battle tested set-up to accommodate for the new challenging feature. In my case this battle tested set-up starts of with the Ruby on Rails stack, which builds on techniques that align well with how I believe the web should work too. RESTful (proper HTTP-messaging and URLs), semantic, CURL-able. And all graceful…

Continue reading...

Mijn werk: Concordia weekoverzicht

An article, posted more than 2 years ago filed in , , , , , , , , , & .

murb bestaat inmiddels een aantal jaar, daarom lijkt het me leuk om de komende blogposts een aantal mooie resultaten te delen. Als eerste in de rij: Het Concordia Weekoverzicht.

Wat is het?

Concordia, een culturele instelling in Enschede, brengt iedere week een weekoverzicht op A5-formaat uit. De weekoverzicht tool die ik voor hen heb gebouwd maakt het mogelijk deze zonder veel moeite wekelijks uit te draaien.

Het probleem

Tot zomer 2015 was het maken van het weekoverzicht een repetitieve handmatige invuloefening met dure en ingewikkelde Adobe software, terwijl de meeste gegevens keurig waren opgeslagen in hun ticketsysteem en de kijkwijzer-database. Het voordeel van de Adobe-pakketten was weliswaar oneindige mogelijkheden qua opmaak, maar in de praktijk was het eindproduct telkens vrijwel hetzelfde. Ondertussen koste het handmatig opmaken dus relatief veel tijd en kunde.

De oplossing

Het volledig automatisch genereren van e…

Continue reading...

murb blog