teleren/devto huggingface dataset:
TIL Using Postgres in GitHub Actions
Tags: githubactions, postgres
Published: 2020-07-24 14:10:33

I recently made my first experiences with GitHub Actions.

Setting up Postgres took me several attempts because of a misunderstanding with variables in the service's `env` block.

I thought that I could just define `POSTGRES_PASSWORD` in the global `env` block and this would then be available and used in Postgres' service. However, not having set `POSTGRES_PASSWORD` in `services.postgres.env` gave me this nice, quite unhelpful error message:

```shell
##[error]Failed to initialize, postgres service is unhealthy.
```

After a while I learned that the environment variable `POSTGRES_PASSWORD` in `services.postgres.env` is **mandatory** and **must not be blank**.

Also, the variables defined in `services.postgres.env` are **passed into the docker image**, thus they are _somewhat different_ compared to regular `env` blocks in Github Action Workflow syntax... I guess?

However, my final result looks like this.

```yml
env:
  # ...
  POSTGRES_PASSWORD: mysecretpassword

jobs:
  a-job-that-uses-postgres:
    # ...
    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }}
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432
    # ...
```

Which is being translated into this command, which makes  it clear what happens with the variables.

```shell
docker create\
  # many others\
  -p 5432:5432\
  --health-cmd pg_isready\
  --health-interval 10s\
  --health-timeout 5s\
  --health-retries 5\
  -e "POSTGRES_PASSWORD=mysecretpassword"\    # <= 💡
  -e GITHUB_ACTIONS=true\
  -e CI=true\
  postgres:latest
```

My learning may be trivial, but I hope that this helps someone having the same issue.

(Photo by [Andrew Rice](https://unsplash.com/@andrewricegolf?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText))
LeetCode 1470. Shuffle the Array
Tags: leetcode, python, algorithms
Published: 2020-07-24 13:46:39

## Solution
[link](https://leetcode.com/problems/shuffle-the-array/)
The logic of this problem is quite simple: 
1. treat the given array which is divided at the position **n** as two parts.
2. use **n** as the iterator(reduce the cost of For Loop to O(len(array)/2)), then add each element into the result array
 
I made two submissions to solve this problem, all the lines are the same except one line inside the For Loop , which made a huge difference in the time complexity. 

## Submissions
* faster than 39.93%:
```
class Solution:
    def shuffle(self, nums: List[int], n: int) -> List[int]:
        result=[]
        for i in range(n):
            result+=[nums[i],nums[i+n]]
        return result
```

* faster than 95.78%:
```
class Solution:
    def shuffle(self, nums: List[int], n: int) -> List[int]:
        result=[]
        for i in range(n):
            result+=[nums[i]]+[nums[i+n]]
        return result
            
```
## Analysis
`result+=[nums[i],nums[i+n]]` has the same effect as: 

```
result.extend([nums[i],nums[i+n]])
# O(k),k is the number of elements inside the extending list 
```
`result+=[nums[i]]+[nums[i+n]]`has the same effect as: 

```
result.append(nums[i]) # O(1)
result.append(nums[i+1]) # O(1)
```

**I wrote a complement post to this topic:**
https://dev.to/effylh/internal-implements-of-list-extend-and-list-append-operations-in-python-4p8j

## Summary
We're familiar with those methods, but we still need to pay attention about the time complexity and make the most appropriate choice.
**Method	Time Complexity:**
`append()	O(1)`
`insert()	O(n)`
`extend()	O(k)`
Deep Dive into CQRS - Event Sourcing Architecture Patterns
Tags: cqrs, eventsourcing, ddd, techtter
Published: 2020-07-24 14:03:58

CQRS - Event Sourcing Architecture Patterns play an important role while building Event Driven Systems. Checkout the video on deep dive on these 2 patterns complement each other to build efficient Event Driven Systems..

Part-1: https://youtu.be/3TwLEoLtpw0

{% youtube 3TwLEoLtpw0 %}

Part-2: https://youtu.be/MKdHSKeMpk0

{% youtube MKdHSKeMpk0 %}
5 Great Go Resources
Tags: go, tutorial, beginners
Published: 2020-07-24 13:57:32

---
title: 5 Great Go Resources
published: true
description: 
tags: #go,#tutorial,#beginner
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/a1sem808xxdxtqwvrsky.jpg
---

Here are 5 great resources for all you Gophers out there:

# Awesome Go

{% github github.com/avelino/awesome-go %}

# Go Training Courses and Material by Ardanlabs

{% github ardanlabs/gotraining/ %}

# Idiomatic Go Resources

{% medium https://medium.com/@dgryski/idiomatic-go-resources-966535376dba %}

# Security Related Resources for Go

{% github github.com/guardrailsio/awesome-golang-security %}

# Style Guides for Go

{% github dgryski/awesome-go-style %}
คุณคิดอะไรอยู่???
Published: 2020-07-24 13:35:32

ความคิด เป็นกระบวนการหนึ่งของสมอง ที่ขับเคลื่อนให้ชีวิตก้าวไปข้างหน้าได้ ไม่ว่าจะคิดเรื่องเล็กหรือใหญ่ เรื่องประจำวัน เรื่องงาน ครอบครัว ต่างๆมากมาย ในแต่ละวันเรามีความคิดหลายร้อยหลายพันเรื่อง บางครั้งคิดมากเสียจนเสียสติ ไม่รู้ว่าต้องโฟกัสกับอะไรบ้าง หรือ บางครั้งก็รวน เรื่องสำคัญไม่คิด มีแต่คิดเรื่องไร้สาระ มาทำความเข้าใจง่ายๆกับความคิดกันค่ะ

ความคิด แบ่งเป็น
1. ความคิดด้านบวก 
2. ความคิดดด้านลบ

เกณฑ์ที่ใช้ในการแบ่งความคิดเป็น 2 ด้าน ด้านบวกและลบ คือ การตั้งคำถามที่เราใช้เพื่อบรรลุเป้าหมาย เพื่อให้เรามีแรงพลังในการเดินต่อไป และ ทำให้เราสามารถโฟกัสงานที่ทำตรงหน้าได้ หรือ เราควรจะละสิ่งใดที่ไม่เกี่ยวข้องอยู่บนเส้นทางของเราบ้าง แล้วอะไรคือความคิดบวกหรือลบล่ะ ตรงนี้เราจะมาแยกแยะกันได้ว่าอะไรคือคำถามที่จะนำเราไปด้านความคิดบวกหรือลบ เรามาลองดูตัวอย่างคำถามเหล่านี้กันว่าเป็นคำถามแบบไหน

"อะไรคือเป้าหมายที่ฉันต้องการ" 
"ทำอย่างไรเพื่อให้สำเร็จ"
"ฉันจะต้องทำอะไรต่อไป"
3 คำถามด้านบนนี้จะเป็นลักษณะคำถามที่เป็นความคิดบวก สามารถต่อยอดได้ เป็นต้น

"จะทำได้ไหม"
"มันเป็นไปไม่ได้หรอก จะไปต่อดีไหม"
"ฉันไม่เก่งนี่นา จะทำได้หรอ"
3 คำถามนี้เป็นคำถามลักษณะความคิดลบ ทำให้เราหมดพลัง ไปต่อไปไม่ได้ เป็นต้น

ทุกๆเช้าที่ตื่นขึ้นมาลองคิดถามคำถามตัวเองดูนะคะ ให้เลือกคำถามด้านบวก เช่น วันนี้ฉันจะสามารถทำอะไรได้บ้างเพื่อให้ถึงผลสำเร็จที่ตั้งใจ และ ยิ้มให้กับตัวเอง เพิ่มพลังความสุขเข้าไปในทุกๆเช้า แล้วคุณจะสัมผัสได้ถึงชีวิตที่เปลี่ยนไป เปี่ยมล้นไปด้วยความมุุ่งมั่นและความสุขค่ะ
My First NPM Package
Tags: javascript, npm
Published: 2020-07-24 13:31:18

We all have our pain points when it comes to programming. Mine is using the `Math` function with JavaScript. It's a wonderful tool when you know what you're doing but I constantly find myself having to Google what each method means. Off the top of your head, do you know how to generate a random number between 50 and 100? I know you're not required to *know* these sorts of things but what if we can make it easier on us?

That's why I created [totally-random](https://www.npmjs.com/package/totally-random)! A utility class to help with random number generation in JavaScript. It's a real-life NPM package I made all by myself that you can install and use right now! Let's me show you how :)

To get started you will need to install the package to your project with the following command:

![npm i totally-random](https://i.imgur.com/1lg6Jml.png)

This will add a node_modules folder to your project (if you didn't have one already) and include totally-random.

Now, let's import it to our JS file:

![some code](https://i.imgur.com/Igimbx7.png)

The first line is the import statement using `require`. Right now, I don't know how to implement the ES6 `import` statement but that can be something I can add in a future release.

In the next line, we create an instance of the `TotallyRandom` class. You can actually see the entire class and its included methods in the repo [here](https://github.com/superhackerboy/totally-random/blob/master/index.js).

There's not much to it now but I just wanted to create a working NPM package before I deep dive into adding more methods. The included class methods are probably more than what you need from it, anyways. Let's explore some of them:

![code](https://i.imgur.com/8PCK0Wi.png)

You can get a random number up to a positive number and even get a random number down to a negative number. You can also get a random percentage.

![code](https://i.imgur.com/fMY9s29.png)

Getting a random number within a range of two numbers hasn't been easier! You can even pass an optional third number which will return an array of n randomly selected elements within the range of numbers you provided. Whoa!

![code](https://i.imgur.com/cIMlJKT.png)

You can also get random colors generated! You can see `random.color()` will return a random HEX value and `random.color('rgb')` will give you a random RGB value.

There are several more methods I'm not going to list here for the sake of length. I hope you guys find totally-random a useful tool to add to your projects to make it just a bit easier. 

I will continue to work on this package by adding a more clear README, more random number methods, and maybe I can find a quirky thing or two to add just for fun. Please feel free to contribute!
Who is responsible for learning new technologies
Tags: discuss
Published: 2020-07-24 13:19:34

Lately I've been getting into a fight with a work colleague because we disagree about new technology. We mainly work in the web area with C# .NET and Angular/React. However, one of our customers wants a mobile app and so ReactNative or Flutter would be an option. I've already worked with Flutter in my spare time and found the project very interesting. My colleague thinks that the company needs to send us to workshops or training courses now, so that someone can teach us Flutter. I say we should learn in our free time. How do you see that? Do you have similar conflicts?
Dica Rápida: Paginando no MSSQL considerando escala
Tags: sql, database, braziliandevs
Published: 2020-07-24 13:09:00

Olá!

Este post é uma breve continuação do [Dica Rápida: Paginando no MSSQL com Offset e Fetch](https://dev.to/wsantosdev/dica-rapida-paginando-no-mssql-com-offset-e-fetch-3kgl).

Antes de começar, gostaria de agradecer aos colegas [Rafael Ponte](https://twitter.com/rponte) e [Renato Todorov](https://www.linkedin.com/in/renatotodorov/) que fizeram considerações sobre alto volume de dados na Dica Rápida anterior, dando origem a esta continuação! Obrigado, pessoal!

Vamos lá?

Muito embora, para cenários mais simples, com baixo volume de dados, o uso de `Offset` e `Fetch` seja suficiente, quando precisamos trabalhar com grandes volumes, a história muda.

Explico.

No último post disse que a instrução `Offset` vai pular a quantidade de linhas informada. Certo? Pois é! Mas para que o banco saiba quantas e quais linhas pular, ele precisa percorrê-las primeiro. Ou seja, o banco vai percorrer todas as linhas que respeitem o critério `BirthDate` e, em seguida, vai usar as instruções `Offset` e `Fetch` para decidir quais linhas retornar. 

E é aí que mora o problema porque, quanto mais linhas sua tabela tiver, e quanto maior for o `Offset` informado, maior será o número de linhas que deverá ser percorrido antes de retornar a quantidade solicitada pelo uso do `Fetch`! E este é um baita prejuízo para a performance se for preciso paginar milhares de registros.

Mas, então, como resolver isso? Por incrível que pareça, é fácil! A solução se chama *keyset pagination* (ou *cursor pagination*)!

Em vez de informarmos ao banco em qual página estamos, informaremos o último `Id` que lemos, retornaremos apenas os registros de `Id` superior, e assim eliminamos o esforço do `Offset`.

O código anterior seria convertido para o seguinte:

```sql
SELECT TOP (@PageSize)
	Id,
	FirstName, 
	LastName
FROM 
	Customer
WHERE 
	Id > @LastId -- Ou Id < @LastId se a intenção for retroceder uma página
AND
	BirthDate >= '2000-01-01'
ORDER BY
	Id
```

Aparentemente não mudou muita coisa. Não é? Mas, do ponto de vista do banco, essa simples mudança representa um enorme alívio porque, desta forma, não precisamos mais instruir o banco a subdividir a consulta com todos os resultados que atendam ao critério `BirthDate` informado, pois a informação do `TOP` no `SELECT`, e do último `Id` conhecido na cláusua `WHERE`, são o suficiente para instruir o banco sobre a partir de qual linha ele deve começar, e até quantas linhas ele precisa percorrer.

> **Nota:** A coluna `Id` pode combinada com, ou substituída por, qualquer coluna indexada.

Legal. Né? 

Gostou? Me deixe saber pelos indicadores. Dúvidas? Me envie pelos comentários que responderei assim que puder.

Até a próxima!

> Referências:
>
> [Please Don't Use OFFSET and LIMIT For Your Pagination](https://hackernoon.com/please-dont-use-offset-and-limit-for-your-pagination-8ux3u4y)
AngularJS Tutorial
Published: 2020-07-24 13:05:08

This tutorial has been designed to help you learn AngularJS as quickly as possible. Here, we are going to cover basic as well as advanced concepts with appropriate examples to give you a complete overview of AngularJS. To learn this framework, you need to have a basic knowledge of JavaScript, HTML, CSS, and web applications. Without wasting much time, let's get into the Angular JS tutorial part. 

What is AngularJS?

AngularJS https://bit.ly/2XQaEyo is an open-source Javascript MVC (Model, View Controller) framework which is widely employed for developing web applications. It has become one of the most popular frameworks at present due to its unique features. The AngularJS framework is mainly used to develop single-page applications.  

AngularJS has got the ability to transform the static HTML into a dynamic one. This framework enhances the capabilities of HTML with its built-in attributes, components and also helps in creating custom attributes using simple JavaScript. 

AngularJS has been developed by a group of people at Google and it has got a large community that makes it up to date. It always comes up with new features to meet market requirements.

What makes AngularJS more Popular?

The biggest and in fact the true factor that contributes to the popularity is nothing but the global community support of AngularJS. Actually, many designers are working with developers and are also contributing to enhancing the overall reliability, as well as the credibility of AngularJS. It is equipped with a unique feature, i.e., two-way data binding which makes it simple to work with. Also, AngularJS is considered as a full-fledged framework. It contains many top-class features when compared to ReactJS. In addition to this, it simply prompts rendering.

CDN Access: 

You can also have access to the Content Delivery Network (CDN) that will allow you to access the regional data centers. Here the CDN takes the responsibility to transfer the data between your own servers to a series of external servers. It also brings you an advantage; if a user of your site has already downloaded a copy of AngularJS from the same CDN, then there is no need to re-download it.
When to use Microservices
Tags: microservices, architecture
Published: 2020-07-24 12:47:49

Sam Newman spoke with Martin Fowler about his newest book "Monolith to Microservices". One of the key questions was "When should you use Microservices"

"I could talk about the things that microservice architectures can give a lot. It gives you more options around how to scale up applications. It gives you this lovely property of independent deployability. When implemented correctly, it can really help isolate the surface area of failure, what some people call kind of limiting the blast radius, which can help make applications more robust."
{% youtube D5CGyA9xIH4 %}
Hacky Friday Stuff #24.07.2020
Tags: ruby, rails, javascript, hackyfriday
Published: 2020-07-24 12:32:32

*Links about web development, product engineering, tools and services from all over the internet.*

[Ruby Method Overloading](https://lucaguidi.com/2020/07/22/ruby-method-overloading/)
Method Overloading is a programming language feature that allows you to define multiple signatures (and implementations) of the same method. Ruby doesn’t have such a feature, but there is a hack to make this possible based on method arity.

[Removing SHA1 passwords from RubyGems.org](https://blog.rubygems.org/2020/07/16/removing-sha1-passwords-in-rubygems-org.html)
Yet another reminder to stop using SHA1 hashing algorithm for passwords as it's widely considered insecure.

### Articles, tutorials

[Building a Toy Lexer in Ruby](https://www.honeybadger.io/blog/building-lexer-ruby/)
Lexers are magical. They take your messy, hand-typed, human text, and convert it into a clean data structure that the computer can process. Every time you run a ruby program, use structured search or type in a date by hand, you'll find a lexer hard at work. In this article, Alex Braha Stoll pulls back the curtain to show us how lexers work and how to implement one for a simple programming language.

[22 Miraculous Tools for React Developers in 2019](https://medium.com/better-programming/22-miraculous-tools-for-react-developers-in-2019-7d72054e2306)
It's almost a one-year-old article but it covers a comprehensive list of tools that still could be useful to anyone working with React nowadays.

[Making RSpec Tests More Robust](http://jakeyesbeck.com/2020/07/19/making-rspec-tests-more-robust/)
Mocks and stubs in RSpec allow developers to make important assertions about their code. Unfortunately, mocking can also cause false positives when modifying real code. In this article, you'll find how to overcome some of those issues.

### Gems, libraries

[Pragmatic Tokenizer](https://github.com/diasks2/pragmatic_tokenizer)
Pragmatic Tokenizer is a multilingual tokenizer to split a string into tokens.

[Recoil](https://recoiljs.org/)
A state management library for React.

### Podcasts

[Full Stack Radio | 143: Rich Harris - Svelte and Defending the Modern Web](https://fullstackradio.com/episodes/143)
In this episode, Adam talks to Rich Harris about Svelte, and why we should keep pushing forward with the modern web even if it's not perfect yet.

[Ruby Rogues | RR 464: PWAs on Rails with John Beatty](https://devchat.tv/ruby-rogues/rr-464-pwas-on-rails-with-john-beatty/)
John Beatty joins the Rogues to talk about building Progressive Web Applications on Ruby on Rails. He walks the Rogues through the ins and outs of building a PWA and what it’s like adding the features you need to get a PWA set up on Rails. It turns out to be surprisingly straightforward and yet has a ton of potential.

Photo by [Alexander Sinn](https://unsplash.com/@swimstaralex) on [Unsplash](https://unsplash.co).
Prune Your Web Dev Career (or Watch It Grow Wild!)
Tags: career, tips, beginners, codenewbie
Published: 2020-07-25 00:57:12

---
title: Prune Your Web Dev Career (or Watch It Grow Wild!)
description: Your career isn't defined only by the opportunities you say 'yes' to. It's defined just as much those you say 'no' to. If you say yes to everything, you're letting other people define your path for you.
published: true
date: 2020-07-24 12:20:00 UTC
tags: career,tips,beginners,CodeNewbie
canonical_url: https://raddevon.com/articles/prune-your-web-dev-career-or-watch-it-grow-wild/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/qc7v9t8q0inxtq6nj311.jpg
---
All too frequently, people end up changing careers into web development only to realize their new career sucks and they just want to get out of it! 😫 This usually happens if you say yes to everything. Your career is defined not by what your goals are but by who gets to you first. 🏃‍♂️

Watch this. It’s important!

{% youtube _g_pEwRzMko %}

I’ll share an analogy to bonsai trees (along with some absolutely choice puns) to help explain why saying yes to everything is a terrible idea and how pruning your career by saying no will allow you to build it into the career you ultimately want.

I’ll also tell you a story about my own experience turning down a job that paid 50% more than my previous job 💸… which cleared the way for me to take a job months later that paid 2x 💰💰 what that one would have paid.

In the process, I share a short clip of a video by [Bonsai Boise](https://www.youtube.com/channel/UCq_hcjdI7a_HJ_LxBri4prw).

Thanks for watching. Comment here or on YouTube if you have questions. While we’re here, are you driving your career, or are you waiting for someone to invite you into the party? Stop waiting for someone to take a chance on you, and start freelancing instead! [My Freelancing Crash Course 🎓](https://raddevon.com/enroll-in-the-freelancing-crash-course/) will help you get started for free!
Appium & Robot Framework: Record Test Execution
Tags: mobiletesting, appium, robotframework, tutorial
Published: 2020-07-24 12:18:07

The latest release of the Robot Framework's [Appium Library](https://github.com/serhatbolsu/robotframework-appiumlibrary) introduces keywords for recording a video of the Appium test execution in iOS and Android phones. 

## Instructions for use:

1. If test is run in iPhone, install ffmpeg in the Mac where Appium is running: `brew install ffmpeg`
2. **Simple use case:** Use [Appium Library's](https://serhatbolsu.github.io/robotframework-appiumlibrary/AppiumLibrary.html#Start%20Screen%20Recording) keyword `Start Screen Recording` in the Test Setup and `Stop Screen Recording` in the Test Teardown. Recording is stored in the same place where Robot test case reports are. Video file is not stored permanently to the storage of the phone.
3. **Error-proof use case:** Some Android phones (for example  Huawei models) are not capable of recording the screen and the test case will fail (in the latest Appium library 	1.5.0.4 - this might change in the future). It is a good idea to start and stop recording using a keyword `Run Keyword And Ignore Error` (remember also import BuiltIn library for the Robot Framework code). Here's an example of this error-proof case:
{% gist https://gist.github.com/laojala/2f60ba95ff72c38397b780984c4ad69a %}
4. **Storing recording only for failed tests:** Here's an example code that stores screen recording only when a test case fails:
{% gist https://gist.github.com/laojala/086249b6435990896971d2a99ab0d1a4 %}

### Viewing videos

For Android recordings, file format is `.mp4` that is easy to open with many tools. For iOS, file format is `.ffmpeg`. To view ffmpeg videos, use `ffplay` in the command line (in a computer where ffmpeg is installed):

```
ffplay appium-screenrecord-10.ffmpeg
```


## Free word

In my opinion, this example showcases nicely how the use of readily available Robot Framework libraries reduces the amount of test automation code (and thus less maintenance and bugs in it!). Capturing video of the screen is now only a few simple lines of code, whereas file handling using native Appium would require more logic.