teleren/devto huggingface dataset:
Advent of Code 2020 Solution Megathread - Day 20: Jurassic Jigsaw
Tags: adventofcode, challenge
Published: 2020-12-20 15:34:10

---
title: Advent of Code 2020 Solution Megathread - Day 20: Jurassic Jigsaw
published: true
description: Reassembling an image from partial tiles by matching the pixels on the edges!
tags: adventofcode, challenge
series: Advent of Code 2020
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/qsovcna9xjcrv5mmvtxf.png
---

Five more days!  Five more days!  Five more days!

## The Puzzle

In [today’s puzzle](https://adventofcode.com/2020/day/20), we're looking for Nessie!  Well, we're rotating, flipping, and reassembling tiles of pixels on the off-chance that we actually see something in what can only be described as a complexity *nightmare*.  I'm not really sure how this one is going to get done without ridiculous amounts of looping, but that's why we get paid the big bucks! 

## The Leaderboards

As always, this is the spot where I’ll plug any leaderboard codes shared from the community.

```
Ryan's Leaderboard: 224198-25048a19
```

If you want to generate your own leaderboard and signal boost it a little bit, send it to me either in a DEV message or in a comment on one of these posts and I'll add it to the list above.

## Yesterday’s Languages

Updated 07:33AM 12/20/2020 PST.

| Language   | Count |
|------------|-------|
| Haskell    |     2 |
| JavaScript |     1 |
| Ruby       |     1 |
| Python     |     1 |
| Rust       |     1 |

Merry Coding!
Creating Postman Tests
Tags: webdev, testing, tutorial, beginners
Published: 2020-12-20 15:16:32

In this post, we will be creating Postman Tests and take a look at some of the advantages of using Postman Tests.

#### **Advantages of Postman Tests**

- We can validate the response of the API to ensure it’s working as expected. So far we have just been making API requests using Postman but how do we know the data being returned is what we want, using tests we can verify the response and the functionalities of our APIs.
- We can perform regression testing to ensure new development changes haven’t broken existing functionality. One of the main purposes of writing these tests is to make sure if something breaks we catch it right away through the automation we have built using these tests without having to do anything manually.

#### **How to create Postman Tests?**
We can use the `pm.test` function to create tests in Postman. Here’s an example where we are verifying the status of the response we got back.

![postman tests](https://automationbro.com/wp-content/uploads/2020/12/Screenshot-2020-12-14-190554-1.png)

Postman tests use ChaiJS BDD syntax for test assertions. For those that are not familiar with Chai JS, it’s a JavaScript testing library that allows you to add test assertions. Some examples of that are –

- .to.have
- .to.equal
- .to.not.have

These are quite readable and you easily know what the assertion is trying to verify.

#### **Postman Test to verify response body**
In the example below, we created a test to verify the response body by using various Chai assertions –

```
pm.test("Verify response body", () => {
    pm.expect(pm.response.json().id).to.equal(pm.variables.get("card_id"))
    pm.expect(pm.response.json().name).to.not.be.empty;
    pm.expect(pm.response.json().idLabels).to.be.an('array')
});
```
---

### **Check out the video below to learn more about Postman Tests –**
{% youtube p3bNoGHC_PQ%}

---

#### To learn about API Test Automation using JavaScript, check out my free tutorial series here –
[JavaScript API Test Automation Tutorial Series](https://www.youtube.com/watch?v=ZSVw3TyZur4&list=PL6AdzyjjD5HDR2kNRU2dA1C8ydXRAaaBV)

---

📧 Subscribe to my [mailing list](https://automationbro.com/mailing-list) to get access to more content like this 
👍 Follow @automationbro on Twitter for the latest updates

...

I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

<a href="https://www.buymeacoffee.com/automationbro">![Buy me a coffee](https://dev-to-uploads.s3.amazonaws.com/i/4aw2ub3f4qkyjk0ivwt4.png)</a>

You can also support me by liking and sharing this content.

Thanks for reading!
What is success in Software Engineering?
Tags: success, career, engineering
Published: 2020-12-20 15:11:32

---
title: What is success in Software Engineering?
published: true
description: Success is defined as the accomplishment of an aim or purpose. So, success has to be accomplished. Success can be a role for somebody, a senior software engineer role or it can be a salary bracket or any other thing like getting your acknowledged. What is a success for you?
tags: success, career, engineering
---
Progress: Creating and viewing jobs, contacts and vehicles
Published: 2020-12-20 15:06:19

So far for the CRUD functionality, I'm able to create and view jobs, contacts, and vehicles.

## Jobs
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9wt4n2gczn5qk8wdq8re.png)

## Contacts
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/1b7w8b1bfcwxcabpmalc.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/h8h1qwg77sswu5zan7ba.png)

## Vehicles
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/9n3znvpn79fybsw183xf.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hwt5xzn5qih27bxfdw7m.png)

## Next step
Implement update and delete and start showing some data on the dashboard.
How to Enable Dark Mode in GitHub.
Tags: github, tutorial, darkmode, git
Published: 2020-12-20 14:59:58

# DARK MODE is now available in GitHub.
![github profile](https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg)
[GitHub](https://github.com) has announced the **Dark Theme** for GitHub during the [Github Universe](https://githubuniverse.com).

Yes, finally the long awaited **Dark Mode** on GitHub is now available to paint your repositories and profiles Dark. 

Here's how you can enable this dark theme for your github. 

# Step 1: Log In to your Github Account
You can skip this step if you're already logged into your GitHub account on your system. If not [Login Here](https://github.com/login) using username and password.</br>
You will then be redirected to the home page of Github which will look something like this. 
![Github Home Page](https://dev-to-uploads.s3.amazonaws.com/i/462p3lg2wdz1daxinqhl.png)

# Step 2: Open Your Account Page
Once logged in, head over to the dropdown on top right just below your Profile Picture, and click on your username to head over to your profile main page. </br>
![dropdown](https://dev-to-uploads.s3.amazonaws.com/i/pps9ovuqy1328xhqd47k.png)</br>Ps. You will be redirected to this page. 
![profile page](https://dev-to-uploads.s3.amazonaws.com/i/o2ez8esgfaumfoxmraxd.png)

# Step 3: Toggle **Dark Mode**
On the Top Right corner, there can be seen a toggle which will _paint your repositories dark._ 
![Light mode](https://dev-to-uploads.s3.amazonaws.com/i/ivmafasmmtt201ky35l1.jpg)
**before toggling 👆🏻**
**after toggling 👇🏻**
![dark mode](https://dev-to-uploads.s3.amazonaws.com/i/juk09vviex50l0u6o42q.png)

#Enjoy the Dark Themed Github across all devices 🎉
![github profile](https://dev-to-uploads.s3.amazonaws.com/i/qst3htg25xxpq1r4ehll.jpg)
![repo](https://dev-to-uploads.s3.amazonaws.com/i/73s24zsj0yz4pnojqix4.png)
<hr>
Thank you for reading. Do Follow me on my other social media handles 👇🏻. 

~ Yuvraj.
[LinkedIn](https://linkedin.com/in/yuvraj-dagur) | [Twitter](https://twitter.com/@yuvrajdagur12)
[GitHub](https://github.com/thatfreakcoder) | [Medium](https://yuvraj-dagur.medium.com/)
Scrape ALL latest news on any company/person within 3 lines of Python code
Tags: webscraping, scraping, webdev, saas
Published: 2020-12-20 14:49:35

Step 1. Install [pygooglenews](https://github.com/kotartemiy/pygooglenews)

    $ pip install pygooglenews

Step 2. Three lines to get news data

````
from pygooglenews import GoogleNews

gn = GoogleNews(lang = 'en', country = 'US')

# latest news on Amazon that got published over the last hour
news = gn.search('Amazon', when = '1h')
```

## Why is it cool?
1. You get data from Google — the best search engine
2. pygooglenews hits RSS feed URL (not the UI URL). So, you don't get blocked by scraping Google

3. Google’s RSS can have up to 100 articles. But, Google allows you to specify that you want to see only the articles from the past hour.

Make such a request a few times an hour, and you will not miss a single news article that mentions your company/person of interest.
Advent of Code 2020: Python Solution Day 20
Tags: adventofcode, algorithms, programming, challenge
Published: 2020-12-20 14:46:44

This is the most hardest challenge and I again could not find solution by myself. So I had to cheat instead. And it is pretty known that today's challenge took nearly 20 minutes for fastest solution too. All the credit goes to the  [author](https://gist.github.com/tomKPZ/6932a5b8d9eaad13a9abbfc80ee8f928).

I will update his code to make it work on NumPy because it is more faster to do transpose and indexing than general list. I will update this blog soon.

```python
import math
import re


def transposed(tile):
    return list(''.join(row) for row in zip(*tile))


def reversed_tile(tile):
    return [''.join(reversed(row)) for row in tile]


def rotations(tile):
    ans = [tile]
    for _ in range(3):
        ans.append(reversed_tile(transposed(ans[-1])))
    return ans


def group(tile):
    return rotations(tile) + rotations(transposed(tile))


tiles = {}
for tile in open('day20.txt').read().split('\n\n'):
    lines = tile.strip().split('\n')
    tile_id = int(re.fullmatch(r'Tile (\d+):', lines[0]).group(1))
    rows = lines[1:]
    tiles[tile_id] = group(rows)

n = int(math.sqrt(len(tiles)))
arranged = [[0] * n for _ in range(n)]
stack = list(reversed(list((r, c) for c in range(n) for r in range(n))))


def solve():
    if not stack:
        print(arranged[0][0][0] * arranged[-1][0][0] * arranged[0][-1][0] *
              arranged[-1][-1][0])
        return True
    (r, c) = stack.pop()
    for tile_id in list(tiles):
        tile_group = tiles[tile_id]
        del tiles[tile_id]
        for tile in tile_group:
            if r > 0:
                if arranged[r - 1][c][1][-1] != tile[0]:
                    continue
            if c > 0:
                if list(row[-1] for row in arranged[r][c - 1][1]) != list(
                        row[0] for row in tile):
                    continue
            arranged[r][c] = (tile_id, tile)
            if solve():
                return True
        tiles[tile_id] = tile_group
    stack.append((r, c))


solve()


def remove_border(tile):
    return [row[1:-1] for row in tile[1:-1]]


board = [[remove_border(tile[1]) for tile in row] for row in arranged]
tile_n = len(board[0][0])


def get(r, c):
    return board[r // tile_n][c // tile_n][r % tile_n][c % tile_n]


board = [
    ''.join(get(r, c) for c in range(n * tile_n)) for r in range(n * tile_n)
]
for pattern in group(
    ['                  # ', '#    ##    ##    ###', ' #  #  #  #  #  #   ']):
    matches = 0
    for dr in range(len(board) - len(pattern) + 1):
        for dc in range(len(board[0]) - len(pattern[0]) + 1):
            matches += all(pattern[r][c] == ' ' or board[r + dr][c + dc] == '#'
                           for r in range(len(pattern))
                           for c in range(len(pattern[0])))
    if matches:
        print(''.join(board).count('#') -
              ''.join(pattern).count('#') * matches)
        break
```
Reactjs fetch API request getting blocked by CORS policy
Tags: react, javascript
Published: 2020-12-20 14:35:07

I am able to hit an sample endpoint via `fetch` and display the data in the UI. But for some endpoints, the request is `getting blocked by CORS policy`

I also tried to add `"proxy" : "endpoint_link"` in `package.json` and also tried to add `allow Access Origin in the headers section` but the issue still persists

[Here is the code which is working fine](https://codesandbox.io/s/tender-butterfly-js7if?file=/src/App.js)

This is the console log I am getting
```
Access to fetch at 'http://localhost:8000/header' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

```
**Please suggest how to overcome this during development as I have tried all possible ways.**
Another ordinary week
Tags: devjournal
Published: 2020-12-20 14:25:13

I'm not someone who is big on productivity tools but I usually keep a diary and jot down everything I want to achieve for that day first thing in the morning. I almost never get to cross off everything on that list but I am someone who is very forgetful and that list really gives my life some consistent direction. 

For some reason I thought it would be a good idea to leave my diary on campus. Maybe I thought, what the heck, its the holiday and I won't need it but boy was I wrong. I can't remember how I used to function without one. I guess it is just one of those situations where you don't really appreciate something until its gone. 

### The Coding Updates

Good news is that I made a breakthrough in my Java card game. I am currently building all the objects and methods that I think I will need to implement the game logic. If I have learned anything so far from building this program, its that object orientated programming is a powerful programming paradigm.

Since the card game that I am building is not a single player game, I will have to write code for the computer to make decisions so that you can play against it. I'm not entirely sure how to go about doing just that but I have some ideas, thanks to watching [this](https://www.youtube.com/watch?v=3nzupVMpZeA&t=10s) video about the minimax algorithm. If all else fails I'll probably throw in a bunch of if statements and call it a day.

The Web Development progress has been too slow for my liking. I've been busy restyling/designing some old codepens. I created them for the sole purpose of obtaining the certificate you get when you finish projects at the end of the course. I did the bare minimum, and it shows. To be fair, I had to juggle 4 modules of online learning at the time. Now I'm doing it properly in case I want to showcase it on my portfolio whenever I decided to continue that project. 

I wish I could show before and after pictures of some of my codepens because I honestly believe that a long way in terms of my CSS and designing abilities. I'm not artists but I make a decent website. My secret is `border-radius : 10px`. You're welcome :)

I have noticed that I have been struggling with designing form elements. I know you can create custom form elements using vanilla CSS but I've heard that it is not good for accessibility so I want to do it the hard way. Once I've learned to style form elements I want to go over media queries and animations because I always forget how to use them. That is where my focus will lie in the coming week. Alongside going over the basics of React by completing some beginner projects.

# Niche

I have started making friends using VSinder! VSinder is an app that was designed to be like Tinder for Coders but I use it just to make friends. It was created by ex-founder of VSCode stories [Ben Awad](https://www.youtube.com/channel/UC-8QAzbLcRglXeN_MY9blyw). His content is pure gold. If you get the chance, I encourage you to check his YouTube Channel.

That's it from me today, As always, stay safe, wash your hands and Happy Coding :computer:
Fight the pandemic during DO-Hackathon
Tags: dohackathon, javascript, react, digitalocean
Published: 2020-12-20 14:12:37

I had this little idea for some months already: Building a secure contact tracking / diary app to help prevent the COVID-19 spreading.

After reading the [Digital Ocean Hackathon announcement](https://dev.to/devteam/announcing-the-digitalocean-app-platform-hackathon-on-dev-2i1k) earlier this this month, I decided to sat down and execute on this project.

The idea is, you log with whom you had close contact. In case you get infected (and I hope you wont), you can warn your contacts, without forgetting one. Then they in turn can isolate and stop spreading the disease further. 🎉

Since security and data protection is very important, especially for health related apps, I decided to save the logged contacts on the users' devices. And I'm planning to go one step further: 
Reading {% link https://dev.to/voraciousdev/a-practical-guide-to-the-web-cryptography-api-4o8n %} and tinkering around with Web Crypto I was eager to use that somewhere. 🔐

That means, the logged contacts will be **stored encrypted locally** on users device, *not* sent in the cloud, or analyzed anywhere else. It also means, I won't need much of Digital Oceans app platform resources, only static hosting and DNS. Luckily, that's also part of their platform, so we're golden.

![First draft screen of the project: Some inputs to log with whom you had contacts](https://dev-to-uploads.s3.amazonaws.com/i/0xl8nahenmni7uhhxi7s.png)

Oh, and for the interested ones: There's already a working Proof of Concept available at [covtact.app](https://covtact.app). Don't get scared by the WIP UI, set a Encryption password and log ahead! It's all working as of now.
🚀🔥👍

And for the even more interested ones: {% github kriswep/covtacts no-readme %}

For feedback, comment down here and/or connect with me on [twitter](https://twitter.com/kriswep).
Building a personal website & blog with React, Gatsby, and styled-components
Tags: ux, react, gatsby, showdev
Published: 2020-12-20 13:50:18

I would have started this a long ago but I always Procrastinated things saying that "I make a great blog with great features and styling". But the thing is a blog with great styling but no content is of no use. So, I started making this blog with basic Figma designs I made and thought let's start and at least make something where people can read some content.

I have used React, gatsby, styled-components, graphQL & MDX for the blog which is super fast.
I have deployed it to Netlify. 

I am linking the GitHub repo which is public you can fork it and create your own personal site. 

Github Repo: https://github.com/rohanprasadofficial/react-gatsby-portfolio 

How it looks: https://www.rohanprasad.dev/


Do let me know in the comment sections, how does it look.
I have kept it minimal because I believe "less is more".

Do read the GitHub readme to understand how to use and build it. 

Please support by giving it a star, I have invested a lot of time thinking about the colors, design, and coding.  


#gatsby #styled-components #react #mdx #personal-site #blog-site #rohanprasad
Insert Update Delete In PHP On Same Page Using Ajax
Tags: programming, php
Published: 2020-12-20 13:28:17

We learn how to insert update delete in PHP on the same page. we will show you how to fetch insert update and delete data in PHP MySQL using Ajax. This time learn to insert delete update data using ajax in PHP.

In this example, we will use jQuery, ajax, MySQL, and Bootstrap with PHP to create insert update delete in PHP on one page.

This time Using jQuery and ajax insert, edit, and update delete data from MySQL database in PHP on the same page.

**[Insert Update Delete In PHP On Same Page Using Ajax](https://www.phpcodingstuff.com/blog/insert-update-delete-in-php-on-same-page-using-ajax.html)**
<!DOCTYPE html>
Tags: html, webdev, programming, javascript
Published: 2020-12-20 13:27:29

We will understand this code:


![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1608468769856/wDWC0S_mv.png)



- 
Technically this is **not a tag/element**, it just an **"Instruction"** to the browser about the document type. 



- 
We Call it **DTD** [Not a special move from your WWE character].




- 
It's know as **Document Type Declaration** [as name suggests it declare the document type].



- 
So, basically we are saying:
> 
 Hey browser, I am using a document that contain HTML and in this Document i have used all the new features of HTML version 5. So, at the time of rendering document don't say - I don't know about it, else i will beat the shit out of you.



Read More:

https://www.geeksforgeeks.org/html-doctypes/

https://www.w3schools.com/tags/tag_doctype.asp


**Connect**

- Twitter

https://twitter.com/NewGenDeveloper
Nginx caching tips
Tags: nginx, cache, tips
Published: 2020-12-20 13:04:49

## Performance tips

- **Put the cache on a dedicated SSD/NVME disk.** On an HDD, the performance hit caused by constant read/writes to disk of the cache manager will dwarf any caching benefits.
- **Don’t cache HTTP responses upon first hit.** Use `proxy_cache_min_uses 2;` to only cache items that have been accessed more than once. This way, you will alleviate the proxy cache’s write pressure and prevent your cache from filling up with content that’s seldom accessed.
- **Avoid unexpected backend traffic spikes caused by cache misses**:
    - Set `proxy_cache_lock on;` 
        - When there is a cache miss and multiple simultaneous requests hit the same URL, send a single request to your backend while the rest of the requests wait on the Nginx side. 
    - Add `proxy_cache_use_stale updating;` to your Nginx config.
        - This flag instructs Nginx to keep serving stale cache content to users while the cache is being refreshed.
- **Save bandwidth by refreshing your Nginx cache with conditional GET requests**, set `proxy_cache_revalidate on;` 
- **Cold start blues**: when you cold start an Nginx instance with a big existing cache on disk, wait a few minutes before you expose it to the public. Nginx needs to scan the entire cache to load its metadata into memory.

## Nginx proxy cache for Tomcat servers

Java web apps running on [Apache Tomcat](https://tomcat.apache.org/) always set a `JSESSIONID` cookie in the HTTP response, even if your web visitor is not logged into any account. To prevent session IDs from leaking into your Nginx cache, you need to filter out any `Set-Cookie` response headers returned by your backend.

```
proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
```

### How to bypass the cache for dynamic content and logged-in users

Your backend should set a `nocache` cookie in the HTTP responses for dynamic content. Then you include `proxy_cache_bypass $cookie_nocache;` in your Nginx configuration to bypass your Nginx cache for those requests.

## Nginx proxy cache for multilingual sites: use this cache key

The default Nginx caching key doesn’t work well with sites with multiple subdomains. You can customize your cache key by setting `proxy_cache_key`. This one has worked well for me:

```
proxy_cache_key $scheme$host$uri$is_args$args;
```

## How to purge cache items

If your Nginx runs on a Debian server, I highly recommend you install the `nginx-extras` package from the Debian repos, instead of the `nginx` package from the official repos. The `nginx-extras` package comes with the [`ngx_cache_purge`](https://github.com/nginx-modules/ngx_cache_purge) community module, whereas the `nginx` package from the official repos doesn’t.

(If you liked this, you might enjoy [6 Nginx configuration pitfalls that bit me in the ass](https://dev.to/braindumpk/5-nginx-pitfalls-that-bit-me-in-the-ass-and-how-you-can-avoid-them-1glp))