teleren/devto huggingface dataset:
Valid Elements in a sorted array
Tags: python, challenge
Published: 2020-09-30 10:01:03

### Problem: Statement Write a function to count number of distinct elements given in a sorted array.

#### Difficulty level: Easy

#### Test Cases

* \[2, 2, 3, 3, 4, 5] --> 4
* \[4, 5, 7, 10, 15] --> 5
* \[1, 1, 1, 2, 5, 5, 5] --> 3
* \[1, 2, 3, 4, 4, 5, 5, 5] --> 5
* None --> 0

- - -

### Algorithm

* Python *Set* Solution

  * Add elements of array to *set* and return it's length.
* Dictionary Solution

  * Iterate through the given array
  * If element was previously not seen in dictionary than,

    * Add the element to dictionary with *value* of 1.
  * Return the length of dictionary.
* Best Solution 

  * Initialise index at *1*
  * Iterate from 1 to length of given array.
  * If, the element at current iteration *i* is not equal to element at position of *index - 1*, than

    * Overwrite the element at *index* with the element at current iteration *i*
    * increment value of *index* by 1
  * Return *index*

- - -

#### Time and Space complexity

* Time complexity of all solutions: O(n)
* Space complexity

  * Set: O(n)
  * Dictionary: O(n)
  * Best solution: O(1)

- - -

### Code

```python
class ValidElements(object):
    def validElements(self, arr):
        if not arr:
            return 0
        return len(set(arr))

    def validElements2(self, arr):
        if not arr:
            return 0
        seen = {}
        for entry in arr:
            if entry not in seen:
                seen[entry] = 1
        return len(seen)

    def validElements3(self, arr):
        if not arr:
            return 0
        index = 1
        for i in range(1, len(arr)):
            if arr[index - 1] != arr[i]:
                arr[index] = arr[i]
                index += 1
        print(arr)
        return index
```

#### Unit Test

```python
import unittest
from validElements import ValidElements


class TestValidElements(unittest.TestCase):
    def testValidElements(self, func):
        self.assertEqual(func([2, 2, 3, 3, 4, 5]), 4)
        self.assertEqual(func([1, 2, 3, 4, 4, 5, 5, 5]), 5)
        self.assertEqual(func([1, 1, 1, 2, 5, 5, 5]), 3)
        print("All test cases passed")


def main():
    test = TestValidElements()
    elements = ValidElements()
    test.testValidElements(elements.validElements)
    test.testValidElements(elements.validElements2)
    test.testValidElements(elements.validElements3)


if __name__ == "__main__":
    main()
```
[Original article](https://codewithml.netlify.app/posts/valid-elements-sorted-array)
[Github solution](https://github.com/Codewithml/coding-problems-solutons/tree/master/arrays/valid-elements)

### Happy Coding ! :smiley:
Shorthand Javascript Techniques
Tags: javascript, webdev, tutorial
Published: 2020-09-30 10:00:57

# Declaring Variables
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/weqrz75m29edvk5d3yql.JPG)

# Ternary Operators
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/qu64whf2wqogy6naevoz.JPG)

# Assignment Operators
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/a6o82pwfjdasmbul5400.JPG)

# Switch Case
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/4wv5o2ylvn6q9574tk76.JPG)

# If Presence
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7j6g3q5qhypblz67onm9.JPG)

# Arrow Functions
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tjxl8sfcw9ymmc2lotxf.JPG)

# Object Array Notation
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tetyip87zx9vafmxeknc.JPG)

**Happy Coding!**
30 Days Of React
Tags: react, javascript, webdev
Published: 2020-09-30 09:56:38



Another monthly challenge will start on 1 October 2020. This challenge starts tomorrow and ends on 30 October 2020. This challenge will help you to completely immerse yourself in React and to take your JavaScript or React skill to a higher level.

👉 It is recommended to have an intermediate level of HTML, CSS, and JavaScript to get the taste of this challenge.

👉 Starting the challenge with a friend or with a team increases the chance to complete the challenge. In addition to that, asking, answering, and helping others in the telegram group will help you to learn faster and to be engaged.

💻 30 Days Of React: https://lnkd.in/d8VAS2J
👥 Join telegram group: https://lnkd.in/dNbxT8M

Previous challenges
💻 30 Days Of JavaScript Github: https://lnkd.in/efqy_df
💻 30 Days Of Python Github: https://lnkd.in/epW6d_U

👥 Join the 30 Days Of JavaScript group: https://lnkd.in/er7kdTE
👥 Join the 30 Days Of Python group: https://lnkd.in/eE5Qgqd
Is Python slow in comparison to use cases of other languages?
Published: 2020-09-30 09:53:40

A variety of studies have indicated that Python is slower than other commonly used programming languages, including Java and C++. Instead of enhancing code execution speed, many programmers substitute the default runtime of Python with a custom runtime. 

To improve the performance and speed of the application, some developers also rewrite existing Python code. But the usage statistics posted on different websites show that Python is more successful than PHP, Ruby, JavaScript, and Go at the moment. There are also a number of reasons why, considering it being so slow, developers prefer Python to many other programming languages.

<h2>Why is it so popular?</h2>

1. Concise and Readable Application Code

2. Multiple Popular Programming Paradigms

3. High-Level Programming Language

4. No Code Recompilation

5. Rapid Application Prototyping

6. A Robust Standard Library

7. A Variety of Frameworks and Tools

8. Build Complex Applications

9. A Component of LAMP Stack

10. Test-Driven Development

11. Reduce Project Overheads

12. Python is highly flexible

In terms of benchmarks and efficiency, Python might be slow in comparison to C/C++, but its processors and computers are as solid as ever in terms of computing power and the performance gap from C/C++ won't matter that much. Python, however, is a high-level programming language that is often used around the world. It mainly has more in-built functions that can decrease a programmer's effort. 

As compared to some other languages, the code lines are much shorter. It is commonly used to solve mathematical problems, which is why it is used in artificial intelligence and machine learning. Python has better precision and is more productive to use. That's why more people are trying to get pythons for a better future.  
 
<h2>Check the Link For Some of the Best Code Editor For python</h2>
https://codersera.com/blog/best-python-ides-and-code-editors/
https://www.softwaretestinghelp.com/python-ide-code-editors/
Moving 2D Backgrounds in Unity
Tags: unity3d, gamedev
Published: 2020-09-30 09:41:41

In my Unity 2D Game, I need to move some items in the background, including:

* Pavement
* Street Lights
* Buildings

Then it feels like the player is moving. But actually, the items are moving backward.

Have a look at this video:

{% youtube bOldSL7xTKY %}

It'd be great if we automatically spawn these items & move. That's where we can get some help from a C# script. Here's how to do that:

* Create a script called "InfiniteMovingBelt.cs" in your project
* Then add the following content

{% gist https://gist.github.com/arunoda/51a9d738b18bac2a43b3870488edc204 %}

* Then Create an "Empty Game Object" and add this script

After that, customize the parameters of this script as shown in the above video.

## Better Solution

Since this might be a common task in 2D games, I think there is a much better solution than this. If you know a better solution, just let me know.
What is the best platform for professional bloggers ?
Published: 2020-09-30 09:18:57

If you want to share your knowledge or experience on an online platform, you can start blogging. As a blogger firstly need a website. There are lots of options for you, you can choose any CMS such as WordPress,Joomla,Drupal. You have to spend some money for your website. Many bloggers are confused about what CMS or platform is perfect for blogging. If you are confused, this article for you.
## WordPress is perfect for you ?
If you are non-technical and have no knowledge about coding or programming, you can choose WordPress. It's very easy and manageable. Have many page builders you can easily drag and drop elements. WordPress SEO friendly also. Drupal And Joomla Are quite similar.
## Ghost CMS is perfect for you ?
Basically Ghost Is perfect For Professional Bloggers, if you are a professional writer or want to start paid blogging, you can choose ghost. Ghost hosting is quite costly, if you are a beginner and have no enough budget just ignore Ghost. Ghost is blazing fast SEO friendly Awesome Membership Blogging Platform.
## I have no money, can I start blogging ?
Yes you can. Anyone can create a professional website without any cost. If you have no money to create a website you can choose Jekyll Or Hugo. Do you know about Jekyll? Jekyll is a static site generator created with Ruby Language and Hugo is also a static site generator created with Go language. To manage your website you do not need to know any programming languages. Static sites have no database, have no dashboard. For changing website content you have to change some text from files, it's very easy. You can host your website in github and connect with netlify. You can easily change your domain name from your netlify account. If you have a custom domain you can add that by netlify.
5 Best Shared Hosting In India
Tags: best, shared, hosting, india
Published: 2020-09-30 08:53:38

5 Best Shared Hosting In India - 

1. Hostinger.
2. Siteground.
3. A2 Hosting.
4. FastComet.
5. Chemicloud.

1. Hostinger - 

Hostinger is the best and cheapest shared hosting platform, as well as, provide the <a href="https://www.besthostinginindia.in/">Best Web Hosting Services In India</a>

2. Siteground.

Siteground is the most recommend hosting platform in the blogging industry and it is also the best hosting company but because their prices are high that's why Siteground in on the 2nd number of this list.

3. A2 Hosting.

A2 Hosting is the 2nd most recommended hosting services in the blogging industry. But their uptime is a little bit, not good that's why it is on 3rd option.

4. FastComet. 

FastComet is the best alternative to the Siteground hosting platform. I review that hosting and this hosting gives me results like the Siteground hosting platform.

5. ChemiCloud.

ChemiCloud is the 2nd best alternative of Siteground hosting his performance is also almost like Siteground Hosting. 

Last Words. 

If you have the budget then Siteground is the best shared hosting in india and if your budget is low then hostinger is the best hosting for you.
I'm Participating in Hacktoberfest. Solving Problems about the Hactoberfest
Tags: hacktoberfest, showdev, github
Published: 2020-09-30 08:38:40

Hacktoberfest Online Meetup in [UIET,MDU]

Hacktoberfest® is open to everyone in our global community. Whether you’re a developer, student learning to code, event host, or company of any size, you can help drive growth of open source and make positive contributions to an ever-growing community. All backgrounds and skill levels are encouraged to complete the challenge.

-Hacktoberfest is a celebration open to everyone in our global 
 community.
-Pull requests can be made in any GitHub-hosted 
 repositories/projects.
-You can sign up anytime between October 1 and October 31.

A Global Open Source Event - HactoberFest is organized every year worldwide. This year We, Students of CSE, are organizing and trying to Participate in this event. In this students participate and contribute to the online open-source projects. This will be totally online and we are taking care of all the arrangements so that all the participating students can attend it at a conference meet. 
In this students have to participate and contribute to the online open-source projects.

Google Meet :- Join In and let's pull it ......
https://meet.google.com/yif-ggid-jug




Date - 02-oct to 4- October
Timing-09:00AM to 1:00PM
How to permit nested parameters in Rails
Tags: howto, rails
Published: 2020-09-30 10:34:46

---
title: How to permit nested parameters in Rails
published: true
date: 2020-09-30 08:28:00 UTC
tags: howto,rails
canonical_url: https://flaviabastos.ca/2020/09/30/how-to-permit-nested-parameters-in-rails/
---

### The context

Rails 5 introduced a big change in how it handles `ActionController::Parameters` (the parameters that you get on your Controllers): before Rails 5, if you called your params you would get a hash back and after Rails 5, you get a `ActionController::Parameters` object. You can see that by calling `params.inspect` and if you call `.to_h` on these parameters you should be good to go.

However, you might get an empty hash when calling `.to_h` on some parameters because they were not explicitly permitted – see the result of inspecting my params (note the “permitted: false” at the very end):

```
<ActionController::Parameters {"friends" => {"park" => "Doggoland", "dogs"=>[{"id"=>73, "name"=>"Milou", "household"=>"Tintin"}, {"id"=>74, "name"=>"Snoopy", "household"=>"Charlie Brown"}]}} permitted: false>
```

Permitting params was showing up back in Rails 4 when Strong Parameters were introduced as part of security features and [this blog post goes through some examples](https://eileencodes.com/posts/actioncontroller-parameters-now-returns-an-object-instead-of-a-hash/) of why just calling `.to_h` might be an issue now that Rails 5 returns objects instead.

### Permitting parameters

One good way to permit some parameters is by creating a private helper function in your controller that will explicitly permit the parameters you want:

```
private def nice\_params params.permit(:id, :name, :email).to\_h end
```

When accessing your params, instead of `params[:name],` you use `nice_params[:name]`.

### Permitting nested parameters

Things get a little more complicated when you have a nested data structure. [The documentation only gets one level deep](https://api.rubyonrails.org/classes/ActionController/StrongParameters.htmlhttps://api.rubyonrails.org/classes/ActionController/StrongParameters.html) and I had something more complicated than that. Let’s use the following as an example:

```
{"friends" => { "park" => "Doggoland", "dogs"=>[{"id"=>73, "name"=>"Milou", "household"=>"Tintin"}, {"id"=>74, "name"=>"Snoopy", "household"=>"Charlie Brown"}] } }
```

My nice\_params function looks like this:

```
def nice\_params params.permit( friends: [:park, dogs: [:id, :name, :household]] ).to\_h end
```

One very important thing to notice is that the nested list must be placed last!

I hope this helps someone else with deep nested params. ![😅](https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f605.png)

* * *

> If you found this helpful, let me know on [Twitter](https://twitter.com/FlaSustenido)!

> _The post_ [How to permit nested parameters in Rails](https://wp.me/pa0b0y-7V)_ was originally published at _[flaviabastos.ca](https://flaviabastos.ca/)
Just Gotta Keep Working at It!
Tags: devjournal, react, womenintech, codenewbie
Published: 2020-09-30 08:19:25

_This post was originally published on September 30, 2020 on [my blog] (https://alexlsalt.github.io/blog)._

Nothing too new or too exciting to post this sunny, autumn-y Wednesday morning.

Still carrying on with my So You Think You Can France rebuild using React, slowly but surely. I had a great conversation with one of my mentors and friends yesterday, and just a couple minutes of talking it through got me so much more clear on moving forward with the project.

I'm finding that I have a good handle on React theoretically and on very small, manageable projects in practice - but as soon as I start moving on to more advanced concepts, my brain spirals out of control and I feel like I don't even know the absolute basics in React!

I think that's normal though. Just gotta keep working at it.

Oh, and I think I *am* gonna stick with Firebase Firestore for storing the data. If you've read before now, I was having a brief flirtation with learning SQL, but I think for now, I should try to focus on one thing at a time to improve and learn.

In other news, going to be publishing a new podcast episode today - yay! Onward.

----------


P.S. Did you know I have a podcast with new episodes each Wednesday? Go listen [right over here >>] (https://www.ladiescodecollective.com/podcast)

![The Ladies Code Collective Podcast cover art](https://dev-to-uploads.s3.amazonaws.com/i/e9bnxljvfrdjeti7fvbr.png)
Step out of your web dev comfort zone
Tags: webdev, node, javascript, cms
Published: 2020-09-30 08:17:35

When I first learned about web development, CGI-scripts was a thing and PHP was in version 3.x 😲 After not so long, I got confident with the [LAMP stack](<https://en.wikipedia.org/wiki/LAMP_(software_bundle)>), and it has been the setup on a majority of the projects I have worked on. That became my comfort zone.

Sure, since then I have done some hacking with the [CodeKit app](https://codekitapp.com) on some smaller projects, publishing them on GitHub Pages. But this spring, in perfect sync with Covid-19, I decided it was time to get serious with exploring new tools and methods for web development. New for me.

> My trick to step out of my comfort zone was to imagine myself as a 13-year-old kid, today.

What technics or languages would I have started playing with to get into web development now? Of course, I have no clue, and that's not the point. The point is it made me discard my old ways of thinking and look for something new to take that place.

What's your trick to step out of your comfort zone? And what did you find? I'm curious!

## Here is what I found on the outside

👉 The fresh, good looking, CMS systems call themselves _headless_. [The old ones](https://en.wikipedia.org/wiki/List_of_content_management_systems#PHP) are still around, but they do look old 🏚

👉 Node.js is everywhere. [Literally](https://www.youtube.com/watch?v=_1kETLlGn-8) everywhere.

👉 If you learn to use Heroku, Digital Ocean, or something similar you have the key 🔑 to build everything from tiny websites to large-scale businesses.

👉 Speaking of tiny websites, Static Site Generators are the over-engineered equivalents of uploading `about.htm` to `public_html/` over FTP.

👉 For every part of the process, there is an [As a service-alternative](https://en.wikipedia.org/wiki/As_a_service). Do you really have the argument to build it yourself?

Needless to say – I like it on the outside!
<br>
This text is crossposted from [my blog at psu.se](https://psu.se)
Blog Analytics without Javascript
Published: 2023-04-29 22:26:27

---
title: Blog Analytics without Javascript
published: true
date: 2020-09-28 23:46:00 UTC
tags: 
canonical_url: https://mikestaszel.com/2020/09/28/blog-analytics-without-javascript/
---

As part of my migration from Wordpress to Ghost, I wanted a way to see how many views my posts had. This blog only gets a few hits per day - but over 10,000 people have seen my content over the past 2 years which serves as an incentive to keep writing!

My requirements:

- It has to be free. A goal of this blog is to cost $0 to run (plus a few dollars per year for the domain name).
- I'd prefer no Javascript.

I looked at a few options:

- Google Analytics. It's free, simple, and everyone uses it. It also seemed like overkill for a blog that gets a few hits per day.
- [Simple Analytics](https://simpleanalytics.com). I couldn't find a free option, but this looked really neat.
- [Ghostboard.io](https://ghostboard.io/). No free option I could find.
- Nginx server access logs - I have these on disk!

The last option is the one I went with. Nginx access logs have all the information I need - a timestamp and URL requested. This is enough to show me visitors per day and the most popular blog posts.

But I did not want to read through a log text file to get this information. Luckily, there's an open-source project called [GoAccess](https://goaccess.io/) that visualizes server log files. With one command, I could get a visualization via an HTML file:

```
goaccess /var/log/nginx/access.log -o analytics.html --log-format=COMBINED
```

That's all there is to it. That command generates an HTML page with charts and graphs with everything I need:

![](https://mikestaszel.com/content/images/2020/09/analytics.png)<figcaption>GoAccess Analytics Screenshot</figcaption>
Install pgadmin4 using apt on Ubuntu 20.04
Tags: apt, postgres, pgadmin, ubuntu
Published: 2020-09-30 08:16:49

## Problem

You type `sudo apt install pgadmin`, press `TAB` and see only `pgadmin3` in recommendations. `pgadmin3` is currently obsolete and it doesn't even work properly with the latest PostgresQL!

## Solution

1) Install pgadmin's public key (if you haven't done this before)

```
curl https://www.pgadmin.org/static/packages_pgadmin_org.pub | sudo apt-key add
```

2) Add pgadmin's repo to your source list and run `update`

```
sudo sh -c 'echo "deb https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/$(lsb_release -cs) pgadmin4 main" > /etc/apt/sources.list.d/pgadmin4.list && apt update'
```

3) Install the package

```
sudo apt install pgadmin4
```

4) Run pgadmin4 in the console or from the main menu (press Win button and type "pgadmin"), done!

[Read more about postgres on my blog](https://ntscx.com/)
Why learning back-end made me a better front-end developer.
Tags: javascript, webdev, backend, frontend
Published: 2020-09-30 08:12:09

A year ago I started my journey in the web-development world. Like a lot of self-taught developers I took some courses on front-end development and started with some simple projects.
In these projects making API calls was an important part of the application. Whether it was with Axios or fetch. There were a set of rules I had to follow. When making a API call you had to make sure to include the following (some optional):

* URL
* Method
* Body
* Header

And I am probably forgetting a few more..
This didn’t really make sense for me at the time. I knew I had to include them when making a GET or POST request. I promised myself to maybe someday check it out.


A lot of bugs, red screens and liters of coffee later, we fast forward to 2020. The world is in the midst of a pandemic. Covid-19 is taking the world by storm and this meant for a lot of people working from home and a lot of extra time. Including me. This was the perfect time for me to deep dive into the world of back-end. Fortunately for me as a Javascript developer I was able to do this with Node.js and Express.js.

I took a comprehensive course on the topics by Maximilian Schwarzmüller. I This cleared up so much about the questions I had when working with fetch or Axios.

 Why is Content-Type sometimes application/json and other times a multipart/form-data?
*This depends on the size and data type you post.*

Why do we send params in a url?
*This is used in the back-end to retrieve the right data from the database.*

What is the reason we have to send bearer tokens with certain API calls?
*This is for security reasons, it allows us to get, post or update data only when we are authorized.*

And a lot more questions got answered!

This took a few weeks to complete but gave me a good understanding of the different parts of back-end development and a general basis of how it works. I believe this has changed me as a developer and really affected the way I work on the front-end side of my applications.

Not only because I now better understand how the data handling process in applications takes place, but now I also have a better grasp of what back-end developers go through and why they do the things they do. I am able to better assess whether certain issues should be handled on the front-end side of the application or the back-end side.

This is why I can really recommend other developers to take some time to learn the other side of the development spectrum you are working in. You are better able to have some empathy for the people you work with on different parts of an application, site or game. Do you have some free time? A game developer? Try making some 3d assets. Web developer? Make a simple back-end. Hotel? Trivago (Just kidding).