Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / loose-ref.red
Created November 26, 2019 05:20
Example of letting refinements loose
Red []
system/lexer/pre-load: func [src][
ws: charset reduce [space tab newline]
ws+: [some ws]
dig: charset "0123456789"
num: [some dig]
parse src [any [
"myfunc" s: ws+ 2 [num ws+]
any [i: ["/r3" | "/r4"] ws+ num ws+ (
move/part i s 3
@toomasv
toomasv / parse-study.red
Created November 23, 2019 14:37
Study matching of `any-string!`, `any-word!` and `any-path!` values in `parse`
Red [
Description: "Study of parsing `any-string!`, `any-word!` and `any-path!` values"
Date: 23-Nov-2019
]
string-parse: function [s /case /quote /upper /block][
l: append/dup copy "" #" " 15
s2: either upper [uppercase copy s][s]
print append copy l "string url tag email file"
types: [to-string to-url to-tag to-email to-file]
@toomasv
toomasv / m2-pricing.red
Last active November 22, 2019 22:38
Little unit handling dialect
Red [
Description: "Exercise in limited unit handling"
Date: 22-Nov-2019
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
context [
digit: charset "0123456789."
num: [some digit]
unit: ["$/m2" | #"$" | "m2"]
@toomasv
toomasv / de-hex.red
Created November 15, 2019 13:52
Dehexing to char
Red [
Purpose: {Workaround for limitation of official `dehex` func}
Date: 2019-11-15
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
de-hex: func [hex [string!] /low][
if odd? length? hex [
hex: copy next hex
]
@toomasv
toomasv / pie-style.red
Last active November 14, 2020 17:04
Another pie style
Red [
Description: {Pie style with panel and extendable actors}
Date: 9-Nov-2019
Updated: 14-Nov-2020
Author: "Toomas Vooglaid"
]
extend system/view/VID/styles [
pie: [
template: [
type: 'panel
@toomasv
toomasv / charset-def
Last active October 28, 2019 12:15
Reconstructs charset definition from a `bitset!`
Red [
Description: "Reconstructs charset definition from a `bitset!`"
Date: 2019-10-28
Author: "Toomas Vooglaid"
Rights: "Public domain"
]
charset-def: function [
"Reconstruct charset definition from bitset"
cs [bitset!]
@toomasv
toomasv / form-to.red
Last active November 3, 2022 06:33
Form number to given precision
Red [
Description: "Form number to given precision"
Date: 2019-0-13
]
form-to: func [
"Form number to a given floating-point precision"
number [number!] "Number to be formed"
precision [integer!] "Decimal places (positive integer)"
/local pcnt?
][
@toomasv
toomasv / autoselect
Last active October 13, 2019 22:11
Dropdown autoselect mimick
Red [
Description: "Drop-down autoselect"
]
blk: [
["Blog" http://www.red-lang.org]
["About" https://www.red-lang.org/p/about.html]
["Getting Started" https://www.red-lang.org/p/getting-started.html]
["Download" https://www.red-lang.org/p/download.html]
["Documents" https://www.red-lang.org/p/documentation.html]
["Contributions" https://www.red-lang.org/p/contributions.html]
@toomasv
toomasv / quat.red
Created September 21, 2019 18:40
Some quaternion manipulation funcs
Red [
Description: {Some quaternion manipulation funcs}
Date: 21-Sep-2019
Author: "Toomas Vooglaid"
]
quaternion: context [
quaternion!: make typeset! [block! hash! vector!]
e-pow: function [q][
sc: x: y: z: none
set [sc x y z] q
@toomasv
toomasv / zoom-and-move.red
Last active September 5, 2019 12:39
Zooming and moving different faces
Red [
Date: 5-Sep-2019
Description: {Example of zooming and moving with different faces}
Author: "Toomas Vooglaid"
Licence: "Public domain"
]
context [
ofs: just-down: none
moving: function [face event][