teleren/devto huggingface dataset:
Scrimbas  JavaScriptmas: More satisfying than chocolate!
Tags: javascript, javascriptmas, scrimba
Published: 2020-12-31 15:03:56

24 small JavaScript challenges in December. Some of them were easy, others challenging. All of them made me more satisfied than chocolate:

1 → Candies: https://scrimba.com/scrim/co8e0496c9fc5c36dbab0a33e

2 → Deposit Profit: https://scrimba.com/scrim/cof114961bfacba25021a90fc

3 → Chunky Monkey: https://scrimba.com/scrim/co5114de5842c561b3c8cb726

4 → Century From Year: https://scrimba.com/scrim/co7a846ba960fc18c2324f862

5 → Reverse A String: https://scrimba.com/scrim/co63d4f0695db351c7eed5de8

6 → Sort By Length: https://scrimba.com/scrim/co1f34533b1dcbfc9cabc35ae

7 → Count Vowels Consonants: https://scrimba.com/scrim/cof58457ea9a76f8082320420

8 → The Rolling Dice: https://scrimba.com/scrim/coc664425a2acdc44450644bc

9 → Sum Odd Fibonacci Numbers: https://scrimba.com/scrim/cob814dabb7385f6b4bdf5d28

10 → Adjacent Elements Product: https://scrimba.com/scrim/co8ce4fd3af3fe9876a70971a

11 → Avoid Obstacles: https://scrimba.com/scrim/co4ae46de9f7d76a61162d6ab

12 → Valid Time: https://scrimba.com/scrim/co8d54fde8ca75ddb9417140f

13 → Extract Each Kth: https://scrimba.com/scrim/cof734727856074435acc2b36

14 → Maximal Adjacent Difference: https://scrimba.com/scrim/cocdc48af826e070ee40bb4bb

15 → Carousel: https://scrimba.com/scrim/co20948a2915fdcd528d6eb64

16 → Insert Dashes: https://scrimba.com/scrim/coa7f4903abd8e3892ba482cd

17 → Different Symbols Naive: https://scrimba.com/scrim/co45c424ca9fb1b12aafaf623

18 → Array Previous Less: https://scrimba.com/scrim/co77c4d4ea908ee6f6bc87d24

19 → Alphabet Subsequence: https://scrimba.com/scrim/codf1424080809b7ebb9554ab

20 → Domain Type: https://scrimba.com/scrim/co53a4caf903cb56ecb39cb42

21 → Sum of 2: https://scrimba.com/scrim/co43c4c3b9e2f4b75913010ae

22 → Extract Matrix Column: https://scrimba.com/scrim/co19242ff9e6e950aa70e77dc

23 → Social Media Input: https://scrimba.com/scrim/co3b744b388ca6c160de8cb3a

24 → Test Your Agility: https://scrimba.com/scrim/cod7d43a48effa9a62a69d017
Best time to buy and sell 📈 (easy)
Tags: javascript, algorithms
Published: 2020-12-31 14:57:11

This problem asks to find the highest profit given a list of daily prices. We are provided with an array of integers and have to find the highest possible buy-sell combination during the period of time in the array.

The main technique of this algorithm is to use `Math.max` method to compare the profits of the combinations and keep the highest one.

```javascript
const maxProfit = (prices) => {
    
    if (prices.length === 0){
        return 0
    }
    let current = 0
    let max = 0
    for(let i = 0; i<prices.length; i++){
        
        for(let j = i+1; j<prices.length; j++){
        // O(n^2) nested loop
        // inner loop on i+1 to always compare to next elements
            if(prices[j] - prices[i] > 0){
                current = prices[j] - prices[i]
            }
        max = Math.max(current, max) 
        // compare profits save higher
        }
    }
    return max
};
```

We use a nested loop that starts at `i+1` so we can compare the future days' price to the current day's price. 

Also, we use two variables to store the profits `current` (only when the difference is positive so there is profit) and `max`, and with the `Math.max` method, only keep the highest of the two.

Feel free to reach out on [LinkedIn](https://www.linkedin.com/in/santiago-salazar-pavajeau/) and [Twitter](https://twitter.com/santispavajeau)!
My 2020 in One Article
Tags: career, beginners, webdev
Published: 2020-12-31 14:56:31

2020 is hard year for everyone,It teach us to fight, Learn and how to stay strong in tough times

This year i build myself as developer, I learned React, Express, Flutter, Git, Firebase, Github, I Joined Dev to, Create 4 Main Project and Write 13 Article on Dev.to, And Many more
## My Posts
{% post https://dev.to/web/list-of-github-cli-commands-5516 %}

{% post https://dev.to/web/list-of-all-git-commands-4m83 %}

{% post https://dev.to/web/design-github-profile-using-readme-md-8al %}

{% post https://dev.to/web/have-you-tried-this-it-s-live-33po %}

{% post https://dev.to/web/invitation-in-web-organization-1ef9 %}

{% post https://dev.to/web/creating-a-master-portfolio-for-developers-during-hacktoberfest-4i9p %}

{% post https://dev.to/web/master-portfolio-create-a-portfolio-website-in-minutes-34mo %}

{% post https://dev.to/web/master-portfolio-first-release-2mbe %}

{% post https://dev.to/web/master-portfolio-v2-what-s-new-23df %}

{% post https://dev.to/web/svghero-javascript-package-for-hero-effect-in-svg-47l3 %}

{% post https://dev.to/vimal/my-process-of-dev-digitalocean-hackathon-8em %}

{% post https://dev.to/vimal/my-portfolio-you-can-customize-to-your-own-in-5-minutes-19dp %}

{% post https://dev.to/vimal/my-2020-in-one-article-jfj %}


## my Projects
 {% github vimalverma558/devto no-readme %} 
 {% github vimalverma558/Master-Portfolio no-readme %} 
 {% github vimalverma558/vimalverma558.github.io no-readme %} 
 {% github vimalverma558/Covid19-Api no-readme %} 


<span>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/s/photos/2020?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span>
Caching records by tags in Go
Tags: go, redis, programming, cache
Published: 2020-12-28 20:39:37

---
title: "Caching records by tags in Go"
published: true
description: "Tag based approach to invalidate cache objects"
tags: ["go", "redis", "programming", "cache"]
---

## Introduction
Caching has an important role to play in a system design. It is primarily used to speed up information retrieval from a service and reduce the load on a database engine, the primary source of truth for a service. Data that is frequently requested by users are stored in a in-memory key-value store, like [Redis](https://redis.io/), to speed up subsequent look up of the same data. In this post, I want to specifically talk about cache invalidation and provide an implementation in Go for invalidating cache using tags.

## Cache Invalidation
When frequently accessed data which is stored in a cache is updated, it is necessary for the application to evict the stale data from the cache. So when subsequent requests for the same data is received by the application, it will retrieve fresh data from the database and store it in the cache. This way, users will never receive stale data from the application. The process of cache invalidation can be made easier by tagging data with specific tags when storing in the cache. This way, when the data needs to be invalidated, we can use the tag names to evict them from the cache.

Here is an implementation of caching records by tags. We will use Redis and `github.com/go-redis/redis` package.

```go
import (
    "github.com/go-redis/redis/v7"
)

type cache struct {
    client redis.Client
}

func (c *cache) SetByTags(ctx context.Context, key string, val interface{}, tags []string, expiry time.Duration) error {
	pipe := c.client.TxPipeline()
	for _, tag := range tags {
		pipe.SAdd(tag, key)
		pipe.Expire(tag, expiry)
	}

	pipe.Set(key, b, expiry)

	_, errExec := pipe.Exec()
	return errExec
}

func (c *cache) Invalidate(ctx context.Context, tags []string) {
	keys := make([]string, 0)
	for _, tag := range tags {
		k, _ := c.client.SMembers(tag).Result()
		keys = append(keys, tag)
		keys = append(keys, k...)
	}
	c.client.Del(keys...)
}
```

In `SetByTags` method, we maintain a `set` data structure for each tag provided. We then add the given cache key into these sets. When invalidating cache by tags, we get all the members, i.e. cache keys, for the given tags and delete them from Redis.

Example usage:
```go
tags := []string{"post1", "post2"}
value := "blog data"

key1 := "blog:one:post1"
key2 := "blog:one:post2"

// Set cache by tags here:
cache.SetByTags(ctx, key1, value, tags, 24 * time.Hour)
cache.SetByTags(ctx, key2, value, tags, 24 * time.Hour)


// Invalidate cache by tag "post1" here.
// Both key1 and key2 will be evicted, since both were tagged with "post1".
cache.Invalidate(ctx, []string{"post1"})
```

## References
- https://redis.io
- https://github.com/go-redis/redis.git

If you find any issues or errors in the content, please do let me know in the comments below.

In case you like to read more articles related to software development and programming, check out my [blog](https://ayada.dev).
Multi-Year Database of Daily Ranked HackerNews Front Page Posts
Tags: database, startup
Published: 2020-12-31 14:51:52

#Features
- A Multi-year database of Daily Ranked Hacker News Front Page posts.
- Tens of Thousands of records from multiple years, with more being added.
- Multiple data points, including Date, Post Rank, Post Title, Keywords, Posted on Week Day, Posting at Hour, Post Domain, Post URL, Posted by User, No. of Comments, Score, etc.
- Filterable and Searchable Color Coded Database
- Included only the curated and Top Ranked posts from the front page for each day of the year(s)(30 per day).

[Sounds Interesting? Get Now >>](https://gumroad.com/a/940438643)
Day 54 of #100DaysOfCode: Review CSS- display
Tags: 100daysofcode, css, display, webdev
Published: 2020-12-31 14:45:23

## Introduction
The *Review CSS* series is the note for some common CSS usages. Three are three types of CSS position: block, inline, inline-block.


## 1. display: block

#### Properties
1. Everything is respected
2. The elements don’t sit side by side

#### Demo
{% codepen https://codepen.io/JenHsuan/pen/LYRQryd %}

#### Code

```html
<div class="outer">
  <span class="inner">
    inner
  </span>
  <span class="inner">
    inner
  </span>
</div>
```

```CSS
.outer {
  position:relative;
  color:green;
  border: 3px solid green;
  height: 400px;
  width: 500px;
}

.inner {
  display:block;
  padding:2%;
  margin: 2%;
  color: blue;
  border: 3px solid blue; 
  text-align:center;
  font-size: 30px;
  height: 100px;
  width: 200px;
  top:50%;
}
```

## 2. display: inline

#### Properties
1. Width and height are not respected
2. Top and bottom margins are not respected

#### Demo
{% codepen https://codepen.io/JenHsuan/pen/mdrXKMa %}

#### Code

```html
<div class="outer">
  <span class="inner">
    inner
  </span>
  <span class="inner">
    inner
  </span>
</div>
```

```css
.outer {
  position:relative;
  color:green;
  border: 3px solid green;
  height: 400px;
  width: 500px;
}

.inner {
  display:inline;
  padding:2%;
  margin: 2%;
  color: blue;
  border: 3px solid blue; 
  text-align:center;
  font-size: 30px;
  height: 100px;
  width: 200px;
  top:50%;
}
```

## 3. display: inline-block

#### Properties
1. Width and height are respected
2. Top and bottom margins are respected
3. The elements sit side by side

#### Demo
{% codepen https://codepen.io/JenHsuan/pen/GRjQGye %}

#### Code

```html
<div class="outer">
  <span class="inner">
    inner
  </span>
  <span class="inner">
    inner
  </span>
</div>
```

```css
.outer {
  position:relative;
  color:green;
  border: 3px solid green;
  height: 400px;
  width: 500px;
}

.inner {
  display:inline-block;
  padding:2%;
  margin: 2%;
  color: blue;
  border: 3px solid blue; 
  text-align:center;
  font-size: 30px;
  height: 100px;
  width: 200px;
  top:50%;
}
```

That's it!

## Articles
There are some of my articles. Feel free to check if you like! 
* My blog-posts for software developing: https://medium.com/a-layman
* My web resume: https://jenhsuan.github.io/ALayman/cover.html
* Facebook page: https://www.facebook.com/imalayman
* My latest side project - Daily Learning: https://daily-learning.herokuapp.com/
2020: Year in Review
Tags: byebye2020
Published: 2020-12-31 14:30:51

It’s the last day of the year!🎉
I like to share with you how my year has been.
A year full of **challenges, pains, and lessons**.
2020 made all of us to **accept the change and adapt accordingly**.
I realize it sounds insane to state thinking about the ongoing pandemic situation and so many unfortunate incidents, but this is, however, true for me. This year was one of the most remarkable years of my life where I learned lots of things, not only career-related but also about people and life in general. I grew as a person.


❌My failures of 2020:❌
* Failed to keep journaling consistently
* Failed to take care of my mental and physical health
* Failed to learn Django, AWS
* Failed to participate in Google Kick Start
* Failed to qualify for the Microsoft Azure Certification exam
* Failed to start or complete the projects which I wanted to do this year.
* Failed to do job challenge by [Tanay Pratap Sir](https://www.instagram.com/tanaypratap/)

✔My wins of 2020:✔
* Earned Google crowdsource badge
* Participated in a design challenge by [Ambika S](https://www.instagram.com/sheistechie/) and learned a lot of things.
* Got [GitHub Student Developer Pack](https://education.github.com/pack) (worth $200K)
* Learned Microsoft Azure cloud computing
* Earned Azure Hero Kudo Badge
* Earned Cloud Skills Champion Badge
* Earned a free certification voucher (approx $165)
* Completed the [Hacktoberfest challenge](https://hacktoberfest.digitalocean.com/)
* Earned a JS book in a giveaway by [javascript_interviews](https://www.instagram.com/javascript_interviews/) 
* Featured as a creator in [Vaibhav Khulbe’s](https://www.instagram.com/vaibhavkhulbe143/) Dev Weekly newsletter issue no #66 

What I learned this year is **never take things for granted and be thankful for what you have.**

✅Quote of the day✅
“The person who fails the most wins.” – **Seth Godin**
It's been a crazy year.
Thank you everyone from the bottom of my heart for your support.💖👏
Stay healthy, keep hope, and never stop learning!
The best is yet to come!💯💯✨✨
Bye-bye 2020👋👋
Setting up production-grade Kubernetes clusters
Tags: kubernetes, devops
Published: 2020-12-31 14:27:56

According to the latest research, 76% of enterprises will standardize on Kubernetes (k8s) within the next 3 years. K8s is THE standard for container orchestration. Many companies are starting to take advantage of k8s or are already deploying their first applications. Getting k8s up and running is easy. No need to do it ‘the hard way anymore (sorry Kelsey). You will get a cluster up and running on Google Cloud Platform (using Kubernetes Engine) in just a couple of minutes. Or open up a Microsoft Azure subscription and search for ‘Kubernetes’. In a few clicks, you’ll have a cluster up and running.

But now the journey starts. Are you ready now, for deploying applications in a production scenario? Hmmm, there is still a lot to do. In this post, I will give you some directions on how to set up a production-grade k8s cluster.

Read the full article on https://redkubes.com/blog/setting-up-production-grade-kubernetes-clusters/
¿Qué tan «globales» son las variables globales en PHP?
Tags: php
Published: 2021-09-16 12:14:38

---
title: ¿Qué tan «globales» son las variables globales en PHP?
published: true
date: 2020-12-31 14:27:00 UTC
tags: php
canonical_url: https://academy.leewayweb.com/que-tan-globales-son-las-variables-globales-en-php/
---

Parece una pregunta rara, ¿no? Seguro estás pensando «¿Dónde está la trampa?», ¿cierto? En general se entiende que una variable global es aquella que está presente (es decir, puede ser leída y modificada) en cualquier lugar de un programa. El caso de PHP es algo particular. Para comenzar si hicieras algo como esto: Esperarías ver: […]

La entrada [¿Qué tan «globales» son las variables globales en PHP?](https://academy.leewayweb.com/que-tan-globales-son-las-variables-globales-en-php/) se publicó primero en [Leeway Academy](https://academy.leewayweb.com).
Como coletar logs do MongoDB com o Filebeat
Published: 2020-12-31 14:24:09

## O que é o MongoDB?
O MongoDB é um software banco de dados orientado a documentos, que é opensource e é desenvolvivido pela MongoDB Inc e é classificado como um banco NoSQL (Não Relacional).

Para conhecer mais sobre o projeto, acesse o site oficial dele [aqui](https://www.mongodb.com/2).

Também recomendo a leitura do post [*SQL ou NoSQL?*](http://db4beginners.com/blog/sql-ou-nosql-mongodb/) no blog da Dani Monteiro, onde ela explica as diferenças de um banco de dados SQL e NoSQL e mostra alguns conceitos sobre o MongoDB.

## Como coletar logs do MongoDB com o Filebeat
O módulo Mongo DB coleta logs que são criados pelo MongoDB. Para saber mais sobre esse módulo, acesse a documentação nesse [link](https://www.elastic.co/guide/en/beats/filebeat/7.10/filebeat-module-mongodb.html)

* Instale o Filebeat:

**Windows:** `PowerShell.exe -ExecutionPolicy UnRestricted -File .\install-service-filebeat.ps1`
**Linux:** `sudo rpm -vi filebeat-7.10.1-x86_64.rpm`

* Acesse o arquivo de configuração do Filebeat:

**Windows:** `C:\Program Files\Filebeat\filebeat.yml`
**Linux:** `/etc/filebeat/filebeat.yml`

Insira nele as informações de conexão com o Elasticsearch e com o Kibana:

```
output.elasticsearch:
  hosts: ["url_do_elasticsearch:9200"]
setup.kibana:
  host: ["url_do_kibana:5601"]
```

* Habilite e configure o módulo :
**Windows:** `.\filebeat.exe modules enable mongodb`
**Linux:** `sudo filebeat modules enable mongodb`

* Habilite e configure o módulo :
**Windows:** `.\filebeat.exe modules enable mongodb`
**Linux:** `sudo filebeat modules enable mongodb`

* Para modificar as configurações do módulo, altere o arquivo mongodb.yml:

**Windows:** `modules.d/mongodb.yml`
**Linux:** `/etc/filebeat/modules.d/mongodb.yml`

Por padrão, o arquivo vem com as seguintes informações e é aqui que você especifica o caminho para o seu diretório de logs:

```
# Module: mongodb
# Docs: https://www.elastic.co/guide/en/beats/filebeat/7.10/filebeat-module-mongodb.html
- module: mongodb
  # All logs
  log:
    enabled: true
# Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    #var.paths: ["/diretório/do/log/mongodb/*.log*"]
```

* Carregue os dashboards do módulo:

**Windows:** `.\filebeat.exe setup`
**Linux:** `sudo filebeat setup`

* Inicie o serviço do Filebeat:

**Windows:** `Start-Service filebeat`
**Linux:** `sudo service filebeat start`

Depois disso, você conseguirá ver os logs do seu ambiente no discover, além de ter dashboards com informações e métricas do seu MongoDB.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/snbknsvrep3dkvuuc15g.png)
2020: Year in Review
Tags: yearinreview
Published: 2020-12-31 14:17:39

Hi everyone! I will like to share my year in review (2020). This happens to be my first time writing a review. I love to share my achievements and failure.

### Top Highlight

- Started Technical Writing and Blogging ( [Powered by Hashnode](https://blog.idrisolubisi.com/) and [Dev.to](https://dev.to/olanetsoft))

- [My portfolio](https://idrisolubisi.com/) went live early this year after a long time of planning and procrastination

{% twitter 1224649794255314949 %}

- Bagged a certification in  JavaScript Algorithms and Data Structures
{% twitter 1248627007883116546 %}

- Contributed to Open Source (technically and non-technically) [Gatsby](https://www.gatsbyjs.com/), [Svelte](https://svelte.dev/) and many more...(looking forward to contributing more)
{% twitter 1253706229307838464 %}

- Bagged a certification in API & Microservices 
{% twitter 1257671409700134914 %}

- Pass my Azure Exams
{% twitter 1284137908698591232 %}


- Completed #100daysOfCode
 {% twitter 1293137810673864706 %}


- Became a member of the International association of engineers
{% twitter 1253706229307838464 %}

- Became a Public Speaker ([gave my first ever talk](https://www.youtube.com/watch?v=hIxzr8UK89M))

- Became a Mentor & a Technical Coordinator at [SheCodeAfrica](https://twitter.com/SheCodeAfrica) and  I was able to give a selfless dedication, commitment, and contribution.
{% twitter 1343295594975154185 %}

- Got over 30 job rejections

- Made new friends on #Techtwitter

I think that's all 🤦‍♀️

If I start mentioning names of amazing individual that helped me directly or indirectly, this article will become too long, I am so grateful. 

I thank God for everything, Looking forward to more opportunities in 2021

Happy New Year 🎉🎉

You can reach out to me on [Twitter](https://twitter.com/olanetsoft)
New one more more declarative templating syntax?
Published: 2020-12-31 14:09:21

Following my previous [post](https://dev.to/chrisczopp/how-i-designed-an-alternative-to-jsx-2nmh), I'd like to ask you what you think about the presented syntax?

It suppose to be as close to HTML as possible. But, the main difference between this and others is that it doesn't use any inline JS e.g. in `for` loops or `if`'s. It suppose to be something complimentary to [GlueDOM](https://github.com/gluecodes/gluecodes-glue-dom) to let developers write HTML and only when necessary extend it with sandboxed JS.

The rationale behind making another syntax instead of using JSX can be found in this [README.md](https://github.com/gluecodes/gluecodes-glue-dom). But in short is to have a unified way of writing UI components containing complex conditionals. JSX is cool but can easily get nasty. 


```html
<h1>Syntax Idea</h1>
<input-x type="text" name="firstName">
  <script>
    if (actionResults.setFirstNameInputVisible) {
      props.className = 'visible'
    }
    
    props.onClick = () => {

    }
  </script>
</input-x>
```
DO Submission: PDF Server (for Figma templates)
Tags: dohackathon, nextjs, figma, chakra
Published: 2020-12-31 13:59:37

---
title: DO Submission: PDF Server (for Figma templates)
published: true
description: Next.js app to fill figma PDF designs with custom data
tags: dohackathon, nextjs, figma, chakra
series: ["pdf-server-for-figma-templates"]
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/l8jhylxfo9ghpi8nw7hg.png
---

## What I built

PDF Server

Next.js app with a front and backend to fill Figma PDF designs with custom data. Only simple vectors + layouts and text based templates supported for now. But you could already use it for a lot of use cases.

### Category Submission: 

Built for business

### App Link

https://pdf.blooob.co

[![Deploy to DO](https://mp-assets1.sfo2.digitaloceanspaces.com/deploy-to-do/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/madhenry/pdf-server/tree/main&refcode=5fc6d2f5bf61)

### Screenshots

![Frontend with predefined templates](https://dev-to-uploads.s3.amazonaws.com/i/ji0y93m8l5bm4r0rjhy3.png)
![Frontend with and figma file url input](https://dev-to-uploads.s3.amazonaws.com/i/l8jhylxfo9ghpi8nw7hg.png)

### Description

It's easy to setup and configure, just check the docs or demos.
Integrate it into your other services/apps that need custom PDF template download/streaming functionality etc!

Built with next.js (typescript) + chakra + react-pdf + figma-js + figma-transformer.

### Link to Source Code

https://github.com/madhenry/pdf-server

{% github madhenry/pdf-server %}

### Permissive License

MIT

## Background

I'm building a SaaS for a client and one part of a critical functionality is the ability to export dynamic reports with all kinds of data in PDFs.
Currently the layouts and styles for PDFs are hardcoded in code and any updates need code changes. But what if a designer could just edit a template in Figma, test it out and voilà the new design is applied in production as well without any code changes.

### How I built it 

I learned a bit more about typescript and how to configure DigitalOcean's deploy button for easier setup. I also learned that there is a lot of work ahead to support all the features and styles from Figma.

Definately planning to support dynamic rows in templates + custom fonts and other primitives and hopefully gradient colors and images as well.

### Additional Resources/Info

Documentation: https://github.com/madhenry/pdf-server

{% github madhenry/pdf-server %}

[![Deploy to DO](https://mp-assets1.sfo2.digitaloceanspaces.com/deploy-to-do/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/madhenry/pdf-server/tree/main&refcode=5fc6d2f5bf61)

Any feedback appreciated! Happy new year everybody :)