Custom telnet Groovy shells – version with shared context

2011-12-16

A follow-up to the previous postcustom Telnet shared Groovy shells. This time having shared context for all shells, i.e. shared variables!

The trick was to get Binding object from current Groovy shell Interpreter and pass it in constructor to Groovy shells that we instantiate programmatically on socket connections. Not sure if it’s thread safe BTW (this isn’t production ready (-: ).

The code is based on Groovy Shell internals a bit, so should probably be run only from Groovy shell. (And just in case – I’m using version 1.8.4 of Groovy).

In any case, here’s again some demo video:

UPD: Also there’s the thread-safe version.
In it each shell will have it’s own Binding object, i.e. separate variables context.
But on creating shell we’ll inject two variables into that context:
- sharedConcurrentMap – an instance of ConcurrentHashMap which will serve as thread-safe shared context for all shells, and is pre-populated with “server” and “sockets” (the latter are also made thread-safe);
- thisShellSocket – a socket that is used for this child shell.

See source code at the end of the post.

As usual, a little demo video:

The source code Read the rest of this entry »


Little Groovy fun

2011-12-16

Got a bit of free time to play with Groovy today.
So I checked out some groovy sockets example and made a little groovy shell server that is running in a groovy shell itself (-:

UPD: A little video demo

Sources (updated 2011-12-16 04:16): Read the rest of this entry »


Liferay dictionary

2011-12-08

When I started working with Liferay some things took me a while to figure out due to a certain difference in names used for Liferay features in user documentation and interface (Control Panel in particular) and names used internally in Java APIs, database tables etc. So I though a little table of correspondence might come handy for someone starting with Liferay or getting from user to developer level.

Let’s start with an extended example – Web Content, the base of Liferay CMS features.
It is actually mentioned on Liferay Wiki that some time ago Web Content was called Journal or something like this, but at a certain point all related portlets, control panel sections etc got renamed. Yet internally you will find no sings of “Web Content”.
The Java APIs for working with webcontent as well as DB tables are all still using old naming.

Web Content item is JournalArticle, Structure is JournalStructure and template is JournalTemplate.
To manipulate those you would use classes like JournalArticle(Local)ServiceUtil, JournalStructure(Local)ServiceUtil, JournalTemplate(Local)ServiceUtil, and to see them in database you’d have to look up tables also called “journalarticle”, “journalstructure” and “journaltemplate”.

So, let’s move on to our vocabulary: Read the rest of this entry »


Checking out Groovy…

2011-10-30

It’s a quite typical architecture for Java webapp to have Apache Velocity as templating engine that handles the View part of your MVC.

Well, having worked for a while with it and checking out Groovy now I immediately felt it’s be very interesting to have Groovy there instead of Velocity.

Velocity is sensibly weak in working with arrays and lists. But Groovy on contrary adds more power and convenience in this aspect. And doesn’t seem to be lacking in any other.

It seems someone in 2007 already though about this: http://raykrueger.blogspot.com/2007/07/groovy-views-in-spring-mvc.html

And even more – Grails, the Groovy framework, is actually based on Spring MVC, although this is a bit too much compared to just having Groovy scripts as “views” in Spring MVC.

All in all, it sounds like a good ting to try out.


Few simple/obvious ideas on education

2011-10-17

I’ve got a few rough idealistic “SCI-FI kind” ideas on education that I somehow would like to share.
If you find them obvious or… ehm… even a bit silly – well, you might be right (-:

Anyway…

# University lectures generally don’t change much, and thus can be re-used over time by using recordings (that are updated when necessary) – like Berkeley University did.
Also they can be re-used “in space” by using video-conferencing technologies.

Of-course, some theories are refined etc etc, but in general physics and mathematical analysis lectures remain mostly the same, thus making it reasonable to re-use them over time.
Also physics and math are same, no matter which university (or not even necessarily university) they’re told in.

I see no compelling reason why lectures from one university cannot be re-used in another 10 or 10 000 universities (DRY principle for real world).

Berkeley recordings IMO are a good example how not to make recorded lectures BTW: these should be more presentation/screencast-like I think, certainly not a videotaping of typical lectures in front of live auditory with all the outcoming timewaste (that blabber about attending labs etc is especially annoying in it’s distracting irrelevance).
Also Berkeley 2006 recordings look like early 90-es (-: – a bit weak sound (sometimes problems with it), bleak colours, all this chalk and dusty blackboards etc etc – even whiteboards + coloured markers would be a noticeable improvement.Compare Berkeley recordings to Google Tech Talks for instance, and you’ll know which is the direction to improve as I see it.

There are many different ways to modernize it – think of PowerPoint-like presentations, screencasts, iPad magazines ADs (-; (and flipboard app, heh) etc etc. Lots of space for imagination and experiments.

# Videoconferencing for lectures can be particularly interesting if organized as cooperative lectures, performed by several lecturers from different universities together.

Imagine two (three, four, five…) best specialists/teachers in a field lead a lecture for auditory of millions of students, distributed over multiple universities all around the country/globe, at which local teachers (or professors, title doesn’t matter) are taking over when it comes the time for Q&A (questions & answers) – after cooperative lecture is over.

Of-course, practical part (labs etc) remain local, though can also be performed cooperatively, having, say, groups from 2 universities working together, having different universities each time – that’d be somewhat refreshing and help distributing ideas quicker I reckon.
There are many variants here also – only sky is the limit.

# It’s many years now since video-recording and video-conferencing have become common and quite inexpensive. Unlike it was in 80-es or early 90-es, there’s no need for any special equipment to make (let alone playback) video recordings, or even organize a video conference – every student now has a mobile phone now that can record video, and some smartphones can actually stream it to web where anyone can watch it (see justin.tv and the like).
So there should be no problem experimenting with those until best working practices would be found.

Same/similar practices can be applied to schools and other educational facilities.

# Outro: when my parents were young, television was something new and amazing. When I was younger, Internet was new and amazing. I sincerely envy subsequent generations (-:


Liferay 6 CP portlets for site admins + sources

2011-08-24

As mentioned in previous post, I’ve been planning to make a little Control Panel portlet for Liferay 6 that would allow site admin to tell on which pages particular portlets are.

Today I’ve written two portlets for this. One allows you to see which groups and pages you have, and check portlets are on those pages.
Another – see what portlets you have, and check on what pages do you have instances of those portlets.

Little warning:
Portlets are pretty fresh, so there’s a chance something might fail or not work quite right.
Also the code is not very efficient, yet I haven’t got any OutOfMemory exceptions during the whole day of writing and checking, so in general they should be fine (-:

Without further due, here’s the download link. Sources are contained inside WAR file.

Portlets are written for Liferay 6.0.6 Community Edition (using corresponding plugins SDK), and should also work just fine on Enterprise Edition (though I haven’t checked yet, I’m pretty sure they will).

WAR is compiled for Java 6, some occasional @Override-s are present in code – remove them and recompile if you need it for Java 5. I might as well change it to Java 5 version a bit later…


Liferay (6) small hint – where are my portlets?

2011-08-19

Note: We’re running Liferay 6 on MySQL DB.

One day I just wanted to see on which pages my portlets are used. So I had to make a little query for this:
select portletId, layout.plid, group_.friendlyURL, layout.friendlyURL from portletpreferences left join layout on layout.plid = portletpreferences.plid left join group_ on layout.groupId = group_.groupId where portletId like '%_WAR_[YOUR WAR NAME GOES HERE]%';

If you want to see all of the portlets, you can remove the “where” clause (but be prepared to be overwhelmed with the output).

The results look like this:

+-----------+--------+--------------------+--------------------+
| portletId |  plid  | group_.friendlyURL | layout.friendlyURL |
+-----------+--------+--------------------+--------------------+
| 103       | 704033 | /guest             | /my-community      |
| 145       | 704033 | /guest             | /my-community      |
| 29        | 704033 | /guest             | /my-community      |
| 49        | 704033 | /guest             | /my-community      |
| 86        | 704033 | /guest             | /my-community      |
| 87        | 704033 | /guest             | /my-community      |
| 88        | 704033 | /guest             | /my-community      |
...

Maybe I should make a full-fledged control-panel portlet for this – who knows, it might come handy.


SQLite BLOB exporter with GUI

2011-07-13

As promised in one of previous posts, I’ve written a little GUI-ed program in Java that allows exporting BLOBs data from SQLite to separate files. And I’m giving it away, with all sources.

The program has only one dependency - sqlitejdbc-v056.jar, which is a JDBC driver for SQLite databases. Download it from www.zentus.com/sqlitejdbc/ and put in the same folder where my program’s JAR is.

Besides the above-mentioned dependency, my program is just a single JAR file (sources are packed into it). To launch the program simple double-clicking on it should be just enough. If it isn’t, search web for “lanuch JAR” – you’ll find plenty of instructions. You must have Java installed, but that is an obvious thing I suppose.

Here’s the download link: mvmn.ho.ua/dld/sliteblobexp.jar (MD5 checksum = 99ca2488ac62f48721dced3c119d1271).

A small video of it in action: 


Liferay 6: querying webcontent dynamically

2011-06-23

Liferay 6

Problem: we need to obtain webcontent items by custom query with conditions, one of them being webcontent item type for instance.

The JournalArticleLocalServiceUtil.dynamicQuery(DynamicQuery query) method seems to be just what we’re looking for.

Let’s make a custom query to get 100 latest webcontent items of types “blogs” and “news”. We also add condition on groupId, because we want only items from certain group:

DynamicQuery query = DynamicQueryFactoryUtil.forClass(JournalArticle.class, PortalClassLoaderUtil.getClassLoader())
.add(PropertyFactoryUtil.forName("groupId").eq(groupId)
.add(PropertyFactoryUtil.forName("type").in(new String[] {"blogs", "news"}))
.addOrder(OrderFactoryUtil.desc("createDate"));
query.setLimit(0, 100);

List <JournalArticles> = JournalArticleLocalServiceUtil.dynamicQuery(query);

It almost worked. Almost.
Read the rest of this entry »


Liferay (6) practices

2011-06-20

Working with Liferay always raises a lot of questions about best practices, or even just correct or even working ways to do things. That’s because Liferay is quite non-standard in many ways (which isn’t surprising actually, as really all Portlet containers invent their own tricks due to limitations of Portlets specificatin).

Today I’ll share some generic practices which I wish I myself knew when I was starting my Liferay experience.
Read the rest of this entry »


Follow

Get every new post delivered to your Inbox.