Friday, January 21, 2011

Tab to space for indentation: Configure Eclipse and Pydev editors

Configure Eclipse and Pydev editors
  • Go to "Window > Preferences > General > Editors > Text Editors"
  • Set "Displayed tab width" to 4 and make sure "Insert spaces for tabs" is checked
  • Go to "Window > Preferences > Pydev > Editor"
  • Set "Tab length" to 4 and make sure "Replace tabs with spaces..." is checked

Oracle Net: TNS and EasyConnect


  1. sqlplus id/pwd@
  2. sqlplus id/pwd@server:port/service (service is schema that is given by DBA)

Thursday, December 23, 2010

cx_Oracle

Follow http://mostperfect.net/blog/2010/07/28/installing-cx_oracle-on-windows/,
A looking at cx_Oracle.pyd with dependency walker (from MS) will show it depends on OCI.dll.
As a result, we need to install Oracle Instant Client from here

strace


stats: strace -c -p
look for system call: strace -f -p -e epoll_wait

Thursday, November 25, 2010

Customize the Nginx Server:Apache

  1. vi src/http/ngx_http_header_filter_module.c
  2. static char ngx_http_server_string[] = "Server: Apache" CRLF;
  3. static char ngx_http_server_full_string[] = "Server: Apache" CRLF;
  4. configure, make, make install.

Monday, November 8, 2010

how to change user-agent for chrome

C:\Users\vyang\AppData\Local\Google\Chrome\Application\chrome.exe -user-agent="Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"

Wednesday, October 13, 2010

a smtp proxy server

http://code.activestate.com/recipes/577260-multi-threaded-smtp-proxy/

is useful for helping me to test my html email via outlook. This is due to the real MTA that can deliver to outlook is IP based, and my workstation is not allowed but as long as I run the server on the allowed IP, it works.

Tuesday, August 31, 2010

ldapsearch usage

For example,
In order to find the home directory for a certain user id.

ldapsearch -H "ldap://ldapserver/" -D -W -vvv -L -x -b 'OU=Users,DC=mycomp,DC=com' -z 0 uid=$1 Home

range(a..z): python generator expression for

In order to generate a..z with generator expression.

import string
for filter in ('uid='+x+'*' for x in string.lowercase):
print(filter)

Thursday, August 26, 2010

Play with TTL value with ping

Router will decrement TTL value within IP packet.
"ping" can be used to simulate how ICMP works in more complex tool such as "mtr", "traceroute". 

Please try increasing ttl-value against any target machine is ICMP is enabled along the route.
  

on unix/linux: ping -t target-ip
on windows: ping -i target-ip

mtr

mtr -n www.microsoft.com

ping test with incremental TTL

Similar like Traceroute (and mtr),
We can conduct an incremental testing with one ICMP packet each time:
ping -t 1  -c 1 www.yahoo.com
ping -t 2  -c 1 www.yahoo.com

...

how to find default IP TTL value of the remote system

TTL value is 1 byte within IP header.
  1. "ping " will show ttl returned by the remote machine.
  2. Find out how many hops between src and remote ip. traceroute/mtr
  3. Add the value from Step 1 and 2 will get the default TTL value of remote system
  4. For the curious, can look up http://www.binbert.com/blog/2009/12/default-time-to-live-ttl-values/ to take a guess what the remote system might be.

Tuesday, August 17, 2010

winpcap 's dlls



There are two dlls with winpcap installation.
  • wpcap.dll implements the libpcap API (plus some extensions) for Win32 systems.
  • packet.dll, and the drivers for various Win32 operating systems, provide a Win32-specific raw link-layer packet

Monday, March 1, 2010

set up rsync daemon

start_rsyncd.sh

/usr/bin/rsync --daemon --config=rsyncd.conf


rsyncd.conf (server runs on port 9873)

pid file=/home/vic/opt/rsync/pid
log file=/home/vic/opt/rsync/log
lock file=/home/vic/rsync/lock
port=9873
address=192.168.1.100
timeout=600

[data]
path=/home/vic/tmp
use chroot=false
read only=no
transfer logging=yes
max connections=1


rsync client test
rsync -v foo rsync://192.168.1.100:9873/data

Thursday, January 14, 2010

How to build mod_wsgi,web.py with httpd and python from source code

It is best to compile everything from source code.

Version used
Python: 2.7 (with shared library)httpd 2.2.17 (with shared DSO support)WSGI (integrating with httpd): mod_wsgi 3.3
Web framework: web.py 0.34

Compile Python for shared lib

./configure --prefix= --enable-shared


Set up LD_LIBRARY_PATH so that running "python" would find its shared lib
export LD_LIBRARY_PATH=${python-lib}:$LD_LIBRARY_PATH


Compile (apache) httpd Add DSO support
./configure --prefix= --enable--module=module_so



Compile mod_wsgi
./configure --with-apxs=$APACHE_HOME/bin/apxs --with-python=$PYTHON_BIN/python

Configure httpd.conf for mod_wsgi



LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /wsgi/ /u/local/www/wsgi-scripts/

WSGIApplicationGroup admin-scripts
Order allow,deny
Allow from all

WSGIProcessGroup example1.com
WSGIDaemonProcess example1.com processes=2 threads=15 display-name=example1.com

Install a sample python code under /u/local/www/wsgi-scripts/sniff
import sys
def application(environ, start_response):
status = '200 OK'
output = 'sys.version= %s\nsys.prefix=%s\n' % (sys.version, sys.prefix)
output += 'sys.path= %s\n' % (sys.path)

response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]






Wednesday, December 2, 2009

To install Nginx from source

./configure --prefix=/u/pandev/opt/nginx --without-http_rewrite_module

Saturday, April 4, 2009

netstat + lsof = my friend

linux
  1. "netstat -anpt | grep -i listen | grep 8888" will find out the process id is running on that port.
  2. "/usr/sbin/lsof -p " find out what file and sockets it opens.
  3. "lsof -P -n -i TCP" will list all the TCP sockets with unresolved (numeric) IP and port

Wednesday, March 4, 2009

Database connection pooling with firewall troubleshooting tip: Use Netcat

Database connection pooling is useful and common feature for performance. However there are some cavets.
Sometimes your sql query just got timed out, and you wonder why.
If you suspect the TCP connection between your application hosted in DMZ to the database (which is usually sits behind a firewall) got dropped by the firewall. It is very likely firewall has a policy to terminate any idle connection.

Let's go back to the basics to use Netcat.

Server(internal machine):
nc -v -l 9999

Client (DMZ machine):
nc 9999

Assuming port 9999 is allowd on the firewall.

Let's assume the firewall drops the connection after 30 minutes idle time, then the nc will be broken after 30 minutes.