Wednesday, December 30, 2009

New Menu Using jQuery

I wasn't happy with the existing title menu that spread across the top of the screen but didn't provide much value. There was a lot of blue gradient with no content, especially on very wide screens. It needed to be changed.
What I was hoping for was an expanding menu with a small foot print, kind of like the Windows 7 jewel. At first I started shuffling around some divs with homemade dhtml, but that was a pain. I'm not sure where I came across jQuery, but it solved all the problems I was having; working in different browsers, easy syntax, minimal code, etc. It's really a nice library, and I can see why it was so highly recommended.
So the new menu contains 2 parts. The first part is a little icon that, when clicked, shows the navigation. It expands it to fit and I was very surprised at how easy it was. Essentially, this is all the code needed:

<script type="text/javascript" src="/includes/jquery132.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#slider").hide();
$("#button").toggle(function() {
$("#slider").show("fast");
},function(){
$("#slider").hide("fast");
});
$("#slider h1").click(function() {
$("$slider").hide("fast");
});
});
</script>
I hope you like the little icon and new menu. Try it by clicking him in the upper left. I'm definitely going to look into jQuery more for cool dynamic webpages or if I need to have javascript do other magical things.

Tuesday, December 22, 2009

Mom's Rhubarb Muffins & Bars

Found some rhubarb recipes while cleaning house. Image from Time Online UK.

Rhubarb Muffins

Makes 18 muffins or 2 large loaves.

1 1/2 cups brown sugar
2 1/2 cups flour
1 tsp baking soda
1 tsp salt

2/3 cup vegetable oil
1 egg
1 cup milk
1 tsp vanilla extract

1 1/2 cups diced rhubarb
1/2 cup nuts

Cinnamon and sugar

Mix sugar, flour, soda, and salt together in a bowl that will hold everything. Mix oil, egg, milk, and vanilla in another bowl. Mix wet mixture into dry. Fold in rhubarb and nuts. Pour into greased muffin pans or loaf pans. Sprinkle top with cinnamon and sugar.
Bake muffins at 350 degrees for 20-25 minutes.
Bake loaves at 350 degrees for 40-45 minutes.

Rhubarb Bars

Makes a 9x13 pan

Crust
2 cups flour
1/2 cup margarine or butter
1/2 cup shortening
2 tbsp sugar

Mix, mash, and bake into bottom of 9 by 13 pan, 375 degrees for 15 minutes.

Filling
3 cups rhubarb
1 1/2 cup sugar
2 tbsp flour
1/2 cup cream
1/3 cup orange juice

Meanwhile, in a large saucepan cook all filling ingredients till thick. Remove from heat and blend in 3 egg yolks.

Meringue
3 egg whites
6 tbsp white sugar

There's probably more instructions, but that's all ma wrote. Maybe she wants you to use your powers of deduction.


Friday, December 18, 2009

Hubble Ultra Deep Field Background

After reviewing Boston Big Picture's Decade in News Photographs, I was reminded how awesome the Hubble Ultra Deep Field photo was. And since I like dark backgrounds, I just figured I'd make some wallpaper to share. This one is 1680 x 1050. The original is available through Wikipedia.



From Random Awesomeness

Thursday, December 10, 2009

Odd Number Counter Finder 3000

So after bombing an Amazon technical interview because I couldn't remember syntax and the efficiencies of data structures, it seemed like a good idea to fix that. So here's the question and the code I'm going to say is correct. I'm still reviewing the java documentation, but if you have suggestions please comment.

Create and test a function that accepts a positive integer array and returns the value that appears an odd number of times. There should only be one integer in the array that has an odd number of occurences.

Here's some broken code below. I realize this accepts non-positive integers, has bad commenting, and other issues, but my biggest question is if I'm using the most efficient data structures.



RunTests.java




import java.lang.reflect.Array;
public class RunTests {
public static void main(String[] args) {
OddNumberFinder onf = new OddNumberFinder();

TestCase[] testCases = {
new TestCase(new int[] {1}, 1),
new TestCase(null, 0),
new TestCase(new int[] { 1, 1, 2, 2, 3 }, 3),
new TestCase(new int[] { 1, 1, 0, -1, -1 }, 0),
//new TestCase(new int[] { 'a', 'b', 'c' }, null),
//new TestCase(new int[] { }, null),
//new TestCase(new int[] { 1, 1 }, null)
};

for(int i = 0; i < testCases.length; i++) {
TestCase tc = testCases[i];
try {
System.out.print("For test set ");
System.out.print(tc.toString());
System.out.println(" the odd value is " +
onf.FindOddNumber(tc.numberSet));
}
catch (Exception e) {
System.out.println("Exception");
}
}
}
}


OddNumberFinder.java



import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map;
import java.lang.Exception;

public class OddNumberFinder {
public OddNumberFinder() {
}

public int FindOddNumber(int[] numbers) throws Exception {
int numbersLength = numbers.length;

//ArrayList counts = new ArrayList(); // what do I use? map?
HashMap counts =
new HashMap(numbersLength);

for(int i = 0; i < numbersLength; i++) {
int key = numbers[i];
int newValue = 0;
if(counts.containsKey(key)) {
newValue = (Integer) counts.get(key) + 1;
}
else {
newValue = 1;
}
counts.put(key, newValue);
}
Set countSet = counts.entrySet();


Iterator i = countSet.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
if((Integer)me.getValue()%2 != 0) {
return (Integer)me.getKey();
}
}

throw new Exception();
}
}


TestCase.java



public class TestCase {
public int length;
public int[] numberSet;
public int expectedValue;

public TestCase(int[] numberSet, int expectedValue) {
this.numberSet = numberSet;
this.expectedValue = expectedValue;
}

public String toString() {
String s = "{";
for(int i = 0; i < numberSet.length; i++) {
s += numberSet[i];
// Add a comma unless we have reached the last of the set.
if(i != numberSet.length - 1) s += ", ";
}
return s + "}";
}
}

Monday, December 7, 2009

Mobius Bagel

The wonderful worlds of food and mathematics have merged in a marvel of thought and engineering.

Behold!


The Mobius Bagel

Mobius Bagel

Its glorious conception and instructions are here: http://www.georgehart.com/bagel/bagel.html