MongoDB: find duplicates in a field

Software Development 1 Comment »
m = function () {
    emit(this.my_field, 1);
}
r = function (k, vals) {
   return Array.sum(vals);
}
res = db.MyCollection.mapReduce(m,r, { out : "my_output" });
db[res.result].find({value: {$gt: 1}});

MongoDB: rename a field in all collections

Software Development No Comments »

I would like to share a script to rename all fields in a collection. It can be used to update field values, as well.

var collections = db.getCollectionNames()

collections.forEach(function(collectionName) {
	var collection = db.getCollection(collectionName)
	collection.update ( {}, { $rename : { "oldFieldName" : "newFieldName" }} );
});

AmazonSESSMTPAppender for Log4J

Software Development 1 Comment »

Log4J can easily send e-mail notifications   every time an error occurs. It is particularly interesting and a very powerful functionality for production environments. However,  the default SMTPAppender lacks support for SSL enabled SMTP servers and it is also not easily configurable according to the environment.

This is an enhanced version of the Original SMTPAppender, which supports SSL and is environment aware.

package com.dattein.logging;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import java.security.Security;
import java.util.Properties;

public class SMTPAppender extends org.apache.log4j.net.SMTPAppender {

    public SMTPAppender() {
        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    }

    @Override
    protected boolean checkEntryConditions() {
        //Obviously you have to use your own environment aware mechanisme, instead of the line below
        return Environment.isProduction();
    }

    @Override
    protected Session createSession() {
        Properties properties = new Properties();
        properties.setProperty("mail.transport.protocol", "smtp");
        properties.setProperty("mail.host", getSMTPHost());
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.port", getSMTPPort());
        properties.put("mail.smtp.socketFactory.port", getSMTPPort());
        properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        properties.put("mail.smtp.socketFactory.fallback", " false");
        properties.setProperty("mail.smtp.quitwait", " false");
        Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(getSMTPUsername(), getSMTPPassword());
            }
        });
        return session;
    }
}

That is how you use it:











        

        
    

    
        
        
    

If you are wondering how to activate the Amazon SES SMTP server, check this out:

https://console.aws.amazon.com/ses/home#smtp-settings:

(Portuguese BR) Visita ao Sydney Aquarium

Aquariums No Comments »

Installing mongodb with apt-get

Software Development No Comments »

sudo mkdir -p /etc/apt/sources.list.d/
sudo echo ‘deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen’ >/tmp/mongodb.list
sudo cp /tmp/mongodb.list /etc/apt/sources.list.d/
sudo rm /tmp/mongodb.list
sudo apt-key adv –keyserver keyserver.ubuntu.com –recv 7F0CEB10
sudo apt-get update
sudo apt-get install mongodb-10gen

Intellij not hot-deploying Grails application

Software Development No Comments »
Intellij IDEA 10.5 users might have noticed an annoying bug when running Grails applications, Controller classes are not reload, although Intellij says they have been recompiled.
This error is particular to IDEa 10.5.x and Grails 2.x.x and makes Grails development nearly as slow as Java development.
Fortunately, the solution is easy. Simply add the following configuration to the “VM Parameters” field of Grails Run/Debug:
-Xmx1024m
-Xms256m
-javaagent:/Users/franklin/java/grails-2.0.1/lib/com.springsource.springloaded/springloaded-core/jars/springloaded-core-1.0.2.jar
-server
-noverify
-Dspringloaded=profile=grails

The solution has been found here:

http://grails.1312388.n4.nabble.com/Grails-2-0-0-M1-Controller-reloading-broken-under-Windows-7-again-td3712633.html

And, the bug is being tracked here:
http://youtrack.jetbrains.net/issue/IDEA-72968?projectKey=IDEA&query=grails

Development tools for Windows

Software Development, Technology 4 Comments »

There is nothing more annoying than having to use Windows as the main development machine. However, it happens a lot, specially when you work as a consultant.
These is a list of free tools to make Windows less unpleasant for software developers:

  • Freecomander: replacement for the slow Windows Explorer
  • ClipX: Clipboard History
  • BareTail: Visual tail for log files monitoring.
  • Notepad++: Lightweight text editor
  • Greenshot: Quick screenshot editor.
  • Putty Connection Manager: Store server addresses, usernames and passwords.
  • portaPuTTY: Enhanced  Putty with the ability to export and restore connection configuration.
  • Winscp: SCP/File transfer for SSH connections.
  • Procexp: Enhanced process monitor.
  • Paint.net: Powerful and lightweight image’s editor.
  • Lauchy: Application launcher, similar to Mac’s hotspot.
  • Fiddler: Web debugging proxy
  • CNTLM: Authentication proxy (for apps without proxy authentication support, such as iTunes)
  • Hudson Tray tracker: Tray Icon for Hudson/Jenkins Continuous Integration server.
  • ForceBindIP: Tool to route applications to specific network connections. For example: Firefox through ethernet and Putty through 3G.

If you know some other interesting tools to suggest, please make a comment.

Update: Added ForceBindIp and portaPuTTY.

Grails Social Showcase

Software Development No Comments »

I have been working in a new pet project called Maga.ly, which is meant to be a Social Magazine for the Web, such as what Flipboard is for the iPad.
Maga.ly will not use a common login page with username, password and e-mail validation, but an integration with Twitter and Facebook, where all a user needs to do is authorize the app within the Social Networks.

Spring Social seemed to be a good starting point, since they provide a Java API to connect to the major Social Networks. In addition, Spring Social Showcase from Spring-Social-Samples provides a code sample, which covered good part of my needs.

Unfortunately, my problems began when  I tried to integrate Spring Social Showcase with Grails, the main development framework for Maga.ly.

After struggling a little I came up with a solution and named it grails-social-showcase, which is now available as open source on GitHub at: https://github.com/fsamir/grails-social-showcase

Please advice grails-social-showcase is based on Spring Social version 1.0.0 M2. Version M3 is already available and it is full of enhancements, specially regarding Facebook Apis.
Finally, it will be much appreciated if you want to help upgrading  it to support Spring Social M3.

Arduino Build Light

Arduino, DIY, Software Development, Technology 2 Comments »

The Build Light is meant to monitor Continuous Integration Servers and changes its colour according to the status of the server. Usually the red colour means that the code is broken, green is fine and blue means that the server is currently building.

Besides being an expensive gadget, for some, a build light might also sounds like a silly and useless geek toy, but it is not.
Continuous Integration is all about communication, so you want to ensure that everyone can easily see the state of the system and the changes that have been made to it.
One of the most important things to communicate is the state of the mainline build. Many teams like to make this even more apparent by hooking up a continuous display to the build system – lights that glow green when the build works, or red if it fails are popular.

Martin Fowler about Continuous integration

As the text above states, Martin Fowler also suggests a build light as a good source of quick feedbacks.
Personally, I have experienced substantial benefits after adopting a build light or other types of visual build monitoring. The light is different from a Tray Icon or an automated e-mail, because it is shared by the team and is impossible to ignore. So, it is common to see team members making jokes on red lights and trying to find “who broke the build“. Also, no one wants to be blamed for breaking the build and it creates a race for fixing the build as soon as possible.
I have been using Delcom lights for a couple of years now, but it always felt that I could have some fun building my own with Arduino, so I did.

It is using Java and RXTX to consume Hudson/Jenkins feeds and communicate via serial port.
The Arduino code is pretty simple and uses the Colorduino library to change the colors of the LED matrix.

What do you need?

Total Cost: $53.80

How to install?

Next steps

  • Perform a code cleaning. It has been written in just one day, so keep in mind that the code is still the first version that works.
  • Start the Ethernet version. I am already working in another board that will be completely independent and won’t require a Java app connected to the serial port.

Nelson Bay

Photos, Traveling No Comments »

Nelson Bay, NSW at EveryTrail

NELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSW
NELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSW
NELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSW
NELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSWNELSON BAY, NSW

Nelson Bay, a set on Flickr.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in