Skip to content

Instantly share code, notes, and snippets.

@toomasv
toomasv / range-pre-load.red
Last active June 23, 2020 05:29
Mimick range and bound syntax
Red [
Description: "Pre-load to mimic range/bounds syntax"
Date: 22-May-2020
Author: @toomasv
]
context [
default-start: func [stop step][
case [
any [percent? stop percent? :step][1%]
any [pair? stop pair? :step][1x1]
@toomasv
toomasv / range-ops.red
Last active May 24, 2020 07:21
Range and step ops
Red [
Description: "Some range and step ops"
Date: 21-May-2020
]
;Simple range op!
;works when a < b and with integer! and date! only
..: make op! func [a [integer! date!] b [integer! date!] /local i out][
out: copy [] repeat i b - a + 1 [append out i - 1 + a]
]
@toomasv
toomasv / replace-each.red
Last active April 13, 2020 12:03
Replace several items in one run + example converters
Red [
Description: {Replace several items in one run + example conversions}
Date: 27-Mar-2020
Author: "Toomas Vooglaid"
]
context [
sp: charset " ^-"
sp*: [any sp]
digit: charset "0123456789"
integer: [some digit]
@toomasv
toomasv / compare.red
Last active March 25, 2020 12:56
Return relation of provided arguments
Red [
Description: {Return relation of provided arguments}
Date: 25-Mar-2020
Author: "Tooams Vooglaid"
]
compare: function [
"Compare arguments and return their relation"
a [any-type!]
b [any-type!]
/length "Compare length of arguments"
@toomasv
toomasv / bmath.red
Last active March 6, 2020 13:03
Boundary-math with James' numbers
Red [
Title: "Boundary Math with James' numbers"
Source: http://www.wbricken.com/pdfs/01bm/06number/bnums-complete/07bnums-james.pdf
Fail: %bmath.red
Date: 6-Mar-2020
Author: "Toomas Vooglaid"
]
object [
main: [(res: 0 clear stack) struct collect keep (round/to res .001)]
stack: copy []
@toomasv
toomasv / bf.red
Last active October 4, 2020 03:45
Another brainfuck implementation
Red []
;#do [debug: no] ;Seems not to work anymore
ctx: context [
what: none
size: 30000
eof: 0
c: 0
lim: none
input-text: none
db: func [check][not empty? intersect check what]
@toomasv
toomasv / named-color-picker.red
Last active February 29, 2020 04:14
Pick named Red-colors and Web-colors
Red [
Date: 28-Feb-2020
Description: "Another color-picker with named Red-colors and Web-colors"
Licence: "Public domain"
File: %named-color-picker.red
Idea: https://gitter.im/red/red/gui-branch?at=5e58287f4eb23e6ae179f475
]
context [
red-colors: split replace/all lowercase trim help-string tuple! [some [#" " | #"^/"]] #" " #" "
remove back tail red-colors
@toomasv
toomasv / web-colors.red
Created February 28, 2020 10:32
Web-colors to populate text-list
Red [
Date: 28-Feb-2020
Description: "Web-colors"
Source: https://htmlcolorcodes.com/color-names/
]
web-colors: [
"IndianRed" 205.92.92
"LightCoral" 240.128.128
"Salmon" 250.128.114
"DarkSalmon" 233.150.122
@toomasv
toomasv / color-by-dragging.red
Last active January 12, 2020 16:05
Minimal colorer
Red [
Date: Jan-12-2020
Description: "Color key-selected elements by up/down dragging"
Help: {
Key for elements:
D - BackDrop
T - Text
F - Fill
P - Pen
Key for channel:
@toomasv
toomasv / clean-url.red
Created November 26, 2019 14:22
Crude hack for cleaning a web-page.
Red [
Date: 26-Nov-2019
See: https://gitter.im/red/help?at=5ddd28def65fec1c8e72c7da
]
clean-url: function [url][
bin: read/binary url
while [
error? err: try [str: to-string b: bin]
][
while [b: find b err/arg1][remove b]