Rebol.RU
- Сообщество Rebol программистов (25,143)
- How to pass Arguments from PHP to Rebol CGI (PHP/REBOL RPC) (6,082)
- Почему Rebol? (2,845)
- Почитать (2,774)
- Сообщество (2,649)
Feed items
How to create a Quick Alarm Application with Sound Play
I was looking for a freeware for a quick sound alarm and surprisingly couldn’t any that was really quick to use. Naturally I thought about using Rebol and happily this is going to be really easy with the wait and the open sound:// command.
Put a wav file in your rebol directory (for example this one named attention.wav).
Then type or copy and paste in rebol console the code below:
wav: load %attention.wav sound-port: open sound:// wait 30 do [ insert sound-port wav ]
After 30 seconds, the wav should play, easy isn’t it ?
But there is a problem with the code above, if you try again it won’t work as you need to wait for the sound to finish and close the sound port so that the final code is rather:
wav: load %attention.wav sound-port: open sound:// wait 30 do [ insert sound-port wav wait sound-port close sound-port ]
Of course you can then create an alarm function and put it in user.r for recurrent and immediate use each time you launch Rebol’s Console:
alarm: func[seconds][
wav: load %attention.wav
sound-port: open sound://
wait seconds do [
insert sound-port wav
wait sound-port
close sound-port
]
]
Finally if you want OPTIONALLY to add a message use unset! pseudo-type for the message parameter like this:
alarm: func[seconds message [string! unset!]][
wav: load %attention.wav
sound-port: open sound://
wait seconds do [
insert sound-port wav
wait sound-port
close sound-port
if (value? 'message) [
print message
]
]
]
You can then create an alarm like this
alarm 5
or like this:
alarm 5 "attention"
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
How to write software specifications documents fast with Makedoc2 (part1)
In all Fortune 500 companies you are required to write software specifications documents. Even when not a process obligation, writing specs is a good practice according to Joelonsoftware.
But it’s usually time consuming. There are some heavy-weighted $$$$ softwares from IBM, Borland and others which can do so, but they are anti-productivity softwares.
Thanks to Rebol’s little gemware Makedoc2, you can write specs the agile way just using a simple notepad.
For example, you could write a spec like this one below (replace the generic parts with your own custom words for example replace by “My Super Projet”) with a simple notepad (see simple example here):
Software Requirements Specification for <%ProjectName%> Version 1.0 approved <%AuthorName%> - <%organization%> - <%date%>History:
\table Name Date Reason for change Version =row <%authorname1%> <%date1%> <%reason-for-change1%> <%version1%> =row <%authorname2%> <%date2%> <%reason-for-change2%> <%version2%> /table ===Introduction ---Purpose <%{the product whose software requirements are specified in this document, including the revision or release number. Describe the scope of the product that is covered by this SRS, particularly if this SRS describes only part of the system or a single subsystem.}%> ---Project Scope <%{Provide a short description of the software being specified and its purpose, including relevant benefits, objectives, and goals. Relate the software to corporate goals or business strategies. If a separate vision and scope document is available, refer to it rather than duplicating its contents here. An SRS that specifies the next release of an evolving product should contain its own scope statement as a subset of the long-term strategic product vision.}%> ===Overall Description ---Product Perspective <%{Describe the context and origin of the product being specified in this SRS. For example, state whether this product is a follow-on member of a product family, a replacement for certain existing systems, or a new, self-contained product. If the SRS defines a component of a larger system, relate the requirements of the larger system to the functionality of this software and identify interfaces between the two. A simple diagram that shows the major components of the overall system, subsystem interconnections, and external interfaces can be helpful.}%> ---Product Features <%{Summarize the major features the product contains or the significant functions that it performs or lets the user perform. Details will be provided in Section 3, so only a high level summary is needed here. Organize the functions to make them understandable to any reader of the SRS. A picture of the major groups of related requirements and how they relate, such as a top level data flow diagram or a class diagram, is often effective.}%> * Feature 1 * Feature 2 ===System Features <%{This template illustrates organizing the functional requirements for the product by system features, the major services provided by the product. You may prefer to organize this section by use case, mode of operation, user class, object class, functional hierarchy, or combinations of these, whatever makes the most logical sense for your product.}%> ---System Feature 1 <%{Don’t really say “System Feature 1.” State the feature name in just a few words.}%> +++Description and Priority+++Stimulus/Response Sequences <%{List the sequences of user actions and system responses that stimulate the behavior defined for this feature. These will correspond to the dialog elements associated with use cases.}%> #Step 1 #Step 2 #>Step 2.1 #>Step 2.2 #>>Step 2.2.1 =image images/sequenceDiagramBasicCourse.jpg
After saving, run makedoc2.r (.r extension should be associated with Rebol) which will let you choose the file above in a file dialog. Confirm and the html document below will be generated (nothing will prevent you to copy and paste in a document afterwards):

In some next article, I’ll show you some advanced tips for generating specs with Makedoc2.
Update: for software design template see for example this one.
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
How to create your own setup package in 2 minutes
If you want to deploy rebol with your own custom configuration on multiple computers or distribute your applications to other users with a professional looking installer, there’s an easy freeware that can quickly do so which is createinstall. Notably it can write to registry so that you can customize the user startup directory (Free Rebol doesn’t support Reading/Writing to Registry currently which is a pity).
Here’s the step by step instructions below to package makedoc2, a very usefull rebol application for creation html documentation (see Makedoc2’s article):
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
How to simply create a RSS Feed from a text file
If you need to generate a RSS Feed from scratch - for example for an html static website or a site which is not your own - you can of course download some softwares to do so but after trying many of them, I didn’t find them as productive as I wish so I decided to use my favorite scripting language to do so.
If you have followed past tutorials like this one, the script should be easy to understand so I won’t comment it as you should understand it by just reading the source code below. To test it, just copy and paste it in rebol’s console then type genrss and result should be copied to the clipboard.
datas: [
"Creating an OData API for StackOverflow including XML and JSON in 30 minutes"
http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludin...
{I emailed Jeff Atwood last night a one line email. "You should make a StackOverflow API using OData." Then I realized that, as Linus says, Talk is Cheap, Show me the Code. So I created an initial prototype of a StackOverflow API using OData on an Airplane. I allocated the whole 12 hour flight. Unfortunately it took 30 minutes so I watched movies the rest of the time.}
"2010-03-28 09:29"
"Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong"
http://www.hanselman.com/blog/WebDeploymentMadeAwesomeIfYoureUsingXCopyY...
{I did a talk on Deployment called "Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong." }
"2010-03-24 10:36"
"ASP.NET MVC 2 Released"
http://www.hanselman.com/blog/ASPNETMVC2Released.aspx
{ASP.NET MVC 2 is out. This means, it's released. It's final. Use it. Love it.
You can download it directly, or install it (and whatever else you like) with the Web Platform Installer.}
"2010-03-11 09:35"
]
if exists? %datas.txt [
datas: load %datas.txt
]
genrss: func[][
item-template: { -
<%title%>
<%url%>
<%description%>
<%date%>
}
items: copy ""
foreach [field-title field-url field-description field-date] datas [
title: field-title
url: field-url
description: field-description
date: field-date
append items build-markup item-template
append items newline
]
template: {<?xml version="1.0" encoding="UTF-8"?>
Sat, 03 Apr 2010 21:52:39 +0200
<%items%>
}
write clipboard:// build-markup template
]
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
Backup to FTP Server with this free script
There are many great FTP Client Freewares like Filezilla but uploading the same folders again and again is a pain in a hass. So this little Script is a real time-saver as it will allow you to automate your backup or upload to FTP Server. I didn’t have to invent it as it’s the same copy-dir script that exists on Rebol Cookbook with a verbose refinement: I just tested that it really works with FTP :). So here it is:
ftp-backup: func [local-folder ftp-folder /verbose /local i] [
i: 0
if not exists? ftp-folder [
make-dir/deep ftp-folder
either verbose [
print form [ftp-folder "folder created ..."]
][
print i
]
]
foreach file read local-folder [
i: i + 1
either find file "/" [
ftp-backup local-folder/:file ftp-folder/:file
][
either verbose [
print file
][
print i
]
write/binary ftp-folder/:file read/binary local-folder/:file
]
]
]
To use it for example on Dreamhost FTP Server for example, type:
ftp-copy %"/c/install/wordpress/" ftp://ftpuser:ftppassword@maindomain.com/reboltutorial.com/
Note: to have ftp-backup available at startup, store it in user.r.
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
Parsing Optional Html Tag Attributes using none keyword
You really hate Regular Expressions and discovered the power of Parse with our simple parse tutorials. Nevertheless after a while, you feel frustrated because even after reading the excellent manual, you’re still lacking some real world examples. So here’s an example for using none with Parse.
Let’s say you want to parse this:
content: {
}
or
content: {
}
If you try this rule …
attribute1: [{attribute1="} copy valueattribute1 to {"} thru {"}]
attribute2: [{attribute2="} copy valueattribute2 to {"} thru {"}]
attributes-rule: [attribute1 attribute2 (print valueattribute1 print valueattribute2 )
| attribute2 attribute1(print valueattribute2 print valueattribute1)
]
rule: [any [to {} to { } thru {}] to end]
… the second content won’t fully parse. Instead you have to add none keywords like this:
attribute1: [{attribute1="} copy valueattribute1 to {"} thru {"}]
attribute2: [{attribute2="} copy valueattribute2 to {"} thru {"}]
attributes-rule: [[attribute1 | none] [attribute2 | none] (print valueattribute1 print valueattribute2
valueattribute1: none valueattribute2: none)
| [attribute2 | none] [attribute1 | none] (print valueattribute2 print valueattribute1
valueattribute1: none valueattribute2: none
)
| none
]
rule: [any [to {} to { } thru {}] to end]
If you test content 2 with last rule, you should get
>> parse content rule
valueattribute1
valueattribute2
none
valueattribute21
== true
>>
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
How to create a Program Launcher (using Rebol Bind Function)
I have a personal productivity problem as I have a bunch of programs all over the place on my Desktop or in my Program Files Menu. I tried many launchers freewares but none really satisfied me so I finally decided to use Rebol Shell as my launcher. It’s also a great example of a context when you need to use the Bind function in Rebol.
So let’s say I have a list of programs I want to launch by just typing a keyword in Rebol Shell. For example, Notepad would launch my favorite notepad2 program in c:\program files\notepad2\notepad2.exe. So I created a file list shell.list.txt to store them as a sample:
"notepad" "c:\program files\notepad2\notepad2.exe" "calc" "c:\windows\system32\calc.exe" "WebDevExpress" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\VWDExpress.exe"
If this file is located in data sub-directory within the current directory (generally the directory of the current script that is executing), it will be loaded into a Rebol block with this instruction:
shell.list: load %data/shell.list.txt
Then the run function will refer to it to get the real path with the Rebol Select function:
Run: func[exe-path][
if/else not none? it: select shell.list exe-path [
call quote it
][
;in case keyword cannot be found, one supposes it's the full path
call quote exe-path
]
]
Copy and paste it into Rebol Console along with this mock data:
shell.list: ["notepad" "c:\program files\notepad2\notepad2.exe"
"calc" "c:\windows\system32\calc.exe"
"WebDevExpress" "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\VWDExpress.exe"]
So that you can test it by typing
run "c:\windows\system32\calc.exe"
or just the keyword
calc
This latter won’t work. Why? Because calc has not yet been defined as a command in Rebol. To do so, you would create a calc function like this:
calc: func[][
run "c:\windows\system32\calc.exe"
]
Copy and paste the code above and test calc again, this time it should work.
Now, it would be tedious to define each keyword by creating a new function by hand whereas the procedure is rather generic. So naturally you’d like to use a dynamic generator function to do this for you something like this:
foreach [name path] shell.list [
func-body: to-block rejoin ['run " " {"} name {"}]
set (to-word name) make function! [] func-body
]
If you execute the code above, you could see that it created notepad and calc functions by using the rebol source command:
>> source notepad
notepad: func [][run "notepad"]
>> source calc
calc: func [][run "calc"]
>>
Now if you want to test the calc keyword again, you would get this bad “surprise”:
>> calc
** Script Error: run word has no context
** Where: calc
** Near: run "calc"
because run is an unknown word within the context of func-body you created at runtime within the foreach loop. So you have to bind run to the func-body context by using the bind function like this:
set (to-word name) make function! [] bind func-body 'run
so that you can copy and paste the foreach loop once again:
foreach [name path] shell.list [
func-body: to-block rejoin ['run " " {"} name {"}]
set (to-word name) make function! [] bind func-body 'run
]
Finally typing the calc keyword in Rebol Console should launch the calculator !
To have all this automatically at Rebol launch, put these functions in User.r.
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
Rebol Essentials: Free Rebol Ebook
If you’re looking for a free rebol ebook and type this on Google, you won’t find any, whereas there is one excellent here, so to boost it on the search engine, I have created this post.
It’s a gentle but rather complete course to Rebol language which will give you a good background to understand other books like the one from Olivier Auverlot and Peter Wood or tutorials on rebol tutorial or elsewhere like the excellent musiclessonz now re-bol.com.
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
Prepare for the next Big Bang Release: ODBC (use Rebol with MS Access Wow !!!),SSL/HTTPS,…
I know I’ve been a bit harsh lately
but you all know I’m well intentioned and that you should always take my critics positively. But when time comes when I see something great, well I won’t restrain myself from telling it.
And a few days ago, HostileFork has whispered me that in a future release of Rebol 2, you will have nothing less than ODBC, SSL/HTTPS, in fact it is as if you had Rebol Command for FREE. That is not only great, that is unexpected so I say Wow to RT!
What you can do with ODBC ? Well you can edit MS Access Database with your Rebol 500Ko (instead of dozens of megabytes just for the GUI part, of course the data size will stay as big) or you can use secure SSL with twitter API and other webservices, only imagination is the limit :).
Just have all of us to wait for it except if you join Altme World or Qtask at the moment as it is in beta stage.
Update January 19th: From the link given by Petr
http://www.rebol.com/docs/v2-7.html
* View/Pro features enabled: allowing SSL, ODBC, and encryption
* Adds R2/Forward mezzanine functions (from Brian Hawley)
* Re-enables installation and proper view-root startup (appdata dir on Win32)
* Install and uninstall added to ViewTop GUI panels
* Fixes LOAD with PORTS that return strings to be loaded as blocks.
* Fixes Decode-CGI for url-encoded variables (e.g. used by Flash)
* Fixes Strict-not-equal? of integers and adds != and !== operators
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->
How to pass Arguments from PHP to Rebol CGI (PHP/REBOL RPC)
PHP is everywhere, it has a huge Ecosystem of Libraries (like User’s Session Management, Security, …) which are still lacking in REBOL (though Rebol has all the network protocols and the very nice Parse to process strings, building a well-organised reusable framework takes time), so it makes sense to use PHP as Front-End to the External World by wrapping REBOL Objects - which would be considered to reside in the Business Layer in an Enterprise Application Architecture - and communicate between the two using a kind of RPC - instead of Web Services for better performance and integration when we can have control of both sides.
We have in fact already seen how to call a Rebol CGI from PHP, it’s now time to look at message passing from PHP to Rebol (the return message stays the same: the output of Linux/Windows standard I/O).
Let’s take the example of a search form. Instead of posting to Rebol CGI from the html form embedded in an HTML Page like this:
We would put the form in an index.php page and call the same index.php from the form
then within index.php we would test for the existence of the $_GET['s'] variable or not and forward to search.cgi passing the search term and any other other parameters we want by separating them with space, for example below, we also pass the command “search” at the end (this could be usefull if we have several kind of actions):
<?php
if (!isset($_GET['s'])) {
$command= './cgi-bin/index.cgi';
echo system($command);
}
else {
$searchterm = $_GET['s'];
$command= './cgi-bin/search.cgi '. '"' . $searchterm . '"' . ' ' . '"' . 'search' . '"';
echo system($command);
}
?>
On Rebol’s side we just have to pick the search term from the first element of system/options/args block (Rebol’s array):
#!/home/yourhostingaccount/yourdomain/rebol/rebol -c
REBOL [Title: "Search"]
command-line: system/options/args
search-term: pick command-line 1
]
If we want we could even make the script work in both context RPC or CGI by testing system/options/cgi/remote-addr:
#!/home/yourhostingaccount/yourdomain/rebol/rebol -c
REBOL [Title: "Search"]
test-remote: system/options/cgi/remote-addr;
;write/append/lines %log.txt mold test-remote
;write/append/lines %log.txt mold system/options/args
if/else (none? test-remote) [
command-line: system/options/args
search-term: pick command-line 1
][
print "content-type: text/html^/"
;==========================
do %cgi.lib.r
cgi: get-cgi
;write/append/lines %log.txt mold cgi
;==========================
search-term: cgi/s
;write %log.txt search-term
]
Of course this is just the basis of RPC between PHP and Rebol. A more standard serialization format could be defined furthermore using Rebol format or any other like JSON.
This is simple and flexible so that mixing PHP and Rebol should be a pleasure for both lovers of one language or the other while ripping the benefits from both sides : no more languages war :).
<!-- Social Bookmarks BEGIN -->
<!-- Social Bookmarks END -->


























