Skip to content

Instantly share code, notes, and snippets.

@nedzadarek
nedzadarek / red_draw_names.red
Created October 26, 2018 15:16
Uses `el1/type` instead of index `face/draw/1` for changing draw elements
Red [
author: "Nędza Darek"
version: 0.0.1
license: {
use/edit everywhere
post link to the gist/github
no waranties
}
]
get-draw-element: function [draw] [
@nedzadarek
nedzadarek / caching_and_serializing.red
Created September 14, 2018 12:48
Fibonacci with cache and serializing cache to a string
Red [
author: "Nędza Darek"
license: "Just point to this gist/github"
link: https://gist.github.com/nedzadarek/43878a2eedd31c793e35eac854bcfe3d
]
; if `n` is in the cache just return `n` else print ['not-cached n]
fib: function [n] bind [
cache
either c: cache/:n [
s1: {This is a description without example.
}
s2: {doc: description of s2
example: foo <baz> <bar>
}
s3: {example: foo3 <baz> <bar>
}
f: func [str][
Red [
author: "Nędza Darek"
license: "point to this gist/github"
]
get-with-paren: function [:word [word! path! paren!]] [
case [
word? word [
get get :word
]
@nedzadarek
nedzadarek / help-vid.red
Created September 3, 2018 12:10
Help system for vid (tested with Red for Windows version 0.6.3 built 26-Mar-2018)
Red [
author: "Nędza Darek"
license: "Just point to this repository/gist"
content-used: [
examples: http://www.red-by-example.org
docs: https://doc.red-lang.org/en/vid.html
]
bugs-new_features: [
printing: {Print in nice form and divide by words}
]
@nedzadarek
nedzadarek / 2-way-drawing.red
Created August 2, 2018 11:39
Draws rectangles on the red canvas & update the area text with the `draw` code. Updates the red canvas when you write something in the area.
view [
do [start: end: 0x0 ]
b: base red 100x100 draw [] on-down [
start: event/offset
] on-up [
end: event/offset
append b/draw c: reduce ['box start end]
append a/text form c
append a/text newline
]
@nedzadarek
nedzadarek / probe-event.red
Created July 22, 2018 23:05
Probe `event` type from view/vid
probe-event: function [e] [
fields: [
type
; face window ; big objects - do you need them?
offset key picked flags away? down? mid-down? alt-down? ctrl? shift?]
foreach field fields [
prin mold field
print ": "
probe e/:field
]
; stop: 0:0:1
2 -> 2.0
4 -> 4.0
6 -> 6.0
8 -> 8.0
10 -> 9.0
12 -> 11.0
14 -> 13.0
16 -> 16.0
18 -> 16.0
Red[
author: "Nędza Darek"
]
str: "a1bcvcvba2mcbncva3z"
find str "a"
iterator: copy #()
find-next: func [
str candidate
/local
@nedzadarek
nedzadarek / func-set-local.red
Created July 6, 2018 12:09
Making words set by 'set' local - sample
func-set-local: func [spec body] [
locals: copy []
parse body [
to any ['set set w lit-word! (probe w) (append locals w)]
to end
]
func append spec compose [/local (locals)] body
]
f: func-set-local [a b] [set 'c (a + b) c]