I hereby claim:
- I am hamelin on github.
- I am hamelin (https://keybase.io/hamelin) on keybase.
- I have a public key whose fingerprint is 1978 A5D5 D9BF A2CA B792 2086 A248 2E19 42D0 D8ED
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
This is a translation of Eric Pement’s [collection of Awk one-liners](http://www.pement.org/awk/awk1line.txt) as Ruby one-liners. These so-called _one-liners_ are small programs that hold on a single (sometimes longish) line of code, so it may be run from the command line, typically for text processing purposes. So, all problems solved by Awk one-liners on the page linked above are solved here in Ruby, sorted along the same categories as Pement’s work. In some cases, multiple solutions are proposed, as they outline nice features or idiosyncrasies of the Ruby language and conventions. | |
Note that this is not the first collection of Ruby one-liners: googling “Ruby one-liner” yields multiple hits. However, I have put up this collection by myself, without looking at other solutions, for the sake of practice. I have posted about what generalities I have learned throughout this exercise [here](http://benoithamelin.tumblr.com/post/10945200630/text-processing-1liners-ruby-vs-awk). | |
# File spacing | |
Double-space a file. |
# From source repository | |
cd repo | |
git diff-index --patch --binary --full-index <commit ID, included>^ | |
# The patch is dumped to standard output. We capture it (to file, to clipboard) and | |
# send it to the destination host. | |
# Into source repository | |
cd repo | |
git apply <path to patch file> |
SHELL = /bin/bash | |
bigfiles = auth dns proc flows | |
lines-per-chunk = 250000 | |
.PHONY: bigfiles | |
bigfiles: $(addsuffix .chunks,$(bigfiles)) | |
%.chunks: %.txt.gz | |
trap "rm -rf $@" INT ERR;\ | |
mkdir $@;\ |
# 1. Run: jupyter lab --generate-config | |
# 2. Edit $PATH/.jupyter/jupyter-lab-config.py, add the following at the end. | |
# | |
# In Jupyterhub, one needs to restart their "server" to get such config changes to take. | |
def strip_ws(t): | |
return '\n'.join([i.rstrip() for i in t.split('\n')]) | |
def scrub_output_pre_save(model=None, **kwargs): |