Linux Background Jobs

Suspend a job and send it to the background:

$ Ctrl+Z

Resumes jobs that have been suspended, and keeps them running in the background:

$ bg

Bring most recently suspended background job to foreground:

$ fg

Display status of jobs in the current session:

$ jobs

Java Runnable, Callable, Supplier, etc.

Java doesn’t have the concept of delegate; instead, if you need a pointer to a function, you can create inline anonymous classes (or lambda expressions as of Java 8 ) which are implementations of certain interfaces designed for this propose (a.k.a functional interfaces as of Java 8). However as Java evolves, more of such interfaces are being added. While they may seem very similar and confusing, each of them has a unique characteristic which sets it apart from the others. You can map many of them to identical types in .NET. The following table lists some of the famous interfaces but there are many more. For example to support functions with two arguments, Java has another interface called BiFunction and if you need more arguments, you have to create your own interfaces. Remember that Java (up to version 10) doesn’t support identical class names if the only difference is number of type arguments. (In .NET there are various Func and Action types with up to 16 type arguments.)

Java Supports Exceptions Argument Returns .NET Equivalent
Callable  Yes  No  Yes  Func
Supplier  No  No  Yes  Func
Function<T,R>  No  Yes  Yes  Func<T,R>
Consumer  No  Yes  No  Action
Runnable  No  No  No  Action

API Security Checklist

  • Use HTTPS to protect sensitive data (authentication credentials, API Keys, etc.) in transit.
  • Authentication/Authorisation: Make sure the endpoints are protected with proper access levels.
  • GET methods are an easy target for attackers. So never perform an operation that changes the state of your application in a GET method.
  • Protect your API agains CSRF (Cross-Site Request Forgery) attacks.
  • Make sure your API is not vulnerable to XSS (Cross-Site Scripting) attacks.
  • Sign JWT (JSON Web Tokens) securely preferably using secrets.
  • Use API Keys for every request.
  • Treat Management Endpoints differently than normal ones, by enforcing stronger security policies (e.g. multi-factor authentication.
  • Handle exceptions decently so that technical error details are not exposed to clients.
  • Use SOP (Same-Origin Policy) and disable CORS if it’s not needed. When enabling CORS, be as specific as possible.
  • Do not put any sensitive information in the URL params as they can be logged by servers. Put them in the request header or body.
  • When setting cookies, use Secure and HttpOnly. Also restrict the scope of cookies.
  • Any input or data being imported may eventually end up in users’s browsers as part of an HTML page and you don’t want to send a malicious script to the them. Validating input and imported data is one of the ways to prevent clickjacking, XSS or stored CSRF flaws.
  • Any input or data being imported may also end up being inserted into your database, so make sure your application is protected against SQL Injection attacks.
  • Set response Content-Type header properly to mach the response MIME type and disable MIME type sniffing (nosniff).

Install .NET Core on Ubuntu 15.10

Currently .NET Core is only supported for Ubuntu 14.04 and when you try installing it on Ubuntu 15.10 you get the following error:

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 dotnet : Depends: libicu52 (>= 52~m1-1~) but it is not installable
E: Unable to correct problems, you have held broken packages.

As a workaround you can download and install libicu52 manually before installing dotnet .

How big can a class be

A class should be so small that anyone can easily understand it. If a method is not required to be understood in order to understand the class, then that method probably doesn’t belong in there and it’s not part of the responsibility of that class.

It is not a good idea to judge how big a class is based on the number of lines of code, however the following list can give you a rough estimate:

  • Less than 100: Ideal
  • 100 to 200: Ok
  • 200 to 300: Warning
  • 300+: The class is too big

How to install JSon.Net NuGet package


You are going to install Json.NET NuGet package but you get the following error:

 JSON Failed to initialize the PowerShell host. If your PowerShell execution policy setting is set to AllSigned, open the Package Manager Console to initialize the host first.


  1. Open PowerShell console in Administrator mode. Note that you should open the x86 version if you are running the 32bit version of Visual Studio. Likewise open x64 if your Visual Studio is 64bit.
  2. Run this command start-job { Set-ExecutionPolicy Unrestricted } -RunAs32 | wait-job | Receive-Job
  3. Reopen Visual and the issue should be fixed

Association vs. Aggregation vs. Composition


Association is the most general type of relationship and it  includes other types as well. If the relationship doesn’t fall into a more specific type, like Aggregation or Composition, it can simply be referred to as an Association.

Example: When a Customer places an Order, the relationship is simply an Association.




Aggregation is a more specific type of association. In an aggregation the children can also be shared with another owner at the same time, and even if the owner no longer exists, the children can still continue their lifetime.

Example: The relationship between a UserGroup and the Users, is an Aggregation. A User can still have meaning in the system even if it doesn’t belong to a UserGroup, so if you delete a UserGroup you won’t delete its Users. On the other hand, the Users can belong to several UserGroups at the same time.




Composition is a more strict type of Aggregation. In an aggregation, the children cannot be shared with a different owner and it doesn’t make sense for the children to exist without their owner. So, you usually want to delete the children if you delete their owner.

Example: The relationship between an Order and the OrderDetails is a composition relationship. The OrderDetail items are valid only as long as there is an Order related to them. When you delete an Order you will delete it’s OrderDetails as well. An OrderDetail associated to a particular Order cannot belong to a different Order.



Batch edit TeamCity build configurations

TeamCity supports parameters, so if you are dealing with so many build configurations on your TeamCity server and you need to change something in all of your projects, the best practice is to use parameters or build templates. But what if you need to change a value in multiple build configurations or multiple projects and that value cannot be (or is not) defined as a parameter? In such cases you can use the following shortcut instead of going through each build configuration to edit them:

  1. On the TeamCity machine, open the data directory. It can be identified using the TEAMCITY_DATA_PATH environment variable.
  2. Open the corresponding directory to your required project from %TEAMCITY_DATA_PATH%\config\projects.
  3. All of the build configurations are stored as XML files in the buildTypes directory.
  4. Use a powerful text editor (e.g. Notepad++ ) to batch edit the files.
  5. From the TeamCity administration page, go to Server Administration\Diagnostics\Caches and reset buildsMetadata.

After a couple of seconds the changes should be reflected in all of your build configurations.