Moire Pattern

a moire pattern generated by a java program
a moire pattern generated by java code

 

 Click on the moire pattern to see the full size image

You can see the code for the java program that generated this image here

Seamus.

java.util.Calendar ~ what day of the week is it?

I’m new to Java and i had a bit of a problem trying to work out what day of the week it is/was. i’d been using java.util.Date to no avail. Then I discovered (well, it was new to me) java.util.Calendar. It was just what i needed. Here’s a bit of code i used to check it worked:

package miniCalendarExperiment;

import java.util.Calendar;
import java.util.Date;

/**
*
* @author Seamus @ bearsbreeches.com
*/

public class WhatDay {

public static void main(String[] args) {

Calendar myCal = Calendar.getInstance();
String dayOfWeek = null;

switch (myCal.get(Calendar.DAY_OF_WEEK)) {
case Calendar.MONDAY:
dayOfWeek = "Monday";
break;
case Calendar.TUESDAY:
dayOfWeek = "Tuesday";
break;
case Calendar.WEDNESDAY:
dayOfWeek = "Wednesday";
break;
case Calendar.THURSDAY:
dayOfWeek = "Thursday";
break;
case Calendar.FRIDAY:
dayOfWeek = "Friday";
break;
case Calendar.SATURDAY:
dayOfWeek = "Saturday";
break;
case Calendar.SUNDAY:
dayOfWeek = "Sunday";
break;
}

System.out.println("Today is a "+ dayOfWeek);
}
}

Enjoy,

Seamus.

Java Moire Pattern

I’ve never used any of the Java graphics APIs before. What better way to get started than to create a very simple program that creates a moire pattern and writes that moire pattern to a file ( a PNG file).

Here’s the code:

package com.bearsbreeches;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Main {
public static void main(String[] args) {

int xMax = 768;
int yMax  = xMax;
int step = 4;

// Change the fileName below to whatever suits you.
String fileName = "c:\\moire.png";

BufferedImage bi = new BufferedImage(xMax, yMax, BufferedImage.TYPE_INT_RGB);

Graphics g = bi.getGraphics();

Graphics2D g2 = (Graphics2D) g;

g2.setStroke(new BasicStroke(1));
g2.setColor(Color.WHITE);

// Uncomment the line below to create an anti-aliased image. Can look good.
//g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

for (int x = 0; x <= xMax ; x += step)
{
g2.drawLine(x,0,xMax - x,yMax);
}

for (int y = 0; y <= yMax ; y += step)
{
g2.drawLine(0,y,xMax,yMax-y);
}

g2.drawImage(bi, 0, 0, null);

try {
ImageIO.write(bi,"PNG",new File(fileName));
} catch (IOException e) {
e.printStackTrace();
}
}
}

I know its no use but i enjoyed doing it..

Seamus.

Save money when you its time to renew your Norton Internet security Subscription

Its that time of year. The time of year when my Norton Internet Security subscription expires. This time round though things were a little bit different. Instead of renewing online I decided to shop around and see if I could save some money. [Un]Surprisingly i managed to save myself £15 (GBP). I should add that I have the subscription that covers three PCs for one year.

First of all i checked out Symantec’s offer. For £39.99 they would renew my subscription. Not bad but not great. When i first purchased NIS I paid £30. £39.99 for another year was, t me, a little steep.

Next I popped into PC World. They were flogging a subscription for £40. Same as the online price. At this point i almost cracked but a fellow shopper told me – to the chagrin of the chap in PC World – that Tesco were selling the very same product for £24.50 but there weren’t many left. I usually avoid Tesco (not for political reasons but because its usually packed to the rafters with irate shoppers).  Anyway, I scooted round there, and managed to pick the last copy on display for the afore-promised £24.50.

I had a look online when i got home on Amazon and couple of other sites. There were vendors selling this bit of software for less but i needed the subscription now rather than in a few days time. Anyway, i’m happy and i feel i got a good deal.

So, the moral of this story is shop around!
Seamus.

How to Change Timezone of Oracle VM Server 3.2

If you want to change the timezone of your Oracle VM Server and – like me – are a little bit puzzled by how to do it then take a peek at this Article by Redhat which tells you exactly what you need to know and do. Its written with Redhat Linux in mind but as Oracle VM is pretty much a Redhat Linux server you’ll find that the instructions work. Well, i’ll qualify that, applied the instructions to an installation of Oracle VM Server 3.2.7. Others should work though.

You can find the link here.

Best of luck,

Seamus.

Free Upgrade to OS X Mavericks

Here’s a new one from Apple. A Free upgrade OS X Mavericks provided your on Snow Leopard or higher and your hardware is up to scratch (more details on that can be found at the link at the bottom of this article) . I’d managed to avoid to relatively inexpensive upgrades to Lion and Mountain Lion but now, well, a free upgrade was to good to miss.

The good is news is that the upgrade worked first time and Mavericks has, so far, been pretty stable.

You can find the instructions and other info at https://www.apple.com/uk/osx/how-to-upgrade/

 

Good luck with your upgrade!

Seamus

Oracle VM 3.2.2 Server Loses Default Route After Reboot

If, like me, you’ve spent a great deal of time getting your shiny new Oracle VM cluster set up only to find that after rebooting one or more of the cluster members, networking no longer works for that member server then read on… for a potential solution..

In my case it looked like the default route had gone walkabout. I couldn’t ping anything except the ip address assigned to the ac180800 interface (an Ethernet bridge, apparently).

I’ll be honest with you. I’m not a Linux network expert. So, I had a poke around and gave the following a go:

route delete default
route add default gw xxx.xxx.xxx.xxx ac180800

Much to my surprise networking came back to life. So I added the two lines to the end of my rc.local file. Rebooted again and it worked! I tried various combinations of editing files in /etc/sysconfig but got nowhere. Anyway, this works for me. For now at least. Going to hit metalink (or MOS) and look for an official fix for Oracle VM loses default route after a reboot when I get back to work tomorrow.

Encrypt and decrypt with the Java 6 Crypto API ~ javax.crypto

Here’s bit of Java code which uses the Java 6 Crypto API classes and functions to encrypt and decrypt a string. The code encrypts a string using AES, decrypts it again and then displays the plaintext, the cipher text and the decrypted text.

Can’t guarantee the code is ‘correct’ but it seems to do what it says on the tin.

 

import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class myFirstEncryptionCode {

     public static void main(String[] args) {

          String plainText = "This is a plaintext message. You should be able to read this.";

          try {
               // Encrypt ze plaintext..
               SecretKey mySecretKey = KeyGenerator.getInstance("AES").generateKey();
               Cipher myCypherOut = Cipher.getInstance("AES");
               myCypherOut.init(Cipher.ENCRYPT_MODE, mySecretKey);
               byte[] cipherText = myCypherOut.doFinal(plainText.getBytes());

              // And Now Decrypt ze plaintext
              Cipher myCypherIn = Cipher.getInstance("AES");
              myCypherIn.init(Cipher.DECRYPT_MODE, mySecretKey);
              String decryptText = new String(myCypherIn.doFinal(cipherText);

              // Display the plaintext, cipher text et al.
              System.out.println("PlainText: " + plainText);
              System.out.println("Encrypted Text: " + new String(cipherText, "UTF-8"));
              System.out.println("Decrypted Text: " + decryptText);
          } catch (Exception ex1)
          {
              System.out.print(ex1.toString());
          }
     }
}

3DS Will Not Power on even though it is charged — how to fix it (maybe)

My 3DS wouldn’t power on this morning. I hadn’t used it for a week. I guess the battery was as flat as a pancake. After charging the 3DS for an hour it still wouldn’t power on (it was still plugged into the mains and charging as far as I could tell).

Hmm. That’s a bit weird I thought. In a fit of desperation/pique I removed the game card (Mario Kart 7) and I removed the SD Card too. I immediately tried to power on the 3DS and bingo it came on first time. I powered it down again, put the SD card and game card back in and bingo, it powered up again.

Phew.

 

Seamus

The Bears Breeches

 

 

Fix Database Won’t start due to invalid parameter in spfile.

Hmmm. Database Won’t start due to invalid parameter in spfile.. hmm..

This is a quote from appsdba.comWhen using an SPFILE it is possible to get into the situation where the database won’t start due to an invalid parameter, and since the database won’t start it is not possible to fix the SPFILE.

I got into this situation this morning. Its very very frustrating but relatively straightforward to fix. Here goes.

Step 0: Check for a pfile equivalent of your spfile! If it exists then start the database using startup pfile=/path/to/pfile and issue a create spfile from pfile when the database starts and then restart your database. Bingo. Amend your spfile parameters at your leisure. If you haven’t got a pfile then read on..

Step 1: find your spfile. If you don’t know where this is you’re goose is already cooked. It usually lives in $ORACLE_HOME/dbs and is called spfile<ORACLE_SID>.ora though yours may have a different name. In my case the ORACLE_SID is TEST so my spfile is called spfileTEST.ora. 

Step 2: Back up your spfile (and pfiles too).

Step 3: Open a command prompt, navigate to the directory containing your spfile and type strings spfile_name > $ORACLE_HOME/dbs/temp_pfile.ora (this creates a pfile not an spfile!!). If the spfile file is in $ORACLE_HOME/dbs then rename the spfile to something you’ll remember…  IF the spfile is stored within ASM then login as the ASM owner, start asmcmd and use the cp command to copy the file to a directory your database/instance owner can read and run strings /path/to/spfile/spfile_name > $ORACLE_HOME/dbs/temp_pfile.ora.

Step 4: open temp_pfile.ora with a text editor and check its parameters. Tidy up incomplete entries and amend offending entries where appropriate. (I’d accidentally reduced one of the memory parameters from 24G to 2G preventing the instance from starting up).

Step 5: try starting up the database.. startup pfile=/path/to/file/temp_pfile.ora should do the trick. If the instance starts shut it down immediately (shutdown immediate should do the trick). If the instance doesn’t start then check your parameters and try again!

Step 6: rename temp_pfile.ora to init<ORACLE_SID>.ora. Mine is called initTEST.ora.

Step 7: startup the database again. once its started type create spfile from pfile and press enter.

Step 8: Restart the database. Your database should now start up but this time its using the newly created spfile.

Step 9: Take applause from your colleagues and count your lucky stars.

 

This document was typed rather hastily on a train on my way home. If you spot a mistake please let me know.

 

Enjoy,

Seamus