Sunday, December 11, 2011

Arduino + Rotary Encoders, rev2

This version of the rotary encoder code handles the random misreading and also has a 2 stage debouncer to help minimize the annoyance of the big debounce time. Here's the code:

/* 
   read a rotary encoder with interrupts
   Encoder hooked up with common to GROUND,
   encoderPinA to pin 2, encoderPinB to pin 3
   it doesn't matter which encoder pin you use for A or B  

   uses Arduino pullups on A & B channel outputs
   turning on the pullups saves having to hook up resistors 
   to the A & B channel outputs
   
   initially based on http://www.arduino.cc/playground/Main/RotaryEncoders
*/ 

#define encoderPinA 2
#define encoderPinB 3
#define interruptPin 0

const long encoderDebounce = 175;
const long encoderDebounceFast = 10;
const long encoderFastTimeout = 200;
const int encoderStepsTilFast = 2;
long nextEncoderTime = 0;
boolean encoderActive = false;
int encoderLastDirection = 0;

void setup() { 
  pinMode(encoderPinA, INPUT); 
  digitalWrite(encoderPinA, HIGH);
  pinMode(encoderPinB, INPUT); 
  digitalWrite(encoderPinB, HIGH);
  attachInterrupt(interruptPin, startEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);
  Serial.println("start");
} 

void loop() {
  if (encoderActive) {
    encoderActive = false;
    long now = millis();
    if (now > nextEncoderTime) {
      //reset fast debounce since there was a pause
      if (now > nextEncoderTime + encoderFastTimeout) {
        encoderLastDirection = 0;
      }
      int a = digitalRead(encoderPinA);
      int b = digitalRead(encoderPinB);
      int encoderDirection = 0;
      if (a == b && a == HIGH) {
        encoderDirection = 1;
      } else if (a != b && b == HIGH) {
        encoderDirection = -1;
      } else {
        encoderDirection = 0;
      }
      boolean fastMode = abs(encoderLastDirection) > encoderStepsTilFast;
      //if we get a random direction change while fast, ignore it
      if (fastMode
            && (encoderLastDirection > 0 && encoderDirection < 0
            || encoderLastDirection < 0 && encoderLastDirection > 0)) {
        encoderDirection = 0;
      }
      encoderLastDirection += encoderDirection;

      if (encoderDirection != 0) {
        nextEncoderTime = now + (fastMode ? encoderDebounceFast : encoderDebounce);
        Serial.println(encoderDirection);
      }
    }
  }

}

void startEncoder() {
  encoderActive = true;
}

Arduino + Rotary Encoders, rev1

After a few days of reading forums of how people can't get accurate results from a rotary encoder from an arduino, I finally figured out a way to make it work for me. In my application, its ok to drop a few "ticks" of the encoder but I really wanted to avoid over-counter and much worse, count in wrong direction. Other solutions often cause both when rotating at slow speeds. Attached is my 1st implementation that only uses the interrupt to notify the arduino that it should look at the encoder pins and instead uses the program loop to read the values. This may not be optimal for code that uses excessive delays but it works well for my application.

/* 
   read a rotary encoder with interrupts
   Encoder hooked up with common to GROUND,
   encoderPinA to pin 2, encoderPinB to pin 3
   it doesn't matter which encoder pin you use for A or B  

   uses Arduino pullups on A & B channel outputs
   turning on the pullups saves having to hook up resistors 
   to the A & B channel outputs
   
   initially based on http://www.arduino.cc/playground/Main/RotaryEncoders
*/ 

#define encoderPinA 2
#define encoderPinB 3
#define interruptPin 0

// we can probably have 2 stage debounce where 2nd stage 
// debounce lower when a few ticks in same direction
const long encoderDebounce = 150;
long nextEncoderTime = 0;
boolean encoderActive = false;

void setup() { 
  pinMode(encoderPinA, INPUT); 
  digitalWrite(encoderPinA, HIGH);
  pinMode(encoderPinB, INPUT); 
  digitalWrite(encoderPinB, HIGH);
  attachInterrupt(interruptPin, startEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);
  Serial.println("start");
} 

void loop() {
  if (encoderActive) {
    encoderActive = false;
    long now = millis();
    if (now > nextEncoderTime) {
      int a = digitalRead(encoderPinA);
      int b = digitalRead(encoderPinB);
      int encoderDirection = 0;
      if (a == b && a == HIGH) {
        encoderDirection = 1;
      } else if (a != b && b == HIGH) {
        encoderDirection = -1;
      } else {
        encoderDirection = 0;    
      }
      if (encoderDirection != 0) {
        Serial.println(encoderDirection);
        nextEncoderTime = now + encoderDebounce;
      }
    }
  }

}

void startEncoder() {
  encoderActive = true;
}

As you can see if relies heavily on a high debounce time. If I reduce the debounce time to less than 50, I get lots of double-counts on slow rotations so I just played it safe and set it really high. I'll address the limited count speed in my next post.

Friday, December 02, 2011

JavaJson

http://javajson.thedeanda.com is a great little open source JSON parser I wrote a few years ago. I've used it in lots of little projects including Android development. The project is hosted at sourceforge.

Monday, August 15, 2011

Count the problems...

public class CacheRegionType
    extends AbstractConstants 
    implements CompanyNameTypeConstants, Serializable 
{
...
}

Another gem.

Monday, August 08, 2011

Somebody shoot me please!

So I ran into this today...



package com.blahblahblah.defaults;


import com.blahblahblah.FileContents;


public class ProfileImageUnavailableDefaultFile implements FileContents {
public String getOriginalFilename() {
return "unavailable.jpg";
}


static byte[] bytes = null;


public byte[] getBytes() {
if (bytes == null) {
byte[] output = new byte[5159];
int count = 0;
for (int i = 0; i < FileBytes0.PART.length; i++) {
output[count] = FileBytes0.PART[i];
count++;
}
bytes = output;
}
return bytes;
}


static class FileBytes0 {
public static byte[] PART = new byte[] { -119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, -56, 0, 0, 0, -56, 8,
2, 0, 0, 0, 34, 58, 57, -55, 0, 0, 0, 25, 116, 69, 88, 116, 83, 111, 102, 116, 119, 97, 114, 101, 0, 65, 100, 111, 98, 101, 32,
73, 109, 97, 103, 101, 82, 101, 97, 100, 121, 113, -55, 101, 60, 0, 0, 19, -55, 73, 68, 65, 84, 120, -38, -20, -99, 9, 115,
-37, 54, 22, -57, 41, -118, -94, 14, -33, 113, -30, 58, 118, 115, -72, 77, 102, -46, 108, -90, -99, -23, -41, -18, 103, -39,
105, 55, 77, -109, -116, -69, -101, -61, -15, -95, 91, 20, 69, -119, 55, -71, -113, 98, 34, -85, -78, 40, -126, 36, 64, -126,
36, 48, 29, 79, 35, 83, -78, 68, -4, -12, 127, 127, 60, 60, 0, -107, -33, 126, -5, 77, 16, 4, -114, -75, 2, 53, -41, 117, 17,
31, 15, -70, 50, -24, -126, -27, 127, 6, -3, 63, 52, -45, 52, -123, -109, -109, -109, -99, -99, 29, -42, 25, -123, 103, 8,
-111, -83, -51, -88, 33, 114, 38, -53, -78, 0, 84, 29, 28, 28, -80, 30, 98, 96, 33, -94, -122, 40, 90, 60, -21, -101, 92, -73,
74, -91, -110, -16, -15, -96, 43, 19, -66, 19, 6, 86, -23, -40, -118, -6, -126, 27, -2, -71, -31, 79, 48, -80, 74, -57, 22, 57,
-47, 98, 96, -107, -120, 45, -20, 42, -75, 65, -76, -106, -1, -97, -127, 85, 112, -74, -48, 31, -60, -5, 30, 24, 88, -116, 66,
36, -107, -38, 112, -15, -38, 43, 25, 88, 37, 21, 45, -46, -95, -106, -127, -59, 2, 98, 76, -47, -38, 44, 96, 12, 44, -42, -16,
24, 124, -90, 88, 76, -76, -120, -69, 120, 120, 89, 6, 22, 107, -8, -13, 14, 76, -79, -104, 104, -111, 18, 45, 6, 22, 107,
-119, 68, 43, -24, 87, 12, -84, 114, -119, 22, -106, 84, 2, -54, 115, 25, 88, -116, 54, 34, -49, 98, 96, 49, -89, 21, -103, 36,
-108, 104, -56, -64, 98, -115, 72, 52, 100, 96, 49, -47, -118, 99, -31, 89, 40, 100, -115, -120, 104, -123, 70, 67, 6, 22, 35,
-122, -56, -72, -110, -127, -59, 104, -61, -32, -39, -17, 94, -55, -64, 98, 13, 15, -102, 108, 74, -121, 65, -112, 70, 99, 96,
49, -38, -120, -116, 13, 25, 88, 12, 35, 34, -38, -58, -64, 98, -115, -120, -51, 98, -37, -127, -124, -33, 59, -65, -83, 44,
39, 15, -35, 78, 35, 47, -97, 46, -12, -125, -84, 92, -125, -14, 20, 6, -42, -70, 113, 50, -49, 47, -66, 121, -2, 29, 52, 77,
-45, 48, 76, -41, -1, -105, -53, -119, -94, 32, -118, -30, -54, 53, 28, -62, -50, 45, 69, -94, -115, -127, 21, -103, 39, 77,
55, -90, -45, -103, -86, 105, -70, 110, 40, -54, -44, 39, -58, 113, 93, 110, 89, -91, -26, 87, 54, 27, -11, -70, 40, 54, 27,
-115, -19, -99, -83, -83, 86, 19, 75, 127, -48, 79, 12, 3, 11, -11, 94, 87, -85, 85, -8, 105, -102, -42, 96, 52, 26, -113, 39,
-102, -90, 89, -106, 109, -37, 14, 52, -97, -88, -69, -126, -28, 35, 104, 24, 70, -123, -85, -8, -1, -128, -41, -40, -37, -35,
125, 120, 124, 4, -84, -91, 63, -74, 79, 57, 26, -94, 4, -54, 82, -125, 5, 42, 5, 84, -127, 50, 117, -70, 61, 73, -98, -104,
-122, 105, -103, -106, 13, 48, 57, -34, -83, -39, 112, -77, -65, -34, -54, -7, 85, 62, 68, -74, -51, -11, -6, 67, -8, -81, 46,
-42, -98, 62, -3, 126, 119, 103, 39, 95, 120, 97, 103, 81, 40, -77, 80, -63, -67, -23, -11, 6, -19, 110, 95, -41, 117, 80, 44,
79, -94, -94, -65, -44, -54, 83, 52, -61, 124, 127, -2, 113, -85, 89, 127, -2, -20, 108, -39, -118, -27, 43, 26, 38, 15, -102,
124, 57, -87, -86, -43, 106, 64, -46, -25, -117, -85, -53, -21, 54, 56, 42, 16, 45, 59, 22, 85, 65, 109, -86, -22, 127, -68,
126, -37, -21, 15, 114, -31, -24, -39, 110, 51, -40, -88, 2, -110, 62, 126, -2, 50, 24, 12, -63, -92, -125, -95, 34, -46, -7,
21, -2, -61, -89, 47, -97, 63, 95, -128, 16, 22, 27, -93, -75, -39, -84, -46, -127, 37, 8, -126, 110, 120, 84, -55, -78, 98,
24, 38, 86, -99, -70, 123, -57, -7, 118, 111, -8, -31, -29, 71, -38, -40, -118, -115, 11, 83, -84, -11, -51, -13, 85, -82, -5,
-23, -45, 37, 80, 101, -102, -90, 67, 62, 78, 1, 91, -3, -95, 124, 113, 113, 81, -104, 44, 23, 106, -6, -90, 108, 99, -64, -85,
-21, -10, 68, 73, -119, -86, 5, 91, 87, -41, -35, -63, 96, 80, 36, -74, 66, 5, -84, 68, 96, 1, 85, 35, 73, 30, 12, 37, -61, 48,
-100, 116, -5, 88, 16, -21, -17, -34, -97, -61, -40, -109, 90, -74, -80, 27, -81, -78, -128, 5, 114, 5, -99, -38, -23, -10, 52,
77, 39, -22, -85, -126, 90, 77, 108, -68, 125, -9, -114, 18, -80, 82, 72, -126, -108, 5, 44, -112, -85, -31, 104, 60, -101,
-86, 54, -95, 49, 96, -8, 24, -79, 58, 30, 43, -29, -15, -72, 36, 102, -85, 20, 96, -127, 92, 65, -20, -21, -11, -121, -23, 7,
-63, -27, -42, 108, 109, -99, -97, -1, -99, 35, -80, -30, -19, -38, 80, 34, -80, 64, -82, 20, 101, -86, 105, -102, -99, -23,
-80, 31, 68, 107, -94, 76, 101, 89, 46, -125, 104, 21, 31, 44, -1, -53, 52, 24, -116, 64, -82, 50, -17, -47, 102, 115, -21,
-30, -30, -126, -123, -62, -126, -128, 101, 89, -106, 50, -99, 101, -27, -82, 86, -122, -121, -35, 110, 15, 16, 47, -4, -64,
-80, -8, 96, 65, 28, -100, -50, 84, 96, -117, -110, -8, 3, -63, -72, -112, 22, -66, -116, -53, -65, 96, 48, 104, 89, 54, 37,
125, 89, -85, -127, 104, 117, 11, -96, 79, 108, 115, 91, 110, 50, -99, -46, 16, 7, -3, 86, -81, 55, 6, -125, 1, -68, -97, 60,
-22, 16, 11, -123, -73, -9, 5, -70, 80, -41, 117, -57, -91, 101, 26, -72, 42, -44, 102, 51, -43, 52, 77, 102, -34, -13, 109,
-80, 52, -35, -80, 109, -121, -93, -55, -46, 84, 120, 94, 85, -43, 98, 39, 29, -118, 31, 10, 53, 77, -9, -30, 32, 77, -67, 88,
-83, 10, -32, -33, -117, 61, 48, 44, 62, 88, 30, 85, -114, 75, 89, -1, -15, -123, 79, -109, 22, 31, 44, -45, 48, -23, 49, 88,
-117, 0, 13, -95, 48, -113, -6, -124, -66, -49, 81, -15, -63, -46, 77, -125, 54, 105, 0, -1, -18, -115, 39, 114, 88, 86, -54,
20, 107, -87, -7, 75, 77, 105, -45, 81, -45, 100, -95, 48, -1, 30, -117, -74, -101, -50, -13, -50, -68, -27, -17, 75, -118, -4,
101, 40, 62, 88, -86, -82, 115, -108, 121, -84, -102, 88, -89, 109, -96, -54, 20, 43, 122, -93, 43, -121, 117, -85, -93, 121,
73, -66, 51, -80, 2, 45, 22, -115, -76, -25, 51, 20, 50, -80, 88, 99, 96, -79, -106, -37, -74, 33, -83, 85, 6, -80, 92, 70, 0,
83, 44, 18, 35, 100, -42, -53, 73, -18, 94, -76, -37, 87, -94, -45, -65, 90, -83, -90, -73, 61, 26, 77, 77, -41, 84, 126, -34,
-104, 98, -27, -7, 19, -50, -73, -90, -91, -19, 93, -43, 106, 53, 65, -56, 120, 115, 50, -94, -119, -76, 50, -92, 27, 60, -67,
-94, -115, -84, -27, 45, 116, -13, 27, -8, -54, 11, 22, -36, -87, 86, -85, 1, -86, 69, 91, 40, -12, 55, 62, 101, -95, 48, -57,
77, -88, 86, 121, -54, 54, -43, 113, 93, -89, -47, 104, 48, -113, -107, 111, -59, -126, 46, -84, -16, 116, -39, 44, -53, 52,
-74, -74, -74, -24, 87, -84, 36, -111, -79, -8, 96, 109, 111, -75, 104, -21, 66, -61, -48, -9, -10, -10, 88, 40, -52, 55, 88,
-48, 127, 13, -102, 118, 47, 54, 13, 29, 12, -42, -2, -2, 62, 3, -85, 8, -94, 69, -49, 24, 12, -100, -69, 40, -118, -51, 102,
51, 119, -127, 47, 82, 100, 44, -59, 92, -31, -34, -34, 78, -123, 26, -89, -84, 105, -77, -99, -99, -99, 90, -83, 86, 96, -125,
85, 22, -59, -38, -39, -39, -26, 97, 116, 79, 65, -46, -63, 117, 108, 8, -123, -57, -57, -57, -59, -114, -125, 101, 1, 11, 126,
-18, -17, -18, -46, 48, 50, 84, 20, 25, -76, -22, -24, -24, -120, -127, 85, 16, -74, -114, -113, -113, 120, 46, 123, -76, -90,
19, -7, -32, -32, -96, -43, 106, 81, 30, -23, -110, -89, -32, -53, 82, -113, -43, -88, -117, -83, -83, 38, -105, -23, 116, -12,
76, -111, 1, -20, -77, -77, -77, 98, 79, -26, -108, 75, -79, -32, -25, -109, -57, -89, -107, 76, 69, 75, 30, 15, -9, -9, -9,
31, 60, 120, 80, -8, 56, 88, 34, -59, 2, -74, -68, 19, 43, -73, -67, 65, 126, 38, -67, 58, -111, 71, -64, -45, -13, -25, -49,
-85, -43, 106, -63, -66, -79, -91, 6, -53, 111, 63, 60, 125, -100, -55, 18, 6, 24, 12, 42, -78, 116, 120, 120, 72, -119, 92,
-83, 0, 65, -94, 126, -90, 92, 96, -63, -120, -20, -28, -31, -125, -12, 75, 74, -121, -3, -82, 40, -118, 47, 95, -66, 44, -110,
92, 49, -80, 110, 27, -88, -59, -23, -55, 67, -79, -106, -22, -89, -122, 32, 104, 24, 26, 120, -10, -62, -49, 15, 46, -117, 95,
-23, 86, -23, -16, 60, -1, -22, -27, 11, -50, 77, 105, -79, -88, 105, -24, -78, 52, 60, 58, 58, 122, -10, -20, 25, 37, 117, 50,
-95, 113, 16, 75, 100, 44, -29, -14, 47, 65, 16, 94, -66, 120, -18, -40, 86, 10, 84, -11, -69, -41, -69, -69, -69, -65, -4,
-14, 75, -26, -123, -56, 44, 20, -90, 17, 16, -73, -73, -73, 127, -4, -31, -119, 75, 114, 79, 7, 48, -20, -3, -34, 77, -77,
-39, -4, -11, -41, 95, 91, -83, 86, -34, -125, 96, 84, 25, 43, -23, -126, 85, -24, -26, 7, -9, 15, 79, -66, -69, 79, -120, 45,
-96, -86, -37, -71, -86, 9, -62, -49, 63, -1, 124, 112, 112, 64, 45, 85, -28, -42, 83, -108, 119, 37, 52, 116, -10, -93, 71,
-33, 63, -72, -73, 103, 26, 26, -121, 53, -71, -27, 83, -59, 87, 42, -81, 94, -67, -94, 109, -66, 25, 111, 109, 12, 3, 43,
-112, -83, -77, -77, -89, 63, -98, 61, -82, 112, 46, -58, -38, 7, 111, -69, 15, -37, 6, -73, -2, -24, -47, 35, -102, 35, 32,
91, -2, 69, 118, -112, 120, 122, 122, -6, -29, -39, 19, -95, 90, -59, -123, -64, -80, -33, 5, 83, 117, 118, 118, 70, -37, 114,
-119, 52, 119, -28, 98, -101, -126, 120, 91, -51, 54, 26, 117, 30, 95, -22, 82, 108, -44, 15, 15, 15, 41, 47, -27, -117, 4, 89,
12, 34, 25, 88, 94, 83, 53, -100, 91, -51, -42, 106, 117, -54, -21, 23, -126, 64, -63, 72, 91, -39, 61, -106, 32, 8, 112, -125,
-28, -119, 98, -37, -40, 54, -125, -81, -41, 27, -78, 60, 41, -10, -122, 125, 76, -79, 66, -88, 2, -98, 62, 125, -66, -100, 76,
20, 23, -97, 98, 85, 5, -48, -84, 86, -73, -37, -93, 103, -105, 81, 20, -71, -62, -37, -124, -110, 126, -97, 120, 126, 126,
-114, -31, -20, -53, 101, 91, 81, 20, -61, 59, 100, 0, -25, -19, 22, 106, -30, -25, 47, -41, 0, -18, -47, -47, -125, -14, -92,
70, -105, -81, 44, 29, 88, -66, 80, 121, 103, -113, -9, 6, 55, -35, -98, -86, 106, -74, 101, -109, 56, -127, 28, 116, -21, -29,
-59, -107, 50, -99, -98, 61, 125, -110, -19, -16, 16, 81, -82, -16, 42, -103, 80, 42, -92, -4, -83, 56, -58, 19, -27, -26, -90,
11, 114, -27, 29, 106, 111, 19, 60, 103, -89, 82, -31, -5, 67, 89, -110, -34, -4, -12, -30, 121, -77, -39, -56, 92, -70, 48,
-94, 19, -6, 82, 66, -87, -112, -102, -87, 106, -81, 55, 28, 73, 99, -35, 48, 8, 9, -43, -35, 102, 57, -18, -97, 127, -67, 63,
-68, -73, -1, -61, -39, -109, 74, -22, -101, 117, 101, -27, -13, -124, -62, 35, -27, -105, 21, -8, 72, -115, -57, 19, 64, -54,
-76, 76, -41, 73, -9, 126, 87, -8, -63, 72, 30, -114, 94, -97, 28, 31, -99, -98, 62, -28, 112, -97, -20, -99, -36, -77, 99, 73,
64, 20, 31, 44, 95, 24, -4, 114, 77, -128, 73, 26, -113, -91, -15, -60, 35, -54, 50, 29, 39, -77, -95, -102, -53, 85, -82, -38,
-67, -101, 118, -17, -31, -55, -47, -23, -61, -29, -123, 122, 21, -29, -120, -118, -107, 79, 33, 20, -113, 39, -33, 41, 91,
-106, 53, 28, -115, 71, -93, 49, 104, 21, 120, 41, 107, 126, 106, 33, 13, 29, -24, 112, -36, -43, 117, 23, -16, -70, -73, -65,
119, 122, 122, -36, -88, -33, 102, 83, -15, 18, -106, 92, -82, -110, 92, 47, 20, -125, -89, -59, -50, -117, -90, 105, -127, 56,
-127, -117, -14, -49, 93, -74, 76, 112, 82, 14, -123, -89, 127, 1, -27, -125, -95, 52, -108, -58, 98, -83, -10, -32, -2, 33,
56, -80, 70, 3, 39, 97, 88, 62, 113, -110, 23, 17, -14, -82, 79, 16, -17, -32, -13, -125, 115, -110, 36, 89, -127, -111, -34,
84, -99, -45, 100, -37, -44, 72, 84, 64, 88, -12, -27, -53, -43, 117, -29, -22, -90, 125, -45, -18, -118, -94, -80, -69, -69,
125, -1, -34, -67, -83, -7, -122, 94, 105, -114, -32, -104, 121, -1, -121, 68, 65, 3, 73, 26, -114, -122, -93, -111, -92, 106,
58, 24, 40, 27, -120, 2, -102, -26, 9, -124, 92, -40, 22, -9, -101, 122, -71, -100, -83, 105, -114, -90, 15, 123, -67, 81, -75,
-54, -33, 59, -40, 59, 58, -70, -65, 28, 37, -23, 33, 105, -19, -117, -33, 125, 48, 127, 96, -7, 73, 115, -80, 80, -99, 110,
-65, 63, 24, 121, -2, -55, -102, -57, 59, 39, -57, 30, -40, -11, -5, 6, -20, 61, 96, -26, 56, -99, -18, -96, -35, 29, 108, 111,
53, -97, 62, -7, -66, -43, 108, 70, -62, 43, -22, -102, 65, -20, -29, -63, -4, -127, -27, 35, 5, -9, 29, 2, -121, -113, -108,
97, -102, 68, 51, -100, -103, -123, -56, 121, 83, -90, -22, -101, -73, 127, 111, 53, -21, -49, -97, -99, -119, 104, -101, 18,
-46, 99, 38, 115, 3, 22, 32, 5, 96, -115, 36, -71, -45, -23, 121, 73, 115, -45, 114, -24, 59, 58, -107, 68, -101, -86, -6, 31,
-81, -33, -35, 63, -36, 63, 123, -6, 120, 115, 126, -107, -48, 66, -82, 120, 47, -104, 3, -80, 22, -77, 123, 23, -105, 55, -93,
-47, 72, -45, 12, -37, -74, -99, 82, 29, -111, 83, -87, -12, -121, -29, -31, -16, -11, -53, -97, -98, 7, 45, -8, -119, -57, 16,
-71, -62, 44, -38, -63, 2, -107, 2, -86, -108, -23, -12, -14, -78, 13, 63, -67, -39, 61, -89, -92, -57, 46, 57, 92, -27, -51,
-37, -13, -17, -114, -18, 63, 126, 116, -70, 50, -85, -115, 104, -88, 83, 13, -123, 52, -89, 125, 125, -86, 6, -125, -47, -43,
77, 71, 85, 85, -53, -78, -99, -110, -97, -27, 85, -31, 59, -67, -95, 36, -115, 95, -3, -21, -59, -30, 108, -117, -40, 84,
-111, -56, -117, -34, -10, 29, -51, -90, 10, -88, -70, -23, 116, -65, 92, -35, 76, -89, 51, 19, 76, 21, 59, 33, 110, -34, 116,
-45, -2, -9, -17, -81, 65, -68, 9, -119, 2, -106, 2, 101, -98, -93, 114, -82, 10, -112, -126, -81, -29, -27, 117, -69, -35,
-18, -51, 84, -43, 46, -121, 79, -113, 34, 93, -43, -33, -1, -8, 83, 81, -108, -75, -91, -6, 36, -28, 42, 114, -76, -95, 109,
-104, -22, 107, 21, -4, -68, -8, 114, -35, -23, -12, 85, 85, 43, 88, 66, 1, 95, 84, 20, -64, 114, -115, 70, 82, 10, -101, 93,
113, 73, -106, -40, 83, -62, -106, -97, -84, -70, -70, 110, 15, -122, -110, -90, 107, 94, -26, -109, 65, -76, -82, -97, -25,
-9, -86, -6, -2, -4, 127, -29, -15, 24, -93, 91, -62, 18, 7, -31, 113, 62, 5, -40, -93, -70, -11, 118, -57, -53, 127, -22, -70,
-58, -96, -38, 64, -43, 55, -49, 80, -5, -21, -35, -7, 108, 54, -13, -5, -114, -98, -56, -61, -45, 51, 70, -11, -13, 85, 48, 6,
108, 67, 4, -44, 52, 22, 0, 67, -87, -14, 91, -83, 86, 127, -3, -25, 91, 116, 47, 31, -93, -117, -15, 44, 88, -51, -124, 45,
-96, -86, 86, -85, -55, 19, 101, -98, 89, -16, 124, 21, 67, 8, -123, -86, -81, -82, 84, 16, -1, -13, -6, -115, 105, -102, 9,
-5, -114, -8, -126, -43, -12, -39, 2, 95, -27, 21, -112, 92, -75, -39, 24, 48, 16, -87, -115, -99, -30, 112, -4, -37, 119, -17,
83, -37, 76, 38, -12, 79, -16, 25, -66, -125, 101, 107, 5, -19, -6, -90, -93, 76, -89, -106, 105, 49, -86, 16, -123, -22, 31,
-9, -80, -62, 79, 103, -6, -43, -43, 85, 108, 99, -114, -73, -52, -127, -49, -36, -18, 45, -84, -107, 52, -106, 13, 16, 115,
-122, 81, 116, -86, -66, -103, 45, -15, -45, -25, 47, 11, 35, -97, -126, 44, -123, -124, 66, 66, 21, 57, -111, -126, -32, 77,
-69, -85, 105, -70, -53, 12, 123, -108, -16, 119, -73, 53, -102, -37, 127, -67, 125, 27, 35, 107, -118, -117, -127, -43, 93,
-109, -77, 98, 107, 17, 4, 103, -86, -58, -84, 85, 60, -95, 90, 105, -106, 93, -71, -68, -68, 36, -70, 75, 17, -54, -11, 60,
118, 102, -93, -54, -43, 72, -110, 33, 8, 122, 107, -3, 24, 76, -119, -87, -14, 3, -30, -25, -117, 75, 85, 85, -45, -33, 8,
100, -7, -81, 32, 37, 72, 9, -67, 45, -48, 42, 120, -27, 78, -73, 7, -95, -112, 5, -63, -40, -31, -17, 110, -85, 55, 90, -17,
-33, -33, -114, 16, 99, -81, -3, 74, 82, -115, -61, -93, -61, -120, 23, 47, 127, -127, -51, 112, 52, -98, 77, 89, 126, 1, -125,
80, -3, -13, 27, 91, -107, -107, 89, -116, -87, 30, -100, -86, -127, -59, -30, -59, -109, 43, -53, -78, 123, -67, -127, 87,
-69, -57, -22, 97, -16, 81, -27, -73, 102, 115, -21, -4, -17, -1, 58, -13, 53, -107, 24, -27, 10, -3, -91, 34, 103, -34, -79,
109, -41, -20, 21, -80, 75, 83, 85, -75, 29, -106, 100, -57, 76, -107, 47, 90, -102, 102, -12, -5, 125, -68, -5, 22, -95, 63,
37, 78, -26, 61, 121, 88, 4, -86, -32, -85, 52, 24, 72, 38, -18, 29, -49, 24, 85, -73, 78, -85, -39, -6, -33, -121, 15, -15,
-10, 86, 77, 62, 78, -116, -97, 121, 79, -62, -106, 55, 24, 28, -115, -67, 57, -63, -110, -53, 21, 14, -85, -66, -31, -37, -85,
-21, -90, 36, 73, 81, 61, 56, -106, 49, 28, -97, 68, 42, -29, -79, -27, 87, 106, -113, 70, -110, -111, 120, -46, -108, 9, 85,
-32, 107, -49, 87, 40, 54, -102, 91, 31, 63, 126, 76, 97, 89, -40, -6, 80, -104, 50, 91, 32, 87, -54, 116, 54, -99, -127, -69,
42, -15, 96, -112, 60, 85, -34, -83, 22, -124, -15, 68, 81, 85, -107, 92, 16, 12, 122, 74, 120, 105, 114, -88, -93, -118, -6,
86, -68, -51, 26, -57, -78, 97, -104, 37, -51, 93, -111, 12, 127, -53, 84, -7, 77, 20, 27, 43, 51, -45, 120, 87, 32, -122,
-101, -9, 36, -12, -96, -37, 121, -49, -74, 59, -114, 36, -55, -106, 93, -54, 42, 6, -62, 49, -56, -67, -77, 25, 74, -93, -39,
-70, -66, -66, -74, 44, -117, -48, -112, 63, -56, -64, -15, -111, -24, 9, -3, 27, -95, -41, 64, 28, -100, 40, 51, -49, 93,
-107, 77, -82, 8, 11, -43, 90, -86, -4, 102, -37, -82, 44, -53, 73, 92, 13, -122, 10, -46, -28, 68, -121, 94, 51, -103, 76, 76,
-45, 42, -111, 109, 39, -113, -44, -26, 38, -42, -101, 55, 55, 55, 92, -70, 91, 57, 16, 73, -112, 6, 73, 23, -60, 65, 27, -30,
-32, 88, 46, -111, 109, 79, 11, 41, 55, 120, 71, -80, 70, -85, -43, -21, -11, 76, -45, 76, 71, -82, -66, 86, -112, -58, -104,
104, 68, 47, -38, 95, 77, -13, -13, -68, 58, -45, -84, -7, -18, 104, 76, -88, -46, -95, -54, 111, -106, -27, 40, -118, 18, 35,
65, 21, 27, 56, -98, -117, 53, -119, -115, -18, -42, -105, -81, -124, -15, -32, 68, 81, -118, 31, 7, -45, -115, 125, 46, -62,
-18, -123, 98, -67, -47, -23, 116, 82, -7, -24, 8, -123, 126, 24, -109, 88, -117, 43, 21, 101, 90, -28, 90, -122, -44, -19, 20,
10, 85, 112, 9, -128, 5, -47, 112, -19, -127, 100, 36, -28, -118, 11, 45, -101, -63, 50, 18, 92, -56, -107, 97, -104, -86, -82,
59, -82, -61, -112, 74, -109, 42, 110, -66, -82, 85, 85, 53, -61, 48, -120, -114, 4, -41, 23, -6, 37, -103, 33, 66, -86, 85,
-11, -90, -82, 116, 27, 12, 86, -63, -30, 96, 70, -125, 62, 116, -86, -66, 125, -77, -7, 13, 54, 11, -41, 96, 112, -67, 98,
109, 96, 43, -71, 116, -127, 98, 105, 0, 22, -88, -79, -5, -83, 51, 114, 77, 88, -90, 31, 33, 50, 85, 94, -55, 114, 77, -110,
36, 114, 65, 48, -92, 30, 43, -95, 54, 110, -66, 102, 58, 47, 22, -91, -89, 123, 114, -57, 83, 108, -86, -72, -7, -36, -50,
104, 52, 66, -87, 87, -58, -94, 106, -4, -38, -87, -17, -124, 97, 49, -24, -78, -103, -86, 6, 30, 19, 65, 63, 97, 20, -68, 61,
-1, 30, -59, -96, -54, 83, 44, -79, 14, -95, -48, -97, -37, -119, -115, 14, 58, 24, 124, -116, -105, -120, -127, 23, -60, 65,
-48, 42, 11, -59, 96, 45, 8, -93, 1, 50, -102, -34, -116, -117, 120, 40, -126, 27, -24, 113, 13, -45, 4, -80, -46, -103, 46,
-116, -71, 96, 53, -22, -58, 38, -2, -86, -44, 121, -94, -63, -115, -39, -81, -87, 117, 45, 85, 100, 99, -94, -22, 27, 91, -43,
-107, 101, 97, -111, -70, 53, -50, 30, -92, 65, 58, -124, -123, 45, 104, -66, 115, -9, -22, 69, 93, 76, 93, -114, -79, -41, 51,
-63, 55, 117, -86, -4, -92, -125, 44, -53, -92, -125, -32, -41, -65, -75, 114, -47, -35, 61, -60, -41, 62, 24, -6, -85, -69,
87, -50, -49, 37, 113, 48, 75, -53, -99, -111, 103, -124, -117, -13, 50, 90, -64, 68, -107, 111, 72, -4, 50, 7, -116, 59, -59,
7, 117, -73, -128, -62, -118, -1, 39, -125, -34, 13, 34, 91, -102, -90, -49, -73, 104, 39, -39, -63, -123, -101, 41, -62, 72,
21, 92, 34, -44, -60, -39, 108, -122, 49, 8, -30, -87, 110, 72, 104, -25, -67, -93, 40, 93, -121, 99, 43, 8, -15, 14, 0, -111,
-87, -30, -26, 91, 29, -23, -66, 33, 33, 73, -43, -90, -3, -79, -30, -39, -7, -51, -17, -49, 115, -18, -116, 42, -68, 66, 21,
-123, 42, -81, -77, -85, 60, -116, 10, 87, -64, 34, -76, -116, 52, 114, 117, 67, -20, -9, -95, 106, -102, -53, -56, -62, 40,
84, 17, -87, -30, -68, 84, 86, -29, 46, 88, -124, -68, 124, -100, -22, -122, 24, 21, 53, -2, 97, 124, 12, 43, -100, 66, 21, 43,
81, -22, -99, 111, -75, 4, 22, -119, 32, -72, -22, -79, -126, -40, -118, -12, -8, -38, 11, 110, 15, 67, 99, -118, -107, -106,
80, 5, 93, 5, 84, 45, 102, -43, -120, -18, -91, -64, -29, 34, 116, 3, 94, 64, -107, 89, -14, -75, -87, -72, -124, 42, 25, 85,
-100, -105, -87, 22, 80, 118, -124, 39, 50, 9, -115, 49, 44, 46, -102, -73, -118, -112, -127, -107, 80, -88, 18, 83, 53, -9,
-17, 85, 77, -117, -65, -77, 65, -46, -71, -62, -88, 108, -123, 22, -52, 56, -82, 27, -70, -91, 14, 67, 42, -71, -87, 10, 101,
15, -70, 0, -64, -118, 71, 79, -76, 80, 24, 73, -118, -30, -91, 27, -100, 121, 96, -41, 13, 99, 49, 111, -62, -112, -118, -6,
28, 108, -20, -71, -18, -38, 2, 101, -116, 65, 48, 36, -35, -64, -59, 93, 100, -79, -10, 65, -45, -78, -106, 63, 79, 57, -39,
-118, -7, -91, 114, -15, 93, 69, 96, -51, 106, -56, 92, -31, -122, -7, -93, 72, 51, 60, 107, 127, 11, -113, -76, -102, -115,
-29, -93, -61, -13, -13, 115, 67, 55, 86, -94, 100, 41, -112, -118, -73, 93, 2, -34, -81, -33, -41, 3, -61, -8, -19, -19, 109,
92, 84, 109, 104, 66, 40, 46, -111, -104, 11, 122, -75, 106, -75, 122, -14, -16, -72, -39, -16, 106, -51, -104, -63, -62, -53,
98, -92, -54, 94, -96, -22, -32, -32, 0, 27, -6, -63, -49, 66, -99, -124, -34, 48, 31, -114, -126, 23, 52, -8, -82, 28, -50,
-37, -26, -9, 90, 12, 13, 75, -30, 127, -15, 34, -75, -10, -78, -107, -101, -116, 125, 6, -38, -85, 110, 88, -101, 37, -57, 91,
60, 19, -54, 95, 97, 8, 91, -50, 9, -57, 126, 58, 122, 37, 18, -54, -107, -120, -67, -125, -15, 27, 114, 59, 9, -115, -72, -29,
-37, -26, 90, 120, -20, 91, -76, -71, -33, 90, 46, 120, 74, -2, 86, 73, -100, 37, -111, -80, 83, -110, -72, -82, 64, -13, 30,
-61, 90, 17, -110, -82, -107, -38, -7, 2, 4, 59, 26, -112, 34, 68, -43, -30, 87, -62, 6, 44, 98, 88, 43, 20, 116, -30, -31,
-123, 104, 23, -14, 2, 83, 108, 21, -49, 5, 85, 92, 104, 105, 114, -68, -38, 81, -46, 120, -123, 126, 78, 66, 47, 75, 63, 82,
25, 82, -75, 26, 10, 87, 46, -115, 58, 42, -36, 60, 36, 12, -19, 96, 92, 120, -91, -116, 69, -38, 9, 45, 58, -88, -118, -12,
-78, -62, 93, 2, 48, 102, 28, 16, -71, 73, 56, -104, 42, 112, 2, 34, -123, -44, 3, -106, 55, 115, -9, 87, -21, -51, -5, 90, 32,
98, -37, 118, 116, 89, 42, 30, 97, -40, -41, 28, 103, 53, 72, -116, -6, -85, 104, -26, 61, -119, -81, -118, -102, -92, -55, 53,
97, -23, 36, 72, -15, 74, 26, -87, 41, 29, 116, -74, -110, -60, -66, -88, -90, -118, -50, 92, 3, 33, 111, -105, -95, -93, -57,
-66, 60, 58, 124, 74, 39, 106, 34, 30, 49, -95, 21, -125, -110, 2, 39, -76, -120, 30, -60, -107, 112, 7, -1, 24, -65, 69, -99,
-46, -119, -57, 22, -118, 116, -31, 74, 104, -27, 55, -101, 69, 20, -87, -84, -88, 90, 63, 42, -116, -60, 86, -14, -64, -121,
37, -29, 16, -12, 33, 9, -67, 108, 1, -112, 34, -54, 28, 23, 105, 74, 39, 106, 93, 77, 12, -68, -80, 107, 15, -99, 9, -83, 20,
78, -77, -55, -118, -86, -43, 117, -123, 92, -108, -87, -24, -75, 15, -30, -102, -124, -50, -53, -60, 115, 60, 50, -30, 125,
-70, -88, -49, -54, -100, -86, 56, -93, 66, 46, 110, 34, 62, 94, 66, -85, 0, 57, -83, -44, 82, 15, 28, 85, -103, -9, -48, 41,
-99, -96, 100, 105, 80, 88, -60, 110, -86, 114, -102, -45, 74, 57, -11, -112, 14, 85, -24, 69, 127, -119, -90, 116, 98, 87,
-106, -58, -13, -20, -12, -53, 88, 86, -87, 7, 14, -57, 105, 15, 120, 43, -22, 2, -89, 116, 18, -78, -59, 17, -98, -124, -90,
7, -78, -84, 10, -77, 48, 10, 21, 71, 32, -125, 26, 56, -91, -125, 62, 93, -104, -80, 60, 11, 123, 78, -117, 28, 106, -124, 70,
21, -92, -25, 19, -45, -89, -118, -61, 56, -91, -109, -80, 60, 11, 99, 78, -117, -93, -72, 108, 38, 101, 95, 79, 90, -52, 34,
100, -34, -109, 12, 12, -79, -108, -48, 112, 37, -88, -94, 73, -57, -41, 99, -15, 76, -79, -25, 16, -123, -69, 93, -66, 118,
-59, 41, 58, 70, -72, -16, 42, 30, 97, -55, 117, 52, -75, -46, -28, 36, 84, -35, 78, -23, -96, -8, 119, -94, -53, 89, -117,
-99, -42, 74, 121, -88, 72, 3, 85, 33, 30, 43, 121, -66, -108, -61, 90, 66, -109, 35, -56, 50, 25, 42, 82, -75, 38, 44, -60,
99, 37, -97, -115, 38, -124, 23, -123, -112, 101, -69, -122, 39, 29, 47, -113, 46, 99, -31, 9, -46, 116, -106, -123, 37, -73,
83, 41, -81, 12, -93, -89, -16, -127, -50, 53, 97, 72, 9, -46, 60, 46, 11, 67, -71, -107, 40, -96, -45, 44, 123, 120, 23, 80,
-32, 93, 19, -106, -56, -68, -109, 91, -70, -109, -50, 120, -112, -98, 116, 87, -74, -53, 12, 57, 2, 43, 13, -109, -102, 119,
-46, 75, 119, -118, -99, -45, -54, -80, 34, 25, -117, -105, -33, -76, -115, 81, 114, -13, -98, -114, 115, 47, 18, 97, 52, 20,
-6, 17, -91, -22, -21, 33, 77, 88, -52, 123, -6, 43, -61, -72, -46, 20, -46, 100, -78, 32, 44, 97, 112, -60, 105, -34, 83, 94,
25, -58, -107, -96, -112, -122, -62, 53, -122, 92, -62, -35, 102, -110, 20, 59, 100, -78, 122, -89, 72, -123, 52, -39, 122, 47,
-30, -91, -55, 52, -84, -34, -31, 18, 87, 107, -111, 70, 45, 71, -85, -63, 82, 77, -112, -122, -102, 119, 46, 108, 66, -102,
-24, -22, 29, 92, -74, 29, -27, -98, 70, -38, -103, -77, 120, 118, 30, -81, -111, -81, -80, -45, 34, 88, 35, -47, -2, 47, -64,
0, 8, 49, -108, 89, 94, -83, -64, 58, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126 };
};
}



... and it made me feel really dumb because I can't figure out why it was done this way, nor how somebody allowed somebody else to spend however many months it took for them to hand-convert an image to bytes. I'm sure it wasn't done some other way because the person who did this wasn't looking for shortcuts.

Friday, July 15, 2011

My RAID5 broke

For the longest time my "backup" machine was sitting in the closet with a broken raid array. I didn't want to deal with so I went without a backup. I finally spent a few minutes and figured out what was happening. One of the disks was not recognized as part of the array for reasons I don't care to understand right now. This is what I did to fix it:

# first i forced the array to start in degraded mode
root@nfs:~# mdadm --assemble -s -f

# then i had it add the drive back into the array
root@nfs:~# mdadm --manage /dev/md0 -a /dev/sdd1

# then i go on vacation for a week while this completes...
root@nfs:~# watch cat /proc/mdstat 

That's it. Hopefully it won't happen again.

Tuesday, June 28, 2011

Ajax Proxy

http://ajaxproxy.thedeanda.com is a great little tool i've created to help with ui development for websites. it allows you to build ajax websites and not deal with the hassles of configuring the full server stack on your workstation. it's been used by myself and coworkers for the last few years and it can be a great time saver.

This open source project is hosted at github.

Wednesday, April 13, 2011

i came back into office for this? stupid longs

package com;

import java.util.Date;

public class D {
public static void main(String[] args) {
for (int i = 0; i < 40; i++) {
printDateInt(i);
printDateLong(i);
System.out.println();
}

long now = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 30L;
System.out.println(new Date(now));

}

private static void printDateInt(int daysBack) {
long now = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * daysBack;
System.out.println(daysBack + " " + new Date(now));
}

private static void printDateLong(long daysBack) {
long now = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * daysBack;
System.out.println(daysBack + " " + new Date(now));
}
}

Saturday, March 26, 2011

Rate My News Anchor

http://ratemynewsanchor.com it's finally live and although it's not finished, it does have plenty of content that gets updated and added regularly. Feel free to signup or login with an existing account from gmail, yahoo or facebook and start contributing yourself.

Rafael Iron Works

http://rafaelironworks.com is a small website for my dad's wrought iron business.