Archive

Archive for the ‘Groovy’ Category

A Groovy Script to Keep The Internet Cafe’s WIFI Alive

October 26th, 2012 Comments off

Have you ever been to an Internet Cafe and connected to the free WIFI? Have you found that after five minutes of activity the connection has been dropped and you have go through the License and Terms of Agreement again and again and again? Annoying isn’t.

Well after expiring this at Charlotte Airport in the USA recently, I re-concocted the script that I wrote for the half-dozenth time. This time I going to blog it and save it for all time.
Here is a simple Groovy script to keep the Internet alive.

// Hang-up to Internet Connection Groovy Script
// Useful for Internet Cafe that drop WIFI connectivity through
// perceived lack of activity e.g. Starbucks / Hotels
// Peter Pilgrim
// 28 September 2012

def maxTimeout = 30000
def minTimeout = 15000

def domainList = [
    'gmail.com', 'google.co.uk', 'google.com', 'bbc.co.uk', 'cnn.com', 'java.oracle.com',
    'facebook.com', 'twitter.com', 'oracle.com', 'zen.co.uk', 'java.net', 'www.scala-lang.org',
    'plus.google.com', 'guardian.co.uk', 'linkedin.com', 'www.typesafe.com', 'www.yahoo.com',
    'www.ibm.com', 'www.apache.org', 'www.adobe.com', 'www.microsoft.com', 'www.stackoverflow.com',
    'www.apple.com', 'groovy.codehaus.org', 'java.oracle.com', 'www.telegraph.co.uk', 'www.jroller.com',
    'www.dell.com', 'www.samsung.com', 'www.amazon.co.uk', 'docs.oracle.com', 'www.infoq.com',
    'www.devoxx.com', 'www.qconlondon.com', 'www.smashingmagazine.com', 'en.wikipedia.com' ]

def count = 1
while (true) {
    int idx = (int)( Math.random() * domainList.size )    
    println "[$count]  nslookup ${domainList[idx]}"
    def process = "nslookup ${domainList[idx]}".execute()
    println "Found text ${process.text}"
    
    def sleepTime = (int)( minTimeout + Math.random() * ( maxTimeout  - minTimeout))
    Thread.sleep( sleepTime );
    
    ++count
}

// done

The script can be improved with a much larger set of domain names, perhaps I could machine generate the domain names from the Chrome Browser history, or something like this. That is about all I would do, except to parameterise the command line arguments. On Mac or Linux I just hit the terminal and type with auto completion of course groovy ~/hangon-to-internet.groovy

Now, the only thing to write is a similar script to keep the WIFI connection to the both mobile phone and tablet alive. Answers on a post card please.

+PP+

Categories: Groovy, language, programming, tool Tags:

Building ScalaFX 1.0 with Gradle 1.1

August 28th, 2012 2 comments

After becoming a little disenchanted with the SBT for Scala, I wanted an alternative that was more logical, simpler to understand and had a better user experience. After all, the whole point of a domain specific language is to make the writing of the script, formulae or grammar to be affordable to the users. A DSL must be comprehensible to the users, it must be relatively easy to write the script in the language of the domain, and surely must be mostly free of annoyances. The great examples of course are spreadsheets like Excel, the XML Stylesheet Language for Transformations (XSLT) and shell scripts (like DOS, BASH).

I recently added a build.grade file to the ScalaFX project. Here is a screen cast about how to use Gradle build instead of the current SBT file.

Building ScalaFX 1.0 with Gradle 1.1 from Peter Pilgrim on Vimeo.

The only sore point so far, I have found with Gradle, is that the project takes it name from the containing folder. In other words, I found that force setting the artifactId does not work.

group = 'org.scalafx'
artifactId = 'ScalaFX-javaone-2012'  // This does not work
version = '1.0-SNAPSHOT'

That might be worth considering when moving project folders around in order to make a quick research branch for a delta, or look at some other committer’s changes separately from your own.

Because Gradle is written in Groovy, you have the full power of that dynamic language to play with. I was able to write a groovy task to push a UNIX bash launcher script in less than ten minutes. I was also able to run a launcher within Gradle for the Colorful Circles demo app. The Gradle documentation is a lot better than SBT, in my humble opinion.

In SBT, if you missed adding a single blank line between statement declarations, or you forgot to add an extra delimiter between to Seq() or perhaps used the wrong method name “+” versus “++” then you could be lost for quite a long time.

It would good to see how the Scala Plugin for Gradle could work with recently announced Zinc and Incremental Compilation from Typesafe. After reading that blog post, I think Zinc, Gradle and Scala plug-in should just work. Has anyone tried this combination yet? I have not yet.

PS: Under Windows, you need to comment out the “chmod” line in the build.gradle for now. I will fix this later on before the 1.0 release.

PS PS: With the Vimeo, you might prefer to click on the HD option to see improved clarity.

+PP+

Devoxx 2010: Conference Days Part One

November 19th, 2010 Comments off

 

Keynotes

 

To Wednesday 17th November 2010 and the proper conference began in earnest with a keynote by Mark Reinhold, which was about Java SE 7 and then followed by Dion Almer and Ben Galbraith, who had a breathe taking reprise of State of the Web.

Java SE 7 and 8

Mark Reinhold talk about the upcoming reasons for the Release Plan B. The schedule for the release is pretty ambitious as the date is 28th July 2011. There were no more surprise in store in Project Coin, since the keynote at JavaOne 2010. There were explanations for the delays in getting out JDK 7. I think generally the development community were acceptable to new features like: multiple-catch exceptions, string literals inside switch statements, type inference for generic types. The big announcement of course the night the keynote was a Mark Reinhold blog, where Oracle pushed out the Java Specification Requests for Java SE 7 and 8, Project Coin, Jigsaw and Lambda, namely 334, 335, 336 and 337. Now that was good news that the community had wanted hear for a long time.  These JSRs have now been submitted to the Java Community Process.

State of The Web

Devoxx 2010

(L-to-R: Dion Almer and Ben Galbraith keynote)

There was another keynote to follow up and it was by Dion Almer and Ben Galbraith. It was a really good presentation and rather thought provoking I should say. Galbraith and Almer started with an examination of Microsoft sudden change of heart on the web with push of Internet Explorer 9 (in Beta status now) and the deprecation of Silverlight.

Devoxx 2010

The Ajaxian duo team reviewed the state of the web with screen captures from the grand old days of the web. Screenshot of the Google web page from 1998 was updated to the present day.  The same applied to Apple and the audience were amused by the sheer change. It was clear the change in the look and user interface when UX designers got on board the web. The duo pointed out that the influence of Ajax and Ruby-on-Rails, 37 Signals creator, David Heinemeier Hansson on the way the web has evolved. There was a clear distinction in the presented evidence of web sites pre 2006 and post the Ajax revolution.

Almer and Galbraith of course were pushing the web as may be ultimate platform for development. Yours truly might beg to differ on the web being complete. It is however interesting how HTML5 / CSS3 / AJAX / Web Sockets and of course JavaScript the programming language have come along for people. It is also the design of web pages and separate of styles and mark-up that allowed this evolution. The web cannot quite replace high performance and data intensive native application and there is no universal off-line solution. What happens when one boards a jet plane from London to San Francisco? You cannot work on the web. It is all to play for, in this decade. Maybe Google can actual deliver Chrome OS over a hyper-spatial link?!

 

Reflection Madness by Heinz Kabutz

 

Devoxx 2010

Heinz Kabutz, fellow Java Champion

Doctor Heinz Kabutz had some interesting Java puzzler solutions concerning Java Reflection. It appears you can break the JVM by changing the private field property of immutable objects. Take instance the venerable java.lang.Integer class. An object of this class can be subverted such that it’s secret private value is not in agreement with its declared constructor input. Now if you add to this object to collection and you start iterating over the collection, may your program can go into infinite loop or crash. His newsletters contains the full explanation and examples so I refer you to got subscribe to this fellow Java Champions web site Java Specialist.

 

From Shabby To Chic by Richard Bair and Jasper Potts

This was repeat of the presentation almost that Bair and Potts gave at JavaOne six weeks ago. The technical session was about styling JavaFX components. The JavaFX SDK team, namely the duo here spent some considerable time building Caspian component with really nice designer look and feel. The example was the JavaFX Login Dialog screen and so this is repeat report and I will leave it there.

 

JavaFX Your Way: Building JavaFX Applications with Alternative Languages by Stephen Chin

Devoxx 2010

Stephen Chin, fellow Java Champion

This is also a repeat presentation from JavaOne 2010 and for the benefit of the European. So ok if you could not get to JavaOne, then it shows the presenters do get send the message to a different continent. Since the surprise announcement about JavaFX Script these examples on the experiments of programming with JavaFX 2.0 as DSL are quite useful. For my money, many developers, especially the innovative one, might look to program JavaFX 2.0 from alternate JVM language in the future rather than Java. If you are thinking of JavaFX 2.0 then it worth taking a look at some the presentation slides and also getting the Parley’s video when it is released.

 

Performance Anxiety by Joshua Bloch

Unfortunately this was one I missed due to networking with individual. I will pick it up on Parleys.

 

Android Graphics and Animation by Romain Guy and Chet Haase

 

Devoxx 2010

(L-to-R: Chet Haase (Google), Romain Guy (Google) and James Ward (Adobe). Actually there is a funny story of the custom "hoodies" that I think is better told by Devoxx chief organiser, Stephan Janssen. ;-)

Here was a session that left me a little confused about the Android platform. I think that I sort of got the design architecture of the Android platform. A Canvas type has no state and does not store a display list. A Paint type has a state about the colour and the brush to fill a Drawable type. Android is an unfamiliar graphics system based on the hierarchical order of “views”. There is the concept of a ViewRoot and nested Views. Actually I think that Romain Guy answered my question as best he could have. I asked about the different states and the filtering that could be applied to an Android graphic application. He answered that the filtering work only with bi-linear algorithm and not bi-cubic one, and in fact that even Java 2D does not implement the graphics context hint BICUBIC.

Devoxx 2010
Devoxx 2010


 

JavaFX BOF by Richard Bair and Jasper Potts

In this BOF Richard Bair and Jasper Potts were connected to the other Oracle SDK over a web conference. They had the brilliant idea of throwing open the design decision to a much wider audience. The question was, which design programming idiom should the Oracle JavaFX SDK team use to write the new JavaFX 2.0?

This BOF, therefore, was much more intense discussion of the above scene-graph node construction kit. Stephen Chin, Jo Voordecker and Johan Vos were also in attendance for this crucial BOF. It made for a more technical discussion of JavaFX 2.0. The result was that the “Builder method chaining” programming idiom looks like it was the best solution going forward. This is, however, no guarantee that the Oracle JavaFX SDK team will take it forward. As was said, before the huge issue is the binding of properties of the Java scene-graph node objects, and that binding works best when it is immutable and therefore the binding must initialised at object construction time. In other words, as with JavaFX Script, it is not easy to implement dynamic binding and therefore infer “unbinding” of two properties without excessive cost and complexity.

Salient questions were:

  • How can we have an object construction idiom in Java that is type safe?
  • How can we reduce the boiler-plate of the syntax to make it easier for [intermediate] Java developers?
  • How can we write an object constructor idiom that is amenable binding in Java [that inherits most of the power of JavaFX Script]?

Here is my own question thrown in is:

  • How does the new object construction idiom, whatever its future scheme, help domain specific language writers in other programming languages like Groovy, Scala or Clojure?

     

    What’s New In Parleys.com Version 4 by Stephan Janssen

     

    This BOF with Parleys.com Version 4 was extremely impressive. It was quite amazing how much further along the software improved since 2009. The Parleys 4 now works on iPad and will be shortly working on Android devices. The iPad support was through a MP4 conversion process that Stephan Janssen described. MP4 will be featured on Devoxx 2010 technical sessions and keynotes. Unfortunately older presentation streams and channels will not be transcoded. Stephan Janssen claimed it is just too much work, memory and time.

    The key demonstration was how to use Parleys to capture a presentation talk in audio and video including the slides. Most presenters export PDF to the conference, so a specific application captures the PDF slides and separates each slide to a JPG image. Another part of the Parleys application examines the video stream of the presenters laptop and smartly demarcates slide transitions. This same technique also recognises when the presenter has jumped into demo mode. In other words, Parleys can automate a lot of the digital capture of a presentation.

    The iPad client version was created by Jan-Kees van Andel  in his spare time. The version has a very nice U/X specifically designed for the Apple tablet device’s resolution. The author pointed out that it is designed solely for the iPad U/X and not the iPhone. The Parleys client supports the iPad using HTML5, standard Java Server Faces (JSF) and streaming MP4 service. It is also open source.

    The Android client version was still in development mode. However it had all the good U/X hallmarks of the other clients. Android Parleys client is expected early 2011.

     

    This is Peter Pilgrim at Devoxx 2010. Out

    Devoxx 2010 University Day 1

    November 17th, 2010 Comments off

    Devoxx University Day 1

    Yours truly arrived on Sunday for the annual Devoxx conference in Antwerp, Belgium. After the experiences of JavaOne only six weeks before it felt rather peculiar to be here on the continent again so soon.

    Seam 3 Context Dependency Injection

    http://devoxx.com/display/Devoxx2K10/Dan+Allen

    Monday started for me with the SEAM 3 CDI technical session. Personally I have been less interested in SEAM for a while, because there are other technologies and solutions in this space. SEAM is great for integrated JavaServer Faces and EJB (as in 3.0/3.1 and JPA entities) . It was Gavin King’s originally design baby to solve the conservational scope and the page flows issues, which were prevalent in 2005-2007.  Not to bemoan CDI by any stretch of the imagination, the tech is still relevant to those who marry dependency injection and portability and frameworks. However I wonder about the CDI relevance to other alternative JVM languages like Groovy or Scala.

    That said I liked the ability to extend CDI with SEAM modules, and idea of type safe configuration of beans (managed beans).  How is this appropriate to JavaFX 2.0? Could this be a solution? So I skipped out during a tea break and found Neal Ford’s session.

    Devoxx 2010

    The Productive Programmer

    http://devoxx.com/display/Devoxx2K10/Productive+Programmer

    Oh my sweet  funkiness, was Neal Ford on a good form? Was he good? He was great. How about this for a bullet quote:

    If you must ever do anything in computing worthwhile. prefer to work like a craftman, not a labourer

    Or this one

    Always use a real language for scripting

    The former quote related to the part where Ford discussing Selenium IDE, automating web UI testing and the latter pertained to automating Microsoft COM using Ruby!

    Actually, I had wished that went Neal Ford entire session for the whole morning, especially for this snippet of gold dust:

    Top Ten Corporate Smells

    (Here Neal Ford’s smells means corporate mistakes or suspicious activities that make a consultant or contractor think twice before agreeing to work on project with that particular corporation)

    10. We invested our web/persistence/messaging/caching framework because none of the existing ones was good enough (an averice of dot Net companies where there lack of open source tradition)
    9. We bought the entire tool suite (even though we needed about 10% of it) because it was cheaper than buying the individual tools
    8. We use WebSphere because … (He always stops listening at this point)
    7. We can’t use any open source code because our laywers say we can’t
    6. We have an architect who reviews all code precheckin and decides whether or not to allow it into version control
    5. The only JavaDoc is the Eclipse message explain how to change default JavaDoc template
    4. We keep all of our business logic in stored procedure … for performance reasons (premature optimisation already in up front architect)
    3. We don’t have time to write unit tests (we’re spending time doing debugging)
    2. The initial estimate must be within 15% of the final cost, the post-analysis estimate must be within 10% and the post-design estimate must be within 5% (A lot of company desparately try to
    1. There is a reason that WSAD isn’t called WHAPPY (IBM Websphere derived Eclipse environment that is always several version behind the current Eclipse and crippled by blot)

    Actually, this list of corporate smells, which a small sub section of Neil Ford’s larger presentation: 10 ways to improve your code. The main take away was not get involved in business who practice these corporate fails knowingly or unknowingly.

    Groovy Update Ecosystem with Guillaime LaForge

    http://devoxx.com/display/Devoxx2K10/Groovy+update%2C+ecosystem%2C+and+skyrocketing+to+the+cloud+with+App+Engine+and+Gaelyk!

    Let me just say simply, Guillaime Laforge is the Groovy Project Manager and now is the “Groovy man”. If you have an question about Groovy then Laforge can probably answer it well enough. This university talk was an overview and update of Groovy starting from version 1.6. Of interest to me was the ideas of AST Transformations, abstract syntax tree manipulations, which mean developers can write annotation that modify the meaning of Groovy code as it is compiled. The fruits of this labours are @Singleton, @Immutable, @Delegate, @Lazy, @Newify, @Mixin and of course @Grab.

    Devoxx 2010

    Groovy has support dynamic mixins.

    Groovy has a DSL for handling JMX.

    Groovy 1.7 brings the AST Viewer/AST Builder and anonymous inner classes and nested classes. With the latter you can bring more Java code now into Groovy directly. Groovy 1.7 brings the customisable GrabResolver.

    Groovy 1.8 will improve currying so that curry from left associativy or the right associativy,  rcurry() and ncurry() calls respectively.

    Groovy 1.8 will add Closure annotation parameters, functional composition, memoisation and trampolining, native JSON improvements, Gradle build and earlier modularisation and alignment with JDK 7 / Project Coin.

    If you have an interest in DSL implementations, then Groovy 1.8 will add Command Expressions. This is a feature that is impossible to do in Scala at the moment, and Groovy will have a nice syntax for DSLs

    send("Hello").to("Grame Rocher")
    sell(100l.shares).of(MFST)
    take(2.pills).of(chloroquinone).after(6.hours)

    With command expression expansion becomes:

    send  "Hello" to "Grame Rocher"
    sell  100l.shares  of MFST
    take 2.pills of chloroquinone  after 6.hours

    Wow! These were examples of {verb} followed by a {noun} DSLs! (Why can we not do this well in Scala?)

    LaForge covered a lot of Groovy projects in a brief overview and the ecosystem for Groovy is rather rich now.

    • GContracts – André Steingress idea of writing invariant specifications using closures and annotations
    • GPars – parallelisation of Groovy collections, which relies on JSR 166y the concurrent fork join framework created by Doug Lea
    • Griffon – is a Grails like application framework for developing desktop applications in Groovy applications in the style of Grails application (convention over configuration)
    • EasyB – behaviour driven development framework that is similar to RSpec in Ruby
    • Spock – powerful mocking framework and also specification framework with fluent interfaces
    • GMock – another mocking framework and library for Groovy
    • GAELYK - Laforge’s own pet project for running Groovy inside the cloud, namely the Google App Engine

    I am very intrigued by Google App Engine and GAELYK, because it may be way to generate Groovy web content sites very efficiently. WIth GAELYK there is lot of Groovy styled DSL implemented to wrap around the App Engine standard services. For instance a DSL wraps the XMPP, Images, User, TaskQueues, URL Fetcher, Memcache, Blob store and of course the key value based Data store. Therefroe it looks to my eyes very easy to write a GAELYK application. The issue here one has to write Groovy Server Pages and break up HTML design into template defintions yourself.

    Here is the Groovy sample code for using Memcache DSL

    class Country implements Serializable { String name }
    def countryFr = new Country( name: France )
    memcache['FR'] = countryFr // store inside memcache
    
    // Check memcache for the key and if it is there do some work
    if ( 'FR' in memcache ) {
         def countryFromCache = memcache['FR']
         doWork( countryFromCache )
    }

    In summary, the Groovy ecosystem talk was very impressive and to my mind showed the strength of Groovy and the users who are actively involved in it.

    Overall, it was a very entertaining day at the Devoxx races.

    This is Peter Pilgrim at the Devoxx 2010. Out.

    http://www.flickr.com/photos/8268882@N06/5187049930/in/photostream/

    Categories: Devoxx, Groovy, Java Tags:

    JavaOne 2010: Day 5, Writing Domain Specific Languages using Groovy

    October 27th, 2010 Comments off

    Hello

    Here is another video recording from the JavaOne 2010 Conference. Althought the conference was not quite the worldwide developer event that we used to love, especially in years gone by, under the auspices of Sun Microsystems, the new stewards of Java, Oracle,  did have great technical speakers. This video recording was one of the best of those extraordinary highlights. One of which was Paul King‘s excellent talk on Writing Domain Specific Language using Groovy, and it was the last technical session of the conference. Many people have already said before, sometimes the best technical sessions take place on the last day of the conference, and those people who left early missed a treat.

    Enjoy. ;-)

    PS: Next Easter comes earlier near the end of the recording.

    Categories: Groovy, Java Tags: