Tuesday, September 23, 2008

Getting jruby running with mysql on ubuntu

You want to get jruby running quickly on ubuntu using mysql as a backing store?

Unfortunately, it does not "just work" with sqlite3 out of the box on ubuntu for some reason. I don't really care why, as mysql is very easy to setup. The most important step that flexed my googling muscles was setting the database adapter to jdbcmysql in the database.yml file.

I will post later on a howto to get this working with glassfish and war files. For some reason, warbler nor goldspike "just work" on ubuntu either.

# install mysql
sudo apt-get install mysql-server mysql-client libhtml-template-perl mailx dbishell libcompress-zlib-perl mysql-doc-5.0 tinyca

# install ant and jdk
sudo apt-get install ant sun-java6-jdk

# install jruby
cd software
wget http://dist.codehaus.org/jruby/jruby-bin-1.1.4.tar.gz
tar xvfz jruby-bin-1.1.4.tar.gz
ln -s jruby-1.1.4 jruby
export PATH=$PATH:$HOME/software/jruby/bin

# install the version of rails wanted by jruby
jruby -S gem install jruby-openssl
jruby -S gem install rails

# list your gems
jruby -S gem list

# install the gems needed for db
jruby -S gem install activerecord-jdbc-adapter activerecord-jdbcmysql-adapter

# generate some code
cd ~/scripts/ruby
jruby -S rails wherehaveyoubeen -d mysql
cd wherehaveyoubeen
jruby script/generate controller states index

# configure access to the database server
vi config/database.yml

#development:
# adapter: jdbcmysql <- very important!
# encoding: utf8
# database: wherehaveyoubeen_development
# username: root
# password: database
# socket: /var/run/mysqld/mysqld.sock

# generate the db
jruby -S rake db:create:all
jruby -S rake db:migrate


# edit your app
sudo apt-get install emacs ruby-elisp irb1.8 emacs22-el
emacs -bg black -fg wheat app/views/states/index.html.erb

# uncomment the secret in app/controllers/application.rb
vi app/controllers/application.rb

# run your app
jruby script/server

# go to your app
GET http://0.0.0.0:3000/states

Monday, September 22, 2008

Adding subversion to eclipse on linux (ubuntu)

You want to use subversion in eclipse? You will need a javahl implementation.

Ubuntu has a javahl package:

sudo apt-get install libsvn-java


Then add this to your eclipse.ini:

-Djava.library.path=/usr/lib/jni

Monday, August 4, 2008

Simple shell for loop

Simple for loop in shell to run a command n times.

for i in `seq 1 10`; do your_command_here.sh; done;

Sunday, July 27, 2008

Find a class in a lot of JAR files

Where did that class come from? Which JAR do I need to import to resolve this compilation error? Arrgh.

find ./ -type f -name "*.jar" -print -exec jar tvf {} \; | less

Thursday, July 10, 2008

Example Java code for posting to blogger.com using labels/tags

So I really can't believe how long it took to get this right, but here is some example code for posting to blogger.com with the ability to add some tags or categories or labels.

You just try searching for some code example on how to "post to a blog using tags". Jeez, it took about 45 minutes of searching to find an actual post that WASN'T a blog post that had a tag.

public class GoogleBlogPostTest extends TestCase 
{
public void testBlogPost() throws Exception
{
GoogleService myService = new GoogleService("blogger", "company-xampleApp-1");
myService.setUserCredentials("googleusername", "googlepassword");

String title = "This is my title " + (new Date()).toString();
String blogID = "blognumber";
String contentStr = "This is a test of the emergency blogging system";
String authorName = "Test Author";
String userName = "author@email.com";
String summary = "This is the summary";

ArrayList tags = new ArrayList();
tags.add("News");
tags.add("Alerts");

Entry myEntry = new Entry();

for(String tag : tags)
{
Category category = new Category();
category.setScheme("http://www.blogger.com/atom/ns#");
category.setTerm(tag);
myEntry.getCategories().add(category);
}

Content content = new TextContent(new PlainTextConstruct(contentStr));
myEntry.setTitle(new PlainTextConstruct(title));
myEntry.setContent(content);
Person author = new Person(authorName, "http://flatebo.org", userName);
myEntry.getAuthors().add(author);
myEntry.setSummary(new PlainTextConstruct(summary));

URL postUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/posts/default");

Entry newEntry = myService.insert(postUrl, myEntry);

assertEquals(title, newEntry.getTitle().getPlainText());
}
}

Tuesday, June 3, 2008

Using microsoft VPN on ubuntu hardy in KDE

In the newest ubuntu, there is a package for kde to use network-manager in the tray to connect to microsoft VPN (PPTP).

sudo apt-get install network-manager-pptp network-manager-vpnc \
network-manager-openvpn network-manager-kde


Then just use the network manager app in the tray to define your VPN connections. When you are ready to connect, just right click and connect.

How to reset IIS

c:\> iisreset


This also resets the exchange services on a Small Business Server install.

Monday, June 2, 2008

How to unzip 'encrypted' zip files in linux

sudo apt-get install p7zip-full p7zip p7zip-rar


bash$ 7z e filename.zip


(it will prompt you for the password)

Friday, May 30, 2008

Managing IMAP accounts on Sprint blackberry devices

I forgot how to add an IMAP email account to my Sprint Blackberry 8830. I found the direct line to Sprint's blackberry support:

1-877-654-9111

He was able to tell me my username and reset my password. What I really needed was this web address:

http://sprint.blackberry.com


which is where you manage your email accounts.

Actually getting lpr to work with cups

Yes, it should 'just work', but it doesn't. After installing cupsys-bsd to provide lpr, you also have to set the printer's name in your environment.

After setting up the printer in cups, list out the printer's names like this:


bash$ lpadmin -p
printer PDF is idle. enabled since Fri 25 Apr 2008 02:37:51 PM CDT
printer Savin is idle. enabled since Tue 20 Nov 2007 06:03:36 PM CST


Then pick the one you want and set the environment variable PRINTER:


export PRINTER=Savin


Now you can use lpq:


bash$ lpq
Savin is ready
no entries


As a follow up, you can also use the '-P' switch like this:

lpq -P Savin
Savin is ready
no entries

Thursday, May 29, 2008

Oracle open transactions

Here is another neat Oracle query you can run that will give you any open transactions:


SELECT
s.osuser, vp.spid as os_pid, S.BLOCKING_SESSION blocker,
S.SID, S.SERIAL#, S.USERNAME, S.MACHINE,
Q.SQL_FULLTEXT cur_sql, PQ.SQL_FULLTEXT prev_sql,
vt.used_urec, vt.start_date
FROM
v$session S
LEFT JOIN v$sqlarea Q on S.SQL_ID = Q.SQL_ID
LEFT JOIN v$sqlarea PQ on S.PREV_SQL_ID = PQ.SQL_ID
LEFT JOIN v$process vp on s.paddr = vp.addr
LEFT JOIN v$transaction vt on s.saddr = vt.ses_addr
WHERE
vt.start_date < SYSDATE - (5/1440)
-- AND
-- s.machine = 'machine.name'
ORDER BY
S.SID
;


With this query, you can track down any open transactions to their Oracle subprocess PID on the operating system. Any transaction that has been running for longer than five minutes will show up with this query.

Now if you wanted to create an alert (I love alerts) that will tell you when you have an open transaction for more than five minutes:


select
LTRIM(COUNT(1))
from
v$transaction
where
start_date < SYSDATE - (5/1440)
;


Thanks to Ted for this query.

Oracle longops

Oracle has so many amazing features, and one of them I learned about yesterday was longops. It keeps track of all long operations within a database. You can view them like this (with the associated SQL):


select
vl.*, vsql.sql_fulltext
from
v$session_longops vl,
v$sqlarea vsql
where
vl.sql_id = vsql.sql_id
AND
vl.sql_id = vsql.sql_id
ORDER BY
vl.elapsed_seconds desc
;



Now if you want to create an alert to let you know when there are current long operations in your system you can do something like this:


select
vl.*, vsql.sql_fulltext
from
v$session_longops vl,
v$sqlarea vsql
where
vl.sql_id = vsql.sql_id
AND
vl.username = 'SOMEUSER'
AND
vl.time_remaining > 30
AND
vl.elapsed_seconds > 30
;



This will tell you if you have any current long operations that have been going for longer than 30 seconds, and have more than 30 seconds left to go.

You will likely want to use the vl.username where statement to filter out system events.

Thanks to Russ for this query.

dia cannot export to PDF

The great dia program for linux cannot export to linux. Also, if you have not setup lpr properly to work with cups, you cannot print from dia.

Dammit. So now I have to export to a png file (which is at the wrong dpi, so the picture is very small). The drawing I did to scale when printed out is nowhere near the correct size.

Lesson learned?

Use a program that can export to PDF. EPS is fine, but people expect PDF.