teleren/devto huggingface dataset:
send a certain portion to a specific address with every transaction in Smart Contract

Published: 2021-04-06 23:27:31

          

i have created a Smartcontract. now i want the functionality: where 2.5% of every transaction is transferred to a fixed address. say the address is 0x809341c1c1cba2d6accf8188bca463a119443d. i know it can be done but could not able to sum up the code.

here is the contract

     `pragma solidity ^0.5.0;


     contract ERC20Interface {
          function totalSupply() public view returns (uint);
         function balanceOf(address tokenOwner) public view returns (uint balance);

    function allowance(address tokenOwner, address spender) public view returns (uint remaining);

    function transfer(address to, uint tokens) public returns (bool success);
function approve(address spender, uint tokens) public returns(bool success);

    function transferFrom(address from, address to, uint tokens) public returns (bool success);

    event Transfer(address indexed from, address indexed to, uint tokens);
    event Approval(address indexed tokenOwner, address indexed spender, uint tokens);
}

safe math---------------------------------------------------------------------------
......................
/////////

    


contract me is ERC20Interface, SafeMath {
    string public name;
    string public symbol;
    uint8 public decimals; // 18 decimals is the strongly suggested default, avoid changing it

    uint256 public _totalSupply;

    mapping(address => uint) balances;
    mapping(address => mapping(address => uint)) allowed;

    
    constructor() public {
        name = "me";
        symbol = "me";
        decimals = 18;
        _totalSupply = 250000000000000000000000000;

        balances[msg.sender] = _totalSupply;
        emit Transfer(address(0), msg.sender, _totalSupply);
    }

    function totalSupply() public view returns (uint) {
        return _totalSupply  - balances[address(0)];
    }

    function balanceOf(address tokenOwner) public view returns (uint balance) {
        return balances[tokenOwner];
    }

    function allowance(address tokenOwner, address spender) public view returns (uint remaining) {
        return allowed[tokenOwner][spender];
    }

   function approve(address spender, uint tokens) public   returns (bool success) {
        allowed[msg.sender][spender] = tokens;
        emit Approval(msg.sender, spender, tokens);
        return true;
    }

    function transfer(address to, uint tokens) public returns (bool success) {
        balances[msg.sender] = safeSub(balances[msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(msg.sender, to, tokens);
        return true;
    }

    function transferFrom(address from, address to, uint tokens) public returns (bool success) {
        balances[from] = safeSub(balances[from], tokens);
        allowed[from][msg.sender] = safeSub(allowed[from][msg.sender], tokens);
        balances[to] = safeAdd(balances[to], tokens);
        emit Transfer(from, to, tokens);
        return true;
    }
}
Fetch Data using TypeScript and React Query
Tags: typescript, react, database, beginners
Published: 2021-04-06 23:14:16

Let's get started!

Let's say we have some data from an API and we want to use ReactQuery to fetch that data. Here is my approach. 

Firstly install ReactQuery and also you can read these information below: 
https://react-query.tanstack.com/

I am using Firestore for these purposes.

Create an endpoints.ts file and add your api endpoint such as:

```js
const EXAMPLE_DATA = `example/`

```
Create a request.models.ts file where we are gonna add all they different types of our API call. For instance if your API had a cats[] then you can do inside the file ->

The key-data below is your key on the JSON data that you receive

```js
export interface CatsData {
  animal: string,
  name: string,
  id: string
}

export interface CatsDataModel {
  data: CatsData[]
}
```js
In case you have a jwt token create an interface for that as well

```js
 export interface TokenRequestModel {
  jwt: string
}
```

Create a getCatsData.ts file. Bearer is Firebase's
Authorisation, other system using a different keyword.


```js
export interface CatsDataModel {
  dataSummary: CatsData[]
}

export type GetCatsDataResponse = APIResponse<CatsDataModel>

export type GetCatsDataAxiosResponse = AxiosPromise<GetCatsDataResponse>

export const getCatsData = ({
  jwt,
}: TokenRequestModel): GetCatsDataAxiosResponse => {
 return axios({
  method: 'GET',
  url:(EXAMPLE_DATA)
headers: {
    Authorization: `Bearer ${jwt}`
  }
})
}
```
                


Now on your main file where you want to render your data
The useUserContext is a customised hook build on the Auth.ts file that has the signIn function for firebase.

```js
const {idToken} = useUserContext()
const { data: dataSummary } = useQuery(
 ['dataSummary'],
() => getCatsData({ jwt: idToken }),
{
 enables: !!idToken
 }
)
```
See you next Time!!
Why did you choose the SPA architecure?
Tags: discuss
Published: 2021-04-06 23:12:23

Single Page Apps (SPA) + APIs seem to be the default nowadays over more traditional Multi-page apps Ruby on Rails / PHP type server-rendered HTML.

I want to write an article about why I think MPAs are still a valid a nice way to make applications but I'm not sure where people are at right now besides they seem to be picking SPAs almost exclusively. 

1. Was React + APIs the only thing you learned?
1. Why did you pick SPAs personally?
1. Why did your company pick a SPA if they did?
1. Why do you think SPAs became the default for most orgs? Or do you think they aren't?

If you have no idea what the difference between a SPA or MPA is then I am curious about that as well (I just want to hear from you guys I guess 🤗). 

Cheers!

Photo by <a href="https://unsplash.com/@soymeraki?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Javier Allegue Barros</a> on <a href="https://unsplash.com/s/photos/choice?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
5 Beginner-Friendly Coding Livestreams to Learn Programming
Tags: beginners, webdev, python, javascript
Published: 2021-04-06 22:55:26

2020 has been a great year for code livestreams. Stuck at home, developers took to their OBS setups to share their coding projects with their peers. And viewers tuned in to watch a fellow developer struggle through a programming issue, get stuck, google things, and eventually figure things out, and found their coding communities in the process.

But if you are a code newbie, you might find it daunting to follow along with the experienced developers' livestreams. Fear not, for you have your own peers learning new tech stacks live! Here are five of our favorite beginner-friendly streamers that you can watch to learn programming:

## Learn full-stack web development with Leon

Leon Noel (https://www.twitch.tv/learnwithleon) runs a free Web Dev Bootcamp live on Twitch every Tuesday and Thursday at 6:30 PM EST. The goal of the bootcamp is to help those affected by the pandemic as well as help underrepresented folks learn web development and get hired as software engineers. You can also bring your questions to the Office Hours on Saturdays at 12 PM EST.

## Learn Python with Pachi 

Pachi Carlson is currently learning Python live on her Twitch channel (https://www.twitch.tv/pachicodes) on Mondays and Wednesdays at 10 AM EST.

## Learn Golang with Paul

Paul Kernfeld is currently learning Golang from scratch every Friday at 12 PM EST on Cockroach Labs' Twitch channel. 

## Learn Rust with Prince

Prince Wilson is currently learning Rust with Exercism.io on his Twitch channel (https://www.twitch.tv/maxcellw)

## Learn JavaScript with CJ

The creator of the popular coding YouTube channel (Coding Garden) also has an excellent Twitch channel (https://www.twitch.tv/codinggarden) for full-stack app projects, tutorials, and Q&A sessions (mostly featuring JavaScript).

## Bonus streams

- Follow along Jeseekia Vaughn's awesome journey through 100 Days of Code: https://www.twitch.tv/metadevgirl
- Want to get some of your own coding done? Join Mayuko (https://www.twitch.tv/hellomayuko) for a chill co-working stream for pomodoro coding sprints.
Day 339 : Easy Skanking
Tags: hiphop, code, coding, lifelongdev
Published: 2021-04-06 22:42:51

_liner notes_:
- Saturday : Pretty good day. Watched the latest "Falcon and Winter Soldier episode. Did some research on a side project. Then it was time to do the radio show. Had a really good time! After the show, I got all the post promo work done also. Felt pretty productive. The recording of this week's show is at https://kNOwBETTERHIPHOP.com

![Radio show episode image of a man in the stands at a football game holding a sign that says Save us Bezos Washington Amazons with the words April 3rd 2021 And then...](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vqa2n0u0kl1kb64mp5x.jpg)

- Sunday : Finished up my laundry. Worked on an upcoming presentation. Worked a little on my side project. It was an easy skanking type of day. Watched "The Walking Dead" and a new show called "Gangs of London" and turned in for the night.

- Professional : Monday was a holiday in the US so I pretty much rested up and got ready for work the next day. It's funny, it's like I needed a break from taking a week off of work. Got a few things done during my break. It was good getting back to work. Had a few meetings. It was good to see people. Spoke with my manager and we discussed what we'll work on this sprint. I've got a presentation coming up so I'll be working on that and another event that I'll be at the virtual booth. Good to be back.

- Personal : This past week off has been pretty eventful. My father's knee surgery went well. I'm going to hang around while he gets his physical therapy just incase my folks need me for anything. Thought of how I may want to structure some parts of my side project. It involves Web Components. Also paid off my van early. I actually used cash from a 0% offer I received to pay off the auto loan that had interest. This way, all my money I pay goes towards paying down the money instead of some going to interest. This is how I brought down my credit card debt by a lot to just no interest cards and raised my credit score by 100's of points! Looking forward to having no debt and a good amount in savings and investments. Hopefully by the end of this year. It's been a long road. haha

![A waterfall in the middle of a jungle in Sri Nakarin Nat'l Park, Thailand](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0fyjjyzgkrs72hon3qj.jpg)

Going to work on my side project. I didn't really get to work on it as much as I thought I would. I kind of spent that time getting stuff together to start building out the inside of my van. Went to a couple of hardware stores looking for some parts. Looks like I may need to drill and bend some parts to fit the way I need. Also, I started paying for a subscription to a place I've been watching anime. There's no more commercials and it's amazing how fast the episodes go! haha. Feels good to get back to blogging. It was a good time off and ready to dive back in. I'm rambling now. haha.

Have a great night!

peace piece
Dwane / conshus
https://dwane.io / https://HIPHOPandCODE.com
{% youtube wlqB13iJu2o %}
100 Bytes Of Wisdom: Day 39
Tags: career, journey, advice
Published: 2021-04-06 22:18:10

---
title: 100 Bytes Of Wisdom: Day 39
published: true
description: Bytes of Wisdom is a new project by Sam Jarman that brings together snippets of advice for software engineers
tags: career, journey, advice
//cover_image: https://direct_url_to_image.jpg
---

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l2bctfx4eloe55bm0b69.png)


Always work in the smallest unit possible, eg milliseconds, cents, meters. You can always divide to something reasonable when it comes time to display the value, such as dollars. Computers really suck at storing floating points number, so using whole numbers is usually best.

Heads up: As with any terse bit of advice, there will be exceptions of course, and subtleties and nuance that can't possibly be captured in a Byte of Wisdom. This has been what I've experienced, I'd love to hear yours in the comments too!

You can catch up with all the other bytes at http://bytesofwisdom.com/
Typetron has a CLI now
Tags: typetron, node, typescript, framework
Published: 2021-04-06 21:13:37

A few months ago I [released the Beta version](https://dev.to/typetron/tyeptron-beta-is-here-typetron-org-5g16) of Typetron and since then I've made a few changes to it and added some new features. One of it is the [CLI](https://typetron.org/docs/installation).

The CLI was created to make dev's life easier by giving them a set of tools to automate some parts of the development process. 

#### Installation
Installing Typetron's CLI is easy enough, as you would already expect:
```sh
$ npm install -g typetron
```
This will create a global command called, well, `typetron`.

This command line tool has a few sub-commands that you can use. Here is a list of them:

1. The `new` command
```sh
$ typetron new MyProject
```

As you are already used to in CLIs, the `new` command creates a new Typetron project with a basic scaffolding and installs its dependecies. 

2. The `routes` command

```sh
$ typetron routes
```

Tis command will print out all the routes in your Typetron project together with some information about them. It comes in handy when you have a lot of them in a big project.

3. The `migrate`, `migrate:rollback` and `migrate:reset` commads

```sh
$ typetron migrate
Migrating...
Migrating 'CreateUsersTable'
Migrated 'CreateUsersTable'

$ typetron migrate:rollback
Rolling back...
Rolling back the 'CreateUsersTable' migration.
Reverted 'CreateUsersTable' migration.

$ typetron migrate:reset
Resetting database...
```

These commands are used to manage your Typetron app migrations


Check the website [typetron.org](https://typetron.org)
Typetron Twitter [@Typetron_](https://twitter.com/Typetron_)
My twitter [@ionellupu_](https://twitter.com/ionelLupu_)
Come and leave a question on [Reddit](https://www.reddit.com/r/typetron)
Join [the Facebook](https://www.facebook.com/Typetron-662589810876633/) group
Let's talk on [Slack](https://typetron.slack.com)
Introducing Upstream: A free one-day celebration of open source, the developers who use it, and the maintainers who create it
Tags: opensource, news, development, technology
Published: 2021-04-06 21:07:17

---
title: Introducing Upstream: A free one-day celebration of open source, the developers who use it, and the maintainers who create it
published: true
description: On June 7, 2021, please join us for Upstream, a new one-day celebration of open source, the developers who use it, and the maintainers who create it.
tags: opensource, news, development, technology
---

<p>Open source is an amazing testament to human ingenuity.</p>
<p>We don’t often stop and take the time to celebrate what we—the creators and users of open source—have made together and the impact it has on our world.&nbsp;</p>
<p>So let’s stop and do exactly that!</p>
<p>On June 7, 2021, please join us for Upstream, a new one-day celebration of open source, the developers who use it, and the maintainers who create it. This 100% virtual, completely free event will bring together like-minded application developers, open source project maintainers, and the extended network of people who care most about their work.&nbsp;</p>
<p><a href="https://upstream.live">REGISTER NOW</a></p>
<p>Do you ever stop to think about all the open source libraries, frameworks, and components that your applications depend on?&nbsp; All those dependencies—hundreds of lines scrolling by when you run an "npm install" or the equivalent in another language? Upstream is about zooming in on the creators behind those essential open source packages and the developers who build amazing things with them.</p>
<p>We’ll journey with the maintainers behind the open source libraries and frameworks you use every day, across ecosystems including JavaScript, Java, PHP, Ruby, Python, .NET, Rust, and Go, learning the “how” and “why” behind the projects, and getting sneak peeks into where they are headed next. We’ll explore today’s most interesting and exciting open source projects, and ride along with those developing applications with open source at scale.&nbsp;</p>
<p>Our goal is to accelerate the creation of even more great open source software by bringing together an inclusive community of people with a shared interest in making open source work better for everyone.&nbsp;</p>
<p>You can learn more and register for free at <a href="https://upstream.live/" rel="noopener" target="_blank">Upstream.live</a>. The first 300 people who register will receive some cool goodies, so don’t miss out. (Shipping to North America only, sadly.)&nbsp;</p>
<p>Do you have an interesting story to share you think might be a fit for Upstream? <a href="https://www.papercall.io/upstream" rel="noopener" target="_blank"><span>We are accepting applications</span></a> until May 4 for presentations from developers using open source to build interesting applications and open source maintainers who want to share more about their projects or passions.</p>
<p>We look forward to seeing you at Upstream!</p>
To the centre of the galaxy, and beyond...
Tags: futuretech, space, unity3d, ai
Published: 2021-04-06 20:34:28

I started to make a landing page on one of my *outta the world* ideas lately. It was so out of the world that I felt that I needed to put it out there in some form or the other. So here is my article on what the project represents, where I want to go with it and eventually be the next iteration of human innovation.

# Sagittarus A*

Well this is the name of the Super massive black hole at the centre of our galaxy and it is essentially the end game destination for the project. Imagine if we could send a spacecraft / satellite to this supremely amazing phenomenon. We could for sure learn something or the other about the universe and the nature of reality.

The project is subdivided into various stages which will essentially build towards our end goal. They are:
- SpaceCraft
- SatCraft
- SpaceMarket
- Trading guilds
- SpaceYards


## SpaceCraft

Imagine Minecraft in space, this is essentially SpaceCraft. Being the low threshold first step, we want to use VR to bring human minds to space. Developing a VR game in which people can easily mine objects in the solar system. With this we aim to build a computational equivalent for our solar system.

## SatCraft

This is the next step after SpaceCraft and the "hardware" part of the project. After having a computational replica of the solar system within our pockets, we can launch nanosats into our space neighbourhood. We then link the real world sats to our computational solar world and the users can interact in real time with those nanosats. They can mine, explore and actually affect our space, all without taking a journey to space itself.

## SpaceMarket, Trading Guilds and SpaceYards

The space market can be the place where miners can trade their goods for money. They can mine some iron from Mars and trade it virtually in the SpaceMarket. They can then be delivered to the buyer, here on Earth. 

Sending 3D printers to space, we can in theory create spaceships and other manufacturing tools to space and have shops to sell new models of satellites to miners and maybe also prepare for the eventual exploration of our solar system

Once the SpaceYards program is in place, we can have Trading guilds operate trade routs and markets. 

With these three, we would have established an economy in space as well as brought the human mind to space. 

check out the project [here](https://sagittarius-a-star.webflow.io/)
for/in vs. each in Ruby: More than just syntax
Tags: ruby, beginners
Published: 2021-04-06 20:31:38

During a recent PR review I found myself having to explain why we would want to use `each` over `for/in` in Ruby. Turns out most people think it's just more idiomatic to use `each` over `for` but it's much more than that.

With `for`, the variable you use will be available outside of the loop, while the variable you use in `each` will only be available in that block.
```ruby
x = [1, 2, 3]

x.each do |i|
  puts i
end
#...
puts i #=> NameError: undefined local variable or method `i' for main:Object

for i in x
  puts i
end
#...
puts i #=> 3
```
This is because `for` **does not** introduce a new scope but `each` does via the block you pass it. It’s important to understand scope here because you can really make a mess with `for` if you’re not careful. ie:
```ruby
def num
  puts 4
end

num #=> 4

x = [1, 2, 3]

x.each do |num|
  puts num
end
#...
num #=> 4

for num in x
  puts num
end
#...
num #=> 3
```
I hope this clears up why you should use `each` over `for` while working with Ruby. It's a simple thing that can have a rather large impact.
April LeetCoding Challenge 2021 — Day 6: Minimum Operations to Make Array Equal
Tags: computerscience, algorithms, programming, codenewbie
Published: 2021-04-06 20:20:08


Today, we will solve the 6th problem of the April LeetCoding Challenge 2021.


## Problem Statement

You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values of i (i.e. 0 <= i < n).

In one operation, you can select two indices x and y where 0 <= x, y < n and subtract 1 from arr[x] and add 1 to arr[y] (i.e. perform arr[x] -=1 and arr[y] += 1). The goal is to make all the elements of the array **equal**. It is **guaranteed** that all the elements of the array can be made equal using some operations.

Given an integer n, the length of the array. Return *the minimum number of operations* needed to make all the elements of arr equal.

**Example 1:**

    **Input:** n = 3
    **Output:** 2
    **Explanation:** arr = [1, 3, 5]
    First operation choose x = 2 and y = 0, this leads arr to be [2, 3, 4]
    In the second operation choose x = 2 and y = 0 again, thus arr = [3, 3, 3].

**Example 2:**

    **Input:** n = 6
    **Output:** 9

## Solution

This is a basic problem. Here we have to make all the elements of the array equal by a particular operation. We have to find the minimum number of steps to make the array elements equal.

To do this task in minimum steps, we can convert the elements into their mean value.

According to the question, the elements at i-th index is (2*i)+1 . Therefore the mean of these elements will be n ,which is given in the question.

The code is given below.

 <iframe src="https://medium.com/media/d3b5aba3b7df6bdbbd292ed863563af3" frameborder=0></iframe>

The code can be found here
{%github sksaikia/LeetCode %}
"Easy" exercise solved
Tags: python, beginners
Published: 2021-04-06 19:51:36

I was struggling so bad whit this exercise found in codingBat (https://codingbat.com/prob/p113659) asking for a output of the first 3 numbers of pi
Result: ![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ioez0gw76vqp2cnpnkge.jpg)