Saturday, October 15, 2011

HTML5-Compliant YouTube Embedding

Today I was updating my fathers site, Home Tips With Jim to be HTML5-compliant.  It was pretty much just a matter of removing the center tag and target="_blank" from the links -- or so I thought.

I'm putting this out there for anyone that may run into the problem in the future; while trying to use YouTube's new iframe embed system to embed my father's playlist into the page, I ran into two problems spit out by the W3 Validator:
Attribute allowfullscreen not allowed on element iframe at this point.
And:
The frameborder attribute on the iframe element is obsolete. Use CSS instead.
After some quick research, I found the solution; apparently frameborder is depreciated, and allowfullscreen is not fully implemented.
The solution, was to remove those two elements, and replace the frameborder one with CSS.  So, if anyone else runs into this problem, go into the
<iframe> tag, and change this part:
frameborder="0" allowfullscreen
To this:
style="border: none"

You can now view the source to the HTWJ site, and see how it's been fixed.

Wednesday, October 5, 2011

How to create a desert

Hi everyone, assuming there's actually someone out there that reads this blog.

I thought I'd blog about something that's been on my mind for awhile now, though it may not be on others: how does one create a desert?  I'm not talking about a desert-themed terrarium or a panorama, I literally mean how would someone create a physical desert?

Let me explain.  Back when I was growing up, my family lived in this nice little house that we rented.  When we first moved there, the backyard had lush green grass, it was a really nice yard.  By the time we moved, all of that grass was gone, nothing could grow, nothing would live.  The dirt became more of a "dust" or "sand" texture; it didn't hold water, it couldn't hold life.  What happened in this yard, on a small scale, is what's called Desertification.

Desertification is primarily what has happened in the Midwest of the United States, and it is currently happening in Asia.  It's why the huge Sahara Desert used to be ocean, and why places in China that were lush green fields just 20 years ago are baron wastelands.

So my question is, how would I create a desert?  It seems once the process of desertification starts, it "snowballs" into an unstoppable force, turning entire landscapes into a desert.  On other words.....
How does this:
 Become this:

Step 1: Overgraze
Probably the best way to kill fertile land, is to overgraze.  With so many animals trampling the land and eating the vegetation, it isn't hard to figure out why the land actually dies.  I'm sure people that own large, outdoor dogs can probably agree with me, if their dog pen ended up becoming bare dirt.

Step 2: Dig
Back when we had that old yard growing up, I would dig things up there on a daily basis.  I would try to dig my own "streams" try to excavate rocks.  All of this constant digging seemed to make the land more "arid" and loose; eventually it became almost like a sand.

Step 3: Irrigate
It seems kinda odd that irrigating the land would actually contribute to killing it, but this seems to be the going consensus.  I remember during the summer, I would tie a hose to the top of my sliding board set, and I'd dig streams going from the huge mud puddle in my yard, all the way through to the back in the woods.

Step 4: Overfarm.
Overfarming is also a major contribution to desertification.  It's true that the runoff from farming could hurt the dirt, but when plants grow, they are constantly sucking nutrients out of the earth.  usually when the plant dies, the nutrients goes back into the dirt, but if the entire plant is harvested, those nutrients will never go back in.

Conclusion.
It's simple, really.  If you want to kill your land, simply trample the dirt, dig a lot, irrigate, and overfarm.  It's what happened in the Dust Bowl, it's what's happening in China.  No go out there, and create some deserts! :D

Sunday, September 4, 2011

My new website and other updates

It's been quite awhile since I had a chance to update this blog, been busy IRL, but I thought I'd at least give an update with what I've been doing.

Currently in my fourth year at college, leading the school's programming team again, and also working on some new websites of mine.


Also, for those who are interested, here is a quick update on that Dvorak Keyboard Layout.  It's been about nine months since I made that switch, and I'm up to 89-95wpm again.  Yes, it's not the 100+ wpm I had before, but hold fast, I'm slowly getting there.

Anyways, to the website.  I've recently created a pretty funny website, called LOLFlash.com.  It's pretty much a website with a ton of funny (and for some, seizure-inducing, so watch out) flash loops.  The whole website is written in C, of course, and not php.  I've also been slowly but surely working on the groundwork for the website, www.ironicsecurity.com, which will be another type of blog I'll be working on, so keep and eye out for that.


I will try to update this blog when I can though, I'm currently working on an article on desertification (what, you thought I only knew about programming?), if I can ever get around to finish it....

On an unrelated note, Home Tips With Jim is started to get pretty awesome, and there are plenty of new episodes; check out my dad's new website: www.hometipswithjim.info for the latest playlist.

NOTE: This is part of a series, check the next entry here! 

Monday, May 30, 2011

Why your website should be written in C, not PHP

It's been awhile since I updated this blog, been pretty busy IRL.  Just recently got back from a Longsword Course with ARMA, in Ohio, was very nice, and I learned a lot.  I've also been playing the silver market recently; there's a pretty nice blog that I follow.  If you're looking for an interesting perspective on precious metals, check this guy at Along the Watchtower; he seems to know his stuff.

Okay, back to the point of this post. 

I have studied several scripting and programming languages; off the top of my head, I know Ada, C, C++, Fortran77, FORTH, Perl, PHP, Python, Java, and JavaScript.  Which language do I prefer, though?  C.

Now, for the record, just so you do know that there are plenty of sites written using something other than PHP.  Any website ending in .cgi are usually written in a compiled language.  I have came across some sites that are written in C++ before, and Deltapsi Studios, my good friend Stephan's site, is written in C, with mysql support and everything.

Anyway, more and more people in today's world are designing websites in PHP.  After all, as one of my professors would say, "PHP is built for the web!"  Maybe that's why Facebook uses PHP
Addendum 08/27/11: Actually it seems like Facebook wrote their site in PHP, then used software to convert it into a complied language, since interpreted PHP wouldn't be able to hold up the site.

C, on the other hand, I keep finding people consider it a low-level language that is only used by the hard-core programming.  One of those "hard to learn" languages that take millions of lines of code to get things done.

Despite the above accusations, you will find that C is actually a very good language.  It is an easy language to learn, and if programmed correctly, easy to understand, and by default, C is one of the fastest-executing programming languages out there, and when optimized, it can blow almost anything out of the water.  Check the end of my switch() vs elseif benchmarks post.  PHP took 8.169889 milliseconds to traverse my last test, whereas C took 0.01267 milliseconds.

Maybe you're thinking, "Okay, PHP takes 8ms and C takes 0.01ms.  A millisecond isn't that long."  There are two points I should make.  First, if you do the math between those two times, you find that C's switch() executed almost 645 times faster than PHP.  This in a matter of speaking, makes C about 64,500% faster than PHP!  Now THAT, is a speed difference.
And even then, while a millisecond may not seem that much to you, if you're having your web application serving hundreds or thousands or millions of requests, the speed difference will add up, and while the websites designed in C will be happily treading down the road, you'll find your PHP-site stalling and lagging while the preprocessor parses for your people.  For the virtual machine guys out there, if you want to get technical, ASP.NET or JSP should theoretically run faster than PHP.

Okay, so C is faster, C is more efficient, and I'm telling you that C is easier.  "But Anthony!" you cry, "What about the sessions and the cookies and the hash map arrays and the typeless variables, and my strings, and HTML output, and..."  Yes, yes.  By this point, you realize that PHP was indeed designed for the web, hence it will have a ton of web-design libraries that are not in the Standard C Library.  This means that if you want to use mysql, you will have to get the MySql Library and do your queries in C.  If you want sessions, you will have to find a session system for C, or write your own.


Yes, you will have to have "type" your variables, that is, using "int iNumber = 3;" instead of "$Number = 3;" and you will loose those hashmap/linked list arrays that everyone seems to love so much, though if you look at that previous benchmark, you'd find the hashmaps in PHP executing pretty slowly as well.  This is due to the slow nature of a hashmap, which is not in the scope of this entry, and just remember, in C, you can implement radix tables or something much, much, faster than hashmaps.

As for cookies, GET, and POST, it's really not that hard.  Below, you can read the get/post/cookie receiving that I used, in my C-web application, as well as the sessions system:

» Click to show Spoiler - click again to hide... «

There is a downfall, however in C, and that is how horrible it handles strings.  After all, with the happy-go-lucky $mystring = "Hi everyone!"; how can you go wrong?  In PHP, to concat a string, all you have to do is:
"Hi " . "Everyone!"
I believe.  Everyone knows that C-strings are slow.  Try to concat a string in C multiple times, and you'll quickly find that it has to traverse the string in strlen() every single time strcat() is called.  If String A and String B are 256 characters, and you strcat() them, when you try to concat the new string, it will be twice as slow.  Strings are a mess in C.  So what did I do?  I wrote a new string library, that handles strings like Pascal does:

struct string_t
{
  size_t len, /*Size of string to '\0' */
         max; /*Size of the total string*/
  char* str;
};

What's the point of the above structure?  Those that know C will probably be going "OH!", and for those who don't...  I'm storing the length of the string in my actual string.  You'll notice a HUGE increase in performance once strlen() can return the length with "str->len" instead of "for(s=str;*s;++s);"
So now, I can do,
string_t* mystr = mystr_create(256); //Make a string that can hold 256 characters.
mystr_concat(mystr, "Hello World!");
Was that so hard?

"What about outputting text?"  What about it?  It is true that in PHP, you can do:
<p>The number is: <?php echo $number ?></p>
Or whatever it is you do, but in C, I can just do:
printf("<p>The number is: %d<p/>", number);

What I'm doing, is simply embedding the HTML into the c-code, instead of embedding the c-code into the HTML.
(NOTE: Stephan, if you're reading this, no, I do not actually use printf..)



So in short, anything written in PHP can be written in C (even if you don't feel like writing the systems yourself, there's a good chance you can find a libcgi worth using), and PHP is slow (very slow).  Now, I can go over and discuss

Friday, April 8, 2011

Alpha Chi Conference in San Diego, CA (warning: heavy picture content)

There hasn't been much of an update from me in a while, as I have been working on my projects at Uni, and preparing for trip for the Alpha Chi Honor Society National Conference (which I just got back from), to give my presentation on Artificial Life.

 The conference was in San Diego, California, a very beautiful place.  I was there for 5 days, and I had experienced my very first time on a plane.  I won a national award (10 are handed out, from a pool of over 11,000 alpha chi members made up of the top 10% of their universities), saw some seals at the Children's Pool Beach, and got to go to Sea World with my Aunt and Uncle!

On a side note, I'm up to about 67-68 wpm with the Dvorak layout (remember that?) when on my macbook (I'm abit slower on my main computer).  Should be back up to my 100+wpm I had in QWERTY in no time!

Anyway, there were plenty of pictures (I didn't take any, I just asked my fellow students to take some and give me theirs); I hope you enjoy!


Tuesday, January 18, 2011

switch() vs elseif benchmarks

There was an interesting benchmark on a friend's blog.  He was running a "switch() vs else if" test in php, which yielded some very interesting (and at first, perplexing) results.

I'd just head over there and read his article as a primer, so you know where I'm coming from.  Now, after reading his results, I was desperate to find out why this was happening, and I decided to run some benchmarks on my own.

Might want to sit back, this is going to be a long one (you'll have to click "Read More" for this one).

Friday, January 14, 2011

Progress and a new keyboard!

It's been about two weeks since my switch to the Dvorak Simplified Keyboard.  I checked my typing speed on TypeRacer earlier today, and I'm currently running at about 40 wpm -- I'm getting there.

Then, today my $129 keyboard came in the mail; with gold-plated mechanical switches and absolutely no labels.

That's right; I bought the $129 Das Keyboard Ultimate -- it's loud, it's heavy, and when added to this key mapping, it's confusing for anyone that attempts to use my computer.

There's been quite a few people asking me about this layout, and I have to say, the immediate results are pretty nice.  I managed to learn to touch-type with this new layout in a matter of days, and within two weeks, I'm around half the speed I was with QWERTY.  I'm able to type most of my words on the home row (consisting of aoeuidhtns), and my wrists don't hurt after a long day of typing anymore (please be aware, I punched out almost 2000 lines of code this week while programming).  But then again... I'm not typing as fast as I did with QWERTY yet, so we'll see.

On a side note, I no longer have a problem with "F", though I'm slipping up with "j" and "q" once in awhile.

PS: On a side note, I ran this entry though a neat little applet that would calculate some stats based on how much I'd type, etc...

Is this post, 64% of my typing took place on the home row, and my fingers traveled a distance of 58 feet.

If I were to use QWERTY to type this, only 32% would've been on the home row, and my fingers would have traveled almost 100 feet!

NOTE: This is part of a series, check the next entry here!