Category Archives: developer’s Guide

developer’s tools & references

pdf embed on html without using flash





I was looking for ways to embed pdf file on html without using flash. There are many ways of doing it, other suggested of using www.scribd.com but the prob is it would be hosted in their server. Then I found this solution using the google viewer which you only need to supply the url and also another good thing is it doesn’t require flash :)

<iframe src="http://docs.google.com/gview?url=http://example.com/mypdf.pdf&embedded=true" style="width:718px; height:700px;" frameborder="0"></iframe> 

 

date() error in php 5.3

After reinstalling my local machine and updating the php version to 5.3 I’m getting this error:

Warning: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.

Based from what I’ve researched regarding this you need to set a timezone for date. So go to php.ini locate date.timezone and put some value on it. e.g.,
date.timezone = ‘UTC’





htdocs folders in vista not showing

After reinstalling apache, php in vista I got trouble displaying my htdocs folders on browser. Some were there and some were not. I double checked my apache settings if I missed something but so far I did not. I compared what’s the difference of those folders and found out that the one with .htaccess file in it were not showing. Realizing that, it means something to do with my htaccess file. Checked my httpd.conf settings and I forgot to uncomment this line #LoadModule rewrite_module modules/mod_rewrite.so, so all you need to do is uncomment it and you’re good to go.

mysql string replace

You can check the mysql function string_replace here http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

Ex:
mysql> SELECT REPLACE(‘www.mysql.com‘, ‘w’, ‘Wo’);
output:  ‘WoWoWo.mysql.com’

Or you can also do it on UPDATE statements like this

UPDATE table SET table_field=REPLACE(table_field, search_string, replace_value_here)

 

TAR command

create:
tar -cvf mystuff.tar mystuff/
tar -czvf mystuff.tgz mystuff/
extracting:
tar -xvf mystuff.tar
tar -xzvf mystuff.tgz
testing/viewing:
tar -tvf mystuff.tar
tar -tzvf mystuff.tgz

Note that .tgz is the same thing as .tar.gz
Tar “tars up” a bunch of files into one “tar-file”
gzip is compression, but only works on one file, so the entire “tarfile” is compressed.

Also when creating a tar or cpio backup, never, never, never use an “absolute” path — you have been warned; also linux tar warns you of this too. The problem is that when you want to unpack, you cannot choose where to unpack to, you will be forced to unpack to the “same” absolute path. When creating a tar or cpio you should change the the appropriate directory and tar from there.

Also when creating a tar or cpio it is general good practice to tar up a directory (appropriately named) which contains your files, rather than just the files. This is good courtesy to anyone unpacking your tarfile.

If you would like to create a tar file while saving ownership and permissions, add the “p” flag.

Creating and saving ownership and permissions:
tar -cpvf mystuff.tar mystuff/
tar -cpzvf mystuff.tgz mystuff/

Also take note of the following commands:
gzip
gunzip
cat
zcat
bzcat
bzip2
bunzip2
zgrep
bzgrep

(cd /mydir && tar -czf – .)|(cd /destdir && tar -xzvf -)
tar -czf – . | ssh user@dest “(cd /destdir && tar -xzvf -)”
(cd /mydir && tar -czf – .) | ssh user@dest “(cd /destdir && tar -xzvf -)”

Errors:
If you receive an error such as the following:

[root@localhost test]# ssh user@dest "(cd /rh62/home/kernel && tar -czvf - linux-2.2.22.tar.bz2)"|tar -xzvf -
user@dest's password:
linux-2.2.22.tar.bz2
linux-2.2.22.tar.bz2

gzip: stdin: decompression OK, trailing garbage ignored
tar: Child returned status 2
tar: Error exit delayed from previous errors
[root@localhost test]#

Then try leaving off the compression as follows:

[root@localhost test]# ssh user@dest "(cd /rh62/home/kernel && tar -cvf - linux-2.2.22.tar.bz2)"|tar -xvf -
user@dest's password:
linux-2.2.22.tar.bz2
linux-2.2.22.tar.bz2
[root@localhost test]# echo $?
0
[root@localhost test]#

Spaces in your filenames?
Having fun with spaces in the filename or directory name? Here’s your answer:

find . -type f -name '*jpg' | grep " " | while read REPLY; do
     tar -cf - "$REPLY" | (cd /tmp/jpg && tar -xvf -)
done

Bonus:

find . -type f | while read REPLY; do
     cp -a "$REPLY" /tmp/jpg/`echo $REPLY \
       | sed -e 's/ //g' -e 's/\///g' -e 's/^\._//'`
done

ssh root@dest 'tar -C / -czf - --exclude ./proc/* --exclude ./dev/pts/* .' > gmaster.tgz
proc and dev was empty for the following command, so I didn't exclude them:
tar -czf - . | ssh user@dest "cat - > k12ltsp.master.tgz"

source: http://roffle.us/blog/archives/13-Linux-TAR-Command.html