HTML Quickform is pretty cool, I think I have mentioned this before. Hierselect is a way to have select boxes cascade. User selects something in the first box, then the options in the second box change automatically to be relevant.


I have been playing around the past couple days getting some stuff done for Share The Beat, namely allowing users to select their country, and have the provinces/states/counties/districts/etc for that country prompt automatically. Gathering the data and sticking it in the DB took a while, but I was having some problems getting the JavaScript to kick in and make the magic work. It turns out it was as simple as having forgotten the <form> tags around the form. Silly me, but something to keep in mind if you are hitting your head against the wall trying to figure out why your hierselect wont work.


Okay, well, previous blog posts aside, I still love using Bloomba for my email. Yes, it has given me some problems with losing mail and such, but the ability to find a specific message within seconds, rather than minutes is awesome.


Well, they just got bought by Yahoo, and as far as I can tell Yahoo bought the company for the staff and expertise, not the program, so the program is being canned.


Damn


(as a side note with reference to the previous post, I don't have a decent word processor on this machine, so I spell checked in UltraEdit, my apologies if I missed anything)


After going through and deleting a lot of the spam comments that have infested this blog, I noticed a few comments I hadnÂ’t read before. One of them pointed out the deplorable spelling oft present in my posts. Well, to that end, from now on I will make every effort to not only write these posts in a program that offers spell checking, but also proof read before posting.


I have also begun going back through my posts and correcting the spelling retroactively.


Thanks

Paul


I saw this interesting item on slashdot today, just thought I would add my own couple of entries, in the tone/style of the original article.


Overbuild assignments!

The program assignment (which you learned from others, having not read it yourself) was designed as a minimum specification. Technically all you need to write is a simple addition calculator, user needs to enter two separate numbers, the program adds them together and returns the result, bah, what a waste of time! That was written with liberal arts majors taking a CS elective in mind. What you need to write is a full featured calculator, with at least three levels of abstraction, capable of handling all forms of mathematics, and alternate entry methods such as RPN. The program should be able to interpret and numbers entered numerically (23), as well as linguistically (twenty-three), in a minimum of four languages. Additional languages should be easy to add.


Ask TAs demeaning questions about overbuilt assignments

So, you managed to turn your simple "Introduction to the Internet" HTML assignment into a 47 page JavaScript application. Sure the assignment only called for standard HTML (CSS for a bonus point), but what good is that? You want stars to circle around the mouse cursor, scrolling text in the status bar, semi-transparent mouse overs on images with variable text depending on the time of day, etc. You decide to be extra sneaky and remove all possible white space to make the file smaller, then give all variables single character names to cut down on a few more bytes, oh the brilliance! What's that? It doesn't work? Dump the program off on a TA the night before the assignment is due, exclaim "It's broken" then insult them, and blame them when the assignment doesn't get in on time.


On a serious (non-sarcastic) note

As someone who had a lot of programming experience going into University, I found the best way to guarantee good marks was to build exactly what the assignment called for, nothing more. We had a basic assignment to build a 10 page HTML website. Most of my friends decided to show off their skills, Flash, JavaScript, mouse roll overs, etc. They got killed when it came time to get marked! Some of their tricks didnÂ’t validate as HTML, they used the newest sexiest browser to check stuff, but the TAs used an older version of IE so stuff didn't look right, etc. I built a 10 page website talking about the sculptures along the river in Windsor. Every page but the first had exactly the same format. White background, blue text, picture name in H1 tags, paragraph talking about the picture in P tags, my name at the bottom. Done, perfect mark. Took like an hour and a half outside of actually shooting the photos.


It is so easy to overbuild assignments, but resist the temptation. The more you add, the more places you can lose marks, and the more likely you are to surpass the knowledge of your TA should you require assistance.


I needed some form of a captcha thing for Share The Beat, just to put some token effort into preventing bot registrations, I tried to find ez-gimpy at captcha.net to no avail, so I used a PHP class from Pascal Rehfeldt. Integration with HTML_Quickform was way easier than I expected, but I thought I might document what I did for the novices out there.


1. Grab the captcha class from Pascal.

2. Either grab the font specified in the class, or point it at some other font (or some random font, you get the idea)

3. Try to load the example image, if it doesn't work turn off the headers in the class so you can see error messages (note that the TTF I downloaded didn't match the case of the one specified in the file, might want to look at that). Don't proceed untill that works.

4. Add the apropriate element to your form definition, mine looked like this:

$form->addElement('text', 'txtCaptcha','Crazy Text: ');

5. Register an additional rule for the text

$form->registerRule('captchaTest', 'function', 'checkCAPTCHA');

$form->addRule('txtCaptcha', 'Please ensure the text in the box matches the text in the image exactly', 'captchaTest');

6. Write that function:

function checkCAPTCHA ($name, $value)

{

if ($value == $_SESSION['CAPTCHAString'])

{

return true;

}else

{

return false;

}

}

7. Display the example as an image on your form (I use templates so this was easy)
<img src="./example.php">

8. Test

9. ..

10. Profit!



The class stores the captcha string in the session, so it is quite easy to access it later on. I personally saved the example.php file as captcha.png and told Apache to interpret it appropriately, your mileage may vary.


Things you could do to improve it:

-Select a random font from a list

-Make it case InSensiTIVe

-Find a more complicated captcha :-)


Converting Media Types


Many (though definitely not all) people agree that purchasing media in one format, gives you the right to use it in another. For example, I ripped most of my CDs into a smaller format on my PC, for easier listening. What happens when the conversion isn't so easy?


Q: Does the purchase of media in some format give one the right to enjoy it in another format? And if so, is it necessary to do the conversion oneself, or can the alternate format be obtained by other means?


Scenario: Sue (a single mom) buys the new Lion King 2 DVD, she wants to tape the DVD onto a VHS cassette, so that her two daughters can use the TV & VCR in the play-room to watch and watch again (and again, and again) to their hearts content, without risking this valuable investment. Then when the VHS tape wore out, or when the kids broke it, she could just make a new one for the cost of a blank tape. Would this be legal?


Alternate Scenario: William, a young executive is about to leave on a business trip, he expects to have a lot of free time on his flights as his presentation is complete. He wants to bring some movies, but doesn't really want to deal with the bulk of carrying 5-6 DVDs, nor any worries at customs. So he uses some software and rips the DVDs into a compressed DiVX format for easy storage on his hard drive. Was this legal?


Alternate Scenario: William can't get the DVD encoding software to work, so he loads up a file sharing client, and downloads those same movies. Was this legal?


Things to ponder:

1. In none of the cases was their any dark motive, people just wanted to enjoy something they purchased in a way slightly different than the original form.

2. In every case, there was now two copies of something that had only been paid for once.

3. Under William's cases, what happens if his girlfriend watches one of the movies while he is gone?

4. Under William's second case, it is entirely possible that the DiVX copy of the movie he ended up with exactly matched (bit for bit) the one he would have had, should he have been able to get the DVD encoding software to work.


My Answer: In my opinion purchase of a piece of media gives one the right to convert/copy etc. as required, so long as the copies/alternate formats remain in their possession. Copying a DVD to VHS is completely permissible, as is copying a DVD to DiVX or some other more portable format. In terms of obtaining the DiVX from the internet, I believe this is also permissible, however the onus rests on the downloader to ensure it is the same version.

1. Not really a question.

2. Not really relevant, all copies are owned by the same individual

3. This could pose a problem should both copies be in use at the same time. Some arguments could be made for either side.

4. The fact that the two versions (downloaded vs encoded by self) would/could be identical supports my argument that this is permissible.


This is probably my favorite function for dealing with getting data back from MySQL. It's infinite usefulness may be tied to the fact that I often send arrays straight to smarty for display, which handles arrays of associative arrays really well, but perhaps not.


The way it works is thus. You send the function two parameters, the first being the query you would like to run (something like SELECT * FROM news_posts WHERE ID > 50), and the way you want the results.


Sending the function 0 (or nothing), allows the data to determine what is returned, if you send the function a query that returns 1 row, you will get a single associative array with field name => data. If the query returns multiple rows, you get an array of arrays. Each internal array being the same as it would be for a single result. I never use this setting, it exists for legacy reasons with old code.


Send the function 1, and you will only get a single associative array returned. It will either be the single result your query returned, or the first result. For performance reasons, unless your query is guaranteed to only have a single result (like selecting based on a primary key), you should add LIMIT 1 to the end of your query.


Send the function 2, and you always get the array of associative arrays. This is my most commonly used setting, as it works really well for populating information in Smarty.


(I am referring to the getAssoc function in the following include, I put it all in there just in case someone was interested)



I would like to take a moment and vow, to never, ever, release or publicly use code that contains the following line:
#TODO: better security


I think you should to.


Splitting Albums.


I think everyone would agree that if you purchase a CD, you have the right to sell it later. Used CD stores are prevalent, so it must be legal, so...


Q: Does the purchaser of a set of music pieces have the right to further divide the work, and then sell the portions.


Scenario: Joe goes to the store, and buys the new ABBA album for $10. He then copies it onto his computer for easy listening. Joe decides he doesn't like some of the songs, but is friend Tom does. Joe sells Tom half the songs from the album for $5. To accomplish this, he gives Tom the appropriate files from his computer (then removing them from his computer), and destroys the original CD. Was that legal?


Alternate Scenario: Tom buys a CD on iTunes for $9.99, he doesn't like some of the songs, so he resells them to his good friend Joe. To accomplish this, he needs to remove the DRM encryption from the files, then send them to Joe, then remove the originals from his PC. Was that legal? (Please ignore the DMCA, I'm considering copyright law, not silly laws preventing you from things you purchased).


Things to ponder:

1. Does profit/loss come into play. If a CD is with 14 tracks purchased for $10, then each track is resold individually for $1, is that any better/worse.

2. In the first scenario, what if Joe had not destroyed the original CD, but had kept it, vowing only to use it in case the songs HE owned on his PC were lost. Does that effect anything?

3. Can you subdivide it any further than a song? Could half a song be sold? A few seconds? A single note?


My Answer: In my opinion, purchase of the music, regardless of format (physical/digital) gives one the right to resell all or a portion of the piece later, note that a piece once sold must be turned over in its entirety. This should be no different than buying a cord of wood to split with a neighbor.

1. Profit or loss is immaterial.

2. To be honest, I would put this a hair on the wrong side of the law. When you have a single copy of something, and sell it, you should have 0 copies remaining. Its basic math. Ethically, if Joe's vow is respected, I would call it pretty neutral.

3. Subdivision is immaterial, the artist's/label's right to determine how the music was to be enjoyed ended when purchased. Whether you can find someone willing to buy a second of a Britney Spears song is debatable.


My problem with a lot of the comments on php.net is that they often tackle the more difficult problems, while ignoring the simple ones. And sometimes when you're just looking for a quick answer, they skipped it :-).


So anyways, hereÂ’s a quick function to create an png thumbnail image.



function makeThumbnail($sourceFile, $destFile)

{

$S_im = imagecreatefromstring(file_get_contents($sourceFile));

$S_info = getimagesize($sourceFile);

$x = 0;

$y = 0;

$z = 0;

if ($S_info[0] > 75 || $S_info[1] > 75)

{

if ($S_info[0] > $S_info[1])

{

$z = ($S_info[0] / 75);

$x = intval($S_info[0] / $z);

$y = intval($S_info[1] / $z);

}else

{

$z = ($S_info[1] / 75);

$x = intval($S_info[0] / $z);

$y = intval($S_info[1] / $z);

}

if ($x == 0)

{

$x = 1;

}

if ($y == 0)

{

$y = 1;

}

}else

{

$x = $S_info[0];

$y = $S_info[1];

}

$D_im = imagecreatetruecolor($x, $y);

imagecopyresampled ($D_im, $S_im, 0, 0, 0, 0, $x, $y, $S_info[0], $S_info[1]);

imagepng($D_im,$destFile);

return array($x, $y);

}


Starting today, and going as long as I can, I will pose a question each day with regards to the confusing world of copyright.


These aren't questions I expect answers to, but ones I think the legislature should answer.


You may, or may not agree with my stance on the question, that is up to you, if you disagree, please explain why.


Question: Does purchasing a videogame or movie give one the right to that music in other formats? May the music be copied off the game disc/dvd and enjoyed elsewhere?


Scenario: I own Burnout 3: Takedown, there are several songs included on the disc that are played while racing. Can I (legally mind you) copy the songs off that disc onto my PC, my iPod, etc.


Things to ponder:

1. Did the recording artist get paid a flat fee for being included, waive any fees for promotional consideration, get paid on a per disc sold royalty system? Does it matter?

2. Does how I get the music off the disc matter? Line out from the X-Box into my computer, copy the files off the disc, etc.

3. What if the exact same song is downloaded off the Internet via a P2P network?

4. The songs on a game disc are usually present as-recorded, with the game noises over laid at play time. For a DVD containing a movie, the soundtrack would generally be mixed with the standard audio track professionally, and as such, the audio can not be copied as easily, does this matter?


My Answer: I think as the purchaser of any game disc/dvd I have obtained the right to use the product in whole or in part anything contained within to my hearts content.

1. Method of compensation of the artist is immaterial in this case.

2. Method of transfer is immaterial.

3. Acquiring the song through other means is permissible, but the burden rests on the party to ensure they obtain exactly the same song (live vs studio, alternate mixes etc).

4. Purchase of the disc only gives one rights to the material on the discs. If for example, a particular song played during a movie is over laid with gun shots and screams, so be it. The party does not have any rights to any other recording.


No spam this time around (though I must ask, am I the only one who finds the concept of Viagra soft tabs (the most recent trend of spam I am receiving), rather... odd?), but a couple odd notes from life.


I decided I needed a CD burner early yesterday afternoon, so I hit up NCIX.com, ordered one, and it arrived today, early in the afternoon. Quite a feat, since NCIX is on the west coast, and I am in Ontario. Pretty sweet all around. I got the case apart, installed the burner, booted up, and now my PC will only recognize the burner, the old CD-ROM is forgotten. I tried switching IDE cables to no avail, double checked power, it's all good. Who Knows? (if you do, please let me know!). Anyways, hereÂ’s the odd part, when I eject the tray on the burner from windows (either via the right click menu, or the button in iTunes), occasionally BOTH CD trays eject! ThatÂ’s right, windows is ejecting the tray from the drive it refuses to admit exists!. Though, to be honest, I think the fact that it only happens some of the time disturbs me far more than the fact that it happens at all...


P.S. I am also noticing that CDs are ripping under iTunes roughly 3x faster than before. Rip rates used to hold between 3x-6x, and are now generally 11x-17x. Weird.


P.P.S. I am now ripping Dance Mix USA '96 (Limited Canadian Edition), yeah, that's odd too (the title, not the music (okay, well, the music is odd too, but who can beat a CD with pizzaman on it!)).


I'm glad I don't watch much TV anymore, it's too confusing these days.


Stuff used to be pretty simple, new episodes started in September, ran through until some time before the summer started. Over the summer you had re-runs.


So, over the summer I saw two series start, Summerland and The Days. Both of them started and ended during the summer, I think.


I would also swear that I saw an ad stating that there would be a new episode of Summerland soon. So the show will premier, finale, then premier again all in one year. The season finale of Nip & Tuck is coming up soon?


Stop the madness!


P2P or a TiVO seems to be the answer, download/record and watch at your leisure.


Is anyone else seeing a direct correlation between the number of firefox vulnerabilities reported/patched and the rise of its popularity? Popularity = Scrutiny = #Vulnerabilities?. Once Firefox achieves equal popularity with IE, we can really see which is the safer way to browse.


Okay, so this confused me for a bit, until I figured out where to look.

Simple example:


foreach ($images AS $value)

{


if ($value['height'] > 75)

{

$value['height'] = 75;

}

if ($value['width'] > 75)

{

$value['width'] = 75;

}

}



Pretty basic, if either of the image attributes are over 75, then set them back to 75 for easy previewing. Trouble is, the changes don't stick.


Foreach works on a copy of the array. So my changes were applied to a copy of the $images array that was destroyed as soon as the foreach loop finished.


If you're lucky enough to be working with PHP 5+, just add an & before $value to work with the real values. If not, use one of the other alternatives.


As a small side note, if you have a large array, there may be some performance reasons to work with the array byref unless you have a reason not to. It would save the allocate/deallocate of the ram needed to store your array.

Hi, I’m Paul Reinheimer, a developer working on the web.

I co-founded WonderProxy which provides access to over 200 proxies around the world to enable testing of geoip sensitive applications. We've since expanded to offer more granular tooling through Where's it Up

My hobbies are cycling, photography, travel, and engaging Allison Moore in intelligent discourse. I frequently write about PHP and other related technologies.

Search