teleren/devto huggingface dataset:
Date handling bites again
Tags: dotnet
Published: 2020-09-23 08:11:17

Hi

One of my team mates found an interesting issue in our code-base so I thought I'd do a write-up.

**TLDR: Don't compare a DateTimeOffset to DateTime.MinValue, compare it with DateTimeOffset.MinValue.**

*Technically you could compare DateTimeOffset with DateTime.MinValue if you can guarantee that the system timezone will always be UTC or UTC minus some offset.*

## Into The Detail

Every request my teammate mate to our API was failing with the same exception, but despite running the master branch and the exact same request, I couldn't reproduce the error.

The exception was being thrown by the constructor of an `AbstractValidator` from the FluentValidation package.

```
public class TestValidator : AbstractValidator<ThingWithDate>
{
    public TestValidator()
    {
        RuleFor(x => x.Date)
            .GreaterThan(default(DateTime));
    }
}
```

This validator was injected into nearly every controller in our API via a BaseController (👍).

It turns out that to reproduce the issue I needed to run the service using the same system timezone as my colleague in the Balkans (UTC+3).

You can see from the stack trace that:
- We're initialising the `TestValidator`
- That is hitting the `DateTimeOffset` implicit cast operator to convert the `DateTime` to a `DateTimeOffset`. 
- That calls the `DateTimeOffset` constructor which accepts one `DateTime` parameter.
- The constructor calls `ValidateDate(DateTime, Timespan)`. The `TimeSpan` is the difference between UTC and the local system timezone.

Internally a `DateTimeOffset` is a `DateTime` and an offset in minutes. `ValidateDate`, unsurprisingly, ensures that the `DateTime` is valid when the offset is applied. When you apply a negative offset to `DateTime.MinValue` you get a date that can't be represented by the `DateTime` type and you get an `ArgumentOutOfRangeException` instead.

Here is the code for the validate method  [lifted from here] (https://github.com/microsoft/referencesource/blob/master/mscorlib/system/datetimeoffset.cs). Comments are mine...

```
private static DateTime ValidateDate(DateTime dateTime, TimeSpan offset)
{
    // +2 is 72000000000 ticks
    // utcTicks is converting the "local" dateTime to UTC by subtracting the offset
    Int64 utcTicks = dateTime.Ticks - offset.Ticks;

    // This section validates that utcTicks is a valid time that can be represented

    // utcTicks = -72000000000
    // DateTime.MinTicks = 0
    // -72000000000 < 0 == true => Kablamo
    if (utcTicks < DateTime.MinTicks || utcTicks > DateTime.MaxTicks)
    {
        throw new ArgumentOutOfRangeException("offset", Environment.GetResourceString("Argument_UTCOutOfRange"));
    }
    return new DateTime(utcTicks, DateTimeKind.Unspecified);
}
```
yum --disableexclude
Published: 2020-09-23 07:56:07


    To disable the excluded packages mentioned in a repo file, --disableexclude function is used by yum as follows :-

```
--disableexcludes=[all|main|repoid]
              Disable the excludes defined in  config files. Takes one of three options:
              all == disable all excludes
              main == disable excludes defined in [main] in yum.conf
              repoid == disable excludes defined for that repo
```
2 Quick Tips when working with JS console output
Tags: javascript, typescript, webdev, node
Published: 2020-09-23 07:54:44

Here are 2 quick tips you can use when working with the output from JS console:

## 1) Displaying data
If you are displaying arrays or objects, use `console.table` rather than `console.log`:

```js
// try running this:

console.table([
	{ firstName: 'John', lastName: 'Doe', age: 2 },
	{ firstName: 'William', lastName: 'Shakespeare', age: 3 },
]);
```

This will display the data in a nice tabular view as shown below:

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

## 2) Copying data

If you are working with Google Chrome & need to copy data from the console output, instead of manually highlighting & copying the data, you can run this:

```js
const data = [2, 3, 4];
copy(data);
```

This will copy the data to your clipboard.

**NOTE**: the `copy` command is only available on Chrome & not on the node.js env.

---

Have fun coding! 🎉
Sundae Club - Ruby on Rails Livestreams for Learners
Tags: rails, ruby, webdev, beginners
Published: 2020-09-23 07:48:00

---
title: Sundae Club - Ruby on Rails Livestreams for Learners
published: true
description: A post about Sundae Club, weekly live-streaming of Ruby on Rails coding.
tags: rails, ruby, webdev, beginners
//cover_image: https://direct_url_to_image.jpg
---

I’ve recently started live-streaming Ruby on Rails coding again 🎉 I really enjoyed the stint I did last year and appreciated everyone that got in touch.

Check out my new channel, [Sundae Club](https://www.youtube.com/channel/UC6JPQW8LnAZyfC_rUZqDqqA), where we'll be working on a Rails app together.

Each week (usually Sunday morning, UK time) I’ll be working on a different part of the app and, as it develops, use questions from learners to experiment with different approaches for different features.

The livestreams aren’t tutorials, they’re more like working on some code together in real-time, but I hope they’ll be useful for people that have started, or are interested in, learning Ruby on Rails.

I'm also hoping that nothing needs to be watched live, all the streams are saved as YouTube videos, so you can go back and watch anything you find useful.

Here are the first few streams if you want to check them out:

‘rails new’ for the first time in a long time. - https://youtu.be/2_pUPKCVX28  
Creating our initials models, associations and a front-end. - https://youtu.be/vQjw5uUAx5k  
Rebasing work-in-progress git commits into a pull request - https://youtu.be/z1XjfGFl5qQ
What's you favorite headless CMS?
Tags: webdev, discuss, productivity
Published: 2020-09-23 07:46:27

---
title: What's you favorite headless CMS?
published: true
description: 
tags: webdev, discuss, productivity
cover_image: https://img.storyblok.com/h_Lr-cgu6UQCnNhjL9hxx_6GdKk=/840x0/filters:filters:fill(FFFFFF):filters:format(jpeg)/f/51376/5303x1881/3de28deb84/headless-cms-vs-monolithic-cms.jpg
---
A headless CMS is a back-end only content management system (CMS) built from the ground up as a content repository that makes content accessible via a RESTful API for display on any device.

So far I've aware of Contentful, Sanity, Strapi and Ghost.

Which is your favorite headless CMS and why?
Removing duplicate code from the codebase
Tags: help
Published: 2020-09-23 07:43:21

So... when there're features development going on, we developed the feature and published it. But at some point, new features arrive and it may so happen that we can't support it with the existing desing so we introduce design patterns i.e. factory, strategy, etc and incorporate those changes. 

Say, for example, a factory pattern is introduced and currently there're two different types of classes A and B.
And the factory method is responsible to generate an instance of A or B based on some logic.

And later, say for new requirements, there's a new class C. And A, B, C has 4 functions to do. A, B, C has been implemented based on an interface abstracting the core logic.

Now two functions of C is similar to B but two functions of C is different than B. Now as interface has been used here, then we have duplicate code in our codebase.

The two functions of B and C who does the same thing is duplicated in the codebase.

In such scenarios, what are the best practices to - 

1. Implement these in such a way so that diplicay does not arise in the first place?
2. If no 1 is not possible then how to remove duplicate code from the codebase?
Automation, Data & Analytics, Cloud
Tags: qaautomationtesting, softwaretesting
Published: 2020-09-23 07:33:43

 Automation, Data & Analytics, Cloud Test automation services include the implementation of a wide set of testing and around-testing components. From test automation planning and tool selection to the construction and maintenance of a test automation environment, implementation of automated test data preparation, design and maintenance of all types of automated test scripts and more.
Seeding Data In Ruby On Rails
Tags: rails
Published: 2020-09-23 07:27:37

I've been working on recording a few of my presentations, I still don't think I've perfected the style or production quality, but I'd love to hear any feedback on how to improve :)

{% youtube _HSudwhdAR8 %}

In this video, I went though seeding in Ruby On Rails. Quite often I pickup projects where to get a local development environment up & going, I'm handed a production Database & left to it.

I'm a much bigger fan of using tools like Faker to generate useful seeds.

## Mentioned Links

https://github.com/james2m/seedbank
https://github.com/faker-ruby/faker
https://thoughtbot.com/blog/factory_girl-for-seed-data
https://github.com/evilmartians/evil-seed
https://guides.rubyonrails.org/v5.0.0/active_record_migrations.html#migrations-and-seed-data
ssh can not resolve hostname in included config file
Tags: ssh
Published: 2020-09-23 07:26:22

I used Include directive to include ssh config generated by vagrant ssh

    vagrant ssh-config > ~/.ssh/vagrant.d/centos4k8s.config

add

    Include vagrant.d/*

to ~/.ssh/config before the `Host *` section, but when I try to ssh into the guest, I get an error like

> can not resolve hostname <guest-name>

Then I put the ssh config generated by vagrant in to the ~/.ssh/config directly (without the use of `Include`, I put it before any other directive), then it works ok

I noticed that I have Include directive in the included file

    Host master-1                                                                                                                                                                                                      
    Include /home/hi/.ssh/vagrant_config

and the content of vagrant_config is

```
Host *
    ControlPath ~/.ssh/controlmasters/%r@%h-%p
    ControlMaster auto
    ControlPersist 10m
```

maybe the duplicated `Host *` has caused the problem

I change back to use `Include vagrant.d/*`, but I put it in the first line of ~/.ssh/config, it also works
WeAreDevelopers Live Week – Second edition
Tags: developerconference
Published: 2020-09-23 07:23:54

{% youtube d01-DQe2i_I %}

**[WeAreDevelopers Live Week – Second edition](https://wearedevelopers.com/live/live-week) is coming up on 5-9th October!**

Join 12,000+ of the brightest minds in software development to learn, share secrets and connect online from the comfort of your home.

For 5 days, WeAreDevelopers will stream 5 tracks, consisting of hyper-focused coding sessions, hands-on workshops and live Q&A sessions to help take your skills to the next level.

**Participation is free, [registration is needed.](https://wearedevelopers.com/live/live-week)** We hope you like the event.
Introduce the new PlantUML IntelliJ Plugin, which has high functionality editor!
Tags: uml, plantuml, intellij, showdev
Published: 2020-09-23 07:23:29

I develop new PlantUML IntelliJ Plugin with an editor function that also supports PlantUML syntax,so I introduced it features!

https://plugins.jetbrains.com/plugin/14821-plantuml-studio

It has been released as a paid plug-in, and I plan to continue active development in the future,
so I would be very grateful if you could give us feedback.


# Features

## Editor

### Syntax Highlighting

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

All major UML diagram's syntax are supported, including class diagrams.
Other diagrams that cannot be supported will be supported in the future.


### Auto Completion

It provides the completion of keywords optimized for each notation of each diagram and the completion of simple Identifiers.
Like the below image, It focuses reducing the things to remember and improving visibility, I think which lead to more comfortable writing.

_Auto completion sample on the sequence diagram_
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/e9q5mebkht919vpzfjnm.png)


### Refactoring

It provides the rename feature of identifiers.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vdd4xltbjyt80qsesyjf.gif)


### Code formatting

It provides the auto indenting when entering block token(ex: {})

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

It also supports batch conversion using "Code" > "Reformat Code" in the menu.

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


### Auto inserting a closing tag

For smooth writing the block syntax, It provides automatic input a closing tag.

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


## File Viewer

I put PlantUML codes in a project, and I wanted a feature to view a list of PlantUML files, so I made a simple one.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/2mb3x5wmjikbwmgjmvtc.gif)


---


I think PlantUML is a powerful tool for drawing nice diagrams with simple code,
I also think that it can be a more powerful tool when combined with a good editor.

Once again, I'm waiting for your feedback!
What is the lighthouse score of your porfolio/personal website (and why)?
Tags: portfolio, lighthouse, discuss
Published: 2020-09-23 07:23:13

I want to discover new portfolios, and in order to do it I want you to post and discuss your lighthouse score.

*For thoses who don't know what I'm talking about, [here's the doc](https://developers.google.com/web/tools/lighthouse) for lighthouse.*
Top Projects in Python
Tags: python
Published: 2020-09-23 07:18:18

Hey guys,this is Satyam and in today's blog I am going to discuss about some of the cool projects which I have built on Python's Libraries such as Tkinter or Pygame and some on selenium and those which are my personal favorite,if you can build all of these you can consider yourself a Good Python Programmer.

#1.Hangman game
This is the classic game “Hangman”. The word to guess is represented by a row of dashes. If the player guess a letter which exists in the word, the script writes it in all its correct positions.  The player has 10 turns to guess the word. You can easily customize the game by changing the variables.You can either build a console based Hangman game or a GUI based hangman game.

#2.Snake Game
This is another awesome project on Python,you can built it using Tkinter or Pygame,this is a very traditional game  which is with us from a long time.

#3.Rock Paper Scissors Game
I have built this game on the top of the pygame library,believe me  you will enjoy building this game,you can either built the console based version of this game or the GUI based version of this game using Tkinter or Pygame Library but I will prefer you to use the Pygame Library.

#4.Ludo
This is a awesome board game which four peoples play,so you can built it using the popular pygame library in Python.This is also very easy and enjoyable project in python according to me.

#5.Tetris
Tetris is one of the most popular games in the world and According to Wikipedia,[100,000,000] units of Tetris has been sold till now.It was first launched in September 12, 2006.You can easily build a clone of tetris using Python's Pygame Module.

#6.File Explorer
File Explorer is a simple application is used to navigate to all the files and folders in your system.You can create a simple File Explorer in Tkinter.

#7.Fruit Ninja
Fruit Ninja is a good game for kids,I have already built this game for android actually a clone not my own creation but in this blog we are focusing on desktop apps,so you can built it using pygame but if you want to code it for Desktop,but at the same time if you want to build it for android you can use a python library called Kivy.

#8.Speed Typing
This will be a desktop app which will allow us to type a given paragraph and it will measure the time taken by you for typing that paragraph.

#9.Library Management
This is a GUI Application which you can built on the top of tkinter library,I have built the same using tkinter,It's on my github repo it's not complete built completely but it will help you to understand:
Project:https://github.com/SkvProgrammer/library-mangement-system-in-python-tkinter

#10.Ping Pong Game
Table tennis, also called (trademark) Ping-Pong, ball game similar in principle to lawn tennis and played on a flat table divided into two equal courts by a net fixed across its width at the middle.The game is popular all over the world.This is the project based on Pygame.

This is not the complete article,if you wish to read the complete article you can go to https://www.devtipsntricks.com/2020/09/top-20-awesome-projects-in-python.html
Contribute to and Open Source Python project - Create a Pull request to add the author field
Tags: python, github, opensource
Published: 2020-09-23 06:13:33

---
title: Contribute to and Open Source Python project - Create a Pull request to add the author field
published: true
description: Start Contribution to Open source software with a  small steps
tags: python, github, opensource
//cover_image: https://direct_url_to_image.jpg
---

{% youtube HuL2WSgP2mU %}

[PyDigger](https://pydigger.com/) collects meta-data about Python packages uploaded to [PyPi](https://pypi.org/). Some of the meta-data is missing. This video explains how to add one-of them and thereby start contribution the the body of Open Source software.
PODS in Kubernetes for Developers
Tags: kubernetes, devops
Published: 2020-09-23 06:08:56

####Here, we will take a look at PODS.
* POD introduction
* How to deploy a pod?

Kubernetes doesn't deploy containers directly on the worker node.
* The containers are encapsulated into a Kubernetes object called POD.
* A POD is a single instance of an application.
* A POD is the smallest object that you can create in Kubernetes

Here is a single-node Kubernetes cluster with a single instance of your application running in a single docker container encapsulated in the pod.

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

A Pod usually has a one-to-one relationship with containers running your application.
* To scale up, you create a pod, and to scale down, you delete a pod.
* You do not add additional containers to an existing POD to scale your application.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n0e5f8n6j6zfkvbpopnx.png)

####Multi-Container PODs
* A single pod can have multiple containers except for the fact that they are usually not multiple containers of the same kind.
* Sometimes you might have a scenario where helper containers that might be doing some kind of supporting tasks for a web application such as processing a user-entered data, processing a file uploaded by the user, etc. and you want these helper containers to live alongside your application container. In that case, you can have both of these containers part of the same POD.

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

####How to deploy pods?
Let’s now take a look to create an Nginx pod using kubectl.

To deploy a docker container by creating a POD.
`$ kubectl run nginx --image nginx`
 
To get the list of pods
`$ kubectl get pods`

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

####K8s Reference Docs:
[https://kubernetes.io/docs/concepts/workloads/pods/pod/](https://kubernetes.io/docs/concepts/workloads/pods/pod/)
[https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/)
[https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/](https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/)
 
###Access [certified Kubernetes administrator course with practice tests](https://kodekloud.com/p/certified-kubernetes-administrator-with-practice-tests?utm_source=pbel&utm_medium=DevTo&utm_campaign=%26src%3Dpbel_devto)
Looking for people to collaborate with ? Join our community to find like-minded people.
Published: 2020-09-23 04:21:45

Join our web dev community to find helpful and like-minded individuals join <a href="https://discord.gg/E52dCUb">here</a>

UNDER Web World is a new Discord server for developers who...
<br/>
>🐥 Want to find like-minded individuals with similar interests in web development.
🦄 Need help on their web-related projects.
🐸 Seek to hire talented developers, or seek to be hired for their talents.
🧬 Want a place to share, talk about, and find information on web-related projects.
⚡ Looking for collaborators for your projects.

<br/>
Web developers of all kinds are invited whether you're a pro, a beginner, or simply are interested in learning a thing or two, you're welcome to join us.
<br/>
We currently have channels for a bunch of JavaScript frameworks, such as React.js and Electron.js. We've also created channels for most of the common languages, such as CSS, HTML, PHP, Python, and more.

We're actively developing this server, so we're open to creating new web-related channels desired by users.

The server also has a fair bit of recruiters and a bunch of people have already been hired 😉.
CodeQL Analysis on GitHub 
Tags: github, codenewbie, security, tutorial
Published: 2020-09-23 05:40:36

## Enabling Code Scanning - CodeQL Analysis using GitHub Actions

**Note: Code Scanning is currently in Beta - Join the waitlist using this [link](https://github.com/features/security/advanced-security/signup)**

For demonstration, I will use a repository with known security vulnerabilities and coding errors, former of which were also tacked using GitHub Native Dependabot Application, to see that blog, please visit the link below.

{% medium https://medium.com/@noicecurse/shifting-from-dependabot-preview-to-github-native-dependabot-app-3f39037fb69c %}

{% github https://github.com/NishkarshRaj/Maven-Using-CMD no-readme %}

### Step 1) Click on Security Tab on your Repository

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

### Step 2) Under Code Scanning Alerts - Click on Code Scanning

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

### Step 3) Setup CodeQL Analysis GitHub Actions

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

Let's take a look at the GitHub Actions Job YML script and understand few important points:

{% gist https://gist.github.com/NishkarshRaj/9e0eb58969e5883d3c23e2214939a58e %}

* When will the Action perform the analysis:

**1. Event Driven:**

    i. Push - Push event on master branch

    ii. Pull_request - Pull Request on master or any sub branch.

**2. Time Driven:** Cron Schedules can be created. Cron is an open source package used to schedule tasks and events. To learn more about Cron Jobs, use this [link](https://man7.org/linux/man-pages/man5/crontab.5.html).

It will take few minutes for the CodeQL Engine to analyze your repository for the first time. Wait till the Action jobs have successfully finished.

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

### Step 4) View the GitHub Native Alerts Dashboard

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

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

Hurray! :heartpulse: 

There were no errors or security issues in this repository.

In Part 3, I will create a demo repository and add intentional code and security errors and let's see how CodeQL Engine would help us with it. :smile:

### References

https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/enabling-code-scanning-for-a-repository

### Adios

The posts are meant to spread awareness about the latest tips and tricks for upcoming and trending technologies in the software world.

If you like this work, please support me by following me on Dev, [GitHub](https://www.github.com/NishkarshRaj) and [Twitter](https://www.twitter.com/NishkarshRaj1). Cheers! :heart: