Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / _.md
Last active November 12, 2015 19:34
test
@toomasv
toomasv / split-block.red
Last active April 23, 2017 15:26
Break a block into pieces using the provided delimiter
Red [Author: "Toomas Vooglaid"
Adapted-from: "split"
Date: "2017-04-23"
Version: "0.1"
]
split-block: func [
{Break a block into pieces using the provided delimiter}
series [block! hash!] dlm [string! char! bitset! any-word! any-block!] /local s num
][
num: either any-block? dlm [length? dlm] [1]
@toomasv
toomasv / to-columns.red
Last active June 30, 2017 10:26
Format a block into columns
Red [
Author: "Toomas Vooglaid"
Date: "2017-05-05"
Needs: {Examples may use `fill.red` by Gregg Irwin (https://gitter.im/red/red/welcome?at=590b4daac93941e153c94b8e)
or as adapted by me (https://gitter.im/red/red/welcome?at=590cae8d33e9ee771c793966)}
]
to-blocks: func [
{Splits a block into more or less equal chuncks}
blk [block!] {Initial block to split}
num [integer!] {Number of resulting chuncks}
@toomasv
toomasv / fill.red
Last active August 29, 2017 16:39
Formatting a value
Red [
Author: "Gregg Irwin"
File: "%fill.red"
Source: "Gitter @greggirwin "
Reference: ":point_up: [May 4, 2017 6:50 PM](https://gitter.im/red/red/welcome?at=590b4daac93941e153c94b8e)"
Changed-by: "Toomas Vooglaid"
Changed-date: "2017-05-05"
Change: "Added 'justify and helper 'x'"
]
x: make op! func [n c][pad/with copy "" n to char! c]
@toomasv
toomasv / dir-tree.red
Last active January 6, 2022 11:30
Print a directory tree
Red [
Author: "Toomas Vooglaid"
Date: "2017-05-07"
Changed: "2018-07-09"
Purpose: "Print a directory tree"
File: "%dir-tree.red"
]
context [
; Some helpers
get-char: func [hex][to-char to-integer hex]
@toomasv
toomasv / regex.red
Last active November 20, 2017 18:22
Regex to parse translator
Red [
Author: "Toomas Vooglaid"
file: "%regex.red"
Purpose: {Regex to parse converter}
History: {Started: 2017-05-09
v.0.1: 2017-05-12 -- first working version with:
start `^^` and end `$` anchors,
non-capturing groups (one level) with alterns,
quantifiers (possessive),
some character-classes.
Red [
Author: "Toomas Vooglaid"
file: "%regex~.red"
Purpose: {Perl-like regex for Red}
History: {
Started: 2017-05-30 from %regex.red
2017-05-31 Improved pattern. Now simple matches with no modes can be done wo delimiters.
eg. "abcbba" ~ "^^[abc]+$"
2017-06-01 Some minor changes in code from regex.red
}
@toomasv
toomasv / feats.red
Last active June 30, 2017 10:22
Find recent feats
Red [
Title: {Find recent feats}
Usage: {`feats 30` -- find 30 latest feats
`see 5` -- see 5th feat's code
}
Needs: {To improve readability you can use `to-columns`
(https://gist.github.com/toomasv/464bd3bc775b75ce734bebf6d7aca190)
}
]
context [
@toomasv
toomasv / feats2.red
Created June 29, 2017 08:58
Find feats through github-api.v3
Red [
Title: {Find feats through github-api.v3}
Author: {Toomas Vooglaid}
Started: {2017-06-27}
Needs: {
* rebolek's http-tools (https://github.com/rebolek/red-tools/blob/master/http-tools.red)
* my regex~ (https://github.com/toomasv/regex/blob/master/regex~.red)
* my to-columns (https://gist.github.com/toomasv/464bd3bc775b75ce734bebf6d7aca190)
* github access token
}
@toomasv
toomasv / reverse.red
Last active September 1, 2017 06:25
Rewrite of `reverse` to allow record-like reversing
reverse: func [
series /skip size /part length /local i tuple
][
switch type?/word series [
pair! [return to-pair reduce [series/2 series/1]]
tuple! [tuple: clear [] repeat i length? series [append tuple pick series i] series: copy tuple tuple: yes]
]
size: any [size 1]
either 0 = ((length? series) % size) [
length: any [length length? series]