iOS Swift – Playground

I started learning Swift (via a few months ago. I was planning to create an application that will give me alerts for specific stock data price changes. Although this app hasn’t materialize yet, I find from developing that app, that learning Swift seems to be very straight forward and easy. The language itself is not that complicated to learn – as long as you are familiar with the C-style syntax. The XCode application is remarkable in its development tools. The IDE has a wide range of features that can help an app developer initiate and finally upload their apps on the app store.

Of course, for the likes of me, I haven’t really uploaded an app yet since I’m still learning the language, but I’m really impresses with the wide variety of channels that can be used to learn the language. One I wanted to be specific about is the Playground.

The playground is just a project within xcode that a student can use to code Swift. It can be use as a running ground to write code and see the results instantly.

//: Playground - noun: a place where people can play

import UIKit

var str = "Hello, playground"
var name:String = "String"

var number:Int = 1;
var numberD:Double = 10/42;
var numberF:Float = 10/21;
var newString:String = "111";

print("Hello world!!!");


//var numberX = "90";
var numberX:Double = 0.0;

var array = ["as0","as1"];

var dict = ["name":"Alvin","Description":"Description of Alvin"];

var nameStr:String = "name";

var textSample:String = "My name is \(dict[nameStr]!)";

var dict1 = [["name":"name1","desc":"desc1"],["name":"name2","desc":"desc2"]];


if dict1[0]["name"] == "name1" {
    print("Hello World!");

var random = arc4random_uniform(10)
print("The random number is \(random) ");

for var i = 1;i<10;i++ {
    print("This is \(i)");

var arr = ["aa","aa1","aa2"]

for x in arr {


let arr1 = ["1","2","3"]
for x in arr1 {


var g = 0;
while g < 5 { print(g); g++; } var str1:String = "1"; func polymorphMe(inout name1:String, name2:String) { name1 += "Hello"; } polymorphMe(&str1,name2: ""); print(str1); func getEverything(name1 name2:String, description1 desc:String) -> (Int,Int) {
    return (1,1);

That’s a direct copy and paste of my playground code. It has all the basics syntax and powerful features of Swift. I just hope I can finish an app with it before 2016. 🙂

I would certainly recommend anyone who’s learning Swift to use this tool and follow Rob Percievals Udemy course! (I highly recommend it!)

Happy coding!

Coding the Thread Deadlock

You want a deadlock right?

I wanted to make sure that I understand this correctly. Thread deadlocks are one of the issues that Core Java Developers usually faced especially if developing a high availability/performance application. They need to ensure that threads are created in an efficient manner.

I’d like to disclaim that I’m an expert on the subject matter, but I do understand why it can happen, how to identify and how can it be resolved.

Take a look at an threadlock example below:

package com.areyes.datastruct;

class Friend {
	private final String name;

	public Friend(String name) { = name;

	public String getName() {

	public synchronized void bow(Friend bower) {
		System.out.format("%s: %s" + "  has bowed to me!%n",,

	public synchronized void bowBack(Friend bower) {
		System.out.format("%s: %s" + " has bowed back to me!%n",,

public class DeadLock {
	public static void main(String[] args) {
		final Friend alphonse = new Friend("Alphonse");
		final Friend gaston = new Friend("Gaston");
		new Thread(new Runnable() {
			public void run() {
		new Thread(new Runnable() {
			public void run() {

“What is deadlock?” answer is simple, when two or more threads waiting for each other to release lock and get stuck for infinite time , situation is called deadlock . it will only happen in case of multitasking.

“How do you detect deadlock in Java?” – easy as checking and testing your code. You can also check your systems thread dump and see from there if it’s in a deadlock.

Hope this helps!

Diagonal Sum

Get the sum of the diagonal values and add them. Just had some time trying to play around arrays.

1st. Get the all diagonal values. Add the numbers for each line segment.
2nd. Add the the total of the two line segments.

I had to traverse the table matrix to get the numbers within the line segments. It’s basic array.

package com.areyes1.algo;

public class DiagonalSum {
	static int[][] arrNumber = new int[][] {
	static int diagnoalSum() {
		int startingCounter = 0;
		int sum1st = 0;
		int sum2nd = 0;
		for(int i=0;i<arrNumber.length;i++) {
			for(int j=0;j<arrNumber[i].length;j++) {
				if(j == startingCounter) {
					sum1st += arrNumber[i][startingCounter];
		startingCounter = arrNumber.length - 1;
		for(int i=0;i<arrNumber.length;i++) {
			for(int j=arrNumber[i].length - 1;j>=0;j--) {
				if(j == startingCounter) {
					sum2nd += arrNumber[i][startingCounter];
		return sum1st + sum2nd;
	public static void main(String[] args) {

The code can be modified as long as the table matrix is proportional, that is number of rows = number of columns.

1 + 2 + 3 + 4 + 9 = 19
6 + 7 + 3 + 5 + 8 = 29
19 + 29 = 48

Git me the log

There are times that as a developer who primarily responsible for the deployment can use a little helping hand on getting the right source and builds for a release. After all, the artefacts coming out of it can be the same one that’s going to be deployed in production. It’s really important that we check each and every code commits as well as their impacts.

One thing I do in this situation is I use the git log to give me the information of the sources and commits that will be part of the release:

git log --pretty=format:"%h - %an, %ar, %ae : %s" --stat --name-only --graph --since=2015-01-01 >> logme.log

Let’s run this down bit by bit

git log is a git command that gets the details of the commits
--pretty=format can be used to specify a specific format using "%an, %ar, %ae, : %s". Thats author revision, name, email and file.
--stat to show the statistics
--name-only to show the filenames only
-- graph to show a graphical representation
--since to show only the commits made from the given date up to the current date (today)

16-07-2015 8-34-13 AM

How about a graph only? I ran the same git log but only passed a format and a –graph argument. Output below.

$ git log --pretty=format:"%h %s" --graph
* 2d3acf9 ignore errors from SIGCHLD on trap
* 5e3ee11 Merge branch 'master' of git://
| * 420eac9 Added a method for getting the current details to the branch.
* | 30e367c timeouts
* | 5a09431 add timeout protection to hubbys
* | e1193f8 support for heads with slashes in them
* d6016bc require time for xmlschema
* 11d191e Merge branch 'hubbys' into local

.. and how about log specifically for areyes since January 01, 2014 but before November 01, 2010

$ git log --pretty="%h - %s" --author=areyes1--since="2014-10-01" --before="2010-11-01"
5610e3b - Fix testcase failure when extended attributes are in use
acd3b9e - Enhance hold_lock_file_for_{update,append}() API
f563754 - demonstrate breakage of detached checkout with symbolic link HEAD
d1a43f2 - reset --hard/read-tree --reset -u: remove unmerged new paths
51a94af - Fix "checkout --track -b newbranch" on detached HEAD
b0ad11e - pull: allow "git pull origin $something:$current_branch" into an unborn branch

There’s a lot of format options available for git log that can be found here and given these, a lot of automations can be created!

Idea: You can echo this to a file and send it out to developers for verification, or a better idea, loop through the list of users, get each of their emails and revisions, generate the logfile for each and send it out to them. Pretty neat as it will give the developer a bird eye view of their sources that will be included on the release (and notify the team if theirs was not included)

Basics – JasperReport on your Java Desktop App


Have you ever had a client that only wants a basic reporting screen that has the values in it? Good thing JasperReports was invented!

In this post, I’m going to share a small example of how you can create your own report in iReport, compile it to *.jasper and call them via your own Java Desktop App!

Step by Step

Create your report in iReport

You can actually code this in XML but that would be inefficient. iReport is an open source report editor that developers can use to design reports. Jasper Reports are basically like Java Source code that you can compile in different language, as of this writing, it supports Java (of course), Groovy and JavaScript. Obviously, if you want to create a report that can be viewed in the Java based report viewer, you should compile it in Java. If you want to view it in a Web Browser, it should be in Javascript (although, technically, you can wrap a JFrame in an Applet and place the JasperReport viewer on the Applet, but not getting ahead in here).

In this example, let’s just create a simple Report (a blank perhaps) and put a few parameters and fields.

Screenshot at Jun 15 22-20-20

Once done, compile it and locate your jasper file (*.jasper is the compiled source file).

Code it!

I wouldn’t dive much on how you where you should put your jasper files. It can be externally access or via resource classpath. My recommendation is of course, put it in your classpath, but we all have our own case of usage. If there will be a lot of adjustments to your report because of alignments, then I would go with putting it externally. This is so that you wouldn’t have to compile your project again just to do minor alignments.

Before we go to the snippet code, make sure you have the dependency below.


If you’re not familiar with Maven, you should be, read here. 🙂

and here is a sample of code.

// Get the file, put it in a stream
FileInputStream fis = new FileInputStream(this.getClass().getResource("").getFile());
BufferedInputStream bufferedInputStream = new BufferedInputStream(fis);
// We do have parameters, so we create the map object to store values for them.
Map map = new HashMap();
map.put("SAMPLE1", "This is a sample 1 text");
map.put("SAMPLE2", "This is a sample 2 text");

// We create the jasper report object, load the report with JasperFillManager object and use the
// JasperViewer to display the report            
JasperReport jasperReport = (JasperReport) JRLoader.loadObject(bufferedInputStream);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, map,new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);

Screenshot at Jun 15 22-19-45

If you’re having issues, just let me know (via comments), I can help you out.