Home - Archives - About Me - Feed

Markdown Resume

14.05.2013

A few weeks ago I needed to build my curriculum vitae. When was the last time that you composed your cv? The last time I had to build it, I used a completely different stack. I remember having used Microsoft Office Word.

Now my options are an online editor, LaTeX or Markdown. I love to write in Markdown and I like to create my own tools so I decided to craft a tool to do the job.

Biteydown

Biteydown is Ruby application that turn a simple Markdown document into a resume in HTML or PDF file.

 Instalation

bundle install

Usage

Usage: biteydown [options] file
        --html                       Create HTML file
        --pdf                        Create PDF file
    -h, --help                       Display help

$ bin/biteydown --html --pdf example/curriculum.md

Style

You can customize the look and feel of text and headings in your document using the style/style.css file. First is transformed the Markdown document to HTML file and then apply the style. It’s a little bit hacky, but works fine.

Markdown is a lightweight markup language designed as an easy-to-read, easy-to-write plain text format and then convert it to structurally valid HTML; therefore, CSS selectors can be used to customize the curriculum.

image

CSS works by associating rules with HTML elements. In this case, there are a little group of selectors that can be used: h1-h6, blockquote, a, li, code, strong, em, img. You cannot use id or class selectors to create rules that apply to elements.

Managing Notebooks

04.12.2012

There are a lot of tools to organize and get work done, some are more focused on task management like Do or Wunderlist, and others are more focused on project management like AgileZen or Trello.

These are great tools, but I prefer notebooks. I thought to write about notebooks hacks, but there is already a monster collection of Moleskine tips, tricks and hacks.

Mike Rohde Notebook

Bill Westerman Notebook

I prefer notebooks over other devices and media. It’s the same feelings with books and e-readers. I love the feel of paper and provide a better user experience for me. In many ways it’s more versatile than software because I can organize my daily tasks, communicate ideas through drawing, sketchnotes, create lists, project planning, journal, quotes, random thoughts…

Sparky

17.06.2012

I start to hack on an idea I had last week. The idea is to display statistics about version control systems in a Unix shell and I also want to improve my command line fu.

Before starting, I remembered spark, an awesome project that generates sparklines for a set of data, so I interested in trying out an alternative Groovy implementation and have fun.

▁▂▃▅▂▇ in your shell. Groovy flavoured!

My project is sparky. It’s a Groovy script that lets you graph tiny sparkline graphs from your command line.

sparky takes a list of numbers (comma-delimited, spaces, whatever you’d like) and then prints a sparkline out of it. It’s designed to be used in conjunction with other scripts that can output in that format.

Examples:

$ sparky 1 5 22 13 53
▁▁▃▂▇

$ sparky 0,30,55,80,33,150
▁▂▃▅▂▇

$ echo 9 13 5 17 1 | sparky
▄▆▂█▁

Cooler usage

There’s a lot of stuff you can do.

Number of commits to the github/groovy-core Git repository, by author:

$ git shortlog -s |
> awk '{print $1}' |
> sparky
▁▁▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▁▂▁▁▄▁▁▁▁▁▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

Code visualization. The number of characters of sparky itself, by line, ignoring empty lines:

$ awk '{ print length($0) }' sparky |
> grep -v 0 |
> sparky
▂▂▁▁▃▁▃▂▃▃▃▂▁▁▂▄▁▄▅▅█▅▂▁▁▃▃▅▁▁▃▂▁▁▇▃▁

Try it!

Ruby Version Manager

04.06.2012

I’m a Groovy developer. As you might know, I love to learn and play with other programming languages.

This time, it’s the turn of the Ruby programming language. Ruby has a great ecosystem, there are a plenty of projects, libraries and tools. In fact, this blog is powered by toto and right now I’m creating a new static site with Jekyll.

To develop these projects, I need to use different Ruby versions and gems. The established leader in the Ruby version management scene is RVM and rbenv is an alternative.

RVM

Ruby Version Manager (RVM) is a command-line tool which allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.

I have taken some notes that I think you will find helpful if you are starting with RVM.

Install RVM:

curl -L get.rvm.io | bash -s stable

Display a list of all “known” rubies:

rvm list known

Install Ruby:

rvm install 1.9.3

I had issues with zlib and openssl, I reinstalled Ruby including these packages:

rvm pkg install zlib openssl
rvm reinstall 1.9.3 --with-zlib-dir=$rvm_path/usr --with-openssl-dir=$rvm_path/usr

Switch beetween Ruby versions:

rvm 1.9.3
rvm system

The project .rvmrc files is intended to be used to setup your project’s Ruby environment when you switch to the project root directory.

Create a project specific .rvmrc file:

rvm --rvmrc --create 1.9.3@project

Closure Design Patterns

25.04.2012

Design Patterns

These days I’m learning design patterns. There are a lots of documentation about software design patterns, but I’m interesting in closure design patterns.*

Many patterns imply object-orientation, so may not be as applicable in dynamic languages. Peter Norvig demonstrates that 16 out of 23 patterns in the Design Patterns book are simplified or eliminated, Design Patterns in Dynamic Languages.

I’ve found an interesting presentation of Venkat Subramaniam about Design Patterns in Java and Groovy and another presentation of Neal Ford about Design Patterns in Dynamic Languages. Here, I extract some patterns of these presentations that involve closures and add others patterns based on my own experience.

* Groovy makes no such distinction between closures or anonymous functions. I’m really trying to get at is how we can use tools such as first-class functions, lambdas and closures when implementing design patterns.

Closure Design Patterns

Execute Around Method

A pair of operation that needs to be performed before and after operations.

def operations(closure) {
    println "Open"
    closure()
    println "Close"
}

operations { println "Operation" }

===> Open
===> Operation
===> Close

Pluggable Behavior

Specify the behavior of an object at runtime.

def selectValues(number, closure) {
    def list = []
    1.upto(number) {
        if (closure(it)) list << it
    }
    return list
}

assert [2, 4, 6, 8, 10] == selectValues(10) { it % 2 == 0 }  // even
assert [1, 3, 5, 7, 9]  == selectValues(10) { it % 2 != 0 }  // odd

Iterator Pattern

Allows sequential access to the elements.

def listNumbers(closure) {
    (0..3).each { closure it }
}

listNumbers {
    if (it < 2) println "$it is a little number"
    else println "$it is a big number"
}

===> 0 is a little number
===> 1 is a little number
===> 2 is a big number
===> 3 is a big number

Dynamical Conditional Execution

Create and execute a conditional operation.

def greet(user, successClosure, failClosure) {
    if (isAdmin(user)) successClosure()
    else failClosure()
}

greet(user, { println "Hi Admin!" }, { println "Hello User" })

Template Method Pattern

Define common algorithm steps (getting a customer) and customizations (passed as a closure).

def withCustomer (id, closure) {
    def customer = getCustomer(id)
    closure(customer)
}

withCustomer(1234) { customer ->
    println "Found customer $customer.name"
}

Loan Pattern

Ensures that a resource is deterministically disposed of once it goes out of scope.

def withListOfWordsForEachLine(file, closure) {
    def reader = file.newReader()
    try {
        reader.splitEachLine(' ', closure)
    } finally {
        reader?.close()
    }
}

withListOfWordsForEachLine(file) { wordList ->
    println wordList
}

Command Design Pattern

Encapsulate all the information needed to call a method at a later time.

def count = 0
def commands = []

1.upto(10) {
    commands.add { count++ }
}

println "count is initially ${count}"
commands.each { cmd ->
    cmd()
}
println "did all commands, count is ${count}"

===> count is initially 0
===> did all commands, count is 10

Strategy Pattern

Define a family of interchangeable algorithms.

calcMult = { n, m -> n * m }
calcAdds = { n, m ->
    def result = 0
    n.times { result += m }
    return result
}

def calcStrategies = [calcMult, calcAdds]
calcStrategies.each { calc ->
    assert 10 == calc(5, 2)
}

Factory Pattern

Abstract the object creation process (currying as a function factory).

def adder = { x, y -> x + y }
def incrementer = adder.curry(1)

assert 5 == incrementer(4)

Method Combination

Build a method from components.

def sum = { Collection collection -> collection.sum() }
def first2 = { Collection collection -> collection.take(2) }
def take2andAdd = first2 >> sum

assert 3 == take2andAdd([1, 2, 3, 4, 5])

Polyglot Programming

27.03.2012

Polyglot Programming

How many programming languages do you know?

Most programmers know several languages. I, as web developer, work on a daily basis with Groovy, SQL, Bash Scripting, HTML, CSS, JavaScript…

Learning different languages allows us to solve problems with the most appropriate language and to explore new paths of thinking about computational problems.

Neal Ford coined the term polyglot programming, to refer about this topic.

I think it’s important in this day and age of polyglot programming to understand a variety of different languages, as they are the design tools we use to craft software. Just like regular engineers must understand the physical properties of different materials, we should understand the capabilities, strengths, and weaknesses of different languages. And when to apply them.

Neal Ford

Polyglot JVM

Java has long been known simply as a programming language. Today, when thinking in Java we refer also a robust and mature development platform. Currently, the Java Virtual Machine (JVM) supports over 200 different programming languages.

These days I have been exploring different languages on the JVM: Java, Groovy, Scala, Clojure… I shared my experiences with others developers at Codemotion 2012.

Hope you enjoy the slides.

Create your own Groovy type conversion

06.02.2012

Type conversion the standard way

Type conversion or casting is a programming language method for changing an object’s data type into another.

I’m sure you are familiar with this code that converts a String to an Integer.

def number = (Integer)'1'
def number = '1'.toInteger()
def number = '1' as Integer

If I want to convert the type of my own objects, I need to create a method to achieve this goal. I copy object properties to another object in a generic way; if a property exists on target object, I copy it from the source object.

class User {
    String name
    String city
    Integer age

    def toAdminUser() {
        def adminUser = new AdminUser()
        copyProperties(this, adminUser)
        return adminUser
    }

    def copyProperties(source, target) {
        source.properties.each { key, value ->
            if (target.hasProperty(key) && !(key in ['class', 'metaClass'])) {
                target[key] = value
            }
        }
    }
}

class AdminUser {
    String name
    String city
    Integer age
}

Now I can do something like this:

adminUser = user.toAdminUser()

Type conversion the fancy way

Great, but I want to use this fancy way to coerce one type to another:

adminUser = user as AdminUser

Simple, Groovy supports operator overloading and creating your own type conversion is really easy: we can override the asType() method.

class User {
    String name
    String city
    Integer age

    Object asType(Class clazz) {
        if (clazz == AdminUser) {
            def adminUser = new AdminUser()
            copyProperties(this, adminUser)
            return adminUser
        }
        else {
            super.asType(clazz)
        }
    }

    def copyProperties(source, target) {
        source.properties.each { key, value ->
            if (target.hasProperty(key) && !(key in ['class', 'metaClass'])) {
                target[key] = value
            }
        }
    }
}

GNU Screen

10.01.2012

GNU Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. With this tool, you can keep a process running after disconnecting an SSH session. Kudos to Diego Toharia and his blog post Screen en máquinas remotas.

Basic usage

Create a new screen session:

$ screen -S sessionname

Resumes a detached screen session:

$ screen -r sessionname

List all of the screen sessions:

$ screen -ls

Kill a session:

$ screen -S sessionname -X quit

Close all screen sessions:

$ killall screen

Useful key bindings:

Ctrl + a, d Detach screen from this terminal
Ctrl + a, c Create a new window
Ctrl + a, space Switch to the next window
Ctrl + a, backspace Switch to the previous window
Ctrl + a, A Rename current window
Ctrl + a, " List of all windows for selection
Ctrl + a, k Destroy current window
Ctrl + a, ? Show key bindings

Multiple shells open in the same terminal:

Ctrl + a, | Split vertically
Ctrl + a, S Split horizontally
Ctrl + a, tab Switch the input focus to the next region
Ctrl + a, X Kill the current region
Ctrl + a, Q Delete all regions but the current one

A worry-free session

$ ssh me@server.com
$ screen -S sessionname
$ start something really important

Disconnect from the server (panic at other times without screen).

$ ssh me@server.com
$ screen -r sessionname

Everything is fine, keep working.

Automate your job

After disconnection, you can log into the remote machine and reattach the session in a single step:

$ ssh me@server.com -t "screen -r sessionname"

How can we improve this? autossh is the answer.

autossh, automatically restarts an SSH session and reattaches a session transparently:

$ ssh me@server.com
$ screen -S sessionname
$ Ctrl + a, d
$ exit
$ autossh me@server.com -t "screen -r sessionname"

In fact, autossh include a script called rscreen for perpetual sessions.

OK, it works. But it’s not so great because first you need to connect to the server, create a new screen session, detach the screen, exit from the server and finally connect it again with autossh.

What can we do? You can use screen -R to reattach a session or even create it first. Finally we solve all problems:

$ autossh me@server.com -t "screen -R sessionname"

Magic in Software Development

19.12.2011

My opinion about magic in software development coincides with these great posts:

Do You Believe In Magic?

Magic in software development

I extract some fragments of them that I would like to highlight.

Bad word: Magic

I often find that people talk about magic when referring to programming languages and frameworks.

The concept that some particular language features are more magical than others is insane. None of it involves fairy dust or anything particularly complicated; it’s all just programming.

There is absolutely no logic in calling language features magical. It implies that certain programming techniques are inherently fantastic and strange. That’s only the case if you don’t understand the language.

The correct response is not calling arbitrary features magic. The correct response is to keep learning how to write code and overcome your ignorance.

Magic rocks!!

Ultimately, you can continue using magic, but what’s magic? I’d define it as anything below your current level of abstraction that you don’t understand.

Any sufficiently advanced technology is indistinguishable from magic.

Arthur C. Clarke

Magic is a good idea, we don’t understand exactly how quantum physics works but we accept that it does and make good use of it.

Now, if you don’t understand some feature of your favorite framework or how it works behind the scenes, don’t worry. Do not be intimidated, just learn and enjoy without worrying about every detail.

Functional Programming with Groovy

28.11.2011

The diversity of languages and programming paradigms allows us to solve existing problems by thinking of solutions from very different approaches.

But why should a Groovy developer learn functional programming?

As I learned about functional programming, I found good ideas but I also found that it brought new clarity to my thinking about the design of class and methods. It also allowed me to write more concise code and to make it easier to reuse.

A few weeks ago, I spoke about functional programming with Groovy at Greach 2011. I presented basic concepts of the functional programming paradigm and then focused on how to apply them to improve the code that we write with Groovy.

Si quieres leer más, consulta los Archivos >>