teleren/devto huggingface dataset:
solana-test-validator on m1 without rosetta
Tags: solana, rust, blockchain
Published: 2022-01-11 03:22:37

> This approach is tested on v1.9.4

`solana-test-validator` is very important for local solana program development, but if you have tried to set it up on m1, you know it's not as easy as install and done.

## The official way

[The official documentation](https://docs.solana.com/cli/install-solana-cli-tools) states that, for MacOS, running this command and you are good to go:

```sh
sh -c "$(curl -sSfL https://release.solana.com/v1.9.4/install)"
```

The other command seems to work ok, but...


## The problem

Running

```sh
solana-test-validator
```

You probably get

```
Version: 1.9.4
Shred Version: 22786
Gossip Address: 127.0.0.1:1024
TPU Address: 127.0.0.1:1027
JSON RPC URL: http://127.0.0.1:8899
⠒ 00:00:01 | Processed Slot: 699 | Confirmed Slot: 668 | Finalized Slot: 668 | Full Snapshot Slot: 600 | Incremental Snapshot Slot: - | Transactions: 1107 | ◎499.997707500
[1]    47143 illegal hardware instruction  solana-test-validator
```

## Prior thesis

All of them suggested that you build from source. Some suggest that you [clean up everything including rust and use rosetta](https://dev.to/nickgarfield/how-to-install-solana-dev-tools-on-an-m1-mac-kfn).

I personally used a [non-rosetta approach](https://github.com/project-serum/anchor/issues/95#issuecomment-913090162) on `v1.7.x` but it does not work anymore on 1.9.x, since m1 somehow could not build `tikv-jemallocator`.

## The fix

For 1.9.x, we still need to build from source, but what we need to do is similar to [previous non-rosetta approach](https://github.com/project-serum/anchor/issues/95#issuecomment-913090162)


1) Clone Solana repo
```sh
$ git clone git@github.com:solana-labs/solana.git
$ git checkout v1.9.4
```

2) Edit `validator/Cargo.toml`, remove or comment out the following lines:

```toml
[target.'cfg(not(target_env = "msvc"))'.dependencies]
jemallocator = {package = "tikv-jemallocator", version = "0.4.1", features = ["unprefixed_malloc_on_supported_platforms"]}
```

3) Then you can build the whole thing.

```sh
./scripts/cargo-install-all.sh .
export PATH=$PWD/bin:$PATH
```

Or optionally, you can just build only `solana-test-validator` and use the rest of `solana-cli` from prebuilt binaries.

```sh
$ cargo build --release --bin solana-test-validator
$ cd bin
$ ./solana-test-validator
```

---

Let me know if it works for you or know what exactly `tikv-jemallocator` is for (I only know that it's for memory allocation but don't know why it's needed or when it is used).

Cheers.
Git Survival Kit - Part 2
Tags: git, github, productivity, devops
Published: 2022-01-11 03:12:30

This is the second part of my git survival kit series, a collection of easy-to-learn and vital commands for day-to-day git operations for everyone. Even if you're new to git, knowing these commands will definitely help you become more productive and solve your mistakes.

**1. display the list of branches**

local branches: `git branch`

remote branches: `git branch -r`

**2. display current repository configurations**
`git config -l`

**3. delete tag from the local repository**
`git tag --delete tagname`

**4. delete tag from the remote repository**
`git push --delete origin tagname `

**5. see which commit a tag points to**
`git rev-parse tagname`

**6. revert branch history to a specific tag, discarding all changes after the tag**
`git reset --hard tagname`

**7. revert branch history to a specific tag, keeping all changes after the tag in the staging area**
`git reset --soft tagname`

**8. filtering history of commits in date ranges using since and until options**
`git log --since='yesterday'`
and 
`git log --since="1 week ago" --until="yesterday"`

**9. showing commit history with summary of changes made in each commit**
`git whatchanged `

also, the since and until options can be used to filter history

`git whatchanged --since='2 weeks ago' --until='2 days ago'`

**10. see the changes to a file in a commit**
`git show commit_hash -- file_name`
top amazing games
Tags: romanticpoetr
Published: 2022-01-11 02:40:13

[Romantic poetry](https://www.sadpoetry4u.com/) is the poetry written during the Romantic era. It was an intellectual, artistic, and literary movement that emerged in Europe at the end of the eighteenth century. Its influence can be found in everything from opera to ballet. The period of Romantic poetry lasted from 1800 to 1850. There are many great works of this period. Here are some of its most popular poems. If you want to learn more about this time period, read on.
The [4K video downloader](https://getintopc4u.com/) is a software application that enables you to record and download 4K videos from almost any website.
[Rekordbox Dj Crack](https://crackhub.org/) is the best instrument for DJ’s general exhibition. That gadget is created by the pioneer DJ who else is well known these days. Additionally, Rekordbox Dj Crack fathoms the personality of text just as the sound
[Betternet VPN ](https://gematsu.org/)Premium Crack is a strong programming project to utilize a VPN administration. The Betternet gives for versatile and works area stages
[PhoneRescue 7 Crack](https://crack-watch.com/) is a high information recuperation application. It causes you to reestablish all erased information which lost coincidentally. The product can recuperate all records and information like instant messages
Import CSV data to Ruby on Rails 7
Tags: rails, ruby
Published: 2022-01-11 02:33:56

Occasionally, we have a big data to be imported to our databases rather than adding data entry through forms. So, we use csv files to get that data to different tables in databases.

By default, CSV parser is in-built in rails. All you have to do is `require 'csv'` in the file where you want to use it.

I would suggest to use background job while importing data as data can be huge to handle and the request will be kept on waiting until it completes.

## CSV file path
First, we have to get the file path:
```ruby
def csv_file_path
  # give url to csv file
  @csv_file_path ||= File.read("https://...")
end
```

## Initialise csv
Now that we have a path of the file to be read. Now parse this file so that we can use that data to import:
```ruby
def csv
  @csv ||= CSV.parse(csv_file_path, col_sep: ",", row_sep: :auto, skip_blanks: true)
end
```
So, we call the path method and parse the file explaining that the data in the file will be using the separator `,` and separator of rows auto and skip the row if blank.
We can also call `csv.count` now to check the number of rows in the file.

## Import Data
Let’s assume my file contains two columns, i.e., name, and email of the subscribers and I want to add to the user specified list the subscribers.
![CSV file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ampr6iat7nqr35gsej57.png)
I have `user` model which has many `lists` and I have `subscriber` model which has many `lists` as well. Now `list` has many `subscribers` through `list_subscriber` model.

```ruby
csv.each_with_index do |row, index|
  next if index == 0 # skip headers
  subscriber = Subscriber.find_or_initialize_by(email: row[1])
  subscriber.name = row[0]
  next unless subscriber.valid? # skip if subscriber data is invalid
  imported_subscriber << {name: subscriber.name, email: subscriber.email}
end

# save imported students
imported_subscriber_ids = Subscriber.upsert_all(imported_subscribers, returning: %w[id], unique_by: :email)

if imported_subscrriber_ids.present?
  # update list with imported subscribers
  list_subscribers = imported_subscriber_ids.map { |id| {subscriber_id: id["id"], list_id: list_id} }
  imported_list_subscribers = ListSubscriber.upsert_all(list_subscribers, returning: %w[id], unique_by: :index_list_subscribers_on_list_id_and_subscriber_id)
end
```

And viola! The contacts will be imported now. The `upsert_all` method is built in Rails 6 will import the data in one call and `unique_by` will stop any duplicated row to create.

As `list_subscriber` has a unique index on listId and subscriberId, so we can use the name of index direct by calling `index_list_subscribers_on_list_id_and_subscriber_id` otherwise `uniq_by` only works with columns having unique index.

---- 

Happy Coding!
Develop a social network with ReactJS, Spring Boot and MongoDB
Tags: webdev, javascript, react, programming
Published: 2022-01-11 02:31:53


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

I have developed a small social network web app for educational purpose and want to share this with the community. This app is built with ReactJS for frontend, Java Spring Boot for backend and MongoDB as the database.

The app tries to mimic a few functions of Twitter, including:

- Create post with text and image
- The number of characters in each post is limited to 200 characters
- Like, comment and re-post a post
- View the number of likes, comments and shares of a post
- Comments are toggle
- The number of character in each comment is limited to 100 characters
- Follow, un-follow someone
- See who are following us and follow them back
- Check who we are following
- View all posts of an individual
- View our own posts
- List all user accounts in the entire social network (due to the number of users are still small, I did not develop search user function)

Other functions:

- Due to limited storage space, client app compresses the uploaded image to the maximum of 250px (width or height) 
- User avatar is created by hashing user id and convert that hash code into a hexagonal image
- Authentication and authorization use JWT
- Responsive frontend for desktop and mobile devices

Technical stack:

- Frontend: ReactJS, Redux Toolkit, React Router, React Bootstrap
- Backend: Java Spring Boot
- Database: MongoDB

Hope you enjoy it and if this project is useful for you , please give me a ⭐ **Github star** ⭐ for my effort!

Source Code:
https://github.com/linhtch90/psn-social-network-public-source

Live Demo:
https://psn-social-network.herokuapp.com/#/
I built a NextJS/Tailwind portfolio template for you to use!
Tags: opensource, design, nextjs, tailwindcss
Published: 2022-01-11 02:20:19

Hey hey hey Dev community!

It's been a while since I posted about a new open source project! I'm here to announce that I'm going to start building some open-source landing page/website templates from here and on into the future!

**Obsidian**. It's a slick and speedy portfolio template to showcase your projects and skills built on the awesome stack of NextJS and TailwindCSS.

Live demo: https://obsidian-portfolio.vercel.app
Github repo: https://github.com/braydentw/obsidian

---

If you have any feedback or any suggestions for future templates, I'd love to hear them! Let me know in the comments below.

Thanks! Have an awesome Monday.
Remote Module Federation with Webpack and React
Published: 2022-01-11 02:17:07

# Module Federation Demo
- <a href='https://github.com/bronifty/npx-create-mf-app-build'>Github Repo</a>
- <a href='https://youtu.be/8_ra5tK36dQ'>Tutorial Vid</a>
- based on <a href='https://www.youtube.com/watch?v=K-yQB9YGmgE' >Jack Herrington's Module Federation demo</a> but with some code fixes

- to see the demo, run the following commands and open browser tabs on localhost:8080 and localhost:8081

```bash
yarn
yarn build
yarn start
```

- to demo the fallback, switch to host app and run yarn start then open browser on localhost:8080 (it serves the nav app from build via linked library instead of remote federation)

```bash
cd packages/home && yarn start
```



## Summary

- create packages directory (could be named anything) and build 2 mf-apps inside, which will be run by wsrun (a yarn workspaces task runner)
  - follow the prompts to create your app (I'm using react)

```bash
mkdir packages
cd packages
npx create-mf-app --name host
npx create-mf-app --name nav
```

- create the component in the nav app that you want to share and default export it
- next we will import the exported component with module federation by configuring webpack.config.js in both apps

```js
/* nav */
{
  const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
  ...

plugins: [
    new ModuleFederationPlugin({
      name: 'nav',
      library: { type: 'var', name: 'nav' },
      filename: 'remoteEntry.js',
      remotes: {},
      exposes: {
        './Nav': './src/Nav',
      },
      shared: require('./package.json').dependencies,
    }),
    new HtmlWebPackPlugin({
      template: './src/index.html',
    }),
  ],
}

/* host */
{
  const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');
  ...

  plugins: [
    new ModuleFederationPlugin({
      name: 'home',
      library: { type: 'var', name: 'home' },
      filename: 'remoteEntry.js',
      remotes: {
        mfNav: 'nav',
      },
      exposes: {},
      shared: require('./package.json').dependencies,
    }),
    new HtmlWebPackPlugin({
      template: './src/index.html',
    }),
  ],
};
```

- now you can refer to the remote module as 'mfNav/Nav' in your host app (we will lazy load it into suspense to handle the async import)

```jsx
/* host/src/App.jsx */
const Nav = React.lazy(() => import('mfNav/Nav'));

const App = () => (
  <div className='container'>
    <React.Suspense fallback={<div>Loading...</div>}>
      <Nav />
    </React.Suspense>
    <h2>HOME</h2>
  </div>
);
ReactDOM.render(<App />, document.getElementById('app'));
```

### Ref

<a href='https://reactjs.org/docs/error-boundaries.html'>React Error Boundaries</a>
#12 - Fibonacci digit sequence CodeWars Kata (6 kyu)
Tags: javascript, webdev, tutorial, 100daysofcode
Published: 2022-01-11 02:13:09

##Instructions

**Task**
You are given three non negative integers a, b and n, and making an infinite sequence just like fibonacci sequence, use the following rules:

step 1: use ab as the initial sequence.
step 2: calculate the sum of the last two digits of the sequence, and append it to the end of sequence.
repeat step 2 until you have enough digits
Your task is to complete the function which returns the nth digit (0-based) of the sequence.

**Notes:**
0 <= a, b <= 9, 0 <= n <= 10^10
16 fixed testcases
100 random testcases, testing for correctness of solution
100 random testcases, testing for performance of code
All inputs are valid.
Pay attention to code performance.

**Examples**

> For a = 7, b = 8 and n = 9 the output should be 5, because the sequence is:
> 78 -> 7815 -> 78156 -> 7815611 -> 78156112 -> 781561123 -> 7815611235 -> ...
> and the 9th digit of the sequence is 5.

---

> For a = 0, b = 0 and n = 100000000 the output should be 0, because all the digits in this sequence are 0.

---

##My solution:

```javascript
function find(a,b,n){
  let r = a.toString() + b.toString()
  n = +n.toString().slice(-4);
  
  while (r.length <= n){
   let x = r.split('')
   r += (+x[x.length-1] + +x[x.length-2]).toString()
  }

  return +r.charAt(n)
}
```

---

##Explanation
First I started concatinating the 2 first numbers as a string, then I changed the n value, because if it was too high, the code performance would be awful and it tooka  lot to returning the result, so I just used the last 4 numbers of the n variable because after some cycles, the result is the same.

> let r = a.toString() + b.toString()
> n = +n.toString().slice(-4);

---

After that I used a while loop that would keep iterating until the string "r" length is equal to "n", inside the loop I made a variable "x" that splitted the "r" string into an array and after that the "r" string will concatenate and be equal to the sum of the last 2 elements of the "x" array, for making this strings a number I just added the + operator before the values, and after summing them I just made them string again so for the next loop cycle it would be a string again.

> r += (+x[x.length-1] + +x[x.length-2]).toString()

---

At the end I just returned the character at the "n" position of the "r" string, and converted it to a number because I used the + operator before returning the value.

> return +r.charAt(n)

---

**Comment how would you solve this kata and why? 👇🤔**

[My Github](https://github.com/Cesardlr)
[My twitter](https://twitter.com/cesar__dlr)
[Solve this Kata](https://www.codewars.com/kata/5bc555bb62a4cec849000047)
I am building a cheap remote co-working space
Tags: workstations, webdev
Published: 2022-01-11 02:05:03

**The Problem**

One big Con of working remotely is the **lack of an office vibe and team spirit.**

 Many try going to physical Co-Working spaces but they tend to be expensive and noisy and for digital nomads that jump around constantly it's hard to develop meaningful relationships.

**Virtual Co-Working Space**

To fix that I started building a [remote co-working space](https://wannabe-entrepreneur.com/coworking/) that entrepreneurs can access no matter where they are.

*Now I have more than 50 members and some have even already met in person.*

Besides having the slack channel we also have always available virtual rooms where people can work or hang together and events like hackathons, random coffees, and workshops.


Would love to hear your thoughts on the idea. Would you see yourself using such a service?

Cheers
How to fix security vulnerabillities in a newly created react app.
Tags: webdev, react, javascript, tutorial
Published: 2022-01-11 02:01:34



If you ever get error messages in the command line interface after creating a new react app with the create-react-app command, just like the image below, then this fix might help you out.

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

The first thing we do is deleting the starter files in the src path except the index.js and app.js files, ending up with the result in the below image.


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

The next step involves deleting every starter file in the public path except the index.html file just like below


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

In The next step, we will delete some code in the index.js file so that we don't have dependency imports that might trigger errors. 


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

We will also delete some code in the index.html file to get rid of some of the deleted dependencies.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ppr5uo07t3h9d1su0rf.jpg)

After you are finished with finding all the imports that are not used anymore and removing them, there should not be any more errors in the terminal. I hope this helped you out.
Thanks.
Resilient Caching in Redis
Tags: redis, tutorial, architecture, design
Published: 2022-01-11 01:06:38

Before the introduction, I will describe what is the resilience.

> Distributed systems will fail, a resilient software system will not try to avoid failure but expect it and respond gracefully.

We all know data in cache will sooner or later be lost. The reason comes from many situations even the writing operation is successful. Let's take Redis as an example.

1. Redis server crashed: of course, data was lost, because all data in Redis was stored in the memory.
2. Redis replica went through the partition failure and recovered again.
3. Even without any hardware/software failure, Redis spent all memory spaces and proceeded to evict the existing cache.
4. If using `ElastiCache` of `AWS`, the upgrade process will also drop all entries.
5. And so on.

As far as we know, the cache is not reliable and hard to ensure the data consistency. However, there are indeed some tasks which leveraged cache to improve the performance requiring the reliability. 

We have talked about the cardinality counting in [my previous article](https://lazypro.medium.com/cardinality-counting-in-redis-3c3a472e2d9f), and that is a great example to show the importance of data persistence. If the collections in Redis is no longer trusted, how can we design a large system? The solution is making your cache more resilient.

## Resilient Collections

Following my example of health status, we want to make sure our sensor networks work properly; therefore, we record the activity of API calls in Redis. In order to simplify the explanations, I will choose bitmap with recording in days in this section.

The data in Redis bitmap must answer a question, how many days does the sensor work in this month?

We can leverage my previous statements as follows.

```
SETBIT sensorA_jan 1 1
SETBIT sensorA_jan 2 1
SETBIT sensorA_jan 3 1
```

The statements show that `A` worked at 1/1, 1/2 and 1/3. And we can get the answer from: `BITCOUNT sensorA_jan`. What if the Redis crashed at 1/2? The `bitocunt` would become 2 without the record of 1/1. In such case, the `bitcount`  is distorted.

To tackle this issue, we can add an integrity into the collection, let's say `SETBIT sensorA_jan 0 1`. When we want to retrieve `bitcount`, we check the integrity first, `GETBIT sensorA_jan 0`. If the result is `1`, which means the `bitcount` is under controlled, otherwise, we have to rebuild the data from a durable storage like a database.

## Conclusion

Since we have to rebuilt the result from a database, why not do it at the first? The reason is quite simple, we want to keep the system high performance. We should ensure the reporting throughput by using cache and expect there should be failed someday. Nevertheless, we still can get the correct result by some heavy aggregating operations on the database.

This is how resilience does, and this article provides a straightforward example to demonstrate how to accomplish a cardinality counting resiliently.
Day 506 : Makin' Moves
Tags: hiphop, code, coding, lifelongdev
Published: 2022-01-11 00:08:56

_liner notes_:
- Saturday : Just a pretty normal Saturday. Went to the station. Did the show. Had a good time. Stayed in the van over night and did some coding. The recording of this week's show is at https://kNOwBETTERHIPHOP.com

![Radio show episode image of a black and white photo of Sidney Poitier standing across the street of the Apollo Theater large signs in New York City with the words Jan 1st 2022 Not That Serious](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/18pdrfjggft1vi1ij2it.jpg)

- Sunday : Got up early and drove to my spot. Ordered some McDonald's breakfast on the app that I picked up on the way. Did my https://untilit.works cyphers and worked on my side project. I added a scroll snap to the mobile view so that people can swipe to view different sections. After the cyphers, I watched a couple of episodes of "Attack on Titan" and went to sleep.

- Professional : Had soooo many meetings today. haha It was cool because a couple were for a project we are building to be completed by the end of the month. Got the okay for some updates I did to a blog post and demo app. Going to get that published soon. Rest of the day, worked on the aforementioned app, fixed some things and added a new feature. Not a bad Monday. Makin' Moves Monday! haha.

- Personal : Been making some progress on my side project. Not as much as I would like, but it's some progress. I've also been thinking of some ways to help with some of the workload from some the tasks during and after the radio show. I'll probably start that after my current project.

![A canyon in Masada, Israel with orange mountain sides](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8z4hw42njm26lb71afs0.jpg)

Going to plan out what is left to do with my current side project. I think the reason it's going slowly is because sometimes I'm looking for things to work on and then get distracted when I come across something while doing research. haha. Going to eat dinner, put together that list, maybe code and then watch an anime.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube VJKqloPr604 %}