Let’s Encrypt is a certificate authority that is providing free SSL certificates. The process to acquire certificates is fully automated and is designed to make the creation and renewal of certificates as painless as possible.
This short post will describe the steps to get and configure certificates for a website hosted on ubuntu using nginx as webserver.
The first step is install the certbot tool. Ubuntu provides packages so the installation can be done with a simple
The next step is to generate the certificate using certbot, the process creates some files in the root directory of the website, so access to the folder is required. Launching certbot with this command line does the trick
The command will generate the verification files in the specified folder and will look for them using the domain to be certified. If the verification process is successful, the certificates will be created in
After creating the certificate we need to configure nginx to serve the website using SSL along with the unencrypted HTTP version. To do so we need to edit the nginx configuration file for the website (for example
/etc/nginx/sites-available/munisso.com) and add the following configuration options
Make sure to replace the domain name with the appropriate folder for your website. Restarting nginx or reloading the configuration will enable SSL on the website.»
Is handy to use SSH while connecting to git, for better security and the advantage of not having to type passwords at every remote operations.
Here the instruction on how to set it up for Windows:
Generate the ssh key
- using the command prompt, go to
C:\Program Files (x86)\Git\binor
- generate the key pair using
ssh-keygen, leave the key name as default
Upload the key to github
- Go to
- open the file
id_ssh.puband copy the content
- go to your account in github, and under the SSH Keys tab, enter a new key. Paste your public key and give it a friendly name
Set up ssh for git
- Copy the path of the
ssh.exeexecutable under your
- Create a new environment variable called
GIT_SSHand set it to the path of the
- Now just clone your repository using the SSH link, rather than the http(s) ones.
- If everything was setup correctly you shouldn’t be requested a username or password.
- The first time you clone, SSH will ask you to confirm the ssh fingerprint of the remote server
Other git hosts have support for SSH. If you use Stash for example, just copy and paste your id_ssh.pub content into a new SSH key under your account preferences.»
In this post I’ll explain the 4 methods available to get the IDs of newly inserted rows when the table has an identity Id column.
This variable contains the last identity value generated by the current connection, is not limited to the scope of the code being executed. In case the current connection didn’t insert any row with an identity the property will have a NULL value.
This code will give you unexpected result if there is a trigger, running for inserts in TableA, that is inserting row in other tables with an identity. In this case the
@@IDENTITY variable will give you the ID inserted by the trigger, not the one inserted in the current scope.
This function will return the value of the last identity inserted in the current executing batch.
The following code
will return the last value inserted in TableA by our insert, even if other connections, or trigger fired by the current connection are inserting values with IDs.
This will be the best method to use in most of the cases.
This function returns the last identity value inserted in the specified table, regardless of the scope and connection.
This function is available in SQL Server 2005 and newer versions.
The output clause can be used to get IDs when inserting multiple rows.
This obviously will insert into
@NewIds the Ids generated by the current statement. Other connection or code executing in different scopes will not affect the result of the operation.
IDENT_CURRENT, also this function is available in SQL Server 2005 and newer versions.
Visual Studio (starting from version 2005) gives you the possibility to use the code snippets to insert frequently used code parts quickly using an alias. Try for example to digit “prop” and press TAB to create a full property. The type and the name of the property are parameters of the snippets, they have a default value that can be changed.
Visual studio has a long list of pre-made code snippets available, but obviously not every option that we might need is available. In this post I want to show you how to create your own code snippets.
One task that I perform very often is to check method arguments against null values, in every public method I repeat this piece of code for each parameter.
Let’s create a code snippet, that I will call “checknullargs”, to automate the creation of this code.
First of all we have to create a new file called “checknullargs.snippet” (you don’t have to call the file in with the same name as the alias, but I recommend to do so, it will be quicker to identify which file contains a specific snippet if you will need to edit or delete them) in the folder
%Documents%\Visual Studio %Version%\Code Snippets\%Language%\My Code Snippets, where
%Documents% is your Documents folder,
%Version% is the visual studio version that you have installed (eg. 2005, 2008, 2010) and
%Language% is the programming language that you want to use to write the snippet (and the snippet will be available only for that language).
The code snippet file is a simple XML file with the following structure.
The file can be opened in visual studio to get full intellisense support.
Inside the Header element let’s add information about our snippet
- Title: is the name of the snippet
- Shortcut: is the shortcut that we use inside of visual studio to activate the snippet
- Description: description of your snippet
- Author: your name!
- SnippetTypes / SnippetType: is the type of snippet, can be
Expansionsnippet just add code to the editor, a
SurroundsWithsnippet surrounds the selected code with the content of the snippet.
Let’s fill now the
Snippet section. The snippet section is divided in two parts, a
Declarations element that allows us to declare the parameters (the replaceable parts) of our snippets, and the
Code element containing the actual code.
Declarations element contains a list of
Literal elements, one for each parameters of the snippet. For each parameter we have to specify the ID (that needs to be unique), a tooltip and the default value.
Code element contains the actual code to be inserted. You can insert your parameter using sourrounding them with dollar symbols (in this example
Note that in the above sample there is a parameter called
$end$ that we didn’t declare. This is a predefined value that represents the position of the cursor after the snippet is inserted in the editor. In this case the cursor will be placed after the snippet.
There is also another predefined parameter, called $selected$ that represents the code selected in Visual studio when adding the snippet. This is useful for the
SurroundsWith type of snippets.
Once you have created your snippet you will need to restart visual studio for see the changes in the editor.
The full code for the sample snippet can be downloaded here
Let’s start this blog with something simple, but often performed in the wrong way even by experienced .Net developers. I’m talking about string comparisons.
The basic comparison is performed using the == operator (or it’s negation !=), that executes a comparison that is culture insensitive and case sensitive. We should use this operator only when we expect strings to exactly match.
An example is while iterating through an XML document using a XmlReader, we can use the == operator to compare the current node name with the name that we expect. In this case we want the node name to exactly match the string, so using == is the right choice.
== operator is the same as using the
String.Equals(string, string) static method or the instance method
Now let’s have a look at another type of comparison: case insensitive comparison. Too often I see code like
This type of comparison has a flaw: with
ToUpper you are creating an uppercase copy of the string. If you are comparing large strings or a lot of strings inside loops the performance penalty can be significant.
An alternative in this case is string.Compare(string, string, bool). This method returns 0 if the two strings are equals, a non zero value if the strings are different. Passing true to the boolean parameter allows us to specify that we want to perform a case insensitive comparison.
This method however will give you different comparison results than the
== operator, the reason for this is that this overload of the Compare method uses the current culture to do the comparison, while the
== operator uses the raw binary value of the string.
A more appropriate overload of the same method to perform the comparison in the same way as the
== operator is the string.Compare(string, string, StringComparison) method.
Passing the value
StringComparison.OrdinalIgnoreCase to the last parameter we will obtain the same comparison done by the
== operator, but in a case insensitive way.
We can use the same overload of
String.Compare to perform comparisons based on a Culture (also called locale). Passing as the last parameter
StringComparison.CurrentCultureIgnoreCase we will do comparison using the current culture of the application, passing
StringComparison.InvariantCultureIgnoreCase will do the comparison using the
InvariantCulture (a culture based on the English language but country independent).
Please bear in mind that the methods using some
Culture information are slower than the ones that do the comparison based on the raw value of the string.
An equivalent approach to use the string.Compare method is to use one of the default
StringComparer (there is one matching each
StringComparer is a class implementing the
IEqualityComparer generic interface for the type
String. We can pass instances of this object to other objects to control how they perform string comparisons.
For example we can easily create a dictionary where the key is a string and we want the key comparison to be case insensitive.