Skip to content

Instantly share code, notes, and snippets.

@hamelin
hamelin / keybase.md
Created July 11, 2016 20:37
Keybase identity proof

Keybase proof

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:

Keybase proof

I hereby claim:

  • I am hamelin on github.
  • I am hamelin (https://keybase.io/hamelin) on keybase.
  • I have a public key ASBecxIb2ssOe8J12rN6oFrolvuvsKXLe3X5e8FpB83hFgo

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.
@hamelin
hamelin / Extract a patch from a repository
Last active March 3, 2020 20:26
How to extract a patch file describing the change between present (`HEAD`) and an older commit in a Git repo.
# 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>
@hamelin
hamelin / Makefile
Last active March 19, 2020 19:18
Makefile for chunking the Los Alamos dataset for parallel processing of the data, while preserving compression.
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 $@;\
@hamelin
hamelin / dask-example.ipynb
Created April 15, 2020 16:17
Distributing Python computations with Dask
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hamelin
hamelin / jupyter-lab-config.py
Last active December 23, 2021 16:45
Configuration to get Jupyter Lab's editor to trim whitespace at the end of each line when it saves a file.
# 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):
@hamelin
hamelin / minimal-transport.ipynb
Last active October 27, 2021 14:52
A discussion of optimization with linear equality constrains applied to minimal transport problems
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hamelin
hamelin / Building sparse matrices in Python.ipynb
Last active December 8, 2021 13:44
Explains how to build sparse (COO) matrices that one-hot encode square lists
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hamelin
hamelin / accessing-data-from-azure-blob-containers.ipynb
Last active April 26, 2022 21:13
Tutorial on using Rclone and fsspec to wrangle data stored on Azure blob containers.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.