Skip to content
Raine Virta edited this page Jun 8, 2015 · 40 revisions

Feel free to contribute to this document with ramda-cli snippets that have helped you.

Recipes

Create a markdown formatted table of Ramda's functions

Output from ramda-cli can be piped to markdown-cli-table to create a Markdown formatted table.

npm install -g markdown-table-cli
curl -s https://raine.github.io/ramda-json-docs/latest.json | \
  R 'project <[ name sig category ]>' \
    'map evolve sig: (-> it and "`#it`"), name: -> "[`#it`](http://ramdajs.com/docs/##it)"' \
  | md-table
name sig category
add Number -> Number -> Number Math
adjust (a -> a) -> Number -> [a] -> [a] List
always a -> (* -> a) Function
aperture Number -> [a] -> [[a]] List

Merge JSON files into a single object

cat *.json | R --slurp merge-all

Unwrap a list of objects into Line Delimited JSON

cat data.json | R --unslurp --compact identity

Read filenames from stdin as an object of {filename: body}

find . -name '*.txt' | R -r --slurp 'map -> (it): read-file it' merge-all

Inspect MongoDB collection as a table

mongoexport -d test -c zips --jsonArray -q '{state: "NY"}' --sort '{pop: -1}' |\
  R identity -o table | less -F

Data: http://media.mongodb.org/zips.json

The result looks something like this:

Create an <img> tag based on identify output

$ identify test.png
test.png PNG 594x472 594x472+0+0 8-bit sRGB 187KB 0.000u 0:00.009

$ img-tag test.png
<img src="test.png" width="594" height="472">
#!/usr/bin/env bash

identify "$1" | R -Rr \
  'match /(^.+?) .+\b(\d+)x(\d+)\b/' \
  'tail' \
  'zip-obj [\src, \width, \height]' \
  'h \img, _' \
  '.outer-HTML' \
  'replace "<\/img>", ""'

I use this to create img tags for retina images with dimensions of half the size (for GitHub READMEs). For that you have to add this after the zip-obj line.

'f=parse-int >> (/ 2); evolve width: f, height: f' \

Get a table of things occurring per minute

By using countBy, we get counts for elements of a list according to how many match the supplied function.

In this case, we pass a function that parses a time field and formats it to %H %M with strftime module.

query-es 'url:catpics' | R -s -o table -c \
  'count-by -> require("strftime")("%R", new Date it.time)'
┌───────┬────┐
│ 11:58 │ 10 │
│ 11:59 │ 26 │
│ 12:00 │ 32 │
│ 12:01 │ 96 │
│ 12:02 │ 80 │
│ 12:03 │ 44 │
│ 12:04 │ 46 │
│ 12:05 │ 66 │
└───────┴────┘
Clone this wiki locally