World: r4wp
[Rebol School] REBOL School
older newer | first last |
ChristianE 14-May-2012 [292x3] | indent: funct [string [string!]] [ whitespace: charset "^- " indention: line-start: content: none parse/all string [ copy indention any whitespace any [thru "^/" line-start: any whitespace content: (insert remove/part line-start content indention) :content] ] string ] |
>> print indent ajoin [tab " test" newline tab tab "line 2" newline tab "line 3"] test line 2 line 3 | |
Or what else is it what you're wanting to do? | |
Endo 14-May-2012 [295x2] | hah! I wrote something similar: indent: func [s /local x] [parse/all s [x: (insert x "^-") any [thru newline x: (insert x "^-")]] s] |
It's simple but it solves my issue. | |
JohnM 14-May-2012 [297x2] | Hello, all. I am new to REBOL4 and while having followed Lava to REBOL and looked through tutorials every year once a year for more than 10 years I have only recently began making an actual REBOL script. |
I hope it is not rude to leave a question here as opposed to be here for the disucssion live, ala IRC. Please forgive me if so, and if so I will ask again when others are present. I will break down my script into smaller part questions as time goes on. First thing, I am under the impression that if I can generate a random number between 1 and 1 billion and assign this result to an aribtray variable word like so token: random/secure 1000000000 I want to email my newly generated random number to someone. So I thought of this: send [person-:-example-:-com] "Thank you. Your number is token." One second later I realized that will just the send the actial word token, not the number the variabkle word token represents. Is the above a correct way to generate a random number? How do I insert that random number into the body of the text of an email to send someone? (send [person-:-example-:-com] "Thank you. Your number is [token]" maybe?) Thanks for your help in advance, apologies for any breach of rules or etiquette. etiquetteetiquette | |
GrahamC 14-May-2012 [299] | You need to seed the random generator first eg. with the datestamp or something, and then generate your random number. But a better way is to create a UUID if you want something guaranteed to be unique. The library has code for windows http://www.rebol.org/view-script.r?script=guid.r Just using random, something like this should work random/seed form now/precise send [person-:-example-:-com] rejoin [ "Thank you. Your number is " random/secure 1000000 "." ] |
Maxim 14-May-2012 [300x2] | welcome to Rebol John, this group's etiquette is: "there are no stupid or wrong questions". In case you ever wonder if you are asking too advanced questions at some point .... the fact that you are thinking of asking them here is an indication that you're still a candidate for this group :-) |
even the simplest questions are good to keep our memories intact, and I've learned quite a few things when trying to respond to some seemingly simple questions (often by looking at other people's innovative answers). | |
GrahamC 15-May-2012 [302x2] | But there are off topic questions :) |
BTW, looks like the 'form is not needed above | |
Gregg 15-May-2012 [304] | And don't wait for people to be online. One of the great things about AltMe is the async nature. |
JohnM 15-May-2012 [305] | Thank you all for addressing my concerns and for your answers about my first coding question. Ahh.. rejoin. Reading up on it makes me better understand how some things are to be done in Rebol. Continuing to the final goal... I have to extract an email address from a GET transfer. The methoed of sending the info to me is completely out of my control. An email address will be entered into a form on a website not controled by me. GET methoed will send the data to my script. The people who created the form on the external site advised that they label the email address as "trnEmailAddress". So now I want to see if I am correct in thinking how to extract and use the email address. Will using the decode a cgi form command (I know they are not commands in the tradiational sense) work. How does it work, does it create variables out of the GET (or Post when using Post, but I am forced to recieve the info via GET) stream? The GET stream in my case will include "&trnEmailAddress=person%40example%2Ecom. So can I do this? decode-cgi system/options/cgi/query-string send trnEmailAddress "Thank you. Rest of message." Thanks for your help. |
Sunanda 15-May-2012 [306] | You can easily create an object! (ie a set of words) from the CGI input. This articles explaiins how: http://www.rebol.org/art-display-article.r?article=x60w ....Section 3 is the quick guide ....The next few pages describe all the things that can go wrong (probably more than you need to know right now) ....Section 7 points you to a script that handles all the edge cases for you. |
JohnM 16-May-2012 [307] | Sunanda: Thanks again for issuing the World invitation. Everyone thanks for the continuing help. I have read the cited document, but it just leaves me with more questions. Is the following literal? cgi-string: read-cgi cgi-block: decode-cgi cgi-string cgi-obj: make object! cgi-block That is to say should I type exactly that? Or is cgi-string for example a theoretical variable assignment that I could call anything? Are they all proper commands, or is any part of that just for example purposes? I am thinking I should copy and paste it verbatium. I am also thinking I mispelt verbatum. I am stuck with GET. Does this mean I can leave out some code that makes up for not knowing if the original data is POST vs GET? These are hypothetical questions for better long term learning. I for now will go with the idea that everything is as straight fowarrd as it seems. I know that my GET stream will have "trnEmailAddress" in it which is a field that will contains an email address. So will the following generate a random number, extract the address and email the same random number to that email address? token: random/seed now/percise cgi-string: read-cgi cgi-block: decode-cgi cgi-string cgi-obj: make object! cgi-block send trnEmailAddress rejoin [ "Thank you. Your number is" token "." ] Graham: Thank you for the extra info on GUID, but Windows is not involved here. I realize that random number generating really isn't unless you have a monkey throwing darts at a numbered board. Regardless extra effort to make a number unique is useful and your advice appreciated. I do not think the corner cases will come up and the people who control the original form assured me that web page issues warnings if the form is not filled out correct which should help. I do realize that people are idiots, systems are not fool proof, etc. What I am saying is my basic needs are basic and I should be OK so I am not fretting over those examples. It is great though to know the solutions are out there when I need them. Tahnks. |
Sunanda 16-May-2012 [308x2] | Yes, the names of the words are arbitrary. -- you can chose your own names. Whether the data came in via GET or POST makes no difference if you issue the READ-CGI just once. If the CGI string was yadda.com?email=[me-:-test-:-com]&token=0 then the cgi-obj will look like this: make object! [ email: "[me-:-test-:-com]" token: "0" ] Note the values are strings, so you need to convert the email value to an email! datatype: send to-email cgi-obj/email rejoin [ "Thank you. Your number is" cgi-obj/token "." ] |
If the CGI string was yadda.com which is what a lot of indexing bots will use, then the cgi-obj will look like this: make object! [ ] Hence you do need to do some data sanitisation, no matter how much the form people assure you the data will be right. | |
GrahamC 16-May-2012 [310x2] | John you have to seed the generator first and then generate your number And you can dispense with the cgi-string by cg-block: make object! decode-cgi read-cgi |
cgi-block is your variable, and the rest are functions | |
Endo 17-May-2012 [312] | Here is an example: cgi-obj: construct decode-cgi read-cgi ;check the input all [ in cgi-obj 'email trnEmailAddress: to-email trim form cgi-obj/email not empty? trnEmailAddress ] [ ;evrything seems ok send trnEmailAddress reform ["Thank you. Your number is" token "."] quit ] print "Error!" |
GrahamC 17-May-2012 [313] | Missing an 'if :) |
Endo 17-May-2012 [314] | oh, yes.. Thanks for correcting. IF ALL [ ... |
JohnM 19-May-2012 [315] | Thanks guys. Endo: Special thanks for going so far as type out an example that includes checking out that everything is OK. I realize that one cannot trust outside sources of info and that one has to always be prepared to outsmart dumb users, but the needs of this project are straightdforward and I am in unfamilar territory so if it can make things easier I can go on a bit of faith for now. That being said, better code that covers mistakes is better code and I am appreciative of it. Sunanda: That is what I thought, but I had to be sure. Thanks for helping with the details. Graham: Is that general advice or a comment on code examples I posted? I thought I had done what you just said. |
Arnold 19-May-2012 [316x6] | Hi, I have a small problem playing an mp3 file I have so far player: "/Applications/Vox.app/Contents/MacOS/Vox" thissong: "/Users/Arnold/Music/A song.mp3" thatsong: "/Users/Arnold/Music/A-song.mp3" And then call reform [player thissong] call reform [player thatsong] Playing thissong will start the musicplayer, but no music was found and playing thatsong starts the player and is being played without problem. Because most of my mp3's and directories they are in have spaces in their names so starting to play them from REBOL gets hard this way. I tried to-file thissong but this produces "%/......&20song.mp3" so it was not successful. (Allthough thatsong just played without a problem) :( Any ideas please? |
Another thing, I want to make an 'application' using REBOL that plays an mp3, an mp3 with a story for kids and I want to display the pictures from the book depending on maybe a timer(file) so the pictures are displayed acoording to the storyline. This also could be a helping aid for making presentations. I do not want to binary save my mp3 in the source of the application or in any other rebol-script so I just want to use the mp3 file and not convert it. Furthermore I do not want an external app to be started unless it can be done under the hood and/or it can be controlled by my app because the presentation could be paused by the user. Any ideas where and how to start such script. | |
Yet another task I think REBOL could help me with. Say I could not find the subtitles for an ancient tv-series i stumbled upon on the net. But I found subtitles in English. I can translate but some words will reoccur often, so I imagine a rebol script showing an original line or words to be translated. I type some translations and when I translate a word, all equal words in the rest of the document will change, saving me quite some time. | |
Okay now the words are almost all translated. Unfortunately the words are in the wrong order. Now the app shows me the lines again and this time the words are little blocks that I can click and drag to the desired position. | |
Been there, done that, got the T-shirt?? | |
Found the answer to my first task: Had to read the documentation a little further and needed a function localize-file: func [file] [ rejoin [{"} to-local-file clean-path file {"}] ] Now call reform [player localize-file to-file thissong] does play the song! | |
Sunanda 19-May-2012 [322] | A slightly shorter version that does the same, I think: localize-file: func [file [file!] ][ mold to-local-file clean-path file ] I added [file!] to the parameter.....You get the parameter type-checked, hence a better error message if you pass it something that is not a file name. |
GrahamC 19-May-2012 [323] | @JohnM .. my last comment was on the code Endo posted which was missing an 'if |
Bas 19-May-2012 [324x2] | Arnold, |
are you aware of the Universal Subtitles project? http://www.universalsubtitles.org | |
JohnM 20-May-2012 [326] | Graham: Sorry I was not clear. I was refering to you stating that I have to seed the generator first then generate my number. |
GrahamC 20-May-2012 [327x2] | @JohnM You have to do it like this random/seed now/precise token: random/secure 1000000 and not like this token: random/seed now/precise |
random/seed does not return a value | |
JohnM 20-May-2012 [329] | Graham: Thanks. That makes sense out of something someone else told me. I thought the information was contradicting what you guys said earlier, it just means I misunderstood the order of things. The modiffer after the slash is closer to making a new command than it is an agrument than I had envisioned. The fact that random is part of both made me think they could be done together. Thank you for catching that I did not know that detail. Next part of myscrip enters something into a database. The server will have an mySQL database installed. It is possible that alternative could be used, but knowing for sure I have at no extra charge this options means I am starting with this option. So I found a MySQL Driver for REBOL from here: http://softinnov.org/rebol/mysql.shtml I am following the instructions that came with the download. Is there anything I should know. Maybe it is not the driver people use because there are better ones. Maybe the author kills kittens on the weekend and it is consider bad form to use it. Maybe it is harder than it looks. Basically, please just tell me if there is general info about it I should know that is not obvious. Thanks. Hey, someone else is asking questions? i thought this was all about me! :-) :-) |
GrahamC 20-May-2012 [330x2] | It's pretty much the only driver used for mysql |
odbc drivers for windows can only be used with the rebol/view, the gui build, unless you paid for a rebol/command sdk | |
Arnold 20-May-2012 [332x2] | Hi Bas, no didn't know that one, maybe there should be an universalopensubtitleday to generate more attention to it :) |
The subtitles seem to be kept on their servers. Which is not a problem for a video on the web, but for my purpose it is not what I want. | |
Gregg 20-May-2012 [334] | On filename quoting, I have an ENQUOTE func (and a more generic ENCLOSE, ENCLOSED?, etc.) to make the intent clear. MOLD is shorter, but if you pass things around, not knowing if they've already been molded, you can get tripped up. At least I have. |
Arnold 20-May-2012 [335] | MOLD is definitely more vague, could become anyshape the form of the mold is. An ENQUOTE saves the time finding out what it does. |
Ladislav 20-May-2012 [336x2] | You have to do it like this random/seed now/precise token: random/secure 1000000 - mathematically, the above code does not differ from token: now/precise |
(it is neither more "random" nor more "secure") | |
Kaj 20-May-2012 [338] | Except that you get a date instead of an integer? |
GrahamC 21-May-2012 [339] | Enlghten us Ladislav |
Ladislav 21-May-2012 [340] | The principle is that the token calculated that way: 1) depends only on now/precise, in fact 2) since there are the is the RANDOM/SEED and RANDOM calls, it is still possible that in some cases distinct NOW/PRECISE results lead to the same TOKEN value |
Arnold 23-May-2012 [341] | Today I tried combining some tables in Excel, but without (frustrating!) no success. So tomorrow I will try and build a quicky REBOL script to put the data in one Rebdb databasetable and then do a dump of that and import that again in Excel. So I combine data NAME PROP1 with NAME PROP2 giving a table NAME PROP1 PROP2 Any tips suggestions for lookalike scripts? Tia! |
older newer | first last |