Skip to content

Instantly share code, notes, and snippets.

@hiiamboris
hiiamboris / func-cache-estimation.red
Created Mar 18, 2021
Function cache size estimation and cache creation prototype
View func-cache-estimation.red
Red []
#include %assert.red
#include %keep-type.red
#include %composite.red
#include %map-each.red
#include %format-number.red
#macro [#print string!] func [[manual] s e] [insert remove s [print #composite] s]
word-id: routine [word [any-type!] return: [integer!] /local w] [
@hiiamboris
hiiamboris / rolling-text.red
Last active Mar 16, 2021
Smooth rolling text
View rolling-text.red
Red []
speed: 50
rt: rtd-layout [{ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}]
rt/font: make font! [name: "Colonna MT" size: 100]
rt/size: 99999x999
rt/size: size-text rt
draw: compose/deep [scale 0.5 0.5 [pen cyan text 0x20 (rt)]]
draw2: compose/only/deep [translate 0x0 (draw) translate (rt/size * 1x0 / 2) (draw)]
t0: now/precise
View lagometer.red
Red [needs: view]
img: draw 4000x2000 [scale 2 2 fill-pen yello circle 1000x500 1000 500]
lag: object [max: avg: 0.0]
offset: 0x0
plot: []
system/view/auto-sync?: off
view/no-wait [
below
@hiiamboris
hiiamboris / react-mark-view.red
Last active Jun 19, 2020
Reactivity benchmark (using faces)
View react-mark-view.red
Red [title: "reactivity benchmark" needs: view] ;) run as `red --cli ...` to eliminate GUI console influence!
do https://gitlab.com/hiiamboris/red-mezz-warehouse/-/raw/master/clock.red
do-unseen: function [code [block!]] [
old: system/view/auto-sync?
system/view/auto-sync?: no
do code
system/view/auto-sync?: old
]
@hiiamboris
hiiamboris / react-mark-noview.red
Last active Jun 19, 2020
Reactivity benchmark (using reactors)
View react-mark-noview.red
Red [title: "reactivity benchmark"] ;) run as `red --cli ...` to eliminate GUI console influence!
do https://gitlab.com/hiiamboris/red-mezz-warehouse/-/raw/master/clock.red
recycle/off
print-count: does [
attempt [print ["relations count:" (length? system/reactivity/relations) / 4]]
attempt [print ["relations count:" system/reactivity/relations-count]]
]
@hiiamboris
hiiamboris / react-mark.red
Last active May 25, 2020
Reactivity benchmark
View react-mark.red
Red [title: "reactivity benchmark" needs: view] ;) run as `red --cli ...` to eliminate GUI console influence!
do https://gitlab.com/hiiamboris/red-mezz-warehouse/-/raw/master/clock.red
do-unseen: function [code [block!]] [
old: system/view/auto-sync?
system/view/auto-sync?: no
do code
system/view/auto-sync?: old
]
@hiiamboris
hiiamboris / slow-redraw.red
Created May 22, 2020
Time redraw of an image
View slow-redraw.red
Red [needs: view] ;) run as `red --cli ...` to eliminate GUI console influence!
img: make image! 2000x1000 ;) need a big enough image
system/view/auto-sync?: no ;) disable auto-update so we can profile it
view [
panel [
base font-color black "CHASE THE MOUSE AROUND" 1000x500 img
all-over on-over [
t0: now/precise
face/image/(10x10): random white ;) update the image
@hiiamboris
hiiamboris / inspect.red
Created Dec 11, 2018
image inspector func
View inspect.red
Red []
inspect: function [i] [
pixel: 10x10
? (also i': make image! i/size * pixel
x: y: repeat y i/size/y [
repeat x i/size/x [
p: as-pair x y
draw i' compose [
line-width 1 pen (i/:p) fill-pen (i/:p)
@hiiamboris
hiiamboris / parse-then-test.red
Created Jul 21, 2018
Test of the `then` keyword
View parse-then-test.red
Red []
idiom: [ [a (x: b) | reset (x: c)] x | reset d ] ; 1
impl: [ a then b | reset c | reset d ] ; 2
;impl: [ a b | reset c | reset d ] ; 2
;impl: [ (f: yes) a (f: no) b | reset if (f) c | reset d ] ; 1
;impl: [ a b | reset not a c | reset d ] ; 3
;impl: [ not a c | reset a b | reset d ] ; 3
;impl: [ [a fail b] | reset c | reset d ] ; 2, nightly build only
;impl: [ p: a [b | :p reset d |] | reset c | reset d ] ; 1
@hiiamboris
hiiamboris / composite.red
Last active Jun 12, 2018 — forked from greggirwin/composite.red
Composite func (compose for strings) for Red
View composite.red
Red [
Author: [@greggirwin @endo @toomasv]
Purpose: "COMPOSE for strings"
Notes: {
TBD: Security model for eval'ing expressions
TBD: Decide if support for custom marker and eval contexts are worthwhile
TBD: Finalize refinement names
}
]