FTP is Getting Mean…

By , January 17, 2012 6:52 pm

Just noticed this when timing out on FTP.  Guess FTP gets mean when you ignore it.

FTP Getting Mean...

FTP Getting Mean...

XFDL with PHP 2…

By , January 6, 2012 7:49 am

Recent progress with doing XFDL forms in PHP.  I put some time into this project recently figuring that this web based viewer would be the most applicable.  Think if AKO’s MyForms, a setup where you can pass forms from one user to the next to get it filled out and signed; if that program never needed to leave the web?  With doing XFDL forms in PHP, that is possible!  My code is a mess right now so I will put up the PHP, Javascript for the page on a later post.

For now, go to the old version to see what the forms should be like and go to the new version to see progress on the viewer.

My Nomination

By , December 23, 2011 7:25 am

My nomination for Time’s “Person of the Year.”  The though when I made this image was that the Seal Team 6 Member that shot Osama Bin Laden would be so secreted that he’d have name redacted and even his silhouette would be hiding his eyes.  Enjoy the picture and Merry Christmas!

Time's Person of the Year

My nomination for the person of the year.

wxWidgets and ODBC…

By , November 4, 2011 5:25 pm

Since wxWidgets > 2.8 has dropped wxODBC, I decided to learn how to use sql.h on my own.  I made a simple program to retrieve and print data in C for the command line and everything worked well.  Unfortunately, when I placed this code in my wxWidgets GUI program, it failed.  This was due to wx being unicode, so I had a whole world of learning on how to make sql.h talk with wx.  I’ve outlined the steps to make this work:

With ODBC, sql.h can work with unicode, the functions are the same, but different variables are sent.  WX defines as Unicode (as it’s usually compiled) and ODBC will map the function to the unicode variant.  For example, in a C++ program with #define UNICODE 1, such as WX, SQLDriverConnect will map to SQLDriverConnectW, the unicode variant.  The other option is SQLDriverConnectA which will allow ANSI variables.  Most of the functions you’ll need have an ‘A Variant’, which is what I’ll refer to the functions ending in A.

To Send Data:

  1. Cast your variable as a SQLWCHAR pointer.
  2. Set a string to that pointer, type cast the string too.
  3. Use the functions of ODBC that end with an A.
  4. Send that function a variable type cast as (SQLCHAR*).
SQLWCHAR *connStr;
connStr = (SQLWCHAR*)"DSN=testDB;";
SQLDriverConnectA(dbc, NULL, (SQLCHAR*)connStr, SQL_NTS,
    (SQLCHAR*)outstr, sizeof(outstr), &outstrlen,
     SQL_DRIVER_COMPLETE);

To Return Data:

  1. Do the same steps.
SQLWCHAR colName[256];
SQLDescribeColA(hstmt, i+1, (SQLCHAR*)colName, 255, &colNameLen,
      &dataType, &colSize, &numDecimalDigits, &allowsNullValues);

Convert SQLWCHAR to wxString:

  1. Use wxString’s PrintF() function and interpret the variable with a capital S.
SQLWCHAR colName[256];
wxString test;
test.PrintF(_("Column Name: %S"),colName);

Convert wxString to SQLWCHAR:

  1. Declare your buffer variable as SQLCHAR array.
  2. Cycle through each char in wxString and assign to your SQLCHAR array.
  3. Add a null value on the end (so SQL_NTS knows to stop!)
  4. Typecast the variable as a pointer in send.
wxString send = wxT("SELECT * FROM master");
SQLCHAR sqlTest[1024];
unsigned int j;
for(j=0;j<send.Len();j++) {
sqlTest[j] = send[j];
}
sqlTest[send.Len()] = _T('\0');

SQLPrepareA(hstmt, (SQLCHAR*)sqlTest, SQL_NTS);

Watch Out! Here comes a dart!!

By , October 13, 2011 12:58 am

It’s like if php and java met on a lonely night, dart would be the result.

Google Dart, a new language developed to be the ‘new javascript’ is soon to be available from Google.  Check out the webpage that’s set up to show you the language and give a nice tutorial.  It has an interpreter on the page so you can tinker and get a feel for it.  It seems to me, after playing with the language a bit, it’s like if php and java met on a lonely night, dart would be the result.  An advantage of this language, is unlike HTML5, you will not have to wait for a browser to be made to understand this language.  It can be cross-compiled to javascript on the server side until browsers catch up!  Unfortunately, this is not something I’ve been able to apply to a live server, yet.

XFDL in PHP…

By , September 19, 2011 3:34 am

Lately, I have started working on the OpenXFDL project again, concentrating efforts in making a C++ application with WX Widgets that can compile for Windows, Mac, and Linux.  Getting frustrated with libxml2 and wanting to learn more of xpath queries, I decided to make a XFDL reader in PHP.  This can be applied easily as browser/e-mail plugins to view XFDL forms without the need of an external viewer.  I’ve been bad about posting but I’ll work to add more to this blog soon.  For now, here is a sight to try it out with.  Unlike previous stuff, you can do a straight XFDL form instead of converting to XML first.  Try it out!

Apologize…

By , March 26, 2011 12:06 am

I know its been awhile since I’ve posted on here.  About a month ago, I got a new job where I’m working overnights so its been tough getting programming as a hobby in and especially writing as it while I adjust to the new work shift.  Some projects I’ve been working on:

1. I’ve gotten real heavy into using microprocessors.  Recently, I’ve gone to programming on the Arduino to using the ATMega in its own circuit (programmed while on the Arduino board for testing and then once ready to complete, finishing it on its own circuit.)

2. As usual, working on an XFDL for Linux project.  The GUI in WXWidgets is coming along, working out using libxml2 to parse the file, which is taking awhile but its beginning to flow.  Keep checking back for updates as they happen.

3. Finally got a Mac OSX running with xCode in Virtual Box.  I’m going to get back into Objective C and iPhone apps as I get it working more smoothly.

Thank you for checking in, I’ll be posting more regularly from here on out.

Fixing libcoolkey…

By , January 24, 2011 1:49 pm

With my new CAC card, I found that libcoolkey.so was not working with Firefox correctly.  The new, 144k CAC cards do not play well with the old version of libcoolkey.  I did find that the ‘experimental’ release of libcoolkey will fix this problem, here is the fix:

amd64 (64bit)

sudo su
apt-get purge coolkey libckyapplet1 libckyapplet1-dev
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1_1.1.0-7_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1-dev_1.1.0-7_amd64.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/coolkey_1.1.0-7_amd64.deb
dpkg -i libckyapplet1_1.1.0-7_amd64.deb libckyapplet1-dev_1.1.0-7_amd64.deb coolkey_1.1.0-7_amd64.deb

i386 (32bit)

sudo su
apt-get purge coolkey libckyapplet1 libckyapplet1-dev
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1_1.1.0-7_i386.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/libckyapplet1-dev_1.1.0-7_i386.deb
wget http://ftp.us.debian.org/debian/pool/main/c/coolkey/coolkey_1.1.0-7_i386.deb
dpkg -i libckyapplet1_1.0-7_i386.deb libckyapplet1-dev_1.1.0-7_i386.deb coolkey_1.1.0-7_i386.deb

A side note, if you are registered with https://software.forge.mil/, then there is a fix in the project ‘Community CAC’ that includes libcackey which offers a fix for this as well.

Netflix on Linux.

By , January 24, 2011 1:32 pm

Netflix is a great resource for watching videos, particularly the ‘Watch Now’ feature for instant streaming.  Unfortunately, for Linux users, Netflix uses a Microsoft PlayReady, Silverlight plugin for this feature.  This is to protect the content from piracy (arrgh, pirates!!) so they have no problems with copyright.  Too bad for Linux, as this feature is not available in any way, shape, or form.  There is no way to develop a fix for to use this in Linux either, as PlayReady is proprietary.  If this angers you as much as it should any Linux user, that the only work around is to use Windows, then please visit and sign this petition.

#! Statler – b43 driver fix.

By , January 15, 2011 12:45 pm

This week I switched to #! (Crunchbang) because my Ubuntu was getting slow.  I love the speed and was very happy with the wifi because it had the b43 driver working by default.  Except, I could not get on my network after the most recent upgrade, but I found a work-around after a day of reading forums.  Surprisingly, it’s not too complicated!  You just need to create a conf file for b43 to use PIO and it will not through a DMA error anymore… my hardware is: Broadcom Corporation BCM4312 802.11b/g LP-PHY [14e4:4315] (rev 01).  This is the only line you should need.

sudo echo "options b43 pio=0 qos=0" > /etc/modprobe.d/b43.conf

Reference: This article from Ubuntu Forums.

Disappointment with IE.

By , January 10, 2011 10:48 am

A pivotal question in development is whether to use new technology or not. HTML5 and CSS can make great pages but Internet Explorer, being a huge portion of the browsers used, does not handle these except in the most recent versions. A quick google search led me to this page which had a great script to work with this problem. The work around is to create new elements to match HTML5. The detailed analysis is located in the link above.

<!--[if IE]-->
	<script type="text/javascript">
		(function(){
			var html5elmeents = "address|article|aside|audio|canvas|command|datalist|
				details|dialog|figure|figcaption|footer|header|hgroup|
				keygen|mark|meter|menu|nav|progress|ruby|section|
				time|video".split('|');
			for(var i = 0; i < html5elmeents.length; i++){
			document.createElement(html5elmeents[i]);
			}
		}
	)();
	</script>
<!--[endif]-->

EDIT: Got the page looking like I want it in IE, Firefox and Chrome/Safari but found the above script was not needed.  I surrounded my HTML5 elements (<header>, <footer>, and <nav>) with <div> tags that include the desired HTML5 element.  This makes for an easy move to HTML5 when it’s more broadly implemented. Example:

<div class="footer">
	<!-- Include the same class name only if you want CSS styling specific to the footer -->
	<footer class="footer">This is my footer text.</footer>
</div>
.footer {
	position: absolute;
	background-color: black;
}

Hallmark Postcard Hoax — Disappointing.

By , December 16, 2010 11:38 am

Today I received a warning e-mail about an e-mail virus.  Immediately I responded to the sender to let me know if they get an e-mail with this attachment because it would be a nice ‘exhibit’ for my ‘virus zoo.’  To explain, I have a computer lab I’ve set up to run and test viruses (correct plural form of virus).  For anyone with interest as to why, it is the best way to understand vx problems and make resolutions.  Additionally, I just find it fun to reverse a virus and do my portion of good Samaritan duty and send any resolutions to the internet so that the virus can be fixed and therefore mitigate the ability of that virus to be destructive.

On the second read, I realized that this was ‘too good to be true’ from the perspective of a virus junkie.  Here is the e-mail with the signs of a hoax highlighted:

You  should be alert during the next few days. Do not  open any message
with an attachment  entitled  ’POSTCARD FROM  HALLMARK,’regardless of who sent
it  to you.
It  is a virus which opens A POSTCARD  IMAGE, which ‘burns’ the
whole hard  disc C of your  computer.

This  virus will be received  from someone who has your  e-mail address in
his/her  contact list. This is  the reason why you need to send  this e-mail
to all  your contacts. It is better to  receive this  message 25 times than
to receive the  virus and  open it.

If  you receive a mail called’  POSTCARD,’ even though  sent to you by a
friend, do not  open it!
Shut down  your computer immediately. This is  the
worst virus  announced by  CNN.

It  has been classified by  Microsoft as the most  destructive virus ever.
This  virus was discovered  by McAfee yesterday, and there is  no repair yet
for this kind of virus.
This virus  simply destroys  the Zero Sector of
the Hard Disc
,  where the vital  information is  kept.

Here’s a breakdown of that e-mail.  Keep in mind this e-mail was supposedly forwarded from a group that has some decent computer knowledge (enjoy the Christmas color theme!):

  1. which ‘burns’ the whole hard  disc C of your  computer….This virus  simply destroys  the Zero Sector of
    the Hard Disc…

    • Compare these two statements.  Does this virus burn the whole hard disk or the zero sector?
    • Assuming ‘zero sector’ means the Master Boot Record (MBR), that is a small sector of your whole hard drive.
    • Have to ask yourself why just the C: drive and not the whole drive?
  2. Shut down  your computer immediately.
    • This is simply bad advice.
    • If it was a real virus, just don’t open the file and delete the e-mail.
    • On some e-mail clients, e-mail images are automatically opened which means it’s too late anyhow.
  3. This is  the worst virus  announced by  CNN…It  has been classified by  Microsoft as the most  destructive virus ever.
    • I’ll give you the ‘Blog Reader of the Day’ award if anyone can find this virus listed with these phrases from either company!
    • ‘Work Virus’ and ‘Most Destructive Virus Ever‘ seem more than extreme.
    • Frankly, there are worse viruses in the computer world that do worse than erase data on one machine.
  4. The use of ‘psuedo-technological terms’ is  a bad sign.  Refer to the first point about the ‘zero sector’ vs. hard drive issue.

So, after thinking about all of this, I did a google search for ‘hallmark postcard virus’ and without even reading articles realized that this was virus was too good to be true.  Here’s a list of the top results:

  1. Snopes.com
  2. About.com
  3. Hoax-Slayer
  4. Ezine @rticles
  5. Sophos

To be fair, a couple of those came from a search for ‘zero sector’ which resulted in finding this previously used e-mail (Does this sound familiar?):

You should be alert during the next days: Do not open any message with an attached filed called “Invitation” regardless of who sent it. It is a virus that opens an Olympic Torch which “burns” the whole hard disc C of your computer. This virus will be received from someone who has your e-mail address in his/her contact list, that is why you should send this e-mail to all your contacts. It is better to receive this message 25 times than to receive the virus and open it.

If you receive a mail called “invitation”, though sent by a friend, do not open it and shut down your computer immediately.

This is the worst virus announced by CNN, it has been classified by Microsoft as the most destructive virus ever. This virus was discovered by McAfee yesterday, and there is no repair yet for this kind of virus. This virus simply destroys the Zero Sector of the Hard Disc, where the vital information is kept. SEND THIS E-MAIL TO EVERYONE YOU KNOW, COPY THIS E-MAIL AND SEND IT TO YOUR FRIENDS AND REMEMBER: IF YOU SEND IT TO THEM, YOU WILL BENEFIT ALL OF US

Now, I think it’s pretty well established that this e-mail is a hoax.  The point of this post is just to make the reader aware of the e-mail itself.  Regardless, it is important to remember to update your anti-virus software and use all due caution when opening e-mail attachments.  Several viruses do exist and reproduce in this manner and it is important to realize these consequences are real.

I’m Back…

By , December 13, 2010 9:38 am

Sorry for anyone who watches this site.  After the last server upgrade, this site went offline and I was not able to focus my attention on it until I’d returned from my Army school.  Now that I’m back though, I have several projects getting ready to go, here’s a list of what to expect over the next couple months:

  1. Return to the garmin wardriver project.
  2. A python based minesweeper (ncurses).
  3. XFDL projects (primarily MS Access integration).

That’s just a short list of what is on my mind.  It’s great to be back on-line!

Slow Down…

By , August 4, 2010 12:56 pm

Some of the avid readers may of noticed a slow down in the frequency of my posts.  That is because I am preparing to go to a school with the Army (BOLC) for the next four months.  Due to the pace of this school, I will be doing far less development and it’s likely I’ll have less internet access.  I have not gone away and this page is not dead though.  I will post as able while gone but everything will return to normal when I’m back home.

Navigating views on iPhone.

By , July 29, 2010 10:17 am

Its been awhile since I’ve posted anything, but I’ve been obsessing over an iPhone application.  I have three views set and was able to switch forward to next views pretty easily following several online tutorials that were available.  My favorite of which is this blog/tutorial.

That’s all well and good that I can move my views forward but how do I go back?  For this, I had to use some time, Google and Apple’s references and was able to find how to utilize the navigation controller.  See, my views did not have room for a navigation bar but I had used buttons to do the same.

After much testing and research, I found this simple line of code to move the page back.  In fact, once I used that everything about the navigation controller began to make sense!  I was just sad that there were no blog posts, tutorials or forums that had this method listed, so I decided to make sure there was at least one!

// Method: - (UIViewController *)popViewControllerAnimated:(BOOL)animated

-(IBAction)pageBack:(id)sender {
	[self.navigationController popViewControllerAnimated:YES];
}

Geocache idea.

By , July 6, 2010 5:38 pm

So recently, I’ve been doing geocaching.  This is a lot of fun and great to do with children.  As I find caches, I get the feeling I should add one and I’ve thought it’d be fun to make it more nerdy than the sport already is.  The device I’m thinking of would incorporate using electronics in a waterproof box.  Obviously, as I build this, I’ll post it but the concept is simple…  A bit of PIC programming, some buttons and LED’s should be all that’s needed.  Then create a lock that will open with the right combination.  So press button A and a red light is on.  This should signal the next button and make about 4 stages of this and the lock is open.  Any geocachers have input on this?

An Idea.

By , July 6, 2010 5:33 pm

Okay, this may be a rather dull post but here’s an idea and input would be helpful from those who’ve done this type of thing. So, a few years ago I did a lot with rocketry. A move to a less open area and the addition of kids caused a slow down, to a point. The kids love it but I don’t have the time to build the big ones until they get a little older. Anyhow, in that time I dabbled a bit with electronics.

My idea is a fun project my kids (6 and 7 years old) may have fun helping with. I’m sure it’s been done many times but make a radio that is controlled by a serial interface. I am constantly in work environments that block streaming radio, but I thought it’d be fun to make a device that will plug into a serial interface and it can receive the sound data as well as be able to control the channel and such through a program.

Anyone with experience in serial devices is welcome to contribute an opinion. Like most projects that seem simple, I’m sure this is not but thank you for your comments!

VBA – User Defined Type

By , June 25, 2010 10:06 am

As much as I do not like VBA, I do like the “User Defined Types” which, from a C/C++ programmer’s prospective, this is a lot like using structs.  And for data management, which is probably 90% of what VBA is used for, it makes a lot of since.  How do we define a User Defined Type?

Private Type dict
    a As Integer
    b As String
    c As String
    d As Integer
End Type

Once Defined, we need an initialization function to store the struct.

Private Function defineDict() As dict
    defineDict.a = 1
    defineDict.b = "two"
    defineDict.c = "three"
    defineDict.d = 4
End Function

At this point, we can use the same calling to to that ‘struct’ to change the variables as needed.

Sub testType()
    Dim t As dict       ' Set the variable
    t = defineDict      ' Initialize
    Debug.Print t.b     ' Prints >> "two"
    t.b = "no more"     ' Change a variable
    Debug.Print t.b     ' Prints >> "no more"
End Sub

Minesweeper Guide

By , June 24, 2010 1:38 am

So the classic game of Minesweeper is a great waste of my time.  I’ve found though, the secret to being successful is understanding the 2′s.  I’ll demonstrate with a series of screenshots.  I’ll remind my readers that the Minesweeper I use is Linux based, and Windows’ Minesweeper is somewhat different.  For example, the version I’m using will always have the upper left corner free and there is always a solution through logic.  Unfortunately, in Windows, there are times when no logic will fix it.

Now, I’ve created a program to solve the puzzles, but it’s no where near as fun.  For the cheat program (for Windows XP version) check out my tutorial.  It’s a good read on using C in Windows to pull information about a program, or hooking, as it is better known.

The key for all the graphics is:

  • RED = MINE
  • YELLOW = MAYBE
  • GREEN = CLEAR

The first three graphics will show a common pattern with a 5 and some a row including 2′s.  When 2′s are in a row, you can start eliminating.

EDIT: I plan to continue updating this, but for now I’ll post as is.

GZip with ZLib

By , June 22, 2010 8:41 am

In an effort to use zlib in VBA, I had to first learn to use it.  I’m looking to gunzip the XFDL files to use the data as an MS  Office plugin.  In tinkering with zlib’s GZip functions, I found them to be very much like normal file handling in C.  Here’s a link to the official zlib reference manual, GZip is the tenth section.  So, to test it, I made a “micro-gunzip” which does work well.  When compiling, don’t forget to link to libz.a using gcc -o out -i in.c -lz.   Other than that, enjoy!  The basics are covered in the comments.

#include <stdio.h>
#include <zlib.h>
/* gcc filename.c -o outname -lz */

int main(int argc, char *argv[]) {
	// variables
	gzFile gFile;           // gzip file object
	FILE *pFile;            // out file object
	char *filen = argv[1];  // get the name of the file
	char buffer[100];       // buffer for reading

	// open files
	gFile = gzopen(filen, "rb");        // same as file
	pFile = fopen("example.out","wb");
	if(pFile == NULL || gFile == NULL)
		perror("Error opening file");
	else {
	    // write
		while(!gzeof(gFile)) {
			gzgets(gFile,buffer,100);   // file object first
			fputs(buffer,pFile);        // write to plain tex
		}
		// close
		fclose(pFile);
		gzclose(gFile);
	}
	return 0;
}

NCOER Spreadsheet – Done

By , June 11, 2010 3:13 pm

Okay, so I’ve updated my code and I’m ready to release to the world my NCOER speardsheet.  Here’s a quick tutorial on how to use it.

  1. Download the Excel 2007 or Excel 2003 version. (Right Click and Save As)
  2. Ensure that you have enabled macros [ Office 2007 ] or [ Office 2003 ] for your MS Excel.
  3. Open the file you downloaded.
  4. Enter the unit you need the report for in the textbox on the left.
  5. Click Update
  6. It will prompt you for your AKO Username/Password to access the data.
  7. Wait a short time and it will automatically load and filter.
  8. Print or export the data as needed.

And that’s it.  I know military types read this blog (proven through the Open XFDL project) so please comment and let me know your opinion!

NCOER Spreadsheet

By , June 11, 2010 2:30 am

Last week, I complained about how bulky VBA (Visual Basic for Applications) can be.  My current project is to create a spreadsheet to keep track of upcoming NCOERs.  This is an easy task in anything but the most used and abused application the admin personnel in the Army use, Microsoft Excel.  Now, the data is easy enough to pull once you get an SSL connection with this website (to access you need to use an AKO Username/Password.)  The Interactive Web Response System will allow you to pull data on any past, due or current NCOERS (Evaluations).  This is great as I can track our evaluations as they move up the chain and will see when they are late.  Unfortunately, the web designers have only sorted the information by last name.

So, my basic program is complete.  I can make a connection (fortunately, MSXML6.0 makes an easy post request to an SSL website… something that if using Python, is not an easy task.)  It would appear that it is utilizing Internet Explorer’s library for the connection.  Once the connection is made and the data is loaded, then I parse.  Here is where VBA gets bulky.  Fortunately, I can use a reference to VBScript’s RegEx object, but it is far from being as complete as say, any other regex engine in any other language.  On top of that, parsing text through splits and such is an amazing pain.  Here’s an example.

Python:

import re
test = 'A simple "test of the languages" will show how bad VBA is!'
a = re.findall(re.compile(r'".*"',re.I),test)
print "Result = %s" % a[0]
## Result = "test of the languages"

VBA:

Private Sub CommandButton1_Click()
    ' must include Microsoft VBScript Regular Expressions 5.5 in references
    Dim re As New RegExp
    Dim testing As Variant
    Dim test As String
    ' to escape quotes "" can be used or chr(34).
    ' unbelievably, chr(34) is easier to read than ""
    test = "A simple " & Chr(34) & "test of the languages" & Chr(34) & " will show how bad VBA is!"
    re.Pattern = Chr(34) & ".*" & Chr(34)
    re.IgnoreCase = True
    Set testing = re.Execute(test)
    Range("A1").Value = "Result = " & testing(0)
    ' Result = "test of the languages" in "A1"
End Sub

See the difference?  I know it’s pretty close but keep in mind, this is a single line of text.  Multiple lines, large text files, etc. can be horrendous.  What in the world is left, mid and right anyhow?  I know 90% of this is that I refuse to touch this language if I can avoid it but still, this is ridiculous!!

Fern Screensaver : Part 4

By , June 3, 2010 1:11 am

I’ve now completed the Fern Screensaver in Objective-C for the Mac!  Surprisingly, using Objective-C was not that far from C/C++.  In fact, much of my code could be pasted directly in.  That includes the variables, math functions, etc.  Also, Mac has done a good job of documenting it’s libraries so using the NSObjects was not that difficult between Google and a quick reference search along with the example screensaver code.  I’m going to hit a few key differences and then post the entire file I edited.  XCode does the templating pretty well.

First, all the variables are at the top of the code so they don’t change as the program advances frames.

// VARIABLES
float mat[4][7] = {
//...

@implementation ZackScreenSaverView

Secondly, I had to use implement my NSObjects at the start of the -(void)animateOneFrame method.  The size = [self bounds].size; calls the screensize.  It’ll take some time to get used to the method calls in Objective-C!

- (void)animateOneFrame
{
	NSRect dot;
	NSSize size;
	NSColor *color;
	NSBezierPath *path;
	float red,green,blue,alpha;

	size = [self bounds].size;

The framework has some good methods for getting random floats, or any integer type!

	// random number
	p = SSRandomFloatBetween(0.0,1.0);

Finally, it took some new methods to draw my dots to the screen.

	// set dot
	dot = NSMakeRect(jx,jy,1.0,1.0);

	// make dot
	path = [NSBezierPath bezierPathWithRect:dot];

	// draw dot
	[path stroke];

Other than that, the rest is pretty much the same.  I encourage those more used to Objective-C and programming for Mac products to comment about the use of this code and correct any bad assumptions!  Here is the code in it’s entirety (note that I’ve taken out the redraw at this time)…

//
//  ZackScreenSaverView.m
//  ZackScreenSaver
//
//  Created by Zachary D. Skelton on 5/30/10.
//  Copyright (c) 2010, Skelton Networks. All rights reserved.
//

#import "ZackScreenSaverView.h"

// VARIABLES
float mat[4][7] = {
	{0.0,0.0,0.0,0.16,0.0,0.0,0.01},
	{0.85,0.04,-0.04,0.85,0.0,1.6,0.85},
	{0.2,-0.25,0.23,0.22,0.0,1.6,0.07},
	{-0.15,0.28,0.26,0.24,0.0,0.44,0.07}
};
// constant sets
float xa = -5.5;
float xb = 6.5;
float ya = -0.5;
float yb = 10.5;
// x and y to be altered
float x = 0.0;
float y = 0.0;
// screen/image size
int ix = 512;
int iy = 512;
// floats for math fulction
float p = 0.0;
float x0 = 0;
float jx = 0;
float jy = 0;
// variables to control function
int i = 0;
int k = 1;
int end = 10000;

@implementation ZackScreenSaverView

- (id)initWithFrame:(NSRect)frame isPreview:(BOOL)isPreview
{
    self = [super initWithFrame:frame isPreview:isPreview];
    if (self) {
        [self setAnimationTimeInterval:1/30.0];
    }
    return self;
}

- (void)startAnimation
{
    [super startAnimation];
}

- (void)stopAnimation
{
    [super stopAnimation];
}

- (void)drawRect:(NSRect)rect
{
    [super drawRect:rect];
}

- (void)animateOneFrame
{
	NSRect dot;
	NSSize size;
	NSColor *color;
	NSBezierPath *path;
	float red,green,blue,alpha;

	size = [self bounds].size;

	ix = size.width;
	iy = size.height;
	dot = NSMakeRect(ix/2,iy/2,1.0,1.0);

	red = 255.0;
	green = 255.0;
	blue = 255.0;
	alpha = 255.0;
	color = [NSColor colorWithCalibratedRed: red
									  green: green
									   blue: blue
									  alpha: alpha];

	[color set];

	// random number
	p = SSRandomFloatBetween(0.0,1.0);

	// find random i
	if(p <= mat[0][6])
		i = 0;
	else if(p <= (mat[0][6] + mat[1][6]))
		i = 1;
	else if(p <= (mat[0][6] + mat[1][6] + mat[2][6]))
		i = 2;
	else
		i = 3;

	// super math function
	x0 = ((x*mat[i][0])+(y*mat[i][1])+mat[i][4]);
	y = (x*mat[i][2]+y*mat[i][3]+mat[i][5]);
	x = x0;
	jx = ((x-xa)/(xb-xa)*(ix-1));
	jy = (iy-1)-(y-ya)/(yb-ya)*iy-1;

	// set dot
	dot = NSMakeRect(jx,jy,1.0,1.0);

	// make dot
	path = [NSBezierPath bezierPathWithRect:dot];

	// draw dot
	[path stroke];

	// CLEANUP
	/*
	if(k == end) {
		k = 0;
		//sleep(5);
	} else
		k += 1;
	*/
	return;
}

- (BOOL)hasConfigureSheet
{
    return NO;
}

- (NSWindow*)configureSheet
{
    return nil;
}

@end

Microsoft Access : XFDL Viewer – Introduction

By , June 2, 2010 7:42 pm

I know, I said it yesterday that it is rare that I develop on Windows, but this is a long promised application.  In 2007, my unit administrator (in the U.S. Army Reserves) suggested code that would allow batch loading XFDL forms from MS Access.  Due to the scope of the Apps 4 The Army project, I was limited to using a web application.  Now that the project is submitted and done, I am free to do my original plan, which is code to do the same process in MS Access.

Starting this today, I realized how much I hate doing Visual Basic.  Particularly, VBA is very painful!!  It’s not that the language is bad but it just always feels bulky and pieced together to me.  It seems to lack the professionalism of C/C++ and the flow of Python.  But, I may be alone in that.

I have a question for my readers though. Would anyone have an interest in seeing this project on SourceForge?  The Apps 4 the Army project is no longer my intellectual right, but a desktop application, a MS Office Plugin, etc… that’s all good to make public.  So let me know, if I get readers saying we’d like to help; then I will happily move this project to SourceForge!

Fern Screensaver : Part 3

By , June 1, 2010 5:27 pm

Today, I had no Mac with me to work on my screensaver in Objective-C.  As you can see in my previous post, I used my python program and wrote it in C for SDL that works on either Windows or Linux.  Now, the basic principle is the same, I just need to output that location to the correct pixel plot method to use other systems.  I thought, since I was on Windows all day, I might as well use that to make the screensaver using Windows API.

I’ve had some use of Window’s API before to make a Breakout game for my children.  It is rustic at times but works.  I decided to not mess with OpenGL today and just use Win32 API and GDI methods.  Below you will find my complete source code and a link to download this screensaver.  Once downloaded, save it in C:\WINDOWS\System32\ and it will appear on your personalization menu.

A quick note before the code, for those unfamiliar with Windows API… there’s a lot of goobly gook here that looks scary.  It’s really not that bad but here’s the meat of the project:

  • Lines 8-34 are the same variables we’ve seen before.
  • Lines 36-40 are a ‘dot()’ method I made to clean the code (slightly).
  • After Line 42:
    • WM_CREATE is called on the start of the program.
    • WM_DESTROY is called on the completion of the program.
    • WM_PAINT is used to paint to the screen.
      • Here you see the same math as before until lines 78-82.
      • At Lines 78-82, I’m using Win32 API to create a color brush and paint it with the dot method.
    • WM_TIMER is called every millisecond in this program, it keeps the loop going.
      • InvalidateRect() will force a WM_PAINT message.
  • Everything that follows is not really applicable as it just meets the demands of the Screensaver library.

If you would like to try out this screen saver, download from this link and save the file to your C:/WINDOWS/system32/ folder.  Let me know how it works for you!

#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include <scrnsave.h>

#define TIMER 1

// VARIABLES
float mat[4][7] = {
    {0.0,0.0,0.0,0.16,0.0,0.0,0.01},
    {0.85,0.04,-0.04,0.85,0.0,1.6,0.85},
    {0.2,-0.25,0.23,0.22,0.0,1.6,0.07},
    {-0.15,0.28,0.26,0.24,0.0,0.44,0.07}
};
// constant sets
float xa = -5.5;
float xb = 6.5;
float ya = -0.5;
float yb = 10.5;
// x and y to be altered
float x = 0.0;
float y = 0.0;
// screen/image size
int imgx = 128;
int imgy = 128;
// floats for math fulction
float p = 0.0;
float x0 = 0;
float jx = 0;
float jy = 0;
// variables to control function
int i = 0;
int k = 1;
int end = imgx*imgy;
int done = 0;

void dot(HDC hdc, HBRUSH whtBr, int x, int y) {
        SelectObject(hdc, whtBr);
            Rectangle(hdc, x-2, y-2, x+1, y+1);
        DeleteObject(whtBr);
}

LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    static HDC hdc;
    //static HGLRC hrc;
    PAINTSTRUCT ps;
    HBRUSH whtBr;
    static RECT rect;
    switch(message) {
        case WM_CREATE:
            GetClientRect(hwnd,&rect);
            imgx = rect.right;
            imgy = rect.bottom;
            int ret = SetTimer(hwnd, TIMER, 1, NULL);
            if(ret == 0)
                MessageBox(hwnd, "Could not set Timer", "ERROR", MB_OK);
            break;
        case WM_DESTROY:
            KillTimer(hwnd,TIMER);
            PostQuitMessage(0);
            break;
        case WM_PAINT:
            k++;
            p = (float) rand()/RAND_MAX;
            if(p <= mat[0][6])
                i = 0;
            else if(p <= (mat[0][6]+mat[1][6]))
                i = 1;
            else if(p <= (mat[0][6]+mat[1][6]+mat[2][6]))
                i = 2;
            else
                i = 3;
            x0 = ((x*mat[i][0])+(y*mat[i][1])+mat[i][4]);
            y = (x*mat[i][2]+y*mat[i][3]+mat[i][5]);
            x = x0;
            jx = ((x-xa)/(xb-xa)*(imgx-1));
            jy = (imgy-1)-(y-ya)/(yb-ya)*imgy-1;
            // Paint it
            whtBr = CreateSolidBrush(RGB(255,255,255));
            hdc = BeginPaint(hwnd, &ps);
                dot(hdc, whtBr, (int)jx, (int)jy);
            EndPaint(hwnd, &ps);
            ReleaseDC(hwnd, hdc);
            if(k == end) {
                Sleep(5);
                done = 1;
            }
            break;
        case WM_TIMER:
            if(done == 0)
                InvalidateRect(hwnd, NULL, FALSE);
            else {
                InvalidateRect(hwnd, NULL, TRUE);
                k = 0;
                done = 0;
            }
            break;
        default:
            return DefScreenSaverProc(hwnd, message, wParam, lParam);
        }
    return 0;
}

BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
    //return FALSE;}
    switch(message) {
        case WM_INITDIALOG:
            //get configuration from the registry
            return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case IDOK:
                    //write configuration
                    EndDialog(hDlg, LOWORD(wParam) == IDOK);
                    return TRUE;
                case IDCANCEL:
                    EndDialog(hDlg, LOWORD(wParam) == IDOK);
                    return TRUE;
            }
    }
    return FALSE;
}

BOOL WINAPI RegisterDialogClasses(HANDLE hInst) {
    return TRUE;
}

Just a note, this is the rare time you will find me messing with Windows.

RSS RSS

Persephone Theme by Themocracy