teleren/devto huggingface dataset:
Day 52 Of 100DaysOfCode: exec( ) Function in Python
Tags: womenintech, codenewbie, 100daysofcode, beginners
Published: 2021-02-15 15:35:14

This is my 52th day of #100daysof code and python. Like yesterday today also continued to learn more about algorithm. Tried to write effective  algorithm for Fibonacci numbers, Greatest common devisor. Defintion of Big-O ,types of Big-O and used of Big-O from [Coursera.](https://www.coursera.org/learn/algorithmic-toolbox/lecture/MWN7W/course-overview)

Here is one python code today I wrote for sorting different function in ascending order.
#Python Code
####exec() function 
exec() function is used for the dynamic execution of Python program which can either be a string or object code. If it is a string, the string is parsed as a suite of Python statements which is then executed unless a syntax error occurs and if it is an object code, it is simply executed.

exec is a built in function which allows us to run dynamic pyton code on runtime. For example,
```python
exec("""
def  sum(a,b):
    return a+b
""")
sum(5,4)
```
I tried to write following code to kept the function in ascending order.
```python
import numpy as np
n = 10
value = np.e
base = np.e
f1 = lambda n: 3**n
f2 = lambda n: n* (np.log(n)/np.log(2))
f3 = lambda n: np.log(n)/np.log(4)
f4 = lambda n: n
f5 = lambda n: 5**(np.log(n)/np.log(2))
f6 = lambda n:n **2
f7 = lambda n:n **0.5
f8 = lambda n:2**(2*n)

sol = {}
for i in range(1,9):
    exec(f'v=f{i}(n)')
    sol[f"f{i}"]=v
print(sol)
x = sol.copy()
dict(sorted(x.items(), key=lambda item: item[1]))
```
Output of above code is,
```python
{'f1': 59049, 'f2': 33.219280948873624, 'f3': 1.6609640474436813, 'f4': 10, 'f5': 209.8592395866664, 'f6': 100, 'f7': 3.1622776601683795, 'f8': 1048576}
{'f3': 1.6609640474436813,
 'f7': 3.1622776601683795,
 'f4': 10,
 'f2': 33.219280948873624,
 'f6': 100,
 'f5': 209.8592395866664,
 'f1': 59049,
 'f8': 1048576}
```
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Day 52 Of <a href="https://twitter.com/hashtag/100DaysOfCode?src=hash&amp;ref_src=twsrc%5Etfw">#100DaysOfCode</a> and <a href="https://twitter.com/hashtag/Python?src=hash&amp;ref_src=twsrc%5Etfw">#Python</a> <br>* Algorithmic Toolbox<br>* Completed Some Assignment <br>* Python exec( ) function<a href="https://twitter.com/hashtag/womenintech?src=hash&amp;ref_src=twsrc%5Etfw">#womenintech</a> <a href="https://twitter.com/hashtag/DEVCommunity?src=hash&amp;ref_src=twsrc%5Etfw">#DEVCommunity</a> <a href="https://twitter.com/hashtag/CodeNewbie?src=hash&amp;ref_src=twsrc%5Etfw">#CodeNewbie</a> <a href="https://t.co/USBO43P1Ni">pic.twitter.com/USBO43P1Ni</a></p>&mdash; Durga Pokharel (@mathdurga) <a href="https://twitter.com/mathdurga/status/1361333278268039169?ref_src=twsrc%5Etfw">February 15, 2021</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
About Virender Sehwag, Impossible Dreams, video with react
Tags: react, node, webdev, programming
Published: 2021-02-15 15:33:36

Greetings..


Every Monday I publish my newsletter/Blog. Throughout the week I try to gather some useful links and post them in a specific format and I believe this would help my readers and the community.

Read about this week's newsletter by clicking this link or using the below URL:

https://gokhale.me/about-virender-sehwag-impossible-dreams-video-with-react

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tjxx33wbkqel17q4d5ar.jpg)

Until next time, Stay Safe.
A LIFE-SAVING GitHub Feature that you need to know RIGHT NOW!
Tags: productivity, github, webdev, programming
Published: 2021-02-15 15:32:02

Ever browsed a Github repository and felt the pain of not being able to view the code without having to download the entire repository? 

It's huge pain, especially when you simply want to look through the code.

Wouldn't it be great if we could simply view the code while browsing without having to download the entire repo?

Well, this problem has been solved! A great tool that will help you to view the code on the go, that too, in one of our favorites and powerful code editor, **VS Code!**

## Wondering how to do it? 

You can do this in just 3 steps:

Step 1 - Go to any GitHub repository
**For Example: **
https://github.com/iamrohitsuthar/quizller

Step2 - Just put **1s** in the between of Github and .com in the address bar and see the magic happen.

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

Step 3 - Wow! The repository opens in an online VS Code editor!

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

**Isn't it time-saving for devs?**

Let us know your thoughts in the comments below

Follow us on instagram
https://www.instagram.com/the.ninja.programmer/
[BLOG] - Laravel, PHP elegante – Artigo para iniciantes – Série Laravel para Iniciantes – Parte 1
Tags: php, laravel
Published: 2021-02-15 15:25:23

Este é o primeiro artigo de uma série de 8 artigos (+ artigos de apoio) em que falaremos sobre o framework PHP mais utilizado da atualidade, o Laravel!

Vamos partir do início, com a instalação do Laravel e construir uma aplicação completa a partir disso enquanto aproveitamos para aprender como usar o framework e as melhores formas de trabalhar com ele.

[Continuar...](https://blog.erikfigueiredo.com.br/laravel-php-elegante-artigo-para-iniciantes-serie-laravel-para-iniciantes-parte-1/)
Deciding on our infrastructure was nerve-racking.
Tags: database, javascript, infrastructure, webdev
Published: 2021-02-15 15:18:10

####In December of 2020, we got very nervous.

Let's go a little back in time. At Codesphere, we ran our very first infrastructure on a small German data center.

They offered a really nice UI, were GDPR compliant, and also much cheaper than the big international competitors in comparison.

What we were not aware of, was that they provided a maximum of only 10 servers.

This meant that there was no way they could scale with us long term, as our team is located in different countries and utilize hundreds of nodes. It would have not even sufficed for our launch alone.

#### Our dream requirements were:

* initially 80+ servers in one German datacenter
* each server having >50GB RAM and >10 vCPUs
* >20% automatable growth per month
* low price per node
* easy monitoring
* managed load balancer (HAProxy)
* simple reimaging
* dedicated NVMe SSD’s for our ETDC cluster
* GDPR compliant


In the long run, we want to scale to hundreds of servers per data center. We strive to have multiple data centers in the USA, Asia, Europe, Russia, and Latin America with ideally, as few providers as possible.

After having 60+ calls with hosting providers, it seemed that all of them would either be more expensive or did not provide what we required at scale.

We realized that it was unrealistic to secure and maintain our own hardware and keep our launch schedule on track at the same time.

In the end, we only found 2 providers Contabo and PlusServer, that could get the job done, and we ultimately decided to collaborate with Plusserver to build our own datacenter on their new GAIA-X infrastructure.

Setting up the infrastructure went well and we would recommend everyone to make their infra decision with a long-term perspective in mind and after much in-depth research.
We believe that trusting your infrastructure to be able to scale smoothly with you is the key requirement to be able to focus on your product. 

We are more than thrilled to be working with the guys from PlusServer and whether or not this was a success, you can be the judge of, after testing Codesphere. :)

What are your experiences with infrastructure decisions?
Animation challenge
Tags: css, tutorial, todayilearned, codenewbie
Published: 2021-02-15 15:16:59

Hey coding people :)

Hope you are doing well in your journey.

This post is a part of our "20 Days of CSS animation post".

{% link https://dev.to/atulcodex/20-days-of-css-animation-post-3g8d %}

In this post, I am going to share my challenge which I have solved.

{% codepen https://codepen.io/atulcodex/pen/jOVyYqg %}

That's all for this post And if you are interested to learn CSS you can join [E-Learning platform](https://www.eduonix.com/UHJvZHVjdC0xMzE1MDIw).
Installing GIT on your system
Tags: git
Published: 2021-02-15 15:13:36

Okay so now I think that you know what is GIT and why it is used **if you don't know I recommend reading [my previous post](https://dev.to/aadityasivas/introduction-to-git-1ech)**

## Installing
### For Windows:
First head over to https://git-scm.com/download/win/ this will start the download of the latest version of GIT. After the file is downloaded follow these steps.

#### Step 1
![file-img](https://dev-to-uploads.s3.amazonaws.com/i/68m4uwhnnah14plbdlw7.png) ☝ Locate and open this file after download

#### Step 2
![alt text](https://dev-to-uploads.s3.amazonaws.com/i/1cq9adunz0jbbgofhc0l.png)
 Agree to the license after reading it

#### Step 3
![alt text](https://dev-to-uploads.s3.amazonaws.com/i/l10fgftrxt5hmzouwkdm.png)
Choose the **Let GIT decide** Option 

#### Step 4
Now press next and continue with the installer and your good to go.

### For Linux
For Linux there are different methods for different distributions so head over to https://git-scm.com/download/linux/ and do the steps given there for your distro of Linux.

### For macOS
#### Step 1
Install homebrew from here https://brew.sh/
#### Step 2
run this
```bash
brew install git
```

## Testing the installation
To test if it is installed properly run this
```bash
git --version
```
If it is printing the version then **Congrats !!🎉🎊🥳** it is installed successfully.


So I am ending this post here bye and have a nice day!
Any queries ask me in the discussions
IS PHP Dead?
Tags: php, programming, laravel, webdev
Published: 2021-02-15 14:56:56

You hear it all the time - "PHP is dead", "PHP is spaghetti code", so on and so on, but is that really the case?

I'm a PHP developer, who's dabbled in some backend JS too, and I try to be impartial as possible.

No. The short answer is no. PHP is alive and kicking. Does that mean you should flock to it for all projects? Again, no. Should you instantly dismiss the language? No. 

No no no. 

In late 2020, PHP 8 was publicly birthed into the world, packed full of enhancements, features, improvements, and life. I get it, I truly do - older PHP was... or could be... unfortunate... we'll say. Having inherited 8-year-old codebases originally build on PHP 5.x, I know just how messy PHP can and does get - heck, even modern PHP can be written badly, but isn't that the case for near all languages?

Near every language, sure, more commonly interpreted languages have room for messy code, but that doesn't mean the language itself is bad. Modern PHP can be elegant, scalable and efficient, and that's without much effort. 

Let's think - PHP is very much in active development. There's many, many CMS' based on PHP, and many great frameworks, too. One of the world's most popular frameworks - Laravel, is based on PHP. The world's most popular CMS - WordPress, is based on PHP. The PHP community is growing, and so is the quality of code. 

This doesn't mean you should swear by the language for every use-case. Sockets? Sure, PHP can do it, but should you? Are there better tools out there? Definitely.

I think the problem with PHP is the low-entry barrier. PHP is great at making code just "work", which means you can, and do see a lot of poor code. That isn't always a bad thing, though. Everyone starts somewhere, right? And with the gigantic community, it's so so easy to learn and grow, which is **incredible**. 

This post is just me spewing my views. I think it's important to remain logical and to use the best languages and tools for the solution to problems. That language might be PHP, and if it is, you can write some incredible code with it - if it isn't? Great, you can do just that with any other language too. 

I'm very keen to hear thoughts on this topic - please do share yours :)
11+2 รูปแบบที่น่าจำ Truthy and Falsy และ  Primitive Type & Reference Type
Tags: javascript
Published: 2021-02-15 14:48:55


กำลังอ่าน [What the fuck js](https://github.com/NantipatSoftEn/wtfjs) แล้วเลยไปเจอพวกนี้มาเลยต้องจดใส่สมองไว้หน่อย

## Truthy Value

ก็คือค่าที่ถือว่าเป็น `true` เมื่อใช้ในการเปรียบเทียบ boolean ซึ่งมีด้วยกันทั้งหมด 5 ค่าที่เราควรระมัดระวัง

- '0' string 
- 'false' string 
- [] empty array
- {} empty object
- ()=>{} empty function

## Falsy Value

ก็คือค่าที่ถือว่าเป็น `false` เมื่อใช้ในการเปรียบเทียบ boolean ซึ่งมีด้วยกันทั้งหมด 6 ค่าที่เราควรระมัดระวัง

- false — ค่า boolean ที่เป็น false
- 0 — เลข 0 ที่มี type เป็น number
- "", '', `` — empty string
- null
- undefined
- NaN


## null และ undefined

ค่าของสองตัวนี้จะเท่ากัน และเท่ากันกับค่าของตัวเองเท่านั้น

## NaN
ค่าของตัวนี้อภิมหาพิเศษเพราะนอกจากมันจะไม่เท่ากับค่าใดๆแล้ว มันยังไม่เท่ากันกับค่าตัวเองอีกด้วย (โอ้โห!)

# Primitive Type &  Reference Type

Primitive Type  คือเมื่อสร้างตัวแปรใหม่โดยอ้างอิงจากตัวแปรเก่า ค่าที่ได้จะเป็นการคัดลอก

![Javascript-DataType](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n0nd27i26uc35zmflnqk.png)
  
Reference Type คือเป็นการสร้างตัวแปรแบบอ้างอิง โดยที่เมื่อตัวแปรไหนเปลี่ยนตัวแปรอื่นก็จะเปลี่ยนตามด้วย จะใช้กับทั้ง Array และ Object

Ref:
- [javascript-truthy-falsy](https://www.sitepoint.com/javascript-truthy-falsy/)
- [falsy-values-จุดเล็กๆที่ไม่ควรมองข้าม-javascript](https://medium.com/arcadia-software-development/falsy-values-%E0%B8%88%E0%B8%B8%E0%B8%94%E0%B9%80%E0%B8%A5%E0%B9%87%E0%B8%81%E0%B9%86%E0%B8%97%E0%B8%B5%E0%B9%88%E0%B9%84%E0%B8%A1%E0%B9%88%E0%B8%84%E0%B8%A7%E0%B8%A3%E0%B8%A1%E0%B8%AD%E0%B8%87%E0%B8%82%E0%B9%89%E0%B8%B2%E0%B8%A1-javascript-a9935d1cba10)
- [JavaScript ความแตกต่างระหว่าง Primitive Type และ Reference Type](https://dev.to/hambalee/javascript-primitive-type-reference-type-485)
Has Open Source Licensing Reached Its End of Life?
Tags: opensource, licensing
Published: 2021-02-15 14:43:36

---
title: Has Open Source Licensing Reached Its End of Life?
published: true
description: Lately I’ve begun to wonder if open-source licensing has failed to keep up with technology. The first version of GPL debuted in 1989, and was updated soon after in 1991. The most recent revision of GPL was in 2007. That was 14 years ago!
tags: opensource, licensing
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/dpmwyuzx6ow2vb1jzzia.png
---
Recently, I finished working on a software project that I’m especially proud of. It took months of effort to complete, and the final result was something that perfectly fit my needs. It was a labor of love.

It’s not important to reveal the purpose of the software here, or the technical details of its inner workings. Simply allow me to say that it’s something that I will use right away, and that other programmers may find useful as well.

When the project was complete, there were a few important decisions that I needed to make. How do I share what I’ve created? How can I get fair compensation for my efforts? And how do I protect what I’ve created from unscrupulous profiteers?

Getting fair compensation for our individual efforts is part of the equation here. Yes, I’m aware that GPL licensing makes a distinction between “Free as in Speech” and “Free as in Beer”. Yes, I know that *I can charge a fee* for my efforts.

I’m curious to know what other software developers are doing about this. What considerations go into the decision-making process? What works and what doesn’t?

Lately I’ve begun to wonder if open-source licensing has failed to keep up with technology. The first version of GPL debuted in 1989, and was updated soon after in 1991. The most recent revision of GPL was in 2007. That was 14 years ago!

I've explored this topic more fully in this [JavaScript Fanboi](https://medium.com/javascript-fanboi/2021-035-has-open-source-licensing-reached-its-end-of-life-d04243acd042) article.

I haven’t figured out where to go from here, but it feels like something needs to change.
How to use redux-form SubmissionError in react.
Tags: react, redux, reduxform
Published: 2021-02-15 14:38:07

Redux-form is an open-source javascript, for managing form state in redux and a validation library that can be integrated into react web application so easy but i won’t be explaining how to integrate the library into a react project has i assume the reader is not a novice to redux-form or redux as a whole. In this tutorial will only look at how to use redux-form SubmissionError function to achieve something like this kind of error

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

Inside login presentation file, we’ll import reduxForm and Field from the redux-form library and also renderInput file

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

The above image is the Login presentation, we have handleSubmit, pristine, submitting props from redux-form. Next we create our renderInput file

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

The css selectors are from bootstrap. Next, we create our Login container, to perform data manipulation or whatever we need to use the data received from the presentation

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

We import connect from redux library, also our login action and the presentation file then create our function to be called when the submit button is clicked. Next we create our login action to send our values to the server or API or cloud function

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

From the above snippet, we imported SubmissionError and reset from redux-form library, from the beginning of this blog you know what we want to achieve with SubmissionError but reset looks new, so what reset does is to notify redux-form to reset the values inputted by the user in redux state.

At this stage we are not yet done, if you try to login and you receive an error from the server or from a third party API, you will notice that your app crashes with an error on the browser. To solve this we just need to add return or use async/await on our handleSubmit, like this

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

That’s all to SubmissionError from redux-form.

Conclusion

I hope you have a clear idea of how you can use redux-form SubmissionError in your react app. Hope to see more ways to implement this function.
Syncing files from AWS S3 to local storage on Rails
Tags: rails, aws, activestorage
Published: 2021-02-15 14:36:08

I usually use Amazon S3 for storing images with Active Storage. There are some issues when pulling my database to work with it on localhost:

- I don't want to accidentally delete something on S3
- I don't want my localhost without images 🥲

I added this rake task to download files from S3 and format them in a way that works with local storage:

```ruby 
# lib/tasks/s3_to_local.rake 
desc "Sync files from S3 bucket to local storage folder"

task :s3_to_local do

  s3_bucket = "YOUR_S3_BUCKET"
  access_key_id = Rails.application.credentials.dig(:aws, :access_key_id)
  secret_access_key = Rails.application.credentials.dig(:aws, :secret_access_key)

  storage_folder = Rails.root.join('storage')
  storage_folder.mkpath

  system("AWS_ACCESS_KEY_ID=#{access_key_id} AWS_SECRET_ACCESS_KEY=#{secret_access_key} aws s3 sync s3://#{s3_bucket} #{storage_folder}")

  # Ignores sub_folders already created and .keep files
  images = storage_folder.children.select { |file| file.file? && !file.empty? }

  # Formats the file path of each image so ActiveStorage understands them using :local storage
  images.each do |path_name|
    dir, basename = path_name.split
    file_name = basename.to_s
    sub_folders = dir.join(file_name[0..1], file_name[2..3])
    sub_folders.mkpath # Create the subfolder used by active_record
    path_name.rename(dir + sub_folders + basename) # Renames file to be moved into subfolder
  end

end
```

What makes this tricky is that S3 storage has everything in the root of the bucket, and when using local storage with ActiveStorage, everything should be under a subfolder. 

Also, you need AWS CLI for this to work: 
```
brew install awscli
```

Basically copy this task into `lib/tasks/s3_to_local.rake`, add your bucket name, your AWS credentials, run `rake s3_to_local` and you're good to go
TLDR: Button to update status attribute of a table
Tags: ruby, rails, polymorphism
Published: 2021-02-15 14:24:53

---
title: "TLDR: Button to update status attribute of a table"
tags: ruby,rails,rubyonrails,polymorphism
published: true
canonical_url: https://blog.corsego.com/ruby-on-rails-change-status-button
cover_image: https://blog.corsego.com/assets/images/change-status.gif
---

### Mission: add buttons to change the `status` of a `task`

![change-status.gif](https://blog.corsego.com/assets/images/change-status.gif)

### HOWTO:

migration - add `status` column to `tasks`

```
add_column :tasks, :status, :string, null: false, default: "planned"

```

task.rb - list available statuses

```
  validates :status, presence: true
  STATUSES = [:planned, :progress, :done]

```

tasks_controller.rb - add action to change status

```
  def change_status
    @task = Task.find(params[:id])
    if params[:status].present? && Task::STATUSES.include?(params[:status].to_sym)
      @task.update(status: params[:status])
    end
    redirect_to @task, notice: "Status updated to #{@task.status}"
  end

```

routes.rb - add actionable link to change status.

```
  resources :tasks do
    member do
      patch :change_status
    end
  end

```

tasks/show.html.erb

```
  <% Task::STATUSES.each do |status| %>
    <%= link_to change_status_task_path(@task, status: status), method: :patch do %>
      <%= status %>
    <% end %>
  <% end %>

```
Voila, that's it!