-
Notifications
You must be signed in to change notification settings - Fork 12
Cookbook
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.
- Create a markdown formatted table of Ramda's functions
- Merge JSON files into a single object
- Unwrap a list of objects into Line Delimited JSON
- Read filenames from stdin as an object of
{filename: body}
- Inspect MongoDB collection as a table
- Create an
<img>
tag based onidentify
output
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 |
cat *.json | R --slurp merge-all
cat data.json | R --unslurp --compact identity
find . -name '*.txt' | R -r --slurp 'map -> (it): read-file it' merge-all
mongoexport -d test -c zips --jsonArray -q '{state: "NY"}' --sort '{pop: -1}' |\
R identity -o table | less -F
The result looks something like this:
$ 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' \
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 │
└───────┴────┘