Barbarian Meets Coding
barbarianmeetscoding

WebDev, UX & a Pinch of Fantasy

barbaric-tip-of-the-weekwebdevweb-essentials

Barbaric Tip of the Week: Ultra-Fast HTML and CSS Editing With Web Essentials and Emmet (ZenCoding)

Barbaric Tip of the Week is a weekly series whose main purpose is to share tiny bits of knowledge that I find specially useful and interesting.

Web Essentials is an awesome Visual Studio Plugin that comes with a ton of goodies to help web developers build great websites. One of these goodies is a port of ZenCoding(now known as Emmet), a plugin in itself that helps you to write HTML and CSS in a super intuitive and fast way.

With Zen Coding you can use CSS selectors to generate a whole tree of html elements from a single line of code. For instance, let’s say that you want to create a list of items. You can type this snippet within Visual Studio:

ol>li*5

Press TAB and see how it expands into a complete HTML list:

<ol>
    <li></li>    
    <li></li>    
    <li></li>    
    <li></li>    
    <li></li>    
</ol>

And in that same spirit you can use any CSS selector and get the results that you would expect based on CSS selector semantics. For instance:

section.spell-book>article.spell*5>header>h1>a[name="spell-name-$"]{spell-name-$}

Would become:

<section class="spell-book">
    <article class="spell">
        <header>
            <h1><a href="" name="spell-name-1">spell-name-1</a></h1>
        </header>
    </article>
    <article class="spell">
        <header>
            <h1><a href="" name="spell-name-2">spell-name-2</a></h1>
        </header>
    </article>
    <article class="spell">
        <header>
            <h1><a href="" name="spell-name-3">spell-name-3</a></h1>
        </header>
    </article>
    <article class="spell">
        <header>
            <h1><a href="" name="spell-name-4">spell-name-4</a></h1>
        </header>
    </article>
    <article class="spell">
        <header>
            <h1><a href="" name="spell-name-5">spell-name-5</a></h1>
        </header>
    </article>
</section>

And you can even use custom elements if you are working with Web components, Angular, Aurelia or any other modern web framework:

magic-spell-book>magic-spell>header>h1>a[name="spell-name-$"]{spell-name-$}

Would become:

<magic-spell-book>
    <magic-spell>
        <header>
            <h1><a href="" name="spell-name-1">spell-name-1</a></h1>
        </header>
    </magic-spell>
</magic-spell-book>

Using ZenCoding (Emmet) With CSS

ZenCoding gives you a lot of help even when you are writing CSS in the form of style abbreviations. If you want to add some margins to a given class, you can use the following abbreviation:

m20-10

click on TAB and voilà:

margin: 20px 10px;

And there’s a ton more of CSS stuff ZenCoding can help you with:

// specify units
m50p
margin: 50%;
fz2e
font-size: 2em
// or colors
c#4
color: #444;
// and you have abbreviations for 
// pretty much every CSS property

And It Comes With a LoremIpsum Generator

How many times have you gone off to the web to find a lorem ipsum generator to add some fake content to your website as you go prototyping? Well, do that no more! ZenCoding also gives you a Lorem Ipsum generator that integrates perfectly with its HTML generation workflow. Just type:

article>p*2>lorem

And you’ll get all the lorem you need:

<article>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quaerat laboriosam laudantium repellendus nihil quos ipsum vero eligendi dignissimos consequuntur praesentium quasi ullam aut omnis assumenda provident ratione repudiandae debitis soluta.</p>
    <p>Dolore eveniet tenetur eius consequatur reiciendis nisi et magnam praesentium in voluptatum. Incidunt vitae ipsam veniam tenetur corrupti itaque officiis temporibus perspiciatis aperiam ex et alias blanditiis minus harum fugiat.</p>
</article>

Start Learning ZenCoding (Emmet) With The CheatSheet

A very nice way to get started learning the different features available and CSS abbreviations that come with Emmet is to take a look at its Cheatsheet.

And it is Also Available For Other Editors!

Emmet is available, not only in Visual Studio with Web Essentials, but also in other editors that you know and love like Sublime, Atom, Brackets, TextMate, WebStorm, etc and even in online quick prototyping tools like jsFiddle, jsBin or codePen.

So go take a look at it if you haven’t already! Have a nice day!

P.S. Note that although I have used ZenCoding and Emmet almost interchangeably during the article, some features in Emmet are not available in ZenCoding. Particularly CSS abbreviations are not yet implemented in Web Essentials’ port of ZenCoding.

Mastering the Arcane Art of JavaScript-mancy for C# Developers - Chapter 6: Functions in ES2015

The Mastering the Arcane Art of JavaScript-mancy series are my humble attempt at bringing my love for JavaScript to all other C# developers that haven’t yet discovered how awesome this language and its whole ecosystem are. These articles are excerpts of the super duper awesome JavaScript-Mancy book a compendium of all things JavaScript for C# developers.

Welcome back! Today we will make a summary of the different ES2015 features related to functions that we’ve seen and worked with so far in the series: destructuring, default arguments and rest parameters. This will help you to consolidate these new features in your mind and also dive into them a little bit deeper.

We will also take a look at the new arrow function and how it solves the this conumdrum that we discussed in chapter 1 and will end up discussing smaller features like let, const and the spread operator.

{% img center comic—rotated-right /images/javascriptmancy-es2015-functions.png “ES2015 and functions” “ES2015 and functions” %}

Read on →
personalproductivitygitthingsdone

Want to Get Stuff Done? Behold!! The Ultimate System to Git-Things-Done!

Do you ever feel like you can’t get enough stuff done? That days and weeks pass and you never get around doing that thing that you really want to focus on? Then this article may help you!

Today a great colleague from Active Solution, Evgeny Lukashevich, encouraged me to share my productivity system with you. After pondering about it a little bit on the commute home I thought: Why not? Perhaps it will help someone to get more stuff done and live a more fulfilling and happy life. Who knows? I have never ever written about this before… it is definitely going to be interesting…

Read on →
cssoocsssass

Learn Some CSS and Stuff with the Redesign of Barbarian Meets Coding

Twice have I tried to redesign this blog, and twice have I failed miserably to do it. Yet from the ashes like the Phoenix of old shall I rise and attempt it… one more time.

This time, unlike in the past, I am going to try an iterative approach, I am going to take it in small steps, slowly but sure, changing, re-desining, re-shaping, re-defining and pushing these changes every week. And I thought to myself, why not share it, publicize it, so you may learn as I myself do?

So, the challenge!! Redesign barbarian meets coding within the next 8 weeks!! and most importantly, in a way that it does not suck :). Let’s get to it.

Read on →

Even More Useful JavaScript Function Patterns - Function Overloading

The Mastering the Arcane Art of JavaScript-mancy series are my humble attempt at bringing my love for JavaScript to all other C# developers that haven’t yet discovered how awesome this language and its whole ecosystem are. These articles are excerpts of the super duper awesome JavaScript-Mancy book a compendium of all things JavaScript for C# developers.

In the last couple of articles we learned some useful patterns with functions in JavaScript that helped us achieve default arguments and multiple arguments and we saw how ECMAScript 2015 (ES6) can simplify the way we can incorporate either of these in our code.

Today I will close this section - useful function patterns - with some tips on how you can achieve function overloading in JavaScript. Hope you like it!

Read on →