Posts Tagged ‘Programming’

ActionScript Animation

Posted in Programming on June 10th, 2009 by Jamie – Be the first to comment

Kosal had a problem pausing between tweens. We went through several revisions.

First I suggesting defining the tween properties via array and using anonymous functions passed to the setTimeout function.

We found out anonymous functions were a no-go in his version of ActionScript. Then, I suggested using globals, which resulted in the following code:

// globals

var g_mc,
	g_a,
	g_b,
	g_c;

function animate () {
	var arr = [
			// mc, slideto vars, timeout
			[ car, 200, 100, 1, 10 ],
			[dog, 200, 100, 5, 5]
		];

	var timeout = 0;
	for ( var i = 0; i < arr.length; i ++ ) {
		var item = arr [ i ];
		g_mc = item [ 0 ];
		g_a = item[1];
		g_b = item[2];
		g_c = item[3];

		timeout += item[4]; // total seconds to timeout

		setTimeout ( doSlide, timeout );
	}
}

function doSlide () {
	g_mc.slideTo ( g_a, g_b, g_c );
}
</code>

That had a problem with it, as when I was visualizing the code, I forgot that the globals would always point to the last array. We finally wound up with the code below, which uses recursion instead.
<code lang="actionscript">
// globals

var g_index = 0,
 g_arr = [];

function animate () {
 g_index = 0;
        g_arr = [
 // mc, slideto vars, timeout
 [ car, 200, 100, 1, 10 ],
 [dog, 200, 100, 5, 5]
 ];
        doSlide ();
}

function doSlide () {
        if ( g_index < g_arr.length  ) {
 var item = g_arr [ g_index ];
 g_mc = item [ 0 ];
 g_a = item[1];
 g_b = item[2];
 g_c = item[3];

 g_mc.slideTo ( g_a, g_b, g_c );
        	g_index ++;
         setTimeout ( doSlide, item[4] );
 }
}

Stack Overflow – Digg and Expert Exchange’s Love Child

Posted in Programming, Websites on April 3rd, 2009 by Jamie – Be the first to comment

There’s a great new–I think it’s new–site that combines the best aspects of Digg and Experts Exchange into a fun and addicting way to help and be helped!

http://stackoverflow.com/

Look me up:

http://stackoverflow.com/users/85905/jamie

T-SQL Export Table Data

Posted in Programming on April 1st, 2009 by Jamie – Be the first to comment

Here’s a quick script to export table data:

if exists ( select * from sysobjects where name = 'ExportData_P' )
	drop proc ExportData_P
go

CREATE PROC dbo.ExportData_P (
	@tableName varchar(500),
	@where varchar(5000) = '(1=1)'
)
AS
BEGIN
	SET NOCOUNT ON

	DECLARE @sql varchar(8000)
	DECLARE @fieldList varchar(8000)
	DECLARE @valueList varchar(8000)
	SELECT @fieldList = '', @valueList = ''

	DECLARE @cols TABLE ( column_name nvarchar(250), data_type varchar(250) )
	DECLARE @c nvarchar(250), @data_type varchar(250)

	INSERT INTO @cols
	select column_name, data_type
	from information_Schema.columns
	where table_name = @tableName

	WHILE EXISTS ( SELECT TOP 1 * FROM @cols )
	BEGIN
		SELECT TOP 1 @c = column_name, @data_type = data_type FROM @cols

		SELECT
		@fieldList = @fieldList + @c + ', ',
		@valueList = @valueList + CHAR(13) + 'case when ' + @c + ' is null then ''NULL'' else '''''''' + ' +
			case when @data_type in ('text','ntext','char', 'nvarchar', 'varchar' ) then
				' REPLACE ( REPLACE ( REPLACE ( '
				else ''
			end +
			'IsNull ( convert(varchar' +
			( -- change this section to pass the length of varchar to convert
				case when @data_type in ( 'uniqueidentifier' ) then '(50)'
					when @data_type in ( 'text', 'ntext' ) then '(8000)'
				else '' end
			) +
			', ' +
			@c +
			'), '''' )' + -- end is null
			case when @data_type in ('text','ntext','char', 'nvarchar', 'varchar' ) then
				', CHAR(39), CHAR(39)+CHAR(39) ), CHAR(13), '''' + CHAR(13) + ''''), CHAR(9), '''' + CHAR(9) + '''') '
				else ''
			end +
			' + '''''''' end + '', '' + '

		DELETE FROM @cols WHERE column_name = @c
	END

	SELECT @fieldList = LEFT ( @fieldList, LEN(@fieldList)-1 ),
		@valueList = LEFT ( @valueList, LEN(@valueList)-1 )

	SELECT @sql = 'select ''insert into ' + @tableName + ' (' + @fieldList + ') ' +
		' VALUES ( ''+ ' + left ( @valueList, len(@valueList)-5) + ''') '' from ' + @tableName +
		' WHERE ' + @where

	-- into [#mcoe_temp_export' + @tableName + ']
	print @sql
	EXEC ( @sql )
	--EXEC ( 'select * from [#mcoe_temp_export' + @tableName + ']' )		

	SET NOCOUNT OFF
END

go

exec dbo.ExportData_P 'tablename'

JSXGraph

Posted in Libraries on March 24th, 2009 by Jamie – Be the first to comment

Awesome JS graphics library compatible with JQuery and Prototype.

JSXGraph ยป Examples

Gesture Recognition

Posted in Libraries on March 24th, 2009 by Jamie – Be the first to comment

I came across an awesome article on simple gesture recognition.

This page implements a “$1 Gesture Recognizer” that is easy, cheap, and usable almost anywhere. It requires under 100 lines of easy code and achieves 97% recognition rates with only one template defined for each gesture below. With 3+ templates defined, accuracy exceeds 99%.

http://depts.washington.edu/aimgroup/proj/dollar/


Before We Begin in Earnest

Posted in Uncategorized on March 24th, 2005 by admin – Be the first to comment

I haven’t written for awhile, so here are my last series of entries before I retire this blog.


PatientPro Design Diary

Before We Begin In Earnest

As a prepubscent child, I had but a passing interest in computers. They were as enchanting in their use as edutainment devices–I must’ve hogged our classroom computer playing Oregon Trail for hours. I even got a chance to “program” in sixth grade, when we were introduced to Basic. I created a program to display an image of Darkwing Duck on screen by drawing the cartoon character on graph paper and plotting pixels by hand–I felt like I was on the bleeding edge of technology. Still, at home, I didn’t have a computer, and to aggravate matters, I had a Nintendo. So, instead of becoming profiecient with computers at an early age, I learned to excel at video games.

My highschool years offered increased contact with computers at home and at school. My dad purchased a gleaming new Gateway (which still served as the family’s main computer until a couple months ago), a Pentium II 233 with 10 gigabytes of space. At the time, it cost a couple thousand dollars. At school, we had rows of computers, but they were Macs, and I hated Macs.

My interest in computers mushroomed when I took my first real programming class. We used Borland’s Turbo C compiler to do trivial tasks that I excelled at. My senior year, I decided to go to Drexel University to study Computer Science, and I took the Computer Science AP* class at my high school. It was an interesting class that gave me lots of things to talk about when I went to my scholarship interview at Drexel. I was able to talk to Professor Bruce Char about things like linked lists and recursion.

I’ve been blessed with the chance to do pretty much anything I want to do in life–it’s a rare gift that the best of us never receive. So, why did I choose to major in Computer Science?

  1. I love computers!
  2. I am part idealist and part pramatist, and the job outlook for computer science graduates was looking pretty good in 2000.

These past five years, there have been many times when the work seemed impossible to finish, or the rewards too little to drive me forward. Still, I have learned so much, and have had fun doing it. My love of computers has only become deeper, an intimate relationship cultivated over several years.

Now, everything I have learned in college will be tested with one final project. To me, my success or failure with this project will measure the progress I have made these passed five years. That project is PatientPro.


* I received a 1 on the Computer Science AP test, the lowest score one can receive on an AP test.

Reversi (Java)

Posted in Programming, Software on July 2nd, 2004 by Jamie – 2 Comments

This program was written for my first AI class at Drexel University. It features an AI opponent using the MiniMax algorithm.

A Youtube video of the program in action is provided in case you do not want to download the executables:

To run, download the zip file, unzip, and run:

java OthelloApplication

The game was designed to be run as an applet but may not work as such.

Project Page (Downloads available)

Homework Update

Posted in Programming on May 24th, 2004 by admin – Be the first to comment

Homework Update!

Work hard people! We’re almost done! Yay!

Finished

Travelling Tournament Problem [see last wednesday's entry] (cs381)
- 8 teams
- 10/12 teams not fully functional

Othello v .3 (cs451)
- added midgame save feature
- added load feature
- added test units and coverage reports

To Finish

Several Concurrent Programming Problems (cs361) due 5/31
- 1 semaphore problem
- 3 monitor problems

Lucky 13 V .2 (cs338) due 6/1
- will add random ai
- will add gui

Group Term Paper (psy337) due 6/1
- topic: verbal protocols

Human Sociology as Related to PCs (psy337) due 6/1

Party GUI

Posted in Uncategorized on December 3rd, 2003 by admin – Be the first to comment

My party goers, click here to see a list of couples who will be playing for title of “Best Couple.” http://dusers.drexel.edu/~asian/bd2003/gui.swf

This is version 1 of my party-competition interface. I tested the login on my laptop and it worked fine, but I believe the dusers server uses a older version of PHP, so my scripts may need to be modified.

CS/IS/Computer-Related FAQ

Topic: My Party Competition Interface

Question
What did you use to build the interface? How does it work?

Answer
Well, you should all have realized that the graphical user interface (GUI) is presented in Flash SWF format. A discussion on how flash works is beyond the scope of this lesson; suffice it to say that it is a wonderful medium for web-based multimedia.

Each person, along with their email address, full name, and password is stored in a database table called ‘People’. Each of these people has a unique numerical identifier.

Each team, along with the numerical identifier corresponding to the captain of the team and his/her partner, their team name, and score, is stored in a database table called ‘Teams’. Each of these teams has a unique numerical indentifier.

Using PHP: Hypertext Preprocessor (PHP), the database is queried, and class objects corresponding to each Person and each Team are created.

These objects are sent to an XML Renderer, where their attributes are parsed into XML. To see the Renderer in action click one of the following links: View All People | View All Teams.

Flash loads this dynamically generated XML and generates its own internal objects representing each person and each team.

A movieclip instance for each person is created within Flash, as well as for each team, and the results are displayed as what you see.

SQL Joins

Posted in Uncategorized on November 24th, 2003 by admin – Be the first to comment

CS/IS/Computer-Related FAQ

Topic: SQL

Question
What are joins? What is the difference between all of the different types of joins?

Answer
A join is the combination of columsn across multiple tables. This differs from a union, in that unions are combinations of rows.

The join syntax looks something like:
SELECT * FROM tbl1 [LEFT | RIGHT | INNER | OUTER] JOIN tbl2 ON tbl1.id=tbl2.id;

The syntax of course can have slight variations with additional or alternative keywords. The line above will append the columns of tbl2 onto tbl1, aligning records where the id field of tbl1 is equal to the id field of tbl2.

An inner join will return all those records in tbl1 that have a match in tbl2.
A left join will return all records in tbl1 regardless of it having a match in tbl2. Any missing fields will be filled with NULL.
A right join will return all records in tbl2 regardless of it having a match in tbl1. It is important to note that a left join can be made into a right join by swapping the order of the tables.
An outer join will return the cross product of the tables, meaning all possible combinations from tbl1 and tbl2.

This concludes today’s tip. Thank you for joining me. A har har.