Archive for the ‘developer's Guide’ Category

TAR command

Thursday, March 11th, 2010 by dreamluverz

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

regex cheat sheet

Tuesday, March 9th, 2010 by dreamluverz




Special Sequences
  • \w - Any “word” character (a-z 0-9 _)
  • \W - Any non “word” character
  • \s - Whitespace (space, tab CRLF)
  • \S - Any non whitepsace character
  • \d - Digits (0-9)
  • \D - Any non digit character
  • . - (Period) – Any character except newline

Meta Characters

  • ^ - Start of subject (or line in multiline mode)
  • $ - End of subject (or line in multiline mode)
  • [ - Start character class definition
  • ] - End character class definition
  • | - Alternates, eg (a|b) matches a or b
  • ( - Start subpattern
  • ) - End subpattern
  • \ - Escape character

Quantifiers

  • n* - Zero or more of n
  • n+ - One or more of n
  • n? - Zero or one occurrences of n
  • {n} - n occurrences exactly
  • {n,} - At least n occurrences
  • {n,m} - Between n and m occurrences (inclusive)

Pattern Modifiers

  • i - Case Insensitive
  • m - Multiline mode – ^ and $ match start and end of lines
  • s - Dotall – . class includes newline
  • x - Extended– comments and whitespace
  • e - preg_replace only – enables evaluation of replacement as PHP code
  • S - Extra analysis of pattern
  • U - Pattern is ungreedy
  • u - Pattern is treated as UTF-8

Point based assertions

  • \b - Word boundary
  • \B - Not a word boundary
  • \A - Start of subject
  • \Z - End of subject or newline at end
  • \z - End of subject
  • \G - First matching position in subject

Assertions

  • (?=) - Positive look ahead assertion foo(?=bar) matches foo when followed by bar
  • (?!) - Negative look ahead assertion foo(?!bar) matches foo when not followed by bar
  • (?<=) - Positive look behind assertion (?<=foo)bar matches bar when preceded by foo
  • (?<!) - Negative look behind assertion (?<!foo)bar matches bar when not preceded by foo
  • (?>) - Once-only subpatterns (?>\d+)bar Performance enhancing when bar not present
  • (?(x)) - Conditional subpatterns
  • (?(3)foo|fu)bar - Matches foo if 3rd subpattern has matched, fu if not
  • (?#) - Comment (?# Pattern does x y or z)

source: http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

regex: match all including new line

Tuesday, March 9th, 2010 by dreamluverz

I was looking for a way to match all characters plus new line and using “.” is not solely the answer because:

The dot matches a single character, without caring what that character is. The only exception are newline characters. In all regex flavors discussed in this tutorial, the dot will not match a newline character by default. So by default, the dot is short for the negated character class [^\n] (UNIX regex flavors) or [^\r\n](Windows regex flavors).

source: http://www.regular-expressions.info/dot.html

So I found some answers on the references below by using the \s

\s
Matches any whitespace character; this is equivalent to the class [ \t\n\r\f\v].

sources:
http://www.amk.ca/python/howto/regex/

http://www.phpro.org/tutorials/Introduction-to-PHP-Regex.html

So combining it all example showed below:

<?
$str = ‘you \n are \n good’;
preg_match(‘/(.*)/s’, $str, $match);

?>

[additions] After testing several examples I found out that S is not enough for the example below, so instead I added the U pattern modifier so it would be like preg_match(‘/div(.*)<\/div>/sU’, $str, $match);

$a = “
<div>
<p>aaa</p>
</div>
<div>
<p>bbb</p>
</div>
<div>
<p>ccc</p>
</div>
“;

You can also check regular expressions list here.

localhost not working in vista after installing nod32 v3

Thursday, July 9th, 2009 by dreamluverz

This error is making me so crazy… my localhost works fine until I installed nod32 v3 in windows vista business. But it works fine with windows xp… I’ve been searching the web for solutions but seems like none of it works for me.

Some solutions I gathered, it works for some but i’d still be looking for other solutions since these things listed below didn’t work for me.

SOLUTION 1

To access your hosts file go to.
1. C:(or Windows Folder)\\Windows\System32\drivers\etc
2. Open the
HOSTS file using Notepad or any HTML Editor.
3. Look and delete
:. localhost or :. 127.0.0.1
4. Save the file as hosts
5. Open your browser type localhost — it should work.

*I’m using Windows Vista Home Basic, Xampplite and Nod32 v3.0

Disclaimer:
If something happens on your computer don’t blame me.
;)

SOLUTION 2

Go to the Setup tab and click “Enter entire advanced setup tree”

Click “Web access protection” and uncheck the checkbox labeled “Enable web access protection”

This worked using Vista Business SP1 and VS2008 SP1

source: http://www.donalyza.com/localhost-doesnt-work-in-windows-vista-using-nod32-v30/#comment-458

what is SOAP

Monday, June 15th, 2009 by dreamluverz

How is SOAP Used?
There are many possible applications for SOAP, here are just a couple:

  • Business to Business integration – SOAP allows businesses to develop their applications, and then make those applications available to other companies
  • Distributed applications – programs like databases could be stored on one server and accessed and managed by clients across the Internet

One thing to consider when looking into implementing SOAP on your business server is that there are many other ways to do the same thing that SOAP does. But the number one benefit you’ll gain from using SOAP is it’s simplicity. SOAP is just XML and HTTP combined to send and receive messages over the Internet. It is not constrained by the application language (Java, C#, Perl) or the platform (Windows, UNIX, Mac), and this makes it much more versatile than other solutions.

source: webdesign.about.com/library/weekly/aa031802a.htm

using xml for live search

Wednesday, June 3rd, 2009 by dreamluverz

For the XML interface, there is an interface specific parameter XmlType, which can control the flavor of XML interface. If ElementBased enumeration is specified, each field will be rendered as a separated tag. If AttributeBased enumeration is specified, all simple type fields will be rendered as attributes instead of elements. The default value is ElementBased.

The following sections give an example request and response for each of these options.

ElementBased Enumeration Example

Request

http://api.search.live.net/xml.aspx?AppId = [YOUR_APPID] &market=en-US&Query=testign&Sources=web+spell&web.count=1&xmltype=elementbased

Note: For information about obtaining an AppId, see Live Search Developer Center.

(more…)