Search This Blog
Tuesday, November 13, 2012
Sample generated melodies
The original article of the melody generator can be found here: Melody generator
Thursday, October 18, 2012
Kinect within VMWare
For a client we developed a Kinect application which was shown at the Dutch Floriade festival. More details about this project in a next post.
The problem with the old Kinect SDK was the inability to use the Kinect within a virtual machine. Because of this I had to create a bootcamp partition and install Windows on it just for the sole purpose of Kinect development. The 1.6 SDK solves this!
Below are the results of my tests with the Kinect within VMWare. I used the following system configuration to test on:
- MacBook pro 2011 with 2Ghz core i7 and 8GB RAM..
- OSX Mountain Lion.
- VMWare Fusion 5 running Windows 7.
- Visual Studio Express 2012.
- Kinect 1.6 SDK.
Conclusion
The new Kinect 1.6 SDK does work within a virtual machine if the Kinect for Windows is used.
Thursday, October 4, 2012
IntelliJ SSR: replace constructors
public SomeClass(String a, String b, String c, String d) {
// Do something
}
This constructor is used at various places in the codebase.
At some point in time an update to SomeClass is made which introduced another constructor:
public SomeClass(String a, String b) {
// Do something
}
Lets assume you want all calls to the 4 argument constructor to be replaced by the 2 argument constructor. The arguments of the 4 argument constructor should be used in the 2 argument constructor in the following way: new SomeClass(1, 2, 3, 4) becomes new SomeClass(3, 1).
See the following example:
public class UsageOfSomeClass {
private SomeClass instance_1 = new SomeClass("a", "b", "c", "d");
private SomeClass instance_2 = new SomeClass("d", "e", "f", "g");
private SomeClass instance_3 = new SomeClass("h", "i", "j", "k");
public static void main(String[] args) {
SomeClass someClass = new SomeClass("1", "2", "3", "4");
}
}
Should become:
public class UsageOfSomeClass {
private SomeClass instance_1 = new SomeClass("c", "a");
private SomeClass instance_2 = new SomeClass("f", "d");
private SomeClass instance_3 = new SomeClass("j", "h");
public static void main(String[] args) {
SomeClass someClass = new SomeClass("3", "1");
}
}
You can achive the following for an entire codebase with one single structural search and replace action. Use the following templates to achieve this:
Search template: new SomeClass($arg1$, $arg2$, $arg3$, $arg4$)
Replace tempalte: new SomeClass($arg3$, $arg1$)
Hit find and Replace All. Thats it!
Sunday, September 9, 2012
IntelliJ: HTML and structural search and replace
There was no external CSS used. All styling of the tables was done with attributes or inline style elements. The styling was also not consistent throughout the page so each table looked slightly different.
Here is an example:
<table>
<tr>
<td width="200px">Some text</td>
<td width="221px">More text</td>
<td width="300px" height="100px">Example</td>
<td style="width: 210px;">HelloWorld</td>
<td style="width: 190px;">More text</td>
<td id="test" style="width: 222px;"></td>
<td id="test2" class="right" style="width: 200px;">Java</td>
</tr>
</table>
Without rewriting the whole site at once I wanted to remove all the inline styles so I could use css to style all the tables the same. That at least looked more attractive in the short run while in the long run we could focus on a complete redesign of the site.
The first thing I wanted to do was replace all the td elements with inline styling with plain, empty td elements. As written in my previous posts, IntelliJ's structural search and replace features fits this use case nicely.
In the structural search and replace dialog I used the following:
Search template:
<td $width$="$value$" $style$="$value$">$text$</td>
Replace template:
<td>$text$</td>
In the Edit variables dialog I specified a minimum count of zero for the $width$, $style$ and $text$ variable. The $value$ variable has a minimum count of one. For all variables I used a maximum count of one.
The template searches for all td elements with zero or one width or style attributes (or both) and with or without text. The replace template replaces the td found with the search template in a plain td. The output of the HTML after the search and replace is run is:
<table>
<tr>
<td>Some text</td>
<td>More text</td>
<td>Example</td>
<td>HelloWorld</td>
<td>More text</td>
<td></td>
<td>Java</td>
</tr>
</table>
After this replacement I could just insert the appropriate CSS and style all tables consistently. Without structural search and replace I think such scenario's take considerably longer to execute.
Saturday, August 11, 2012
IntelliJ: customize the editor
- Open the settings window
- Open Editor -> appearance and check Show method separators.
- Open the settings window
- Click Editor and check Highlight usages of element ar caret.
- Open the settings window
- Click Editor and check Highlight current scope.
- Open the settings window
- Click Editor and uncheck Allow placement of caret after end of line.
- Open the settings window
- Click Editor and check use soft wraps in editor and Show all soft wraps.
- Open the settings window
- Click Editor -> Editor Tabs and specify a tab limit.
- Open the settings window
- Click Editor -> Auto Import and check Optimize imports on the fly
Sunday, August 5, 2012
IntelliJ: Final parameters and variables
- Adding the final keyword to all methods generated with IntelliJ.
- Add the final keyword to existing methods.
- Open up the Project Settings dialog and navigate to Code Style -> Java.
- Click the Code Generation tab.
- In here you will find the Final modifier section.
- Check the "Make generated parameters final" option.
- Open up the settings dialog and click Inspections (in Project settings)
- Click copy to copy the Project default inspections and name the profile anything you want.
- Click the Rest to Empty button to disable all inspections. Disabling all inspections is a quick way to only focus on a specific inspection if you want to apply just that specific inspection.
- Enter 'final' in the search box
- Under the "Code style issues" check the following rule: "Local variable or parameter can be final".
- On the left make sure the option "Report method parameters" and/or "Report Local Variables".
- Click OK.
- Click Analyse -> Inspect code in the menu.
- Make sure you select the Whole project and select the profile created in step 2.
- Click OK.
- In the inspection dialog you see all methods where the parameter could be final.
- Right click the inspection and click "Apply fix 'Accept suggested final modifier'" to add the final modifier to all method parameters where it can be final.
Monday, July 30, 2012
IntelliJ productivity tips
public class SomeClass {
public static final Integer VARIABLE_1 = new Integer(10);
public static final Integer VARIABLE_2 = new Integer(20);
public static final Integer VARIABLE_3 = new Integer(30);
}
- Open up the Structural Replace dialog by pressing Ctrl - Shift - M (on Windows) or Command - Shift - M (on OSX)
- In the Search template dialog enter the following: new Integer($arguments$)
- In the Replacement template enter the following: Integer.valueOf($arguments$)
- Make sure you specify java as file type
- In the Edit Variables dialog set the minimum and maximum count of the $arguments$ parameter to 1.
- The above search template finds all occurrences of new Integer() with exactly one argument and replaces it with Integer.valueOf() taking into account the arguments.
- Click find.
- In the Find dialog you see all occurrences of new Integer($arguments$) that were found.
- Click Do Replace all to replace all new Integer() to Integer.valueOf().
Tuesday, May 1, 2012
Increasing user expectations
Users are getting increasingly more demanding about the services and functionality that (online) organizations have to offer. This is especially true for organizations where users arrange most or all of their services online. Some examples are Internet banking, online insurance and travel agencies.
Users expect this functionality:
- To be easy to use
- That new features are added continuously and provide real value
- Will work on their mobile devices like phones and tablets
- Is tailored to their personal needs
This functionality is most of the time designed within the company itself and eventually, when developed and tested, deployed in production. In this model, the company expects that the functionality will meet the needs of most or all users. I believe this model is not sufficient anymore in the ever-increasing expectations of those users.
One of the models to cope with this is to let users/developers themselves build the functionality they need. We also see a lot of this on the Internet where users build their own application/gadgets by using provided API’s. A prime example of this is of course Facebook.
What if we extend this model to the enterprise? What if, for example, Internet Banking companies expose (some) of their functionality through API’s and let users develop functionality they really need? What kind of applications would arise out of this?
I do not think this is a question of how but when. As some or most of you already know, Google owns a banking license. What does it mean for regular banks if Google or perhaps Facebook adopts such kind of platform for banking and/or insurance products? I think a whole new generation of users will make the transition to those companies. This indeed may have a large impact on the customer base of traditional organizations.
Before organizations are ready to make such transitions, a large number of questions must be addressed:
- How do we secure access to API’s and data?
- Which data do we want to expose?
- Why would developers want to build applications for us? How do we compensate developers who are building great applications for us?
- What about legal issues?
- What technology do we use?
- How do we change the mindset of our own people?
- Etc.
And the most important question: when are organizations ready to adopt this model and radically change the way applications are delivered to end-users? Of course this change does not have to be a big bang but can and should be made incrementally.
From a technology point of view, one of the ways to implement such eco-system is by adopting the Open Social specification. The Open Social specification defines:
- A social data model, which provides a standard representation of people their relationships and activities also known as a connected graph of people.
- A set of standard API’s to access people, their relationships and activities available in REST and JavaScript API’s. Besides the JavaScript API for web applications, the REST API is particular interesting as enabler of mobile applications.
- A standard to develop gadgets that encapsulate reusable application logic.
As an example, iGoogle is one of the platforms based on Open Social (in fact, Google donated their iGadgets container to the community which is Apache Shindig). IBM and Atlassian are also incorporating Open Social technology in their own products.
Conclusion
Since users become more and more demanding about the services and functionality that (online) organizations offer, organizations need to find other ways to provide that functionality instead of the traditional specification-build-deploy cycle. A possible way to do this is to let users themselves build the functionality they need. Open Social could be the technological enabler to facilitate this.
However, the ultimate question remains: if and when are organizations ready to adopt a radical new strategy to provide functionality to its end-users.
What is your opinion about this?
Tuesday, April 10, 2012
Flex: unittest a view with radio buttons
- Created a unit test (we are using FlexUnit)
- Instantiate and initialize the view in the unit test
- Populate the UI components with values to test
- Trigger the validators
1: <?xml version="1.0"?>
2: <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
3: <mx:RadioButtonGroup id="genderRadioButtonGroup"/>
4:
5: <mx:RadioButton id="male" groupName="genderRadioButtonGroup" label="male"></mx:RadioButton>
6: <mx:RadioButton id="female" groupName="genderRadioButtonGroup" label="female"></mx:RadioButton>
7: </mx:VBox>
And the code of the unit test:
1: package {
2: import flexunit.framework.TestCase;
3:
4: import mx.core.mx_internal;
5:
6: use namespace mx_internal;
7:
8: public class RadioButtonTest extends TestCase {
9: public function RadioButtonTest() {
10: }
11:
12: public function testPopulateRadioButton():void {
13:
14: var myForm:MyForm = new MyForm();
15: // Initialize the UI component so that all child components are added to the form.
16: myForm.initialize();
17:
18: // Explicitly add the radiobuttons to the group, please note the use namespace mx_internal or else this
19: // method can not be called.
20: myForm.genderRadioButtonGroup.addInstance(myForm.male);
21: myForm.genderRadioButtonGroup.addInstance(myForm.female);
22:
23: myForm.genderRadioButtonGroup.selectedValue = "male";
24:
25: assertEquals("male", myForm.genderRadioButtonGroup.selectedValue);
26: }
27: }
28: }
Conclusion
Thursday, March 29, 2012
Continuously looping video in WPF
1: <MediaElement LoadedBehavior="Play">
2: <MediaElement.Triggers>
3: <EventTrigger RoutedEvent="MediaElement.Loaded">
4: <EventTrigger.Actions>
5: <BeginStoryboard>
6: <Storyboard>
7: <MediaTimeline Source="Instructions.avi" RepeatBehavior="Forever" Storyboard.TargetName="video" />
8: </Storyboard>
9: </BeginStoryboard>
10: </EventTrigger.Actions>
11: </EventTrigger>
12: </MediaElement.Triggers>
13: </MediaElement>
Unfortunately this solution is not reliable. After some time it can took a while before the video starts playing again after it has ended. Sometimes the video stops playing completely. Some searching revealed that the MediaElement indeed is not reliable enough. Some alternatives where suggested, for example http://wpfmediakit.codeplex.com/.
The mediakit can indeed be a solution but there is a simpler way without adding a dependency on a third party framework. Instead of using a StoryBoard and a MediaTimeLine you can also manage the repetition yourself. The following code demonstrates this.
1: <MediaElement x:Name="instructionVideo" Width="320" Height="240" Source="Videos/Instructions.mp4" LoadedBehavior="Manual" Loaded="instructionVideo_Loaded" MediaEnded="instructionVideo_MediaEnded" VerticalAlignment="Bottom" HorizontalAlignment="Center" Canvas.Top="40"/>
The above XAML fragment is accompanied by the following code-behind:
1: private void instructionVideo_Loaded(object sender, RoutedEventArgs e)
2: {
3: instructionVideo.Play();
4: }
5:
6: private void instructionVideo_MediaEnded(object sender, RoutedEventArgs e)
7: {
8: instructionVideo.Position = TimeSpan.FromSeconds(0);
9: }
Instead of letting WPF manage the video, we specify a LoadedBehavior of Manual which means we can manage the starting and stopping of the video ourselves. To actually start the video the Loaded event handler is used which calls the Play method on the instructionVideo element. When the video reaches the end, the MediaEnded event is dispatched. In this event the Position is set back to 0 so the video starts playing from the beginning again. This proved to be a reliable way of continuously looping videos.
PS. the video in questions is in mp4 format and about 20 seconds in length which must loop all day long.
Monday, January 23, 2012
Monitoring an IBM JVM with VisualVM
- Monitor heap usage
- Monitor CPU usage
- Monitor Threads
- Initiate garbage collections
- Profile CPU and memory
- And more…
- navigate to: Server -> Server Types -> WebSphere application servers ->[SERVER_NAME]
- Expand Java and Process Management and click Process definition
- Click Java Virtual Machine
- In the Generic JVM arguments field append the following properties: -Djavax.management.builder.
initial= -Dcom.sun.management.jmxremote -Dcom.sun.management. jmxremote.authenticate=false -Dcom.sun.management. jmxremote.ssl=false -Dcom.sun.management. jmxremote.port=1099 - Restart the server
- Windows 7 64-bit
- IBM JDK1.6 64 bit
- WebSphere Application Server version 7.0