Notes by Dr. Xi
Displaying keyword search results 1 - 10
Created by Dr. Xi on February 07, 2012 15:40:11
Last update: February 07, 2012 15:40:11
An alias defined in .profile does not work when you open a bash window from the desktop. Simply put, alias should be put in .bashrc ; PATH should be put in .profile . These are the facts: .profile is executed by the login shell, i.e., when you login. .bashrc is executed whenever a bash shell is opened - login or non-login. When you open a new bash window from the desktop, a non-login shell is created, it will execute .bashrc , not .profile . When you ssh to a remote system interactively, a login shell is created. When you ssh to a remote system and run a command directly, a non-login shell is created. PATH modifications should be put in .profile since it is usually...
Created by Dr. Xi on March 28, 2011 15:54:20
Last update: March 28, 2011 15:54:20
From the nc man page:
The nc (or netcat) utility is used for just about anything under the sun involving TCP or UDP. It can open TCP connections, send UDP packets, listen on arbitrary TCP and UDP ports, do port scanning, and deal with both IPv4 and IPv6.
To bind to port 8080:
nc -l 8080
To connect to the port above
nc localhost 8080
Type something in either window it will be echoed in the other.
To get the home page of google:
echo -e -n "GET / HTTP/1.1\r\nHost:www.google.com\...
To send email via SMTP:
nc -C localhost 25 << EOF
HELO host.example.com...
Port scan of localhost:
$ nc -z localhost 20-8080
Connection to localho...
Created by Dr. Xi on March 02, 2011 11:39:18
Last update: March 09, 2011 12:19:30
Some peculiarities about Java PrintWriter: PrintWriter never throws any exceptions. From JavaDoc : Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError(). When error occurs, you'll never know anything more than that it occured, because checkError returns boolean. When a character is out of the range of the character encoding of the PrintWriter, it prints a question mark (?). But this is not an error. Test code:
import java.io.*; public class TestPrintWri... Latin1 test result: java TestPrintWriter iso-8859-1 | od -bc 000000... UTF-8 test result: java TestPrintWriter utf-8 | od -bc 0000000 141... Also, the constructor throws a FileNotFoundException when you try to write to a...
Created by Dr. Xi on February 17, 2011 12:59:47
Last update: February 17, 2011 12:59:47
Operator Meaning -e file1 file1 exists -b file1 file1 is a block special file -c file1 file1 is a character special file -d file1 file1 is a directory -f file1 file1 is a regular -g file1 Set Group ID (sgid) bit is set for file1 -h file1 file1 is a symbolic link -k file1 Sticky bit is set for file1 -L file1 file1 is a symbolic link -p file1 file1 is a named pipe (FIFO) -r file1 file1 is readable by the current process -s file1 file1 has a size greater than zero. -t FileDescriptor FileDescriptor is open and associated with a terminal. -u file1 Set User ID (suid) bit is set for file1 -w file1 Write flag (w) is on for file1 -x file1...
Created by Dr. Xi on October 02, 2008 21:35:59
Last update: January 11, 2011 19:51:26
This page demos a pop up window centered on the screen. In the demo tab, the pop up be centered relative to the tab panel.
<html>
<head>
<script language="JavaScript" ...
Created by Dr. Xi on August 21, 2007 21:25:58
Last update: January 10, 2011 22:19:09
You can grab some animated icons here: http://mentalized.net/activity-indicators/ . And here's some code to demonstrate how to use such an icon.
<html>
<head>
<script language="JavaScript"...
However, if you use Ajax and send a synchronous request, the icon won't show up at all, i.e., the following code doesn't work:
function eventHandler() {
startBusy();
...
This works:
function eventHandler() {
startBusy();
...
Created by Dr. Xi on August 30, 2010 20:17:22
Last update: August 30, 2010 20:17:41
Characters \/:*?"<>| are forbidden in Windows file names. For Python, the effect of using a forbidden character in the file name is undetermined.
In the following session a file named mytest can be seen from the Windows Explorer, which contains 0 bytes - as confirmed by the read back in the session. But if you open the file with the invalid file name used to create the file (i.e., mytest: 1.txt ), you get the original contents.
C:\>python
Python 2.7 (r27:82525, Jul 4 2010, ...
Created by Dr. Xi on August 30, 2010 18:17:15
Last update: August 30, 2010 18:19:49
Use the codecs module to read file in Unicode. This is from the Python doc :
import codecs
f = codecs.open('unicode.rst', en...
I had some luck reading files mainly in ASCII but contained some binary data with:
import codecs
f = codecs.open('unicode.rst', en...
Created by Dr. Xi on August 30, 2010 16:33:46
Last update: August 30, 2010 16:33:46
For Python 2.6 and later, this:
with open(filename) as logfile:
for line in...
is equivalent to this:
logfile = open(filename)
try:
for line i...
Created by Dr. Xi on May 23, 2010 01:16:57
Last update: May 23, 2010 01:16:57
open(IMG, "Sample.jpg") or die "Can't open file: $...