Skip to content

Instantly share code, notes, and snippets.

REBOL []
start-url: http://exam.com
done-file: %done.txt
storage: %strore.txt
done-urls: attempt [ read/lines done-file ]
urls: copy []
get-a: func [ url [ url! ] /local rule data s] [
rule: [ while [ thru "<a" thru "href=" skip copy s to [{"} | {'} ]
(if all [find [ %.htm %.html] suffix? s not find urls s not find done-urls s find/match s "http"] [ append urls to-url s ] )
@WayneCui
WayneCui / set-operation.reb
Last active December 31, 2015 10:29
集合函数:阶乘、排列和组合
REBOL []
factorial: func [ n [ integer! ]][
factorial-util n 1
]
factorial-util: func [ n [ integer! ] init [ integer! ]][
if any [ n = 0 n = 1] [ return init ]
return factorial-util n - 1 init * n
]
@WayneCui
WayneCui / tic-tac-toe-2.reb
Last active December 31, 2015 12:58
井字棋游戏(Tic-tac-toe)
REBOL [
title: "A Tic Tac Toe Game to play with a clever computer."
]
tic-tac-toe: context [
keypoints: [[ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ] [ 1 4 7 ] [ 2 5 8 ][ 3 6 9 ] [ 1 5 9 ][ 3 5 7 ]]
center: 5
corners: [ 1 3 7 9 ]
sides: [ 2 4 6 8 ]
REBOL []
blk: [a b c d]
indexes: [1 3]
result: collect [
foreach index indexes [
keep blk/:index
]
]
probe result
@WayneCui
WayneCui / chrismas-tree.reb
Created December 24, 2013 16:29
圣诞树
REBOL []
dialect: [ 3 space 1 asterisk 3 space lf
2 space 3 asterisk 2 space lf
1 space 2 asterisk 1 star 1 asterisk lf
1 star 1 asterisk 1 star 3 asterisk lf
2 space 3 asterisk 2 space lf
1 space 2 asterisk 1 star 1 asterisk 1 space lf
7 asterisk lf
3 space 1 bar 3 space lf
@WayneCui
WayneCui / red-parse-test.red
Last active August 29, 2015 13:56
Red Parse测试
Red []
str: "<Ids></Ids><Names></Names><Ids>99</Ids><Names>bar</Names>"
rule-1: [
some [
thru "<Ids>" insert "01" [ "</Ids>" | insert "," ]
thru "<Names>" insert "foo" [ "</Names>" | insert ","]
]
]
@WayneCui
WayneCui / red-test.red
Created March 5, 2014 05:03
Red 测试
Red []
data: [1 2 3 4 "a" "b" "c" "d"]
output: make block! length? data
foreach [p1 p2 p3 p4] data [ output: reduce/into [p1 p3 p4] output ]
probe head output
>> type? f: func[][print "foo"]
== function!
>> type? get 'f
== function!
>> type? f
"foo"
== unset!
@WayneCui
WayneCui / comment-cleaner.reb
Last active August 29, 2015 14:10
remove comments from JS source files
Rebol [
Title: {remove comments from JS source files}
Author: "Cui Wen"
File: %comment-cleaner.reb
Version: 0.1.0
Tabs: 4
]
data: {
/**
@WayneCui
WayneCui / parse-file-uploads-data.reb
Last active August 29, 2015 14:10
Parse file uploads data by HTTP
Rebol [
Title: "Parse file uploads data by HTTP"
Author: "Cui Wen"
Description: {
simulate file-uploading via curl:
curl --form upload=@D:/a.txt --form upload=@D:/a.jpg --form press=OK http://localhost:8080
}
]
server: open tcp://:8080