William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

Tips Summary

1. PHP

header(“Cache-Control: No-Cache”);
header(“Program: No-Cache”);

<?php header(“Location: http://&#8221; . $_SERVER[‘HTTP_HOST’] . dirname($_SERVER[‘PHP_SELF’]) . “/” . $relative_url); ?>
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file,
or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function,
and have spaces or empty lines that are output before header() is called. The same problem exists when using a
single PHP/HTML file.

string mysql_escape_string ( string unescaped_string )
This function will escape the unescaped_string, so that it is safe to place it in a mysql_query(). This function is deprecated.
mysql_escape_string() is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection
handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection
argument and does not respect the current charset setting.

PHP “automagically” can apply slashes to your $_POST data for security purposes. –> stripslashes(), addslashes()
use encodeurl(php) + unescape(js) to transfer “\n\r” from php to javascript.
echo ereg_replace(” {2}”,”  “,nl2br(htmlspecialchars(stripslashes($in_txt))));

$_SESSION[‘userid’] = $userid;
$file = “./.” . $_SERVER[‘REMOTE_ADDR’];
$fh = fopen($file, “a+”);
$str=”\n”.$userid.’, ‘.$_SERVER[‘REMOTE_ADDR’].’, ‘.date(“D Y-m-d g:i:s A”,$_SERVER[‘REQUEST_TIME’]);
fwrite($fh, $str);
fflush($fh);
fclose($fh);
header(“Location: index.php”);

2. Perl

perl -MData::Dumper -e “print Dumper(\%INC);”
perl -V

[^\s]*q(?!werty)
The above code starts by matching non-whitespace characters ([^\s]*), then a q (err … q). Then the parser reaches the lookahead assertion. This makes the q conditional. The q will only be matched if the assertion is true. In this case, the assertion is a negative assertion. It will be true if what it checks for is not found.

So, it checks the next few characters against the pattern it has (werty). If they are found, the assertion is false, and so it will “ignore” the q – it will not match. If it doesn’t find “werty”, the assertion is true, and the q is matched. It then carries on checking for non-whitespace characters.

(aaa|bbb)[0-9]+\1
The above matches “aaa or bbb”, and groups the match with the brackets. This is followed by a pattern for one or more numbers (“[0-9]+”), then finally “\1″. The “\1″ backreferences the first group, and looks for the same thing. It will match the matched text from the string, not the pattern, so “aaa123bbb” will not match the above pattern, as the “\1″ will be looking for “aaa” to follow the numbers.

$x = “foobar”;
$x =~ /foo(?!bar)/; # doesn’t match, ‘bar’ follows ‘foo’
$x =~ /foo(?!baz)/; # matches, ‘baz’ doesn’t follow ‘foo’
$x =~ /(?<!\s)foo/; # matches, there is no \s before 'foo'

foreach my $ttt(@ary) {
$ttt =~ m/([^\s]+(?=\.(jpg|gif|png))\.\2)/i;
if ($1) {
print $1 . "\n";
}
}

3. JS

onFocus=”this.select()” onblur=”this.value=this.value.toUpperCase();”

var type=typeof object;
switch (type)
case ‘undefined':
case ‘unknown':
case ‘null': return;
case ‘boolean': return object.toString();

if(typeof myObj.myproperty != “undefined”) {}

if (myObj && typeof myObj.myProperty != “undefined”) {
// myObj exists, and so does myProperty
}

4. Bash
linux command line reference for common operations: http://www.pixelbeat.org/cmdline.html

for i in *; do
mv “$i” `echo $i | sed -e ‘s/\s//g’`;
done

ls -l |grep -^- | sort -nr
cat /temp/aaa |sed /^$/d
du -k | sort -nr
du -sk * | sort -nr | head
cat /tmp/fat_file | cut -d: -f4 | sort | uniq
ps -ef | awk ‘{print $1}’ | sort | uniq | wc -l

find pdf/ -type f -name “*.pdf” -exec ls -1 {} \; | sed -e “s/^/\”/” -e “s/$/\”/”
find / -type f -atime -30 > December.files

# .exec file
set tabstop=2
set shiftwidth=2
Notice:
1.in vi, :set cin, :se ff=unix
2. vi -C file to see

echo -en “33[1;32m”
grep “setUserLogon=” * | cut -f2 -d”=” |sort | uniq | more
tidy -o -i 2 -utf8

ls -l /home/weblogic/logs/accs-whs/uploadScan.`date +%Y-%m-%d`.log | awk ‘{ print $5 }’
ls -l /home/weblogic/logs/accs-whs/console.log | awk ‘{ print $5 }’
ls -lrt |awk ‘/Jun 22/ { print $0 }’ |wc -l
for i in `ls -l | awk ‘($5==62 && $7~2) { print $9 }’ |cut -f2 -d_ `; do ls -l *$i; done

vi `grep -R “_SESSION” * | grep user | awk ‘{ print $1 }’ | cut -f1 -d: | uniq`

4. Oracle
getData() {
sqlplus -S ${ORAUSR} <<__EOF__
SET FEEDBACK OFF LINESIZE 32767
SET SERVEROUTPUT ON SIZE UNLIMITED FORMAT WRAPPED
BEGIN
ACCS.CMR.genStatCMR(‘$AWB’, ‘$SCANTYPE’, ‘$STATUSCD’, ‘$EMPLOYEEID’, TO_DATE(‘$SCANDT’,’YYYY/MM/DD HH24:mi:ss’), ‘$SCOMMENTS’);
END;
/
__EOF__
}

Others
FF:
Ctrl + Shift + F: Display element information. This puts a red box under your mouse.
Move the mouse over an element and its attributes appear in a pop-up: the name,
class, pixel sizes, fonts, everything.

Ctrl + Shift + E: Edit CSS.
Script Tab (Debugging): Best. Feature. Ever. Click on a line number to set a breakpoint
(red dot) in your javascript. Reload the page and it will break (pause)
when it encounters the line.

At this point, you can switch over to the console to examine and change variables,
and figure out what the heck is going on when your code won’t work.
You can then hit the blue “play” button and continue running your app,
until the next breakpoint.

One response to “Tips Summary

  1. powercashadvance.com 10/28/2011 at 10:53 am

    It can be rare to get an experienced person in whom you might have some faith. In the world at present, nobody definitely cares about showing others the best way in this subjecttopic. How lucky I am to have now found a real wonderful web-site as this. It truly is people like you who really make a true difference currently through the ideas they discuss.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 75 other followers

%d bloggers like this: