Sunday 12 January 2014

Python: Minimum absolute sum of two integers in an Array

So I was given this problem and figured I would share my solution for others. I believe the Time Complexity to be O(n log n) due to Quicksort being O(n log n). I could be wrong though!
'''
Created on 10/01/2014

# My first foray in python
# min_abs_sum_of_two takes an Integer Array and returns the lowest absolute sum of two integers
# I did not include checking for the following: array length, non integer characters.
@author: BeauR
'''

import time
import sys

def min_abs_sum_of_two(listOfNums):
    #init y as last array place
    y = len(listOfNums)-1
    #init x as first array place
    x = 0
    #set current min to arbitrary max possible integer
    currentMin = sys.maxsize
    #quicksort array into ascending order
    quicksort(listOfNums, x, y)
    #while x is less than y to ensure they never overlap array places
    while (x < y):
        #if the current calculation is less than currentMin
        if abs(listOfNums[x]+listOfNums[y]) < currentMin:
            #store new minimum
            currentMin = abs(listOfNums[x]+listOfNums[y])
        #if the sum of arr[x] & arr[y] is greater than zero
        #x no longer need to be increased as its at optimum minimum value
        if listOfNums[x]+listOfNums[y] < 0:
            #increment search pointer x
            x = x + 1
        else:
            #decrement search pointer y
            y = y -1
    return(currentMin)
   

def quicksort(list, start, end):
    if start < end:                            # If there are two or more elements...
        split = partition(list, start, end)    # ... partition the sublist...
        quicksort(list, start, split-1)        # ... and sort both halves.
        quicksort(list, split+1, end)
    else:
        return

def partition(myList, start, end):
    pivot = myList[start]
    left = start+1
    right = end
    done = False
    while not done:
        while left <= right and myList[left] <= pivot:
            left = left + 1
        while myList[right] >= pivot and right >=left:
            right = right -1
        if right < left:
            done= True
        else:
            # swap places
            temp=myList[left]
            myList[left]=myList[right]
            myList[right]=temp
    # swap start with myList[right]
    temp=myList[start]
    myList[start]=myList[right]
    myList[right]=temp
    return right

start_time = time.clock()
print(min_abs_sum_of_two(listOfNums = [-6, -5, -4, -3, 1]))
print(time.clock() - start_time, "seconds")

Thursday 2 January 2014

OHS HTTPD.conf RewriteRule to point DNS/HOSTNAME Straight to Space

Quick steps

  • edit httpd.conf (/u01/app/oracle/product/fmw/Oracle_WT1/ohs/conf)
  • add line at bottom
<VirtualHost *:80>
ServerName <$CUSTOMDNS$>
ServerAlias <$CUSTOMDNS$>
DocumentRoot /var/www/webcenter
RewriteEngine On
RewriteRule ^/$ /webcenter/spaces/<$SPACENAME$> [PT,L]
RewriteRule ^/webcenter$ /webcenter/spaces [PT,L]
RewriteLog /home/oracle/rewrite.log
<location />
  SetHandler weblogic-handler
  WebLogicHost <$WEBCENTERHOSTNAME$>
  WebLogicPort 8888
</location>
</VirtualHost>

Simple UCM/WCC/OCS JSR Portlet for WebCenter Spaces/Portals

So much to my dismay many of the OCS portlets available for WCS/Portal have limited functionality. I also found it pretty hard to find any portlets amongst the WebCenter Community so heres one I just finished!

Workflow Portlet

This is a pretty simple portlet that takes 2 parameters

  • UCMSERVER: The IP address or HOSTNAME of the UCM Server 
  • WorkflowID: The ID of the Workflow Queue in the target UCM (CSV Ids are accepted)
The portlet than connects to the UCM server using RIDC and builds a table showing the Documents in the current WorkflowID and the Approvers the documents are waiting on.

Download the JDev Project here
or
Download the Ear File here