Thursday, March 21, 2013

Processing.org, Insertion Sort

So, I recently been getting into messing around with Processing.org. If you haven't heard of it yet definitely check it out if you are into doing any kind of animation and graphics programming. The default language is JAVA so the syntax is really easy and its all OO.

On a whim I wrote a small program that shows a step-by-step insertion sort routine running on a randomized array. Here is the code for that..

int[] unSorted = new int[10];
int iter = 1;
int holePos = 0;
int val = 0;
PGraphics pg;
void setup(){
 size(500,400);
 pg = createGraphics(500,400); 
 background(255);
 frameRate(1);
 initialize();
 debug();
 
}
void initialize() {
 for(int x=0;x<10;x++) {
  unSorted[x] = int(random(10)); 
 }
}
void sort() {
    print("Iter=" + iter + "\n");
    val = unSorted[iter];
    holePos = iter;
    while(holePos > 0 && val < unSorted[holePos - 1]) {
     unSorted[holePos] = unSorted[holePos - 1];
     holePos = holePos -1; 
    }
    unSorted[holePos] = val;
    show();
    debug();
    
}
void debug() {
 for(int x=0;x<10;x++) {
  print("[" + unSorted[x] + "]");
 }
  print("\n"); 
}
void show(){
 pg.clear();
 pg.beginDraw();
 pg.stroke(100,200,30);
 float yPos = 500/2;
 float xPos = 400/2 - (0.5 * 160);
 float offset = 0;
 for(int x=0;x<10;x++){
  pg.fill(0,0,0);
  pg.rect(xPos + 20 * (x + 1) + offset,yPos - (10 * float(unSorted[x])),20, 10 * float(unSorted[x]));
  pg.endDraw();
  image(pg,0,0);
  offset = offset + 4;
 }  
}
void draw() {
  if(iter > 9) {
   noLoop();
  } else {
  background(255); 
  sort();
  iter = iter + 1;
  }
}


Wednesday, February 6, 2013

Intel(R) Centrino(R) Advanced-N 6235 Lag Spikes

This post is about troubleshooting the Intel Centrino Advanced N-6235 wireless adapter in Windows 8. There is a problem with this wireless card that is beginning to show up for a lot of people.


So, I decided a good use of this blog will be to post solutions to problems I encounter in the course of my dealings with new hardware, programming challenges, or otherwise anything related to technology. I know how annoying it is when I google a problem and I can't find any answers anywhere. I'm always happy when I see someone who has had a similar problem as me and posted their solution online. So now that will became one of the main focuses of this blog.

I bought a new Windows 8 laptop, the ASUS Zenbook UX51V.  This model comes with a Intel(R) Centrino(R) Advanced-N 6235 wireless network card. Everthing about his laptop is fine except that I was getting really high lag spikes that lasted about 2-4 seconds every minute or so. I thouht it had to be something with the wireless polling, ping times were high and correlated with the lag spikes in m video game (heroes of newerth).

Some people have had a lot of success using WLAN Optimizer to disable wireless background scanning to fix high ping intervals. (http://www.martin-majowski.de/wlanoptimizer/) However for me it did not seem to make a difference for Windows 8. Perhaps they will release a new version for W8.

What did seem to work and suggested by some other people here is turning on 802.11n mode and switching the Wireless Mode to 802.11g in the advanced config. That is the only thing that dramatically reduces the re-occuring high latency issues.

More on the workarounds here:
http://communities.intel.com/thread/31090

and here:
http://communities.intel.com/message/178418

I do not consider this a permanent solution. I believe INTEL needs to come out and address this issue and release a driver fix.


Monday, October 15, 2012

Encrypted Networking Class for VB.NET

This is something i've been working on for a little bit. It provides transparent encryption functionality similar to SSL/TLS in easy to use event driven networking objects. Features are:


  • RSA 1024bit Public Key Exchange
  • AES (CFB) Symmetric encryption 
  • HMACMD5 Hash authentication for every message
  • Auto Ping with Latency update on the client side
  • Negotiation timeout variable
  • All encryption is handled transparently behind the scenes.

How to use:

Private WithEvents Client as New Phoenix.EncryptedClient
Private WithEvents Server as New Phoenix.EncryptedServer

Thursday, October 8, 2009

Automatically fading buttons in VB.NET

I often find myself obsessing over the finer parts of interface design with my applications. I always thought buttons that innocuously faded from their mouseover color back to their default background color was something really nice and not *too* flashy. Since I couldn't find any material for replicating this in VB.NET I did what all programmers do, I wrote one myself. I hope this code helps anyone attempting to do something similar. Improve upon it if you wish, I am just posting the basic code, it will works best if you encapsulate it in a UserControl...

Public Class Form1
Friend WithEvents btnTimer As New Timer
Dim RedValue As Integer
Dim GreenValue As Integer
Dim BlueValue As Integer
Dim RAdd As Integer = 0
Dim Gadd As Integer = 0
Dim Badd As Integer = 0
Dim MyBackColor As Color



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

btnTimer.Stop()
MyBackColor = Button1.BackColor
End Sub

Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave

RedValue = CInt(MyBackColor.R) - CInt(Button1.FlatAppearance.MouseOverBackColor.R)
GreenValue = CInt(MyBackColor.G) - CInt(Button1.FlatAppearance.MouseOverBackColor.G)
BlueValue = CInt(MyBackColor.B) - CInt(Button1.FlatAppearance.MouseOverBackColor.B)
RAdd = 0
Gadd = 0
Badd = 0
btnTimer.Interval = 1
btnTimer.Start()



End Sub

Private Sub btnTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTimer.Tick
Select Case RedValue
Case Is <>
RAdd = RAdd - 1
RedValue = RedValue + 1
Case Is > 0
RAdd = RAdd + 1
RedValue = RedValue - 1
Case Is = 0
RAdd = RAdd + 0
End Select
Select Case GreenValue
Case Is <>
Gadd = Gadd - 1
GreenValue = GreenValue + 1
Case Is > 0
Gadd = Gadd + 1
GreenValue = GreenValue - 1
Case Is = 0
Gadd = Gadd + 0
End Select
Select Case BlueValue
Case Is <>
Badd = Badd - 1
BlueValue = BlueValue + 1
Case Is > 0
Badd = Badd + 1
BlueValue = BlueValue - 1
Case Is = 0
Badd = Badd + 0
End Select
Button1.BackColor = Color.FromArgb(CInt(Button1.FlatAppearance.MouseOverBackColor.R) + RAdd, CInt(Button1.FlatAppearance.MouseOverBackColor.G) + Gadd, CInt(Button1.FlatAppearance.MouseOverBackColor.B) + Badd)
If BlueValue = 0 And RedValue = 0 And GreenValue = 0 Then
btnTimer.Stop()

End If

Friday, January 23, 2009

Access 2003 Using DateDiff for "Business Days" or Weekdays without using outside module

I see this problem alot among developers and I just thought id share some info. If you are using a very simple DBMS like Access 2003 and can't extend functionality to your standalone application, because access 2003 doesn't let you use UDF (User defined functions) outside of itself. Here is how I came up with determing the amount of WEEKDAYS (M-F) between two dates without having to create a UDF in the DB.
SELECT  * FROM tblExample WHERE datediff('ww',[fldDate],Date(),2) + datediff('ww',[fldDate],date(),3) + datediff('ww',[fldDate],Date(),4) + datediff('ww',[fldDate],Date(),5) + datediff('ww',[fldDate],Date(),6) >= 5
That will return all records where fldDate and Date() are greater than or equal to 5 weekdays. Of course if you can use custom functions in your DBMS, then you wont need this.