Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / clock-states.red
Created February 12, 2021 13:40
Harel's Citizen Quartz Multi-Alarm III statechart emulation for DiaGrammar
DiaGrammar [
Options: [
grammar-only?: false
ruleset: true
hovering: true
string-input: true
case-parsing: false
live-edit?: true
iterate-times: 1
max-iterate: 5
@toomasv
toomasv / merry.red
Created December 29, 2020 13:55
Fancy message decoration
Red [
Date: 29-Dec-2020
Purpose: "Fancy message decoration"
]
context [
font: [size: 32 style: 'bold]
size: 360x70
text: "Merry Christmas!"
area: make-face 'area [size: 1200x20 font: xfont]
@toomasv
toomasv / transparent.red
Last active December 24, 2020 15:34
Turn a color in image transparent
Red [
Description: "Make some color of image transparent"
Date: 23-December-2020
]
context [
smudge: function [b [tuple!]][
a: b - 1 c: b + 1
reduce [
charset reduce [a/1 b/1 c/1]
charset reduce [a/2 b/2 c/2]
@toomasv
toomasv / expression.red
Last active November 30, 2020 20:41
Parse math string into Red block and optionally evaluate.
context [
expr: [term any [(op: add) enspace [term | (missing: "term") message]]]
term: [
record factor [
some [ahead [var | #"("] insert " * " factor
| (op: mul) enspace [factor | (missing: "factor") message]
] set-parens
| (remove position)
]
]
@toomasv
toomasv / simple-pie.red
Created November 14, 2020 11:00
Simple pie-chart
Red [
Description: "Simple pie chart"
File: %simple-pie.red
Author: "Toomas Vooglaid"
Original: https://gitter.im/red/help?at=5b4f23adecc1f82e2fc206d6
Date: 18-Jul-2020
Adaptation: 14-Nov-2020
]
start: -90
tx: make-face 'text
@toomasv
toomasv / replace.red
Last active September 25, 2020 08:58
`replace` extended with `/only` refinement
Red [
Description: "`replace` extended with `/only` refinement"
Date: 24-Sep-2020
]
replace: func ["Replaces values in a series, in place"
series [series!] "The series to be modified"
pattern "Specific value or parse rule pattern to match"
value "New value, replaces pattern in the series"
/all "Replace all occurrences, not just the first"
/deep "Replace pattern in all sub-lists as well"
@toomasv
toomasv / quiz.red
Created September 21, 2020 15:16
Quiz about capitals
Red []
page: read-thru/binary https://geographyfieldwork.com/WorldCapitalCities.htm
quiz: does [
capitals: clear []
loop 5 [
list: head page
loop (random 200) - 1 [
l: find list <td height="17"> list: find l </tr>
]
parse to-string copy/part l: find list <td height="17"> list: find l </tr> [
@toomasv
toomasv / hangman.red
Last active September 24, 2021 03:29
wallysilva's hangman modified
Red [
Title: "The Hangman Game"
Date: "21-Jul-2020"
Author: Wally Silva
File: %hangman.red
Needs: View
Original: https://github.com/wallysilva/red-hangman
Modified: {toomasv on 31-Jul-2020}
Tab: 4
]
@toomasv
toomasv / draw-table.red
Last active September 24, 2021 03:28
Experiment with draw-based table
Red [
Description: "Simple navigation for draw-based table"
]
recycle/off
len-data: 200'000;0
data: make block! len-data
rows: 30
cols: 11
bx: 100x24
current: none
@toomasv
toomasv / intermediate.red
Last active June 25, 2021 10:07
Show intermediate values of expression in console
Red [
Description: "Show values of intermediate expressions"
Date: 12-Jun-2020
]
term: gui-console-ctx/terminal
show: function [][
out2: copy [] out: pos: copy []
found: find/tail term/line "show "