Kinds of things.
Whaaaa? Where Am I?
This is Zacharias Stankiewicz's personal blog.
About The Author

Name: Your Name
Location: Anywhere

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc ut sapien. Nunc non massa. Sed venenatis. Vivamus pede dolor, vehicula non, laoreet et, dapibus non, est. Etiam tempus justo a lacus. Vestibulum lectus purus, aliquet vel, bibendum pellentesque, commodo eu, nisi.

tweets for the week 2010-11-26

  • Running VMware converter again, now that I've freed up 300GB worth of junk. #
  • @thespoonyone pirate pills come in that package too it may be worth the risk. #
  • This is a real thing: http://en.wikipedia.org/wiki/Impostor_syndrome #
  • Apple DRM from 1984: http://bit.ly/co2IMV #
  • http://bit.ly/bN63Sg windows XP phone – prolly faster than my eee 900 #
  • pair programming: lets trade off being BOSS and productive: http://bit.ly/aNZ0JI #
  • Is –>Your SON<– a computer hacker? check these warning signs! #
  • Emulating win7_64 seems to be the first thing my Santa Rosa MBP can't really do. #
  • Psych, the show that takes place in Santa Barbara, on the USA network, is shot in Canada. God, this TV stuff is made-up. #
  • Finally shipping this CS lab would be more fulfilling if I didn't have 2 other ones before Tuesday. #lesigh #
  • Jameson 12 is smoother than a thing that is very smooth #kickinginalready #
  • Damn, 12" iBook G4s are still ~$200 on ebay? I've bought Power Mac G5s for less. #
  • what is the spritrix? http://bit.ly/cX1WOZ #
  • Age of Empires III on GFW for 10 MS points. #
  • Somebody's grades are improving in low-level programming (this guys) #
  • definition of college: finding a way to print 4300 words on 2 sides of 8.5"x11" paper #
  • So close to being caught up with all this computer programming nonsense. #
  • The first rule of Philadelphia club is pizza shop. The second rule of Philadelphia club is pretending NYC isn't nicer. 3rd rule pizza shop. #
  • Oh lookit, Dexter is getting AWESOME. #
  • Damn linear probe hash function stop running off the end of my array. #
  • If I didn't have a phone, I'd be looking pretty hard at the Droid Pro. #
  • @schmap Please auto-delete schmap reference 2FZKyT #
  • Oooh, my PI is out of the country. That's why I haven't seen him. #
  • Holy crap newegg will have a $85 64GB SSD tomorrow. Do want. #
  • Think my MacBook Pro may be in MacBook Pro heaven. #
  • Can't say I dislike Visual Studio 2010, especially after the time I spent in the command line C/ASM programming gulag. #
  • Things I've broken or lost this year: well over $2000 and the year is not quite done. #
  • New fake names: Chuck Royal, Rusty Weatherbeaten, D.H. Acker #
  • The breaking of everything I own continues with one of my server's hard drives. #
  • new design of the black eyed peas album is a total ripoff of YMCK #chiptune #

[Java] Using Java graphics to show off heap sort.

I’ve been working on implementations of various Java programs and the like in my Data Structures and Algorithms class, and since I really like how this turned out, I figured it’d be worth sharing.

This is the first time I’ve used multiple buttons and the default UI layout – I think it’d be nice to share an implementation of it. This program also has a delightful side effect of showing how close heap sort works to O(n log(n)). Code follows:

main.class

// thanks to ping for heapsorter as well as rolf's colorbox
// Heapsort was originally published by J.W.J. Williams as
// Algorithm 232 in the journal Communications of the ACM [Wil 64].

package lab10;

public class Main{

    private static int[] a;
    private static int n;
    static int[] w1;

    static int w = 2000;
    static ColorBox b1 = new ColorBox(w);

    public static void main(String[] args) {
     //   int w = 600;
     //   ColorBox b1 = new ColorBox(w);
    }

    static int dh = 0;
    static int sc = 0;

    public static void sort(int[] a0)
    {
        a=a0;
        n=a.length;
        heapsort();
    }

    private static void heapsort()
    {
        buildheap();
        while (n>1)
        {
            n--;
            swap (0, n);
            downheap (0);
        }
    }

    private static void buildheap()
    {
        for (int v=n/2-1; v>=0; v--)
            downheap (v);
    }

    private static void downheap(int v)
    {
        int k =  2*v+1; //k = root's children
        while (k<n)
        {
            if (k+1<n)
                if (a[k+1]>a[k]) k++;
            if (a[v]>=a[k]){
                return;
            }
            swap(v, k);
            v=k;
            k=2*v+1;
            dh++;
        }
    }

    private static void swap(int i, int j)
    {
        int t=a[i];
        a[i]=a[j];
        a[j]=t;
        sc++;
    }
}

/*
 * Okay, these are the numbers I'm getting for the swaps needed for each job
 * When I say "should be" number x, I'm speaking of the following formula for
 * the O(n logn) amount of swaps required...
 *
 * x | x is a side of the array
 * swaps = x^2 * lb(x^2)
 * where lb is binary log.
 *
 * Since big O notation reperesents an >upper< bound after a certain nominal value
 * none of the trials should be larger than O(n log n).
 *
 *
 * size: 100
 * swaps: 123891
 * Should be ~130k
 * http://www.wolframalpha.com/input/?i=100%5E2+%2A+lb%28100%5E2%29
 *
 * size: 200
 * swaps: 575216
 * Should be about ~611k swaps
 * http://www.wolframalpha.com/input/?i=200%5E2+%2A+lb%28200%5E2%29
 *
 * size: 300
 * swaps: 1399854
 * Should be about ~ 1.4 million swaps
 * http://www.wolframalpha.com/input/?i=300%5E2+%2A+lb%28300%5E2%29
 *
 * size: 400
 * swaps: 2,619,194
 * Should be about 2.7 million swaps
 * http://www.wolframalpha.com/input/?i=400%5E2+%2A+lb%28400%5E2%29
 *
 * size: 500
 * swaps: 4,248,474
 * Should be ~ 4.4 million swaps
 * http://www.wolframalpha.com/input/?i=500%5E2+%2A+lb%28500%5E2%29
 *
 * size: 1000
 * swaps: 18,986,697
 * Should be 19 million swaps
 * http://www.wolframalpha.com/input/?i=1000%5E2+%2A+lb%281000%5E2%29
 *
 * size: 1500
 * swaps: 45,343,618
 * should be about ~ 47 million swaps
 * http://www.wolframalpha.com/input/?i=1500%5E2+%2A+lb%281500%5E2%29
 *
 * size: 2000
 * swaps: 83914749
 * should be about ~ 87 million
 * http://www.wolframalpha.com/input/?i=2000%5E2+%2A+lb%282000%5E2%29
 *
 */

next, we have the ColorBox method provided by the Professor and it includes my added buttons. This is the first time I’ve ever implemented multiple buttons on the UI. I know, minor victory. But that, to me, is really what programming is all about – little victories until one day, bam, you are half competent.

ColorBox.class

/*
 * ColorBox.java
 * Created on November 1, 2007, 11:08 AM
 * by Rolf Lakaemper
 * Zach added the buttons and actions
 */

package lab10;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

public class ColorBox extends JPanel implements ActionListener{

    private static final int DEFAULTSIZE = 400;
    private int []colors;
    private int size;

    //zach's buttons
    public JButton j1;
    public JButton j2;
    public JButton j3;

    /* Creates a new instance of ColorBox */
    public ColorBox(int inSize) {

        size = inSize;
        colors = new int[size*size];
        initRandom();

        // Visuals
        setPreferredSize(new Dimension(size,size));
        JFrame frame = new JFrame("ColorBox");
        add(j1 = new JButton("sort"));
        add(j2 = new JButton("randomize"));
        add(j3 = new JButton("downheaps and swaps"));

        j1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                Main.w1 = Main.b1.getColorValues();
                Main.sort(Main.w1);
                Main.b1.setColorValues(Main.w1);}
        });

        j2.addActionListener(this);

        j3.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent aw) {
                System.out.println("size: " + size);
                System.out.println("downheaps: " + Main.dh);
                System.out.println("swaps: " + Main.sc);}
        });

        frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
        frame.getContentPane().add(this);
        frame.pack();
        frame.setVisible(true);

    }

    /* Creates a new instance of ColorBox */
    public ColorBox() {
        this(DEFAULTSIZE);
    }

    public void initRandom(){
        for (int i=0;i<colors.length;i++){
            colors[i]=(int)(Math.floor(Math.random()*256));
        }

    }

    public int[] getColorValues(){
        // return a COPY of colors, keeps colors private
        int []c=new int[colors.length];
        System.arraycopy(colors,0,c,0,colors.length);
        return(c);
    }

    public void setColorValues(int []c){
        if (c.length!=colors.length){
            System.out.println("Error, arrays of different size.");
        }
        else{
            System.arraycopy(c,0,colors,0,colors.length);
        }
        repaint();
        return;
    }

    public void paintComponent(Graphics g){
        int count = 0;
        for (int row=0;row<size;row++){
            for (int r=row;r>=0;r--){
                g.setColor(new Color(colors[count],0,0));
                count++;
                g.drawLine(row-r,r,row-r,r);
            }
        }
        for (int col=1;col<size;col++){
            for (int c=col;c<size;c++){
                g.setColor(new Color(colors[count],0,0));
                count++;
                g.drawLine(c,size-c+col-1,c,size-c+col-1);
            }
        }
    }

    public static void main(String []args){
        ColorBox cb = new ColorBox(500);
        int []c=cb.getColorValues();
        java.util.Arrays.sort(c);
        cb.setColorValues(c);
    }

    public void actionPerformed(ActionEvent e) {
    // randomize button
       initRandom();
       repaint();

    // get ready for another run by setting counters to zero
    // downheap set back to zero
       Main.dh = 0;
    // swap count set back to zero
       Main.sc = 0;

    //  Junk drawer from other implementations/versions...

    //  long time1 = System.currentTimeMillis();
    //  Main.w1 = Main.b1.getColorValues();
    //  Main.sort(Main.w1);
    //  Main.b1.setColorValues(Main.w1);
    //  long time2 = System.currentTimeMillis();
    //  System.out.println(time2-time1);
    }
}

tweets for the week 2010-11-19

  • Making a VM out of ole Balthier here, as I've been having the worst computer luck lately. And I can run him in Fusion on my MBP. #virtualize #
  • As desktop virtualization is like our children (it is teh futrue), I'm subjecting myself to getting ok with the process. #ITiswatchingbars #
  • wait, I thought jQuery was Javascript http://bit.ly/drn8Zv #
  • @jdotames sup dog http://bit.ly/9GwBPx #
  • Analog Bandwidth meter: http://bit.ly/bKOU66 #
  • Anyone wanna tell me what @jdotames wants for Christmas? #
  • I may just buy @jdotames a nice AMD Phenom X3 8400 2.1Ghz Processor for $34.99 #moreusefulthanjewelry #
  • I wonder if I my VM is done cooking or not. #
  • Steeeeak. #
  • Driving across Pennsylvania via Rt. 80 – may be the most boring part of the state. #
  • Remember today, friends, the hype that the Houston Texans commanded just a few weeks ago. #
  • Baldur's Gate 2 now on GoG for $10. http://bit.ly/9CbcOh #
  • I hunger. Brace yourself, unhealthy food merchants of Temple – my class ends in three minutes! #
  • You think reform problems run deep in our country (USA, USA USA USSAAA) http://econ.st/d2G65Q try arguing with a Japanese farmer. #
  • i accidentally read yahoo news comments ouch my brains #
  • @cnn Mr. President: Would you send Michelle/Sasha/Malia through TSA screening? Naked photos or invasive genital groping, you get to pick. #
  • Jenny made us baby food potatoes tonight. #
  • Second day in a row where some putz drives a truck under a bridge not tall enough for him on Richmond St. Thanks for making me late to lab. #
  • Whoops missed a meeting. On Monday. #
  • I'm doing discrete probability in math class, which means I need to know these things: http://en.wikipedia.org/wiki/Poker_probability #
  • @burgerbaroness that looks bad now but a modern Cisco multiline SIP phone with PoE can't double as a melee weapon- also easy to paint purple #
  • .@reddit_prog: The lottery as a rational investment.: submitted by nassty [link] [5 comments] http://bit.ly/9HUxH8 taking this in math now #
  • @rentheimpaler technically, the moment you teach god something you kill him. #
  • Excited about MS Lync, http://bit.ly/9K1bnF which uses the powerful, open-source XMPP protocol http://bit.ly/cHWMj #
  • Impromptu Street Fighter II tournament broke out on the office. Hail to the king, baby. #
  • @benheck I was gonna put my eee900 in a Mac classic for running osx but haven't got to it. Lots of bondo fun. #
  • All the errors thrown by the complier fit on one screen at 1440×990 #minorvictory #
  • @patricknorton I've been telling folk who are using a desktop PC to use a 32/64GB boot ssd and leave the rest to spinnin' hdds. #
  • My Google-Fu I strong tonight. #

tweets for the week 2010-11-12

When using rtdsc on multi-core machines

remember that depending on your particular architecture, you can get some really strange results. As an example, on my macbook pro, I ran an application that polls the counter and asks it how many cycles it’s had since it was powered on. Thats how the spec works, anyways. I was getting some strange results I couldn’t explain, and it turns out every time rtdsc() was called, it was asking the other processor core.

Which wasn’t on when polled.

This meant that every other time it was asked, it was waking up a processor to say, eh, I’ve been awake for 287/24000000000 of a second.

I re-ran the results connected to a Unix server and got the right results.

So it goes. Click on the image below and experience the magic for yourself.

Classic K&R function – strcmp

In hopes of recalling elementary string functions in C, I’m jotting this down with comments.

It makes a lot of sense to really understand library functions before you go and try to re-make Doom.

int strcmp (char *s, char *t)
{
    for ( ; *s == *t; s++, t++)
        if (*s == '\0')
            return 0;
        return *s - *t;
}

So first we look at the input: we have two char pointers. Since we don’t have to change either s or t in order to compare them, pointers are the most efficient way to refer to them.

There is three possible input situations, first s could be greater than t, t could be larger, or they could be the same. Implicitly, we are comparing s to t. The for loop at the first line is made to go until s and t become not equal or to report they’re equal if the end of line \0 enters.

Otherwise, the difference between the two strings are reported as the result. This will be positive if s is longer than t, or negative if t us larger.

Therefore we have a discrete output for each of the three conditions. Note that since this comparison (in the for loop) is done until the end of similarity, the worst-case order of magnitude for this function is O(n). All other cases are O(1).

tweets for the week 2010-11-05

College is hard, yo.

Anyways, here’s a picture I took outside my office on a (not very) rare goofing off break.