Agile Zone is brought to you in partnership with:
DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
  • submit to reddit
Tom Howlett10/16/14
12664 views
7 replies

Interviewing Programmers: Start with Code

For me recruiting a programmer has to start with code. I don’t really care about the CV and the application process for this job involved a quick coding problem.

Johanna Rothman10/16/14
3262 views
0 replies

Large Program? Release More Often

Look, the more people and teams on your program, the more feedback you need. The more chances you have for getting stuck, being in the death spiral of slowing inertia. What you want is to gain momentum.

Rob Allen10/16/14
5160 views
1 replies

Context-specific history at the bash prompt

These two bind command change the way that the up and down arrow keys work once you start typing a command to only search the history for lines that start with what you've typed so far. It's quite handy and I find it easier to use than ctrl+r.

Kin Lane10/16/14
3023 views
2 replies

I Am Not Signing Any More NDAs

I just replied to a company who I really like, and trust, letting them know I won’t be signing any more NDAs. There are plenty of companies that I can exchange knowledge, research, data, and other vital information without signing NDAs.

Venkatesh Kris...10/16/14
4845 views
0 replies

If you are start-up, think beyond one user!

It's extraordinarily difficult to take a product that was built perfectly for a particular user and commercialize that into a broader market.

Dele Sikuade10/16/14
2179 views
0 replies

The Single Most Important Thing in Agile

Agile is a methodology that was formed to bridge the gap between abstract requirement and real-world want. It implicitly acknowledges the existence of the gap by requiring the business to participate and therefore to be complicit in the process of development and delivery. It is the best methodology I have ever seen for overcoming this problem and this problem is the single biggest cause of pain in software development.

Mike Bushong10/16/14
3033 views
0 replies

On choice-supportive bias and the need for paranoid optimism

Companies are not blind because the individuals are not talented; they are blind because there are powerful psychological dynamics at play that keep us all from seeing that which we must see the most.

//Insert a Document at Any Location
/**
 * Inserts content of the external document after the specified node.
 * Section breaks and section formatting of the inserted document are ignored.
 *
 * @param insertAfterNode Node in the destination document after which the content
 * should be inserted. This node should be a block level node (paragraph or table).
 * @param srcDoc The document to insert.
 */
public static void insertDocument(Node insertAfterNode, Document srcDoc) throws Exception
{
    // Make sure that the node is either a paragraph or table.
    if ((insertAfterNode.getNodeType() != NodeType.PARAGRAPH) &
      (insertAfterNode.getNodeType() != NodeType.TABLE))
        throw new IllegalArgumentException("The destination node should be either a paragraph or table.");

    // We will be inserting into the parent of the destination paragraph.
    CompositeNode dstStory = insertAfterNode.getParentNode();

    // This object will be translating styles and lists during the import.
    NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.getDocument(), ImportFormatMode.KEEP_SOURCE_FORMATTING);

    // Loop through all sections in the source document.
    for (Section srcSection : srcDoc.getSections())
    {
        // Loop through all block level nodes (paragraphs and tables) in the body of the section.
        for (Node srcNode : (Iterable<Node>) srcSection.getBody())
        {
            // Let's skip the node if it is a last empty paragraph in a section.
            if (srcNode.getNodeType() == (NodeType.PARAGRAPH))
            {
                Paragraph para = (Paragraph)srcNode;
                if (para.isEndOfSection() && !para.hasChildNodes())
                    continue;
            }

            // This creates a clone of the node, suitable for insertion into the destination document.
            Node newNode = importer.importNode(srcNode, true);

            // Insert new node after the reference node.
            dstStory.insertAfter(newNode, insertAfterNode);
            insertAfterNode = newNode;
        }
    }
}

//Insert a Document During Mail Merge

//This example relies on the InsertDocument method shown at the beginning of the article to insert a document into a merge field during mail merge execution. This code demonstrates how to use the InsertDocument method to insert a document into a merge field during mail merge.

public void insertDocumentAtMailMerge() throws Exception
{
    // Open the main document.
    Document mainDoc = new Document(getMyDir() + "InsertDocument1.doc");

    // Add a handler to MergeField event
    mainDoc.getMailMerge().setFieldMergingCallback(new InsertDocumentAtMailMergeHandler());

    // The main document has a merge field in it called "Document_1".
    // The corresponding data for this field contains fully qualified path to the document
    // that should be inserted to this field.
    mainDoc.getMailMerge().execute(
        new String[] { "Document_1" },
        new String[] { getMyDir() + "InsertDocument2.doc" });

    mainDoc.save(getMyDir() + "InsertDocumentAtMailMerge Out.doc");
}

private class InsertDocumentAtMailMergeHandler implements IFieldMergingCallback
{
    /**
     * This handler makes special processing for the "Document_1" field.
     * The field value contains the path to load the document.
     * We load the document and insert it into the current merge field.
     */
    public void fieldMerging(FieldMergingArgs e) throws Exception
    {
        if ("Document_1".equals(e.getDocumentFieldName()))
        {
            // Use document builder to navigate to the merge field with the specified name.
            DocumentBuilder builder = new DocumentBuilder(e.getDocument());
            builder.moveToMergeField(e.getDocumentFieldName());

            // The name of the document to load and insert is stored in the field value.
            Document subDoc = new Document((String)e.getFieldValue());

            // Insert the document.
            insertDocument(builder.getCurrentParagraph(), subDoc);

            // The paragraph that contained the merge field might be empty now and you probably want to delete it.
            if (!builder.getCurrentParagraph().hasChildNodes())
                builder.getCurrentParagraph().remove();

            // Indicate to the mail merge engine that we have inserted what we wanted.
            e.setText(null);
        }
    }

    public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception
    {
        // Do nothing.
    }
}
 
//If a document to be inserted is stored as binary data in the database field (BLOB field), use the following example. A slight variation to the above example to load a document from a BLOB database field instead of a file.

private class InsertDocumentAtMailMergeBlobHandler implements IFieldMergingCallback
{
    /**
     * This handler makes special processing for the "Document_1" field.
     * The field value contains the path to load the document.
     * We load the document and insert it into the current merge field.
     */
    public void fieldMerging(FieldMergingArgs e) throws Exception
    {
        if ("Document_1".equals(e.getDocumentFieldName()))
        {
            // Use document builder to navigate to the merge field with the specified name.
            DocumentBuilder builder = new DocumentBuilder(e.getDocument());
            builder.moveToMergeField(e.getDocumentFieldName());

            // Load the document from the blob field.
            ByteArrayInputStream inStream = new ByteArrayInputStream((byte[])e.getFieldValue());
            Document subDoc = new Document(inStream);
            inStream.close();

            // Insert the document.
            insertDocument(builder.getCurrentParagraph(), subDoc);

            // The paragraph that contained the merge field might be empty now and you probably want to delete it.
            if (!builder.getCurrentParagraph().hasChildNodes())
                builder.getCurrentParagraph().remove();

            // Indicate to the mail merge engine that we have inserted what we wanted.
            e.setText(null);
        }
    }
public void imageFieldMerging(ImageFieldMergingArgs args) throws Exception
    {
        // Do nothing.
    }
}

//Insert a Document During Replace

//This example shows how to insert content of one document into another during a customized find and replace operation.

[Code Sample]

public void insertDocumentAtReplace() throws Exception
{
    Document mainDoc = new Document(getMyDir() + "InsertDocument1.doc");
    mainDoc.getRange().replace(Pattern.compile("\\[MY_DOCUMENT\\]"), new InsertDocumentAtReplaceHandler(), false);
    mainDoc.save(getMyDir() + "InsertDocumentAtReplace Out.doc");
}

private class InsertDocumentAtReplaceHandler implements IReplacingCallback
{
    public int replacing(ReplacingArgs e) throws Exception
    {
        Document subDoc = new Document(getMyDir() + "InsertDocument2.doc");

        // Insert a document after the paragraph, containing the match text.
        Paragraph para = (Paragraph)e.getMatchNode().getParentNode();
        insertDocument(para, subDoc);

        // Remove the paragraph with the match text.
        para.remove();

        return ReplaceAction.SKIP;
    }
}
Alec Noller10/15/14
9941 views
1 replies

Dev of the Week: Ashwini Kuntamukkala

Every week here and in our newsletter, we feature a new developer/blogger from the DZone community to catch up and find out what he or she is working on now and what's coming next. This week we're talking to Ashwini Kuntamukkala, Software Architect at SciSpike, Inc.

John Walter10/15/14
12501 views
0 replies

The Best of DZone: Oct. 8 - Oct. 15

If you missed anything on DZone this week, now's your chance to catch up! This week's best include a tutorial for getting started building mobile apps with the Ionic framework, an editorial detailing how developers are integrating, an attempt at linear regression, and more.

Adam Diaz10/15/14
6230 views
0 replies

Hadoop and the mystery of the version number

When I’m working with people on Hadoop I ask what you would think is a simple question. What version of Hadoop are you using? In reality though it’s not as straight forward as you might think.

Peter Lawrey10/15/14
5328 views
0 replies

Kafka Benchmark on Chronicle Queue

I was recently asked to compare the performance of Kafka with Chronicle Queue. No two products are exactly alike, and performing a fair comparison is not easy. We can try to run similar tests and see what results we get.

Mikio Braun10/14/14
3411 views
0 replies

Parts But No Car

One question which pops up again and again when I talk about streamdrill is whether that cannot be done by X, where X is one of Hadoop, Spark, Go, or some other piece of Big Data infrastructure. The truth is that there’s a huge gap between “in principle” and “in reality”, and I’d like to spell this difference out in this post.

Mike Cottmeyer10/14/14
6530 views
0 replies

Teams 102

In this post, I want to go just a little deeper on the notion of teams and challenge some of the common thinking around agile and agile transformation.

Johanna Rothman10/14/14
5539 views
2 replies

Management Feedback: Are You Abrasive or Assertive?

We all need feedback. Managers need feedback, too. Because managers leverage the work of others, they need feedback even more than technical people.

Andrew Gilmartin10/13/14
5051 views
0 replies

An Observer pattern implementation and illiterate programming

The Observer pattern and an experiment in documenting Java code using "illiterate programming."

Pubudu Dissanayake10/13/14
3001 views
0 replies

How to draw a Control flow graph & Cyclometric complexity for a given procedure

Cyclomatic complexity is a software metric used to measure the complexity of a program. This metric measures independent paths through the program's source code.

Tim Murphy10/12/14
7628 views
3 replies

Teaching Old Dogs New Tricks

Old developers can easily get set in their ways especially if they work in one environment for a dozen years or more. So how do you overcome the “that is the way it has always been done” mentality that sets in?

Mike Cottmeyer10/11/14
7280 views
0 replies

Teams 101

The notion of forming complete cross functional teams is one of the most well understood concepts in the agile community but maybe one of the least implemented in practice.

Arthur Charpentier10/11/14
3104 views
0 replies

Cross Validation for Kernel Density Estimation

In a post published in July, I mentioned the so-called Goldilocks principle, in the context of kernel density estimation, and bandwidth selection. The bandwidth should not be too small (the variance would be too large) and it should not be too large (the bias would be too large).