<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Ben's Log</title><link>http://www.bensnider.com</link><description></description><atom:link href="http://www.bensnider.com/feeds/all.rss.xml" rel="self"></atom:link><lastBuildDate>Mon, 06 Feb 2012 22:31:00 -0500</lastBuildDate><item><title>PiSeg Arduino Project</title><link>http://www.bensnider.com/piseg-arduino-project.html</link><description>&lt;p&gt;&lt;a class="reference external" href="https://github.com/stupergenius/Arduino-Sandbox/tree/master/PiSeg"&gt;View the sketch&lt;/a&gt; for this project itself, along with the Fritzing file, in my GitHub repository.&lt;/p&gt;
&lt;p&gt;This simple sketch displays the first 8 thousand or so digits of PI on a &lt;a class="reference external" href="http://www.radioshack.com/product/index.jsp?productId=2062557"&gt;7 segment LED&lt;/a&gt; from Radioshack.
The LED display is done nicely with a byte encoded segment value, where each bit turns a segment on or off.
Below is a &lt;a class="reference external" href="http://en.wikipedia.org/wiki/File:7_segment_display_labeled.svg"&gt;labeled diagram&lt;/a&gt; of the segments themselves:&lt;/p&gt;
&lt;img alt="http://upload.wikimedia.org/wikipedia/commons/thumb/0/02/7_segment_display_labeled.svg/150px-7_segment_display_labeled.svg.png" src="http://upload.wikimedia.org/wikipedia/commons/thumb/0/02/7_segment_display_labeled.svg/150px-7_segment_display_labeled.svg.png" /&gt;
&lt;p&gt;Using the above diagram it is easy to see how we derive the values. The following illustrates computing the
value for the digit 6:&lt;/p&gt;
&lt;p&gt;A: 0
B: 0
C: 1
D: 1
E: 1
F: 1
G: 1&lt;/p&gt;
&lt;p&gt;Compounding the above in order from segment A through G we get 0011111, which in base 10 we can write as 95.
A simple way to do this conversion is using the Python interpreter to convert a string representation of the binary value to a base 10 integer using &lt;em&gt;int('0011111', 2)&lt;/em&gt; and noting the return value is 95.&lt;/p&gt;
&lt;p&gt;In the sketch, I create an array of bytes to hold the values for the digits 0-9, so looking up a digit is as
easy as looking up the value at the digit's index into the array. So for digit 3 we would look up index 3.
We can then use the handy &lt;em&gt;readByte&lt;/em&gt;
function to read a byte at a time, and turn the segment of the LED on or off depending on the bit value. Strangely,
Arduino appears to reverse the order of the bits as you read them from the byte. So our above digit 6 would be
read in order 1111100. To fix this, instead of reversing the byte and then reading bits from it, I reverse the
order in which I apply the bit values to the segments, starting at the end and working backward to the beginning.&lt;/p&gt;
&lt;p&gt;The digits of PI are stored in an included header file that defines the actual values into read-only PROGMEM. The sketch
then reads the current digit of PI out of the PROGMEM array. I think using PROGMEM for this is a nice example of
the kinds of data one would store into read-only memory.&lt;/p&gt;
&lt;p&gt;Below is a Fritzing diagram of the prototype (might have obsessed a little on this one):&lt;/p&gt;
&lt;img alt="http://media.bensnider.com/images/sketches/PiSeg.jpg" src="http://media.bensnider.com/images/sketches/PiSeg.jpg" /&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 06 Feb 2012 22:31:00 -0500</pubDate><category>arduino</category><category>hardware</category><category>technology</category></item><item><title>Code Camp Columbus 2011</title><link>http://www.bensnider.com/code-camp-columbus-2011.html</link><description>&lt;p&gt;Last weekend I had the opportunity to attend &lt;a class="reference external" href="http://columbuscodecamp.com/"&gt;Code Camp Columbus&lt;/a&gt; for the first time. This is the second year that the event has been held, and it was pretty great this year. As a busy, working developer, I greatly appreciate their core principles:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;by and for the developer community&lt;/li&gt;
&lt;li&gt;always free&lt;/li&gt;
&lt;li&gt;community-developed material&lt;/li&gt;
&lt;li&gt;no fluff - only code&lt;/li&gt;
&lt;li&gt;never occurs during working hours&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The venue was &lt;a class="reference external" href="http://www.techcolumbus.org/"&gt;Tech Columbus&lt;/a&gt;, which is quite a nice place. The main presentation room was large with a very large screen. There were two additional rooms, one of which was probably a little too small for the group, but it made the talks more interactive in that space. Breakfast, drinks, snacks, and lunch were all generously provided by the event &lt;a class="reference external" href="http://columbuscodecamp.com/?s=sponsors"&gt;sponsors&lt;/a&gt;, as were the many many raffle prizes. I went away with a neat &lt;a class="reference external" href="http://www.apress.com/9781430219897"&gt;Beginning Scala&lt;/a&gt; book (which I'm currently working through) and a $25 Best Buy gift card. All in all, quite worth the cost of attendance, which was &lt;strong&gt;free&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Overall the talks were great, and I highly recommend going to this conference the next time it is presented. I greatly enjoyed the &lt;em&gt;Perl&lt;/em&gt;, &lt;em&gt;Behavior Driven Development&lt;/em&gt;, and the &lt;em&gt;Verilog&lt;/em&gt; talks. I'll outline a few of the talks below.&lt;/p&gt;
&lt;div class="section" id="html5-apps-with-phonegap"&gt;
&lt;h2&gt;HTML5 Apps with PhoneGap&lt;/h2&gt;
&lt;p&gt;The first talk that I attended, and the talk that was likely most persuaded my attendance, was a talk about &lt;a class="reference external" href="http://phonegap.com/"&gt;PhoneGap&lt;/a&gt; and HTML5. In the near future I hope to develop several HTML5 mobile apps and will probably use PhoneGap to wrap them for deployment on the various app stores. My particular problems revolve around video and complexity management, which weren't specifically addressed, but the talk was indeed generally useful.&lt;/p&gt;
&lt;p&gt;The main narrative here was an app that the presenter had made in HTML5 and was planning on releasing it to the various mobile app stores, as well as to the chrome app store. The app was a simple two screen deal that queried the &lt;a class="reference external" href="http://www.heavens-above.com/?lat=0&amp;amp;lng=0&amp;amp;loc=Unspecified&amp;amp;alt=0&amp;amp;tz=CET"&gt;Heavens Above&lt;/a&gt; ISS orbit data, asked the user where he/she is (or uses GPS data when available) and presents the user with the times and locations of the next few ISS viewings. Admittedly a rather simple app, but a good showcase of the integration between HTML5, web services, and PhoneGap.&lt;/p&gt;
&lt;p&gt;This particular talk was hosted in the smallest of the three venues, and it was quite a tight fit for all the people that wanted to attend talks in this room. Otherwise the venue was nice. No real technical difficulties or anything.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="unlock-the-power-of-arduino-with-libraries"&gt;
&lt;h2&gt;Unlock the Power of Arduino with Libraries&lt;/h2&gt;
&lt;p&gt;This talk was a more specific Arduino talk than the others I have previously attended at other conferences. It assumed at least a basic understanding of Arduino, which I thought was quite helpful. Most people interested in Arduino already know a significant amount about the platform, but just don't have the time to devote to actually doing anything with it. This talk introduced more advanced topics that I hadn't previously known. An interesting quote from the presentation speaks to the paradigm shift when switching from primarily software development to a more hardware integrated approach with Arduino:
&lt;em&gt;Ardiuno interacts more directly with the world, as opposed to mediated through a user or another library.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The main topic of this particular talk is about how to use libraries in Arduino. Libraries in Arduino are more or less identical to libraries in other contexts, and the use is the same as well. Simply #including a header file adds callable code to the current program. The header files expose some public members or methods, and the including program can use them as usual. As a sort of throwback to the days when one had to be conscious of memory, including library code can easily overflow the amount of program memory available on the Arduino. Other than that, libraries are just header files that you can use to easily add additional functionally to your Arduino programs. The community is apparently fairly active, and many libraries are available for common add-on hardware, as well as libraries for controlling servos and enabling communication, and the like.&lt;/p&gt;
&lt;p&gt;The talk ended with a demonstration of some cool Arduino hardware. The speaker had quite a cool collection of Arduino shields, displays, servos, a digital analog clock, a TV out shield, and other stuff. I was particularly interested in the &lt;a class="reference external" href="http://www.sparkfun.com/products/10570"&gt;Danger Shield&lt;/a&gt; which is a shield that just gets stuck onto the top of the Arduino board (a &amp;quot;shield&amp;quot;) and adds a bunch of additional hardware like a temperature sensor, a bunch of LEDs, a speaker, three potentiometer sliders, and some other cool tech.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="perl-laziness-impatience-hubris-and-one-liners"&gt;
&lt;h2&gt;Perl - laziness, impatience, hubris, and one liners&lt;/h2&gt;
&lt;p&gt;I've always been a fan of Perl because of its expressive syntax, but it's just not terribly practical anymore. This talk centered around some of the new cool features in the latest versions of Perl, as well as introducing some of the syntax standardization that has been formalized in the past few years. This lets Perl developers adhere to a standard set of best practices and a single coding standard, so that the programs are more readable and more maintainable.&lt;/p&gt;
&lt;p&gt;To this end, the speaker showed an example of some of the core regex library code, and the file's header literally said &amp;quot;VOODOO MAGIC, LINE NOISE FOLLOWS.&amp;quot; It was the sort of Perl that one thinks of when one thinks of overly complicated Perl code. The speaker then showed how to use some new tools available through CPAN that mostly de-obfuscated the line noise into a quite readable program.&lt;/p&gt;
&lt;p&gt;The speaker also went through the use of the &lt;a class="reference external" href="http://search.cpan.org/dist/WWW-Mechanize/"&gt;Mechanize&lt;/a&gt; framework, that has been quite improved since the last time I used it. The framework makes it easy to login to website, carry over the login cookies, and generally request and scrape content from websites in a concise manner. The speaker is using the Mechanize library to automate the transfer of projects from the closing &lt;a class="reference external" href="http://www.berlios.de/"&gt;BerliOS&lt;/a&gt; repository and import them into GitHub.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="intro-to-verilog-for-c-programmers"&gt;
&lt;h2&gt;Intro to Verilog for C programmers&lt;/h2&gt;
&lt;p&gt;I went into this talk without even a little bit of understanding about &lt;a class="reference external" href="http://en.wikipedia.org/wiki/Verilog"&gt;Verilog&lt;/a&gt; but went away with a desire to learn more. Coincidentally the next local Python meetup I went to was about &lt;a class="reference external" href="http://en.wikipedia.org/wiki/VHDL"&gt;VHDL&lt;/a&gt;, a competitor to Verilog. The talk was a basic overview of Verilog, and I probably knew about as much about Verilog as everyone else in the room (e.g. nothing) and the talk was still fairly well above all our heads lol. It's good to experience things outside of our expertise, however, and I appreciated the challenge in understanding Verilog, which is very difference from most procedural languages that compile into code that runs on micro-controllers.&lt;/p&gt;
&lt;p&gt;In a nutshell, Verilog is a hardware description language that, when compiled, can be loaded onto an &lt;a class="reference external" href="http://en.wikipedia.org/wiki/Field-programmable_gate_array"&gt;FPGA&lt;/a&gt; and run. This is a major difference from compiling code that runs on a normal CPU. For one thing, most operations in a Verilog program can happen at the same time, in parallel. This entails that a line at the top of the program can run &lt;em&gt;after&lt;/em&gt; a line at the end of the program. This all depends on the ending structure of gates that get programmed into the FPGA, but the designer must still be aware of such thins. Another difference is the fact that all operations are essentially a set of logic operations that runs through gates on a positive or negative clock edge. This means most of the operations a Verilog program describes are things like XORing or NORing two integers, for example. A major shift from traditional programming languages.&lt;/p&gt;
&lt;p&gt;The speaker is apparently using a Verilog designed FPGA to detect gamma ray bursts from an x-ray machine used in a health care environment. This is for his day job at Batelle, in Columbus. Apparently, using a micro-controller wouldn't work for this particular problem because the gamma ray bursts are on the order of a single nano-second, and even the fastest micro-controllers aren't fast enough to process all the incoming data. So his team turned to an FPGA that can, in parallel, process the input, perform a FFT on it, and dump it out over a serial interface to a PC based program. Overall, very cool stuff.&lt;/p&gt;
&lt;p&gt;Verilog is something I would like to learn more about, because it does indeed seem fascinating, and I greatly appreciated this talk because it helped open my eyes to yet another subset of computer science and engineering.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="in-summary"&gt;
&lt;h2&gt;In Summary&lt;/h2&gt;
&lt;p&gt;Code Camp Columbus was a huge success this year, in my opinion, and I look forward to the next year of new and cool presentations. Perhaps next year I'll get my act together and present something. I fancy myself quite an experienced iOS developer, and perhaps I will have more to share with my experience of HTML5 and PhoneGap. Winning some goodies in the raffle was icing on the cake, and I enjoyed the venue and the presentations very much.&lt;/p&gt;
&lt;/div&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sat, 29 Oct 2011 16:14:00 -0400</pubDate><category>code</category><category>Open Source</category></item><item><title>COhPUG Monthly Meetup and FreeGeek</title><link>http://www.bensnider.com/cohpug-monthly-meetup-and-freegeek.html</link><description>&lt;p&gt;This week I think I've met my geek quota a little early, so hopefully I can just
cruise the rest of the week. I'm always pleasantly surprised by the amount of
geekery that goes on in Columbus on a random week.&lt;/p&gt;
&lt;p&gt;Tuesday was the monthly meetup for the &lt;a class="reference external" href="http://www.meetup.com/Central-Ohio-Python-Users-Group"&gt;Central Ohio Python User Group&lt;/a&gt; (COhPUG
I think...). The main topic this week was &lt;a class="reference external" href="http://geekswithblogs.net/gregorymalcolm/Default.aspx"&gt;Greg Malcom&lt;/a&gt;'s talk on
&lt;a class="reference external" href="https://gist.github.com/1241642"&gt;Unix streaming, piping, and forking&lt;/a&gt;, and how we can write very Unix looking
Python scripts using the same concepts. This talk was apparently originally
given at a Ruby conference, but thankfully, all but one Ruby reference was
converted to Python.&lt;/p&gt;
&lt;p&gt;The bit on forks, for me, was a bit of a refresher course, having taken a Unix
class in college. Thankfully, I had forgotten everything so I was able to learn
it all over again. With forks I feel like there's always an &amp;quot;Aha!&amp;quot; moment where
the concept just sort of clicks into place in your brain, but until then you're
all &amp;quot;what the crap is this?&amp;quot; So, that was a good talk. I was reminded how odd
Python's Popen classes are with respect to piping. I think I usually avoided
using those in favor of the &lt;a class="reference external" href="http://docs.python.org/library/commands.html"&gt;commands&lt;/a&gt; module, but apparently that's deprecated
these days.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://pyohio.org/speaker/profile/7/"&gt;Eric Floehr&lt;/a&gt; gave a talk on using &lt;a class="reference external" href="http://pygame.org/news.html"&gt;PyGame&lt;/a&gt; to compete in the semi-annual
&lt;a class="reference external" href="http://www.pyweek.org/"&gt;PyWeek&lt;/a&gt; game development contest (in which he attempted to participate). PyGame,
as far as I can tell, is a simple Python layer over OpenGL with some sound, font
image, and sprite support baked into a Python module. Writing a PyGame...game
involves the developer implementing a main runloop, much like other frameworks,
and apparenly includes a sort of hybrid event queue mechanism that looks
pretty handy. I don't know how well any physics libraries and such plug into
PyGame, but judging from the sophistication of the entries, it doesn't look too
amazing. There seems to be some activity on a &lt;a class="reference external" href="http://code.google.com/p/box2d/"&gt;Box2D&lt;/a&gt; &lt;a class="reference external" href="http://pybox2d.blogspot.com/"&gt;Python port&lt;/a&gt; that looks
like it's heading in the right direction.&lt;/p&gt;
&lt;p&gt;The remainder of the meetup was spent listening to a fellow who created a nifty
video visualization of all the &lt;a class="reference external" href="http://www.columbusunderground.com/"&gt;Columbus Underground&lt;/a&gt; forum posts. He apparently
used &lt;a class="reference external" href="http://aws.amazon.com/ec2/"&gt;Amazon EC2&lt;/a&gt; to setup a render farm of 60 instances that rendered frames
independently. This sped up the render from all night on his laptop to 10
seconds in &lt;em&gt;the cloud&lt;/em&gt;. When the job was finished it allegedly cost about $8.
Quite impressive.&lt;/p&gt;
&lt;p&gt;I also spent this evening at &lt;a class="reference external" href="http://freegeekcolumbus.org/"&gt;FreeGeek&lt;/a&gt;. This week I attempted to build a
computer, but the gods would not have it. I kept getting a random freeze.
Normally I would chalk this up to memory but we test all the memory we get at
FreeGeek so I assume it would either have to be a bad CPU or a PSU with damaged
voltage regulators (but the voltage seemed to be fine in the BIOS). So I was
stumped. Initially I found that the sound card was faulty and I replaced that,
but that didn't stop the freezes. I also replaced the video card to be safe, no
dice. So I gave up and just tagged it with my findings. The next thing I did was
mostly a success, in that I was able to get through all quality control checks
for a computer that was waiting to be tested. I ran out of time before I could
test the disc drive, but a success I will take!&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 27 Sep 2011 22:07:00 -0400</pubDate><category>linux</category><category>volunteering</category><category>hardware</category><category>python</category></item><item><title>FreeGeek Columbus Volunteering</title><link>http://www.bensnider.com/freegeek-columbus-volunteering.html</link><description>&lt;p&gt;I volunteered today for the first time at &lt;a class="reference external" href="http://freegeekcolumbus.org/"&gt;FreeGeek Columbus&lt;/a&gt;. I got a tour
from the staff, which included a runaround of all the stacks of hardware that
they have in stock. I don't think I've ever seen so many video cards, memory
sticks, hard drives, and various parts in a single place before. My mind was a
little blown at the sheer volume.&lt;/p&gt;
&lt;p&gt;They then explained the process that hardware goes through when it comes in the
door. First we basically tear everything out of the computer and test its
components separately. Then, once the parts have passed some basic tests, they
get put in bins based on what type of component they are. If a part doesn't pass
the hardware tests, it gets tore down a little more and dumped into its own
recycling bin.&lt;/p&gt;
&lt;p&gt;Tonight I was able to work on testing hard drives and memory. Basically the
process here involves using a set of 8 computers that are setup with a &lt;a class="reference external" href="http://en.wikipedia.org/wiki/Preboot_Execution_Environment"&gt;PXE boot&lt;/a&gt;
loader that loads either &lt;a class="reference external" href="http://www.memtest.org/"&gt;memtest&lt;/a&gt; for testing memory, or a disk recovery image
that checks for bad blocks and then does a &lt;a class="reference external" href="http://www.dban.org/"&gt;dban&lt;/a&gt; style wipe on the contents. Once
memory passes I just label it and bin it. Once a hard drive passes and is wiped,
I move it over to the imaging machines where a copy of Ubuntu is cloned onto it,
and I bin it so it can be built into a computer.&lt;/p&gt;
&lt;p&gt;Overall, the process was quite cool. I totally geeked out a little bit at the
sheer volume of tech and gadgetry just laying about. Mostly I just feel good
about putting my wasted youth spent in tinkering with computers to good use. If
you want to get started volutneering here, just walk in and the staff is more
than willing to give you a task (or several).&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 13 Sep 2011 21:46:00 -0400</pubDate><category>linux</category><category>volunteering</category><category>hardware</category></item><item><title>s3cmd, Pelican, and You</title><link>http://www.bensnider.com/s3cmd-pelican-and-you.html</link><description>&lt;p&gt;Turns out uploading this blog to &lt;a class="reference external" href="http://aws.amazon.com/s3/"&gt;Amazon S3&lt;/a&gt; using &lt;a class="reference external" href="http://s3tools.org/s3cmd"&gt;s3cmd&lt;/a&gt; is ridiculously
simple. All I have to do to sync the Pelican generated directory to my S3 bucket
is the follwing:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;s3cmd sync --acl-public --delete-removed output/ s3://www.bensnider.com/
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The &lt;a class="reference external" href="http://s3tools.org/s3cmd-sync"&gt;sync command&lt;/a&gt; basically works like rsync; it uses the hashing and diffing
features in S3 to upload only the contents that have changed. I also specify the
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;--acl-public&lt;/span&gt;&lt;/tt&gt; option to have the files uploaded be HTTP readable by everyone.&lt;/p&gt;
&lt;p&gt;If you don't feel like jumping in with both feet yet, you can use the
rsync-alike &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;--dry-run&lt;/span&gt;&lt;/tt&gt; option until you are satisfied with the operations.&lt;/p&gt;
&lt;p&gt;Handy!&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 11 Sep 2011 21:55:00 -0400</pubDate><category>pelican</category><category>s3</category></item><item><title>Keynote Speech at OLF 2011</title><link>http://www.bensnider.com/keynote-speech-at-olf-2011.html</link><description>&lt;p&gt;This talk was given by &lt;a class="reference external" href="http://malmrose.wordpress.com/"&gt;Cathy Malmrose&lt;/a&gt; of &lt;a class="reference external" href="http://zareason.com/"&gt;ZaReason&lt;/a&gt; and mostly consisted of her
relating how awesome it is to have an operating system that &amp;quot;just works&amp;quot;, to
steal a phrase from the Steve. This enables her to focus on the hardware, making it as
robust, powerful, and cost effective as possible, without needing to focus too
much on the operating system.&lt;/p&gt;
&lt;p&gt;She related several support conversations she has had with her customers, and
how they either love how well Linux works on the desktop (I believe they use
&lt;a class="reference external" href="http://www.ubuntu.com/"&gt;Ubuntu&lt;/a&gt;) or how they need a computer that won't get viruses or won't come bloated
with software, and that won't waste their time. She lamented the fact that
developers often aren't in direct contact with the users of our products, and
that disconnect means we are never really directly appreciated. She, however,
has a dedicated client support line for her hardware business, so she gets to interact with
the client. She remarked how great it is that Linux has matured to the point that she is
getting calls like &amp;quot;how do I turn it on&amp;quot; rather than &amp;quot;my network card isn't
supported.&amp;quot;&lt;/p&gt;
&lt;p&gt;She also apparently is somewhat anti-corporation, which could be the proximity
of UC-Berkley rubbing off on her. She mentioned the documentary &lt;a class="reference external" href="http://www.thecorporation.com/"&gt;The
Corporation&lt;/a&gt;. However, I think she genuinely wants to provide an
excellent service to people, and the mindset of Linux fits very well within that
particular ideology.&lt;/p&gt;
&lt;p&gt;During the talk she tangentially mentioned technology in education, and how we are
moving from rigid computer instructional software to more real-world types of
problem solving, navigational, and practical learning software. She gave the
example of &lt;a class="reference external" href="http://www.minecraft.net/"&gt;Minecraft&lt;/a&gt; and how her son learned to navigate Paris from playing a
racing game. I don't really see how this relates to Linux, but whatever, it was interesting.&lt;/p&gt;
&lt;p&gt;Overall it was a very broad talk encompassing several topics, but it was a
keynote, and it was a good overview of all the ways Linux is used, and how much
the developer community is appreciated. So, a good opener for the day.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 11 Sep 2011 21:23:00 -0400</pubDate><category>OLF2011</category><category>Linux</category><category>Open Source</category></item><item><title>Ohio LinuxFest 2011 Series</title><link>http://www.bensnider.com/ohio-linuxfest-2011-series.html</link><description>&lt;p&gt;In this series of posts I will be review my experience at the &lt;a class="reference external" href="https://ohiolinux.org/"&gt;2011 Ohio
LinuxFest&lt;/a&gt;. I will be giving my opinions and what I learned at the talks.
Overall it was a very good day of talks, and I'm always impressed at how well
organized this &lt;strong&gt;free&lt;/strong&gt; convention is every year.&lt;/p&gt;
&lt;p&gt;I will update this post with links to specific articles, and they will all be
tagged with OLF2011.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 11 Sep 2011 21:01:00 -0400</pubDate><category>OLF2011</category><category>Linux</category><category>Open Source</category></item><item><title>Simple Pelican Blog Post Template Generator</title><link>http://www.bensnider.com/simple-pelican-blog-post-template-generator.html</link><description>&lt;p&gt;I just finished a simple script that helps generate &lt;a class="reference external" href="http://blog.notmyidea.org/pelican-a-simple-static-blog-generator-in-python.html"&gt;Pelican&lt;/a&gt; blog posts by
printing out some reStructuredText, in the format Pelican expects, based on the
given input parameters. You can use it simple as in the following listing:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;./tools/pelican-template-generator.py &lt;span class="s2"&gt;&amp;quot;My New Post&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And it will generate the reStructuredText header file that Pelican expects and
dump it to stdout, where you are free to copy+paste into your desired editor. It
includes options for writing to an output file, attempting to get the current
author's name from the environment, generating dates, and support for categories
and tags. The command I used to generate this post's template was:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;./pelican-template-generator.py &lt;span class="s2"&gt;&amp;quot;Simple Pelican Blog Post Template Generator&amp;quot;&lt;/span&gt; --category Development --tags &lt;span class="s2"&gt;&amp;quot;python, pelican&amp;quot;&lt;/span&gt; -f simple-pelican-blog-post-template-generator.rst
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a class="reference external" href="https://github.com/stupergenius/Bens-Log/blob/master/tools/pelican-template-generator.py"&gt;Get the script&lt;/a&gt; on my GitHub.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 11 Sep 2011 20:55:00 -0400</pubDate><category>python</category><category>pelican</category></item><item><title>It's Alive!</title><link>http://www.bensnider.com/its-alive.html</link><description>&lt;p&gt;&lt;em&gt;Finally&lt;/em&gt; got the new blog up and running. But I feel like I've learned
a lot about modern python development (github, pip, virtualenv, etc.),
which was the main impetus behind doing this conversion.&lt;/p&gt;
&lt;p&gt;This blog is now a static site that's generated using &lt;a class="reference external" href="http://blog.notmyidea.org/pelican-a-simple-static-blog-generator-in-python.html"&gt;Pelican&lt;/a&gt;, stored
on my &lt;a class="reference external" href="http://github.com/stupergenius"&gt;GitHub repository&lt;/a&gt; and served up through my Amazon S3 bucket that
I just point my domain at. Ideally I will automate this to the point
that a git commit will trigger a Pelican build and then a &lt;a class="reference external" href="http://s3.amazonaws.com/ServEdge_pub/s3sync/README.txt"&gt;s3cmd.rb&lt;/a&gt;
script that syncs up the generated files. Not sure if I want to make
that one or two steps though.&lt;/p&gt;
&lt;p&gt;But, expect more to come of this!&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 08 Sep 2011 02:08:00 -0400</pubDate><category>Python</category><category>Hosting</category><category>Linux</category></item><item><title>NSZombie to the Freaking Rescue</title><link>http://www.bensnider.com/nszombie-to-the-freaking-rescue.html</link><description>&lt;p&gt;So I've been beating my head against a wall the past few days trying to
cram as much Objective-C knowledge as possible and I think it's all
starting to click.&lt;/p&gt;
&lt;p&gt;Today I stumbled over the &lt;a class="reference external" href="http://howtomakeiphoneapps.com/2009/02/nszombie-and-xcode-oh-my/"&gt;NSZombieEnabled argument&lt;/a&gt; and HOLY CRAP WHY
ISN'T THIS DEFAULT BEHAVIOR. After enabling the argument I found where
my app crashed in about 1 minute. Turns out you &lt;strong&gt;should not&lt;/strong&gt; do:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
- (void)viewDidUnload {
    self.foo = nil;
    [super viewDidUnload];
}
&lt;/pre&gt;
&lt;p&gt;but rather&lt;/p&gt;
&lt;pre class="literal-block"&gt;
- (void)viewDidUnload {
    foo = nil;
    [super viewDidUnload];
}
&lt;/pre&gt;
&lt;p&gt;A fairly subtle difference I'll grant myself but, apparently, an
important one. In this particular case I am using the self.foo property
as a typed copy of the UIViewController's view property. In the wrong
case setting self.foo to nil releases the property where the framework
assumes it still exists, resulting in an app crash. Simply setting the
foo instance variable to null, however, works great.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Wed, 05 May 2010 11:21:00 -0400</pubDate><category>iOS</category><category>iPad</category><category>iPhone</category><category>Objective-C</category></item><item><title>Exile Issue 1 Released</title><link>http://www.bensnider.com/exile-issue-1-released.html</link><description>&lt;img alt="Exile Issue 1 Cover" src="http://media.bensnider.com/images/exile1_ss1.jpg" style="width: 600px;" /&gt;
&lt;p&gt;The game I've been working on at my &lt;a class="reference external" href="http://ournewgame.com/"&gt;day job&lt;/a&gt; has been released. The
&lt;a class="reference external" href="http://ournewgame.com/buy-exile/"&gt;first issue of Exile&lt;/a&gt; is available today, and if you order now for $8
you get the remaining 3 issues delivered digitally when they are
released.&lt;/p&gt;
&lt;p&gt;Exile is unlike most games and most graphic novels, in that it offers
first rate art and story with a compelling interface including
interactivity, a soundtrack, and sound effects. We've also put a lot of
effort into making the game as immersive as possible by providing
unlockable elements within the game that give players a look at concept
art, character sketches, and even minigames set in the Exile universe.
The end result is a unique experience and the game succeeds in blurring
the line between graphic novels and video games.&lt;/p&gt;
&lt;p&gt;I've been lucky to work with a great team of artists and writers on this
game, and I couldn't be happier with the way this has turned out.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 27 Apr 2010 22:22:00 -0400</pubDate><category>Comics</category><category>Exile</category><category>Exile Issue 1</category><category>Game Dev</category><category>Games</category><category>Actionscript</category><category>Flash</category><category>Flex</category></item><item><title>Don't Get Shot Released</title><link>http://www.bensnider.com/dont-get-shot-released.html</link><description>&lt;img alt="Don't Get Shot" src="http://media.bensnider.com/images/dgs_snap1.png" /&gt;
&lt;p&gt;The minigame I've been working on at my &lt;a class="reference external" href="http://ournewgame.com"&gt;day job&lt;/a&gt; has been released,
play &lt;a class="reference external" href="http://www.kongregate.com/games/OurNewGame/dont-get-shot-issue-1?referrer=OurNewGame"&gt;&amp;quot;Don't Get Shot&amp;quot;&lt;/a&gt; free at Kongregate. This minigame is released
in support of the release of the &lt;a class="reference external" href="http://ournewgame.com/buy-exile/"&gt;first issue of Exile&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The game is a reversal on the popular top down shmup genre, in that you
are the one getting shot at. It is your goal to not get shot, or
exploded, and progress through the levels. The level names I find
entertaining and they typically give you a hint as to what to expect in
the level.&lt;/p&gt;
&lt;p&gt;The game was made with the excellent &lt;a class="reference external" href="http://flixel.org/"&gt;Flixel&lt;/a&gt; and &lt;a class="reference external" href="http://box2dflash.sourceforge.net/"&gt;Box2D&lt;/a&gt; libraries.
It is a successful hybrid between the two, leveraging the Flixel
framework for its great sprite animation, state management, and quick
rendering, while using the accurate physics and collision features of
the Box2D project. The integration was actually a great deal simpler
than I thought it was going to be, which is like icing on the cake given
all the features now available. These features coupled with a simple
editor and an xml level format made it easy to turn out lots of great
levels, which you can look forward to in future issue releases.&lt;/p&gt;
&lt;p&gt;The game's artwork was done by &lt;a class="reference external" href="http://www.linkedin.com/pub/david-will/8/688/451"&gt;Dave Will&lt;/a&gt;, the original concept was
created by &lt;a class="reference external" href="http://www.linkedin.com/in/ranflash"&gt;Ran Flasterstein&lt;/a&gt;, and the levels were done by &lt;a class="reference external" href="http://www.jaytreuhaft.com/"&gt;Jay
Treuhaft&lt;/a&gt; and Fred Dinovo.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 27 Apr 2010 22:20:00 -0400</pubDate><category>Actionscript</category><category>Flash</category><category>Game Dev</category><category>Exile</category><category>Games</category></item><item><title>Lice Helper Launched</title><link>http://www.bensnider.com/lice-helper-launched.html</link><description>&lt;p&gt;Recently finished and launched a new website for a client. The website
advertises a lice removal service and provides means for potential
customers to learn about the service and get in touch with the business
quickly and easily. &lt;a class="reference external" href="http://www.licehelper.com/"&gt;Lice Helper&lt;/a&gt; The site is built on a CakePHP
application and actually uses Wordpress for the blog section of the
site. It doesn't use Wordpress for any of the front end, but in the back
end the standard Wordpress Dashboard is used to manage, edit, and write
blog posts that are then displayed in the front end blog section. The
site also utilizes my meta description and title components, that allow
the application to manage those parts of the page independently of the
page content. Basically it just ties a URL to a title or a description,
matches them up when pages are requested, and if it finds a matching
record it outputs it in the proper place. Otherwise it will output a
sensible default text. I did enjoy working with CakePHP again as it's
been some time. But all the things I liked about it still apply. It's
still lightening fast from prototype to finished site, and design
modifications couldn't be any simpler. All in all, good project, and I
think the end result looks and works very well.&lt;/p&gt;
&lt;a class="reference external image-reference" href="http://www.licehelper.com/"&gt;&lt;img alt="Lice Helper" src="http://media.bensnider.com/images/lice_helper.png" /&gt;&lt;/a&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 01 Mar 2010 21:23:00 -0500</pubDate><category>CakePHP</category><category>Portfolio</category></item><item><title>ImageMagick Split and Join a Sprite Sheet</title><link>http://www.bensnider.com/imagemagick-split-and-join-a-sprite-sheet.html</link><description>&lt;p&gt;Continuing the &lt;a class="reference external" href="http://wiki.github.com/AdamAtomic/flixel/"&gt;Flixel&lt;/a&gt; theme that seems to be brewing here, I found a
good way to transform images from full dimension art to sprite sheets.
This is useful when converting an image into a sheet compatible with the
Flixel tile and map system. In my case I am using it to split up
background images so I can use them in &lt;a class="reference external" href="http://www.tbam.com.ar/utility--flan.php"&gt;Flan&lt;/a&gt;, the Flixel map editor.
I'm just using the standard &lt;a class="reference external" href="http://www.imagemagick.org/script/index.php"&gt;ImageMagick&lt;/a&gt; tools &lt;em&gt;`convert`_&lt;/em&gt; and
&lt;em&gt;`montage`_&lt;/em&gt; to split and join the images, as well as some bash-fu to
sort files properly. I am using &lt;a class="reference external" href="http://www.cygwin.com/"&gt;Cygwin&lt;/a&gt; to get bash tools on my
Windows machine. The first command is used to split up the main image.
The only constraints here are that the resulting tiles must be square,
and that they don't exceed the width limit for Flash &lt;a class="reference external" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html"&gt;BitmapData&lt;/a&gt;
objects. So here we simply are cropping the image into square tiles.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
convert full.png -crop 32x32 tiles.png
&lt;/pre&gt;
&lt;p&gt;This will spit out a bunch of images in the current folder named
tiles-%d.png where %d is the 0 based index of the tile. This also
assumes that the width and height of the full.png image are divisible by
32 without remainder. The next command we need is to stitch the images
back together. For this we will use the handy &lt;em&gt;montage&lt;/em&gt; tool to tile the
images into one big sheet. We just pass it a sorted list of names and
tell it to make 1 row with as many columns as it needs (the x1
parameter). Sorting is not entirely necessary but using the default bash
globbed format will result in tiles that should be at the end of the
image randomly at the beginning (try it before this step by noting the
output of `ls tiles*.png`).&lt;/p&gt;
&lt;pre class="literal-block"&gt;
files=$(ls tiles*.png | sort -t '-' -n -k 2 | tr '\n' ' ')
montage $files -tile x1 -geometry 32x32+0+0 sheet.png
&lt;/pre&gt;
&lt;p&gt;If all went well we should see, inside the current directory, an image
with all of our separate tile sprites in a single row in order from the
original image from left to right and top to bottom. This technique is
also useful for converting &amp;quot;liberated&amp;quot; sprite sheets that have more than
one row, into single row sprite sheets that flixel can handle out of the
box.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 09 Feb 2010 18:03:00 -0500</pubDate><category>Game Dev</category><category>Linux</category><category>Shell Scripting</category></item><item><title>Flixel Pixel Perfect Collisions</title><link>http://www.bensnider.com/flixel-pixel-perfect-collisions.html</link><description>&lt;p&gt;I haven't found a decent source of information about this on the
interwebs so I thought I'd share my findings. Flixel doesn't have any
built in pixel perfect collision support, it just assumes that you are
using square (or at least rectangle) sprites and don't use any rotation.
Well, that's not entirely a real world assumption so some of us will
have to dig around and implement something ourselves. Hence, the below
class. The class I developed is a simple override of the base FlxSprite
class with some modifications to its collision detection system. It
takes advantage of the fact that each sprite has its own set of
BitmapData in its own coordinate space, which the framework uses to blit
to the main screen &lt;a class="reference external" href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html"&gt;BitmapData&lt;/a&gt;. BitmapData objects in Flash provide us
with a native implementation (in the Player AFAIK) of per pixel
collision detection, using the &lt;a class="reference external" href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/BitmapData.html#hitTest()"&gt;hitTest&lt;/a&gt; method. The hitTest method
takes 5 parameters, but we only really care about the first 4. The first
parameter we pass it defines where the calling BitmapData object is in
screen space, i.e. the sprite's (x,y) coordinates. We then pass it a
threshold alpha value, 0 being transparent and 255 being opaque. If you
want semi-transparent regions of your sprite to collide then set this to
something lower than 255 (0xFF is the hexadecimal representation of
decimal 255). The third parameter is the colliding sprite's BitmapData
object. And the fourth is the colliding sprite's (x,y) coordinates in
screen space. I have abstracted this into the class's structure, so the
overridden functions handle everything. You can use another alpha
threshold by setting the sprite's &lt;em&gt;alphaThreshold&lt;/em&gt; value to something
valid, as explained above. You can also disable this pixel perfect
collision detection method per technique by either setting
&lt;em&gt;doPerfectCollide&lt;/em&gt; or &lt;em&gt;doPerfectOverlap&lt;/em&gt; to false. Because there are two
methods Flixel uses to detect collisions, the class implements enhanced
versions of both, and allows you to disable either independently. Note
that, in order for the collision detection to be pixel perfect, either
a) both colliding objects must subclass PPlxSprite or b) the sprite
calling &lt;em&gt;overlaps&lt;/em&gt; or &lt;em&gt;collide&lt;/em&gt; must sublcass PPlxSprite and the
colliding sprite must have a single frame. This is due to fact that the
original FlxSprite class does not expose the &lt;em&gt;_framePixels&lt;/em&gt; BitmapData
object which is needed to collide the objects with the frame that is
currently displayed. When a FlxSprite is collided with a PPlxSprite and
the perfect collision is enabled, the exposed &lt;em&gt;_pixels&lt;/em&gt; BitmapData is
used, which contains the entire sprite sheet, so collisions are detected
against all frames, not just the frame displayed. However, changing
existing sprite's to use this class is easy enough so as not to cause
problems. Note also that we only call the hitTest method when we know
there is already a bounding box collision, so as not to waste CPU
cycles. The native hitTest method is fast but probably not fast enough
to call every frame, which would be wasteful in any case. Below is the
PPlxSprite class which override the collision methods to provide pixel
perfect collisions.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
import flash.display.BitmapData;
import flash.geom.Point;

import org.flixel.FlxCore;
import org.flixel.FlxSprite;

public class PPlxSprite extends FlxSprite {

    public var alphaThreshold:uint = 0xFF;
    public var doPerfectOverlap:Boolean = true;
    public var doPerfectCollide:Boolean = true;

    protected var _corePos:Point = new Point();
    protected var _thisPos:Point = new Point();

    public function PPlxSprite(X:int=0, Y:int=0, SimpleGraphic:Class=null) {
        super(X, Y, SimpleGraphic);
    }

    public function get framePixels():BitmapData { return this._framePixels; }

    override public function overlaps(Core:FlxCore):Boolean {
        var doesOverlap:Boolean = super.overlaps(Core);
        if (doesOverlap &amp;amp;&amp;amp; this.doPerfectOverlap &amp;amp;&amp;amp; Core is FlxSprite) {
            doesOverlap = this.perfectCollision(FlxSprite(Core));
        }
        return doesOverlap;
    }

    public function perfectCollision(Sprite:FlxSprite):Boolean {
        this._corePos = Sprite.getScreenXY(this._corePos);
        this._thisPos = this.getScreenXY(this._thisPos);

        var corePixels:BitmapData;
        if (Sprite is PPlxSprite) {
            corePixels = PPlxSprite(Sprite).framePixels;
        } else {
            // i guess other standard FlxSprites are boned if they are animted
            corePixels = Sprite.pixels;
        }

        return this._framePixels.hitTest(this._thisPos, this.alphaThreshold, corePixels, this._corePos);
    }

    override public function hitWall(Contact:FlxCore=null):Boolean { return this.hitSomething(Contact); }
    override public function hitFloor(Contact:FlxCore=null):Boolean { return this.hitSomething(Contact); }
    override public function hitCeiling(Contact:FlxCore=null):Boolean { return this.hitSomething(Contact); }

    public function hitSomething(Contact:FlxCore):Boolean {
        var didHit:Boolean = true;
        if (this.doPerfectCollide &amp;amp;&amp;amp; Contact is FlxSprite) {
            didHit = this.perfectCollision(FlxSprite(Contact));
        }

        return didHit;
    }
}
&lt;/pre&gt;
&lt;p&gt;Here I have overriden the core FlxSprite methods that are responsible
for collision detection, those methods being overlaps and the hit family
of methods. Overlaps gets called when you explicitly issue a
sprite.overlaps(otherSprite); This is a simple override that adds
functionality to the super overlaps method, namely, calling the pixel
perfect detection method and returning its results. The hit family of
methods are called after calling the collide family of methods,
including collideArray and the like. The collide methods, when they have
detecting a bounding box collision, call the hit family of methods,
depending on the location of the collision, which return a boolean. If
the called hit method implemented by the sprite returns false, the
collide method aborts and reports that it didn't collide after all. This
is the behavior on which the above hit methods rely, and return false
when it detects that while a bounding box collision may have occurred,
the pixels in either sprite have not collided. A short usage class
follows.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
public class SomeSprite extends PPlxSprite {

    // Embed sprite image.

    public function SomeSprite(X:Number, Y:Number):void {
        super(X, Y);
        // Load sprite image, and other sprite stuff
    }

    override public function hitWall(Contact:FlxCore):Boolean {
        if (super.hitWall(Contact)) {
            this.hurt(1);
            return true;
        }
        return false;
    }
}
&lt;/pre&gt;
&lt;p&gt;Here, all we do is simply extend the PPlxSprite class from above, and do
what we normally do for sprites. We also decide to do something special
when a character hits a wall, namely, get hut. To do this we override
the hitWall method, call the super hitWall (which would be the
PPlxSprite hitWall) method, and depending on its return value, we either
get hurt or do nothing. We don't need to do anything special for calling
the overlaps method, as this will simply call PPlxSprite overlaps
method. So, hopefully this is helpful for someone looking to do this, or
at least someone can find the ideas listed here useful. Let me know if
you used it and if you find any bugs, improvements, or have any other
suggestions.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 31 Jan 2010 23:13:00 -0500</pubDate><category>Actionscript</category><category>Flash</category><category>Flex</category><category>Game Dev</category></item><item><title>Flixel Puddles and Oil Slicks</title><link>http://www.bensnider.com/flixel-puddles-and-oil-slicks.html</link><description>&lt;p&gt;I've been using the super cool &lt;a class="reference external" href="http://wiki.github.com/AdamAtomic/flixel/"&gt;Flixel&lt;/a&gt; framework to make a game and
it's quite handy for most things. The game I'm working on is basically a
top down...ehh, well let's just say it's top down. :) I can post more
details when the game is actually released. As a category, top down and
platformer games in general usually have some type of movement
modification obstacles. These obstacles allow the player to pass through
them, so they don't stop the player from moving, but they somehow alter
the player's course by speeding up, slowing down, or sending the player
in a different direction. In my case, these obstacles are oil slicks and
water puddles, which speed up and slow down the player in whatever
direction they are traveling. Here I will cover how I solved speeding up
and slowing down the player when he crosses over such an obstacle. Below
is a skeleton of my main player class:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
 package sprites {
    import org.flixel.FlxG;
    import org.flixel.FlxSprite;

    public class Player extends FlxSprite {

        [Embed(source=&amp;quot;player.png&amp;quot;)] private var Img:Class;

        protected var _runSpeed:Number = 100;

        public var velocityFactor:Number = 1;

        public function Girl(X:int=0, Y:int=0) {
            super(Img, X, Y, true, false, 58, 58);

            drag.x = this._runSpeed * 8;
            drag.y = this._runSpeed * 8;

            maxVelocity.x = this._runSpeed;
            maxVelocity.y = this._runSpeed;

            ...
        }

        override public function update():void {
            // MOVEMENT
            acceleration.x = acceleration.y = 0;
            this.maxVelocity.x = this._runSpeed * this.velocityFactor;
            this.maxVelocity.y = this._runSpeed * this.velocityFactor;
            if (FlxG.keys.UP) {
                acceleration.y -= drag.y;
            }
            // And similarly for all 4 key directions
            ...

            super.update();
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;Using this player class, we can see that by modifying the velocityFactor
instance variable, we can effectively control how fast the player can
move around the screen. By setting velocityFactor equal to a value less
than one, we decrease the player speed, and by setting it equal to a
value greater than one we increase the player speed. So what we need now
is a way to modify this value externally in response to player
interaction with the world, namely, the player stepping onto a puddle or
an oil slick. We also need sprites that define how they should change
the player movement when they are stepped over. Below is a skeleton of
one of my obstacle classes:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
package sprites.obstacles {
    import org.flixel.FlxG;
    import org.flixel.FlxSprite;

    public class SpawnerObstacle extends FlxSprite {

        public function get playerVelocityFactor():Number { return 2; }

        [Embed(source=&amp;quot;spawner.png&amp;quot;)] private var SpawnerImg:Class;

        public function SpawnerObstacle(X:int=0, Y:int=0) {
            super(SpawnerImg, X, Y, true, false, 24, 24);

            this.fixed = true;
        }

    }
}
&lt;/pre&gt;
&lt;p&gt;Here is just a simple implementation of a FlxSprite class where we
define that this sprite, when stepped over, speeds up the player by a
factor of 2. Below are the relevant parts of the update() method in my
main PlayState class.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
this._player.velocityFactor = 1;
for each (sprite in this._obstacles) {
    if (this._player.overlaps(sprite)) {
        trace('modifying player velocity');
        this._player.velocityFactor = obstacle.playerVelocityFactor;
        break;
    }
}
&lt;/pre&gt;
&lt;p&gt;Here we loop over the obstacle sprites in the _obstacles array. This
array would be created whenever you initialize the obstacles for the
game. The obstacles themselves, in this case, are instances like the
above SpawnerObstacle class, which have a playerVelocityFactor getter
attached. In the beginning, we make sure that we set the player's
velocityFactor to 1 so that the player moves at the default speed in the
case that they are not on top of an obstacle sprite. We also break out
of the loop when we collide with a single obstacle sprite to avoid any
extra complexity. We could make it so that we average the velocity
factors when multiple obstacle sprites are encountered, but I don't have
this use case so it would be unnecessary. When all these parts are in
place and working in conjunction, we have a game that satisfies our
original goal. When the player collides with one of our obstacles
sprites, he is either sped up or slowed down, depending on the velocity
factor defined by the colliding sprite. If I get any less lazy (highly
unlikely) I'll post an example swf with source code.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 18 Jan 2010 17:46:00 -0500</pubDate><category>Actionscript</category><category>Flash</category><category>Flex</category></item><item><title>Computer Engineer Barbie</title><link>http://www.bensnider.com/computer-engineer-barbie.html</link><description>&lt;p&gt;A coworker writes me saying:&lt;/p&gt;
&lt;blockquote&gt;
Please take a moment to vote for Barbie to become a Computer
Engineer. Future generations of computer engineers would really
appreciate it if we could influence some girls to take up the
profession.&lt;/blockquote&gt;
&lt;p&gt;So indeed, I did vote, and so should you....or else! From the Barbie
site:&lt;/p&gt;
&lt;blockquote&gt;
Computer engineers have lots of different specialties. They can do
anything from building computers to making video games!&lt;/blockquote&gt;
&lt;img alt="Computer Engineer Barbie" src="http://media.bensnider.com/images/engie_barbie.jpg" /&gt;
&lt;p&gt;It's true folks. Why would any young girl not want a computer engineer
Barbie? It's fun for the whole family! I certainly wish my toys could
program an &lt;a class="reference external" href="http://en.wikipedia.org/wiki/Analog_synthesizer"&gt;analog synthesizer&lt;/a&gt;. &lt;a class="reference external" href="http://www.barbie.com/vote/"&gt;Vote!&lt;/a&gt;&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Wed, 13 Jan 2010 17:10:00 -0500</pubDate><category>Barbie</category><category>Funny</category></item><item><title>Flash Draw Transparent BitmapData</title><link>http://www.bensnider.com/flash-draw-transparent-bitmapdata.html</link><description>&lt;p&gt;Recently ran into an issue where I thought I should have been drawing a
transparent BitmapData object, but the resulting object had a white
background. The original incorrect code was the following:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
var bd:BitmapData = new BitmapData(w, h, true);
&lt;/pre&gt;
&lt;p&gt;The third boolean argument to the function is a transparency flag, and
here it is set to true. However, when creating a Bitmap object from this
BitmapData object and adding it to the display list, it clearly has a
white background instead of being transparent. To remedy this, the
solution is to pass along to the function a 32bit color value where the
alpha value is zero. The following code illustrates this solution:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
var bd:BitmapData = new BitmapData(w, h, true, 0x00000000);
&lt;/pre&gt;
&lt;p&gt;This will create a totally transparent BitmapData object on which you
can draw whatever you desire. In practice I use this to determine the
alpha values of a given pixel in a given display object. The following
function implements this technique:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
public static function getAlphaAt(d:DisplayObject, x:Number, y:Number):Number {
    // Even though we set transparent to true, we still need to use a transparent color.
    // This is easily done by setting alpha to 0; the RGB octects after that don't matter.
    var bd:BitmapData = new BitmapData(d.width, d.height, true, 0x00000000);
    bd.draw(d);
    return (bd.getPixel32(x, y) &amp;gt;&amp;gt; 24 &amp;amp; 0xFF)/255;
}
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 12 Jan 2010 11:17:00 -0500</pubDate><category>Actionscript</category><category>Flex</category><category>Bitmapdata</category><category>Flash</category><category>Transparent</category></item><item><title>Flex Scale Image to Max Dimension</title><link>http://www.bensnider.com/flex-scale-image-to-max-dimension.html</link><description>&lt;p&gt;Recently had a problem where I needed to display images as large as
possible within given bounds. So I made a handy little function that
computes the scaling needed so that the image, if it is larger than any
of the bounds, is scaled so that its largest dimension becomes equal to
the given maximum. This function scales the image proportionally so it
won't skew it.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
public function scaleImageToMaxDimension(img:Image, maxWidth:Number, maxHeight:Number):void {
    var scaleH:Number=1, scaleV:Number=1;
    if (img.content.height &amp;gt; maxHeight) {
        scaleV = maxHeight / img.content.height;
    }
    if (img.content.width &amp;gt; maxWidth) {
        scaleH = maxWidth / img.width;
    }
    img.scaleX = img.scaleY = Math.min(scaleH, scaleV);
}
&lt;/pre&gt;
&lt;p&gt;Flex doesn't do a terribly good job of resizing images, however, but it
works for images that just need to be tweaked to fit. If you have
control over your images and your display size, it is always best to
resize them as needed to save space/bandwidth and preserve quality. This
approach works best when you have little or no control over either. In
application this code would be used after the image has finished
loading. So for example I might do something like the following:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
import flash.events.Event;
import mx.controls.Image;

public class Test {
    public var image:Image;

    // pretend scale function is here

    public function Test {
        image = new Image();
        image.addEventListener(Event.COMPLETE, imageComplete, false, 0, true);
        image.load('http://www.google.com/intl/en_ALL/images/logo.gif')
    }

    private function imageComplete(event:Event):void {
        scaleImageToMaxDimension(image, 100, 100);
    }
}
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 11 Jan 2010 18:21:00 -0500</pubDate><category>As3</category><category>Flash</category><category>Flex</category><category>Image</category><category>Scaling</category></item><item><title>This Is Not a |</title><link>http://www.bensnider.com/this-is-not-a.html</link><description>&lt;img alt="This is not a |" src="http://media.bensnider.com/images/this_is_not_a_linux.png" /&gt;
&lt;p&gt;Saw this joke at this year's &lt;a class="reference external" href="http://www.ohiolinux.org"&gt;Ohio Linux Fest&lt;/a&gt;
during the closing talk, &lt;a class="reference external" href="http://www.ohiolinux.org/talks.html#SOPH"&gt;A Surfeit of Sophistication&lt;/a&gt; which was quite
a good talk.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 28 Sep 2009 14:09:00 -0400</pubDate><category>nerdy</category></item><item><title>Flash 10 Valid Vector Elements</title><link>http://www.bensnider.com/flash-10-valid-vector-elements.html</link><description>&lt;p&gt;Finally got around to learning about the new collection class available
in Flash 10. To be honest, I'm not terribly excited about many things in
Flash 10, hence my slowness to adapt. But, the vector class does
interest me somewhat. It promises faster iteration over a strongly typed
collection. Doesn't seem to add any other handy features however, like
Flex's robust ArrayCollection methods including removeItem. But alas. As
for it being faster, I have heard talk around the internets of the
vector class only being significantly faster with simple types, but I'm
way too lazy to any informal benchmarks of my own, so I'll just read
someone else's results. One specific question I had that I didn't see
answered anywhere, however, was the type of objects you could stick in a
vector once the template class had been set. It was my suspicion that
you could put any subclass of the template class in the vector, just
like C++ templated vetors, but I hadn't read it confirmed anywhere, so I
fired up my shiny new Flash CS4 and gave it a try. And indeed, my
suspicion was correct. The following simple code below validates my
hypothesis.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
var test:Vector.&amp;lt;Sprite&amp;gt; = new Vector.&amp;lt;Sprite&amp;gt;();
test.push(new Sprite(), new MovieClip());

// should output something like &amp;quot;[object Sprite],[object MovieClip]&amp;quot;
trace(test);
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Wed, 19 Aug 2009 20:29:00 -0400</pubDate><category>Flash</category><category>Flex</category></item><item><title>Copying a Flash MovieClip, or The Flash Holy Grail</title><link>http://www.bensnider.com/copying-a-flash-movieclip-or-the-flash-holy-grail.html</link><description>&lt;p&gt;Ran into a nice solution for copying arbitrary MovieClips at runtime
today. I am designing a spot the difference game akin to &lt;a class="reference external" href="http://www.kongregate.com/games/Ivory/6-differences"&gt;6
Differences&lt;/a&gt; with the requirement that, upon finding a difference, the
scene should go to the &amp;quot;correct&amp;quot; state depending on which difference was
defined as master, among a few other criterion. This required that I
somehow duplicate, as much as is possible, the state of the &amp;quot;master&amp;quot;
difference, when appropriate. At any rate, the solution comes from
&lt;a class="reference external" href="http://www.dannyburbol.com/2009/01/movieclip-clone-flash-as3/"&gt;Danny Burbol's blog&lt;/a&gt;, which apparently came from a &lt;a class="reference external" href="http://www.experts-exchange.com/Software/Photos_Graphics/Web_Graphics/Macromedia_Flash/Q_22684629.html"&gt;Experts Exchange
thread&lt;/a&gt; (damn people charging for information). I modified the solution
a bit to fit my needs, but not by a whole lot. Sometimes I only need to
copy the instance and I can reconstitute the MovieClip from there but
other times I will need to get the whole shebang. It's pretty handy in
general. So my version follows (as a bonus I include my handy-dandy
clearAllChildren function):&lt;/p&gt;
&lt;pre class="literal-block"&gt;
package com.bmm.utils {
  import flash.display.DisplayObject;
  import flash.display.DisplayObjectContainer;
  import flash.geom.Rectangle;

  /**
   * ...
   * &amp;#64;author BenS
   */
  public class UIUtils {

    public static function clearAllChildren(c:DisplayObjectContainer):void {
      if (c == null || c.numChildren == 0) return;

      var i:int = 0, n:int = c.numChildren;
      for (i = 0; i &amp;lt; n; i++) {
        c.removeChildAt(0);
      }
    }

    public static function simpleDisplayObjectClone(source:DisplayObject):DisplayObject {
      var cc:Class = Object(source).constructor;
      return new cc();
    }

    public static function displayObjectClone(source:DisplayObject):DisplayObject {
      var copy:DisplayObject = UIUtils.simpleDisplayObjectClone(source);

      copy.transform = source.transform;
      copy.filters = source.filters;
      copy.cacheAsBitmap = source.cacheAsBitmap;
      copy.opaqueBackground = source.opaqueBackground;
      if (source.scale9Grid) {
        var r:Rectangle = source.scale9Grid;
        copy.scale9Grid = r;
      }

      return copy;
    }
  }
}
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Fri, 15 May 2009 19:41:00 -0400</pubDate><category>Actionscript</category><category>C/C++</category><category>Flash</category><category>Flex</category></item><item><title>Flexunit Asyncrhonous Setups</title><link>http://www.bensnider.com/flexunit-asyncrhonous-setups.html</link><description>&lt;p&gt;If you ever need to load some external data before running a test, or
need to wait for a component's creation complete event, then you know
the inadequacies of the Flexunit framework when it comes to asynchronous
operations. One approach you might think of is to load the XML data, for
example, in the setUp() method and attach a handler to the loader to
wait for the complete event which would then call runMiddle() so the
actual test body runs. You would need to override the runMiddle() method
in your test case, and call super.runMiddle() in your complete handler.
However, while this will cause the tests to run properly after the data
has become available, Flexunit will not hang around long enough to catch
the passed/failed asserts in your test body. You will instead get a
runtime error box telling you which asserts failed, and a green bar from
the Flexunit UI. This is not desirable. What we need then is to somehow
write a test case that begins loading the data, and somehow specifies
which method to run that contains the actual asserts for the test
method. Essentially if you wanted to do really simply you would just
load the data with a Loader object, attach a complete handler to the
loader wrapped with the addAsync method of the TestCase to delay test
execution, and write the complete handler so that it accepts the
complete event and does what it will with the event.currentTarget. I
would rather have a general asynchronous setup method that takes as
parameters the URL of the data to load, the test handler with all the
asserts, and the class of the data that should be loaded. Instead of a
jumble of words explaining this it would probably help more to just
paste the code at this point.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
package {
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;

    import flexunit.framework.TestCase;

    public class AsyncSetupTestCase extends TestCase {

        public var data:*;
        public var returnType:Class;

        public function setupAsync(target:String, test:Function, returnType:Class):void {
            this.returnType = returnType;
            var helper:Function = this.addAsync(this.completeHandler, 1000, test);
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, helper);
            loader.load(new URLRequest(target));
        }

        private function completeHandler(event:Event, test:Function):void {
            trace('async load complete');
            this.data = event.currentTarget.data as this.returnType;
            test.call(this);
        }

    }
}
&lt;/pre&gt;
&lt;p&gt;As the previous code demonstrates, I have simply extended Flexunit's
TestCase class and added a few methods to help with asynchronous setups.
Essentially all a test case that needs to load external data must do
then is to call the setupAsync method with the desired information, and
AsyncSetupTestCase will handle running the test once the load is
complete. All the designated handler in the test needs to do differently
from other tests is to a) not be prefixed with test and b) use the data
property to access the loaded data from the setup. An example test case
demonstrating this follows:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
public function testMethod():void {
    this.setupAsync('something.xml', this.doTestMethod, XML);
}
public function doTestMethod():void {
    // do what we will with this.data, it shall be an XML instance
    assertTrue(this.data is XML);
}
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 12 Feb 2009 20:56:00 -0500</pubDate><category>Flex</category><category>Actionscript</category><category>Testing</category></item><item><title>FlashDevelop Setter and Getter Snippets</title><link>http://www.bensnider.com/flashdevelop-setter-and-getter-snippets.html</link><description>&lt;p&gt;FlashDevelop, the Flash IDE I am using at the moment, has support for
saving snippets of code that is general and reusable, like setters and
getters. The default setter and getter snippets simply add the skeleton
code and require the developer to actually type in variable names, and
types. I found this amount of extra typing to be not worth using the
snippets for setters and getters at all. So I made my own snippets for
these two operations. Mine require that you simply name the method,
because the method name can't be the same as the variable name, and
because the snippet system cannot do string processing. The cursor is
placed where the function name belongs after the snippet is completed.
All that is required for this to work as intended is for the cursor to
be on the same line(anywhere on the line) of a variable definition. You
can then use the same Control-B combo to get the snippet box, and select
the appropriate snippet. The actual snippets follow. set:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$(Boundary)$(CSLB)public function set $(EntryPoint)(value:$(MbrTypName)):void { $(MbrName) = value; }$(Boundary)
&lt;/pre&gt;
&lt;p&gt;get:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$(Boundary)$(CSLB)public function get $(EntryPoint)():$(MbrTypName) { return $(MbrName); }$(Boundary)
&lt;/pre&gt;
&lt;p&gt;With these snippets you can make setters and getters quickly and
accurately. The actual code they generate will end up looking something
like the following:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
private var _points:uint = 0;
public function get points():uint { return _points; }
public function set points(value:uint):void { _points = value; }
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 09 Feb 2009 19:02:00 -0500</pubDate><category>Actionscript</category><category>FlashDevelop</category><category>Flash</category></item><item><title>Flex MenuItem Actions</title><link>http://www.bensnider.com/flex-menuitem-actions.html</link><description>&lt;p&gt;So, gonna write this here because I will forget how to do it.
Essentially, this approach eliminates the need to conditionally branch
on menu item properties. Before we would do something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
private function menuHandler(event:MouseEvent):void {
    if (event.item.&amp;#64;label == 'Save') {
        f = File.destopDirectory;
        f.browseForSave('Save');
        f.addEventListener(Event.SELECT, this.selectSaveFolderHandler);
    } else if (event.item.&amp;#64;label == 'Open') {
        // etc
    }
}
&lt;/pre&gt;
&lt;p&gt;As you can see, this is an awfully coupled solution. Whenever we want to
change the name of a menu item, we also need to change the logic in the
handler. This can be somewhat alleviated by using an &amp;#64;id property
instead of the display text, but its still coupled. The better solution
is to allow the menu item itself designate what action it should trigger
when clicked. This is the method that Buttons use, but for menu items
it's a little different because the menu is simply XML data. What we
need then is a way to store a method name in the menu item XML
definition, have that parameter read by the menu handler method, and the
appropriate method called. For simplicity we limit the specified method
to whichever class contains the actual menu, and that the method has no
required arguments. The magic here is the use of the
&lt;a class="reference external" href="http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getDefinitionByName()"&gt;flash.utils.getDefinitionByName()&lt;/a&gt; function to return a Function
definition rather than a Class, and using the &lt;a class="reference external" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#call()"&gt;Function.call()&lt;/a&gt; method
to actually call the returned Function. So our revised menu item XML
would look something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
&amp;lt;!-- menu items --&amp;gt;
&amp;lt;mx:XMLList&amp;gt;
    &amp;lt;menuitem label=&amp;quot;Save&amp;quot; action=&amp;quot;saveMenuHandler&amp;quot;/&amp;gt;
    &amp;lt;menuitem label=&amp;quot;Open&amp;quot; action=&amp;quot;openMenuHandler&amp;quot;/&amp;gt;
&amp;lt;/mx:XMLList&amp;gt;
&lt;/pre&gt;
&lt;p&gt;And our handler would look like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
// AS handler
private function menuHandler(event:MouseEvent):void {
    var method:String = String(event.item.&amp;#64;action);
    try {
        var methodRef:Function = Function(flash.utils.getDefinitionByName(method));
        methodRef.call(this);
    } catch (e:ReferenceError) {
        trace(e.message);
    }
}
&lt;/pre&gt;
&lt;p&gt;I haven't tested this idea so no idea if it works or not, so YMMV. But
it should work, and if I ever get around to refactoring some old code I
will certainly be including this.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Fri, 30 Jan 2009 15:08:00 -0500</pubDate><category>Actionscript</category><category>Flex</category></item><item><title>HP Laptop Linux Boot Parameters</title><link>http://www.bensnider.com/hp-laptop-linux-boot-parameters.html</link><description>&lt;p&gt;Instead of me wracking my braing trying to remember the exact boot
parameters to make my HP laptop not break when I update the kernel, I am
posting it here. Hopefully someone else may find it useful as well. My
specific laptop is the HP dv9000 series special edition I bought at Best
Buy about a year ago and I am currently running Ubuntu 8.10 with the
2.27 kernel. The &amp;quot;magic&amp;quot; boot parameter seems to be pnpbios=off, so I
end up with a grub entry something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
root (hd0,0)
kernel /vmlinuz root=UUID=&amp;lt;some giant UUID&amp;gt; ro quiet splash pnpbios=off
initrd /initrd.img
boot
&lt;/pre&gt;
&lt;p&gt;Fixes most things including sleep, hibernate, USB hotplugging, and most
noticeably my wireless card.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 03 Nov 2008 13:32:00 -0500</pubDate><category>Linux</category></item><item><title>World of Goo</title><link>http://www.bensnider.com/world-of-goo.html</link><description>&lt;p&gt;Not often do I write personally here outside of programming, but I must
make an exception for World of Goo. It's a game unlike anything else
really, maybe a little like the &lt;a class="reference external" href="http://fantasticcontraption.com/"&gt;Fantastic Contraption&lt;/a&gt; flash game in
that they are both logic puzzles. Otherwise it's a great unique game in
which you can lose yourself. &lt;a class="reference external" href="http://media.beanstalkgames.com.s3.amazonaws.com/demos/wog/WorldOfGooDemo_Setup5.exe"&gt;Try the demo&lt;/a&gt; or &lt;a class="reference external" href="http://www.theworldofgoo.com/"&gt;get more information&lt;/a&gt;.&lt;/p&gt;
&lt;a class="reference external image-reference" href="http://www.worldofgoo.com/"&gt;&lt;img alt="World of Goo" src="http://media.bensnider.com/images/wog-1.jpg" /&gt;&lt;/a&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Wed, 29 Oct 2008 17:18:00 -0400</pubDate><category>games</category></item><item><title>Google Chrome and Firefox 3 Benchmark Comparisons</title><link>http://www.bensnider.com/google-chrome-and-firefox-3-benchmark-comparisons.html</link><description>&lt;p&gt;Google released the beta for their new browser called Google Chrome and
one of the features they talked about was the new Javascript virtual
machine. So to test their claims of speed I ran Sun's SunSpider
Javascript benchmark on both. The results of the tests follow:&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://17.254.17.57/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:[223,232,230,440,236],%223d-morph%22:[185,204,191,189,194],%223d-raytrace%22:[198,188,205,199,196],%22access-binary-trees%22:[191,202,197,200,198],%22access-fannkuch%22:[372,371,378,614,377],%22access-nbody%22:[194,211,197,368,207],%22access-nsieve%22:[148,143,139,149,141],%22bitops-3bit-bits-in-byte%22:[172,182,177,198,175],%22bitops-bits-in-byte%22:[223,225,238,226,226],%22bitops-bitwise-and%22:[163,183,168,168,164],%22bitops-nsieve-bits%22:[225,226,227,226,232],%22controlflow-recursive%22:[162,166,165,269,172],%22crypto-aes%22:[159,158,244,251,162],%22crypto-md5%22:[147,172,152,148,150],%22crypto-sha1%22:[144,148,152,148,151],%22date-format-tofte%22:[7698,8148,10761,9761,10298],%22date-format-xparb%22:[408,178,177,177,185],%22math-cordic%22:[293,290,300,290,302],%22math-partial-sums%22:[186,184,356,176,212],%22math-spectral-norm%22:[169,169,175,168,172],%22regexp-dna%22:[299,332,532,308,296],%22string-base64%22:[163,159,164,160,165],%22string-fasta%22:[343,341,340,349,356],%22string-tagcloud%22:[3249,1584,2178,1573,1605],%22string-unpack-code%22:[451,425,542,441,414],%22string-validate-input%22:[193,198,324,194,196]%7D"&gt;Firefox 3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://17.254.17.57/perf/sunspider-0.9/sunspider-results.html?%7B%223d-cube%22:[43,47,53,47,45],%223d-morph%22:[78,84,79,88,86],%223d-raytrace%22:[81,57,61,60,63],%22access-binary-trees%22:[9,8,8,9,8],%22access-fannkuch%22:[45,48,45,50,44],%22access-nbody%22:[48,45,51,45,46],%22access-nsieve%22:[31,31,31,40,36],%22bitops-3bit-bits-in-byte%22:[9,6,6,6,6],%22bitops-bits-in-byte%22:[11,10,12,12,12],%22bitops-bitwise-and%22:[30,35,37,33,36],%22bitops-nsieve-bits%22:[46,38,48,43,37],%22controlflow-recursive%22:[3,3,3,4,4],%22crypto-aes%22:[26,33,34,37,33],%22crypto-md5%22:[23,23,23,30,28],%22crypto-sha1%22:[21,21,20,22,22],%22date-format-tofte%22:[320,355,325,356,328],%22date-format-xparb%22:[338,370,410,371,348],%22math-cordic%22:[91,95,107,90,92],%22math-partial-sums%22:[77,60,63,58,56],%22math-spectral-norm%22:[20,28,22,19,24],%22regexp-dna%22:[593,596,615,590,603],%22string-base64%22:[146,99,86,102,101],%22string-fasta%22:[89,86,100,83,83],%22string-tagcloud%22:[243,242,229,244,231],%22string-unpack-code%22:[301,304,310,319,312],%22string-validate-input%22:[120,125,125,121,129]%7D"&gt;Google Chrome&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As you can see, Google chrome is much faster than
FF3 by nearly a factor of 6. To see the comparison, load the Chrome
score then copy the Firefox link into the second box, push enter, and be
amazed. While Chrome falters on some of the tests, namely regex, it
blows FF3 out of the water for the most part, especially in the bitopts
section. But with Firefox 3.1 coming out in the near future sporting a
new Javascript tracing engine, which will be faster?&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 02 Sep 2008 16:40:00 -0400</pubDate><category>Firefox</category><category>Chrome</category><category>Javascript</category></item><item><title>OpenMP Examples</title><link>http://www.bensnider.com/openmp-examples.html</link><description>&lt;p&gt;Here are some usage examples for the C++ library available in the GNU
C++ compiler versions 4.2 and up, and probably others. This first
example shows how to use the &lt;em&gt;parallel for&lt;/em&gt; construct to iterate over a
set of neurons. Each thread here gets an equal share of the current
layer's neurons. How big of a portion each thread gets is determined by
how many threads OpenMP has been configured to create. Each thread then
iterates over all the parent layer's neurons. This is made possible by
declaring a private loop index variable. This shows how to construct an
OpenMP work sharing for loop with a nested for loop where each thread
iterates over its own copy of the parent layer's neurons. If &lt;em&gt;j&lt;/em&gt; was not
explicitly declared private, it would implicitly be shared among all the
threads OpenMP creates, which would cause the inner loop to behave
erratically as each thread completes iterations over the parent layer.
Likewise with the neuronValue variable. It also shows how to
conditionally fork multiple threads. In this example we only create
multiple threads if the current layer has more than 500 neurons. If the
current layer has only 500 neurons, then the for loop will execute in a
single threaded environment, otherwise it will execute in parallel. This
is useful, for example, if the current layer 200 neurons, then the
overhead associated with creating more threads might actually degrade
performance.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
int j(0); double neuronValue(0);
#pragma omp parallel for private(j, neuronValue) if(layer.numNeurons &amp;gt; 500)
for (int i=0; i&amp;lt;layer.numNeurons; ++i) {
    neuronValue = 0;
    for (j=0; j&amp;lt;layer.parentlayer-&amp;gt;numNeurons; ++j) {
        neuronValue += layer.parentLayer-&amp;gt;neurons.at(j).value * layer.parentLayer-&amp;gt;weights.at(j).at(i);
    }
}
&lt;/pre&gt;
&lt;p&gt;Likewise we can use these two declarations independently as in the
following two examples with expected results.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
#pragma parallel for if(x &amp;gt; 100)
for (int i=0; i&amp;lt;1000; ++i) {
    // something
}
&lt;/pre&gt;
&lt;pre class="literal-block"&gt;
int j(0);
#pragma parallel for private(j)
for (int i=0; i&amp;lt;1000; ++i) {
    for (j=0; j&amp;lt;1000; ++j) {
        // something
    }
}
&lt;/pre&gt;
&lt;p&gt;These are the fundamentals to creating OpenMP threads. Maybe sometime in
the future I will add some more examples.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 07 Aug 2008 20:31:00 -0400</pubDate><category>C++</category><category>OpenMP</category></item><item><title>CakePHP Getting Tree Path</title><link>http://www.bensnider.com/cakephp-getting-tree-path.html</link><description>&lt;p&gt;In a reversal of yesterday's post is today's, getting a path to a node,
or nodes. Basically we just use the core getpath() function of the Tree
behavior and traverse that path.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
function setTreePath(&amp;amp;$data, $path='tree_path', $label='name') {
    if (!is_array($data) || !in_array('Tree', $this-&amp;gt;actsAs)) {
        return $data;
    }
    if (is_array($data) &amp;amp;&amp;amp; is_int(array_shift(array_keys($data)))) {
        foreach ($data as $i=&amp;gt;$item) {
            $this-&amp;gt;_setTreePath($data[$i], $path, $label);
        }
    } else {
        $this-&amp;gt;_setTreePath($data, $path, $label);
    }
}

function _setTreePath(&amp;amp;$data, $pathField, $label) {
    $cats = $this-&amp;gt;getpath($data[$this-&amp;gt;name][$this-&amp;gt;primaryKey]);
    $path = array();
    foreach ($cats as $cat) {
        array_push($path, $cat[$this-&amp;gt;name][$label]);
    }
    $data[$this-&amp;gt;name][$pathField] = implode('/', $path);
}
&lt;/pre&gt;
&lt;p&gt;And we can use it simply like in the following test:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
function testSetTreePath() {
    $result = $this-&amp;gt;Category-&amp;gt;findById(3);
    $this-&amp;gt;Category-&amp;gt;setTreePath($result, 'tree_id');
    $this-&amp;gt;assertEqual($result['Category']['tree_id'], 'My Categories/Fun/Sport');
}
&lt;/pre&gt;
&lt;p&gt;It's mostly useful when working with related models, so the whole path
is displayed instead of just the nodes, which may or may not be unique.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Fri, 25 Jul 2008 12:06:00 -0400</pubDate><category>CakePHP</category></item><item><title>CakePHP Tree Find By Path</title><link>http://www.bensnider.com/cakephp-tree-find-by-path.html</link><description>&lt;p&gt;Wrote these little functions to help with finding tree nodes by
specifying a path of values. For example if we had a tree of categories
with similar names like TVs-&amp;gt;Color and Movies-&amp;gt;Color, we can't find by
the category name since its not unique, but we can search by pathing
like tvs/color or movies/color. So to this end is this model code:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
function findPath($paths, $fieldName) {
    $root = $this-&amp;gt;find('threaded');
    return $this-&amp;gt;findPathHelper($root, $paths, $fieldName);
}

function findPathHelper($node, $paths, $fieldName) {
    // search for paths from the beginning of the list
    $path = array_shift($paths);
    $newNode = false;
    // looking for the current path in the specified field
    foreach ($node as $nodeNode) {
        if ($nodeNode[$this-&amp;gt;name][$fieldName] == $path) {
            $newNode = $nodeNode;
            break;
        }
    }
    if (empty($paths) || $newNode === false) {
        // done processing the paths, or cannot find a matching node
        return $newNode;
    } else {
        // not done, find based on the found node's children
        return $this-&amp;gt;findPathHelper($newNode['children'], $paths, $fieldName);
    }
}
&lt;/pre&gt;
&lt;p&gt;And we can use it from our controller like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$category = $this-&amp;gt;Category-&amp;gt;findPath(array('tv', 'color'), 'name');
&lt;/pre&gt;
&lt;p&gt;Probably not the most efficient code, but it sure is elegant. It also
will probably break if you have two rows on the same level with the same
name, but that would be pointless anyway.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 24 Jul 2008 13:11:00 -0400</pubDate><category>CakePHP</category></item><item><title>CakePHP Lightbox Helper</title><link>http://www.bensnider.com/cakephp-lightbox-helper.html</link><description>&lt;p&gt;Made a helper to output lightbox compatible links, since the core HTML
helper was not working. Stick the following code in
app/view/helpers/lightbox.php:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
class LightboxHelper extends AppHelper {

    var $helpers = array('Html');

    function img($thumb, $full, $imgAttributes = array(), $linkAttributes = array()) {
        $defaultLinkAttributes = array('rel'=&amp;gt;'lightbox');
        $linkAttributes = array_merge($defaultLinkAttributes, $linkAttributes);

        $thumb = $this-&amp;gt;Html-&amp;gt;image($thumb, $imgAttributes);
        if (strpos($full, '://') === false) {
            $full = $this-&amp;gt;Html-&amp;gt;webroot(IMAGES_URL . $full);
        }
        return $this-&amp;gt;Html-&amp;gt;output(sprintf($this-&amp;gt;Html-&amp;gt;tags['link'], $full, $this-&amp;gt;Html-&amp;gt;_parseAttributes($linkAttributes), $thumb));
    }
}
&lt;/pre&gt;
&lt;p&gt;Then you can use it from your views, after including it in your
controller's $helpers array, like the following:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
echo $lightbox-&amp;gt;img('somethumb.jpg', 'somefullimage.jpg');
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 22 Jul 2008 13:24:00 -0400</pubDate><category>CakePHP</category></item><item><title>Using Radio Buttons with CakePHP</title><link>http://www.bensnider.com/using-radio-buttons-with-cakephp.html</link><description>&lt;p&gt;There's sparse documentation on this topic so here I give some example
usages. Say we have a Posts model like in most of the cake documents.
Basically what we do is make an options array available to the template
that contains the keys and values for the radio button. In the $options
array, the keys are the values sent back to the controller, and the
values are the text displayed on the page. Building the controller to
output a list of radio buttons looks like this:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
...
function radioPosts() {
    if (empty($this-&amp;gt;data)) {
        $posts = $this-&amp;gt;Post-&amp;gt;findAll();
        $options = array();
        foreach($posts as $post) {
            $options[$post['Post']['id']] = $post['Post']['title'];
        }
        $this-&amp;gt;set(compact('posts', 'options'));
    } else {
        $this-&amp;gt;Session-&amp;gt;setFlash('You chose a post with id='.$this-&amp;gt;data['Post']['id']);
        $this-&amp;gt;redirect(array('action'=&amp;gt;'radioPosts'));
    }
}
&lt;/pre&gt;
&lt;p&gt;Then the view for this controller would look something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
echo $form-&amp;gt;create('Post', array('action'=&amp;gt;'radioPosts'));
echo $form-&amp;gt;radio('id', $options);
echo $form-&amp;gt;end('Submit!');
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Tue, 17 Jun 2008 20:40:00 -0400</pubDate><category>CakePHP</category></item><item><title>Dynamically Import and Instantiate Python Classes</title><link>http://www.bensnider.com/dynamically-import-and-instantiate-python-classes.html</link><description>&lt;p&gt;Ran into this bit of genius code in the &lt;a class="reference external" href="http://mail.python.org/pipermail/python-list/2003-March/192221.html"&gt;python mailing list&lt;/a&gt;. Here's
the code for now and I'll explain it later:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
def forname(modname, classname):
    ''' Returns a class of &amp;quot;classname&amp;quot; from module &amp;quot;modname&amp;quot;. '''
    module = __import__(modname)
    classobj = getattr(module, classname)
    return classobj
&lt;/pre&gt;
&lt;p&gt;Basically it returns a class object from modname matching classname.
Sound decptively simple, and it is. If it doesn't find classname in
modname, or it doesn't find modname, it will simply throw an import
error. What's left to do is just instantiate an object of that class and
shazam, its magic. Here's an example to create a new Popen instance:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
p_class = forname(&amp;quot;subprocess&amp;quot;, &amp;quot;Popen&amp;quot;)
p_inst = p_class([&amp;quot;ls&amp;quot;, &amp;quot;-l&amp;quot;])
&lt;/pre&gt;
&lt;p&gt;It's useful for getting input from a file or user and creating classes
based on that input. Of course, be certain to properly validate that
input, or it can get really nasty really quickly.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Wed, 27 Feb 2008 16:18:00 -0500</pubDate><category>Python</category></item><item><title>Getting the Owner of a File in Linux</title><link>http://www.bensnider.com/getting-the-owner-of-a-file-in-linux.html</link><description>&lt;p&gt;Ran across this problem where I needed root to execute a script as
whoever owns it. The solution is simple and should work most everywhere.
Basically it just uses the standard &amp;quot;stat&amp;quot; program and uses the print
formatting option to only output the name of the owner. Here I use bash
to get the owner:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
#!/bin/bash
username=`stat ${1} --printf %U`
echo &amp;quot;The owner of ${1} is ${username}&amp;quot;;
exit 0;
&lt;/pre&gt;
&lt;p&gt;And a sample run looks like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ ./whoOwnsIt.sh testfile.txt
The owner of testfile.txt is ben.
&lt;/pre&gt;
&lt;p&gt;Making root run it as the user's owner is then trivially done with:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
su ${username} ${cmd}
&lt;/pre&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Mon, 25 Feb 2008 17:40:00 -0500</pubDate><category>Shell Scripting</category><category>Bash</category></item><item><title>C++ Pointers and Incomplete Types</title><link>http://www.bensnider.com/c-pointers-and-incomplete-types.html</link><description>&lt;p&gt;Learned some new things about C++ and pointers today. Namely that you
can declare a pointer member variable of the class A in class A. Pretty
neat. Take for example the following simple illustration.&lt;/p&gt;
&lt;pre class="literal-block"&gt;
#include &amp;lt;iostream&amp;gt;
class A {
    public:
        void setMember(A&amp;amp; m) { this-&amp;gt;member = &amp;amp;m; }
        A* member;
        int x;
};

int main(int argc, char** argv) {
    A a,b;
    a.x = 2;
    b.x = 3;
    a.setMember(b);
    b.setMember(a);

    std::cout &amp;lt;&amp;lt; &amp;quot;a.member-&amp;gt;x = &amp;quot; &amp;lt;&amp;lt; a.member-&amp;gt;x &amp;lt;&amp;lt; &amp;quot;n&amp;quot;;
    std::cout &amp;lt;&amp;lt; &amp;quot;b.member-&amp;gt;x = &amp;quot; &amp;lt;&amp;lt; b.member-&amp;gt;x &amp;lt;&amp;lt; &amp;quot;n&amp;quot;;
}
&lt;/pre&gt;
&lt;p&gt;It's output is as follows:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
a.member-&amp;gt;x = '3'
b.member-&amp;gt;x = '2'
&lt;/pre&gt;
&lt;p&gt;So instead of doing this same thing in other more complicated ways we
can do it in one class with simple pointers. Also note that we don't
need to destruct the member variable since it will be destructed
automagically. I find this technique useful in cases where it makes
sense for classes to be linked together. In my case the different layers
of a neural network.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 24 Feb 2008 20:57:00 -0500</pubDate><category>C++</category></item><item><title>Python Lies</title><link>http://www.bensnider.com/python-lies.html</link><description>&lt;p&gt;This is probably a documented issue, but I think it deserves another
mention. Python lies, its the truth. Well, as much as an interpreter can
lie. Say we want to do some math in Python. Say we want to raise large
numbers to large numbers. Say those numbers are 324 and 324. Then we
would do something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
&amp;lt;&amp;lt;&amp;lt; 324**324
&lt;/pre&gt;
&lt;p&gt;and see all the pretty numbers spew out from the interpreter. How do we
know if this is right or wrong though? Say we use long doubles in C++ to
determine the results of this same operation. Then we would do something
like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
long double k = 324;
for (int i=0; i&amp;lt;324; ++i) {
    k *= k
}
std::cout &amp;lt;&amp;lt; &amp;quot;324^324 = &amp;quot; &amp;lt;&amp;lt; k &amp;lt;&amp;lt; &amp;quot;n&amp;quot;;
&lt;/pre&gt;
&lt;p&gt;But alas, the output is &amp;quot;inf&amp;quot;, so we check the largest long double our
compiler and machine can represent and find that it is roughly equal to
1.2e+4932. We then check in python if this number is greater than
324^324 by doing something like:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
&amp;gt;&amp;gt;&amp;gt;&amp;gt; (12**4932) &amp;gt; (324**324)
True
&lt;/pre&gt;
&lt;p&gt;However, this contradicts the fact that C++ could not represent 324^324,
so Python must be lying. Indeed we check the largest power of 324 we can
represent in C++ long doubles, and it turns out to be 11. Thus Python
lies. What does this mean. Don't rely on Python for numeric accuracy
without checking its results. &lt;strong&gt;Update&lt;/strong&gt;: This post is probably wrong,
but I don't like deleting things. So refer to Tyler's comment below.&lt;/p&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Sun, 17 Feb 2008 19:13:00 -0500</pubDate><category>Python</category></item><item><title>Flixya Firefox Extension</title><link>http://www.bensnider.com/flixya-firefox-extension.html</link><description>&lt;p&gt;I just recently finished up a Firefox Extension for the social video
site &lt;a class="reference external" href="http://flixya.com"&gt;Flixya&lt;/a&gt;. Extensions are all written in JavaScript and a sort of
XML called &lt;a class="reference external" href="http://www.xulplanet.com/tutorials/whyxul.html"&gt;XUL&lt;/a&gt;. Most of the framework was already written for me
though, so I just hacked together the bits that worked with my code and
nixed some of the old stuff. Basically the extension grabs some relevant
data like tags, the title, etc., from a video hosted on a number of
online video sites like &lt;a class="reference external" href="http://www.veoh.com"&gt;Veoh&lt;/a&gt; or &lt;a class="reference external" href="http://www.youtube.com"&gt;YouTube&lt;/a&gt;. It then fills that text
into the extension's interface so user's can edit or add to the provided
information. Finally it posts all of the information to the user's
Flixya account where other users can view and comment on each other's
videos. The idea of using an extension like this is to streamline the
video submitting process, and it works quite well. Grabbing the text
from all the various sites took a while and was the most difficult part
of the process. Some sites like Veoh are coded in XHTML so they use CSS
for presentation and a minimal amount of actual markup. This makes
parsing a page much easier with either XPath or grabbing elements with
the JavaScript &lt;a class="reference external" href="http://developer.mozilla.org/en/docs/DOM:document.getElementById"&gt;getElementById()&lt;/a&gt; function. Other sites like
&lt;a class="reference external" href="http://www.livevideo.com"&gt;LiveVideo&lt;/a&gt; use tables almost exclusively which makes finding a unique
part of the HTML rather difficult and sometimes near impossible since
the code around the desired text is so similar to other undesired text.
But the resulting extension works very well with a number of online
video sites and allows easy posting to Flixya.&lt;/p&gt;
&lt;p&gt;&lt;a class="reference external" href="http://www.flixya.com/tools"&gt;Flixya Firefox Video
Publisher 2.0&lt;/a&gt;&lt;/p&gt;
&lt;img alt="Flixya Extension" src="http://media.bensnider.com/images/flixya-ext.png" /&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 28 Jun 2007 23:12:00 -0400</pubDate><category>Firefox</category><category>XML</category><category>Javascript</category><category>XPath</category><category>Scraping</category></item><item><title>LocalWineEvents.com Google Gadget</title><link>http://www.bensnider.com/localwineeventscom-google-gadget.html</link><description>&lt;p&gt;Just finished a Google Gadget for the &lt;a class="reference external" href="http://www.localwineevents.com"&gt;LocalWineEvents&lt;/a&gt; website. It
uses the Google Gadget API, of course, which is in JavaScript, XML, a
little HTML, CSS, and the obligatory IE CSS hacks. Basically it asks the
user where he or she lives when it's run for the first time, then it
grabs the corresponding RSS feed from LocalWineEvents.com, parses that,
and produces the output as shown in the screenshot below. Clicking on
the + reveals the event's details and changes the + to a -, which can
then be hidden again using the - button. I used a new tool to make this
gadget, since it's primarily coded in JavaScript, called &lt;a class="reference external" href="http://www.aptana.com/"&gt;Aptana&lt;/a&gt;. It's
essentially a plugin for &lt;a class="reference external" href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt;, but the authors also provide a
stand-alone client preloaded with the plugin. I liked it except that it
didn't detect JavaScript inside an XML document, which is the format for
Google Gadgets. So I just coded the JavaScript in an HTML file and
pasted the JavaScript into the XML as needed. I was once again reminded
how bad I am at using the &lt;a class="reference external" href="http://www.gimp.org/"&gt;GIMP&lt;/a&gt; or any other graphics editor. Must be
missing that visual creativity gene... &lt;a class="reference external" href="http://www.google.com/ig/add?moduleurl=http://local-wine-events-gadget.googlecode.com/svn/trunk/src/ig.xml"&gt;Add to your Google Homepage.&lt;/a&gt;&lt;/p&gt;
&lt;img alt="LWE Google Gadget" src="http://local-wine-events-gadget.googlecode.com/svn/trunk/src/ss.png" /&gt;
</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Ben Snider</dc:creator><pubDate>Thu, 21 Jun 2007 19:49:00 -0400</pubDate><category>google</category><category>gadgets</category></item></channel></rss>