2.15.2007

A little Business Etiquette

This etiquette is only really appropriate for Western companies and should not be applied all over the world.

Introductions
When introducing yourself:

  • Say Hello.
  • Introduce yourself without title (i.e. Mr. Mrs.).
  • Add some info about yourself, your position/responsibilities.
  • Try to repeat their name, so you can remember it.
  • Use other persons title (i.e. Mr. Mrs.) until they invite you to use their first name.

When introducing two people to each other it is important to rank the two people according to the following criteria:

  • Rank, customer is most important
  • Age
  • Familiarity
  • Once rank has been determined introduce the lower ranking person to the higher ranking person. Use the higher ranking person’s title to introduce them (i.e. Mr. Mrs.) and introduce the lower ranking person by the first and last name.

Handshakes
Do:

  • Wipe hands if needed (try not to do it in front of other person)
  • Stand close so elbows are slightly bent
  • Begin as introductions are ending
  • Be firm, but do not squeeze
  • Make eye contact and smile
  • Continue for 2-3 seconds (2-3 shakes)


Don’t:

  • Grab the other person’s hand with two hands
  • Grab the other person’s elbow
  • Drag the other person’s hand around

Entering Cubicles

  • Knock/announce yourself
  • Ask permission to enter
  • Enter cubicle to converse if allowed
  • Do not hover when occupant is busy
  • Do not handle personal or work items on desks

Deflecting work when busy
If you are busy and someone comes to discuss unrelated or less important work you can use the following techniques to end the conversation without offending anyone:

  • Greet the interrupter
  • Show interest
  • Assert your priority (what you are working on is more important)
  • Offer an alternative (i.e. different time to discuss)
    1. If it is not work related discuss during lunch or after hours

Offering Opinions

  • Limit negative opinions to small audiences
  • Open positive opinions to large audiences
  • Focus comments to make them appropriate for specific acts or results
  • Do not overstate or understate, use moderate language

4.14.2006

Adjacency Matrix in LaTeX

Here is some LaTeX markup to write an Adjancency Matrix.


\begin{math}
\begin{array}{cc}
&
\begin{array}{ccccccc}
A & B & C & D & E & F & G
\end{array}
\ \begin{array}{c}
A \\ B \\ C \\ D \\ E \\ F \\ G
\end{array}
&
\left[
\begin{array}{ccccccc}
0 \; & 1 \; & 0 \; & 0 \; & 0 \; & 0 \; & 0 \
0 \; & 0 \; & 1 \; & 0 \; & 0 \; & 1 \; & 0 \
0 \; & 0 \; & 0 \; & 1 \; & 0 \; & 0 \; & 0 \
0 \; & 0 \; & 0 \; & 0 \; & 1 \; & 0 \; & 0 \
0 \; & 0 \; & 0 \; & 0 \; & 0 \; & 1 \; & 0 \
0 \; & 0 \; & 0 \; & 0 \; & 0 \; & 0 \; & 1 \
1 \; & 0 \; & 1 \; & 0 \; & 1 \; & 0 \; & 0
\end{array}
\right]
\end{array}
\end{math}


On a mathematical note. You can use the Adjacency Matrix to find the number of paths of length n between two nodes when you calculate An.

2.24.2006

BlueDot Safari Hacks

BlueDot is a new social search network, it is fun and useful, check it out at Blue.us.

A quick hack to dot in Safari is to save the stylesheet (http://www.blue.us/css/Authoring.css) to your computer and store it in your custom css for Safari (Preferences > Advanced >Style Sheet).

If you don't want to do it this way, you can make a bookmark like this to open up the Dot from Anywhere form at http://www.blue.us/DotFromAnywhere.aspx. To do this go to Bookmarks > Manage All Bookmarks. Select Bookmarks Bar and then make a new bookmark. Add the javascript code below as the url of the bookmark.

javascript:
{
var dotForm = document.getElementById("retroDotForm");
if (dotForm)
{
dotForm.style.display = "block";
}
}

They don't work together though. Once you add the BlueDot stylesheet to you custom stylesheet it will cause the Dot from Anywhere form to not display properly, so you have to choose your hack carefully.

The hack to reveal the Dot anywhere is slightly better in that you won't be left in the dust with changes to the css used by the website. It might be useful to update your local css file any major updates to the site or when you notice something going wrong.

Hopefully a better solution will be found.

2.19.2006

Flash 8 Preloader

If you are coming across this tutorial I will assume you already what a preloader is and why you use it. I am guessing you want to know the technical details the preloader, so I won't go into detail about what a preloader is. You can search Google for that answer.

I will also admit there are many different ways to write a preloader. For example, you can have multiple scenes, code which counts through 100 frames before advancing to the frame of the media. Even with simple scripting techniques the structure of code can very greatly as well. For example you don't need to use a listener object, just write your listeners as functions. With this said, here is the method that I used.

Step 1 - Make a .swf Movie File


Create a .swf file from your movie. You can do this with Flash, by importing video (File > Import > Import Video), or with 3rd party software, and then exporting it (File > Export > Export Movie). You can test the .swf file by opening it in a web browser.

Step 2 - Make a Flash File to Load your Movie


Here comes the fun part. I set up a new Flash document with 5 layers.



The layers are broken down into the following components

  • Functions - Auxillary actionscript functions

  • Preloader - Actionsript code for the preloader (sets up listener)

  • Movie - Contains the Movie Clip instance where the .swf file is loaded to

  • TraceBox - Contains an HTML text area that debugging statements are printed to

  • LoadText - Contains a dynamic text area that displays percentage of movie that is loaded


The two layers, Functions and TraceBox are only used for debugging purposes and can be removed once the preloader works. Because they are used for debugging, I won't go into detail about them. So the layers we want to focus on are Preloader, Movie and LoadText.

Step 3 - Make a Place for the Movie to Load


First we want to make a place for our Movie to load. To do this we need to make an instance of a Movie Clip. First, let's make a symbol (Ctrl/⌘+F8).



The symbol is now in your library and you can drag it onto a layer in your stage.



Since the movie clip I am loading is of me bouldering, I named the instance 'Bouldering'.



Our movie will load into this Movie Clip instance.

Step 4 - Create a Place to Display Loading Progress


Now Flash has a place to put the movie, but there is still no place to display information about the progress of our movie being loaded. There are many different ways display this information. It could be strictly graphic, or simply just text. Whichever way you choose to do it, you must make change your onLoadProgress function accordingly, see below.

In this simple example I create a piece of dynamic text on the LoadText layer. I set it to '0 %' initially since this is what will be displayed before any part of the file is loaded. I named the instance 'loadText'.

Step 5 - Write the Preloader


The method I used to load a movie was to use the new MovieClipLoader class. To use the MovieClipLoader class you must setup a listener before loading the movie with the loadClip method. The listener simply defines functions that will be called at certain events, for example when the loading is starting or ending. The methods I defined were onLoadStart,onLoadProgress and onLoadComplete. Once I add the listener to the MovieClipLoader I can load the clip. Now that the code has been explained, lets look at it:


var mcl = new MovieClipLoader();
var listener = new Object();

listener.onLoadStart = function (targetClip) {
targetClip._visible = false;
}
listener.onLoadProgress = function (targetClip, loaded, total) {
var percentage = (loaded / total) * 100;
_root.loadText.value = percentage + " %";
}
listener.onLoadComplete = function (targetClip) {
targetClip._visible = true;
}

mcl.addListener(listener);
mcl.loadClip("bouldering.swf", _root.Bouldering);


Now, lets break down the code:


var mcl = new MovieClipLoader();
var listener = new Object();


The code above simply creates a new variable of type MovieClipLoader and a generic object that will define listeners for our Movie Clip. The reason to use an Object to hold our listener functions is so we can create multiple movie clip loaders and make separate listeners for each of them without running into conflicts with function name. Or vice versa we can create multiple loaders and one listener that does something dynamic based on a variable set in the listener object.


listener.onLoadStart = function (targetClip) {
targetClip._visible = false;
}
listener.onLoadProgress = function (targetClip, loaded, total) {
var percentage = (loaded / total) * 100;
_root.loadText.value = percentage + " %";
}
listener.onLoadComplete = function (targetClip) {
targetClip._visible = true;
}


This code creates the listeners for the three events of a movie clip getting loaded, the start event, progress event and the complete event. In reality there are more events, but for this simple example I left out the other events like the error event.

onLoadStart gets called when the movie starts to load. I simple set our movie container to be hidden. The movie container will be revealed in the onLoadComplete method.

The onLoadProgress method is where all of the important work is done. This is the method that allows us to give important feedback about the progress of the movie being loaded. The two arguments loaded and total allow us to calculate a percentage. In this method I simply update the content of my dynamic text area to reflect the current progress of the load. _root.loadText will points to the instance of the dynamic text area created in step 3.


mcl.addListener(listener);
mcl.loadClip("bouldering.swf", _root.Bouldering);


The first line of this code tells Flash that the listeners it is supposed to use when firing events is from the listener object we created. The second line tells flash to load the .swf movie (created in step 1) to be loaded into the Movie Clip instance created in step 3. It is important that argument 2 of loadClip corresponds with the name of the instance created on your stage.

Recap


So each part is relatively simple. The key is to make sure you relate your ActionScript to your Flash file properly through the name of the Movie Clip instance. In this case it was 'Bouldering', but you can change it to whatever you like, as long as it is the same in both places.

Click here to view all the Flash files included.

2.08.2006

Checkerboard!

Rather than do anything productive I thought I would make another image function to use with the scripts i had uploaded earlier. Here is the javascript to make a checkerboard.

Script Your Images in Photoshop CS

Lately I have started to play around with scripting in Photoshop for my computer vision course. Here is something I came up with while working on a take home midterm. We had to describe an image described by an equation. Since our professor said we could write programs I decided to do it in photoshop. There are a total of 3 scripts, each of which I will describe next.

The first script is Document.js. This is simply a library function I created to make creating new documents a little easier. Rather than needing to specify all the arguments for a new image I can give a height and width and I will get a new photoshop document.

The second script is called CreateImage.js. This is the script that does all the work in Photoshop. It creates the new document and then iterates over x and y. At each pixel (x,y) a region of the image is selected and filled in with a color. The color is of type RGBColor and is retured from a function called ColorEquation. This function is passed (in order) x, y, width and height. It is your job to define ColorEquation. The function should create and return a variable of type RGBColor.

The third script is Image.js. This file defines two variables and a function (the least information needed to make an image). The variables are the width and the height. The function is called ColorEquation. This function will be given the current pixel (x,y), width of the image and height of the image. You can use these 4 values to construct a color for the pixel (x,y). The color will be stored and returned in a variable of type RGBColor.

Of course, since all of the source code is here for download, so you can it however you want. If you do make something cool please post a reply with some code. It will be cool to see.

1.24.2006

Forking in UNIX/Linux/OS X

Here is some code to fork a new process in UNIX and similar operating systems. Note: Forking is not most efficient method for multiprogramming because it is inefficient, but it is easy. The problem with forking is that it copies the whole address space of the parent process before resuming execution. In most cases people want to execute another program after forking. When an exec (or some variant of exec) is called, the first thing that happens is the address space of that process is wiped out and the new program is loaded into that address space. This is very inefficient because the kernel has to do all of this for the processes. If you don't want to copy the whole address space, check out the
vfork()
command. Here is the code anyways.


#include <stdio.h>
#include <unistd.h>

int main(void)
{
pid_t pid;
int wait_for_child = 1;
int exec_res;
int value = 1;

char* command = "/bin/ls";
char* command_name = "ls";

// Fork new process, copies address space of parent
// process so static data, stack and heap are not shared.
// See
pid = fork();

// Both child and parent processes start here after the
// fork is called

if (pid == 0)
{
// Increment value in childs address space
value++;

// This is the child process
printf("I am the child. [%i]\n", value);

exec_res = execlp(command, command_name, NULL);

// Need to exit on error
if (!exec_res)
{
printf("Error. Could not exec.");
}

// Exit child process
exit(0);

}
else if (pid > 0)
{

// wait_for_child if exec is synchronous
if (wait_for_child)
{
printf("Wait for child to finish before resuming.\n");
wait(NULL);
}

printf("I am the parent. My child is %i. [%i]\n", pid, value);
}
else
{
printf("Error. Could not fork.");
}

return 1;
}

1.21.2006

Replace Colors with ImageMagick

ImageMagick has a great utility called convert. It allows you to do many things, including replacing one color in an image with another.

convert -fill #FFC232 -opaque #000000 inputfile outputfile

This will relace all the black pixels in an image with a dark yellow color. This is only a small part of what ImageMagick utilities can do. I recommend downloading them all.

1.09.2006

Reverse a linked list

This algorithm is a little more efficient than the last I posted about sorting a linked list, running in O(N) time. The algorithm requires a doubly linked list.


queue_length = queue_size(q);

front = q->head;
back = q->tail;

for (i = 0; i < queue_length / 2; i++) {

temp = front->e;
front->e = back->e;
back->e = temp;

front = front->next;
back = back->prev;
}

Sort a linked list

This is not an efficient way to sort a linked list (runs in O(N2), but it works when you don't care about efficiency (sometimes homework for a class). This code sorts a linked list in place with bubble sort.


do {
num_swaps = 0;
cur = q->head;
while (cur) {
if (cur->next) {
res = queue_element_compare(cur->e, cur->next->e);
if (res == 1) {
temp = cur->e;
cur->e = cur->next->e;
cur->next->e = temp;
num_swaps++;
}
}
cur = cur->next;
}
} while (num_swaps > 0);


queue_element_compare returns 0 on equal, 1 if e1 > e2 and -1 when e1 < e2.