Alejandro G. Carlstein Ramos Mejia Blog



If you wish to go to the beginning, were go over installation, basic settings, and package versioning, then go here [link]
This is the continuation of the previous part of this tutorial [link] were we when over installation, basic settings, and package versioning.

 

While NodeJS is great for REST calls using JSON, we are going to play with bootstrap templates. Later on, I will include a section focuses on REST calls.

There are different places were you can go to obtain open source templates such as Start Bootstrap [link], Bootstrap Zero [link], and Bootstrap Made [link]. Doing a search in you favorite search engine must pop many of them.

 icon-warning Make sure to read the license of those templates. There are some of them that you can’t use for your purposes.

In this case, I went into Start Bootstrap [link], search for a single column template, and downloaded “1 Col Portfolio” [link]. Before downloading, I went into the source [link] and took a look to the LICENSE file. It seems that David T. Miller [link], the author of this template, was nice to use an MIT license. This license allow us to obtain a copy without restriction and limitations. Thanks David for your contribution.

Share

This is the continuation of the previous part of this tutorial [link] were we when over installation, basic settings, and package versioning.

Express: Setup

On the previous part [link], we showed the installation of the package Express. Express is a fast, minimalist web framework built for NodeJS.

First, we need to create a JavaScript file with the main part of our program. In this case, we create the file app.js with this line:

var express = require('express');

The method required give us a reference that points to the dependency package Express. However, this doesn’t provide us anything that we can use until we create an instance of Express.

Share

Share

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

In this example you will see: Binary search by using heapsort for sorting.

example_5.hx:

/**
 * @author: Alejandro G. Carlstein R. M.
 */

class HeapSort{

	private var data : Array<Int>;
	private var heap_size : Int;
	private inline function leftChild(index : Int) : Int{ return (index << 1) + 1;	}
	private inline function rightChild(index : Int) : Int{ return (index << 1) + 2; }

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		this.data = data;
	}

	public function sort() : Void{
		if(data.iterator().hasNext()){
			heap_size = data.length;
			buildMaxHeap();
			var index : Int = data.length - 1;
			while (index > -1){
				exchange(0, index);
				maxHeapify(0, --heap_size);
				--index;
			}
		}else{
			trace('There is no data to sort');
		}
	}

	private function buildMaxHeap() : Void{
		var index : Int = data.length >> 1;
		while (index > -1){
			maxHeapify(index, heap_size);
			--index;
		}
	}

	private function maxHeapify(index : Int, heapSize : Int) : Void{
		var largest : Int = index;
		var left : Int = leftChild(index);
		var right : Int = rightChild(index);	

		if (left < heapSize && data[left] > data[index])
			largest = left;

		if (right < heapSize && data[right] > data[largest])
			largest = right;

		if (largest != index){
			exchange(index, largest);
			maxHeapify(largest, heapSize);
		}
	}

	private function exchange(index_a : Int, index_b : Int) : Void{
		var temp_value : Int = data[index_a];
		data[index_a] = data[index_b];
		data[index_b] = temp_value;
	}

}

class BinarySearch{
	private var heapsort : HeapSort;
	private var data : Array<Int>;
	private function search(value : Int, start_index : Int, end_index : Int){
		var middle_index : Int = (start_index + end_index) >> 1;
		var was_found : Bool = false;
		if(start_index < end_index){
			if(data[middle_index] == value){
				return true;
			}else{
				if(data[middle_index] > value){
					was_found = search(value, start_index, middle_index);
				}else{
					was_found = search(value, middle_index + 1, end_index);
				}
			}
		}
		return was_found;
	}

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
		if (data != null) setData(data);
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		if (data != null){
			heapsort = new HeapSort();
			heapsort.setData(data);
			heapsort.sort();
			data = heapsort.getData();
		}
	}

	public function doExist(value : Int) : Bool{
		return search(value, 0, data.length);
	}

}

class Example_5 {

	static function main(){

		var data : Array<Int> = [3, 7, 5, -1, 6, 1, -3];
		printData(data);

		trace('Binary Search:');
		var binarySearch = new BinarySearch(data);
		trace ('Do 3 exist? ' + binarySearch.doExist(3));
		trace ('Do 4 exist? ' + binarySearch.doExist(4));
		trace ('Do 7 exist? ' + binarySearch.doExist(7));

		data = binarySearch.getData();
		printData(data);		

	}

	private static function printData(data : Array<Int>){
		var iter = data.iterator();
		var index : Int = 0;
		trace('[DATA]');
		while (iter.hasNext()){
			trace('data[' + index++ + ']: ' + iter.next());
		}
	}

}

If you encounter any problems or errors, please let me know by providing an example of the code, input, output, and an explanation. Thanks.

Share

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

Transposition Ciphers

The main idea of transposition ciphers is to rearrange the order of the letters used in the plaintext. This prevent the attacker to be able to recognise the message by using the frequency of distributions.

Rail Fence Cipher

Share

The following swift code will give show you how to obtain the width from the first column plus how to set up all the columns’ label

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView {
       
 
        // Display the first column's width
        // The value 0 is to point to the first column regardless if you have one or multiple columns
        NSLog("Width: \(pickerView.rowSizeForComponent(0).width)")
        
        let pickerLabel : UILabel = UILabel()
       
       // pickerViewLabelTextForComponentRow is a custom made function to obtain what text will go in each row  
        pickerLabel.text = pickerViewLabelTextForComponentRow(component, row: row)
        pickerLabel.textAlignment = NSTextAlignment.Center
        pickerLabel.textColor = UIColor.blackColor()
        pickerLabel.font = UIFont.boldSystemFontOfSize(13.0)
        pickerLabel.backgroundColor = UIColor.lightGrayColor()

       // If you wish to set up the labels individually in each column, use the value of the parameter component with a control condition such as if or switch
        
        return pickerLabel
    }
Share

The following describe how to create a basic custom composite component in JSF 2.0+ for Primefaces. The method of using rendering classes, back beans, type classes, and others are not included in this tutorial. Please note that the IDE used for programming is NetBeans 7.4

 

  1. Create a Folder
    Create a subfolder into the resources folder as show in the following image. In this case, we call this folder “utils”.
    create_folder
  2. Create a XHTML File
    Inside the folder utils, lets cretae a XHTML file. This file will contain our custom composite component.
    In this case, we call this file “displaySuperValue.xhtml”
  3. File “displaySuperValue.xhtml” Content
    Copy and Paste this code example:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"	  	 
    	 xmlns:h="http://xmlns.jcp.org/jsf/html"
    	 xmlns:composite="http://java.sun.com/jsf/composite">
    	<head><title>Show Super Value</title></head>
    	<body>
    
    	  <composite:interface>
    	    <composite:attribute name="supervalue" required ="true" />
    	  </composite:interface>	
    
    	  <composite:implementation>			
    	    <hShockutputText value="This is SuPeR: #{cc.attrs.supervalue}" />
    	  </composite:implementation>
    
    	</body>
    </html>
  4. About Your Custom Component
    At the beginning of your file, you will need to include the composite namespace if the IDE did not include it automatically. Just add the following line:

    Share