August 2nd, 2006 by Rich Rodriguez
For my current project we needed to audit the property setters Hibernate was using on our objects to make sure that any logic in them was not overly state dependent. More about this issue in Hibernate is available here. We have fairly rich object models, and a lot of methods, including setters, are never used by Hibernate. We wanted a report of the setters actually used by Hibernate to limit the amount of code we had to examine.
The Hibernate API allows you a lot of access to its configuration object model, and this is ideal for finding out how Hibernate is interacting with your code. I wrote a small class to do this inspection. The method below is run after a Hibernate Configuration object named creatively as “configuration” has been built with mapping files:
public Map findSetters() throws MappingException
{
Map classToSetters = new HashMap();
Iterator classMappingIterator = configuration.getClassMappings();
while(classMappingIterator.hasNext())
{
PersistentClass persistentClass = (PersistentClass)classMappingIterator.next();
Class mappedClass = persistentClass.getMappedClass();
Iterator propertyIt = persistentClass.getPropertyIterator();
List classSetters = new LinkedList();
classToSetters.put(mappedClass, classSetters);
while(propertyIt.hasNext())
{
Property property = (Property)propertyIt.next();
Setter setter = property.getSetter(mappedClass);
classSetters.add(setter.getMethodName());
}
}
return classToSetters;
}
I have uploaded a Java project that contains the full HibernateInspector class, as well as some sample classes and mappings. Un-tar it, and run
ant -Dhibernate.home="path to hibernate 3"
to build and run the example.
Posted in hibernate, java, utilities | No Comments »
July 28th, 2006 by steveny
If you want to access a database without it being in your tnsnames.ora file, you can use a ‘URL’ at the command line:
sqlplus login/pwd@//hostname:1521/sidname
This should work with versions 9 and above. Let me know if other versions work.
Posted in Oracle | 1 Comment »
June 8th, 2006 by carsonm
I’m not sure if something isn’t set up correctly of if this is just a fact of life with rails but the sessions it creates never seem to go away. I think before rails 1.1 the sessions where stored in /tmp and now they are stored in the apps directory along with everything else so they is probably no internal mechanism to delete them. I only noticed because after about a month of an certain app running the disk on the machine started to fill up. After digging a little I found 50K ruby_sess.* files hanging out in the rails session directory.
Anyway it was easy enough to clean up the stale ruby_sess files by going into the rails webapp/session directory and then running the following command:
find -type f -name "ruby_sess*" -exec rm -f {} \\;
I’m not sure why the app is creating sessions but it isn’t something that stores state so I didn’t have to worry about killing active sessions here. If you do need to worry about that you will probably want to toss a time on the find command.
After looking a little more I found a post about this that has a ruby way of cleaning up the sessions.
Posted in rails, ruby, system administration | 1 Comment »
June 1st, 2006 by carsonm
After reading this post on the S3 forum I realized that other people are thinking about doing some of the same stuff I have. paolonew was looking for a way to for a way to create URLs to S3 objects that expired. I did this a while back when I was thinking about how to host objects that I wanted to protect with some outside scheme. The confusion on the forum seemed to be about the timestamps used to expire the URL. For PHP it is fairly easy.
To clear up the expiration time issue I think these two steps are needed:
1) Keep in mind that the HTTP header dates must be in GMT.
2) The PHP function time() returns the seconds since the epoch January 1 1970 00:00:00 GMT). Notice here this is in GMT as well.
3) The HTTP Date header you see in a response from an S3 server is the time on that server. The machine you use to sign your request should be synced with that time. I think a good guess is that all the Amazon servers are synced with the atomic clock.
There isn’t much to securing a URL after you have that tucked away. Here is an example that will sign a URL so that it is valid for 60 seconds:
<?php
require_once('Crypt/HMAC.php');
echo getS3Redirect("/test.jpg") . "\\\\n";
function getS3Redirect($objectName)
{
$S3_URL = "http://s3.amazonaws.com";
$keyId = "your key";
$secretKey = "your secret";
$expires = time() + 60;
$bucketName = "/your bucket";
$stringToSign = "GET\\\\n\\\\n\\\\n$expires\\\\n$bucketName$objectName";
$hasher =& new Crypt_HMAC($secretKey, "sha1");
$sig = urlencode(hex2b64($hasher->hash($stringToSign)));
return "$S3_URL$bucketName$objectName?AWSAccessKeyId=$keyId&Expires=$expires&Signature=$sig";
}
function hex2b64($str)
{
$raw = '';
for ($i=0; $i < strlen($str); $i+=2)
{
$raw .= chr(hexdec(substr($str, $i, 2)));
}
return base64_encode($raw);
}
?>
The hex2b64 function was pulled from the amazon S3 PHP example library.
Posted in php, s3 | 1 Comment »
May 17th, 2006 by darrend
The slides for the presentation are finally available, along with a zipfile, on the Presentation: You’ll Be Seeing Ruby page.
It’s been a month now since our last performance, but it all comes back every time I look at the slides.
Posted in presentation, ruby | No Comments »
May 11th, 2006 by carsonm
Now that google has anounced their new Google trends site I couldn’t help but mention it. If you spend any type of money at all on SEM you need to check your keywords against this site.
There are a couple of intro articles about the new service at TechCrunch.
To get a real feel for how important this information will be you should try out a few queries for yourself. Take a simple query like “motorcycle” and then look at the regions tab. A lot of the queries about motorcycles originated from the Philippines. Now look at “pizza”, most of the queries there originated from the US. That should make it much easier to target your audience with your advertisments. The trending is nice as well and should give marketers a better idea of when to boost spending to maximize exposure.
This follows another tool Google just release for their AdWords service. You can read more about it at the adwords blog. That tool gives you a different view of the search trends and is more like what you get from Yahoo’s advertising system.
Posted in sem, seo | No Comments »
May 10th, 2006 by carsonm
Recently I’ve been collecting links on interesting SEO topics. I figured I would dump a few of them out with quick reasons why I think they are good to read.
A technical read on how search engines work in general. It focuses on google but has a lot of good general information in it.
This is a recent article on how to optimize your site. I like it because it has an acronym on how to do it “camelot”.
SEO chat has a lot of information in its forums.
An article from a guy who works at Google and goes into what the search engines have to deal with to keep people on the up and up. It goes into some of the stuff you don’t want to be doing to try to get your site at the top of a search. For some reason I found it interesting that this guy is from kentucky.
Another good article on the “SEO Code of Conduct” AKA what you should not be doing to get your site at the top of a search.
A nice tool to help you find words to go with your website: WordTracker
Posted in seo, web design | No Comments »
May 9th, 2006 by carsonm
I think by now most sysadmin types know about rrdtool and the nice graphs it makes. I recently wanted to create some graphs by hand using PHP so I turned to the php-rrdtool extension. I found that it takes a little work to get it to compile but that could be because I’m not constantly recompiling PHP and just don’t know better. You can get this module as an rpm for fedora (php-rrdtool) but I like to compile php by hand so I couldn’t use it. I’m going to assume that you know how to compile PHP normally with whatever other items you want to include and that you have the rrdtool development libraries installed or have compiled and installed rrdtool from source.
Step 1. Get the PHP rrdtool source
Go to the contrib directory on the rrdtool distribution site:
http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/pub/contrib/
There are a number of files in this directory that mention rrd. You want the one named: php_rrdtool.tgz
Read the rest of this entry »
Posted in linux, php, system administration | 4 Comments »
May 2nd, 2006 by timothyr
Have you ever mistyped your login name in firefox, only to have it save the wrong entry as well as the correct one? How do you get rid of the wrong entry? You could clear out all of your saved information, but why just for one mistake! Frustrating huh? Even more frustrating is finding the completely undocumented answer. Well I’m documenting it now.
Go to the form where the mistake is. Put your cursor in the text entry widget and hit down until the incorrect entry is highlighted. Now press shift + del … voila. You’re welcome.
Posted in Uncategorized | 35 Comments »
April 29th, 2006 by carsonm
A few days ago I made use of a couple Oracle built in functions and it made me happy I didn’t have to write a stored proc or some type of mini-app to do it. I needed to parse a timestamp out of a field that was put there by a java program. The timestamp was just the output of System.currentTimeInMillis() and was concatenated onto some other information.
It took a little digging to find out how to convert a epoch style timestamp but here it is:
select new_time( to_date('01011970', 'ddmmyyyy') + 1/24/60/60 * :currenttimeinmillis/1000, 'GMT', 'EDT' ) from dual
Note that I convert the output from GMT to EDT here.
Posted in Oracle | No Comments »