Red to-date doesn't work with AAAA.MM.JJ - rebol

This code snippet works on Rebol:
to-date "2017.08.29"
but it doesn't work on Red
Looking at the source seems the same. So why it doesn't behave the same way ? What to do ?

>> load replace/all "2017.08.29" "." "-"
== 29-Aug-2017

Related

Accessiblity of $ in when condtion in dataweave?

I have one requirement where entire response structure will be varied based on the current element. but in dataweave $ is not accessible with when, but with function it is accessible. Could you please suggest am i missing some thing here?
[1,2,5] map $ when $ > 1 otherwise 2 throws error. but same used like the below way works.
%function r(a) a when a > 1 otherwise 2
---
[1,2,5] map r($)
Could you please help me to understand the behaviour.
Thanks
Sushma.
I found the answer after posting the question!!
it works with braces.
[1,2,5] map ($ when $ >1 otherwise 2)
Thanks
Sushma

React-native dynamic images with lots of images

I have an array of 150 buttons that link to 150 pictures, i need to show the picture once the button is pressed. The information for the buttons is stored in a JSON file. The pictures names are the ID's of the buttons, so 1.jpg, 2.jpg etc.
Now I am facing the problem that I can't write:
fish["image"] = {uri: "asset-library://" + fish.id + ".jpg"};
And the other solution with if statements does not work since I have so many options, any ideas?
Thanks so much
I had a similar problem. I built a function that contains a huge switch statement and has static requires for every case.
function getImage(id) {
switch(id) {
case 1:
return require('./img/1.jpg');
case 2:
return require('./img/2.jpg');
...
}
}
Now you can do
fish["image"] = getImage(fish.id);
I also had to use over 100 icons, so instead of writing the cases by hand, I built a script that generates the function automatically.
I had too this problem for a component I developed. I used base64 image in json file. But maybe it's not a good fit for you, I hope it can help.
<Image
style={styles.imgStyle}
source={{uri: CountryFlags[country.cca2]}}
/>
You can see it here : https://github.com/xcarpentier/react-native-country-picker-modal/blob/master/src/index.js#L137-L139
And if you have a folder with files on it, simply convert images like that :
#!/bin/sh
list=`ls ./flags | grep '[A-Z]'`
echo "{"
for item in $list
do
header="data:image/png;base64,"
img64=`ls ./flags/$item | xargs cat | base64`
echo ${item:0:2} :\'$header$img64\',
done
echo "}"

while [[ condition ]] stalls on loop exit

I have a problem with ksh in that a while loop is failing to obey the "while" condition. I should add now that this is ksh88 on my client's Solaris box. (That's a separate problem that can't be addressed in this forum. ;) I have seen Lance's question and some similar but none that I have found seem to address this. (Disclaimer: NO I haven't looked at every ksh question in this forum)
Here's a very cut down piece of code that replicates the problem:
1 #!/usr/bin/ksh
2 #
3 go=1
4 set -x
5 tail -0f loop-test.txt | while [[ $go -eq 1 ]]
6 do
7 read lbuff
8 set $lbuff
9 nwords=$#
10 printf "Line has %d words <%s>\n" $nwords "${lbuff}"
11 if [[ "${lbuff}" = "0" ]]
12 then
13 printf "Line consists of %s; time to absquatulate\n" $lbuff
14 go=0 # Violate the WHILE condition to get out of loop
15 fi
16 done
17 printf "\nLooks like I've fallen out of the loop\n"
18 exit 0
The way I test this is:
Run loop-test.sh in background mode
In a different window I run commands like "echo some nonsense >>loop_test.txt" (w/o the quotes, of course)
When I wish to exit, I type "echo 0 >>loop-test.txt"
What happens? It indeed sets go=0 and displays the line:
Line consists of 0; time to absquatulate
but does not exit the loop. To break out I append one more line to the txt file. The loop does NOT process that line and just falls out of the loop, issuing that "fallen out" message before exiting.
What's going on with this? I don't want to use "break" because in the actual script, the loop is monitoring the log of a database engine and the flag is set when it sees messages that the engine is shutting down. The actual script must still process those final lines before exiting.
Open to ideas, anyone?
Thanks much!
-- J.
OK, that flopped pretty quick. After reading a few other posts, I found an answer given by dogbane that sidesteps my entire pipe-to-while scheme. His is the second answer to a question (from 2013) where I see neeraj is using the same scheme I'm using.
What was wrong? The pipe-to-while has always worked for input that will end, like a file or a command with a distinct end to its output. However, from a tail command, there is no distinct EOF. Hence, the while-in-a-subshell doesn't know when to terminate.
Dogbane's solution: Don't use a pipe. Applying his logic to my situation, the basic loop is:
while read line
do
# put loop body here
done < <(tail -0f ${logfile})
No subshell, no problem.
Caveat about that syntax: There must be a space between the two < operators; otherwise it looks like a HEREIS document with bad syntax.
Er, one more catch: The syntax did not work in ksh, not even in the mksh (under cygwin) which emulates ksh93. But it did work in bash. So my boss is gonna have a good laugh at me, 'cause he knows I dislike bash.
So thanks MUCH, dogbane.
-- J
After articulating the problem and sleeping on it, the reason for the described behavior came to me: After setting go=0, the control flow of the loop still depends on another line of data coming in from STDIN via that pipe.
And now that I have realized the cause of the weirdness, I can speculate on an alternative way of reading from the stream. For the moment I am thinking of the following solution:
Open the input file as STDIN (Need to research the exec syntax for that)
When the condition occurs, close STDIN (Again, need to research the syntax for that)
It should then be safe to use the more intuitive:while read lbuffat the top of the loop.
I'll test this out today and post the result. I'd hope someone else benefit from the method (if it works).

BASH SCRIPT - save in memory then read

Someone can tell if it is possible, save a variable(a number (this number is a total of rows in a SQL tabel)) in like a memory or a file? and then, like 5 min later, check if the number is the same? and send me like a warning or alert for nagios?
Sounds like you are looking to do something like this:
#!/bin/sh
OLD_NUM=`command_to_get_number`
while true
do
sleep 5m
NEW_NUM=`command_to_get_number`
[ "$OLD_NUM" != "$NEW_NUM" ] && notify-send "Number changed"
OLD_NUM="$NEW_NUM"
done
notify-send will give you a desktop notification, not sure if there is a similar command to work with nagios.

Vim script: How to easily pipe data into the cwindow

I use a custom function (currently residing in .vimrc) and not :make or another direct command line tool to compile/check my currently edited file for errors. Like this:
function! CompileMyCode(...)
set errorformat=Error:\ %m\\,\ in\ line\ %l
let l:output = "Error: bad code!, in line 9"
return l:output
endfunction
command! -nargs=* CompileMyCode :call CompileMyCode(<f-args>)
when using the new command in command mode, no error window shows up.
:CompileMyCode | cwindow
What am I doing wrong?
Edit:
I now tried the following which also does not open any cwindow.
function! CompileMyCode(...)
set errorformat=Error:\ %m\\,\ in\ line\ %l
let l:output = "Error: bad code!, in line 9"
" I tried both of the following lines separately
cexpr l:output
call setqflist([l:output])
endfunction
The proposed commands cexpr and setqflist() do not open the cwindow correctly in my example. Maybe somebody can propose a complete solution?
Edit 2:
The main problem is solved. Here is my current code:
let l:result = expand("%").'|8| errortext'
cexpr [ l:result, l:result ]
caddexpr ''
cwindow
This example respects a default error format that vim seems to support. When cexpring the actual error output and using an errorformat the cwindow seems to ignore that.
Nevertheless, I wanted stick to a default error format anyway in the output, not having to rely on a custom errorformat
Thx for your answers!
I did something similar using cexpr l:output instead of returning the string and that placed the output of the compile in the quickfix window. You can see my vim function here: http://www.zenskg.net/wordpress/?p=199
Update
Adding a blank line to the quickfix list seems to allow the cwindow to appear. For example:
function! MyCompile()
let l:output = "Error: line 1"
cexpr l:output
caddexpr ""
cwindow
endfunction
If you already have access to the error information as structured data in Vim (or can easily obtain it), you can use setqflist().