For several of my web projects I align myself to one of the common non-written rules of web design: make the top bar a menu bar and keep it on top of the browser screen even when you scroll.
I did so for my personal website lucamauri.com and I recently replicated it with my new project passafrase.it, so I thought about writing a quick post to summarize how to achieve so. Continue reading “Stick on top”
I recently started a new project on GitHub: a library and a set of Windows, command line and web application to easily generate pass-phrases using Italian language dictionary.
I created the project in Visual Studio Community 2015 and created the online repository with the integrated extension: everything seemed normal except for one small detail.
The language details is the colored bar with details about the programming language used in the project: it was all wrong!
It showed programming languages I did not even know they existed, let alone used!
As GitHub uses an automatic system to determine the language used in a project, I started to think what could have fooled it into thinking my project was created with such exotic languages.
The easier answer to this question was the data contained into the italian dictionaries: a long list of common and uncommon italian words needed to generate random pass-phrases.
There is a simple method to override the automatic selection by let GitHub know what files needs to be ignored because imported from other libraries or because they are part of the Linguist documentation files.
So I edited the .gitattrtibutes file by adding:
$ cat .gitattributes
So instructing GitHub to identify all the files in the subfolder PassaFraseCore/Dizionario as Linguist
And the result was much better!
It is quite a common case to have a website on a remote hosting when, for whatever reason, you can’t afford a full-fledged server onto your fridge or in a remote location. One of the issue you might come across on a hosting server running ASP.net is finding the path of a folder you want to work on. Usually you have a local copy of your website where you work using Visual Studio and then you publish it to the remote location: this is the typical example where the folder structure will not match to the root: you might have a c:\documents\websites\mysite\ that on the hosting server maps as d:\webs\789547\customers\jhondoe\jhondoe.com\. To find the right path both locally, on a hosting location or wherever else there is a simple strategy. Review the following code:
For Each CurrFile As FileInfo In New DirectoryInfo(Hosting.HostingEnvironment.MapPath("\test")).EnumerateFiles
work on each file
This piece of code is enumerating all the files in a subfolder called “test” under the root of your website no matter where it is actually located in the absolute directory tree. Review this article on the MSDN library for more information.
There are plenty of programming languages out there and they all allow endless possibility in how to write a piece of code.
Very often things can be done in two ways: the blunt way and the elegant way.
Consider for instance this piece of code:
For Each SingleFeed As XElement In XMLDoc.Descendants(XName.Get(CurrentFeed.RootElement))
Dim SyndFeed As SyndicationFeed = SyndicationFeed.Load(System.Xml.XmlReader.Create(SingleFeed.Descendants(XName.Get("feed")).Value.ToString))
Dim TempItems As New List(Of SyndicationItem)
If SyndFeed.Items.Count >= CurrentFeed.TotalElements Then
It has to do with the creation of an object to store items from an ATOM feed.
The important point I want to show is the one about the If … else … End If cycle. What you are looking here is the first implementation of the code: it’s the easy way and, as i discovered later, the longest and stupidest way to write it.
Yes, it was stupid: the compact, most logical and briefly the elegant way to wrote it turned out to be:
TempItems.AddRange(SyndFeed.Items.ToList.GetRange(0, Math.Min(CurrentFeed.TotalElements, SyndFeed.Items.Count)))
Probably any coding language nowadays includes some kind of Minimum function to return the smallest of two numbers.
Very often is just a matters of knowing what you are doing.
Earlier today I was creating a new class file for a project of mine in Visual Studio.
Then I went on using the class defined in that file in a web form, but, to my surprise, the class was inaccessible.
I double checked the access level of the class, but it appears that wasn’t the issue, so I started googling for this problem, but I ended up looking at situation different from mine and not really useful.
After a few minutes of scratching my head on this unusual problem, I finally had a look at a pane I rarely look at:
In the Properties pane, the Build Action was set to Content instead of Compile: this is the ways of telling the IDE to include this file in the project as a static resource. So, in this case, the class file was included as a simple plain text file with no action performed on it: no compilation mean of course no usable class, so that was the reason for the seemingly inexplicable behavior.
To have a deeper look into this topic, I strongly advise to read this interesting post on StackOverflow.
An inline element can be centered using the text-align: center style on the parent element like in the following example:
<div id="containersharing" style="text-align: center">
<h1>Share or bookmark this page</h1>
<!-- AddThis code START -->
<!-- Go to www.addthis.com/dashboard to customize your tools -->
<div class="addthis_sharing_toolbox" style="display: inline-block;"></div>
<!-- AddThis code END -->
A block element can be horizontally centered using the following class selector:
margin: 0 auto;