October 6th, 2008 by
Bogdan Nitulescu in
linux
Did you ever saved file names in a bash parameter, and everything crashed down when they contain spaces?
The script started simple:
1
2
3
| FILENAMES="log-file-1.txt log-file-2.txt"
cp $FILENAMES logs
rm $FILENAMES |
When you have spaces, it becomes a nightmare. You’ll probably add a lot of quotes and try first something like this:
1
2
3
| FILENAMES='"log file 1.txt" "log file 2.txt"'
cp $FILENAME logs
rm $FILENAME |
Don’t try it at home, it does not work. Bash applies its dreadfully complex parameter expansion rules and you will end up useless errors about things called “log”, “file” and “1.txt” which cannot be found.
Solution: use arrays:
1
2
3
4
5
6
| FILENAMES=(
"log file 1.txt"
"log file 2.txt"
)
cp "${FILENAMES[@]}" logs
rm "${FILENAMES[@]}" |
They work only on bash. Here’s a page about how they work.
October 6th, 2008 by
Bogdan Nitulescu in
linux
I just wrote a C application where I had to create a directory and let everyone read and write it. That should be plain easy:
1
| int result_code = mkdir("/usr/local/logs", S_IRWXU | S_IRWXG | S_IRWXO) |
Apparently it’s a bit more complex, and I made a beginner’s error. I did forgot about the UMASK (http://www.tech-faq.com/umask.shtml).
Briefly: When you create a new file or directory, some of its permissions are restricted and cannot be set. Each process has a set of restrictions called the umask, and you must use the umask system call to disable or enable those restrictions. In my case, I set the umask to 0, that is no restrictions, created the directory, then restored the umask to its previous value:
1
2
3
| mode_t process_mask = umask(0);
int result_code = mkdir("/usr/local/logs", S_IRWXU | S_IRWXG | S_IRWXO)
umask(process_mask); |
The code above is not reentrant and it gets a bit more complex if your program is multithreaded, but you get the idea.
October 3rd, 2008 by
Marius Hanganu in
General, HTML, Javascript
This is a small one, but I banged my head several times now before fixing it. Although many have written about it, I decided to write also. More resources are always better than fewer resources :-)
So you’ve created the flash object, correctly set the URL, but when embedding it on the web page on your web server, the link doesn’t work. The solution is quite simple: you need to set allowScriptAccess to sameDomain or even always if sameDomain doesn’t do the job.
And of course, you need to do that for both the object and the embedtag. For example:
1
2
3
4
5
6
7
| <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="295" height="240">
<param name="allowScriptAccess" value="always" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="http://server/flash.swf">
<param name="quality" value="high">
<embed src="http://server/flash.swf" quality="high" allowScriptAccess="always" allowFullScreen="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="295" height="240"></embed>
</object> |
Using this parameter, the flash object will now allow linking to the HTML page set in the flash object.
Blogged with Flock
Tags: flash, link, html, URL