teleren/devto huggingface dataset:
How to assign a custom layout to a page according to its URL alias in Drupal 8
Tags: drupal, web, cms, development
Published: 2018-10-28 14:38:48

---
title: How to assign a custom layout to a page according to its URL alias in Drupal 8
published: true
description: Getting a page to use a custom layout depending on how its URL alias is composed can be tricky, but luckily there's a function that can be helpful to define proper instructions for Drupal to handle this!
tags: drupal, web, cms, development
---

For the past couple of weeks I've been working as a contractor for an NYC-based NGO that's using Drupal 8 to power their site. My first task was to move their styleguide from a design done in Figma to actual components built with HTML and CSS inside Drupal, but there was a trick: the styleguide had to be set up as some sort of general type content and all I was able to customize was the URL alias.

I went on and duplicated the `page.html.twig` in our subtheme in order to customize that and work there, later renamed the file to `page--styleguide.html.twig`. After that I created all related content and used a URL alias that was `styleguide` happily knowing that (as stated by Drupal's documentation) it would pick up the custom layout automatically without the need of indicating anything.

_**Narrator:** the custom layout wasn't picked up by Drupal_

I wasn't able to find why the custom layout was not being used, so I decided to do some googling and found a useful function to suggest Drupal which layout to use. After some tweaking I ended up with the following snippet (placed inside my `.theme` file)

```php
// Set up hook
function themename_theme_suggestions_page_alter(array &$suggestions, array $variables) {

  // Check if the content being loaded is a node
  if ($node = \Drupal::routeMatch()->getParameter('node')) {
    
    // Get the node's ID
    $nid = $node->id();

    // Get the URL alias based on the ID of the node
    $alias = \Drupal::service('path.alias_manager')->getAliasByPath('/node/'.$nid);

    // Check if the URL alias matches the styleguide's
    if ($alias == '/styleguide') {
      
      // Suggest Drupal to use whatever custom layout we have defined inside /templates
      $suggestions[] = 'page__styleguide';
    }
  }
}
```

I'm by no means a Drupal expert, quite the contrary, so I'm not entirely sure if this solution is properly executed or performant for that matter. If you know a better way to solve this, feel free to leave a comment!
Some C games (2006 to 2007)
Tags: textbased, terminal, gamedev, c
Published: 2018-10-28 14:29:50

---
title: Some C games (2006 to 2007)
published: true
tags: text-based,terminal,gamedev,C
canonical_url: 
---

Here are some games in C language I made during the time I was studying the “Programació estructurada i modular / Programación estructurada y modular” (Structured and modular programming) subject that belonged to “CFGS DAI (Ciclo Formativo de Grado Superior en Desarrollo de Aplicaciones Informáticas)” which is a Software development associate degree equivalent (similar to Foundation degree in the UK, Diploma of Higher Education in Scotland or Higher Certificate in the Republic of Ireland) at IES Baix Camp school in Reus city (Spain).

![Screenshot](https://raw.githubusercontent.com/jalbam/c_games/master/screenshot.gif)

All are text-based games. It includes a Blackjack (aka Twenty-one) card game, a roulette game (with four different ways to play), a John Conway’s Game of Life (cells can be inserted either manually or randomly), a Mastermind game, Buscacaminas (pathfinding program with some Minesweeper characteristics), Pongetet (a pong game) and Pilotes (just a bouncing text generator). The IDE used was Bloodshed Dev-C++.

They can be found on GitHub: [https://github.com/jalbam/c\_games](https://github.com/jalbam/c_games)
Codetip - Javascript: Remove argument-order dependency and provide defaults
Tags: javascript
Published: 2018-10-28 13:57:17

---
title: Codetip - Javascript: Remove argument-order dependency and provide defaults
published: true
description: Remove argument-order dependency and provide defaults
tags: javascript
---

Argument order in function signature is a common source of bugs and frustration. Imagine you have the following Vehicle class, its constructor accepts values to instantiate an object. Passing the values in the wrong order can easily lead to bugs that are not so easy to catch.

```js
class Vehicle {
  constructor(speed, weight, power, color, brand){
    this.speed = speed;
    this.weight = weight;
    this.power = power;
    this.color = color;
    this.brand = brand;
  }
}
```

Obviously we can avoid the order dependency by passing an object to the function.

```js
class Vehicle {
  constructor(args = {}){
    Object.keys(args)
      .forEach(argument => this[argument] = args[argument]);
  }
}
```

There is a problem though, what if we want our constructor to have some default values in case these are not provided? In the first example, we would write our class like that:

```js
class Vehicle {
  constructor(speed = 100, weight = 1500, power = 111, color = "red", brand = "Kia"){
    this.speed = speed;
    this.weight = weight;
    this.power = power;
    this.color = color;
    this.brand = brand;
  }
}
```

To provide defaults in case we use an object as a single parameter, we can create a defaults property that returns our defaults, and merge the passed args object with our defaults in the constructor. The defaults property acts also as a form of documentation for the properties our class expects.

```js
class Vehicle {
  constructor(args = {}){
    args = { ...this.defaults, ...args };
    Object.keys(args)
      .forEach(argument => this[argument] = args[argument]);
  }
 
  get defaults(){
    return {
      speed: 100,
      power: 1000
    }
  }
}
```

Subclasses can provide their own `defaults`

```js
class Car extends Vehicle {
  get defaults(){
    return {
      speed: 150,
    }
  }
}
```

Or even extend the `defaults` provided by the base class

```js
class Car extends Vehicle {
  get defaults(){
    return {
      ...Vehicle.prototype.defaults,
      speed: 150,
    }
  }
}
```
Spooktober: Git Horror Story
Tags: beginners, git, android, terminal
Published: 2018-10-28 13:16:09

---
title: Spooktober: Git Horror Story
published: true
description: 
tags: beginner, Git, Android, terminal
---
![Header Image](https://thepracticaldev.s3.amazonaws.com/i/lvi3t2rn6jzcpqxx2txs.png)

Since it is the month of all things spooky, I thought it would be a good idea to post one of my scary experiences while developing, to get into the mood of Spooktober.
This scary experience comes in the form of git. So here's the story...

I was placed on an Android project, where I had to add a new feature and apply flavour specific resources. So the first thing to do was to clone the project. Alright, I've done that before so it shouldn't be an issue. Oh was I wrong. The project source resides on BitBucket and I make use of Git Bash terminal to clone and to run other commands. I go to BitBucket and choose the __develop__ branch (see image below), then proceeded to press the "Clone" button, pasted the link into my terminal.
![develop branch](https://thepracticaldev.s3.amazonaws.com/i/w5k4k4db6ospjicbkqte.PNG)
>The develop branch on BitBucket. 

At this point, all seems well. I then proceed to Android Studio to open up the project to make sure that it builds. The project runs a successful build. I go back to my terminal again to run *$git status* to see the status of the branch I'm currently in. I then noticed that I'm in *master*. I then run *$git checkout develop* .  It returns a message that states that the branch does not exist. 
*How can this be possible as it exists on BitBucket.* 

I repeat the whole process again, hoping for a different outcome. I still encounter the same issue. I ask a colleague if he has a successful clone. He says *no*. I then wonder if we were given the correct access rights on BitBucket...
But that wouldn't be the cause because I could view all of the branches. At this point I'm too shy to approach my manager for this silly situation.
Next step: Dig up solutions on Stackoverflow.

I Googled my issue, found some suggested solutions on Stackoverflow. The first few solutions didn't work at all. I digged deeper, and finally a solution that worked. The command is *$git clone -b <branch name> <repo url>* .

Some of the reasons why I did not approach my senior/team lead initially was because: 
1. I wanted to should show attempts in trying to solve my issue.
2. It felt embarrassing, as I am a junior dev. And I've been working with git commands for 3 years so far.

Lessons to take away:
1. Attempt to solve an issue before you approach a team mate.
2. Do not spend too long on trying to solve an issue.
3. Alert your team mates of the issue in time.
4. Share your solutions with the community.

*Which git commands do the trick for you?*

Useful links:
+ https://www.git-tower.com/blog/git-cheat-sheet
+ https://www.atlassian.com/dam/jcr:8132028b-024f-4b6b-953e-e68fcce0c5fa/atlassian-git-cheatsheet.pdf


Cover Photo by Ehud Neuhaus on Unsplash
Bootcamp, how does it work? 
Tags: discuss, beginners, career, bootcamp
Published: 2018-10-28 11:53:38

---
title: Bootcamp, how does it work? 
published: true
description: Recently, more and more people go for bootcamps to learn coding. But what is it?
tags: discuss, beginners, career, bootcamp
---

![bootcamp](https://thepracticaldev.s3.amazonaws.com/i/9kgldf18n95ob2hiaglj.png)


I myself don't have a CS degree, but did a [German Apprenticeship](https://en.wikipedia.org/wiki/Apprenticeship#Germany) which teaches software development skills over 3 years. 

Recently, I see more and more people going for something called a bootcamp. From what I understand, you go to some remote place for 3 months and only learn about coding for the entire time. And at the end you get to meet company representatives to get contacts to find a job afterwards. 

Sounds cool! I think, with the right attitude and the right employer this can work. You need to have an employer who allows you to make mistakes, you wouldn't do with some experience otherwise. But also to learn some other CS fundamentals around the job. I believe that it can work and that you don't really need to have the CS degree. I mean I don't have it. 😅

The three months things makes me a bit sceptical and the promise of a job as well.

- How good do bootcamp graduates feel prepared for a job?
- Do bootcamp graduates get a bit help from the employer to deepen their knowledge? 
- What are the expectations from the employer side to a bootcamps graduate?
- What is the biggest pitfall or misbelieve?

I'd be nice to hear some stories from both sides. Bootcamp graduates and employers. 

Ah, and before I forget:

Just in case, I'm also looking for someone who would like to talk a bit about this topic in a German speaking podcast. The podcast is called: [@codestammtisch](https://www.twitter.com/codestammtisch). Just give us a heads up on twitter. :)
chore: ramda-adjunct v2.11.0 release
Tags: fpjavascript
Published: 2018-10-28 11:23:14

---
title: chore: ramda-adjunct v2.11.0 release
published: true
description: Release notes from ramda-adjunct v2.11.0 in form of an article here 
tags: fp javascript
---

https://www.linkedin.com/pulse/chore-ramda-adjunct-v2110-release-vladim%C3%ADr-gorej/
Magento 2 Orders Export and Import
Tags: magento2, magento, magento2orderimport, magento2orderexport
Published: 2018-10-28 10:44:42

---
title: Magento 2 Orders Export and Import
published: true
description: 
tags: #magento2 #magento #magento2orderimport #magento2orderexport
---


The <a href="https://www.ulmod.com/orders-export-and-import-for-magento-2.html" target="_blank">Orders Export and Import for Magento 2 extension</a> is a great tool to easily export and import customers and guest orders including all orders, products and customers data. Transfer orders between Magento installations easily.

Get more details here :  https://www.ulmod.com/orders-export-and-import-for-magento-2.html
ReactJs Chrome Extension Boilerplate
Tags: javascript, webdev, react, opensource
Published: 2018-10-28 10:44:39

---
title: ReactJs Chrome Extension Boilerplate
published: true
description: chrome extension boilerplate with ReactJs using inject page strategy
canonical_url: https://github.com/satendra02/react-chrome-extension
tags: #javascript,#webdev,#react,#opensource
---
![ReactJs Chrome](https://thepracticaldev.s3.amazonaws.com/i/71if5vcvg1my4rbehyw7.png)
We have open-sourced the boilerplate of chrome extension with ReactJs using inject page strategy. Read [detailed blog](https://medium.com/@satendra02/create-chrome-extension-with-reactjs-using-inject-page-strategy-137650de1f39)

The boilerplate is to quickly create a chrome extension using ReactJs

The motivation behind creating a boilerplate was:
1. Instead of chrome's ready-made popup, We wanted our own page injected into DOM as a sidebar for better UX.
2. We wanted to use ReactJs for the Component-based approach, Routing, and its build mechanism.
3. Extension CSS should not conflict with the host page styles in any case.

I Hope, Someone will find it helpful

Source code:
{% github satendra02/react-chrome-extension %}
QS - CLI tool to quickly squash your commit
Tags: git
Published: 2018-10-28 10:08:44

---
title: QS - CLI tool to quickly squash your commit
published: true
description: QS is the git support command without the interactive editor. You can squash some commits very quickly with the one-liner.
tags: git
---

# Problem

When developing on GitHub, you may want to compile multiple commits into one commit.

At that time, you probably will do the following procedure:

1. git rebase -i \<commit hash\>
2. update from `pick` to `squash`
3. update the commit message
4. quit the editor

It is troublesome to take a lot of such interactive procedures.

# Solution
I and [@kamontia](https://dev.to/kamontia) released QS as CLI tool.

QS helps to do these with just one command.

<img src='https://thepracticaldev.s3.amazonaws.com/i/ym6ruacgroslyp2do8tx.jpeg' witth="320">

from: https://speakerdeck.com/chaspy/look-back-on-our-oss-activities

<img src="https://github.com/kamontia/qs/raw/assets/assets/logo_transparent.png" width="320">

- Repository: [kamontia/qs](https://github.com/kamontia/qs)
- Language: Golang

# How to install
Choose `go get` or `brew`, your preferred way. You can also download the prebuilt binary from the [release page](https://github.com/kamontia/qs/releases) and place it in the directory where PATH passes.

To learn more, please see the [README](https://github.com/kamontia/qs) in the repository.

# Summary
QS is very powerful and simple tool to squash your commit quickly

Please use it, and I'm glad if you give us improvement requests or impressions. 

Thank you!
Less awful module names
Tags: ruby, rails, discuss
Published: 2018-10-28 09:27:01

---
title: Less awful module names
published: true
description: Alternatives to naming modules *able
cover_image: https://i.kym-cdn.com/photos/images/original/001/067/362/f3c.gif
tags: ruby, rails, discuss
---
I'm a fan of naming things correctly.
I loathe Devise.
I just can't bring myself to read Enumerable source.

Why is that?!

#### TL;DR
Stop naming your modules in terms of what they do to the including class.
Instead, name them in terms of the __behavior__ they provide.

```rb
# bad
module Enumerable
module Awarable
module DatabaseAuthenticatable 
include Enumerable

# good
module Enumeration
module Awareness
module DatabaseAuthenticating 
include Enumeration
```

### The full discussion


For a long time I felt it's just how it is with me, you can't like every gem you use, right?  
Then, one day, I encountered a module named `Insurable` in our codebase and went: "That's just **** stupid! What the heck does it mean for a module to be insurable?! OK, maybe the module makes the __including__ object *insurable*? This sounds awful lot like Devise with its `Registerable` and `Database Authenticatable`, yuck!".  
So I feel an instinctive derision towards this sort of naming "convention" and per my own lesson, I went deeper. What is it about postfixing module names with "able" that makes my skin crawl? It may be that it defines the module in terms of what its inclusion does to the receiving class, where defining it in terms of itself would be preferable. Maybe the name gives away a code smell, a coupling, a reliance on functionality in the including object.

#### Is coupling a problem?

I'm fine with some coupling. Certainly, for `Enumerable` the coupling is understandable, it relies on `#each` having been defined, and that is OK. Modules should reflect this expectation with raising methods. Usually this looks like this:

```rb
module Enumerable
  def each
    raise("Expected to be overridden")
  end
end
```

Give Ilija Eftimov's brilliant [Testing Mixins in Isolation](https://semaphoreci.com/community/tutorials/testing-mixins-in-isolation-with-minitest-and-rspec) a read on how to spec this.

#### Could it be about the way it sounds?

It turns out that what gets me in about "*able" is that its awkward to talk about. Consider:

>— This is the Enumerable module.
>— Wut, the module is enumerable?
>— No, no, the module makes the including class enumerable, see? 
>— So the module allows Enumerating?
>— Yes.
>— It provides Enumeration?
>— Uh-huh..

Don't even get me started on participles like "awareness". Surely, it's not `module Awarable`, but `module Awareness (behavior/property)`.  

I would recommend you name modules according to the behavior they encapsulate, try to express it directly, not through the including class. Do not fear sophisticated words, look at synonyms for ideas.
Similar yet different. So confusing
Tags: discuss, programming, catdog
Published: 2018-10-28 08:56:22

---
title: Similar yet different. So confusing
published: true
description: There are concepts which are very similar, yet different and confuses many people
tags: [discussion, programming, 🐱CatDog 🐶 ]
cover_image: https://thepracticaldev.s3.amazonaws.com/i/o6kimdcbpizivs86fot9.jpg
---

There are concepts which are very similar, yet different and confuses many people.

## Referential transparency vs immutability

Referential transparency is a concept in a programming language which guarantees that once the value is assigned to the variable ~~it will not change~~ there is no way to assign a different value to it. For example, in ES6 you can use `const` for it:

```js
const a = { x: 1 };
a = { z: 1 }; // TypeError: Assignment to constant variable
a.x = 2; // This is ok
```

(Not sure why this is a **type** error, but you get the idea)

Immutability is a concept in a programming language (and in different areas)  which guarantees that the value once it was created will remain unchanged.  For example, in ES6 you can use `Object.freeze` for it:

```js
let b = Object.freeze({ x: 1 });
b.x = 2; // Silently ignores error e.g. does nothing
b = { z: 1 }; // This is ok
```

**Confusion**: I guess not a lot of people know or use every day the terminology "referential transparency". Programming language calls it constant (`const`). And constant is something that stays unchanged, you can even say immutable... 

## Authentication vs authorization

Authentication in the context of a user accessing an application tells an application who the current user is and whether or not they're present ([source](https://oauth.net/articles/authentication/)).

Authentication answers the question - who you are.

Authorization in the context of a user accessing an application tells an application if the current user (including unauthenticated users) is allowed to make given action or not.

Authorization answers the question - what you allowed to do.

**Confusion**: for starters - names are very similar which wasn't the best idea in the first place (naming is hard). The second part of the confusion is that you typically need authentication to do authorization.

What are your favorite sources of confusion?

> Photo by Lisa Algra on Unsplash
BxJS Weekly Episode 34 - javascript news podcast
Tags: javascript, node, podcast, news
Published: 2018-10-28 08:20:01

---
title: BxJS Weekly Episode 34 - javascript news podcast
published: true
description: Listen to the best javascript news of the week in a podcast form
tags: javascript, node, podcast, news
---

Hey dev.to community!

BxJS Weekly Episode 34 is now out! 🚀
Listen to the best javascript news of the week in a podcast form right here.
You can find all the mentioned links [here on github](https://github.com/BuildingXwithJS/bxjs-weekly/blob/master/links/18-43-Episode-34.md).

You can also watch or listen to this episode on:
- [YouTube](https://youtu.be/1wWO1Tpdd3s)
- [Castbox](https://castbox.fm/episode/BxJS-Weekly-Ep.-34-Oct-27%2C-2018-(javascript-news-podcast)-id1378315-id97688544?country=us)

Any feedback is appreciated 😁

Additional stuff:
- [Twitch channel](https://www.twitch.tv/yamalight)
- [Discord server](https://discord.gg/hnKCXqQ)
- [BxJS Weekly github repo](https://github.com/BuildingXwithJS/bxjs-weekly)

Social media links:
- [Twitter](http://twitter.com/yamalight)
- [Medium](https://medium.com/@yamalight)
- [Github](http://github.com/yamalight)

If you enjoy my content, please consider [supporting me](https://codezen.net/support.html) 😉
Release Delete-branch-bot as GithubApps
Tags: github, go, apigateway
Published: 2018-10-28 07:50:33

---
title: Release Delete-branch-bot as GithubApps
published: true
description: Delete-branch-bot deletes the branch when it is merged into master automatically.
tags: Github,golang,apigateway
---

# Feature
We released the GitHubApps named **Delete-branch-bot** developed together with @chaspy.
It deletes the branch automatically when it is merged into master.

You need not push the "Delete branch" button anymore!

Before: Necessary to push "Delete branch" button, it's NOT cool.
![](https://thepracticaldev.s3.amazonaws.com/i/n4y6te5pyd8egv9tswzs.png)

After: Delete-branch-bot watches the event of your repository. When the pull request is merged into master, it deletes the branch automatically. It's cool.
![](https://thepracticaldev.s3.amazonaws.com/i/jg9b6desi1apvhfodl6h.png)

# How to install
1. Access to [Delete-branch-bot](https://github.com/apps/delete-branch-bot) page or search *Delete-branch-bot*
1. Install it to your repository
1. Ready to delete the branch automatically. Good luck :)

# Technology
Architecture is very simple.
1. Amazon API Gateway
1. Amazon Lambda. Implemented using Go language.

![](https://thepracticaldev.s3.amazonaws.com/i/3iof0vnf1uv48ooc0d8e.png)


This is the first post for me.
I'm sorry my English is not good.

If you comment something, I will be happy. :)
Why don't I see all posts from people I follow in my notification feed?
Tags: meta
Published: 2018-10-28 06:22:20

---
title: Why don't I see all posts from people I follow in my notification feed?
published: true
description: 
tags: meta
---

When I check dev\.to I usually go straight to https://dev.to/notifications . However, I've noticed that some posts from people I follow don't show up there.

In particular I know @ben writes a lot of posts but I hardly ever see them. 

From @jess, I see the latest [The 7 Most Popular DEV Posts from the Past Week ](https://dev.to/devteam/the-7-most-popular-dev-posts-from-the-past-week-1kh8), but not [Help test the DEV beta app!](https://dev.to/devteam/help-test-the-dev-beta-app-4kme)

Is /notifications not where the new posts are supposed to show up?