PlayFramework – Java

So far I have really liked this concept. The only con is that some times is difficult to find full examples that use the latest version. Installing sbt We need sbt for compiling and running Play applications. brew install sbt@1 Executing a first application Check the tutorials page to see how to create a first…

How to run a custom update using Java JPA

From time to time it is necessary to execute a query without using Java’s JPA infrastructure. In order to do it, we have to define a NamedQuery to execute. In this example, I will run an update against the database. @Entity @NamedQueries ({ @NamedQuery ( name = "SomeEntity.TestQuery", query = "update SomeEntity se set se.myField…

Quick lessons on working with Java’s BigDecimal

Today I bring an example of the different results you can expect when using Java’s BigDecimal class. From instantiation to applying different arithmetic operations, it is important to understand how they affect the resulting instances. The following program shows different scenarios and results applied to BigDecimal’s. package test; import java.math.BigDecimal; import java.math.RoundingMode; public class Test…

How to read a file name argument from the command line in C++

Reading a file name parameter from the command line is a common task. In this post I read a file name and validate it exists. For paths and file names that include spaces, you have to pass them between quotes, otherwise they will be interpreted by the operating system as two different parameters. #include <string>…

How to check command line arguments in any order

Here is an easy solution to passing parameters to a C++ application from the command line that does not require any external libraries. Since parameters are read inside a loop, the order in which they are passed is not important. #include <string> #include <iostream> int main(int argc, char* argv[]) { for (int i = 1;…

Solution: Netbeans 8 not working on Ubuntu 15.10

Netbeans is one of my beloved day to day applications. Yesterday, when I installed Ubuntu 15.10 (Wily Werewolf) on my computer, Netbeans started to hang on the startup screen, specifically at the Loading Modules phase. It took me hours looking for solutions on the internet; and reinstalling different versions of the Java Development Framework didn’t…

Compiling and Debugging Oracle's Pro*C files in OS-X / Xcode

Part of my work as a Web/UNIX developer includes maintenance and development of tools using Oracle‚Äôs Pro*C. In text interfaces, VIM is a pretty decent tool for creating source code and their companion make files. If you created the right make file, compiling is also a breeze. However things get kind of tricky when you…

The Rationale behind the Creation of a Model-View-Controller Framework: Fantastic

Important: This is a work in progress document. The Model-View-Controller is a software pattern frequently used for web development. As its name states, it is composed by three components: A Model or domain representation of a problem. It receives commands, processes them and modifies its state according to the input provided. A View whose main…

Oracle Snippets

This post will be updated with snippets for Oracle. I hope you find it useful.   1. Change the default date format Most useful snippet of the year! ūüėČ ALTER SESSION SET NLS_DATE_FORMAT = ‘MM/DD/YYYY HH24:MI:SS’; select sysdate from dual; 2. Escape single quotes and ampersands on strings Single quotes: select ‘D”Angelo”s’ from dual; Ampersands:…

Create a connection to MySQL in Java

This time we are going to create a basic connection to MySQL in Java and pull some data from it. // Compile it: // javac Mysql.java // // Try it: // java -classpath mysql-connector-java-5.1.27-bin.jar:. MySQL import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class MySQL { public Connection getConnection() throws…

Installing Lucene/Solr on CentOS 6

This time we are going to install Solr, the super text search platform on CentOS. The installation process requires a couple extra libraries in order to work: Apache Commons Logging and SLF4J. ¬† Installing Java yum install java java -version You must have at least version 1.6 in order to run Solr. If you got…

Installing Java 1.6 on CentOS 6

Nowadays more and more Java applications require at least a 1.6 JVM to run. However, the default CentOS 6 repositories still take you to the 1.5 version. By following this step by step tutorial you’ll be able to get version 1.6 running on your system.

WordPress Snippets

As a WordPress developer I have collected / created / curated many snippets that I’ve used in my projects. I hope you find them useful.   General HTML / WordPress tags Get your template’s directory <link href=”<?php echo get_template_directory_uri(); ?>/style.css” rel=”stylesheet” media=”screen”>   Check if this is the home page <?php if (is_home()) { ……

Installing MongoDB/PHP Driver on CentOS 6

Since the module is not included with the default PHP installation, you have to download it from¬†the official repository: cd mkdir mongo-php-driver cd mongo-php-driver curl https://codeload.github.com/mongodb/mongo-php-driver/zip/master¬†> mongo-php-driver-master.zip Unzip it unzip mongo-php-driver-master.zip cd mongo-php-driver-master You need phpize¬†to build the module. You can install it from the remi repository: wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6.rpm yum –enablerepo=remi install…

Installing MongoDB on CentOS 6

The first step is to configure the repositories. Create the following file¬†/etc/yum.repos.d/10gen.repo with the following contents: For 32-bit systems: [10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686 gpgcheck=0 enabled=1 For 64-bit systems: [10gen] name=10gen Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64 gpgcheck=0 enabled=1 Install Mongo yum install mongo-10gen mongo-10gen-server   Configure MongoDB You can configure Mongo by editing the following file: /etc/mongod.conf Set Mongo…

Installing the PHP/MongoDB extension on Mac OSX 10.8

Installing PHP/MongoDB extension is a two steps task on OSX: Install the autoconf tool required for compiling the extension Install the Mongo extension You have to install autoconf in order to avoid the following error: Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script. ERROR: `phpize‚Äô failed…

1000 song names SQL test data

This time I want to share a 1000 rows SQL table that you can use for text searches. It includes a table with 1 column, 1000 rows song title names. It is plain standard SQL so you can use it with any database manager. Download it here. Hope you find it useful.

How many bytes does an "int" have in c++?

Well, that depends on several things, like your current processor and compiler. The best way to know it, is by using the sizeof operator. Copy the following code, compile it and run it: #include <iostream> using namespace std; int main() { cout << “char: ” << sizeof(char) << endl; cout << “int: ” << sizeof(int)…

A simple Makefile

Learning how to create a Makefile is one of those tasks every C/C++ programmer has to do. Since there are many good make tutorials on the web, I’m only going to share a simplistic makefile that you can use for your projects. CFLAGS=-c -Wall -Iinclude LDFLAGS=-lPocoFoundation -lPocoData SOURCES=a.cpp b.cpp main.cpp OBJECTS=$(SOURCES:.cpp=.o) VPATH=src all: pre $(OBJECTS)…