Monday, May 14, 2012

CSS Cross browser support for 'display: inline-block'

I had one of those where-have-I-been moments today. I found a new favorite technique in HTML CSS design:
  display: inline-block;
I was briefly discouraged when I realized the code did not seem to work for IE. Then I found Isaac Schlueter's blog, Foo Hack and all is well in the world again.
  display:-moz-inline-stack;
  display:inline-block;
  zoom:1;
  *display:inline;
Even though it brings a whole bunch of new problems, every time I hit one of these incompatibility issues, I can't help wishing there were one browser to rule them all.

Saturday, February 25, 2012

The Adventure Begins

All logic would suggest our course of action is crazy and I submit to you that it does sound crazy. Let me describe to you what's on the other the line.
  • we feel that we should move to CA -- ok... where?! California is a big place
  • we feel that God has revealed to us that we need to move to Atwater, CA
  • I feel promptings indicating that a job will be provided
Let me pause to mention that I believe there is a God and that He cares about each of us, His children, even on an individual level. I believe these revelations come from our Heavenly Father. The fact that God has an interest in my life is more than enough to offset the concerns for why we shouldn't make this move.
  • we start getting our house ready to go on the market; we want to beat the onslaught of foreclosures coming in the spring of 2012.
  • we receive two offers on our WV house in spite of there being short sale homes in our neighborhood
  • we find a house in Atwater, CA that we are interested in buying
Ok; up to this point, perhaps these facts are not that significant. When our home first went on the market (31 Oct, Halloween night), we had a handful of competing homes, perhaps less than 10. By mid January, there were an additional 20, most of which were short-sales. Having the level of interest we had I see as being truly miraculous.
  • we put an offer on a house in Atwater, CA
  • someone put an offer on our house
At this point, the game starts getting interesting. In order to buy the house in California, we either need to be employed in California or buying a second home. Banks don't feel as confident with someone who is self-employed as they do with someone who has proof of consistent employment for many years, so I decide I need to remain employed with my current company at least while we are closing on the California house. While not impossible, it probably throws up red flags for the banks if someone's location of employment is on the opposite side of the country from their primary residence. This means that in order for the bank to give us the loan, we need to buy the California house as a second home.

So, in order for things to work out optimally, we must buy the California home while I am still employed with my current job and while we still own the home in WV. The first contract on the home fell through. That's fine anyway because the buyers expected us to bring $25K to the table and replace all flooring in the house. I realize it's a buyers market, but come on... what's the color of the sky in their little world?! Less than 1 week later we get another offer on our house. A down to earth family who needs us to settle at a price less than $25K than what we owe, but they are willing to take the house as/is. And it's clear to me they understand they great deal that they are getting right now.

* one
* two
* three

asdf

Location:Charles Town, WV

Monday, January 23, 2012

ENV before Ruby

When making environment variables available to a Ruby script, make sure the environment key/value pairs are declared before the call to run a Ruby script.

E.g.,

MY_ENV_VAR=test ruby show_my_env_var.rb

first things first

I probably goes without saying, but when you are starting out with a new project, it is best to get as much of the framework available to your customer up front. Stick with as much bland as possible (e.g., wire frame) so that it's obvious that colors, graphics, etc. are not the focus up front. What good is the fancy shine when there is little functionality.

I spent a good amount of time looking for a tool that I could use to create wire frames that could be easily published and couldn't find one that would generate actual RoR views that could be published. The best tool I found was only for Windows and I use a Mac. With wire frame views in place along with the ability to navigate from resource to resource, it would be very easy to prioritize the pages and add actual functionality/color/graphics to that particular resource.

Active Scaffold is very interesting and is an example of using convention to save time in creating forms based on model configuration. I realize it's asking quite a bit, but it would be nice to have a tool where controls could be drawn/resized/etc and then published to RoR views.

It might be something worth looking into.

Wednesday, January 18, 2012

the basics of textual progress bars

While running through some maintenance of some log directories, I learned a little bit about $stdout and textual progress indicators.

The app I work with logs like crazy. There are time-date-stamped log files all over, products of the much appreciated log roller we use. Obviously, log rolling helps eliminate the need to peruse through an 8+ gygabyte text file. That's good. The accumulation of so many log files, however, get's to be almost as annoying. Just like my commuter car, at some point you can't stand it anymore and it's time to do some house cleaning.

I'm a software developer, and a lazy software developer at that. If there is any reason to code something, I'll gravitate towards creating a script, even to generate lines I can run in my console to tar up log files. There are so many log files to be tarred that I found myself wanting to view the progress since it's no fun staring at a frozen screen.

I use tail -f often to watch log entries being made from the web application I'm working with.

tail -f log/development.log


I can also see what files in a directory were last touched.

ls -lat | head


Wouldn't it be nice to have a script that monitored the directory and let me see those tar archives grow? That much was pretty easy.

while(true)
puts `ls -lat log/archive | head`
sleep(1)
end


But it is ugly. You get entries that scroll you off the page. Then I start thinking about those textual progress bars. They seem to print some character that moves the cursor back to the beginning of the line so that the next print of characters over-writes the last. That would solve my problem with the scrolling.

Ok; again, I'm lazy. I did a little research, but admittedly, just enough to get the results I wanted. So here are some facts/theories:
  1. carriage returns (\r) are different from newlines (\n). When used together, the cursor shows up on the next line. If you only use a carriage return, the cursor returns to the beginning of the line it is currently on.
  2. 'puts' automatically adds a carriage return (cr) and newline (\r\n) to the outputted string. Ok; that's a step in the right direction.
  3. 'printf' may be used to print to the console without a cr or newline
  4. 'printf' automatically buffers, spitting content out to screen only when the script is finished. If we could only force a flush. Including a call to 'flush' doesn't seem to do the trick.
  5. $stdout and $stderr are built in handles to STDOUT and STDERR (go figure!). I'm not sure, but I think that 'printf' is a method associated with Kernel. I do know that calls to $stdout.printf("hello world") followed by $stdout.flush() does work.
We should have everything that is required now. Let's try this again.

while(true)
res = `ls -lat log/archive | head`
$stdout.printf("%s\r", res) #note: don't use a newline; only a carriage return
$stdout.flush() #or you won't see anything,... ever
sleep(1)
end


Ah, much better! Now, since I can't leave well enough alone, I will clean up my output, limiting the output only to the first actual file in the list.

#note: hit Ctrl-c to end the loop
while(true)
#note: there is no check for when no match was found
res = `ls -lat log/archive | head`.match(/^[^\r\n]+[\r\n]+([^\r\n]+)/)[1]

$stdout.printf("%s\r", res) #note: don't use a newline; only a carriage return
$stdout.flush() #note: flush or you won't see anything,... ever
sleep(1)
end


So to sum up, while there are several gems or plugins that offer the nice convenience of a textual progress bar, it all comes down to printing a line that ends in a carriage return (\r) only and flushing the STDOUT buffer.

Here are several references I discovered during the fun little journey I made into the world of progress bars:

http://www.ruby-forum.com/topic/175626
http://blog.dhavalparikh.co.in/2009/04/progress-bar-in-rails/
http://0xcc.net/ruby-progressbar/index.html.en
http://stackoverflow.com/questions/238073/how-to-add-a-progress-bar-to-a-bash-script
https://github.com/jfelchner/ruby-progressbar/blob/master/lib/progressbar.rb

# shortcut for doing sprintf
http://snippets.dzone.com/posts/show/5027

Thursday, June 3, 2010

integers, not bytes

Our first take at creating a multi-player, networked game will be done by starting with a sample chat client/server code base (included in Luke Escude's tutorial) and adding more functionality to it.

In the chat console, we have added a walled region where a user can move a character (using the arrow keys) around and see other characters who are in the chat room.

We designed the workflow for how this would be accomplished and then implemented the code. After walking through the code at least 5 times, we ran it and it worked... sort of. I was using writebyte() for sending the tcp id and the x,y coordinates for the characters and the x,y max values well exceeded the value 256, which is the maximum numeric value that can be represented with a byte. That accounted for the strange behavior we were seeing -- the user could see their own character bounded in the walls, but the other characters were outside and to the left. Furthermore, the other characters would suddenly jump to the left side of the screen when their owners moved too far to the right.

I couldn't find logging functions in GameMaker (well, there is an error logging method, but I wasn't logging errors), so I created my own using GM's file and time methods. I used the resulting log file to help me better see what was going on. Along with helping me locate my 'byte' issue, I also realized some extra looping that I want to get rid of.

The solution in fixing the 'byte' issue was to change those particular writebyte()/readbyte() calls to writeint()/readint(). Since my game board is no bigger than 640 x 480, integers are all that I will need.

While debugging the code, I found myself wishing there were better debugging tools. Perhaps I don't yet know how to take better advantage of the debug mode in GM; I found my code walk-throughs and the new logging capability to be more useful so far. I also like putting my source code under source control, but since the scripts are all inside a GM file, I don't get the full advantage I would like. It would be nice if there was a way to export all scripts, no matter where they showed up, and to likewise import all scripts from a directory of files. That way I could easily see where changes were last made. Perhaps there is a GM function that can be used to do this and I simply don't know about it yet.

Thursday, May 27, 2010

multi-player games with my son

My son and I have been educating ourselves on making multi-player games using GameMaker 8. It's a wonderful platform for novices to get their feet wet in the field of video game creation. It's also been a great way to introduce my son to computer programming. I mean, what young boy doesn't get a thrill at the idea of creating their own video games?!

A free version of GameMaker is available from the folks at YoYo.com. Advanced features become available once you register for a small fee. There are tons of people in the wiki, forums, and game submissions, which means tons of support.

If you wish to play some of the submitted games, YoYo has made it very easy using a web browser plugin. For those of us Firefox 3.6.3 users, however, the process of installing that plugin is somewhat more involved, but not difficult at all. This is a great way to get some ideas for your own games.

Getting started with creating multi-player games does require a registered copy of GameMaker. Next, it really helps to have a decent tutorial, especially if you are new to the GameMaker language (GML). A library is used to supply the needed functionality for programming multi-player games, specifically the socket handling. There are still tutorials floating around that use an other library called (I think) mplay. This one is old and tends to be flaky, especially where firewalls are concerned. The preferred library of choice is called '39dll'.

A great tutorial for using 39dll has been put out by Luke Escude. Many thanks, Luke! The code is clean, documented and he does a great job explaining the various parameters and providing diagrams to give a big picture view on the matter.

I was able to have success, modifying the example code to have the client send a message to the server and then from the server to the client. Then I modified the sample chat client and server applications so that one could input the ip address of the server and the port number. I ran these on my LAN between my Windows laptop and my iMac with VMFusion (Windows) with great success.

My next step is to have my son connect up with me from outside our LAN. I configured my router to do this, opening up a port for the purpose and forwarding requests on it to my iMac. To make sure that this was done correctly, I tested the newly opened port through CanYouSeeMe.org. Again, success. Once we have tested successfully across the Internet, then it will be time to actually put a real game together. My son has already created several games; we'll see how difficult it would be to retrofit one of those games in a multi-player environment.