-
Notifications
You must be signed in to change notification settings - Fork 12
Cookbook
rai-bot edited this page Jun 11, 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](#create-a-markdown-formatted-table-of-ramdas-functions)
- [Merge JSON files into a single object](#merge-json-files-into-a-single-object)
- [Unwrap a list of objects into Line Delimited JSON](#unwrap-a-list-of-objects-into-line-delimited-json)
- [Read filenames from stdin as an object of `{filename: body}`](#read-filenames-from-stdin-as-an-object-of-filename-body)
- [Inspect MongoDB collection as a table](#inspect-mongodb-collection-as-a-table)
- [Create an `<img>` tag based on `identify` output](#create-an-img-tag-based-on-identify-output)
- [Get a table of things occurring per minute](#get-a-table-of-things-occurring-per-minute)
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 │
└───────┴────┘
Repository: https://github.com/samayo/country.json
git clone [email protected]:samayo/country.json.git
cat src/country-{population,continent,domain-tld}.json | R --slurp -o table -c \
'unnest' \
'group-by (.country)' \
'map-obj merge-all' \
'values'
┌──────────────────────┬────────────┬───────────────┬─────┐
│ country │ population │ continent │ tld │
├──────────────────────┼────────────┼───────────────┼─────┤
│ Aruba │ 103000 │ North America │ .aw │
│ Afghanistan │ 22720000 │ Asia │ .af │
│ Angola │ 12878000 │ Africa │ .ao │
│ Anguilla │ 8000 │ North America │ .ai │
│ Albania │ 3401200 │ Europe │ .al │
│ Andorra │ 78000 │ Europe │ .ad │
│ Netherlands Antilles │ 217000 │ North America │ .an │
│ United Arab Emirates │ 2441000 │ Asia │ .ae │
│ Argentina │ 37032000 │ South America │ .ar │
│ Armenia │ 3520000 │ Asia │ .am │
└──────────────────────┴────────────┴───────────────┴─────┘
cat src/country-population.json | R -o table -c \
'sort-by prop \population'
'map evolve population: require \approximate-number'
'reverse'
┌────────────────────┬────────────┐
│ country │ population │
├────────────────────┼────────────┤
│ China │ 1.3b │
│ India │ 1b │
│ United States │ 278m │
│ Indonesia │ 212m │
│ Brazil │ 170m │
│ Pakistan │ 156m │
│ Russian Federation │ 147m │
│ Bangladesh │ 129m │
│ Japan │ 127m │
│ Nigeria │ 112m │
└────────────────────┴────────────┘