teleren/devto huggingface dataset:
Enum dropdown with readable values in rails
Tags: rails, beginners, webdev, html
Published: 2020-12-19 00:53:28

For the sake of quick documentation of a common use case.
If you have a model, which has an enum attribute and you want to have a select tag(dropdown) with titleized values(no ugly underscores) of the enum and you also want to store the data in its original(enum form). 
Here's a quick example
```ruby
# app/models/source.rb

class Vendor < ApplicationRecord
  # in the db schema, vendors table has payment_type column with integer datatype(the datatype can be different, no issues)
  enum payment_type: [:one_time :recurring :not_known]
end
```
Then in your view file, where you want to display the dropdown for that enum attribute

```erb
<%= form_with(model: @vendor, local: true) do |form| %>
  
  <%= form.label :payment_type %>
  <%= form.select :payment_type, options_for_select(Vendor.payment_types.map {|key, value| [key.titleize, Vendor.payment_types.key(value)]}, @vendor.payment_type) %>

  <%= form.submit %>
<% end %>
```
That's all.
With this done, your dropdown will display three options with the text 
`One Time`, `Recurring`, and `Not Known`
while when you submit the form the submitted value of `payment_type` will be 
`one_time` or `recurring` or `not_known`
depending on which option you selected from the dropdown.
Ruby's Tally Method
Tags: ruby, codenewbie
Published: 2020-12-19 00:48:07

Ruby's `tally` method was [introduced in 2.7](https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/). It's a super convenient method on `Enumerable` that I was [recently able to use](https://github.com/meaganewaller/aoc/blob/main/2020/day-06/puzzle.rb). `Tally` counts each element's occurrences and returns a hash where the key is the element, and the value is the count.

## Pre-Tally

If you are like me, any time you needed to get back a count of the times an element showed up in a collection, you headed over to StackOverflow and looked up how to do it. You probably ended up implementing something that looked like one of the examples below:

```ruby
list = ["a", "b", "b", "a", "c", "d", "d", "d", "e"]

list.group_by { |v| v }.map { |k, v| [k, v.size] }.to_h
#=> {"a"=>2, "b"=>2, "c"=>1, "d"=>3, "e"=>1}

list.each_with_object(Hash.new(0)) { |v, h| h[v] += 1 }
#=> {"a"=>2, "b"=>2, "c"=>1, "d"=>3, "e"=>1}
```

Maybe you needed to count how many times some value showed up in a collection of hashes.

```ruby
hashes = [{name: "Meagan" }, { name: "Meagan" }, { name: "Lauren" }]

hashes.group_by(&:itself).map { |k, v| k.merge(count: v.length)}
#=> [{ :name => "Meagan", :count => 2}, { :name => "Lauren", :count => 1 }]
```

## Using tally

`Tally` makes that collection into hash transformation so much easier.

```ruby
list = ["a", "b", "b", "a", "c", "d", "d", "d", "e"]
list.tally
#=> {"a"=>2, "b"=>2, "c"=>1, "d"=>3, "e"=>1}
```

Bam. You did it. Let's use `tally` on our collection of hashes example.

```ruby
hashes = [{name: "Meagan" }, { name: "Meagan" }, { name: "Lauren" }]
h.tally
#=> {{:name=>"Meagan"}=>2, {:name=>"Lauren"}=>1}

hashes.tally.map { |k, v| k.merge({count: v}) }
#=> [{:name=>"Meagan", :count=>2}, {:name=>"Lauren", :count=>1}]
```

It still requires a little bit of munging to get the same return we got in the pre-tally example.

## Conclusion & Further Reading

I hope that you found this useful and can add `tally` to your toolkit. Knowing `tally` means one less Google search I'll need to do in the future when I've got to count occurrences of an element in an array.

- [Feature discussion on Ruby lang](https://bugs.ruby-lang.org/issues/11076)
- [Ruby specs for `tally`](https://github.com/ruby/spec/blob/master/core/enumerable/tally_spec.rb)
Our Display Git Status plugin has just been approved on the WordPress.org plugin marketplace
Tags: wordpress, git
Published: 2020-12-19 00:14:06

[Display Git Status](https://wordpress.org/plugins/display-git-status/) is a utility plugin to provide basic git status information right in the WordPress admin bar.

We have created this plugin as a complimentary and free plugin for our users. Given our service offers Git source controlled plugin and theme updates. It's obvious such a feature would be beneficial right within the admin area. And we were surprised there wasn't already a solution.

This plugin is great as a gentle reminder or flag to see if your staging or even production site becomes out of sync with your repository.

![Display Git Status Settings Page](https://wpgitupdater.dev/storage/uploads/display-git-status-screenshot.jpg)

Once activated just look out for the admin bar icon link turning to a red background, which indicates there are changes you probably need to investigate.

We have added a new page to the documentation for our plugin (soon to be plugins) [here](https://wpgitupdater.dev/docs/latest/plugins#display-git-status).
Why I hate being a developer around Christmas time.
Tags: discuss, programming
Published: 2020-12-20 04:14:20

---
title: Why I hate being a developer around Christmas time.
published: true
date: 2020-12-19 00:00:00 UTC
tags: discuss, programming
canonical_url: https://chand1012.dev//ChristmasTimeRant/
---

Christmas time is a time of joy, family, giving, and life. Unless its 2020.

Jokes aside, there was always one thing about Christmas time that grinded my gears, and I think it can partially be portrayed with this meme:

![](https://raw.githubusercontent.com/chand1012/chand1012.github.io/master/images/techguymeme.png)

This is especially true around Christmas time. When your Grandmother or some older member of your family gets a new piece of technology and as far as they're concerned the only thing you study is “computers” so they assume you can help them. Well, I’m a programmer not the annoyed IT guy from your work.

Now don’t get me wrong, I don’t mind helping if you ask, but this rant isn’t so much about helping people, as it is a rant about the misunderstanding of my field and how some people react when I tell them “I don’t know”.

> “Well aren’t you supposed to be good with computers?”

Not all of them at once.

Just because I _work_ on a computer all day, does not mean I am **an expert on literally anything computer related**. No, I do not know how to set your printer up. No, I don’t know why your computer is running slow all of a sudden just because you said “All I use it for is email”. No, I don’t know why or how your Facebook got hacked.

Now I understand there are many people who do not understand computers and these are not stupid questions to them as they are legitimate concerns. However, these are not questions I can answer without knowing all the information. I need to look at the printer manual to set it up. I need to take a look at your computer and see what you accidentally downloaded from the “free gift card” websites. If you clicked on a link that looked like it was from Facebook, but asked you to log in again even though you’re already logged in, you just gave your username and password away to a hacker (okay I can sort of answer that one). Anyone who’s reading this probably gets what I mean though.

If you have any experiences about this you would like to share, please leave a comment either on this post or on my [GitHub Discussions Forum](https://github.com/chand1012/chand1012/discussions/2)!

Have a safe, socially distanced, and Merry Christmas! And Happy Holidays!
Ignore Azure Functions application settings drift in Terraform
Tags: devops, terraform, azure, cd
Published: 2020-12-18 23:43:59

**`<TLDR>`** Add application settings causing configuration drift to `ignore_changes` lifecycle hook in function app resource configuration in Terraform. **`</TLDR>`**

**The problem**

You define your cloud infrastructure as code with Terraform and provision all resources. One of the resources is a Function App, based on Linux running in Consumption plan.

You deploy your application code with Azure Functions Core Tools. It uses [external package url](https://docs.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies#external-package-url) deployment method behind the scenes. Essentially it will upload your code to Azure Blob storage account and will mount it as a read-only directory in the Function App at `/home/site/wwwroot`.

You run `terraform plan` or `terraform apply` and you see there are changes in the remote resource: `WEBSITE_RUN_FROM_PACKAGE` setting has now value similar to `https://storageaccname.blob.core.windows.net/function-releases/2020...long-list-of-arguments`. That's the value set by the depoyment tool.
There's no point in importing it to Terraform state since it will change with every application code deployment.

It would be great if we could set `WEBSITE_RUN_FROM_PACKAGE=1` application setting once and for all. It means deploy the package not to the remote storage, but to the [function app host](https://docs.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package#enabling-functions-to-run-from-a-package) itself, and mount it to (again, read-only)`/home/site/wwwroot`. But unfortunately it's [not yet supported](https://github.com/Azure/azure-functions-core-tools/issues/2356) by Linux in Consumption plan.

What else can we do?

**Solution**

In your function app resource in Terraform, set application setting `WEBSITE_RUN_FROM_PACKAGE=""` and tell Terraform to ignore any future changes of this setting in the remote state.

```hcl
...

resource "azurerm_function_app" "function_app" {
  ...

  app_settings               = {
    "WEBSITE_RUN_FROM_PACKAGE"       = "",
    ...
  }

  lifecycle {
    ignore_changes = [
      app_settings["WEBSITE_RUN_FROM_PACKAGE"], # prevent TF reporting configuration drift after app code is deployed
    ]
  }
}
```

That's it. Terraform will no longer warn you about the value of `WEBSITE_RUN_FROM_PACKAGE` being changed. Hopefully Function Apps in Linux Consumption plan will support `WEBSITE_RUN_FROM_PACKAGE=1` setting soon and we won't need this workaround.

*If you like this type of content you can [follow me](https://twitter.com/max_v_i) on Twitter for the latest updates.*
Almost a month since I started studying Swift and that what I learned
Tags: swift, beginners
Published: 2020-12-18 23:43:57

---
title: Almost a month since I started studying Swift and that what I learned
published: true
description: 
tags: swift, beginners
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/aqtyguk5seavuxdbague.jpg
---

It's almost a month since I started working with Swift and I don't think we're getting along.

### I don't like Xcode

The IDE - Xcode - is weird. Maybe you get used to it with time but after a month I still struggle. Too many options, to many "things" besides the code.. I don't know, I just don't like it. I can't compare it to Android Studio, for example, because I didn't use it recently. But I have good memories of it from  University when I worked on an Android project for an exam.

### The emulator is awesome, though

I found very easy debugging my apps on the emulator. Its "smoothness" and speed are things I'm going to miss.
 
### Conclusion

I don't think I'm going to finish my 100 Days of Swift.. Sadly. It was a great thing to do and I found fantastic resources but it's not for me. I don't feel the magic of it - which I feel for other things like React and/or GraphQL.

Goodbye Swift.

![Goodbye Swift](https://media.giphy.com/media/l49FqlUguNsGDNCGk/giphy.gif)
How do you choose a subject to stick to on your blog?
Tags: discuss
Published: 2020-12-18 23:06:27

I am interested in so many subjects that it makes it difficult for me to choose one to blog about. 

If you take the dev world alone, I love talking and reading about containers, microservices, API gateways, data structures, algorithms, Java, Spring, Flutter, Go, Rust, React, Next.js, Jamstack, NoSQL, Kafka... Yes, I am a generalist. That's what 25 years of CompSci do to you.

It doesn't stop there. I love Game Dev! Shaders, procedural generation, 3D modeling, sound design... speaking of which remembers me of my recent passion for samplers and synthesizers, musical production, piano, music theory, drums... And a bazillion other random things like cars and motorsports, knowledge organization techniques like Zettelkasten, personal finance and investments, well... you get the idea.

How do you guys stick to a narrow range of subjects to blog about? Am I getting crazy, a kind of knowledge addicted junkie? Should I create N blogs to spread the word about whichever comes into my radar?
Twitch Recap: Q&A on How Traffic is made!
Tags: techtalks, wecoded, codenewbie, bigdata
Published: 2020-12-18 22:53:05

Hey everyone! Here I'll be recapping our last TomTomDevs Twitch stream of the year, which was this Tuesday! Check out the full recap [here](https://www.twitch.tv/videos/838516180).

This episode was a little different, as instead of a purely coding tutorial, we decided to get a bit more open-ended and bring up some important questions about working with traffic. We didn't go it alone, however -- we brought in reinforcements, aka TomTom Product Marketing Manager, Jonathan Americo!

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

Featuring some of the traffic facts shown above, the world has seen massive changes in traffic patterns this year, which is why we answered some key questions.

1. Can we fool TomTom traffic with a bucket of phones?

In short, you actually can't! Phones are able to send nuanced indications of movement, so we can tell if a phone is moving only a few inches at a time, or is extremely close together. One might indicate a pedestrian, and the other a carful of people - neither of which are individual traffic points.

2. Will COVID-19's wild outlier traffic patterns influence historical traffic profiles of roads and road segments?

This is a good one! 2020's lack of traffic is definitely a part of history - and so, we are working on ways to ensure that it is differentiated in such a way, such as creating a short-term historical view.

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

For more questions and answers, watch our recap, and otherwise... Happy Holidays, and Happy Mapping!
Ce que j'ai appris avec OBS
Published: 2020-12-18 22:32:23

Voici un retour d'expérience sur OBS si vous souhaitez vous améliorer dans la qualité de vos viso-conférences ! 🎥

Plus d'infos sur mon blog :

https://blog.darkwood.fr/article/ce-que-jai-appris-avec-obs

Je serais ravis d'échanger avec vous sur le sujet.
Running Static Analysis on Kubernetes Manifests - Isn't Just For Code Anymore
Tags: docker, devops, kubernetes
Published: 2020-12-18 22:30:19

Running static analysis during a CI/CD pipeline is typically used for the purposes of finding formatting issues, spotting common mistakes and ensuring consistency in code before it is even compiled or tested.  There are tools available that are capable of performing similar checks against kubernetes manifests and also helm charts.  Adding these checks will allow the team to find problems in kubernetes configuration before they are attempted to be applied or deployed.  These tools provide slightly different levels of functional value depending on what they are verifying.

## API Based Validation
There are tools available, such as [kubeval] (https://www.kubeval.com/) that validate your kubernetes manifests against a given API schema.  It provides the option to pass particular version of kubernetes when doing the validation to ensure that your manifest files conform to that version's schema.  Since a tool like this is just validating that the yaml is correct against a particular schema and API it does not do any checking of security issues or allow for customization.  

## Pre-built Rule Based Validation
Tools such as [checkov] (https://github.com/bridgecrewio/checkov) are more rule based and validate your kubernetes manifests against a set of rules.  These are typically industry best practices and also known security issues.  These types of tools can also be extended to add your own custom rules to allow for enforcement of any consistent requirements you have in your manifests.  An example might be if you require each resource to have a certain label you could add a custom rule to enforce that it always exists.

## Helm Linting and Validation
If you are using helm charts you can use most of the tools available to run the same checks but you must first run a ``helm template`` command and then send the resulting output yaml to the tool.  Helm has a lint command that allows for checking that directory structure and pre-requisite files exist to properly template and package the chart.

## Finding Problems Sooner is Good
By adding some sort of static analysis to your kubernetes files to your CI/CD pipeline you can find and address configuration or consistency issues faster and easier.  Feel free to search around and look at different tools and options.  I have just included a few here to start the journey.  You may find that you like one over the other or something meets your needs for different reasons.  You also need to decide the types of things you want to check and enforce.  Maybe you just want to start with linting your helm charts and a second step is to add an opinion based check.  It is all up to what you find value in at the time.

<a href="https://dev.to/leading-edje">
  ![Smart EDJE Image](https://dev-to-uploads.s3.amazonaws.com/i/5uo60qforg9yqdpgzncq.png)
<a/>
On .NET Episode: What is MSAL + Microsoft.Identity.Web?
Tags: dotnet, webdev, security, aspnet
Published: 2020-12-18 22:17:20

Microsoft.Identity.Web enables developers to create web apps that sign-in users and create protected Web APIs using the Microsoft identity platform.

In this episode, Kyle Marsh comes on to catch with Christos about the new Microsoft.Identity.Web package for .NET developers. They go over the goals of the library and even show a quick demo of how to get started with it.

{% youtube i7_Fj1zFLO0 %}

If you liked this video and would like to see some more of our .NET content, please subscribe to our [.NET Developers YouTube Channel](https://www.youtube.com/channel/UCvtT19MZW8dq5Wwfu6B0oxw).

#### Useful Links
<ul>
<li><a href="https://developer.microsoft.com/en-us/identity/blogs/microsoft-identity-web-is-now-generally-available?WT.mc_id=dotnet-00000-cephilli" target="_blank">Microsoft.Identity.Web is now generally available!</a></li>
<li><a href="https://github.com/AzureAD/microsoft-identity-web?WT.mc_id=dotnet-00000-cephilli" target="_blank">Microsoft.Identity.Web on GitHub</a></li>
<li><span class="s2"><a href="https://docs.microsoft.com/aspnet/core/security?WT.mc_id=dotnet-00000-cephilli" target="_blank">ASP.NET Core Security Overview</a></span></li>
</ul>
Turning that project into a business 
Tags: business, newbie, projecttobusiness
Published: 2020-12-18 22:15:59

We have heard of many bigshot companies that started out in garages, dorm rooms, and basements. The likes of Amazon, Disney, Facebook, and Apple just to mention a few. All of them started out as projects, most of them never foresaw the success they have achieved now. Now, most have taken part in hackathons or implemented projects and have wished their projects would turn into a business idea. I know I have. So, how do you go from that "garage" to a business? 






**1.Research!Research!Research!**
Just as I expect a lot of research went into coming up with the project idea, the same goes during this phase. However innovative and smart you think your idea is, it is always a good idea to look up whether it already exists in the market and if it does how many competitors are in that market, and is the potential market going to be able to generate a sustainable income for your business? It can be rather daunting as a start-up to join an already competitive market and counterproductive to start a business with a small market potential to keep you in business. 


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









**2.Just Go!**
Now that you have established that you have a prospective business in your hands where do you go from here? Just start! Do not get so hung up on what you don't have; use what you do. Do presentations to your classmates, a mentor (if you have one), or your college professor and get their feedback. 
Take for example Mark Zuckerberg, founder of Facebook, he would talk to classmates about his idea and continued perfecting it from the discussions he had with them. Do not shy away from applying for student grants. The most important thing is to continually be in motion. Even the laws of physics say that an object cannot gain momentum unless it's already in motion. Well, guess what, the laws of physics apply to you too.


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







**3.Work on your project every single day**
That sounds like a little bit of a stretch. Everyday? Really? It could be a few minutes daily, it could be an hour depending on your inspiration, it doesn't matter as long as you clock in a day's work. The point of it is to keep you in the focus of what your end goal is and that is to bring your business dream into reality. it also helps you fine-tune your project and keep polishing it and finding new ways to improve on it.







**4.Sell your idea**
Now that you have done all this work, it's time to sell your idea. This is to attract investors. Again, this is where feedback from your classmates and possibly more experienced people like your college professor will come in handy. You need to learn how to pitch to investors, at this point your work probably sells itself but why not give it an extra nudge with your pitching skills. 
This is a whole other topic for another day😊😉.
Django In PyCharm Educational
Tags: python, django, beginners, webdev
Published: 2020-12-18 22:10:03

# How to start

- You create your own project 
- You open the terminal 

## Installing an official release with pip

- You Write down : python -m pip install Django

## Installing the development version

- You clone the repo from github :git clone https://github.com/django/django.git
- python -m pip install -e django/