teleren/devto huggingface dataset:
Starchart: Seeding
Tags: webdev, opensource, prisma, typescript
Published: 2023-02-10 20:22:59

This week, my main focus is to work on seeding the database for Starchart project. (see [PR](https://github.com/Seneca-CDOT/starchart/pull/160))
I thought it would be more complicated, but it's actually just writing [query with Prisma](https://www.prisma.io/docs/concepts/components/prisma-client/crud) to insert rows of data into database tables, and there's a bit of script setup.

## Setup [(official documentation)](https://www.prisma.io/docs/guides/database/seed-database)
**Requirement:**
Make sure you have Prisma [setup](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch) already. You need to first have a `pakcage.json` generated from `npm init` too.

1. Inside `pakcage.json`, add the following:
    ```
    "prisma": {
        "seed": "ts-node prisma/seed.ts"
    }
    ```
    If your project needs to use compile option, you should use     this instead:
    ```
    "prisma": { 
         "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts" 
    }, 
    ```
2. Add `seed.ts` under `prisma` folder.
3. Add code for ["create" query](https://www.prisma.io/docs/getting-started/setup-prisma/start-from-scratch/relational-databases/querying-the-database-typescript-postgres#write-data-into-the-database) inside the file to add rows of data. 
4. Run `npx prisma db seed`.


There! If the steps are done correctly, you just seeded the database with some data for testing or whatever you need to do!

## Experience
I realized there are a few things to consider as I worked on this. 
You need to thing about cleaning existing data. Because there are some foreign keys in the schema, I need to think about the order I delete data from each table. Otherwise, it can run into errors. It would be easier if one sets up [cascading delete](https://www.prisma.io/docs/concepts/components/prisma-schema/relations/referential-actions#:~:text=adding%20onDelete%3A%20Cascade), where a row is automatically deleted if the referenced row (usually from another table) for the row's foreign key is deleted.
Because of the foreign keys, another thing to consider is to create things in the correct order, so there's something to be referenced before referencing it.
Lastly, it would be intuitive to let index auto-increment and make index the thing to be referenced for foreign keys. However, doing both would present a problem when you are doing seeding. The referenced value need to stay consistent so that you can properly connect one row to a specific row. Therefore, you actually need to specify the index in such scenario, such as the `id` here:

![an example of specifying the index](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pet3kva18ndg80feuakp.png)
Reblog: Javascript Dev Heart Message
Tags: tutorial, beginners
Published: 2023-02-10 20:05:24

This is a repost from last year. I'm working on updating the project but won't have a blog post ready before the weekend. So here's your reminder Valentines day is next Tuesday. 

 Remember those Valentine's Candy Conversation hearts? For this project I'm recreating them using vanilla JavaScript and CSS. 
## Draw a heart 

If we're going to write on a heart we need to build the heart first. This is made with some basic shapes, a square and two circles. To make a CSS Circle you make a square and give it a border radius of 50%. 

I added borders so you can see the individual shapes.


![A heart made to two overlapping circles on a square that rotated 45 degrees.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9j8fe71imd5oabefy3re.jpg)


Once the shapes are made use `transform: rotate(45deg)` to turn the heart so the point is straight down. I added a drop shadow to make the heart standout from the background.
 

![a heart.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x4t255tb3zqzmjjfxcqf.jpg)


## Javascript Messages

Next we need a list of messages. Here's some of the messages used for the project. I didn't them list all to save some space.

```Javascript
var messages = [
	"Will you be my variable? ",
	"Be the Fizz to my buzz! ",
	"This ♥",
	"Stickers!",
	"if ( (you + date) < 2) {  </br>   call (me) } ",
	"You\”: \“My heart\" ",
	"I will always write tests",
	"git commit -m \":heart:\" ",
	"01101000 01100101 01100001 <br> 01110010 01110100"
]

```

Next we need a function to pull a random message from the list and put it in the heart Id div that is on top of the Bigheart, the CSS heart.

```javascript
function sweetHeartMsg() {
	var randomNumber = Math.floor(Math.random() * (messages.length));
	document.getElementById('heart').innerHTML = messages[randomNumber];
	heart.style.display = "block";	
}
```
The function is activated by clicking a button.

```HTML
	<div class="login-screen" >
		<h1>"Hello World"</h1>
		Click the button for .random(♥) candy heart message.
                <input type="submit" value="Dev Hearts." class="btn btn-primary btn-large btn-block" id="submit" onclick="sweetHeartMsg();">
	</div>
```
That puts the message on the heart.



![screen shot: A heart next to text that reads "click button for message." On the heart it says "I will always read the docs."](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjg2m2c5a76jr7wvqpng.jpg)


## Wrap up
This was a good exercise if I make a version 2 I'll allow users to enter their own messages to display on the heart. I would also like to thank my friends, Meg and Julia  at VirtualCoffee for helping with message suggestions.
Heart shape inspired by [this post](https://www.hongkiat.com/blog/css-heart-shape/)
TIL 2
Published: 2023-02-10 19:45:57

Difference between .method vs .method! - "!" modifies the object so we can't reference the original object. The "safe method" creates a copy of the object and changes that copy.

.split takes a string and returns an array. Cool!

To access a two-dimensional array we need to use double square brackets => array[1][5]



Ruby seems so easy, yet so complicated at the same time.
Versioning in REST APIs
Tags: rest, api
Published: 2023-02-01 03:08:06

Versioning is the process of maintaining multiple versions of an API over time as the API evolves and changes. This is a critical aspect of REST API design, as it allows API consumers to continue using the API even as it changes without breaking existing client applications.

There are many reasons why API designers might choose to version an API, including:

- **Adding new features:** API designers may choose to version an API in order to add new features without breaking existing client applications that rely on the API.
- **Removing features:** API designers may use version an API to avoid breaking existing client applications that rely on the API when they have to remove the features that are no longer needed.
- **Making breaking changes:** API designers may choose to version an API to make breaking changes to the API without breaking existing client applications that rely on the API.

Versioning in REST APIs can be done in a variety of ways, including:

**URI Versioning:** This approach involves including the version number in the URI of the API, such as /api/v1/users. This makes it easy for clients to understand which version of the API they are using, but it can result in lengthy and complex URIs.

**Custom Header Versioning:** This approach involves using a custom header, such as X-API-Version, to specify the version of the API that the client would like to use. This approach makes it easy to version the API without changing the URI, but it can be difficult for clients to understand and use.

**Media Type Versioning:** This approach involves using the response's media type to specify the API version that the client would like to use. For example, a client might request a resource in JSON format by sending the following request:

```bash
GET /users/1 HTTP/1.1
Accept: application/vnd.api+json;version=1
```

The benefits of versioning in REST APIs include the following:

- **Compatibility:** Versioning allows API designers to maintain backward compatibility with client applications, even as the API changes over time.
- **Evolution:** Versioning allows API designers to evolve the API over time without breaking existing client applications.
- **Flexibility:** Versioning allows API consumers to choose the version of the API that they would like to use, which can be especially important in large organizations with many client applications.

In conclusion, versioning is a critical aspect of REST API design, as it allows API designers to maintain backward compatibility with client applications, even as the API changes over time. By embracing versioning, REST APIs can provide a better user experience for API consumers and make it easier for API designers to build, maintain, and evolve the API over time.
TIL The founder of the world’s fastest unicorn found his previous business partner on Craigslist
Tags: management, career, startup, todayilearned
Published: 2023-02-10 19:23:59

{% youtube 9YO2jDMPgU0 %}

Work partners can come from a variety of unexpected places, and in Drata CTO & Co-Founder Daniel Marashlian's case, he found his co-founder on Craigslist. Join Dan Lines and Daniel as they talk about the opportunities you can find in seemingly strange places in this episode of Dev Interrupted. Listen to the full episode here: https://www.youtube.com/watch?v=K_ce_YmtJUw

### [On Feb. 15th, learn how the smartest engineers increased productivity by up to 30% without working longer hours or burning out their teams](https://linearb.io/event/202302-scaling-dev-efficiency/?utm_source=Substack%2FMedium%2FDev.to&utm_medium=referral&utm_campaign=202302%20-%20Event%20-%20GTM%20-%20Referral%20-%20Distro%20-%20Podcast%20Blog)

Every engineering team could use some easy wins right now, including yours. We’re talking quick ways to improve productivity without wasting more hours at work, spending a lot of money or burning out already-stretched teams.

That’s why LinearB teamed up with dozens of engineering orgs to crowdsource the real ways smart companies have improved their productivity - quickly and most importantly, easily.

On February 15th, LinearB will be presenting this playbook at [our free, virtual Scaling Developer Efficiency workshop.](https://linearb.io/event/202302-scaling-dev-efficiency/?utm_source=Substack%2FMedium%2FDev.to&utm_medium=referral&utm_campaign=202302%20-%20Event%20-%20GTM%20-%20Referral%20-%20Distro%20-%20Podcast%20Blog)

Designed to help you gain up to 30% increased productivity, this free online workshop will empower your team with strategies and solutions that let them focus on what they do best: Code.

### [Reserve Your Virtual Seat](https://linearb.io/event/202302-scaling-dev-efficiency/?utm_source=Substack%2FMedium%2FDev.to&utm_medium=referral&utm_campaign=202302%20-%20Event%20-%20GTM%20-%20Referral%20-%20Distro%20-%20Podcast%20Blog)

![Reserve a seat today](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpvy5uftb01p2nwia2zl.png)
What is Blockchain?
Published: 2023-02-10 19:23:18

According to Wikipedia “**A blockchain is a distributed ledger with growing lists of records (*blocks*) that are securely linked together via cryptographic hashes.**” In other words, it is a list of transactions and each bundle of transactions are linked to the previous block.

![Blockchain](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/47xmhfjfc9x6z4ad63mp.jpg)

Blockchain is DLT (Distributed Ledger Technology) which is immutable and distributed in nature, it stores and replicated the data in each node. To understand the Blockchain we should first understand some words.

* Immutability
    
* Distribution
    
* Ledger
    
* Node
    

## Terminology

Let us see this word and what it means.

### Immutability

Immutability means once you have written on a blockchain it can't be deleted how much you try. It is impossible to erase data from a blockchain. So, it is considered the safest data storage. In a web2 database system, we have access to the data, we can create, modify or delete the data but in blockchain, we can only add and modify data. In web2, we need to trust the authorities and hope they don't delete or modify our data without our permission, but in blockchain, we don't need to trust others to handle our data, as no third person is involved.

### Distribution

In Blockchain the data Is replicated and distributed to every node or host or peer, we can trust the data if most of the node is working correctly or in a valid state if a node is misbehaving the node goes to an invalid state and the node is kicked out from the network. Each node has the whole ledger or blockchain in its local storage this guarantees high availability and security as the data is easily verifiable and accessible.

![Distribution](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x1u937r2df67cyfu2kec.jpg)

### Ledger

Ledger is a list of transactions recorded with a time stamp and stored in a block and each block is connected to the previous block, the first block or the head block does not have a previous block so its previous block is **NULL.** The first block is called **Genesis Block**, You can check the first block of any blockchain in [etherscan.io](https://etherscan.io)

![Ledger](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mljpcf4oh4jylz6t72hr.jpg)

### Node ( Host or Peer)

Node is the host, server, or computer in which the blockchain program runs. Think of it as a virtual machine that runs on another OS but it allocates its own resource. Each node has a copy of the blockchain in the host. Anyone can run a node if he or she has the required configuration device. By running a node anyone can earn blockchain cryptocurrencies which can be used as money in that ecosystem.

## What's on the next article?

In the next article, we will see the blockchain structure and how it works, so make sure to subscribe to the newsletter and follow me on Twitter.
What was your win this week?
Tags: discuss, weeklyretro
Published: 2023-02-10 19:20:39

Hey folks!

Hope y'all all enjoy your weekends! 😎

Looking back on this past week, what was something you were proud of accomplishing?

All wins count — big or small 🎉

Examples of 'wins' include:

- Starting a new project
- Fixing a tricky bug
- Taking a staycation 🏡

---

![A clip from the Simpsons of Homer and Marge dancing in a car with food in their hands.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttuqpaazxpt62lacq3sw.gif)
Challenge #3: 🎲 Dice Game
Tags: web3, blockchain, solidity, javascript
Published: 2023-02-10 19:19:19

## Tasks to be done

💬 Dice Game is a contract that allows users to roll the dice to try and win the prize.  If players roll either a 0, 1, or 2 they will win the current prize amount.  The initial prize is 10% of the contract's balance, which starts out at .05 Eth.  

🧤 Every time a player rolls the dice, they are required to send .002 Eth.  40 percent of this value is added to the current prize amount while the other 60 percent stays in the contract to fund future prizes.  Once a prize is won, the new prize amount is set to 10% of the total balance of the DiceGame contract.  

🧨 Your job is to attack the Dice Game contract!  You will create a new contract that will predict the randomness ahead of time and only roll the dice when you're guaranteed to be a winner!

## My Review

This was a fairly simple challenge where we just had to copy the dice roll calculation logic from the main contract and make sure that the function is only called if the user is about to win! VRF (verifiable random function) are something new that I got to learn about ✨ Looking forward to randomness someaday being build into the ethereum protocol ✊

## Important links

- [Speed Run Ethereum](https://speedrunethereum.com/challenge/dice-game)
- [Deployed webapp](https://kevinj-sre-c3.surge.sh/)
- [Deployed contract](https://goerli.etherscan.io/address/0x8b14c651DA326b42cFaCcA96b48507109E57173A)
- [Project source code](https://github.com/kevinjoshi46b/speedrunethereum/tree/master/challenge-3-dice-game)
9. Palindrome Number
Published: 2023-02-10 19:15:39

# Question

Read the Question here [Click Here](https://leetcode.com/problems/palindrome-number/)

```bash
Input: x = 121
Output: true
Explanation: 121 reads as 121 from left to right and from right to left.
```

# Answer

```cpp
class Solution {
public:
    bool isPalindrome(int x) {
        int oldNum=x;
        int newNum=0;
        while(0<x){
            int temp=x%10;
            newNum=newNum*10+temp;
            x=x/10;
        }
        if (oldNum==newNum){
            return true;
        }
        else{
            return false;
        } 
    }
};
```

Here we will reverse the number and check that the given number is equal to the new number. First, we need to store the old number in a variable as the variable `x` will be 0 at last, so we are using `oldNum` it as a variable to remember our given number. The variable `newNum` is where our reverse number will be stored.

Now we will use a `while` loop and check if the x is greater than 0 and run it till the x become 0. The variable `temp` store the last number of the x, eg., given the number 121 then 121%10=1, 1 is stored in the `temp` . After we get the temp then we move to the next line, here we are multiplying the `newNum` with 10 and adding the last number which we stored in temp eg., `newNum` = 0\*10+1 -&gt; `newNum` = 1 and then we will remove the last number from the `x` by dividing `x` by 10. This loop continues till the x become 0.

Till this point new will get our reverse number which is stored in, now we just need to compare this with the `oldNum`, if the number is the same then return true or else false.

```bash
Input : 121

x = 121
oldNum = 121
newNum = 0
Check if x is greater than 0 (0<121) ✅
    temp = x % 10 = 1 
    newNum = (newNum * 10) + temp = (0*10) + 1 = 0 + 1 = 1
    x = x / 10 = 121 / 10 = 12

x = 12
oldNum = 121
newNum = 1
Check if x is greater than 0 (0<12) ✅
    temp = x % 10 = 12 % 10 = 2
    newNum = (newNum * 10) + temp = (1*10) + 2 = 10 + 2 = 12
     x = x / 10 = 12 / 10 = 1

x = 1
oldNum = 121
newNum = 12
Check if x is greater than 0 (0<1) ✅
    temp = x % 10 = 1 % 10 = 1
    newNum = (newNum * 10) + temp = (12*10) + 1 = 120 + 1 = 121
    x = x / 10 = 1 / 10 = 0

x = 0
oldNum = 121
newNum = 121
Check if x is greater than 0 (0<0) ❌

check if oldNum is equal to newNum (121 == 121) ✅
    return true
```
Strategic IT planning and evaluation - part 1
Tags: it, aws, cloud, cost
Published: 2023-02-10 19:02:24

## What we’ll cover

- How IT strategic planning  is changing
- Continuous IT planning  and evaluation
- Using economic metrics to plan  for and evaluate IT spend

## What we’re hearing

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

## The cycle of strategic IT planning


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

## Planning for different types of workloads


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


## Our process for planning migrations


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

## Migration Evaluator

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

## Migration Evaluator: What it delivers


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

## Planning for cloud-native workloads


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

## AWS Pricing Calculator

**Service pricing pages**

- Prebuilt examples with cost included
- Additional cost considerations

**AWS Pricing Calculator**

- 110+ support services  (as of October 2021)
- Estimate AWS support costs
- Export to .csv
- Save estimate (three years) and share
- via public link



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



## Proof of concept and actual data



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnpp2ttqk5t2hl82puyc.png)
Responsive <video />: finally, a solution!
Tags: html, css, webdev
Published: 2023-02-10 18:53:58

On a fine winter's evening, much pain was felt undertaking a treacherous endeavour of fitting a video element inside its parent.

After failed ventures seeking answers from the World Wide Web, and sounding many explicatives to the browser, good old blindly-led trial-and-error saves the day once again.

### ENTER, THE CODE...

> This works for a parent with dynamic or explicit sizing, I'm using it within a CSS grid cell.

Style your `<video />` with this CSS and smile 😄

```css
video {
  height: 0;
  width: 0;
  min-height: 100%;
  min-width: 100%;
}
```

{% codepen https://codepen.io/james2mid/pen/PoBMZLj %}

I was amazed that none of the answers I found out there solved this seemingly trivial challenge. I didn't want anybody else to experience such meaningless pain, so here you go.

You're welcome 🙇‍♂️
Menu & Toolbar
Published: 2023-02-10 18:53:14

## Android Toolbar Adding Menu Items for different fragments

> Activity

```kotlin
        // Add menu items without overriding methods in the Activity
        addMenuProvider(object : MenuProvider {
            override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
                // Add menu items here
                menuInflater.inflate(R.menu.options_menu, menu)
            }

            override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
                // Handle the menu selection
                return true
            }
        })
```
> Fragment

```kotlin
        val menuHost: MenuHost = requireActivity()

        menuHost.addMenuProvider(object : MenuProvider {
            override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
                // Add menu items here
                menuInflater.inflate(R.menu.recyclerviw_menu, menu)
            }

            override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
                // Handle the menu selection
                return true
            }
        }, viewLifecycleOwner, Lifecycle.State.RESUMED)
```

- [Ref](https://developer.android.com/jetpack/androidx/releases/activity#1.4.0-alpha01)


[hide-toolbar-in-specific-fragment](https://stackoverflow.com/questions/29128162/android-hide-toolbar-in-specific-fragment)