teleren/devto huggingface dataset:
SOLID principles in the Go programming language
Tags: solid, go
Published: 2019-12-31 03:19:24

---
title: SOLID principles in the Go programming language
published: true
description: What do 
tags: SOLID, Go
---

There was a discussion on SOLID principles in the Go programming language and I threw in my two-cents. Once I was done writing, I was surprised with what I came up with.

Here is why you shouldn't think very much about SOLID in Go:

Consider each principle:

### Single Responsibility Principle:
"A class should only have a single responsibility..."

Go doesn't have classes. Already the principle doesn't apply...

I write that tongue in cheek, because of course a struct is a bit like a class, and of course SRP is great for a Go struct type, but also, since Go struct types do not have inheritance, we don't get ~classes~types inheriting behaviors. Thus we don't have to worry about un-intended inherited responsibilities. It is easier to achieve SRP in Go.

### Open-close Principle: 
"Software entities ... should be open for extension, but closed for modification."

  No inheritance, thus no extension. Go gets this for free.

### Liskov substitution principle: 
"Objects in a program should be replaceable with instances of their subtypes without altering the correctness of that program." See also design by contract.

Go doesn't have subtypes. YAY. So this only applies to interfaces implementations. Yes, it is an absolute must for interface implementations.

### Interface segregation principle: 
"Many client-specific interfaces are better than one general-purpose interface."

This is such idiomatic Go that it should go without saying.

### Dependency Inversion Principle: 
One should "depend upon abstractions, not concretions"

This is another way of saying accept interfaces. Yes, we value this highly in Go.


In summary:
We think about things slightly differently in Go, because Go isn't OOP, but once translated to Go's type system, SOLID absolutely matches with Go idioms.
Day 61 : Walk into the New Year like..
Tags: hiphop, code, coding, lifelongdev
Published: 2019-12-31 02:14:37

_liner notes_:
- Saturday : Had a really good time for the last radio show of the year. Played a bunch of great music and spoke with people from all over. You can check out the show recording at https://kNOwBETTERHIPHOP.com 

![Cover of December 28th OUR show episode with the date, a graphic of 2020 where the zeros are two the OUR show logos and text saying "End of Decade?".](https://thepracticaldev.s3.amazonaws.com/i/mprat90wo99slpg4op0b.jpg)

- Sunday : Slept over night in the van. Another good night. Before going to sleep, I worked on coding up my side project. Got up pretty early and headed back home because there was some things I wanted to get done for work and left my work laptop home. So for the rest of the day, I did some stuff for, watched some anime and worked on my side project. Got some stuff working, but not as consistent I would like.

- Professional : Got together a rough draft for a report I've been working on and submitted it to my manager. Got some good feedback and I'm on the right track. Spent the rest of the day working on a talk I'm going to give in a few weeks.

- Personal : So over the weekend I was able to get the RevealJS presentation into a Svelte/Sapper app. It wasn't as stable as I would like so I've been diving more into the Svelte documentation.

![View from a mountain over the clouds in Haleakala Crater in Hawaii](https://thepracticaldev.s3.amazonaws.com/i/41dyg2i1b93mcfclcl3p.png)  

So yeah, going to keep working on getting RevealJS and Svelte to play nice together for the rest of the night. Trying to walk into the new year like I got this working! haha I'm off tomorrow, so HAPPY NEW YEAR!!! See you in 2020!

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube wTd7xYyD8U4 %}
Use cfssl in a multi-stage build docker image
Tags: docker, cfssl, dockerfiles, ssl
Published: 2019-12-31 02:00:43

[`CFSSL`](https://github.com/cloudflare/cfssl) is Cloudflare's PKI and TLS toolkit. I recently wanted to use to generate a self signed certificate in a docker file.

You can technically install `cfssl` in a multitude of ways in whatever docker image you are using. There is a simpler approach though using [Docker's multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/).

---

Let us say you have a registry image, code below:
```docker
FROM registry

LABEL maintainer="mostafa@mlstudioapp.com"
```

And to use `cfssl`, you can do something like:

```docker
FROM cfssl/cfssl AS cfssl

WORKDIR /

# Generate certificate
COPY ca-csr.json /
RUN cfssl gencert -initca ca-csr.json | cfssljson -bare ca -
RUN rm /ca-key.pem

FROM registry

LABEL maintainer="mostafa@mlstudioapp.com"

# Copy it to the registry
COPY --from=cfssl /ca.csr /certs/selfsigned.crt
COPY --from=cfssl /ca.pem /certs/selfsigned.key
```

ca-csr.json
```json
{
  "CN": "ML Sutdio CA",
  "hosts": [
    "mlstudio-registry.default.svc.cluster.local"
  ],
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [{
    "C": "NZ",
    "O": "ML Studio"
  }]
}
```

---

If you found this helpful [spread the word](https://ctt.ac/N1QzG).
git log --simplify-by-decoration is my new best friend
Tags: git
Published: 2019-12-31 01:43:45

In short, it's this: `git log --decorate --graph --simplify-by-decoration --oneline   [--all]`

Let's break it down:

`git log` - Well, it shows you a historical log of commits.

`--decorate` - adds information about branches and tags to the log information. If a particular commit hash is tagged or is the latest in a branch, it will show you the name of the branch.

`--graph` - Git will show you some connecting information. For example, it will show you where commits end up and where the split from other branches. Really helpful if you're trying to figure out where one branch happens to split from another branch.

`--simplify-by-decoration` - Ah, this is the juicy one. Basically, adding this option **only** shows commits which have a decoration on them.

`--oneline` - Only show one line per commit. Essentially, show the SHA, the decorator, and the first line of the commit message.

`--all` - Adding this last option will show you not just the active branch, but all tags and branches that Git knows about.

```
* a471bb62 (HEAD -> sprint-7, tag: 2.0.0-9, origin/sprint-7) PROJ-1124 - Use the new widget.
* 39ad8aaf (PROJ-1125-no-boz-far) PROJ-1125 - Also handle no condition.
* 153feba4 (PROJ-1116-access-faz-boo) A couple of extra fixes.
| * 446ae0a4 (origin/PROJ-1125-no-boz-far) navigate to page
|/
| * a1716093 (origin/PROJ-1116-access-faz-boo) fixed access
|/
| * 1c0e6857 (origin/PROJ-1117-lorem-ipsum) fixed css
|/
| * 173131cf (refs/stash) WIP on PROJ-1117-baz-bar-foo: 266064d3 added icons
|/
| * bc7570bc (PROJ-880-bar-baz) PROJ-880 - Adding content.
|/
* bb5f437f (origin/staging, staging) PROJ-181 - Adjust spacing.
* 49f8dae4 (origin/master, origin/HEAD, master) 1.3.12
| * 8ec3b4f9 (tag: 2.0.0b3) Tagging 2.0.0-3.
| * d258e3c8 (tag: 2.0.0) 2.0.0
|/
| * 06f365ee (origin/PROJ-880-bar-baz) PROJ-880 - Adding content.
|/
* 24c6e2e0 (tag: 1.3.11) 1.3.11
<snip>
```
My IME setup for Windows 10
Tags: win10, ime
Published: 2019-12-31 01:10:28

---
title: My IME setup for Windows 10
published: true
description: How I fix my IME in Windows 10 using autohotkey and regedit.
tags: win10, ime
---

It has been a huge pain for me to type Chinese in Windows 10. And it was the main reason I dislike Windows 10.

The problem is that I am used to switch between English & Chinese input methods by typing `Ctrl` + `Space`. This went way back from Windows 95, or even Windows 3.1

But suddenly it changed in Windows 10. You'll have to use `Ctrl` + `Shift` to switch between input methods, and `Ctrl` + `Space` became disable/enable the method.

What I'd like to have is the following:

1. English as the default input methods, no matter which window I go.

2. Use `Ctrl` + `Space` to switch between English & Chinese input methods.

With the default Windows 10 setting, I could only get one of these:

1. Default English, use `Ctrl` + `Shift` to switch.

2. Default Chinese, use `Shift` or `Ctrl` + `Space` to switch to English

None of these satisfied me and I don't really want to adopt myself to get use to it.

I used lots of workarounds before, but today I believe I found the perfect solution: [autohotkey](https://autohotkey.com) + regedit.

For autohotkey, I have these two settings in a `ime.ahk` file.

```
^Space::#Space
CapsLock::Ctrl
```

And put this into startup folder so it could be loaded on boot.

But this script sometimes failed, and my IME will be disabled. I'll have to suspend the autohotkey script and restore it, turn the script back up.

So here comes the second fix: disable the original `Ctrl` + `Space`.

Follow the [instruction](https://superuser.com/questions/327479/ctrl-space-always-toggles-chinese-ime-windows-7) here, use `regedit` and disable this keybinding.

Finally I can type normally in Chinese on Windows 10.
Using Single and Multiline Comments
Tags: sql, tricks
Published: 2019-12-31 00:52:06

---
title: Using Single and Multiline Comments
published: true
description: How to mix them in useful ways.
tags: sql, tricks
---

This is just a quick trick I have used. Specially in long `SQL` scripts.

The idea is mixing single and multiline comments for easier handling.

## SQL Basics

- `--` Single line comment.
- `/*` Multiline comment opening.
- `*/` Multiline comment closing.

## Mixing

Take this simple SQL operation.

```sql
SELECT * FROM users;
```

Now let's use both single and multiline comments.

```sql
--/*
SELECT * FROM users;
--*/
```

The operation will be the same, but if we delete the single line comment `--` before the multiline opening `/*`, then the operation will be commented out. The `--*/` will be interpreted as the end of the multiline comment if multiline is enabled or just a regular comment otherwise, so we do not need to touch it. 

This have the following advantage, just need to delete or add the single line `--` once, and a whole block of code will be (un)commented out. 

### Multiline Enabled

```sql
/*
SELECT * FROM users;
--*/
```

## Other Programming Languages

This technique can be used in any programming language that supports single and multiline comments.

```php
<?php
// /*
echo "Hello";
// */

my_not_commented_out_function();
```


```php
<?php
/*
echo "Hello";
// */

my_not_commented_out_function();
```
Multiple database connections in objectionjs and knex
Tags: javascript, node, database
Published: 2019-12-31 00:47:34

Normally you have one database for your app, but when your app starts to grow it's normal to create more databases to handle more traffic in an efficient way.
So the question is:

### Is [objectionjs](https://vincit.github.io/objection.js/) ready for this?

Spoiler Alert: **YES**.

Let's assume we have 2 databases called: **db_one** and **db_two**

and what we want to achieve is to connect one of our objectionjs Models to the database **db_one** and the other one to the database **db_two**.

Let's start creating our models.

```js
// models/Product.js
const { Model } = require("objection");

class Product extends Model {
  static get tableName() {
    return "products";
  }
}

module.exports = Product;

// models/Category.js

const { Model } = require("objection");

class Category extends Model {
  static get tableName() {
    return "categories";
  }
}

module.exports = Category;
```

Nothing new here, but how can we tell objectionjs to give our models a specific database connection?

### Introducing bindKnex

Every objectionjs model has this method called **bindKnex** and it accepts one parameter: a valid **knexjs** database connection. And it will return the same model, but binded to a knexjs connection.

Let's see the code to have a better understanding of it.

```js
// index.js

const Knex = require("knex");

// connection for our db_one database
const cnDbOne = Knex({
  client: "mysql2",
  connection: {
    database: "localhost",
    user: "root",
    password: "root",
    database: "db_one"
  }
});

// connection for our db_two database
const cnDbTwo = Knex({
  client: "mysql2",
  connection: {
    database: "localhost",
    user: "root",
    password: "root",
    database: "db_two"
  }
});

// require our models

const ProductModel = require("./models/Product.js");

const CategoryModel = require("./models/Category.js");

const Product = ProductModel.bindKnex(cnDbOne);

const Category = CategoryModel.bindKnex(cnDbTwo);

// making queries

// db_one
// select * from products
Product.query().then(console.log);

// db_two
// select * from categories
Category.query().then(console.log);
```

Now we can execute our application

```bash
node index.js
```

and each model will make a query to a different database.

We can easily check this using the **SHOW PROCESSLIST** sql query in our mysql terminal.

```sql
SHOW PROCESSLIST;
```

![Terminal console showing multiple database connections](https://eperedo-blog.s3.amazonaws.com/multiple-database-connection-compressor.png)

and you can see our app has generated two connections for each database.

That's it! 🚀
Week 3
Tags: devjournal
Published: 2019-12-31 00:29:22

     Week 3

Week 3 brought us to our first introduction to React. React made sense to me early on, but it definitely took some organization when it came to classes extending each other and state.

We began our first day by learning about React components. Components are the building blocks for React. They are a JavaScript class or function that takes in an input and returns a React element. Within components you can create a class component and a function component. In React, classes and functions start with an Uppercase letter and are CamelCased.

Create React App is a file structure with codes written by others which are then given to developers to use. It makes it faster and easier for developers to write code when this command is run. We used this command to start us off on creating some React projects of our own.

Lets first look at a basic set up for a React code:

import React, { Component } from 'react',

class App extends Component{
  render (){
   return(
    <div>
     <Counter />
    </div>
   )
  } 
}

export default App

class Counter extends Component{
 constructor(){
  super()
   this.state = {
    counter : 0
   }
 }

 addOne = () => {
  this.setState({ counter : this.state.counter + 1 })
}

 render(){
  return(
   <div>
    Counter: {this.state.counter}
   </div>
  )
 }
}


Thats a lot going on up there so lets break it down. The first class , App, will be where our work in Counter will be displayed. Its only purpose is to display our finished product. In our Counter class we are setting a state for counter which is 0. We then created a method called addOne which will increase the state of counter by 1 each time the method is called and hence setState the state of counter to 1 rather than 0 and so on. In our render, we are writing some html code to display the text :Counter: " followed by the current state of counter.

Now that we know a little about state, we then were introduced to props. Props are a way of passing state into even more classes and functions. We do this by calling this.props rather than this.state in the classes that do not have the constructor and super stating this.state.

Some of our challenges from this week included creating a React dice roller, treasure hunt, and TicTactToe. I had a blast learning React and working through the challenges. It was very frustrating when our code wouldn't work due to a syntax error we didn't recognize for a bit. All in all it was another good week done. 

Checking out!
Beginner Python List Comprehensions
Tags: python, beginners
Published: 2019-12-31 00:26:02

---
description: Learn how Python comprehensions can help with applying logic to data structures without nesting for loops.
---
# Python comprehensions

The purpose of this article is to follow up on my previous article, *[Understanding map, filter, and zip in Python](https://dev.to/codespent/understanding-map-filter-and-zip-in-python-3ifn)*, and show you a more concise way of similar functionality.

## List Comprehensions
In the previous article, I covered `map` and `filter`, so now I can show you how we can emulate the same functionality with **list comprehensions**.

Have a look at the structure of a comprehension here. Its comprised of 3 main parts.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/rb5qyxr10cjdzrdno03q.png)


```python
numbers = [1,2,3,4,5]

def square(number):
    return number*number
```

#### Using a loop to square
```python
...
squared_numbers = []
for number in numbers:
    squared = square(number)
    squared_numbers.append(squared
```

#### Using map()
```python
...
squared_numbers = map(square, numbers)
```

#### Using a list comprehension
```python
squared_numbers = [x*x  for x in numbers]
```
Note: I use `x*x` here for readability, however, you can more appropriately use the ***power of*** operator `**` for this. `[x**2]`.

Lets now re-use our **even or odd** filter example from the last article to show how comprehensions can use a condition as well. We'll get the squared number of **ONLY** even numbers in our list.

#### Using filter() and map()
```python
...
def even(number):
    if (number % 2) == 0:
        return True
    return False

even_numbers = filter(even, numbers)
even_numbers_squared = map(square, even_numbers)
```

#### Using comprehensions
```python
...
even_numbers_squared = [x**2 for x in numbers if (x % 2) == 0]
```

## Conclusion
So with this you should have a basic grasp on how comprehensions work, how they're structured, and how they can help you write more concise code!
2019 Recap
Published: 2020-10-07 15:44:07

---
title: 2019 Recap
published: true
date: 2019-12-31 00:00:00 UTC
tags: 
canonical_url: https://sznm.dev/blog/2019-recap
---

I spent most of my time in 2019 at college, trying to finish all my university courses by the end of 7th semester so I can focus on Thesis / Final Project at the final semester (8th semester). Planning to graduate in 2020. So...not really much happened in this year, but I learned so much in terms of mobile application and web development. How to build an Android App and got my hands on React framework for the first-time in this year.

## What I learned in 2019

- Java and XML - How to build Native Android apps using Android Studio.
- REST API - How to fetch data and display it with recycler view in Android app 
- PHP - how to program a website with PHP, MVC.
- How to setup a website using database with PHP, laragon, and MySQL
- CodeIgniter - how to use CodeIgniter to build website.
- How to deploy PHP sites with its database to cPanel hosting.
- How to setup arcanist in Linux Ubuntu.
- How to use Git for managing personal and team projects.
- TypeScript - how to use it, what is the importance of strong typing, and how to compile it into JS
- React - how to build an app using React with CRA.
- GraphQL - what is it and how is it used
- Apollo - how to implement apollo as a client for GraphQL
- GatsbyJS - how to build a site with Gatsby
- Ionic - how to build hybrid apps and how does it different from native apps.
- Angular2+ - forced to learn this framework because learning Ionic Angular and luckily I've learned TypeScript.
- Zeit - found a Netlify alternative and how to deploy site with it.
Datetimepicker Disable Weekends in Bootstrap
Published: 2020-01-08 09:53:03

---
title: Datetimepicker Disable Weekends in Bootstrap
published: true
date: 2019-12-31 00:00:00 UTC
tags: 
canonical_url: 
---

Hi guysIn this tutoriali will give you simple example of Bootstrap datetimepicker disable weekendsyou can disable bootstrap datetimepicker using daysOfWeekDisabled methodwe are disabled bootstrap datetimepicker in weekendsit will useing daysOfWeekDisabled options to disable weekends in bo
What I learned last week - 30 December 2019
Tags: developer, selfcare, ios
Published: 2019-12-30 16:11:02

---
title: What I learned last week - 30 December 2019
published: true
description: Recharge
tags: developer, self-care, iOS 
---

I didn't.

Not a thing.

I worked last Monday to finish up what I had been working on the previous Friday.

I took the rest of the week off.

I celebrated the holidays with my family.

I took a short vacation to Oregon and spent as much of it outdoors as possible.

I didn't bring my laptop.

I used my phone for taking pictures and uploading to social media...and checking Liverpool football scores.

I even went 5 days without working out, trying to let my body rest. On the 6th day, I ran and then went hiking.

It was glorious.

I urge everyone to take breaks from your career. Burnout is all too common and this notion that we always have to keep up with all the latest going-ons in our profession is the fastest way I know to burnout. Take some time for yourself. Make sure you have hobbies or interests outside of software development. It will always be there. 

![Multnomah Falls, Oregon](https://i.imgur.com/hean9Cc.jpg)
*Multnomah Falls, Oregon*
Datetimepicker Disable Past Dates And Time in Bootstrap
Published: 2020-01-02 13:00:53

---
title: Datetimepicker Disable Past Dates And Time in Bootstrap
published: true
date: 2019-12-31 00:00:00 UTC
tags: 
canonical_url: 
---

Hi GuysIn this exampleI will learn you how to set bootstrap datetimepicker disable past dates and time you can simply set to datetimepicker in html codeyou will check to datetimepicker disable past dates and time bellow examplestrong classstepExample 1 strongpre classpre
Goodbye 2019, New Year resolutions for 2020
Tags: discuss, career, bestof, productivity
Published: 2019-12-30 23:43:15

Today is the last day of the year and I think it would be nice for all of us to share our resolutions for 2020.

For me, 2019 has been a very solid year, my first full year (from January to December) as a Software Developer. 

A quick recap of my year:

- I improved a lot with Angular (our main tool at work) and MySQL. 
- I've also played around a lot with GatsbyJS which I've used to build [my blog](ispirewebdev.com) and [my girlfriend's website where she teaches vietnamese](elingos.com). 
- I've also managed to create a second edition of my [book](https://github.com/AlbertoMontalesi/The-complete-guide-to-modern-JavaScript) that I'm so happy it just reached 650 stars on Github.
- Reached 10k Followers in roughly 5 months on DevTo. To be honest, I have no words to describe it, I would have never thought about reaching such a milestone when I first started out.

My New Year resolutions for 2020 include:

- Learn how to use AWS more, so far I've only touched the basics at work and I would like to dig deeper
- Write more tutorials on [my blog](ispirewebdev.com) where I write about JavaScript related stuff.
- Complete my personal project I was building with Angular, a personal app to track and create reports of [my book](https://leanpub.com/thecompleteguidetomodernjavascript2019/) and upcoming course sales (my course will soon go live on [Educative.io](https://www.educative.io/explore?aff=BqmB), a very cool platform for interactive courses). I know there are probably many free choices out there but the point of the project was also to get better at Angular since I only use it at the office but I rarely have a chance to build anything from the ground up.

How about you? How was your 2019? What do you expect from 2020?

---

Thank you very much for reading. Follow me on [DevTo](https://dev.to/albertomontalesi) or on my blog at [inspiredwebdev](https://inspiredwebdev.com/) or on [twitter](https://twitter.com/montalesi).

Disclaimer: Links to Amazon and Educative are affiliate links, purchases you make will generate extra commissions for me. Thank you

<div className="promotional_banner">
<a href="http://a-fwd.to/5gUojI8" target="_blank">
<img alt="book banner" src="https://raw.githubusercontent.com/AlbertoMontalesi/The-complete-guide-to-modern-JavaScript/master/assets/banner.jpg" />
</a>
<span>Get my ebook on <a href="http://a-fwd.to/5gUojI8" target="_blank">Amazon</a> and <a href="https://leanpub.com/thecompleteguidetomodernjavascript2019" target="_blank">Leanpub</a></span>
</div>