Wednesday, November 30, 2011

I've recently run into the need to create a simple StatefulTelnetProtocol Telnet server. But, most of the examples have lots of extra cruft in the way. So, here's what I came up with by removing some extras from a post I found online: --> Note: I don't know the difference (yet) between doing a self.sendLine() and a self.transport.write() call. Feel free to comment if you know the distinction.
from twisted.internet.protocol import ServerFactory, Protocol
from twisted.conch.telnet import StatefulTelnetProtocol
from twisted.internet import reactor
from time import sleep

class MyProtocol(StatefulTelnetProtocol):
    def connectionMade(self):
        print "DEBUG: connectionMade called"
        self.sendLine("Welcome to the Simplified Telnet Server\r\n")
        self.transport.write("Can also send a line this way.\r\n")
    def lineReceived(self, line):
        print "DEBUG: lineReceived called with %s" % line.strip()
        if line.strip() != "exit":
            #self.transport.write("TRANSPORT_WRITE: GOT LINE='%s'\n" % (str(line.strip())))
            print "telnet killed in line: %s" % str(line.strip())
            self.sendLine("TelnetShell killed. Bye Bye ...")
    def connectionLost(self, reason):
        print "DEBUG: connectionLost called with: %s" % str(reason)
def CreateMyFactory():
    factory = ServerFactory()
    factory.protocol = MyProtocol
    return factory
if __name__ == "__main__":
    MaFactory = CreateMyFactory()
    reactor.listenTCP(8023, MaFactory)

Monday, October 31, 2011

Python sdist package directory not found: Solved

Just was trying to create a new Python module and submit it to PyPi. Trouble was, when I was doing the standard:
me@mybox ~/myusername/blah
$ python sdist --formats=gztar,zip,bztar,ztar,tar
running sdist
error: package directory 'filenameX' does not exist
turns out the problem was, my had the following line:
py_modules = [''],
This should be:
py_modules = ['filenameX'],
FIXED IT! Yay! Now it proceeds nicely.

Friday, October 14, 2011

Using ssh id_rsa without password - another username

Just had to login to another box via ssh, but the other account has a different username than my current one. Further, had to use a different id_dsa / set of files. I couldn't figure this out for a while. Turns out, the right way to do this is:
  • generate the keys
  • copy the pub key into authorized_keys2 on the remote box
  • ssh -i ~/.ssh/privateKeyFileName otheruser@remoteboxname
Pretty straightforward, found out. Kinda cool - didn't know about the -i parameter.

Wednesday, October 05, 2011

SSH Slow password prompt

Just had a problem with my vmware player install of Ubuntu Natty. Doing SSH takes a long, long time to come back with a password prompt. This is really aggravating.

Solved it by finding the following info:

1. Edit the /etc/ssh/ssh_config file using the following command

sudo vi /etc/ssh/ssh_config

Commentout the following lines

GSSAPIAuthentication yes
GSSAPIDelegateCredentials no

save the file and exit

2. Test it with ssh to another box, should be very fast now!

Thursday, September 29, 2011

Python BufferedIOBase Error

Just had a problem with a Python script where it was mysteriously generating an error on a simple import gzip statement.

The problem turned out to be someone had created a directory named 'io' in the PYTHONPATH. This caused python to import from that directory instead of importing the builtin library io.

Silly programmers! Don't you know Trix are for kids! Never create a directory named the same as a builtin library! Ug! I'll be changing this dir name as soon as practicable (gotta negotiate with the rest of the code to make sure it isn't a depended-upon bug).

Wednesday, July 20, 2011

Comparison of MS Sql Server vs. Sybase

Comparison Of Sybase and MS Sql Server

Just some thoughts here:

1. There are many large players in the financial industry who have significant investments in Sybase. This means there's a ready supply of DBA's who know both the industry and the technology.

2. Sybase has a data warehousing solution called Sybase IQ, which does lots of optimization specific to data warehouses automatically. It is a 'sparse database' model, storing all unique values and then references to those values, much like is done with varchar2 storage. This saves lots of space, and allows for faster queries if the queries are large. Caution, IQ is built for a few large queries; if you throw lots of small ones at it, it will choke / run very slow, so don't do that.

3. Sybase has available drivers in Perl, Python, etc., and runs on many different OS's (Linux especially). Not true for SQL server, which is a Microsoft-OS-ONLY DBMS.

4. Sybase has a reputation for handling very, very large datasets easily. Terabyte-sized tables are normal. MS SQL Server has a reputation for being optimized for small tables, and choking on large ones.

5. MS SQL Server has a very strange idea of backup / admin tools. These did not handle continuous backup (keeping the DB online thru a backup is a normal thing). Note, this might be fixed now. Sybase has always had this feature.

Monday, February 28, 2011

List of Common CPAN Modules

I've been having trouble finding a list of handy perl modules. You'd think that people would be ready with a list, but doesn't keep any, and the Google search for 'list of common CPAN modules' doesn't return anything.

So, here's my list, for all it's worth. Feel free to post additions. I presume you've installed CPANPLUS, then invoked:

$ perl -MCPANPLUS -e shell

CPANPLUS> i Algorithm::Diff B::Keywords BSD::Resource Bundle::HTML CGI CPAN CPANPLUS Carp::Always Chart Config::General Crypt::Blowfish Crypt::DES Crypt::DSA DBD::mysql DBD::SQLite Daemon::Generic Data::Alias Data::Buffer Data::Dump Data::Dump::Streamer Data::Dumper Data::FormValidator Data::Peek Date::Calc DateTime DateTime::TimeZone Devel::NYTProf Devel::Size Email::Simple Email::MIME Email::Send Encode::Detect File::CheckTree File::Fetch File::GlobMapper File::MMagic File::Slurp File::Spec File::Temp File::Which Getopt::Declare Getopt::Euclid Getopt::Long Getopt::Std HTML::Entities HTML::Mason HTML::Parser HTML::Template HTML::Tidy HTML::TreeBuilder HTTP::Date HTTP::Request IO::Interactive IO::Prompt IO::Stringy IPC::System::Simple Image::Size JSON-RPC JSON-XS LWP LWP::MediaTypes List::MoreUtils List::Util Locale::Encode Log::Any Log::Log4perl MIME::Tools MIME::Types MailTools Math::Random::Secure Math::BigInt::FastCalc=>0.25, Math::BigRat=>0.2602, Module::Metadata Module::Starter Moose Net::Cmd Net::Domain Net::FTP Net::LDAP Net::NNTP Net::Netrc Net::PH Net::POP3 Net::SMTP Net::Telnet Net::Time PAR::Dist PDF::API2 PDF::Report Parse::RecDescent PatchReader Path::Classs Perl::Critic Perl::OSType POE Return::Value Regexp::Common Regexp::Assemble Text::Autoformat SOAP::Lite Scalar::Util Devel::Cover Test::Pod Test::Pod::Coverage Test::Spelling Test::Valgrind Test::kwalitee Test::MinimumVersion Module::Release Module::Build Module::Install Module::Install::AuthorTests Module::Install::ExtraTests Test::Prereq Parse::CPAN::Meta Spreadsheet-ParseExcel Spreadsheet-WriteExcel Template Test::Deep Test::Fail Test::Perl::Critic Test::Script Test::Tester Test::noWarnings Text::Diff Text::CSV Text::CSV::Simple Text::CSV_XS TheSchwartz Tie::Dir Time::HiRes Time::Zone TimeDate Try::Tiny WWW::Mechanize version