teleren/devto huggingface dataset:
Pass Data Between Services and Activities in Android
Published: 2021-12-07 10:10:27

Create Runnable Class

```
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

public class CommandRunnable implements Runnable{

    private static final String TAG = "CommandRunnable";
    private Context context;
    private String text;
    public CommandRunnable(Context _context,String text){
        this.context = _context;
        this.text= text;
    }
    @Override
    public void run() {
        sendMessage(text);
    }

    private void sendMessage(String msg) {
        Intent intent = new Intent("my-message");
        intent.putExtra("log-msg", msg);
        
        LocalBroadcastManager.getInstance(context)
       .sendBroadcast(intent);
    }}

```

Now Add Listener to your activity


```
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent

 @Override
 protected void onResume() {
        super.onResume();
        LocalBroadcastManager.getInstance(this)
                .registerReceiver(messageReceiver, new IntentFilter("my-message"));
 }



private BroadcastReceiver messageReceiver = new 
    BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String log = intent.getStringExtra("log-msg");

        }
 };

```


Now Add Sender to your Service

```

import android.os.Handler;
    

public static Handler handler = new Handler();

public static Handler handler = new Handler();
    void sendMessage(String msg){
        handler.post(new CommandRunnable(this,msg));

}
```


And That's All ! 

You can also try this vice-versa from activity to service...
Why I am getting the error "no database found"?
Published: 2021-12-07 10:05:22

I am using mongodb as my database. I am trying to save the details(title, price and description) of a product to my database.

Here is my database.js code

```
const mongodb= require('mongodb');

const MongoClient = mongodb.MongoClient;

let _db;

const mongoConnect= callback=>{
    MongoClient.connect('mongodb+srv://pawan:*************@cluster0.vchvo.mongodb.net/myFirstDatabase?retryWrites=true&w=majority')
    .then(client=>{
        console.log('connected');
        _db= client.db();
        callback();
    })
    .catch(err=>{
        console.log(err);
        throw err;
    })
}

const getDb=()=>{
    if(_db){
        return _db;
    }
    throw 'no database found';
};

exports.mongoConnect= mongoConnect;
exports.getDb= getDb;

```

(I have placed "*******" in place of password only for question). I could say that my database connection has been made as I can see the Connected message on my console.

Here is the save() function implementation in the product.js in models
```
save() {
        const db = getDb();
        return db.collection('products')
            .insertOne(this)
            .then(result=>{
                console.log(result);
            })
            .catch(err=>{
                console.log("error from save in model"+ err);
            })
    }
```
Here is the controller implementation:
```
exports.postAddProduct = (req, res, next) => {
    const title=req.body.title;
    const price=req.body.price;
    const description=req.body.description;

    const product = new Product(title, price, description);
    product.save()
        .then(result => {
            console.log("Created product:  "+ result);
            res.redirect('/');
            }
        )
        .catch(err => {
            console.log(err);
        })

}
```
Upon running my code when I submit the details of the product instead of being redirected to "/", I am getting a message as "no database found".

Please guide me to resolve this problem.
Git Cheat sheet
Tags: programming, git, github, cheatsheet
Published: 2021-12-07 09:52:12

Git is a version control (VCS) system for tracking changes to projects. These projects can be large-scale programs like the Linux kernel, but they can also be smaller scale projects like your own R development, homework assignments, papers, or thesis. 


![git logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ba1u21ce1nyxxy8pqiwu.png)

# Using Git


- to add name  

```
git config --global user.name yourname
```

- to add email 

```
git config --global user.email youremail@yourdomain.com
```
- to check name 

```
git config --global user.name
```
- to check email

```
git config --global user.email
```
- to initialize empty git repository 

```
git init
```
 - to show hidden files 

```
ls - lart
```



- to create blank files 

```
touch file_name
```

- to check status of file 

```
git status
```

- to commit file 

```
git commit
```
- to commit all files 

```
git commit -a
```
- to add file in current repository

```
git add file_name
```

- to add all files 

```
git add -A
```

-to add commit message

```
git commit -m "MESSAGE_HERE"
```
- to match with last commit, i.e., to recover losses

```
git checkout file_name
```

- to match all files with the last git commit

```
git checkout -f
```
- to check all commits 

```
git log 
```
- to check last 'n' commits (n should be a number)

```
git log -p -n
```
- to get difference between working file and staged file
```
git diff
``` 

- to get a list of the version history for the current branch.
```
ls
```

- to directly commit files (skip staging area)

```
git commit -a -m "MESSAGE_HERE
```
- to delete files

```
git rm file_name
```

- to remove file from staging area
```
git rm --cached file_name
```

- to get summarized status 

```
git status -s
```
- to create ignore files 

```
touch .gitignore
```
- to add new branches to git 

```
git branch branch_name
```
- to switch between branches 

```
git checkout branch_name
```
- to restore branch into master branch 

```
git checkout master
```

- to merge branches into master branch (user must be in master)

```
git merge branch_name
```
- to create a branch and directly switch into it 

```
git checkout -b branch_name
```

- to add remote git repository

```
git remote add URL_HERE
```
- to push branch into remote repository 

```
git push repository_name branch_name
```
- to clone the repository into local setup from a URL

```
git clone URL_HERE
```
- to get remote URL from where the repository was cloned

```
git config --get remote.origin.url
```
- to unstage the file, but preserve the file contents

```
git reset file_name
```

- to undo all the commits after the specified commit and preserve the changes locally

```
git reset [commit]
```

- to discard all history and goes back to the specified commit

```
git reset –hard [commit]
```
- to show the metadata and content changes of the specified commit

```
git show [commit]
```


Hope you find it helpful and informative!

> Do follow for more such blogs
> Feel free to comment down your thoughts or suggestions if any.
[Binary Search]Decode Message
Tags: algorithms, programming, 100daysofcode, java
Published: 2021-12-07 09:51:11



Created Time: December 7, 2021 10:43 AM
Date: December 7, 2021
Difficulty: Middle
Last Edited Time: December 7, 2021 10:47 AM
Multiple Solutions: No
Question Link: https://binarysearch.com/problems/Decode-Message
Topics: Dynamic Programming

Given the mapping `"a" = 1`, `"b" = 2`, ... `"z" = 26`, and an encoded message `message` (as a string), count the number of ways it can be decoded.

**Constraints**

- `n ≤ 100,000` where `n` is the length of message

### **Example 1**

**Input**

`message = "111"`

**Output**

`3`

**Explanation**

This can be decoded 3 ways: `aaa`, `ak`, and `ka`.

### **Example 2**

**Input**

`message = "8"`

**Output**

`1`

**Explanation**

This can be only decoded one way, as `h`.

### **Example 3**

**Input**

`message = "12"`

**Output**

`2`

**Explanation**

This can be decoded 2 ways: `ab` or `l`.

### Example 4

**Input**

`message = "60"`

**Output**

`0`

**Explanation**

There's no way to decode this message.

### **Example 5**

**Input**

`message = "0012"`

**Output**

`0`

---

**intuition**

Dynamic Programming

1. ‘’ => 1
2. '0' => 0; '1' => 1
3. 'x10' => dp[x]
4. 'x21' => dp[2] + dp[x]
5. 'x01' => dp[0]

**Implementation**

```java
dp[0] = 1; // 1. ‘’ => 1
dp[1] = message.charAt(0) == '0' ? 0 : 1; // 2. '0' => 0; '1' => 1
for (int i = 2; i <= length; i++) {
    int digit = message.charAt(i - 1);
    int number = Integer.parseInt(message.substring(i - 2, i));

    if (digit == '0') {
        if (number >= 10 && number <= 26) {
            dp[i] = dp[i - 2]; // 3. 'x10' => dp[x]
        }
    } else {
        if (number >= 10 && number <= 26) {
            dp[i] = dp[i - 1] + dp[i - 2]; //  4. 'x21' => dp[2] + dp[x]
        } else {
            dp[i] = dp[i - 1]; // 5. 'x01' => dp[0]
        }
    }
}
```

**Time Complexity**

O(*n*): only need one loop for check digit and number(2 digits)

**Space Complexity**

O(*n*): store states for reaching more digits.

---

```java
import java.util.*;

class Solution {
    public int solve(String message) {
        int length = message.length();
        if (length == 0) {
            return 1;
        }

        int[] dp = new int[length + 1];
        dp[0] = 1;
        dp[1] = message.charAt(0) == '0' ? 0 : 1;
        for (int i = 2; i <= length; i++) {
            int digit = message.charAt(i - 1);
            int number = Integer.parseInt(message.substring(i - 2, i));

            if (digit == '0') {
                if (number >= 10 && number <= 26) {
                    dp[i] = dp[i - 2];
                }
            } else {
                if (number >= 10 && number <= 26) {
                    dp[i] = dp[i - 1] + dp[i - 2];
                } else {
                    dp[i] = dp[i - 1];
                }
            }
        }
        return dp[length];
    }
}
```
TikTok Colors - HTML Hex, RGB and CMYK Color Codes
Tags: webdev, tutorial, productivity, css
Published: 2021-12-07 09:46:58

The [TikTok colors](https://www.pakainfo.com/tik-tok-colors/) found in the logo are turqoise, red, black and white. Use this TikTok brand color scheme for digital or print projects that need to use specific color values to match their company color palette. Find the rest of your favorite brand color codes on this web page.

The [TikTok Colors](https://www.pakainfo.com/tik-tok-colors/) with Hex & RGB Codes has 4 colors which are Black (#010101), Sea Serpent (#69C9D0), White (#FFFFFF) and Crayola's Red (#EE1D52).

This color combination was created by user Keshav Naidu. The Hex, RGB and CMYK codes are in the table below.

**TURQOISE**
PANTONE: PMS 319 C (BEST MATCH)
HEX COLOR: #25F4EE;
RGB: (37,244,238)
CMYK: (54,0,18,0)

**RED**
PANTONE: PMS 1787 C (BEST MATCH)
HEX COLOR: #FE2C55;
RGB: (254,44,85)
CMYK: (0,93,56,0)

**BLACK**
PANTONE: PMS BLACK C
HEX COLOR: #000000;
RGB: (0,0,0)
CMYK: (70,35,40,100)

**WHITE**
PANTONE: PMS WHITE C
HEX COLOR: #FFFFFF;
RGB: (255,255,255)
CMYK: (0,0,0,0)

TikTok Logo has four Colors. Hex Codes, RGB Codes and CMYK Color Codes of TikTok logo are given.

## TikTok Logo Meaning

TikTok was launched in China and it's Chinese name translates to Tremolo in English. Tremolo is a trembling effect in music produced by rapid reiteration of a musical note.

TikTok logo also has a white symbol of Musical Note in it, with the black background. While designer created a shaky or glitch effect with two other colors, light aqua and shade of red, to symbolize Tremolo.

## TikTok Logo Color Code

TikTok Logo has four colors, Black, shade of Red, shade of Light Aqua or Blue and White Color. TikTok was launched in 2016 and it's logo hasn't changed much since then. The Light Aqua and shade of Red, these two colors are not much visible in smaller size logo of TikTok.

The Hex Codes, RGB Codes and CMYK Codes of all four colors of TikTok logo are given below.

## TikTok Logo Color Hex Code

The Hex values or Hex Codes of all Colors of TikTok Logo are given below.

**Black**

Hex Value: #010101;

**Light Aqua
**
Hex Value: #69C9D0;

**Red**

Hex Value: #EE1D52;

**White**

Hex Value: #FFFFFF;

## TikTok Logo Color RGB Code

The RGB values or RGB Codes of all Colors of TikTok Logo are given below.

**Black**

RGB Value: (1, 1, 1)

**Light Aqua
**
RGB Value: (105, 201, 208)

**Red**

RGB Value: (238, 29, 82)

**White**

RGB Value: (255, 255, 255)

## TikTok Logo Color CMYK Code

The CMYK values or CMYK Codes of all Colors of TikTok Logo are given below.

**Black**

CMYK Value: (0%, 0%, 0%, 100%)

**Light Aqua
**
CMYK Value: (50%, 3%, 0%, 18%)

**Red**

CMYK Value: (0%, 88%, 66%, 7%)

**White**

CMYK Value: (0%, 0%, 0%, 0%)

**Example** : [Tik Tok Colors](https://www.pakainfo.com/tik-tok-colors/)
Placeholder title
Tags: actionshackathon21
Published: 2021-12-07 07:11:43

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)


### My Workflow
[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)


### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)


### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)


### Additional Resources / Info

[Note:] # (Be sure to link to any open source projects that are using your workflow!)

[Note]: # (Be sure to include the DEV usernames of your collaborators, if any. )

[Reminder]: # (Submissions are due on December 8th, 2021 (11:59 PM PT or 2 AM ET/6 AM UTC on December 9th).
Private sample PostgreSQL databases in seconds
Tags: webdev, sql, showdev, productivity
Published: 2021-12-07 09:32:39

Hi everyone! 

We’ve just released a [free private sample PostgreSQL databases tool](https://www.producthunt.com/posts/sql-playground?utm_campaign=ui_bakery%20-%20PoC%20-%20SQL_playground%20-%20cacq%20-%20views&utm_source=DevTo&utm_medium=webdev&utm_content=ph_launch) 🔥
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rcx4mrmmlan6jlo8e6w8.png)

It allows you to get a private database with sample data to play around and test your ideas. 
Choose a database type, generate test data, and use a sample database. It takes seconds.

We’ll be grateful for [your upvotes and comments on ProductHunt](https://www.producthunt.com/posts/sql-playground?utm_campaign=ui_bakery%20-%20PoC%20-%20SQL_playground%20-%20cacq%20-%20views&utm_source=DevTo&utm_medium=webdev&utm_content=ph_launch). 
Try the tool, and tell us what you think!
I created nonsense 'Hello World' program with GitHub Action and JavaScript. (which failed)
Tags: actionshackathon21, javascript, github, opensource
Published: 2021-12-07 09:30:54

### My Workflow

˙(: nɥɔnɥɔ ıɥɔıɥɔ ɐɥɐɥ ǝɹɐ sƃuıɥʇ ɹǝɥʇo ˙ʎɹoʇsıɥ ʇıƃ s,ʇɔǝɾoɹd ǝɥʇ sı noʎ ɥʇıʍ ǝɹɐɥs ı ƃuıɥʇ ʎןuo ǝɥʇ

### Submission Category:

Wacky Wildcards

### Yaml File or Link to Code

{% github ful1e5/gobabygo %}

### Additional Resources / Info

- Dr. Jo's [Quora post](https://www.quora.com/Which-programming-language-has-the-longest-Hello-World-code/answer/Dr-Jo-6?ch=10&oid=254205207&share=4dd4e761&target_type=answer)

This post is _powered by_ **[TheActionDev](https://github.com/ful1e5/TheActionDev)**
AWS Training in Chennai
Tags: aws, programming, tutorial, beginners
Published: 2021-12-07 09:15:42

Credo Systemz provides the best AWS Course in Chennai with real time projects.

Want to take the [Best AWS Training in Chennai](https://www.credosystemz.com/training-in-chennai/best-amazon-web-services-training-in-chennai/)? Credo Systemz provides you the Best aws Course in Chennai and assures 100% placement. Also, Credo Systemz offers the Live online Sessions with Free lifetime LMS access. 

For more details : +91 9884412301 | 9600112302
How to manage environment secrets and credentials in a Nodejs application
Tags: node, javascript, security, tutorial
Published: 2021-12-07 09:13:19


## Introduction

In this blog article, we will see how we can programmatically store and read environment secrets in a Nodejs application.

Ideally, we'd want to avoid:
- hard-coding API KEYs, PRIVATE KEYs, WALLET SEED phrases, we might end up pushing this sensitive data to a VCS like GitHub or Bitbucket
- exposing sensitive these credentials while in use.
- make these credentials configurable

Let's jump in.
You can find all project code here: [manage environment secrets](https://github.com/naftalimurgor/environment-secrets)
### 1. add a `.gitignore` file to root of project.

The first step would be creating a `.gitignore` file. This file will contain an entry of files and directories that we want git to ignore so we don't accidentally add the files to version control.

Add `.env` to the `.gitignore` file, like:

`Inside file: .gitignore`

```bash
.env
// other entries to be ignored by git
node_modules
```
### 2. create a .env file 

Create a file named `.env` at the root of your project.
Inside the file, add a key value pair of your credentials like this(no double quotes)

```bash
API_KE=your_value
MNEMOMIC=mnemonic
```

### 3. Read environment secrets from the .env file
- Add `dotenv` dependency to your project

```bash
 yarn add dotenv
 ```

Then from where we want to read environmnent secrets:
- Import the `dotenv` dependency:
```typescript
const dotenv = require('dotenv')
// or with ESM
import dotenv from 'dotenv'

// read and make secrets from the .env entries available:
dotenv.config()
```
Call `dotenv.config()` to make the secrets available from the `process.env` object

```typescript
const MNEMONIC = process.env.MNEMEONIC
console.log(MNEMONIC) // prints 'mnemomic`
 ```

## Summary
The goal of hiding environment secrets is to hide sensitive information within our applications. Care must however be taken not to add, commit and push .env files to version control as they might end up in the wrong hands.

Here's what might happen, if one accidentally pushes PRIVATE key to `Github`, a bot may grab the private key, restore your wallet and drain all your ETH or BTC in a matter of seconds. 

Did I miss anything? Feel free to leave a comment, a complement and honest feedback.

Do you feel stuck with learning modern JavaScript? You may preorder  [Modern JavaScript Primer for Beginners](https://naftalimurgor.gumroad.com/l/modern-javascript-primer-for-beginners) where I explain everything in a clear and straight-forward fashion with code examples and  project examples.

Happy hacking!
This article was originally published at https://naftalimurgor.netlify.com
🆕 Luos selftest during compilation
Tags: luos, embedded, opensource, edge
Published: 2021-12-07 09:12:41

🆕 Luos selftest during compilation

Selftest is a specific way of compiling Luos, and specially LuosHAL, allowing you to validate your entire hardware configuration. To make it work you have to connect your different connectors of the board together. Selftest will try to use different hardware resources configured for Luos and will check if everything is OK for you.

https://docs.luos.io/docs/hardware-consideration/Test-your-configuration/

![Software conditions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eznputucm7om29waiw18.png)
Best European Cities to Relocate [React Devs]
Tags: react, javascript, webdev, programming
Published: 2021-12-07 09:04:47

If you are a React Engineer looking to relocate or work remotely for a European company, in what cities should you prioritize your search?
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e394w0b7ooee95eb8wja.png)
[Best European Cities](https://www.dzemo.com/blog/best-european-cities-for-react-engineers)
Spacelift Policy-as-code Introduction
Tags: iac, terraform, security, devops
Published: 2021-12-07 08:58:30

Policy-as-code is the idea of expressing rules using a high-level programming language and treating them as you normally treat code, which includes version control as well as continuous integration and deployment. This approach extends the infrastructure-as-code approach to also cover the rules governing this infrastructure, and the platform that manages it.

Spacelift as a development platform is built around this concept and allows defining policies that involve various decision points in the application. User-defined policies can decide:

- [who gets to log in](https://docs.spacelift.io/concepts/policy/login-policy) to your Spacelift account and with what level of access;
- [who gets to access individual Stacks](https://docs.spacelift.io/concepts/policy/stack-access-policy) and with what level of access;
- [how Git push events are interpreted](https://docs.spacelift.io/concepts/policy/git-push-policy);
- [which Runs and Tasks can be started](https://docs.spacelift.io/concepts/policy/run-initialization-policy);
- [which changes can be applied](https://docs.spacelift.io/concepts/policy/terraform-plan-policy);
- [which one-off commands can be executed](https://docs.spacelift.io/concepts/policy/task-run-policy);
- [what happens when blocking runs terminate](https://docs.spacelift.io/concepts/policy/trigger-policy);

You can refer to [this section](https://docs.spacelift.io/concepts/policy#available-policies) to learn more about commonalities and differences between these policies, or to the dedicated article about each policy to dive deep into its details.
Using GitHub Actions - Publish sdist on PyPi
Tags: actionshackathon21
Published: 2021-12-07 08:49:38

[Instructions]: # (To submit to the GitHub Actions x DEV Hackathon 2021, please fill out all sections.)

### My Workflow
[Note]: # (Please make sure the project links to the appropriate GitHub Actions repository, and includes [an open source license](https://choosealicense.com/) and README.)

How boring would it be to build a software distribution of the package and upload it to PyPi after each release? This is where this workflow comes into play, automating tedious and repetitive tasks.

I created a workflow to automatically build the Python software distribution and publish it on PyPi after every release.

Building wheels is very tricky and often fails due to unforeseen circumstances. This workflow is triggered only after the wheel building procedure has been successfully completed. The sdist (software distribution) can also be tested on TestPyPi before releasing the sdist to production via workflow dispatch.

#### Actions used
- actions/checkout
- actions/setup-python
- actions/upload-artifact
- actions/download-artifact
- pypa/gh-action-pypi-publish



### Submission Category: 

[Note]: # (Maintainer Must-Haves, DIY Deployments, Interesting IoT, Phone Friendly, or Wacky Wildcards)

Maintainer Must-Haves

### Yaml File or Link to Code

[Note]: # (Our markdown editor supports pretty embeds. Try this syntax: `{% github link_to_your_repo %}` to share a GitHub repository)

- [build_sdist.yml](https://github.com/pybamm-team/PyBaMM/blob/develop/.github/workflows/build_sdist.yml)

### Additional Resources / Info

This workflow is currently being utilized by [PyBaMM](https://github.com/pybamm-team/PyBaMM) to build their software distribution on PyPi, which is then picked up by the web service of conda-forge, which bumps the version of PyBaMM on conda-forge automatically.
How to HTML to IPA online?
Tags: ipad, apple, ios, html
Published: 2021-12-07 08:30:36

[Link of my Profile on itch](https://protecgames.itch.io/)
**I know HTML and I make APKs using Apk Geyser but I don't know how to convert an HTML file into IPA**
Can you help me solving this problem 
Note: I don't have Mac or any Apple PC