Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Human Talks: N'ayez pas peur de faire du Groovy

Human Talks: N'ayez pas peur de faire du Groovy

Slides du lightning talk donné à HumanTalks Nantes.

F929f5d80ef8a23b67ad8ac6f08416cd?s=128

Cédric Champeau

November 18, 2014
Tweet

More Decks by Cédric Champeau

Other Decks in Programming

Transcript

  1. N'ayez pas peur de faire du @CedricChampeau

  2. Made in Nantes

  3. Scripting

  4. log.message "Releasing Groovy $version with user: $user" def desc =

    "Release of $version" def date = new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ") def remoteCall = { String url, List params, Closure onFailure -> def p = ['curl', "-m", "3600", "-u", "$user:$key", *params, url].execute() int code = p.waitFor() def resp = p.text log.message "${resp}" if (code!=0 || resp.toLowerCase().contains('error') ) { onFailure(code) System.exit(code) } }
  5. DSLs

  6. remoteSession { scp { from { localDir "$buildDir/application " }

    into { remoteDir '/usr/local/myapp' } timeout 10.minutes } }
  7. Java friendly

  8. @Immutable @ToString class Person { String name int age String

    greet(String them) { "Hello $them, my name is $name" } }
  9. Dynamic

  10. @ToString class Person { String name int age } def

    storage = [new Person(name:'Cédric', age:35), new Person(name:'Hugues', age:44)] Person.metaClass.static.methodMissing = { String name, args -> if (name.startsWith('findBy')) { String prop = (name - 'findBy').toLowerCase() storage.findAll { it."$prop" == args[0]} } } println Person.findByAge(35)
  11. Static

  12. @ToString class Person { String name int age } @CompileStatic

    void erreurDeCompil() { println Person.findByAge(35) }
  13. Functional

  14. new URL('http://beta.groovy-lang.org').text .split(' ') .findAll { it == 'Groovy' }

    .size()
  15. Microservices?

  16. @Grab('com.h2database:h2:1.3.179') import grails.persistence.* @Entity @Resource(uri='books') class Book { String title

    }
  17. Builds

  18. apply plugin: 'groovy' repositories { jcenter() } dependencies { compile

    'org.codehaus.groovy:groovy:2.3.4-beta-3' }
  19. Android

  20. notify(NOTIFICATION_ID) { smallIcon = R.drawable.ic_action_alarms largeIcon = cachedBitmap contentTitle =

    'Time left' contentText = "$timeLeft (Elapsed: ${rounded}%)" contentIntent = pendingActivityIntent(0, intent(WearPresentationActivity), FLAG_UPDATE_CURRENT) ongoing = true style = bigTextStyle { bigText """Time left for your presentation: $timeLeft Elapsed time: ${rounded}%) """ } }
  21. Templating

  22. layout 'layouts/main.groovy', true, pageTitle: 'The Groovy programming language - Mailing-lists',

    mainContent: contents { div(id: 'content', class: 'page-1') { div(class: 'row') { div(class: 'row-fluid') { div(class: 'col-lg-3') { include template: 'includes/community-navbar.groovy' } div(class: 'col-lg-8 col-lg-pull-0') { include template: 'includes/contribute-button.groovy' h1 { i(class: 'fa fa-envelope-o') {} yield ' Mailing-lists' } ...
  23. Et tant d'autres...

  24. None
  25. Merci ! @CedricChampeau