Stick on top

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”

Advertisements

Too many words

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.

LanguagesKO

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
PassaFraseCore/Dizionario/* linguist-documentation

So instructing GitHub to identify all the files in the subfolder PassaFraseCore/Dizionario as  Linguist
And the result was much better!

LanguagesOK

What’s your number?

I assume I do not need to present here the music streaming service Spotify.
Though very costly is the latest and greatest service to listen music unlimited in regards to time and devices.

Spotify is also a very social application that easy allow users to show and whatc what their freinds are listening to.
Freinds are determined using relations on Facebook, but not all the users decide to link Spotify and Facebook accounts, so sometimes you might have a hard time finding your friends.

One easy way to add a riend not connected via Facebook is to use the direct link in the form

spotify:user:UserID

Where UserID is the numerical identifier of any user. It is very easy to find this number, but it appears three is some confusion on how to find it: this is a very easy guide on how to look for it.

playlistFirst of all open the desktop client and pick any of your playlist: below the playlist title you’ll find your display name. It is an hyperlink, just click it.

userNext page is your own homepage and it contains all of your information including the ID: click on the ellipsis button below your name and choose “Copy Spotify URI”.

That string is the direct link to your user: you can give it to a friend that can go directly to your page by pasting it in the Spotify Client Search field.

Doing it elegantly

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
            TempItems.AddRange(SyndFeed.Items.ToList.GetRange(0, CurrentFeed.TotalElements))
        Else
            TempItems.AddRange(SyndFeed.Items.ToList)
        End If

        […]

        FeedItems.AddRange(TempItems)
    Next
    […]

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.

HTML5 horizontal alignment

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 -->
</div>

A block element can be horizontally centered using the following class selector:

.containerfootertext {
    width: 50%;
    margin: 0 auto;
    overflow: hidden;
}