Below you will find pages that utilize the taxonomy term “source code”
SSH with Java
Recently I needed to do some server manipulation over the SSH-2 protocol from a Java client program. There are quite a few choices of SSH libraries for Java out there. Usually I prefer BSD license whenever possible, so I thought I’ll give Ganymed SSH-2 for Java a try. It turned out to be pretty simple to use. Here’s a short example of how to connect to the server using the private key and execute some command.
iBatis and Stored Oracle procedures/functions
This one took me a while to get it right the first time. I won’t go into details of configuring iBatis datasources and such, and will go straight to putting some queries in the sqlMap file. Just let me note that I’m using iBatis 2.3 for these examples. I’ll start off with a procedure call.
<procedure id="getUserRoles" parameterMap="myParamMap"> { call SCHEMA.GET_USERS_ROLES(?, ?) } </procedure> This one is pretty self-explanatory, just defining a procedure to be called.
tail -f for windows
Here’s a simple implementation of “tail -f” UNIX command equivalent in python. I used it a lot on windows servers to monitor log files. The good thing is that it works over SMB (windows shares).
#!/usr/bin/env python import sys, os, time def main(argv): if len(argv) < 2: print "Usage: tail filename.log" exit(1) try: fp = open(argv[1], "r") st_results = os.stat(argv[1]) st_size = st_results[6] fp.seek(st_size) while 1: where = fp.tell() line = fp.
Javascript introspection
Very basic, but sometimes useful javascript object introspection
<img id="test"> <script type="text/javascript" language="JavaScript"> el = document.getElementById('test'); str = ''; for (i in el) str += i+'; '; alert(str); </script>
Strings in JAVA
A few days ago I needed to extract all strings from .java files and also thought that it would be a good idea to keep count how many times a string is used. So I came up with this simple python script. It’s kind of a quick and dirty solution, but it met my needs for the particular task.
import sys, os, re from operator import itemgetter files = [] strings = {} exp = re.