teleren/devto huggingface dataset:
Chronal Calibration
Tags: adventofcode, algorithms, computerscience, programming
Published: 2022-07-13 17:04:20

## [Advent of Code 2018 Day 1](https://adventofcode.com/2018/day/1)

## Task: Solve for X where...
### Part 1
```
X = the resulting frequency - starting from 0 - after all of the changes in frequency have been applied
```
### Part 2
```
X = the first frequency my device reaches twice
```

## Example input
```
+1
-2
+3
+1
```

It represents:
- A series of frequency changes
- `+` is an increase in frequency
- `-` is a decrease in frequency

## Part 1
### The three amigos: `split()`, `map()`, `reduce()`
My proposed algorithm:
```
Generate an ordered list of numbers from the input
For each number
  Accumulate a sum - starting at 0
Return the sum
```

I'll use `split()`, `map()` and `reduce()` to make this a very simple task:
```js
input.split('\n').map(Number).reduce((a,c) => a + c)
```

It worked as anticipated, generating a correct answer!

## Part 2
### Round and around, seemingly forever
```
Set a list of frequency history, starting with one element: 0
Set frequency as 0
Set index as 0
Do as long as the last item in the list is not found elsewhere in the list
  If index is equal to the length of the list
    Reset index to 0
  Increment frequency by the number change at the current index in the list of frequency changes
  Insert the new frequency at the end of history
  Increment index by 1
Return the last item in the history list
```

This animation shows how my algorithm works:
![Algorithm for Part 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnwykjwf14h8opq2omox.gif)

It took over 30 seconds to run, but it generated the correct answer!

## I did it!!
- I solved both parts!
- I solved Part 1 using one concise line of code!

Bummers:
- My algorithm for Part 2 takes a long time to run...longer than I expected
- I'm not sure how I'd write a more performant algorithm to generate the correct answer in milliseconds instead of seconds

## Year in review
![2018 progress map](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/65ub985jorxnzwhrjsvs.png)
- I got 35 gold stars!
- I beat my low score by 1!
- I made 8 simulators! That's my lowest amount in a year thus far, but each one was a delight to make.
- This felt like the toughest year
- I still am frustrated that I didn't solve Day 24. It would have been fun to build that simulator.

## Four-year checkpoint
![Broader progress map](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wrsvnuxbdirv1xz6vg7f.png)
- 100 puzzles attempted thus far!
- Out of 200 stars possible, I've earned 143!
- That's nearly 75% of the stars!
- Not bad for someone like me who is not a trained Software Engineer, Computer Scientist or Programmer

Onward, to 2017!
Catch AWS Lambda Timeouts
Tags: aws, lambda, serverless
Published: 2022-07-13 17:02:37

[![cdk-lambda-timeout-eng](https://img.youtube.com/vi/9Oeu9ewrwXQ/0.jpg)](https://www.youtube.com/watch?v=9Oeu9ewrwXQ)
(Click me :D)

Ahoy,

AWS Lambda is probably one of the most famous if not the most famous compute service from AWS. In fact, Lambda is also my favorite AWS service because it makes implementing business logic very easy and straightforward. However, a few times I had the problem that the timeout of Lambda was too low and thus the code was not completely executed. Debugging or catching this error was also often exhausting and annoying. A good solution for me was to use the Lambda Duration Metrics to define an alarm.

```ts
import * as cw from 'aws-cdk-lib/aws-cloudwatch';
import * as lambdajs from 'aws-cdk-lib/aws-lambda-nodejs';
import * as sns from 'aws-cdk-lib/aws-sns';
import * as subscriptions from 'aws-cdk-lib/aws-sns-subscriptions';

const exampleLambda = new lambdajs.NodejsFunction(this, 'ExampleLambda', {
    timeout: core.Duration.seconds(10),
});

new timeoutAlarm - new cw.Alarm(this, 'TimeoutAlarm') {
    metric: exampleLambda.metricDuration({ statistic: 'max' }),
    threshold: exampleLambda.timeout?.toMilliseconds() ?? 1,
    evaluationPeriods: 1,
}

const topic = new sns.Topic(
    this,
    'ErrorTopic',
);
topic.addSubscription(
    new subscriptions.EmailSubscription('alice@bob.com')
);
timeoutAlarm.addAlarmAction(
    new actions.SnsAction(topic)
);
```

As you can see here, a simple Lambda JS Function is created at the beginning. By the way the [NodejsFunction construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.NodejsFunction.html) also supports TypeScript. Then the timeout alarm is defined which uses the duration metric and the timeout value from the Lambda to configure.

After that, an Error Topic is created via which the triggered alarm is forwarded by email using an EmailSubscription.

## Advantages

The advantage of this solution is that the Lambda code does not need to be modified and the problem is solved on infrastructure level or AWS CDK level. This solution can be applied to other Lambda languages like Python or Java as well.

## Conclusion

Lambda timeout caching is annoying. With a little AWS CDK code and the Lambda Duration metric, the problem is quickly solved.

I love to work on Open Source projects. A lot of my stuff you can already use on <https://github.com/mmuller88> . If you like my work there and my blog posts, please consider supporting me on:

[![Buy me a Ko-Fi](https://storage.ko-fi.com/cdn/useruploads/png_d554a01f-60f0-4969-94d1-7b69f3e28c2fcover.jpg?v=69a332f2-b808-4369-8ba3-dae0d1100dd4)](https://ko-fi.com/T6T1BR59W)

OR

[![Buy me a Ko-Fi](https://theastrologypodcast.com/wp-content/uploads/2015/06/become-my-patron-05.jpg)](https://www.patreon.com/bePatron?u=29010217)

And don't forget to visit my site

[![martinmueller.dev](https://martinmueller.dev/static/84caa5292a6d0c37c48ae280d04b5fa6/a7715/joint.jpg)](https://martinmueller.dev/resume)
Welcome Thread - v182
Tags: welcome
Published: 2022-07-13 16:41:53

---
title: Welcome Thread - v182
published: true
description: Welcome to DEV! A thread of hellos and intros.
tags: welcome
canonical_url: 
---

![the word "hi" waving hi!](https://media.giphy.com/media/MPxg9U887PS0B8XT4J/giphy.gif)

### Welcome to DEV!

1. Leave a comment below to introduce yourself! You can talk about what brought you here, what you're learning, or just a fun fact about yourself.

2. Reply to someone's comment, either with a question or just a hello. 👋 

**Great to have you in the community!**
How to Make a Charity Website Using Html CSS JavaScript
Tags: css, javascript, beginners, tutorial
Published: 2022-07-13 16:30:41

{% youtube 6Dj881BJ5kw %}

How to Make a Charity Website Using Html CSS JavaScript

This video will show you how to make a charity website using html css javascript.

[Live Website](https://codewithsadee.github.io/wildvine)
[Github Repo](https://github.com/codewithsadee/wildvine)

---

HI 👋
I'm Sadee (webdev)
In this channel I make videos about Complete Responsive website.
You can checkout my channel 👇

📺 My Channel : [codewithsadee](https://www.youtube.com/channel/UC1PZHWV6VvICTL1LgFUZq6g)
🔔 Subscribe : [subscribe now](https://www.youtube.com/channel/UC1PZHWV6VvICTL1LgFUZq6g?sub_confirmation=1)

---

🔗 Essential links
-----------------------------
[Starter file](https://drive.google.com/file/d/1-DQQ-8bgVJu1BA32zs9VrJMe7jUJN9dM/view?usp=sharing)

---

⏱️ Timestamps
-----------------------------
0:00 - Demo
5:20 - File structure
5:48 - Project initial
11:24 - Header
26:51 - Hero section
35:23 - Features section
39:19 - About section
50:26 - CTA section
53:42 - Service section
1:00:39 - Donate section
1:09:08 - Testimonials section
1:13:56 - Partner section
1:18:03 - Event section
1:25:45 - Instagram post section
1:31:36 - Footer
1:36:41 - Media queries

---

[![Buy Me A Coffee](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kn6vwn4mulhsx6o69is.png)](https://www.buymeacoffee.com/codewithsadee)
Jessie and friends. Introduction to Git for beginners.
Tags: git, books
Published: 2022-07-13 16:12:55

I recently wrote a short book aimed at people who are starting to learn Git. 

In that Book I tried to deviate from the standard approach, where each Git command (or group of commands) is described in a separate article and, for the most part, paraphrases the official documentation. 

Instead, I tried to create a story or adventure where the reader can help the main characters of the book (Jessie, Boopi and others) achieve their goals with the help of Git commands. I don't know how well I did, so I would like to ask you for feedback.

The book is divided into 16 chapters and covers the most basic interactions with Git: creating and modifying commits, creating and merging branches, as well as resolving merge conflicts, stashing files, reverting changes, and more.

If you don't know what a Git is yet, then this is the best time to get acquainted with it.

Here is [a link](https://github.com/enheit/jessie-and-friends) to the GitHub repository where you can find the download links in three formats: mobi, pdf and epub.

I hope you're having a good time with Jessie, yes, Jessie? 

Woof!
How to view localhost on your mobile phone
Tags: webdev, mobile, tutorial, debugging
Published: 2022-07-13 16:09:41

Nowadays, it's more important than ever to ensure that websites and web applications look and feel great both on a desktop and on a mobile device. While many tools have been created over the years to help aid in mobile-responsiveness, such as [Responsively](https://responsively.app/) and Chrome's built-in Inspect tool, sometimes it would make things a lot easier and smoother to just see your progress, live, from your phone, without having to deploy a work-in-progress. 

Fortunately, there is an easy way to view the same localhost you see in your browser, on your smartphone. 

**Prerequisite**: Your phone and your machine must be connected to the same wifi signal for this to work.

### Step One: run your local project on localhost
On your machine, get your app up and running in whatever way your particular project calls for, to get it projected to `localhost` in your browser. Make sure you have that localhost port open in a tab. 
![localhost in browser address bar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtpmsar3dx2nhhgea9ap.png)

### Step Two: Get your local IP address
Open up your terminal, and type in `ipconfig`. This will spit out a bunch of text, but you want to look for the line that says `IPv4 address`. 
![screenshot of terminal output for ipconfig](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/95gnqso5q9ru8900eetp.png)

Once you've located that address (it should look like 111.111.1.111, but with different numbers), enter it in your phone's mobile browser (Chrome, Safari, whatever) address bar, followed by the *port* you previously opened on your machine (localhost:3000 or 8000 or whatever it may be). So the final result will look something like this:

```
123.456.7.890:3000
```
 
As long as your localhost port is running and you entered the numbers accurately, your phone should now display the mobile view of your project. It should reload in sync with your desktop as you make changes and save. 

Congratulations! You now have a live view of what your project will look like on your particular mobile device, without having to use additional tools, install special software, or deploy a half-made app. While this method doesn't come with any special development tools, it does help ensure that some of the inconsistencies caused by viewing on "mobile" through other means can be eliminated.
Coding Day 48 of 100 complete.
Tags: webdev, beginners, programming, 100daysofcode
Published: 2022-07-13 15:57:38

Day 48 of 100 complete. Finished building the piano & learning about responsive web design. Got stuck on media queries in CSS. I swear my browser was messing with me. Now I have my 3rd big project building a technical documentation page.
Keywords and Expressions
Tags: java, beginners
Published: 2022-07-13 15:32:12


A keyword is a word that you can't use, it's a reserved word and just the JAVA language can use it. Is it confuse? Expressions are more easy to understand...

----------------

{% embed https://replit.com/@thiagocolen/Java-Programming-Masterclass-3-Keywords-and-Expressions#Main.java %}
GitHub Profilator - Add GitHub profiles to Markdown in a snap
Tags: github, deno, denodeploy, typescript
Published: 2022-07-13 15:30:17

## Intro
I just made public a Deno project on GitHub that tries to simplify the embed of (GitHub) profiles into markdown files by using just a Deno server (hosted on Deno Deploy) and a resulting SVG image of the wanted profile, like you can see for GitHub badges.

## An example
### This is how looks like a profile in Markdown
![Mardown Profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4giy7idugctxw6d38vxy.png)
### This is GitHub Profilator
![GitHub Profilator (Preview)](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e0imyovwd8bfrg4r8xo3.png)
Look how looks good! And also errors are good to see (visually) ;)
_(This is just a preview, because DEV.to does not support SVG uploads...)_

 
## How the SVG is built
For the first time (I'm not a designer and I never used this tool) I used Figma and exported the resulting SVG, then I manually modified the text (transforming it from SVG to `<text>` tag for easily template changes) and the image (using a data URL to embed on GitHub).
For all these, I wanted to use Handlebars but because Deno Deploy doesn't allow eval function (I discovered it with a Deploy crash) I decided to build my own (simple) template parser with the same `{{var_name}}` syntax of Handlebars (without all the Handlebars logic template, just to use vars).

## Looking for users and contributors
This project is in Alpha now and I'm looking for help developing and debugging.
If you want, you can find this project here:

https://github.com/Bellisario/profilator
https://profilator.deno.dev/
Kubernetes series (Part 2): Installing Kubernetes dependencies
Tags: kubernetes
Published: 2022-07-13 15:28:25

**Install Kubernetes**

**On Windows:**
Install Docker Desktop:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1v3ja1skxuum5gpulgs.png)
 
and then enable Kubernetes from settings


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjb5q05cn6o3w7ott1n1.png)

If you don't find kubernetes settings, switch to linux containers


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icdn4z7u9ob01mm7gjru.png)


If you have  Windows (10), install [minikube](https://github.com/kubernetes/minikube/releases/) & then install kubectl


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9awwfis6j405fnn91p3.png)

Tips for installing minikube:
    

- minikube defaults to installing the latest Kubernetes release, but you likely don't want that, since it's 6-12 months before many clouds and enterprise solutions update to recent versions. You can look up versions on GitHub, and install a specific version like this minikube start --kubernetes-version='1.17.4'

 - Unlike Docker Desktop, which lets you use localhost for your Kubernetes services, minikube runs in VirtualBox (by default) and has its own IP. Find that with minikube ip

- Remember top stop minikube when you're not using it to save resources minikube stop

- Check the status of what is running in minikube with minikube status
 

**On MacOs:**
Install Docker Desktop & enable kubernetes:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i2yrm1e925h6x3evbh02.png)

   



**For linux hosts and VM **

 install [MicroK8s](https://github.com/canonical/microk8s) or from [here](https://snapcraft.io/microk8s)

- Install [Kubectl](https://kubernetes.io/docs/tasks/tools/#install-kubectl-on-windows) if you are a Windows user

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i88rte0ye3ofva4qn4jp.png)

You have to add additional commands to enable core dns & kubectl which are generally done by Docker desktop on windows & macos

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5wvyhcnokq6drizmcexb.png)

Tips:

-  MicroK8s defaults to installing the latest Kubernetes release, but you likely don't want that, since it's 6-12 months before many clouds and enterprise solutions update to recent versions. You can look up versions on GitHub, and install a specific version like this `sudo snap install microk8s --classic --channel=1.17/stable`

- Before using it, you'll need to enable the CoreDNS pod so it'll resolve service DNS names later: `microk8s.enable dns`

- Check the status of what is running in MicroK8s with `microk8s.status`

You may also use this [website](https://labs.play-with-k8s.com/) to learn Kubernetes
Python exercise 22: ransomnote
Tags: beginners, python, leetcode
Published: 2022-07-13 15:25:36

## Question

- Given two strings `ransomNote` and `magazine`, 
	- return `true`
		- _if_ `ransomNote`_can be constructed 
		- by using the letters from_ `magazine` _and_ `false` _otherwise_.

- Each letter in `magazine` can only be used once in `ransomNote`.

## Example

- **Example 1:**

**Input:** ransomNote = "a", magazine = "b"
**Output:** false

- **Example 2:**

**Input:** ransomNote = "aa", magazine = "ab"
**Output:** false

- **Example 3:**

**Input:** ransomNote = "aa", magazine = "aab"
**Output:** true
- **Constraints:**
-   `1 <= ransomNote.length, magazine.length <= 105`
-   `ransomNote` and `magazine` consist of lowercase English letters.

## My Solution

- algorithm

```
>>determine if ransomNote can be constructed from magzine
  set lengthr to length of ransomNote
  set lengthm to length of magzine
  if lengthr>lengthm:
	  return false
  else:
	  for each char in ransomnote:
		  if char appear in magazine:
			  remove char in ransomenote
			  remove char in magazine
			  if lengthr equal to 0:
				  return True
	  else:
		return False
```
- key point

	- need to split the question into case in terms of the difference between two string
	- if length of ransomNote greater than length of magzine
		- there is no way magzine have enough word to construct to the ransomNote
- code

```python
class Solution:  
    def canConstruct(self,ransomNote: str, magazine: str) -> bool:  
        lenngthr = len(ransomNote)  
        lenngthm = len(magazine)  
        if lenngthr>lenngthm:  
            return  False
        # lenngthr<=lenngthm  
        else:  
            for char in ransomNote:  
                if char in magazine:
	                # remove that char from both string  
                    magazine=magazine.replace(char,"",1)  
                    ransomNote=ransomNote.replace(char,"",1)
                    # This mean the whole string can be found on magzine  
                    if len(ransomNote) == 0:  
                        return True  
            # if ransomNote has not reduce to an empty string
            else:  
                return False

```

## Other solution

```python
class Solution:  
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:  
        magazine_dict = {}
        # constuct a dict with uniques as key and its occurance as value  
        for char in magazine:  
            if char not in magazine_dict:  
                magazine_dict[char] = 1  
            else:  
                magazine_dict[char] += 1  
        for char in ransomNote:  
            if char not in magazine_dict or magazine_dict[char] == 0:  
                return False  
            else:  
                magazine_dict[char] -= 1
        # all char checked to be found on magazine_dict  
        return True
```
## My reflection
- I learn from others that when checking one group is belong to other group, use dictionary is faster.
- I do not understand why the solution should construct  within a class but not a separate function.

## Credit
challenge find on [leet code 383](https://leetcode.com/problems/ransom-note/)
[RANT] Why the hell does everything cool in JavaScript have to be locked behind needing server?
Tags: javascript, webdev, rant, watercooler
Published: 2022-07-13 15:10:49

I wanted to do some messing around with sharing data between HTML files, and the only effective way to do that is by using search parameters which isn't exactly always ideal.  
You can't store cookies in `file://`. (You can, but it doesn't work on any forks of [Chromium](https://www.chromium.org/chromium-projects/), the most common/popular kind of browsers, without setting a flag from the terminal.)

You can't even use [`localStorage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) either.
Why not? Because it only works on a per-domain basis and Chrome treats each file as its own domain. 😩  
Not only is there this downside of not being able to share data across pages, you can't even read local files relative to the folder the HTML file is in, you need a server for that.

I'm so fucking frustrated that a lot of the more useful/complex features of JS require a "server" of some kind. It makes no damn sense.
Luos Hardware Abstraction Layer
Tags: luos, opensource, embedded, microcontrollers
Published: 2022-07-13 15:20:00

Luos engine can work on a single node using localhost #communication or it can create a network for communication between services located on different nodes. This communication must be defined and hardware-configured to fit the chosen #MCU.

⏩ https://www.luos.io/docs/luos-technology/node/luos-hal

Let’s talk about the Luos Hardware Abstraction Layer. #opensource
Conway's Game Of Life
Tags: javascript, programming, codenewbie
Published: 2022-07-13 15:17:41

> The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970 

>  Wikipedia

Basically it runs on just two rules :-

- Cell with less than two or more than three neighbours dies

- Cell with two or three neighbours survives to next generation


Here's a neat working **[Life](https://prajyu.github.io/Conway-Simulator/index.html)**

! Made this just for small screens.

If the page is not working try cloning the repo and running it locally [GITHUB](https://github.com/prajyu/Conway-Simulator)
Upload images with Cloudinary, MongoDB and Express.
Published: 2022-07-13 15:04:55

We will have to create a **middleware** that uploads an image to cloudinary and returns it's image url


 Create an account in cloudinary and choose **programmable media**.

Now go back to editor and create 3 variables in dotev file with these informations: CLOUD_NAME, API_KEY, API_SECRET. 
You get that from cloudinary dashboard.

![cloudinary connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4mflk1t07u476mvw5ha.png)
 
 Create a folder 'utils' with a 'cloudinary.js' file.

![cloudinary.js code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0y0qwgdicad4f50vve2g.png)

Create a 'controller' folder with a 'cloudinaryMiddleware.js' file.


![middleware code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu5b6si6ua86c29fb41s.png)
Now you just have to import and place it in your **REST API** like this:

![rest api code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ytxwtn9gbkvx7ifxzfp.png)