Skip to content

Instantly share code, notes, and snippets.

@meijeru
meijeru / %grep.red
Last active January 21, 2017 05:21
Red [
Title: "Partial grep implementation"
Purpose: {To search the input for lines containing a match
to the given pattern, specified as a regular expression}
Author: "Rudolf W. MEIJER"
File: %grep.red
Version: 0.4.0
Date: "24-Nov-2016"
Rights: "(c) Copyright 2016 Rudolf W. MEIJER"
History: [
now: func [
"temporary replacement for Rebol-like now function, absent in Red"
/time
/local ts dd mm yy hh mm ss
][
ts: read time-server
yy: to integer! copy/part ts 4
mm: to integer! copy/part at ts 6 2
dd: to integer! copy/part at ts 9 2
hh: to integer! copy/part at ts 12 2
Red [
Title: "Tile game with randomizing"
Purpose: {An implementation in Red of the 4x4 sliding tile puzzle
with random start configuration
}
Author: "Rudolf W. MEIJER (meijeru)"
File: %tile-game-2.red
Needs: 'View
Usage: {
Click Random to obtain initial configuration.
Red [
Title: "Red GUI tour"
Purpose: {To showcase the current capabilities of Red GUI}
Author: "Rudolf W. MEIJER"
Version: 0.9.0
Date: "12-Dec-2015"
Needs: 'view
Rights: "Copyright (c) 2015 Rudolf W. MEIJER"
]
Red [
Title: "Tile game"
Purpose: {An implementation in Red of the 4x4 sliding tile puzzle}
Author: "Rudolf W. MEIJER (meijeru)"
File: %tile-game.red
Needs: 'View
Usage: {
Click on any tile that is adjacent to the empty space
and it will shift to that space.
Try to obtain a given configuration, e.g. 1 to 15 in order.
@meijeru
meijeru / split.red
Last active September 28, 2015 14:48
Red mezzanine function to split a string
Red [
Title: "Split mezzanine"
Purpose: {split a string}
Author: "Rudolf W. MEIJER"
File: %split.red
Version: "0.0.0"
Date: "10-May-2015"
Rights: "(c) Copyright 2015 Rudolf W. MEIJER"
License: "TBD" ; source license (URL or full text)
]
@meijeru
meijeru / unicode-multiple.reds
Created October 30, 2011 12:08
UTF-8 string to block of Unicode codepoints conversion: Red/System
Red/System []
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; function utf8-to-cps (cps = codepoints)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This function decodes UTF-8 information supplied as bytes in argument u
; and uses the argument res to store the array of codepoints
; (integers >= 0 and < 10FFFFh); the space for this array should have been
; allocated by the caller; an upper limit for the size of the array in bytes
@meijeru
meijeru / unicode-multiple.r
Created October 25, 2011 17:02
UTF-8 string to block of Unicode codepoints conversion: REBOL
REBOL []
utf8-to-cps: func [ ; yields a block of integers >= 0 and < 1114112
; coding errors are skipped
u [binary!]
/local bcp b1 b2 b3 b4
][
bcp: make block! length? u ; overestimated
while [not tail? u][
b1: u/1
@meijeru
meijeru / unicode.reds
Created October 25, 2011 15:25
Encoding/decoding between Unicode and UTF-8: Red/System version
Red/System []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or -1
u [c-string!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
either 1 = length? u
[
b1: as-integer u/1
either b1 < 128 [
@meijeru
meijeru / unicode.r
Created October 25, 2011 12:25
Encoding/decoding between Unicode codepoints and UTF-8 binary strings
REBOL []
utf8-to-codepoint: func [ ; yields an integer >= 0 and < 1114112, or none
u [binary!] ; should have length 1 to 4
/local b1 b2 b3 b4
][
switch/default length? u [
1 [
b1: u/1
either b1 < 128 [