Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, April 01, 2011

IntelliJ Idea: Frustrations with "cannot resolve Java"

I'm trying to convert myself to using IntelliJ IDEA, as word on the street is that thats what the power developers are using. I'm pretty sold on NetBeans myself. Its pretty, it works every time, its really intuitive and easy to use, it does the task at hand without cluttering me down with loads of crap.

My initial impressions of IntelliJ IDEA are that, I need to force myself to enjoy using it. Hopefully my obstacles to using IDEA will be resolved so I too can get with the program. In this post I'll shed some light on solving a big nasty roadblock I ran into with IDEA.


The Problem:
IDEA doesn't know what Java is.

My first sign that something is very wrong:
IntelliJ IDEA Cannot resolve symbol 'String'

IntelliJ becomes very annoying when it can't find the JDK. It will however prompt me every 10 seconds, that it recommends me to use org.apache.xpath.operations.String, instead of Java's in-built String. It will recommend me a whole crapload of things, such as detecting Spring, wanting to add IDEA project files to the git repository, but it won't detect that I don't have a JDK set.



The nail in the coffin:
IDEA: Cannot resolve symbol 'java'









This does wonders for programmer happiness, in fact, IDEA actually made me frustrated. Even though IDEA was the only IDE that had a certain feature that would be its selling point for me, all of that erases when it doesn't know what Java is, and doesn't give me Code Completion for String.

The Fix:
Properly set the IDEA Platform JDK for your project/module.

Go to Project Structure (Ctrl+Alt+Shift+A), and ensure that Platform Settings[SDK's] has your path for Java set, in my case /usr/lib/jvm/java-6-sun, and then the main fix:
Set the Project Settings[Project] --> Project SDK to your current JDK. I had mine set to none for the project I was working on. Therefore, no java, no string, no primitive types, no nothing.

Once you set that, it should kick off a reindex, and your project will have full Java support. I suppose during the install of IDEA, it didn't detect Java from the usual places, and decided not to ask me.

Sorry if this is a ranty post, but an uncooperative IDE is almost as bad as code thats not doing what you're intending it to.

Monday, February 22, 2010

Document Preview in DSpace, using Google Docs Viewer

    

I've made a modification that allows a DSpace repository to embed a "preview" of the document into the page, so the user never has to leave, just to get to the good stuff.

Adding a Preview link to the item's bitstream.

Then showing the document with Google Doc's Viewer. It essentially becomes a very easy way to make your content more easily accessible, as files that are MS Word or Adobe PDF don't require the visitor to have those programs installed to view them, and load instantly on the page.

How it works
The Google Docs viewer essentially works the same as the user downloading the document to their computer and having the Adobe Reader display the file for them, however, it uses Google Docs to download the document, and then render the PDF before their eyes in real-time so that they can immediately see the document on that page.

It involves modifying ItemTag.java to add the link and a preview box, adding four javascript functions, and used some jQuery. Going forward, I'm thinking that this builds off of Stuart Lewis' idea of having a preview anything. As this is generally a response (for documents) to:
Perhaps we should make this is into a pluggable system for DSpace 1.6 where you can register classes that can render file types, and then make a configurable option to register viewers to filetypes?

UPDATE: The code is available in a writeup at the DSpace Wiki: Document Preview with Google Docs Viewer

Monday, February 01, 2010

Get notified of latest IRC message onscreen with notify-osd (code)

Problem
 When working away in the editor, you see that xChat, "your IRC client" has a new message of activity, and you can't bear to not check on it. The deeper problem lies in the fact that you are like one of Pavlov's dogs and respond to activity.

Solution
 A shell script + php script that reads your xchat channel log, and then sends to notify-osd (the onscreen popup display in Ubuntu et al) that latest message.


#### xchatNotify.sh ####

#!/bin/bash
while [ 1 ]; do
     ./main.php
     sleep 1m
done

#### main.php ####
#!/usr/bin/php
$update_file = DIRNAME(__FILE__).'/last_updated';
$log_file = '/home/peter/.xchat2/xchatlogs/FreeNode-#dspace.log';

$last_updated = filemtime($update_file);
$last_message = filemtime($log_file);
touch($update_file);


if($last_message > $last_updated) {
        $lines = file($log_file);
        echo 'Now: '.date('M d G:i:s');
        $message = $lines[count($lines)-1];
        $cmd = "notify-send \"$message\"";
        echo $cmd;
        system($cmd);
}

You need to have notify-osd and/or notify-osd installed on your system. My system is Ubuntu 9.10.

Room for Improvement
The shell script checks once a minute, and only displays the last message, so intermediate messages are not shown. But the purpose was just to show a message, which should give you enough context to either care or not care. Also, its only checking the one channel, and its not presented as a command line argument. Also, it would be nice to not alert you if xChat is currently the active window.

Sunday, October 28, 2007

Drupal Hack:: Show users email addresses

I was looking through all the spam registrants of a drupal site I maintain. Alot of usernames of zhzjshsk are very suspicious, and also emily and kate, and worst of all, sorry russia, but email addresses from .ru are HUGE sources of spam. Doesn't your country have a valid source of revenue? Can't you just up the production of vodka a little? I don't think stoli sales are as high as they could be.

Anyways, I modified my modules/user.module so that when in the administrative mode of view my users I can see certain info at a glance.

username, email address, status, member since, last online, ...

It doesn't have built in showing of email address, so I hacked modules/user.module to give that feature.


function user_admin_account() {
$header = array(
array('data' => t('Username'), 'field' => 'u.name'),
array('data' => t('Email'), 'field' => 'u.mail'),

array('data' => t('Status'), 'field' => 'u.status'),
array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
array('data' => t('Last access'), 'field' => 'u.access'),
t('Operations')
);
$sql = 'SELECT u.uid, u.name, u.mail, u.status, u.created, u.access FROM {users} u WHERE uid != 0';
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);

$status = array(t('blocked'), t('active'));
while ($account = db_fetch_object($result)) {
$rows[] = array(theme('username', $account),
$account->mail,
$status[$account->status],
format_interval(time() - $account->created),
$account->access ? t('%time ago', array('%time' => format_interval(time() - $account->access))) : t('never'),
l(t('edit'), "user/$account->uid/edit", array()));
}