Páginas

Friday, July 20, 2018

Learning vi: mental notes

Though I use vi here and there for several years now, there's always some new trick to learn.
Lately I've had on my desk the book Learning the vi editor by Linda Lamb, published by O'Reilly.

Here I list, in no particular order, some notes as a way to reinforce what I've learned from the book. The focus is on things that called my attention, were new to me and/or that were not internalized yet in my day-to-day usage.


vi versus/and ex

ZZ = save and exit = :wq (ex command)
:e! = reload from disk
~ = toggle case
xp = transpose two characters

0 = go to beginning of line (same as ^)
W = move to the beginning of the next word, ignoring punctuation
B = move to the beginning of the previous word, ignoring punctuation
e = move to the end of the next word
E = move to the end of the next word, ignoring punctuation

. = repeat last command
Y = yy
P = put text before cursor
D = d$
C = c$
X = delete character before cursor
cc = change line = ddO = 0D
"3p = put contents of buffer number 3 (not the last buffer)
U = undo all edits on a single line
A = append at the end of the line
I = insert at the beginning of the line
s = c+space = xi = substitute character
S = cc = substitute line

50i* = insert 50 times *

ea = append to the end of a word
J = join consecutive lines

Tuesday, June 12, 2018

Quick and easy statistics with Python 3

Today I discovered that Python 3 (starting with 3.4) includes a new module in the standard library: statistics!

The full docs: https://docs.python.org/3/library/statistics.html

It is a useful library for quick explorations in the terminal. Fire an iPython shell, gather some data in a list, e.g. k, and then:

In [8]: import statistics

In [9]: statistics.mean(k)
Out[9]: 354.2944444444444

In [10]: statistics.stdev(k)
Out[10]: 29.47088274648779



Profit!

Monday, April 30, 2018

Go Exceptions: An Introduction

Estimated reading time: 12 seconds.
Table of Contents
  •  

[this section intentionally left blank]

Summing Up

Unlike many other languages, there are no exceptions in the Go programming language.


This post was inspired by the much lengthier Python Exceptions: An Introduction.

Friday, November 10, 2017

zsh - the Z Shell

After years using Bash, and doing more Bash scripting than I ever wanted in the last 2½ years, yesterday I switched to Zsh.

Why? Just because. I got it as my default shell in one remote host, and then decided to install it locally and take the opportunity to learn something new.

I'll be searching a lot for "how do I do X in zsh?"

The interesting things I did today already:
  1. Setup prezto; what seems to be a (better?) alternative to the famous "oh-my-zsh"
  2. Answered an StackOverflow question about zsh! How can I pause in zsh?
  3. Figured out how to get the path to the directory containing the current script: ${${(%):-%N}:h} ${${(%):-%x}:h:a}
    Update Nov/14:
    • Using %x instead of %N makes it work within a function;
    • :a makes the path absolute.

As the last item shows, there is some man zsh going on instead of man bash now.

Tuesday, September 12, 2017

Visualizing pull request merge cadence

This summer I had the pleasure to mentor Martin Nečas, a talented student from Střední průmyslová škola Brno, Purkyňova (a high school in Brno, CZ).
Martin has so many interests and wishes to learn everything that he can, and delivers on doing so, what makes me appreciate his eagerness for knowledge.

His summer internship project at Red Hat was to enable developers to visualize the time it takes to merge Pull Requests in GitHub repositories. In particular, we intended to use that to understand the healthiness of the merge processes in OpenShift-related repositories, and to serve as a guide to gauge the effects of changes to the said processes.

http://martin.codingkwoon.com/openshift/origin/

It all started back in early May, and in the first weeks Martin took the time to learn about OpenShift, containers, Linux and Python. He has been using Fedora on his laptop since then, and I know he really enjoys it, specially when he discovers new ways of doing things in the command line.

Due to my time constraints, it was only in June 1 when we started discussing his project in more detail. He was quick to grasp the idea and kept coming back with working prototypes. At first he was sold on learning Go, but then decided to stick with Python and Django and leverage his pre-existing skills.

His open source project GithubGraphs can be seen live at http://martin.codingkwoon.com, it is a web application that communicates with GitHub through its GraphQL API to fetch data about PRs and stores it locally to generate interactive visualizations. It is worth noting Martin's ability to play with the GitHub v3 REST API, and then, once he realized the downsides of using it, learning about GraphQL and using it effectively to improve the performance of the project.

This project also let Martin write much more JavaScript code than he has ever written before! And he did it well. Through several iterations, collecting feedback from different sources, he got to a good looking and functional design, well done!

In August, Martin reached out to OpenShift developers to announce his project publicly and get feedback. The reception was positive. Now I wish the original goals of the project will be fulfilled.

As we wrap up our collaboration, Martin is looking for new projects and more exciting times at Red Hat. Good luck!


Martin's GitHub profile: https://github.com/ocasek
Martin's blog: http://mnecas.blogspot.cz/