teleren/devto huggingface dataset:
What do you think about the ternary operator?
Tags: discuss, practices, programming
Published: 2018-08-05 09:28:14

---
title: What do you think about the ternary operator?
published: true
description: The often misused feature of several languages
tags: discuss, practices, programming
---

![Shortcuts](https://thepracticaldev.s3.amazonaws.com/i/pdy2jegats9a8ssrqye3.png)

The ternary operator has a reputation of reducing readability. However, in the right hands, it may result in less duplication.

Do you think it's use has enough of a negative impact on readability? Are there enough legitimate use cases do justify the potential misuse? 

How often do you use it? Have you seen it used in contexts where it aids readability? 

Do you think modern programming languages should come with it? Users of languages without the ternary operator (golang etc), do you miss it?
Career changing 
Tags: discuss, career
Published: 2018-08-05 09:21:24

---
title: Career changing 
published: true
description: 
tags: #discuss #career
---
![Where am I](https://thepracticaldev.s3.amazonaws.com/i/yytak8lce0sfuh7xp6nx.jpg)

Hi Folks, I'm 33 years old and almost 2 years have passed since I started getting into this game. I Started this for curiosity but suddenly this became more serious, so serious than I'm changing my career right now. 
I had almost 10 years on chemical engineer field and worked in Germany before. Now that I came to my home country things are different and I felt the necessity to change my professional life.
Frontend world is getting crazy with so many things to learn. It's constantly changing and for folks like me, this is just madness. 
In January I joined in a new concept of Digital school in Porto ( The New Digital School) where we learn a lot of Ux/Ui than development but its still good for the growth as a frontend development in my perspective. 
Right now, we are starting approaching the industry in order to get out the first job in the tech world, and I'm super anxious, question everything, thinking if I'm capable but at the same time I feel that I need to get in and validate all I have learned. 
I would like to know how was your experience and how you dealt with this, especially folks that have passed through all this career change process.
Continuously Deploy Your Frontend using Gitlab and Scotty.JS 
Tags: javascript, webdev, devops
Published: 2018-08-05 07:43:30

---
title: Continuously Deploy Your Frontend using Gitlab and Scotty.JS 
published: true
description: Gitlab all the things.
tags: #javascript, #webdev, #devops
---

My lovefest for [Gitlab](https://gitlab.com/) continues! Heres a quick post showing you how to continuously deploy your React/Vue/Angular Single Page Applications to S3 and Cloudfront, using just Docker, Gitlab and great tool called [Scotty.JS](https://github.com/stojanovic/scottyjs).

First save `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` to your Gitlab environment variables (I recommend a special IAM role for this). Then save the files below to your repository and update the placeholder text to what makes sense for your project.

The Dockerfile below performs a multi-stage build that builds the frontend code (Create-React-App) then copies all of it to a directory that Scotty can access.

```Dockerfile
#Dockerfile
FROM node:8.11.3-slim as node_builder

MAINTAINER @iMichael

WORKDIR /app

COPY /src  /app/src

RUN cd /app/src && \
    npm install && \
    npm run build

FROM node:8.11.3-slim as deployer

RUN groupadd -r react && useradd -r -g react react

RUN npm install scottyjs --global

COPY --from=node_builder /app/src/build /tmp/build

USER react

ENTRYPOINT ["scotty"]
```

And below is the Gitlab config that ties it all together. Update this with any special logic your team adheres to (like only deploying if all tests pass on the master branch).

```yml
#.gitlab-ci.yml
image: docker:latest

services:
  - docker:dind

stages:
- build
- push
- deploy

variables:
  REACT_TAG_NAME: registry.gitlab.com/<user>/<project>/<container-name>:$CI_COMMIT_REF_NAME
  S3_BUCKET: xxxx

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com

build:react:
  artifacts:
    paths:
      - docker-images
  stage: build
  script:
    - mkdir docker-images
    - docker build --pull -t $REACT_TAG_NAME -f path/to/your/Dockerfile .
    - docker save $REACT_TAG_NAME > docker-images/react.tar

push:react:
  stage: push
  script:
    - docker load -i docker-images/react.tar
    - docker push $REACT_TAG_NAME
  only:
    - master

deploy:react:
  stage: deploy
  script:
    - docker run \
      --rm  \
      -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
      -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY  \
      $REACT_TAG_NAME  \
      --source /tmp/build/ \
      --region us-east-1 \
      --bucket $S3_BUCKET \
      --spa

```


Now every time you push to master on Gitlab (and all tests pass). your code will be deployed to AWS with a Cloudfront URL that you can CNAME to your own domain. 

Big thanks to Scotty.js which does all the heavy lifting!
Android-Kotlin Digest #4 : A simple way to Read and Write
Published: 2018-08-05 05:17:47

Here I will give you an overview of :

- how to read user input from command line?

- how to read data from a file?

- how to write to a file?


How to read user input from command line?
```
println(" ->Welcome to our Bakery<-")

println("============================")


println("Hello! How can I help you?")

var userResponse = readLine()


println("Sure!!" + "It's fresh prepared just now!")

var userNextResponse = readLine()


println("You are very welcome! Have a nice day!")



println("================== ====================")


println(" :: Your Conversation with the Clerk :: ")

println("Clerk: Hello! How can I help you?")

println("Customer: $userResponse")

println("Clerk: Sure!! It's fresh prepared just now!")

println("Customer: $userNextResponse")

println("Clerk: You are very welcome! Have a nice day!")
```


How to read data from a file?
```
val reader = FileReader("itsdamslife.txt")
var char: Int?
try {
    do {
        char = reader.read()
        print(char.toChar())
    } while (char != -1)
} catch (exception: Exception) {
    print("There was an exception : $exception.message")
}
```

How to write to a file?
```
try {

    var writer = FileWriter("itsdamslife.txt", true)
    writer.write(message + "\n")
    writer.close()
} catch (exception: Exception) {
    println("There was an exception :  $exception")
}
```
Where does npm install the packages?
Tags: javascript, node
Published: 2018-08-06 14:46:03

---
title: Where does npm install the packages?
published: true
tags: javascript, node, nodejs, node.js
canonical_url: https://flaviocopes.com/where-npm-install-packages/
---

> Read the [npm guide](https://flaviocopes.com/npm/) if you are starting out with npm, it’s going to go in a lot of the basic details of it.

When you install a package using `npm` (or [yarn](https://flaviocopes.com/yarn/)), you can perform 2 types of installation:

- a local install
- a global install

By default, when you type an `npm install` command, like:

```
npm install lodash

```

the package is installed in the current file tree, under the `node_modules` subfolder.

As this happens, `npm` also adds the `lodash` entry in the `dependencies` property of the [`package.json` file](https://flaviocopes.com/package-json/) present in the current folder.

A global installation is performed using the `-g` flag:

```
npm install -g lodash

```

When this happens, npm won’t install the package under the local folder, but instead it will use a global location.

Where, exactly?

The `npm root -g` command will tell you where that exact location is on your machine.

On macOS or Linux this location could be `/usr/local/lib/node_modules`.On Windows it could be `C:\Users\YOU\AppData\Roaming\npm\node_modules`

If you use `nvm` to manage Node.js versions, however, that location would differ.

I for example use `nvm` and my packages location was shown as `/Users/flavio/.nvm/versions/node/v8.9.0/lib/node_modules`.
Convert Image to String and String to Image in Java
Tags: java, base64, coder, webdev
Published: 2018-08-05 04:35:03

---
title: Convert Image to String and String to Image in Java
published: true
description: Convert Image to String and String to Image in Java
tags: #java #Base64 #coder #webdev
---

Post Link : https://www.skptricks.com/2018/08/convert-image-to-string-and-string-to-image-in-java.html

In this tutorial, we are going to explain how to convert/transform Image into Base64 String and convert/transform Base64 String back to Image without compromising a Image data.  I will be using Apache Commons Codec library to achieve the ‘Convert Image to String and String to Image in Java’.

Class: org.apache.commons.codec.binary.Base64
Methods: Base64 class has overloaded methods
Base64.encodeBase64URLSafeString – accepts byte array and converts into Base64 String.
Base64.decodeBase64 – accepts Base64 String and converts into byte array.

<a href="https://www.skptricks.com/2018/08/convert-image-to-string-and-string-to-image-in-java.html" >Convert Image to String and String to Image in Java </a>

<img src="https://3.bp.blogspot.com/-lrKEczp10oQ/W2Z75c6A1rI/AAAAAAAABvE/l4Z44GRLtDoJeKnxTBzapuxnhb_PJfYTACLcBGAs/s320/imgaeS.jpg" />

<a href="https://www.skptricks.com/2018/08/convert-image-to-string-and-string-to-image-in-java.html" > Read More... </a>
Android-Kotlin Digest #5 – Null Safety
Tags: android, appdev, blog, code
Published: 2018-08-07 05:46:45

---
title: Android-Kotlin Digest #5 – Null Safety
published: true
tags: android,appdev,blog,code
canonical_url: https://itscoderslife.wordpress.com/2018/08/05/android-kotlin-digest-5-null-safety/
---

One of the most irritating things in programming is apps crashing due to null / nil objects.

In Objective-C, you can  **call a method on nil objects**  it wont crash but it will never ever give expected result and we developers end up debugging a whole lot of our time searching out for the culprit.

In Java it used to be  **NullPointerException**  (NPE). And reason for app crashes.

Modern languages solves this problem by having the null safety mechanisms.

Swift uses Optionals  **?**  and Unwrapping  **!**  the optionals. Swift also has _if let_ and _guard let_ statements for safely unwrapping the optionals and handle in case of _nil_ values.

Here on the same lines we will discuss about how Kotlin ensures _Null safety_

```
var str: String = "abcd"
str = null // This line gives a compilation error
```

```
var str: String? = "abcd"
str = null // This pass thru since str is declared String?
```

Now suppose you want to check the length of str in case of optional, to do it safely you need to typically:

```
val len = if (str != null) str.length else -1
```

Or else use  **safe call**  operator (  **?.**  ) like : `str?.length`

_(In swift we call it Optional chaining)_

In Kotlin, the former if else statement can also written using what is called  **elvis**  operator (  **?: ** )

```
val len = str?.length ?: -1
```

And if developers are sure of an reference having a value then use not-null assertion operator (  **!!**  )

```
val len = str!!.length
```

(Problem with this is if the reference is null the  **NullPointerException**  is thrown)

happyCoding!
A framework for choosing from multiple job offers.
Tags: python, career, showdev
Published: 2018-08-03 08:20:52

---
title: A framework for choosing from multiple job offers.
published: true
description: Using Python3.7 to pick your next job. 
tags: #python, #career, #showdev
---

"Which job offer should I accept" is a question I see pretty frequently in various Slack groups and hear IRL. The answer of course is always personal and subjective so I thought it would be helpful to write software that helps organize our thoughts in a structured way and eliminate the [Decision Fatigue](https://en.wikipedia.org/wiki/Decision_fatigue) associated with multiple good options.

I've published a very alpha quality version in Python-3.7 @ https://github.com/iMerica/job-offer-selector. Feel free to fork it or use it as inspiration.

The core idea here is:
- Rank the categories that are most important to you.
- Rank the companies in these categories.
- Select the company that performs best using a weighted average.

P.S. Python 3.7's new data class module is pretty awesome. This project relies upon them pretty heavily.
Learning how to learn!
Tags: learning, coursera
Published: 2018-08-05 02:01:54

---
title: Learning how to learn!
published: true
description: An infographic made from Coursera's "Learning how to learn" course
tags: learning, coursera
---

An infographic from my blog from quite a while ago. Made from Coursera's "Learning how to learn" course by Terrence Sejnowski and Barbara Oakley. 




![Learning how to learn infographic](https://thepracticaldev.s3.amazonaws.com/i/m160n15170j5tpov4133.jpg)
Write With Me (Day 2)
Tags: discuss, writewithme, dev, productivity
Published: 2018-07-02 20:38:56

---
title: Write With Me (Day 2)
published: true
description: Day 2 of the writing daily challenge!
tags: discuss, writewithme, dev, productivity
---

This is part of my Write With Me series, where I hope to inspire myself and other to write daily for 7 days. This post is more of a short diary entry, so you've been warned. However, if you are looking for some quick inspiration to motivate yourself to write, read on!

Today is day 2 of my writing extravaganza. [On day 1 I gave an intro what my goal was](https://dev.to/matt24ray/write-with-me-day-1-a67) and hoped that others would join me in trying to write daily. 

Today is only day 2, and I've already found it hard to think of something to write about. As the day went on I kept thinking about what I could write about and nothing came to mind. Then it hit me. I've already been writing for 3+ hours today, so why not write about that! So, small interview with myself begins... Not really, but I am going to break down what I did today, and what I wrote about today, and what I found interesting. 

I help manage the weekly newsletter for DailyDrip.com. We love developer news at DailyDrip, and we find our favorite stories every week and then ship them off to our community with the highlights we took from them, and our takes from the story. 

Typically we send out our newsletter on Saturday mornings, but last week I was at the beach so we decided to send one out today instead. 
​
So, now I've met daily writing goal, so I will just call this part 1, and then I might follow up on the rest of this tomorrow. 
​
Broken Ip on a Digital Ocean Droplet.
Published: 2018-08-04 21:12:02

---
title: Broken Ip on a Digital Ocean Droplet.
published: true
description: Issue Hosting on Digital Ocean.
tags: 
---

Next Monday are 2 weeks old from when "my problem" with Digital Ocean start and it's unfinish.

First, i make a droplet my ip was visible on internet,i make something wrong so i remove droplet and i remake new one, same 3 rd time, 4th time when i make my ip will become unforward,invisible on internet.

My Ssh it's ok, working i can work with it's that perfect for me but my ip after many discussions, after they put me to make a photo with my face and my Id(personal identification card) still remain same, unfixed.

They put my to make some test using a tool for "ping" package to my ip,i make some screens, nothing.

I waste few days because they don't recognize email@mydomain.com so i move conversation to myemail@gmail.com...


The reason why i  chose first time, digital was to make everhing alone, but if ip don't work i can't make anything.And yes until they start disappointed me i love their offer, their tutorials ,anything I do not deny that

It's someone who have similar experience and fixed?

In this moment i'm very disappointed , i pay them for host  i don't used but if in few days can fix me, i will remain disappointed(for long time maybe for ever, probable i don't recommend everyone this company) and i move on to amazon service.

The reason why i make this topic it's because i'm disappointed and i feel necessary to describe my (frustration) so i ask help not to make a bad image, they build that image for me. And i still hope  in next few days can fix it.If not... 
And i admit, maybe i was just unlucky but someone maybe will thank me for this topic.
Checklist - Animation showoff
Tags: webdev, showdev, preact, opensource
Published: 2018-08-04 18:31:11

---
title: Checklist - Animation showoff
published: true
description: Do you like it?
tags: webdev,showdev,preact,opensource
---

Soon I'll release this web app on GitHub! But first, a quick question to everyone:

Do you like the animation? :)
Imagine you are using this web app to create a to-do list or checklist. Would the animation annoy you or you like it?

![Text](https://thepracticaldev.s3.amazonaws.com/i/uluuueb79p8drb8iti17.gif)
7 solutions to EJSONPARSE or Unexpected token `npm install` error
Tags: npm, json
Published: 2018-08-04 18:21:42

---
title: 7 solutions to EJSONPARSE or Unexpected token `npm install` error
published: true
description: HPome possible solutions or ways to diagnose the EJSONPARSE issue
tags: npm, JSON
---

You clone a repo, or maybe you are creating your project with a new `package.json` file. When you try to `npm install`, `npm install package_name — save-dev, or `npm i npm`, the JSON doesn’t parse.

`npm ERR! code EJSONPARSE`
`npm ERR! JSON.parse Failed to parse json`
`npm ERR! JSON.parse Unexpected token…`


This error could occur because of any number of reasons. You think something is probably wrong with your `package.json` file, but you’re not exactly sure what it is. Maybe you try `yarn install` because Yarn is a package manager similar to npm that’s known to be faster and have more enhancements. But that probably doesn’t help if the issue is with your JSON. Here are some possible solutions or ways to diagnose the issue:

1.) `npm cache clean -force`: Cleaning your cache will resolve potential conflicts with previously installed packages.

2.) Debug log: This might point you to the exact location where the error is occurring so you can fix it. You can find the location of the debug log in the console output. For example,

3.) JSON validator: Use a tool like JSONLint to check and make sure your package.json file is valid. A JSON validator or a linter should give you more insight as to why your file is not parsing.

4.) Check commas: In some cases, adding a comma between key value pairs may help. In my case, deleting a trailing comma resolved the error.

5.) Minify: A minifier could remove extra white space or improper formatting and resolve the issue.

6.) Number of packages: Make sure you just have one package in your package.json. It’s better to split your project into multiple directories if you want to use multiple packages. Every component requires its own package.jsonto avoid versioning issues or to make require-statement resolution works.

7.) `rm package-lock.json`: Removing the lock file and running `npm install` again could help resolve versioning issues.

Hopefully one of these solutions helped you. Please add your ideas or any other solutions you may have in the comments!

Thank you Angie Jones for teaching me the listicle blogging style, Jess Lee for reviewing this blog post and providing awesome feedback, Write Speak Code for inspiring me to write it, and Recurse Center for being a wonderful programming community!
How to setup a Postgres Server on Ubuntu
Tags: linux, postgres, ubuntu, server
Published: 2021-02-01 11:48:15

---
title: How to setup a Postgres Server on Ubuntu
published: true
date: 2018-08-02 22:28:19 UTC
tags: linux,postgres, ubuntu, server
canonical_url: https://boobo94.github.io/tutorials/postgres-ubuntu-setup/
---

## Installing on Linux

`$ sudo apt-get update`

`$ sudo apt-get install postgresql postgresql-contrib`

Switch over to the postgres account on your server by typing:

`$ sudo -i -u postgres`

You can now access a Postgres prompt immediately by typing:

`$ psql`, exit with `\q`

## Creating user

`$ sudo -u postgres createuser <username>`

## Creating Database

`$ sudo -u postgres createdb <dbname>`

## Giving the user a password

`$ sudo -u postgres psql`

`psql=# alter user <username> with encrypted password '<password>';`

## Granting privileges on database

`psql=# grant all privileges on database <dbname> to <username> ;`

## Access remotely

1. `$ sudo su - postgres`
2. `postgres:$ vi /etc/postgresql/9.5/main/postgresql.conf`Search after **listen\_addresses** and uncomment that line or add this `listen_addresses = '*'`
3. `postgres:$ vi /etc/postgresql/9.5/main/pg_hba.conf`Append at the end of the file these:

```
host all all 0.0.0.0/0 md5
host all all ::/0 md5

```

1. Restart postgres `$ sudo service postgresql restart`

PS: Make sure that you have postgres version 9.5 `$ psql --version` . If the file it’s empty try to use autocomplete `vi /etc/postgresql/` and then press tab for version autocomplete.

## Useful commands

Show all databases `\l+`

Show all roles `\du+`

Show all tables `\dt`

## Reset auto increment counter in postgres

Firstly you need to find your sequence identifier for the column that you want to reset the counter. Usually the name it’s the name of the table followed by column name followed by `_seq`.

Example:

table name: ‘users’ column name: ‘id’

sequence name will be: `users_id_seq`

First you need to find the current maximum value:

```
SELECT setval('users_id_seq', max(id)) FROM accounts;

```

then you can reset it with one of these commands:

```
SELECT setval('accounts_id_seq', DESIRED_VALUE);

```

or

```
ALTER SEQUENCE accounts_id_seq RESTART WITH DESIRED_VALUE;

```
Sysinfo parser for a window manager status bar
Tags: c, dwm, discuss, opensource
Published: 2018-08-04 17:07:36

---
title: Sysinfo parser for a window manager status bar
published: true
description: Feedback and advice on better coding
tags: c, dwm, discuss, opensource
---

Hi, all,

I am looking for others to review my code and give me any and all feedback. This project is open so that I can learn how to be a better developer and hopefully others can learn along with me.

The program is written mainly for the status bar in dwm (a window manager for Linux), but it can be used for any manager that takes input from the root window in X. It queries different resources in the computer and displays the formatted information in the status bar.

This is a full, tested, ready-and-waiting program. Here is the main repository for the code: [dwm-statusbar](https://github.com/snhilde/dwm-statusbar).

Thanks in advance to everyone who takes the time to read through the program and offer suggestions on how to improve my code. You are the reason why open-source development is amazing.

Hilde
Re-jok - A small react UI component library built with styled-components
Tags: react, showdev, opensource
Published: 2018-08-04 17:00:23

---
title: Re-jok - A small react UI component library built with styled-components
published: true
description: 
tags: react, showdev, opensource
---

Hi everyone!!! I just built a small library ui for react... I just started learning react a few months ago on the internet and had a three-month internship ... The idea came when I got to the spectrum .. I learned a lot of new stuff from the spectrum and I decided to practice by building re-jok ... so maybe my code looks very stupid or has lots of bugs but I hope everyone to like it..... I will try to improve it

This's my repo: 

{% github tranbathanhtung/re-jok %}

Thanks all!!!