The Mouse Move Program

Written by klee on May 29th, 2016

I once wrote a piece of code to prove that you didn’t actually have to be at your computer for your IM to state that you are active. This has since gone on to be a frequently talked about piece of code. Here it is 🙂

import java.awt.*;
import java.util.*;

public class MouseMove {
  public static void main(String[] args) throws Exception{
    Robot mm = new Robot();
    Random random = new Random();
    while(true) {
      mm.delay(1000*60);
      int x = java.lang.Math.abs(random.nextInt() % 640);
      int y = java.lang.Math.abs(random.nextInt() % 480);
      mm.mouseMove(x,y);
    }
  }
}
 

Jumble revisited

Written by klee on November 21st, 2015

Here is a jumble example in Perl.

#!/usr/bin/perl
use strict;
use warnings;
use Algorithm::FastPermute ('permute');
use Text::Aspell;
my $arg = shift or die "takes one arg";
my @arg = split(//,$arg);
my $speller = Text::Aspell->new;

permute {
	if ($speller->check(join("",@arg))) {
		print "@arg\n";
	}
} @arg;
 

Jumble

Written by klee on November 21st, 2015

I have always been interested in the jumble program that is in the paper. A long time ago, I wrote one of my first programs to provide a list of possible words. I am including that “C” source here. I have written several variations on the theme in several different languages. I am fond of this version, as it was the first. After writing it, the first modification I made was to pass all of the results through the dictionary aspell. What was always amazing to me was that there was always one and only one solution to the Jumble.

You may need to install apt-get install libaspell-dev for this to work. I also use a Makefile to build this.

gcc -O -laspell -c jumble.c
gcc -O -laspell jumble.o -o jumble

/*
 * Created by: Kenneth Lee (kelee@nyx.net)
 * Created on: May, 1993
 * jumble - finds permutations of letters
 *
 * Updated by: kelee@nyx.net
 * Updated on: 20-Apr-2009
 * Added ability to only display correctly spelled words by running each
 * word through the aspell spell checker available on Linux distibutions.
 * To compile, needed to get the aspell-devel libs to have the aspell.h 
 * header files available. 
 * 
 *
 */
 
#include <stdio.h>
#include <string.h>
#include "aspell.h"


void perm(char temp[], int r_value) {
  int count;
  char temp1[20];
  char temporary;
  int correct;

	// int correct = aspell_speller_check(spell_checker, word, size);
	AspellConfig * spell_config = new_aspell_config();
	aspell_config_replace(spell_config, "lang", "en_US");
  AspellCanHaveError * possible_err = new_aspell_speller(spell_config);
  AspellSpeller * spell_checker = 0;
  if (aspell_error_number(possible_err) != 0) {
    puts(aspell_error_message(possible_err));
  } else {
    spell_checker = to_aspell_speller(possible_err);
  }  

  // prints first case
  if (r_value==(strlen(temp)-1)) {
     correct = aspell_speller_check(spell_checker, temp, strlen(temp));
     if (correct > 0) {
	     printf("%s\n", temp);
	   }
	}
	
  for (count=r_value;count>=0;count--) {
     strcpy(temp1, temp);
     if (r_value != count) {
        temporary=temp1[count];
        temp1[count]=temp1[r_value];
        temp1[r_value]=temporary;
		    correct = aspell_speller_check(spell_checker, temp1, strlen(temp1));
		    if (correct > 0) {
	        printf("%s\n", temp1);
	      }  
     }
     if ((r_value-1)>0)
        perm(temp1,r_value-1);
  }
}

int main() {
  char data[20];
  printf("\nEnter letters to be unscrambled: ");
  scanf("%s", data);
  perm(data,strlen(data)-1);
  printf("\n");
}
 

MD5 hash using Perl

Written by klee on May 12th, 2014

Earlier, I demonstrated using groovy with a simple bit of code to create an MD5 hash. Here is a Perl version, notice how little code is used.

#!/usr/bin/perl
use strict;
use warnings;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use Digest::SHA qw(sha1 sha1_hex sha1_base64);
use MIME::Base64;
my $password;
if (scalar @ARGV eq 1) {
	$password = shift;
} else {
	$password = "password";
}
print "MD5 hex digest of $password = ",md5_hex($password), "\n";  # human-readable
print "MD5 base64 digest of $password = ",md5_base64($password), "\n";  # human-readable too
print "SHA1 hex digest of $password = ",sha1_hex($password), "\n";  # human-readable
print "SHA1 base64 digest of $password = ",sha1_base64($password), "\n";  # human-readable too

Pretty cool, and this code runs on just about any linux/unix machine. In Windows, I ran the code using Strawberry Perl.

 

RMOUG 2014

Written by klee on January 3rd, 2014

If you are in the Denver area February 5 – 7, consider going to Rocky Mountain Oracle Users Group’s Training Days. This must be the best deal for two days of sessions on just about every facet of Oracle.

Date: February 5-7
Location: Denver Convention Center

Hope to see you there!

 

Moving On Again

Written by klee on April 14th, 2013

I have changed employers, as if you couldn’t tell by the scarcity of posts over the last nine months! I am no longer working with Oracle Content Server. Other than the difficult to use Site Studio, I believe Content Server is a really great platform to drive data management. But all good things do come to an end eventually.

I am currently working with very large datasets on Oracle. I also write more shell script code, mostly Korn shell and also perl for more complex tasks. I was never a fan of perl, as many are not fans of Java. I have a new found respect for this all purpose Swiss Army Sledge Hammer!

I will more than likely be changing the title of this Blog as WebCenter Content is no longer the focus of my work. More likely to be Java/SOA and Quick Hacks to get the job done, or something along those lines.

For those that were curious, I actually took the photo that is displayed at the top of this Blog. This is one of my favorite catch and release fishing spots located just a few miles north of Lake City, Colorado. Hope to be back there soon!

 

Groovy, well, is just groovy.

Written by klee on June 15th, 2012

At some point in your programming career, you will probably need to use an MD5 hash. Most likely just to get the hash for a password.

One of the simplest ways is to use groovy. Here is the code. Don’t even need to put it in the download section. Just copy the code to a file and run it.

import java.security.MessageDigest

srcWord = "password"

if (args.length > 0) {
	srcWord = args[0]
}

println "src: " + srcWord
MessageDigest md5Digest;
byte[] digest;

println "\n****************************************\n"

/* MD5 Code */
md5Digest = MessageDigest.getInstance("MD5");
md5Digest.reset();
md5Digest.update(srcWord.getBytes());
digest = md5Digest.digest();

// println "new BigInteger(1,digest).toString(): " + new BigInteger(1,digest).toString()
println "MD5: " + new BigInteger(1,digest).toString(16)
println "MD5/B64: " + digest.encodeBase64().toString()

println "\n****************************************\n"

/* Now do the same thing for SHA-1 */
md5Digest = MessageDigest.getInstance("SHA-1");
md5Digest.reset();
md5Digest.update(srcWord.getBytes());
digest = md5Digest.digest();
// println "src: " + srcWord
// println "new BigInteger(1,digest).toString(): " + new BigInteger(1,digest).toString()
println "SHA-1: " + new BigInteger(1,digest).toString(16)
println "SHA-1/B64: " + digest.encodeBase64().toString()

println "\n****************************************\n"

/* Now do the same thing for SHA-256 */
md5Digest = MessageDigest.getInstance("SHA-256");
md5Digest.reset();
md5Digest.update(srcWord.getBytes());
digest = md5Digest.digest();
// println "src: " + srcWord
// println "new BigInteger(1,digest).toString(): " + new BigInteger(1,digest).toString()
println "SHA-256: " + new BigInteger(1,digest).toString(16)
println "SHA-256/B64: " + digest.encodeBase64().toString()

println "\n****************************************\n"

/* Now do the same thing for SHA-512 */
md5Digest = MessageDigest.getInstance("SHA-512");
md5Digest.reset();
md5Digest.update(srcWord.getBytes());
digest = md5Digest.digest();
// println "src: " + srcWord
// println "new BigInteger(1,digest).toString(): " + new BigInteger(1,digest).toString()
println "SHA-512: " + new BigInteger(1,digest).toString(16)
println "SHA-412/B64: " + digest.encodeBase64().toString()

println "\n****************************************\n"
 

UCM: Search, GetFile, Checkin with PL/SQL

Written by klee on June 5th, 2012

“Proof of concept” programming in many cases is the first draft of a finished product. Several of my starter programs are in the download section of this blog. They are PL/SQL programs that demonstrate simple Checkin, GetFile, and Search functionality. Besides using RIDC, when needing to retrieve content or Check-in content, these little programs can really help.

These are just proof of concept programs, so you will need to add any additional logging. Also, this program uses functionality originally found in flex_ws_api. This can be found on Jason Straub’s blog. Flex_ws_api has also been incorporated into Oracle’s Application Express in the APEX_WEB_SERVICE API. This code has also found its way into Alexandria, a PL/SQL Utils library.

With just a few additional lines of code, you can pull documents out of a database, and check them into UCM. All with PL/SQL code.

 

Database Hick-up

Written by klee on May 22nd, 2012

I lost posts going back to November 2011. I have the titles, so I will try to recreate some of this content in the next few days. 🙁

 

Website launch delayed. It wasn’t me, really!

Written by klee on August 18th, 2011

UCM website launch was delayed until September 6th. Now that there are containers and departments are responsible for their own data, the launch progress came to a crawl. People are finally realizing that there is work involved in owning your own data. What a surprise… NOT!

Still working full speed+ on the website, and it is looking good. Now if we could only speed up the searches!

So far, the best piece I coded was the lunch menu display. I used two jQuery plugins: A calendar component, and prettyPhoto. I display the food being served each day in schools in the jQuery calendar plugin. The data was created in an APEX application to populate the backend tables. A little materialized view magic later, and the data is available as a JSON feed from a service call to UCM using the IsJson=1 parameter on the service. I use pretty photo to display a list of food properties (similar to the side panel of a cereal box), and a graphic – also fed by a UCM service call. I’ll post the code for the calendar and popup display with a mockup JSON file for data in a few days. I spent way to much time getting this just right. Better to do a job right the first time, then to spend additional days, sometimes weeks coding again…