teleren/devto huggingface dataset:
map: a JavaScript Iterator
Published: 2023-01-12 17:46:40

Last time, we started a series on Javascript Iterators. We will now continue with the next iterator, the map. If you missed the first topic in this series, here is a link to read through https://dev.to/michellebuchiokonicha/javascript-higher-order-function-3jeh

A map creates a new array from the existing array. This is unlike the forEach iterator returns undefined. When mapping an element, you do not need to push elements into a new array as a map creates a new array automatically after calling the function. Similar to the forEach, the first parameter to a map iterator is a callback function and the callback function can have a maximum is three parameters. The value of the array currently being called, the index of the array currently being called, and the array itself currently being called.

Let us use the same example we used in the forEach series and solve it using the map iterator.

Write a function that returns a new array with all its values increased by ten.

Function increasedByTen(ten) { ten.map(function(val){ return val + 10 }); } If the value of ten = [2,4,6,8,10] increasedArray = [12,14,16,18,20].

You can also create a new map object using the new Map() method. Here is an example:

var twenty = new Map([ ["twentyone", 21], ["twentyTwo", 22], ["twentyFour", 24] ]); You can use the get() method to get the value for the key in the map created.

Another map method is the set() method which sets the value for the key in the new Map

var twenty = new Map(); twenty.set("twentyone", 21); twenty.set("twentyTwo", 22); twenty.set("twentyFour", 24);

other map methods like the delete(), has() and more can also be used.

When mapping as an arrow function, it looks like this: map((element) => { /* … */ })

When mapping as a callback function, it looks like this: map(callbackFn)

When mapping as an inline callback function, it looks like this: map(function (element) { /* … */ })

They all get the same results the difference is the syntax you choose which does not change anything.

Next, we will talk about the filter iterator.

My Twitter Handle: https://twitter.com/mchelleOkonicha

My LinkedIn Handle: https://www.linkedin.com/in/buchi-michelle-okonicha-0a3b2b194/
17. Letter Combinations of a Phone Number
Tags: java, algorithms, leetcode, 100daysofcode
Published: 2023-01-12 17:39:29

**Problem Statement:**

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order.

A mapping of digits to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.


 

**Example 1:**
**Input:** digits = "23"
**Output:** ["ad","ae","af","bd","be","bf","cd","ce","cf"]

**Example 2:**
**Input:** digits = ""
**Output:** []

**Example 3:**
**Input:** digits = "2"
**Output:** ["a","b","c"]
 

**Constraints:**
- 0 <= digits.length <= 4
- digits[i] is a digit in the range ['2', '9'].

**Solution:**

**Algorithm:**
1. Use a queue to store the current combination of letters.
2. For each digit in the input string, pop the current combination from the queue, and append each letter to the combination.
3. Push the new combination to the queue.
4. Repeat step 2 and 3 until all digits are processed.

**Code:**
```
public class Solution {
    final char[][] L = { {}, {}, { 'a', 'b', 'c' }, { 'd', 'e', 'f' }, { 'g', 'h', 'i' }, { 'j', 'k', 'l' },
            { 'm', 'n', 'o' }, { 'p', 'q', 'r', 's' }, { 't', 'u', 'v' }, { 'w', 'x', 'y', 'z' } };

    public List<String> letterCombinations(String D) {
        int len = D.length();
        List<String> ans = new ArrayList<>();
        if (len == 0)
            return ans;
        bfs(0, len, new StringBuilder(), ans, D);
        return ans;
    }

    public void bfs(int pos, int len, StringBuilder sb, List<String> ans, String D) {
        if (pos == len)
            ans.add(sb.toString());
        else {
            char[] letters = L[Character.getNumericValue(D.charAt(pos))];
            for (int i = 0; i < letters.length; i++)
                bfs(pos + 1, len, new StringBuilder(sb).append(letters[i]), ans, D);
        }
    }
}
```
**Time Complexity:**
O(3^N * 4^M), where N is the number of digits in the input that maps to 3 letters (e.g. 2, 3, 4, 5, 6, 8), and M is the number of digits in the input that maps to 4 letters (e.g. 7, 9), and N+M is the total number digits in the input.

**Space Complexity:**
 O(3^N * 4^M), since one has to keep 3^N * 4^M solutions.
How to use react three fiber in grafana
Tags: react, threefiber, grafana, javascript
Published: 2023-01-12 17:35:28

## Introduction to Grafana and React Three Fiber

Grafana is an open-source platform for data visualization and monitoring. It allows developers to create interactive and customizable dashboards, using a variety of data sources, including InfluxDB, Prometheus, and Elasticsearch. Grafana also provides a rich set of features, such as alerting, plugins, and an API, which makes it a powerful tool for monitoring and troubleshooting applications.

React Three Fiber is a high-performance 3D library for React. It allows developers to create 3D graphics and animations using the familiar React syntax. React Three Fiber is built on top of Three.js, a powerful JavaScript library for creating 3D graphics, and it provides a set of hooks and components that make it easy to integrate 3D graphics into a React application.

## Mistakes That I've Encountered

1. React version specified in the package.json file may not match the version used by Grafana. To resolve this, it may be necessary to either upgrade Grafana or build a custom version with the desired React version. 

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

2. When using React Three Fiber, it is important to remember to change the mode in webpack to production to avoid freezing the browser, which is a known [issue](https://github.com/facebook/react/issues/14137).

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



I'm writing this to save people a lot of time because this took me couple of days to figure out, maybe it looks simple but I've tried so many things that didn't work.

I hope this will help someone.
Day 9: Making Cool Raspberry Pi Projects even Cooler with Voice AI (4/4)
Tags: challenge, 100daysofcode, raspberrypi, tutorial
Published: 2023-01-12 17:32:38

Last tutorial for adding voice recognition to Raspberry Pi projects is Cobra Voice Activity Detection.

[Cobra](https://picovoice.ai/platform/cobra/) is a highly-accurate and lightweight voice activity detection (VAD) engine that works across platforms.

[Cobra supports](https://picovoice.ai/docs/quick-start/cobra-raspberrypi/)

- Raspberry Pi Zero (W/WH/2W)
- Raspberry Pi 2
- Raspberry Pi 3
- Raspberry Pi 4
- Raspberry Pi 400

This tutorial showcases how to run Voice Activity Detection on Raspberry Pi using C. For other SDK's visit [Cobra docs page](https://picovoice.ai/docs/quick-start/cobra-raspberrypi/) on picovoice.ai

**Compatibility**
C99-compatible compiler
**AccessKey**
Grab your AccessKey from [Picovoice Console](https://console.picovoice.ai/), if you haven't. It's free!
**Requirements**
[CMake](https://cmake.org/) version 3.4 or higher
**Microphone Demo**
The Cobra microphone demo opens an audio stream and detects the presence of speech. Commands are run from the root of the repo.
**Build**
Use CMake to build the Cobra microphone demo target:
```
cmake -S demo/c/ -B demo/c/build && cmake --build demo/c/build --target cobra_demo_mic
```
**Usage**
Run the executable without any command-line arguments prints the usage info to the console:
```
Usage: ./cobra_demo_mic [-s] [-l LIBRARY_PATH -a ACCESS_KEY -d AUDIO_DEVICE_INDEX]
```
List the available audio input devices:
```
./demo/c/build/cobra_demo_mic -s
```
Run the cobra microphone demo:
```
./demo/c/build/cobra_demo_mic -l ${LIBRARY_PATH} -a ${ACCESS_KEY} -d ${AUDIO_DEVICE_INDEX}
```
Replace `${LIBRARY_PATH}` with path to appropriate library available under lib, `${ACCESS_KEY}` with AccessKey obtained from Picovoice Console, and `${AUDIO_DEVICE_INDEX}` with the index of the audio device you wish to capture audio with. An `${AUDIO_DEVICE_INDEX}` of -1 will provide you with your system's default recording device.
**File Demo**
The file demo will analyze an audio file for the presence of voice and print the probability of voice for each frame of audio. This demo expects a single-channel WAV file with a sampling rate of 16000 and 16-bit linear PCM encoding.
**Note:** the following commands are run from the root of the repo
**Build**
Use CMake to build the Cobra file demo target:
```
cmake -S demo/c/ -B demo/c/build && cmake --build demo/c/build --target cobra_demo_file
```
**Usage**
Run the demo:
```
./demo/c/build/cobra_demo_file -l ${LIBRARY_PATH} -a ${ACCESS_KEY} -w ${INPUT_WAV_FILE}
```
Replace `${LIBRARY_PATH}` with the path to the appropriate Cobra library available under lib, `${ACCESS_KEY}` with your AccessKey obtained from the [Picovoice Console](https://console.picovoice.ai/), and `${INPUT_WAV_FILE}` with the path to the WAV file you wish to analyze.
Deploying BLOOM. A 176Billion Parameter Multi-Lingual Large Language Model.
Tags: nlp, facebook, bert, memorymanagement
Published: 2023-01-12 17:13:50

`BLOOM is a multi-lingual large language model that was recently introduced by Facebook AI. It is a transformer-based` model that is trained on a massive amount of text data from multiple languages, resulting in a model with 176 billion parameters. This makes BLOOM one of the largest language models currently available, and it is capable of performing many natural language processing (NLP) tasks with high accuracy and efficiency.

Deploying BLOOM in a production environment can be a complex task, as it requires a significant amount of computational resources and memory. However, the benefits of using such a large language model can be significant, particularly in applications such as machine translation, text summarization, and question answering.

The first step in deploying BLOOM is to acquire the necessary resources. This includes a high-performance computing cluster with a large amount of memory and storage. Additionally, the model will require a large amount of data to fine-tune and evaluate. This can include text data from multiple languages, as well as annotated data for specific NLP tasks.

Once the resources are acquired, the next step is to prepare the data. This includes cleaning, preprocessing, and vectorizing the text data. The data should also be split into training, validation, and test sets for evaluation.

The next step is to fine-tune the model on the prepared data. This can be done using a library such as Hugging Face's Transformers, which provides a simple interface for fine-tuning and evaluating transformer-based models. The fine-tuning process can take several days, depending on the amount of data and the computational resources available.

Once the model is fine-tuned, it can be deployed in a production environment. This can be done by exporting the model and serving it using a framework such as TensorFlow Serving or Hugging Face's Model Hub. The model can then be used to perform NLP tasks such as machine translation, text summarization, and question answering.

Here is an example Python script that demonstrates how to fine-tune and deploy BLOOM using the Hugging Face's Transformers library:

```
from transformers import AutoModelForCausalLM, AutoTokenizer

# load the BLOOM model
model = AutoModelForCausalLM.from_pretrained("facebook/bloom-base-176b")
tokenizer = AutoTokenizer.from_pretrained("facebook/bloom-base-176b")

# fine-tune the model on your data
# code to fine-tune the model

# save the fine-tuned model
model.save_pretrained('./fine_tuned_model')
tokenizer.save_pretrained('./fine_tuned_model')

# load the fine-tuned model
model = AutoModelForCausalLM.from_pretrained('./fine_tuned_model')
tokenizer = AutoTokenizer.from_pretrained('./fine_tuned_model')

# use the model to perform NLP tasks
output = model.generate(tokenizer.encode("What is the meaning of life?"))
print(tokenizer.decode(output[0]))


```
In conclusion, This is how i could explain what it takes to deploy a multi-lingual large language model . Hope you enjoyed the article? kindly like my post
Türk futbol tarihi
Published: 2023-01-12 16:46:08

Futbol Türkiye'nin en popüler sporudur ve kökleri Osmanlı İmparatorluğu'na kadar uzanmaktadır. İlk maçlar 1875 yılında Osmanlı şehri Selanik'te oynanmıştır. Bu spor ülkeye İngiltere halkı tarafından tanıtılmıştır. Türkiye Futbol Federasyonu 1923 yılında kurulmuştur ve 1959 yılından bu yana profesyonel lig maçları oynanmaktadır.

Türkiye Futbol Süper Ligi (Tur. Spor Toto Süper Lig), Türk futbolunun en güçlü ligidir. Normalde ligde 18 takım yer alıyor, ancak COVID-19 salgını nedeniyle 2020/2021 sezonu için takım sayısı 21'e yükselecek. Her sezonun ardından son üç sıradaki takım Birinci Lig'e düşecek ve yerlerini sırasıyla League One'daki en güçlü iki takım ve League One play-off'larının galibi alacak.

Süper Lig'in prototipi 1923'ten beri mevcuttu, ancak 1959'a kadar rekabet nispeten tanıdık iki turlu bir formatı benimsemedi. Şu anda Türkiye Süper Ligi, kulüplerin son beş yılda Avrupa müsabakalarındaki performanslarına dayanan mevcut UEFA katsayısına göre Euroleague futbol sıralamasında 20. sırada yer almaktadır. Superleague tarihinde 73 kulüp yer aldı, ancak bugüne kadar sadece altısı şampiyonluk kazandı: "Galatasaray (22 kez), Fenerbahçe (19 kez), Beşiktaş (16 kez), Trabzonspor (7 kez), İstanbul Başakşehir (1 kez) ve Bursaspor (1 kez).
XRP Ledger vs Ethereum: A User-Friendly Examination of their Pros and Cons
Tags: web3, xrp, eth, xrpl
Published: 2023-01-12 16:44:51

As we see an upsurge in the world of digital finance, **understanding the ins and outs of different blockchain platforms becomes essential**. You've likely heard of Ethereum, a powerhouse in this space, which makes everything from digital art trading to secure financial transactions possible. However, another platform, the **XRP Ledger**, is making waves and garnering attention.

In this piece, we'll explore the strengths and weaknesses of both **Ethereum and the XRP Ledger**, using everyday language and relatable examples.

First up is **speed**. Imagine being in a cafe and paying for your coffee using cryptocurrency. With Ethereum, it could take anywhere from minutes to hours for your payment to go through, not ideal when you're waiting for your morning caffeine fix. On the other hand, the XRP Ledger could process your transaction in 3-5 seconds - about the time it takes to add sugar to your cup. However, critics argue that to achieve this speed, the XRP Ledger uses a different underlying technology that may not be as decentralized, meaning the control might be less spread out.

Next, we consider **costs**. With Ethereum, transaction fees can range from a few cents to several dollars, depending largely on how busy the network is, similar to surge pricing with ride-sharing services. Comparatively, XRP Ledger transactions cost a fraction of a penny, more like a flat-rate fare. However, it's worth noting that Ethereum is aware of these issues and working on solutions, much like ride-sharing companies experimenting with different pricing models to benefit the user.

Lastly, let's talk about **throughput** - essentially, how many transactions each system can handle at once. Think of it like lanes on a highway: currently, Ethereum can handle 15 transactions per second - akin to a small countryside road. In contrast, the XRP Ledger can handle up to 1,500 - more like a multi-lane superhighway. But, Ethereum is not standing still. It's actively working on upgrades to increase its capacity, aiming to turn that countryside road into a bustling motorway.

In summary, while the XRP Ledger might currently provide a faster, less expensive highway with more lanes, **Ethereum's committed efforts to enhance its own road shouldn't be overlooked**. Therefore, users and developers need to stay informed about these platforms' evolving attributes, making decisions based on their unique requirements in this ever-changing landscape of digital finance.
Discover Luos Services
Tags: opensource, startup, microservices, luos
Published: 2023-01-12 16:30:00

A service is a block of code which will provide functionality. Services are able to communicate with any other services present in the Luos network.

▶️ [Read more](https://www.luos.io/docs/luos-technology/services)

A service can be an **application** or a **driver**.

Each service provides a particular set of tasks such as managing a motor, handling a laser range finder, or more complex operations like computing an inverse-kinematics.
Welcome to Code-Maven
Tags: news
Published: 2023-01-12 16:27:44

---
title: Welcome to Code-Maven
published: true
description: The first article published as the Code Maven organization on DEV
tags: news
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-01-11 14:32 +0000
---

I have been publishing on the [Code Maven web site](https://code-maven.com/) for several year and on DEV for some time.

I just created the Code Maven organization here to experiment with this feature.

Welcome to my first post!
How to Connect Database in PHP?
Published: 2023-01-12 16:16:56

To connect the database in PHP, you will need to use the MySQLi (MySQL Improved) or PDO (PHP Data Objects) extension. Both of these extensions provide an object-oriented interface for interacting with a MySQL database.
Here is an example of how to connect to a MySQL database using the MySQLi extension:

`<?php
$servername = "hostname";
$username = "username";
$password = "password";
$dbname = "database name";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>`
Please make sure to replace the placeholders (hostname, username, password, and database name) with the appropriate values for your database. It’s important to also make sure that you have the correct driver installed [to connect to the database](https://techzpad.com/connect-database-in-php).
Advantages and Disadvantages of Solidity
Tags: web3, blockchain, solidity, ethereum
Published: 2023-01-12 16:12:15

A popular language for creating blockchain applications, Solidity nevertheless has its pros and cons like any other programming language.


## Advantages

- Using Solidity, you can create smart contracts that are safe, clear, and dependable. They have the potential to improve operational efficiency, reduce costs, and reduce reliance on third parties.

- Programming Perceptions found in other languages, such as variables, string manipulation, classes, functions, arithmetic operations, and so on, are used extensively in Solidity. Because C++, Python, and JavaScript are major influences on Solidity, learning and using Solidity will be a breeze if you are already familiar with one of these languages.

- There is a lot of open-source documentation on how apps function and numerous use cases available for the Ethereum and EVM chains, making it easy to construct more complicated applications using other people's products written in Solidity.

- On the other hand, if you're constructing your own Decentralized Exchange and want to add novel features like Liquidity Farming, Lending, etc., you may totally fork the source code of Uniswap.


## Disadvantages
- Immutability has many benefits, but it may also be a drawback in some situations. For instance, once a contract has been signed, it cannot be upgraded or enhanced in any way.

- Because Ethereum is based on Blockchain technology, it is unable to gather and update information into the system on its own. In the case of volatile data, such as the price of currency pairings (Forex), this might be a major issue.

- Solidity's major flaw is its infancy (when compared to more mature languages like C or Java). Solidity might be a tough endeavor for newcomers to learn since there are relatively few libraries and references available.
Ternary Operator in Swift
Published: 2023-01-12 16:03:32

In Swift, we often use if-else statements to perform some conditional operations. In some cases, we can use ternary operator instead of if-else to write more readable code. To understand how the ternary operator works, let's examine its syntax.

In order to understand ternary operators, we assume you are familiar with [if-else statements](https://www.swiftanytime.com/if-else-switch-case-in-swift/).

#Ternary Operator Syntax:

```
condition ? expression1 : expression2
```
In syntax,

If condition == true, expression1 will execute.

If condition == false, expression2 will execute.

**Note:**  Here you can see there are 3 operands (condition, exp1, exp2). Therefore, the term ternary operator.
How to use it?

Here, we will check if a given number is even or odd. As a first step, we will use an if-else statement and then the ternary operator.

##Using if-else statement:

```
let number = 10
var result: String

if number % 2 == 0 {
    result = "even number"
} else {
    result = "odd number"
}

// result = even number
```

##Using ternary operator:

```
let number = 10
var result: String
result = (number % 2 == 0) ? "even number" : "odd number"

// result = even number
```
You can see that ternary operator makes it easy to check if the number is even or odd, only in a single line of code.

#Nested Ternary Operator

Just like how we deal with multiple conditions using if, else-if, else statements, we can deal with same conditions using ternary operator too by writing nested ternary operator cases. For example:

```
let number = 10
let result = (number == 0) ? "zero" : ((number > 0) ? "positive number" : "negative number")

// result = positive number
```

> Note: Using nested ternary operators will sometimes make your code difficult to read. In other words, you can completely replace the if-else statement that is true, but you should always choose readability over brevity.

#Ternary operator with optional variable

Yes, you can use ternary operator to unwrap an optional variable.

```
var name: String? = "Johny"
let nameValue = name != nil ? name! : "no_name"

// nameValue = "Johny"
```

But we have another operator nil coalescing to check optional variable to unwrap value like below:

```
var name: String?
let nameValue = name ?? "no_name"

// nameValue = "no_name"
```

This is recommended way to unwrap value from optional variable.


> Note: There is another operator called nil coalescing in Swift, which is similar to the ternary operator by syntax. As you know, ternary operator uses a single question mark (?), and nil coalescing uses a double (??). Make sure you don't confuse the two. They are both used for different reasons.

Congratulations! Today you learned about the ternary operator in Swift and the best practices to use them in your codebase to write more readable code. We recommended you to read more articles like [Conditional Statements in Swift](https://www.swiftanytime.com/if-else-switch-case-in-swift/) and [Generate Random Number](https://www.swiftanytime.com/generate-random-number-in-swift/) till then,
Eat. Sleep. Swift Anytime. Repeat.
Easily Sync Github SSH keys with your Servers
Tags: linux
Published: 2023-01-12 16:00:58

tl;dr

```sh
ssh-import-id-gh <github_username>
```

I've spent too much time not know about this..

If you work on remote servers often and connect via ssh, you'll surely want to know this.

This command grabs the public keys from Github for the username provided and adds them to your `authorized_keys` file. So if you work on multiple machines and have your ssh keys added to Github, then you can easily update any server by simply running this command.

Maybe it was just me, but I always just edited that file manually and copied my public keys around. This is a hassle and introduces potential for mistakes.

Especially because I develop on several different machines and the dynamic nature of life, it's nice to have an easy way to sync your Github keys with the allowed keys on your servers.