The secret "formaction" attribute

Recently I came across a use case of a form which needed two submit buttons. One submit button would just save the data for further edition. Second submit button would save the data and lock it, so you wouldn’t be able to edit it anymore. The best way I know to solve this task is to use formaction attribute. It’s not really a “secret” (as in headline) but it’s lesser known.

Value tuples C# 7

Value tuples is one of the features added in C# 7. I’m going to show you why it was introduced to language and how you can use it. Tuple Before we start with value tuples let’s take a look at regular tuples. What’s a Tuple? Basically it’s a set of grouped properties. You can use it to: quickly group related variables pass multiple related values as a single parameter return multiple values from method General characteristics of a Tuple:

C# merge dictionary and other tricks

Dictionary is a handy class. It’s a collection of key-value pairs. It is a hash table which means that it has to have unique keys (according to equality comparer). Each key is mapped to a value. Retrieving a value by key is very fast. There are many things you can do with it. In this article I’m going to show you some tricks that may come in handy sometimes. Initializing dictionary In cases when you already have some predefined data you can initialize it using collection initializer.

An introduction to unit testing using in .NET Core

Before we get into unit testing we should ask ourselves why would anyone write code to test other code? Is there any reason to do that extra work? It turns out that there are many reasons for that. Firstly, you’re going to make sure that given function works as expected. Secondly, if you decide to change the function, you still have it tested, so in case of some incorrect change you’ll know immediately that something is wrong.

Having trouble learning your first programming language?

You want to learn your first programming language. You read about it a little bit and you decide which programming language to learn. Then you read that big book full of syntax or you watch these programming videos and … nothing. When you open your IDE you can only stare on that blinking cursor, your mind is blank and you don’t know what to do. I’ll tell you why this happens and what to do about it.

Why you only need to know 3 (or 4) programming languages

Why do I think you only need 3 or 4 programming languages? Because I think that with 4 different languages represents big enough array of programming techniques to complete (almost) any project. It’s not about the languages itself, but rather the way of thinking and working which helps us become better as software developers and cover large area of projects which you may encounter. But the main point of it is that it gives you wide array of skills, presumably enough to learn any other language and easily get you a job.

How to preview image before uploading using Javascript

It’s an interesting feature. In some cases it’s better when users can preview image before uploading it, e.g. when you want to let users trim the image or process it in any way. As you’ll see it’s pretty easy to do. After reading this article you will know how to add this feature to your web app using Javascript. Step by step guide to creating preview image We’ll start off with a simple HTML page with a form and and input element which accepts only image files.

.NET reflection - theory, security and all the snippets you need in C#

Reflection code snippets tested under .NET Core 2. What is reflection and how can you benefit from it Reflection allows a program to inspect or modify itself during runtime. In practice it means that you can do all sorts of stuff on objects/properties including checking type of an object at runtime (typeof), listing all fields of an object without knowing variable names (including private members), modifying properties of an object (also including private members), instantiating object by class name and ivoking its methods dynamically, inspecting attributes attached to objects/properties, finding all classes implementing given interface in an assembly and so on.

How to prevent mass assignment in ASP.NET Core

One of the many security risks which you should consider is a mass assignment vulnerability (cheatsheet) also know as overposting. While it’s not in OWASP Top 10 it’s still considered important. Read on to understand the issue and find out possible ways of fixing it. Mass assignment explained ASP.NET Core allows automatic model binding of request parameters into variables or objects to make developers life easier. It can be as simple as binding id parameter via route:

Easy way to understand Big O notation

Many beginners struggle with understanding the Big O notation. I’ll show you a simple way to understand it with examples. It’s not mathematical, professional or academic, but hopefully it will help you understand it. What is Big O You’re writing your code and suddenly you come up with a problem which you can solve using several different algorithms. You have to pick one and you’re interested in the fastest one. How would you determine which one is the best in this case?