New IntelliJ Tricks I Learnt Today

Day three of my brand new job - woohoo! One of my first tasks is checking the documentation of IntelliJ, since I’m already a “Power User”, to see if there’s stuff missing that someone like me might want to see. Firstly, a confession - I’m not sure I’ve actually read the IntelliJ documentation before. I mean, really read it. Of course, I’ve dipped into it when I needed to know something, I’ve searched for help with specific items, but like many developers, I tend to use something first rather than read the documentation first.

But I’ll tell you what, today I’ve learnt a whole bunch of useful things IntelliJ can do that I hadn’t previously known, and they’re the sorts of things you would only stumble over if a) you read the docs (pah!) or b) you watched someone else using the tool and saw them doing something you didn’t know was possible.

So here’s today’s list, and feel free to laugh at me and be smug in my direction if you already knew these things (note: I have upgraded to IntelliJ 14, and at the time of writing I don’t know which of these features are new and which are simply previously undiscovered):

Press Shift+Ctrl+A (Windows) or Shift+Cmd+A (Mac) and start typing the name of the thing you want to do, or the setting you want to change. I’ve found this especially useful now I’m back on Windows and I don’t have that nice helpful typing box on the help menu that will take me straight to the menu item I want. But what’s most useful about this for me today, as I’m setting up a new profile on a new laptop (more on the new laptop later, if it doesn’t defeat me utterly) is that from here, you can turn various settings on and off without having to navigate through the settings screen:

![](https://trishagee.com/wp-content/uploads/2015/01/action-300x226.png)

Statement completion

I never knew there was a shortcut for finishing off a statement, all that Java boilerplate you need to keep the compiler happy - semi colons and curly brackets and everything. But there is, and I can see it being super useful, especially if you’re using other bits of IntelliJ code completion to create the core of your line of code.

Issue tracker integration

I’m sure loads of people are already using integration with their favourite issue tracker, but I hadn’t really thought about this as something that I really cared about. But I was watching the intro videos for YouTrack (not surprisingly I’ll be using this instead of Jira during my time at JetBrains) and when I saw how the IDE integration worked, I suddenly realised how this small thing can add up to save thousands of keystrokes over time, not to mention saving precious navigational seconds and window-switching.

For me, just the ability to generate at least the start of the commit message is a saving in time, and adds to project consistency if all your developers are doing the same thing. On my last project we only just realised we all quoted the Jira issues in subtly different ways.

Settings shortcut keys

When I initially started using IntelliJ in anger back in 2008, I was very much a point-and-click type user. Over time, pair programming with keyboard-super-users and giving live demos with very limited time available, I’ve worked harder to become a keyboard-shortcuts person. With the latest version of IntelliJ, I can’t find the tiny icons I use to get to the settings window, something that I’ve been using a lot as I set up the new IDE instance on the new laptop. So I bit the bullet and learnt the keyboard shortcuts, and it’s already saving me a bunch of time (on the rare occasions when the aforementioned “Navigate to Action” fails me).

Ctrl+Alt+S for the settings dialog (appears to be Cmd + , on the Mac) Shift+Ctrl+Alt+S for the project structure dialog (appears to be Cmd + ; on the Mac)

![Settings](https://trishagee.com/wp-content/uploads/2015/01/settings-300x55.png)

Yeah. I can’t believe I wasn’t already using those either.

Selecting the negative

I use completion/suggestions all the time from IntelliJ, I’m far too lazy to type everything. What I didn’t realise, is that you don’t just have to accept the default they give you. If, for example, IntelliJ suggests a boolean value, you can get it to negate that value by selecting it with “!” instead of enter or tab. Yes, I know I’ve done a horrible job of explaining that, but take a look at the documentation and try it, it’s quite cool.

Exclude from Autocomplete

Speaking of code completion, sometimes IntelliJ is sometimes just a bit too keen to suggest something, and you really will never want that value. In the past, I’ve always used Settings -> Editor -> General -> Auto Import to manage the suggestions (the most common one for me is I will never want java.awt.List, I will almost always want java.util.List). Well, you don’t have to go into settings to do this, you can do it from the suggestions themselves - navigate to the item you don’t want (in my case, java.awt.List) and press Alt+Enter, this will give you the option of excluding this from the suggestions in the future.

That’s what I found from just one day of browsing the documentation and setting up my IDE from scratch yet again. Maybe I’ll promptly forget all these, or maybe they’ll be new weapons in my armoury of IDE-fu. Either way, maybe one or two people will find this useful.

New Year, New Adventures

Just over two years ago, I embarked upon a journey as a developer / evangelist for a company who was then called 10gen (who got fed up of saying "the MongoDB people", and transformed into MongoDB Inc). My goals for this role were: to learn what it was like working for a company that produced a technology product; to discover what impact working in an open source fashion has; and to level up my advocacy skills. I have met all these goals, and more - I met some fantastic people; learnt different approaches to software development; discovered my new favourite database for creating applications; moved to Spain; started both a MUG and a JUG; worked to understand the value of community and evangelism, and to help create a strategy for these areas; and my evangelism efforts and open source work earned me the Java Champion title. I'm extremely proud of what I've achieved over this period, and very grateful to MongoDB for giving me these opportunities.

But now, a new adventure is about to begin. If you've seen my live coding demo this year, you'll know of my love affair with IntelliJ IDEA, a tool I use daily (even for blogging). Well, now I'm joining the team at JetBrains, where I'm going Full Advocate. I hope this means I get to carry on doing more of what I love - presenting, writing, and working on demos to help developers become more productive. I hope this will give me opportunities to stay ahead of the curve in the Java/JVM world.

And yes, in answer to the Most Frequently Asked Question, I am staying in Spain. I've fallen in love with Sevilla and I'm not ready to leave yet.

I shall leave you with my somewhat disasterous "Top Ten IntelliJ Tips" from GOTO Aarhus, which is worth watching just to see Dan North save me from the curse of the live demo. Things can only get better from here, right?

Improving Speaker Diversity

Last month at Devoxx I was in a session discussing what we can do to encourage more diversity in our speakers (specifically, although not limited to, increasing the number of women speakers).

I’m going to outline the things I remember being discussed, although as usual we did not find the answer to the problem, only identify some issues and explore some options.

This is a very chaotic blog post, because if I don’t post it now I’ll never post it, and it’s better if my thoughts are scrawled down and posted than if this all goes to die in my drafts folder.

Firstly, what stops people from stepping up to speak?

I don’t have anything to say
This is the very first thing any developer says when you ask them why they haven’t thought about presenting at conferences or user groups. Turns out, you always have something to say. For example, our most popular sessions at the Sevilla JUG and MUG are “Introduction to…". You hear from plenty of experts who have travelled the whole road to some pinnacle of excellence, but what many developers need is simply someone a couple of steps ahead of them to lead them forwards.

You always know more than someone, you don’t need to know everything, and you don’t need to know more than everyone

Why should I be role model?
So many women feel this, and I’m completely sympathetic to this view point: I’m a woman developer, getting along, happy in my job, happy being a programmer, why the hell should I have to stand up and present and blog and be a role model for other women? Men don’t have to do that. Men can just be developers.

In addition, there’s the fear that if you do stand up, become a role model, that somehow people will think you’re representing all women developers. You’ll be worried because you can only represent who you are, what you do, you can’t represent a whole gender in a single presentation or a single interview. And the pressure! What if I mess up? What if I say something my gender does not agree with? What if I say something that causes my whole gender to be judged?

Totally understandable fears. Totally true that many people will ask you to be the woman developer, to answer for all women. Well, that’s why I’m asking more women to stand up, to be role models - if we all step up, it will no longer just be me, and you, and that other one over there. There’ll be more of us, more differing voices, we’ll stand out less. But we have to stand up first. And in the meantime it’s us and our points of view they’re listening to. Wouldn’t you rather voice your opinion than have someone else speak on your behalf? Especially when very few people really can represent you, who you are and what you want.

What if I can’t answer the questions?
You’ll be surprised at what you do know, so people who present run into this less than you’d think, even if you’re just beginning, but just in case here are some tips:

  • Repeat the question, paraphrasing. Firstly, this ensures you’ve actually heard the question correctly. Secondly, it allows the whole audience to hear it, and thirdly, but most importantly, it buys you time to think.
  • Be honest - say you don’t know, and move on. If you know somewhere that might have the answer, point the person to that resource. But a technical audience actually values the answer “I don’t know” more than you think. Especially the person who asked the question, it makes them feel really smart!
  • If you don’t know, but you think the audience might know, throw it back to them. Either to the person who asked the question, if that feels appropriate (especially if this is one of those “look how smart I am” questions), or to the audience as a whole. In conferences in particular, there’s a good chance someone there knows the answer.
  • If you’re genuinely terrified of all questions, say at the start of the presentation that you won’t take questions in the talk. Offer an alternative, like via Twitter or e-mail, if you can.

What can conference organisers do?

Specifically invite the people you want presenting
Don’t just wait for them to submit. If you want more women, more diversity, invite them. And invite them early…

Secure your women presenters early.
Recognise that there are relatively few women presenters on “the circuit”, and understand that everyone wants them to speak at their conference. This rare breed, the female technical presenter, gets booked up well in advance. They’re probably as in-demand as your keynote speakers, and can probably devote less time to appearing at conferences than those who have made it to keynote-standard (I’m making a sweeping generalisation that your techy women have day-jobs as developers and your keynote speakers are either professional presenters or at least can argue presenting as a critical part of their job).

So, you have a limited resource (experienced women presenters) that’s in high demand. You need to reach out directly to them, invite them, and secure them well in advance of your conference. Many big conferences, for example JavaOne and QCon, will invite speakers six months in advance. If you give women speakers a month’s notice before your conference or event, they simply are not going to have the space in their schedule at that late notice.

Showcase your diversity on your website
If you haven’t already heard of microaggressions, go and read what that means before you get any further. There’s a very simple thing you need to do with your website, whether you’ve opened for CFP or you’re trying to get attendees to register - make sure the photos on your website show the type of diversity you want to encourage. Only yesterday I was looking at the website of a big conference, who I know for a fact are working really hard to ensure diversity, not just with gender but race, age, and where possible in less physically obvious dimensions. The conference is many months off, so the only photo they have on the website is a background photo of the exhibition hall from some previous year, crammed full of attendees - white, male attendees, as far as it’s possible to tell. It’s extremely subtle. You might not even notice, as the photo is behind the headers and text of the site. But I noticed. And you can be sure the subconscious of every person who went to the website to either submit a proposal for a talk, or is considering asking their employer to pay for the registration, also noticed. The conscious mind might be able to shrug it off. But the subconscious of a non-white and/or non-male person notices and plants the subtle seed of “this conference is not for me”.

So, conference and event organisers - if you want more women applying to speak at your conference, show more women on your website. If you want a more diverse audience, show more diverse faces. If you’ve invited your women presenters early and secured them early, show their photos on the site - this sends a strong message to other women that their talk proposals will be taken seriously.

Run warm up nights to try out new speakers
I know conference organisers get lots of submissions, and I know it’s hard to tell which are going to be good speakers, especially if they’re new speakers or don’t have a video. If you’re genuine about improving the diversity of your speakers, run free nights to a) promote your conference and b) try out new speakers. Probably a good idea to have a new speaker and a known speaker to attract the crowd and give newbies a chance.

Don’t be so damn picky

  • New speakers need to be encouraged. Find a way to see their content without just discarding an unknown name.
  • Existing speakers might not have the luxury of creating new content. Many conferences want genuine practitioners, not just evangelists, but those people have day jobs and can’t be creating a new talk just for your conference.

Leave space for new speakers
…and don’t just have 7 slots for a pro speaker

Look at your swag
Not just guys t-shirts. One conference gave out cupcakes for example. But it doesn’t just have to be handbags and high-heeled shoes, just take a quick look and see if your swag is generally useful for techies, or if it leans towards men only. Men only swag (men’s t-shirts, bottle openers, subtle things like that) subliminally says “you don’t belong here” to the women.

Give feedback
You can’t tell every individual why they were rejected, but you could look at all the rejected submissions and give broad indications of the type of CFPs that didn’t make it. Maybe write a blog post explaining which sorts of talks didn’t make it and why. This will help speakers create content that better fits your conference.

Be specific about what you’re looking for
If you have tracks you’re finding content for, put them on the website/CFP, so people know what the topics are. If you have an idea that you want 30% beginner material and 30% very advanced, make that clear too. Especially if you want only beginner or only advanced. People will submit more appropriate talks.

Have a beginner’s track
…not just for the speakers, for the content too. Beginner speakers may be more comfortable presenting “Introduction to…” talks.
Having a beginners track, whether it’s for content or speakers, will make newbies feel more included.

What other things can we try?

User groups can grow talent

  • Practice writing CFPs
  • Help each other
  • Presentation skills
  • Lightning talks, book club, different meetup styles (like fishbowl)
  • Run an open conference to encourage new speakers

Women’s user groups are instrumental
So here’s something interesting. I’m sceptical of all-women user groups as I feel it separates us from the communities we should be contributing to. But women’s user groups can help us to integrate better. For example, Duchess France helped and encouraged its members to submit talks to Devoxx, gave feedback on CFPs before they were submitted, and provided a safe place for the women to practice presenting beforehand. I think this is exactly the sort of thing women’s user groups could be fantastic for.

Advice for budding speakers

  • Just Do It
  • The more you do it, the more comfortable you’ll be
  • If you’re a speaker, it can make you feel less of an impostor at a conference - you’re not just a woman developer, you’re a speaker!
  • Everyone’s afraid, it’s not just you
  • Every developer wants to learn
  • The audience is on your side
  • Start Small (user groups)
  • Be technical. But you don’t have to be super smart
  • Bootstrapping is hard - you haven’t presented so you can’t get into conferences. Again, user groups can help with this.
  • Pair. Ask a more experienced presenter if you can co-present with them.
  • Ask for mentors
  • Ask for feedback
  • “I don’t know” is perfectly acceptable.

I appreciate there is so much more I could have covered, and many topics deserve more depth. But this is the brain dump from the Devoxx session, and maybe one day things will be expanded into their own topics.

MongoDB London

<em>TL;DR MongoDB London, 6th November, 50% off with discount code 50Trisha.

So, MongoDB London is nearly upon us again, and I’m dead disappointed I can’t make it this year (I’m [keynoting at GOTO Berlin] (http://gotocon.com/berlin-2014/presentation/Party%20Keynote:%20Staying%20Ahead%20of%20the%20Curve) instead, which I’m terrified, I mean, excited, about). The last MongoDB London was really interesting for me - I was fairly new to the company, I’d been here less than six months, and it was a really great way to go both broad and deep on the technology.

I was trying to find a blog post where I talked about my experiences, but it looks like I only wrote that In My Mind. In fact, I only only wrote two whole lines of notes on the conference. But 18 months later I clearly remember presentations from my colleagues Ross and Derick demonstrating the geo capabilities in MongoDB, presentations which heavily influenced the live coding demo I’ve been giving recently.

I also remember Eliot’s presentation - Eliot is one of those people who totally gets away with breaking the “speak in a measured, clear fashion” presenters rule, he fires fascinating information at you at high speed and it’s actually one of the compelling things about his talks. If you ever get a chance to see him talk about the product, it’s totally worth it.

Other than that, the most awesome thing about the conference was the chance to meet, and talk to, a bunch of different MongoDB people - there are the engineers who work on the product (like me and my colleagues); the people leading the way with the technology, like Eliot; and finally, but for me most importantly, you get to meet really interesting people who are using MongoDB in ways that you might not even imagine.

Anyway the point of this sales pitch is, whether you’re using MongoDB already or you’re keen to find out about it, MongoDB London is only going to take a day from your life, and you’ll learn a bunch of interesting things. And, with a Special Discount Code from me, it’s only £45! Sign up with code 50Trisha.

Using Groovy to import XML into MongoDB

This year I've been demonstrating how easy it is to create modern web apps using AngularJS, Java and MongoDB. I also use Groovy during this demo to do the sorts of things Groovy is really good at - writing descriptive tests, and creating scripts.

Due to the time pressures in the demo, I never really get a chance to go into the details of the script I use, so the aim of this long-overdue blog post is to go over this Groovy script in a bit more detail.

Firstly I want to clarify that this is not my original work - I stole borrowed most of the ideas for the demo from my colleague Ross Lawley. In this blog post he goes into detail of how he built up an application that finds the most popular pub names in the UK. There's a section in there where he talks about downloading the open street map data and using python to convert the XML into something more MongoDB-friendly - it's this process that I basically stole, re-worked for coffee shops, and re-wrote for the JVM.

I'm assuming if you've worked with Java for any period of time, there has come a moment where you needed to use it to parse XML. Since my demo is supposed to be all about how easy it is to work with Java, I did not want to do this. When I wrote the demo I wasn't really all that familiar with Groovy, but what I did know was that it has built in support for parsing and manipulating XML, which is exactly what I wanted to do. In addition, creating Maps (the data structures, not the geographical ones) with Groovy is really easy, and this is effectively what we need to insert into MongoDB.

Goal of the Script

  • Parse an XML file containing open street map data of all coffee shops.
  • Extract latitude and longitude XML attributes and transform into MongoDB GeoJSON.
  • Perform some basic validation on the coffee shop data from the XML.
  • Insert into MongoDB.
  • Make sure MongoDB knows this contains query-able geolocation data.

The script is PopulateDatabase.groovy, that link will take you to the version I presented at JavaOne:

PopulateDatabase.groovy

Firstly, we need data

I used the same service Ross used in his blog post to obtain the XML file containing "all" coffee shops around the world. Now, the open street map data is somewhat... raw and unstructured (which is why MongoDB is such a great tool for storing it), so I'm not sure I really have all the coffee shops, but I obtained enough data for an interesting demo using

http://www.overpass-api.de/api/xapi?*[amenity=cafe][cuisine=coffee_shop]

The resulting XML file is in the github project, but if you try this yourself you might (in fact, probably will) get different results.

Each XML record looks something like:

<node id="178821166" lat="40.4167226" lon="-3.7069112">
    <tag k="amenity" v="cafe"/>
    <tag k="cuisine" v="coffee_shop"/>
    <tag k="name" v="Chocolatería San Ginés"/>
    <tag k="wheelchair" v="limited"/>
    <tag k="wikipedia" v="es:Chocolatería San Ginés"/>
</node>

Each coffee shop has a unique identifier and a latitude and longitude as attributes of a node element. Within this node is a series of tag elements, all with k and v attributes. Each coffee shop has a varying number of these attributes, and they are not consistent from shop to shop (other than amenity and cuisine which we used to select this data).

Initialisation

Script Initialisation

Before doing anything else we want to prepare the database. The assumption of this script is that either the collection we want to store the coffee shops in is empty, or full of stale data. So we're going to use the MongoDB Java Driver to get the collection that we're interested in, and then drop it.

There's two interesting things to note here:

  • This Groovy script is simply using the basic Java driver. Groovy can talk quite happily to vanilla Java, it doesn't need to use a Groovy library. There are Groovy-specific libraries for talking to MongoDB (e.g. the MongoDB GORM Plugin), but the Java driver works perfectly well.
  • You don't need to create databases or collections (collections are a bit like tables, but less structured) explicitly in MongoDB. You simply use the database and collection you're interested in, and if it doesn't already exist, the server will create them for you.

In this example, we're just using the default constructor for the MongoClient, the class that represents the connection to the database server(s). This default is localhost:27017, which is where I happen to be running the database. However you can specify your own address and port - for more details on this see Getting Started With MongoDB and Java.

Turn the XML into something MongoDB-shaped

Parse & Transform XML

So next we're going to use Groovy's XmlSlurper to read the open street map XML data that we talked about earlier. To iterate over every node we use: xmlSlurper.node.each. For those of you who are new to Groovy or new to Java 8, you might notice this is using a closure to define the behaviour to apply for every "node" element in the XML.

Create GeoJSON

Create GeoJSON Since MongoDB documents are effectively just maps of key-value pairs, we're going to create a Map coffeeShop that contains the document structure that represents the coffee shop that we want to save into the database. Firstly, we initialise this map with the attributes of the node. Remember these attributes are something like:

<node id="18464077" lat="-33.8911183" lon="151.1958773">

We're going to save the ID as a value for a new field called openStreetMapId. We need to do something a bit more complicated with the latitude and longitude, since we need to store them as GeoJSON, which looks something like:

{ 'location' : { 'coordinates': [<longitude>, <latitude>],
                 'type'       : 'Point' } }

In lines 12-14 you can see that we create a Map that looks like the GeoJSON, pulling the lat and lon attributes into the appropriate places.

Insert Remaining Fields

Insert Remaining Fields

Validate Field Name

Now for every tag element in the XML, we get the k attribute and check if it's a valid field name for MongoDB (it won't let us insert fields with a dot in, and we don't want to override our carefully constructed location field). If so we simply add this key as the field and its the matching v attribute as the value into the map. This effectively copies the OpenStreetMap key/value data into key/value pairs in the MongoDB document so we don't lose any data, but we also don't do anything particularly interesting to transform it.

Save Into MongoDB

Save Into MongoDB

Finally, once we've created a simple coffeeShop Map representing the document we want to save into MongoDB, we insert it into MongoDB if the map has a field called name. We could have checked this when we were reading the XML and putting it into the map, but it's actually much easier just to use the pretty Groovy syntax to check for a key called name in coffeeShop.

When we want to insert the Map we need to turn this into a BasicDBObject, the Java Driver's document type, but this is easily done by calling the constructor that takes a Map. Alternatively, there's a Groovy syntax which would effectively do the same thing, which you might prefer:

collection.insert(coffeeShop as BasicDBObject)

Tell MongoDB that we want to perform Geo queries on this data

Add Geo Index

Because we're going to do a nearSphere query on this data, we need to add a "2dsphere" index on our location field. We created the location field as GeoJSON, so all we need to do is call createIndex for this field.

Conclusion

So that's it! Groovy is a nice tool for this sort of script-y thing - not only is it a scripting language, but its built-in support for XML, really nice Map syntax and support for closures makes it the perfect tool for iterating over XML data and transforming it into something that can be inserted into a MongoDB collection.

Getting Started with MongoDB and Java

We've been missing an introduction to using MongoDB from Java for a little while now - there's plenty of information in the documentation, but we were lacking a step-by-step guide to getting started as a Java developer.

I sought to rectify this with a couple of blog posts for the MongoDB official blog: the first, an introduction to using MongoDB from Java, including a non-comprehensive list of some of the libraries you can use; the second, an introductory guide to simple CRUD operations using the Java driver:

Continue reading "Getting Started with MongoDB and Java"

What could possibly go wrong? (GOTO Chicago)

At GOTO Chicago, I was given the chance to chat a bit about the presentation I was giving, which happens to be the same one I’m giving at a number of conferences this year (although of course I’m evolving it as I go along).

The presentation leaves very little time for anything other than coding, as it’s quite challenging to create a full app in 50 minutes, so it was great to have the chance to talk about the motivations for the demo

<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/sZee7lRAUF4&#34; style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video">

The video of the actual talk is also available now:

<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;"> <iframe src="https://www.youtube.com/embed/kmVnhyWqozA&#34; style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" allowfullscreen title="YouTube Video">

At the beginning it doesn’t clearly show the screen, but it does improve. You can see an earlier version from the Joy of Coding as well, so if something’s not clear on one of the videos, hopefully it’s better in the other.

The code for the Chicago version is on Github, and if you look through the history you can see how it builds up, the same as it does in the demo.