teleren/devto huggingface dataset:
Creating an Express Server using Node.js
Tags: javascript, node, express, servers
Published: 2022-12-02 19:03:45

### Overview

This article will show how to create and run a super simple Express server using Node.js within an Angular App.

### Setup

#### Create A Sandbox App

With the Angular CLI installed, run ```ng new```. This will ask for some options to initialize the angular app. Once the options have been supplied and the command has finished running, ```cd``` into the newly created app and open it into a code editor.

#### npm installs

These are the packages you'll need to install from npm:

- express
- express-session
- dotenv

#### Creating .env File

 In the root folder of the project, create a file named '.env'. Environment variables will be placed here and then called from the index.js file. This isn't necessary to create the server, but it is likely that more sensitive environment variables will be needed when creating endpoints and calling API's from the server. **It is also important that this file be added to the .gitignore file.**

The two environment variables needed are:

```.env
// .env

SERVER_PORT=<serverPortToRunOn>     
```

### Creating The Express Server

In the root folder of the project, create a new folder called "Server". Inside that folder create an "index.js" file. This is the file where the server will live and run from. In the index.js file add these lines of code:

```ts
// index.js

const express = require("express")
const app = express()
var session = require("express-session")
require("dotenv").config()
```

Now in index.js get access the variables that were created in the .env file,
    then add the code for the actual server:

```ts
// index.js

const { SERVER_PORT } = process.env;

app.listen(SERVER_PORT, () => {
    console.log(`Server listening on port: ${SERVER_PORT}`)
});
```

That's it! All that is left to do now is to run ```node server/index.js``` in the terminal from the root folder. If everything was done correctly, ```Server listening on port: 4000``` should display in the terminal.
Why I decided to become a developer
Tags: webdev, javascript, programming, react
Published: 2022-12-02 19:12:49

Deciding to become a developer can be a big decision. It requires a significant amount of time and effort to learn the necessary skills, and the field can be competitive. But for many people, the rewards of a career in development are well worth the effort.

**The Attractions of Becoming a Developer ✨**

One of the main attractions of becoming a developer is the potential for a high salary. Developers with a strong skill set can command high salaries, and the demand for their services is often strong. In addition to a high salary, developers also have the potential to work on a wide range of interesting projects. From developing the next big mobile app to creating complex software systems, the work of a developer can be challenging and rewarding.

**The Challenges of Becoming a Developer ⌚**

Another reason why people decide to become developers is the ability to create something from scratch. As a developer, you have the power to take an idea and turn it into a working piece of software. This creative aspect of development can be highly satisfying for those who enjoy the process of building something new.

**The Rewards of a Career in Development 🤑**

Of course, becoming a developer is not without its challenges. The field can be competitive, and it can take a significant amount of time and effort to learn the necessary skills. But for those who are willing to put in the work, a career in development can be highly rewarding.

Additionally, the field of development is constantly evolving, with new technologies and techniques emerging all the time. This means that as a developer, you will have the opportunity to continue learning and growing throughout your career. This can be especially appealing to those who enjoy staying up to date with the latest trends and techniques in their field.

**The Flexibility of a Career in Development ⌛**

Furthermore, a career in development can provide a high degree of flexibility and control over your work. Many developers work freelance or have the option to work remotely, which can provide a great deal of flexibility and the ability to work on your own schedule. This can be especially appealing to those who value work-life balance or who want to be able to work from anywhere in the world.

**Overall Benefits of Becoming a Developer 💪**

Overall, becoming a developer can be a rewarding and fulfilling career choice for those who are willing to put in the time and effort to learn the necessary skills. With the potential for a high salary, the ability to work on interesting projects, and the satisfaction of creating something new, a career in development can provide a wide range of benefits.
How To Use The 'Concat' RxJS Operator To Make Synchronous HTTP Calls
Tags: javascript, angular, rxjs, rxjsoperators
Published: 2022-12-02 19:11:07

### Overview

 Sometimes it is necessary to be able to make HTTP calls in a synchronous order. This can be difficult to do, but with the RxJS operator 'Concat', it is much simpler.

### Getting Into It

Open an Angular app to the component that needs to run the synchronous calls, or create a sandbox Angular app. Knowing what an observable is and how to create/use them is necessary to use Concat. If observables are a new concept, do some research about that first.

Open an Angular app to the component that needs to run the synchronous calls, or create a sandbox Angular app. Knowing what an observable is and how to create/use them is necessary to use Concat. If observables are a new concept, do some research about that first.

In the component that the synchronous calls need to be made create a array of the calls as observables, but don't subscribe to each observable. That should look something like the example below:

```ts
// app.component.ts

ngOnInit(): void {
  const calls = [
    this.fetchCharacter("1"),
    this.fetchCharacter("2"),
    this.postCharacter(),
    this.postCharacter(),
    this.postCharacter()
  ];

  concat(...calls).subscribe(
    res => console.log("next", res),
    err => console.log("error", err),
    () => console.log("complete")
  );
}

fetchCharacter(characterId: string): Observable<any> {
  return this.httpClient.get( "https://jsonplaceholder.typicode.com/todos/" + characterId );
}

postCharacter(): Observable<any> {
  return interval(3000).pipe(
    take(1),
    switchMap(() => {
      return this.httpClient.post("https://jsonplaceholder.typicode.com/todos", {} );
    })
  );
}
```

As you can see, the 'calls' array is created with five observables created by calling the fetchCharacter() and postCharacter() methods. The post Character method waits each time it is called, so there is a clear time lag between each time the method is called.

Once the calls array is created with the observables, spread that array into the concat method. When the concat method is subscribed to, each observable in the array passed into it will be subscribed to and execute in order. In the example above, you can see the characters logged to the console at set intervals. Then once all the observables have been executed, the finished message that is passed into the concat method as the final argument is executed.

### Wrap Up

This can be a very valuable RxJS operator to utilize. Often times having code execute asynchronously is preferred and can increase the speed of functions. But in instances where the code much be synchronous, concat is a great way to accomplish that.

For a live example of the above code, see [this StackBlitz](https://stackblitz.com/edit/angular-concat-post-demo?file=src/app/app.component.ts "Live StackBlitz example")
How a former Adobe engineer unlocks his team’s creativity
Tags: programming, productivity, management, techtalks
Published: 2022-12-02 19:05:18

{% youtube FKDwCgTSjWM %}

How do you get into the creative mindset for coding? 33 Teams CEO Drew McManus has some weird tips to unlock your coding creativity and get you into the proper mindset. Listen to the full podcast with Drew and Dev Interrupted host Dan Lines here ► https://www.youtube.com/watch?v=85e1KYPVEEM

### Want to cut code-review time by up to 40%? Add estimated review time to pull requests automatically!
*gitStream is the free dev tool from LinearB that eliminates the No. 1 bottleneck in your team’s workflow: pull requests and code reviews. After reviewing the work of 2,000 dev teams, LinearB’s engineers and data scientists found that pickup times and code review were lasting 4 to 5 days longer than they should be.* 

*The good news is that they found these delays could be eliminated largely by adding estimated review time to pull requests!*

### Learn more about how gitStream is making coding better [HERE](https://linearb.io/blog/why-estimated-review-time-improves-pull-requests-and-reduces-cycle-time/?utm_source=Substack%2FMedium%2FDev.to&utm_medium=referral&utm_campaign=gitStream%20-%20Referral%20-%20Distribution%20Footers).

![Start using gitstream today!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xg1l6hxt134px501bf7d.png)
What is the difference between flexbox and grid?
Tags: webdev, javascript, programming, css
Published: 2022-12-02 19:01:00

The main difference between flexbox and grid is the way they arrange items within a container. Flexbox is designed for laying out items in a single dimension, either in a row or a column. Grid, on the other hand, is designed for arranging items in two dimensions, in rows and columns.

**Here are some other key differences between flexbox and grid:**

- Flexbox is more suitable for smaller and simpler layouts, while grid is better suited for larger and more complex layouts.
- Flexbox works with the notion of flexible sizes, where items can grow or shrink to fill the available space. Grid, on the other hand, works with the notion of fixed sizes, where items are placed in a grid of fixed-size rows and columns.
- Flexbox uses properties such as `flex-direction`, `flex-wrap`, `justify-content`, and `align-items` to control the layout of items. Grid uses properties such as `grid-template-columns`, `grid-template-rows`, `grid-template-areas`, and `grid-gap` to control the layout of items.
- Overall, flexbox and grid are two different CSS layout modules that can be used to arrange items on a page. They have different strengths and weaknesses, and which one to use depends on the specific requirements of the layout you are trying to create.
ATOM (A Touch of Multiplatform) Episode #2
Tags: kotlin, mobile, programming, ios
Published: 2022-12-02 18:56:47

Welcome to [episode #2](https://www.youtube.com/watch?v=R2HAxIYhcBE) of **A Touch of Multiplatform (ATOM)**! This is our new podcast dedicated to Kotlin Multiplatform technology in production and produced for you by JetBrains and Touchlab. 
 
In this episode, we sit down to talk with Jake Wharton and Jesse Wilson from Cash App about “weird and ambitious multiplatform things.” Join us in a conversation that ranges from work set-ups and music choice while coding to the recent KMM Beta and writing better shared APIs for iOS consumers to unique projects Jake and Jesse are currently involved with.  
You can find full show notes on [Touchlab's blog](https://touchlab.co/a-touch-of-multiplatform-episode-2/).
Embedded Systems Weekly #129
Tags: embedded
Published: 2022-12-02 18:53:02

This week we exchanged around what could be the simplest definitions of hard, firm and soft real-time systems. Each of them definition can cover multiple pages, but at the highest-level what could be a one-liner summary? Here are my propositions:
- __Hard__: if any result is not produced within the deadline, the system is considered as failing
- __Firm__: if some results are not produced within the deadline, they are discarded and the system is still considered as operational
- __Soft__: results produced out of the deadline are all considered valid, and the system is always considered functional whatever are the delays
 
What do you think about them? Do you have alternative one-liner definitions for real-time systems that you find better? Please share them, email me!

**Happy reading!**

## Articles 
[Writing a Really Tiny RISC-V Emulator](https://youtu.be/YT5vB3UqU_E)
It's maybe the tiniest RISC-V emulator around. It is all in one unique function of ~400 lines, but it can run Linux and various executables on it. The [tiny C header-only risc-v emulator](https://github.com/cnlohr/mini-rv32ima) code is on Github with everything needed to make it run yourself. It's a really impressive work which deserves to be highlighted,

[Blue Pill: SysTick programming](https://medium.com/@csrohit/blue-pill-systick-programming-878dec0f1582)
It's a straight to the point tutorial on how to use the Cortex M3 24-bit system timer.

[Hacking your dishwasher, or cloudless Home Connect appliances](https://youtu.be/rhbLgg8mWxs)
A nice presentation where the speaker describes how he managed to reverse engineered Bosh-Siemens appliance communication protocol to be able to use them disconnected from the Internet.

[Peripheral Interaction Without a Linux Device Driver Using Spidev](https://www.embeddedrelated.com/showarticle/1485.php)
This article describes how sometimes it is not necessary to implement a kernel space module to drive a peripheral. A good example on how to use the [Linux kernel SPI userspace API](https://www.kernel.org/doc/html/latest/spi/spidev.html).

## Tools / Libraries
[WireViz, Easily document cables and wiring harnesses](https://github.com/formatc1702/WireViz)
WireViz is a little tool very handy to document your cabling and get beautiful visual from it.

## Jobs
[Intergalactic, Senior Embedded Software Engineer, 3172 Deseret Dr S, St. George, UT 84790, USA (Open to remote)](https://jobs.embedsysweekly.com/job/YGNWznb9/senior-embedded-software-engineer)
Intergalactic is a team of engineers, technologists, designers, mathematicians, and problem solvers committed to a singular idea: reviving the no-boundaries mentality in aerospace. We are a team of the nation’s best, regardless of where we live.

## Misc
[Taking a good picture of a PCB](https://blog.brixit.nl/taking-a-good-picture-from-a-pcb/)
We all need these advices, don’t we?
ERROR - PYTHON
Tags: python
Published: 2022-12-02 18:37:24

Hello, folks! Is everything ok ? 

My code is presenting a error could u, please help me about that error ? I´ll put a pic above ! Thank u so much 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ov1dxdiko1jwbpl2dze2.png)
Vivaldi
Tags: browsers, chromium, vivaldi
Published: 2022-12-02 18:33:14

I’ve been going back to G00gle Chrome for it’s Devtools too-often after switching to FF DE for my main dev browser. It makes me wonder if I should go back. 

[Vivaldi](https://vivaldi.com) to the rescue! It’s come a long way and is a Chromium-based browser. I'll be trying the switch this week!

It's super customizable!

![Screenshot of Vivaldi's Split Tab View](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibnaezlkao9i4w6eze65.png)

And this split-view thing is going to come in super-handy.
Advent of Code 2022 - Day 2
Published: 2022-12-02 18:25:30

---
title: Advent of Code 2022 - Day 2
published: true
description: I'm trying to solve all the Advent of Code puzzles in this video series.
tags:
cover_image: https://i.ytimg.com/vi/OoRyHjTvmIg/maxresdefault.jpg
---

{% youtube OoRyHjTvmIg %}

I'm trying to solve all the Advent of Code puzzles in this video series.
Advent of Code 2015 in Clojure
Tags: clojure, adventofcode
Published: 2022-12-02 18:20:53

Yes, you read that right; 2015.

I envy people who have the time to do these things as they happen but life seems to have a habit of getting in the way. I would describe my progress as "glacial".

But anyhoo, I thought I'd try completing each of the 2015 puzzles in Clojure as I'm learning it at present. I won't be marking spoilers as these puzzles are ~7 years old already and I'll likely just talk about solving them at a higher level than a blow by blow...

## The Setup

I'm just running VSCode and using the [calva](https://calva.io/) plugin so I can just directly run Clojure code within my IDE. There is a `deps.edn` file which just has a `{}` in it. Nothing special.

## Day One

### Part One

Essentially we're given a string of open and close bracket characters as "elevator instructions" where `(` means "go up a floor" and `)` means "go down". Our first task is simply to take a sequence of these chars and determine which floor our elevator ends up on.

So this is my solution for that first part:

```clojure

(defn eval-instr [floor instr]
  (+ floor ({\( 1 \) -1} instr)))

(defn eval-elevator [instructions]
  (reduce eval-instr 0 instructions))

(def puzzle-input (slurp "1.input"))

(comment
  (eval-elevator "(()))")
  (eval-elevator puzzle-input)
  )
```

A few notes:

* `eval-instr` takes a floor and an instruction, returning a new floor. Originally it was part of eval-elevator, but it's a little tidier this way.
* I liked doing the floor command mapping using a map. I like often defining these transformations as data.
* `eval-elevator` takes the instruction list and reduces it with the `eval-instr` to get the final floor number. I *always* have to look up the order of arguments for reduce :(
* `puzzle-input` is initialised with the contents of the file "1.input", which is our puzzle input. Every language I think should have a slurp command, did you know it can take a URL also?
* Finally, I put the tests into a `comment` tag so they're not evaluated unless I put my cursor over them in calva and press `ALT+ENTER`. A nice touch.
* It occurs to me that we could simply count the number of each bracket chars in our puzzle input to get an answer quicker! However as we see in part 2, it's actually useful to not do that yet. But I would have counted if I'd thought about it at the time!

## Part 2

The second part of this puzzle requires us to find the index of the first command to take the elevator below the zeroth floor. So we just want to step through our floors until we get to -1:

```clojure

(defn find-basement [instr]
  (loop [floor 0
         instr instr
         count 1]
    (let [next-floor (eval-instr floor (first instr))]
      (if (== next-floor -1)
        count
        (recur next-floor (rest instr) (inc count))))))
```
`loop` ... `recur` feels close to writing a loop in another language.

See you in a month when I get round to typing up the second day :|
Car Accident Tracker Software in Los Angeles
Tags: webdev, news
Published: 2022-12-02 18:15:48

LA LAX Group's team is almost finished with the software for calculating per hour and per day to give more accurate [car accident statistics in Los Angele's wider area](https://westcoasttriallawyers.com/california-car-accident-lawyer/tips-on-safe-driving/) where there are installed video cameras.
The intention is to be implemented this software all over California.
Parameters which aim the software are:
-number of car accidents
-how fast paramedics help in a given accident
-how to improve the system of better mobility to get to the crash scene
-how to [help victims legally](https://westcoasttriallawyers.com/) or medically
The area started to monitor and calculate 29 miles from downtown Los Angeles on 34.04105482922326, -118.24810612018071.
The goals to help with this software are to give accurate car accident statistics and help the victims and close relatives.
A vital side factor is giving you all info on the fly to get as much help as possible with measuring the GPS location data on the spot.
ColdFusion IsValid("regex") vs reFind() vs Java Regex Pattern
Published: 2022-12-02 18:04:25

I was recently notified of a slow ColdFusion script on a project and, after some isolation, determined that it was due to a regex-based UDF that we used in place of Adobe's built-in function (BIF) for isValid("url").  We used a regex rule with isValid("regex") to validate only HTTP/S URLs with valid hostname [TLDs](https://en.wikipedia.org/wiki/Top-level_domain) and the application was validating ~1,1000 strings from a database and taking ~1.5 seconds to perform.

Brad Wood recently blogged about [improving the performance of Lucee's QofQ](https://twitter.com/bdw429s/status/1598451972922920965) and he noted that "Adobe CF re-compiles the regex every single time". After reading that, I wondered if the same thing was happening with isValid("regex"). I'm not sure if it does or not, but if I had to guess, I'd say 'it depends'. CF2021 performance appears to be notably better than past performance, so it's possible.  I was more concerned with cross-platform performance on both Adobe ColdFusion and Lucee CFML platforms, comparing and determining the best/fastest approach.  I wrote a [Short, Self Contained, Correct (Compilable), Example (SSCCE)](http://www.sscce.org/) so I could compare multiple CFML engines using either [CommandBox](https://www.ortussolutions.com/products/commandbox) or [TryCF.com](https://www.trycf.com/).

As a result of using a cached java regex pattern, the webpage processing time when from the absurdly slow 1-2 seconds to a more efficient 150ms.

Here are some preliminary performance comparisons of [isValid("regex")]((https://cfdocs.org/isvalid)) versus [reFind()](https://cfdocs.org/refind) versus a cached [java regex pattern](https://www.javatpoint.com/java-regex).

## CFTry w/1,000 iterations (2022-12-02)

|Platform | isValid | reFind | Java|
|----|--------:|--------:|--------:|
|CF2021 | 146 | 167 | 10|
|CF2018 | 1,975 | 864 | 97|
|CF2016 | 2,520 | 2,484 | 38|
|Lucee | 3,530 | 176 | 31|

*What's interesting is that tests seemed to run faster after executing it a couple times on TryCF. The cached java pattern remained significantly faster in every test and Lucee's isValid() is much slower than using reFind.*

## CFTry w/1 iteration (2022-12-02)

|Platform | isValid | reFind | Java|
|----|--------:|--------:|--------:|
|CF2021 | 0 | 1 | 0|
|CF2018 | 2 | 1 | 0|
|CF2016 | 5 | 5 | 0|
|Lucee | 4 | 1 | 0|

## SSCCE Code

https://gist.github.com/JamoCA/e8c2ab5815bb26db58ff4024a86c533c

{% gist https://gist.github.com/JamoCA/e8c2ab5815bb26db58ff4024a86c533c %}
Entry-2: ByteArray conversion (React-native)
Tags: reactnative, snippets, java
Published: 2022-12-02 17:39:47

Tasked with building a chat client with the telegram API (Post coming soon), I encountered this issue wherein the byte array had to be converted to a base64 string to display a thumbnail.

After a couple of hours of research with no solution in sight of which I did not need aspirin for, the following solution below settled it.

```java
byte[] bytes = new byte[byteArray.size()];

for(inti = 0; i<byteArray.size(); i++){
    /*
     * In this context the values of the array is parsed as a string hence the method 'getString'.
     */
    bytes[i] = Byte.parseByte(byteArray.getString(i));
}
```

Example with a Base64Converter 


```java
public class FileToBase64 {

    public static String convertToBase64 (byte[] imageBytes){

        return Base64.encodeBase64String(imageBytes);

    }

}
```

Full code

```java
@ReactMethod
public void convertToBase64(Readable ArraybyteArray,Callback callback){
byte[] bytes =new byte[byteArray.size()];

for(inti = 0; i<byteArray.size(); i++){
        bytes[i] = Byte.parseByte(byteArray.getString(i));
    }

// Regular callback gotten from react native
// see - https://reactnative.dev/docs/native-modules-android#callbacks
    callback.invoke( FileToBase64.convertToBase64(bytes));

}
```

## TLDR

1. Send the byte to the native OS 
2. Convert and return to react-native.

PS: Do comment below if further explanation is required, I am happy to oblige!. 

Cheers (:


## External links

- **Twitter**: [@benny_wayn](https://twitter.com/etieno_u)
- **LinkedIn**: [Ibenge-uforo](https://www.linkedin.com/in/ibenge-uforo/)
- **Ongoing** **Research**: [Social Survey](https://docs.google.com/forms/d/e/1FAIpQLScKBo1VQvEVpvxKbOamhWq02uQU8HlgUPq576F-LD3yTljkwg/viewform)