Since I already have this blog around, I figured I would pimp out the new site I'm making. It's called Cobra Dragon Games, and it's really cool! Why is it so cool you ask? Well, if you are into challenging others online in simple, yet addicting games, then this is the site for you.
The first game on the site is a Tangleword clone called Serpentine. Whether or not you remember tangleword, it was a boggle clone with some different rules that really heated up the gameplay. It was also a free online games that you could play with up to 32 people at a time. Unfortunately, Tangleword is no more, but Serpentine is it's spiritual successor, and Cobra Dragon Games hopes to be a place where fun, free multiplayer games will be enjoyed.
The game is currently in a working state, though it still needs more testing to iron out kinks. Anyone is welcome to come by and play though.
The first game on the site is a Tangleword clone called Serpentine. Whether or not you remember tangleword, it was a boggle clone with some different rules that really heated up the gameplay. It was also a free online games that you could play with up to 32 people at a time. Unfortunately, Tangleword is no more, but Serpentine is it's spiritual successor, and Cobra Dragon Games hopes to be a place where fun, free multiplayer games will be enjoyed.
The game is currently in a working state, though it still needs more testing to iron out kinks. Anyone is welcome to come by and play though.
The comments section in this website has been having a bit of a crisis recently. What I'm referring to is the fact that 'bots' or something has been inserting hundreds of anonymous comments postings that generally link to porn or some other thing that I don't want. My brother has solved the problem by putting a randomly generated string of alpha-numeric characters in an image that the user then has to type into a text field in order to post. Unfortunately, this week is my spring break and I'm feeling really lazy, so instead of that fairly decent solution, I've decided to not allow anonymous people to post. You now have to register an account in order to post. The good news is that you don't even have to put in your email address, just type in a name and that's it, you're done and you can join the bustling community of one that I have carefully been cultivating! Happy posting all!
The flip side of this is that passersby will probably be less inclined to post, but that is a tradeoff I'm willing to make in the name of "security".
The flip side of this is that passersby will probably be less inclined to post, but that is a tradeoff I'm willing to make in the name of "security".
I am currently working on a project for an affiliated marketing company, and parsing very large text files is a big part of the job. Previously, I have had little experience with parsing large text files and importing them into a database. However, this job has turned out to be quite rewarding and interesting in that regard. When I saw "large", I mean anywhere from 200KB to 25MB (that's about 45,000 rows of data). This is pretty big for me, though I'm sure there are people out there who have dealt with far more.
Now, parsing a 200KB is relatively easy, and one can usually get away with a relatively sloppy job. But when you have to import 45,000 rows into a database, you have to deal with some interesting problems. First I'll go over how I started out, and then I'll move onto where I've ended up.
There are three sources where I get these text files, and all three have slightly different formatting they and are each delimited differently. The contents of the files are various products, with descriptions, categories (and subcategories), keywords, prices, etc. So I upload the file and set it to be parsed, line by line..
$fd = fopen("file.txt", "r");
while(!feof($fd)){
$line = fgets($fd, 6000);
file_parse_line($line);
}
Each line is parsed like so...
function file_parse_line($line){
$query = mysql_query("select id from products where sku = '123'");
if(fetch = mysql_fetch_row($query)){
mysql_query("update products set blah....");
}
else{
mysql_query("insert products set blah....");
}
}
While this is sort of a psuedocode and not exactly what is going on, it is a rough approximation. It seems to work fine with a products table that is less than 5,000 rows, but more than that and it starts to bog down.
The reason seems to be that it is querying the mysql database for every row that is being parsed to see if it already exists in the database or not. If it exists, update it. If it doesn't, insert it. Needless to say, this takes a really long time when you have 50,000 rows in the database table.
My solution so far has been to create an array of all of the related products already in the database before I begin parsing the text file. Like so...
$query = mysql_query("select id, sku from products where feed_id = '123'");
while($fetch = mysql_fetch_row($query))
$products[$fetch[1]] = $fetch[0];
Then my new file_parse_line() looks like...
function file_parse_line($line){
global $products;
if($products[$this_sku])
mysql_query("update products set blah....");
else
mysql_query("insert products set blah....");
}
For a text file with 45,000 rows, this means I have to call 45,000 fewer "select" queries. So far it has worked quite well for reducing processing time. The only issue that might crop up is the size of the $products array. I will have to see if there is any limit to the size of an array. I do know that it can handle ~50,000 elements without any trouble, but I will keep my eye on it nonetheless.
Hopefully this post will be the first of several regarding programming topics. I know I always say that, but this time I mean it (right).
Now, parsing a 200KB is relatively easy, and one can usually get away with a relatively sloppy job. But when you have to import 45,000 rows into a database, you have to deal with some interesting problems. First I'll go over how I started out, and then I'll move onto where I've ended up.
There are three sources where I get these text files, and all three have slightly different formatting they and are each delimited differently. The contents of the files are various products, with descriptions, categories (and subcategories), keywords, prices, etc. So I upload the file and set it to be parsed, line by line..
$fd = fopen("file.txt", "r");
while(!feof($fd)){
$line = fgets($fd, 6000);
file_parse_line($line);
}
Each line is parsed like so...
function file_parse_line($line){
$query = mysql_query("select id from products where sku = '123'");
if(fetch = mysql_fetch_row($query)){
mysql_query("update products set blah....");
}
else{
mysql_query("insert products set blah....");
}
}
While this is sort of a psuedocode and not exactly what is going on, it is a rough approximation. It seems to work fine with a products table that is less than 5,000 rows, but more than that and it starts to bog down.
The reason seems to be that it is querying the mysql database for every row that is being parsed to see if it already exists in the database or not. If it exists, update it. If it doesn't, insert it. Needless to say, this takes a really long time when you have 50,000 rows in the database table.
My solution so far has been to create an array of all of the related products already in the database before I begin parsing the text file. Like so...
$query = mysql_query("select id, sku from products where feed_id = '123'");
while($fetch = mysql_fetch_row($query))
$products[$fetch[1]] = $fetch[0];
Then my new file_parse_line() looks like...
function file_parse_line($line){
global $products;
if($products[$this_sku])
mysql_query("update products set blah....");
else
mysql_query("insert products set blah....");
}
For a text file with 45,000 rows, this means I have to call 45,000 fewer "select" queries. So far it has worked quite well for reducing processing time. The only issue that might crop up is the size of the $products array. I will have to see if there is any limit to the size of an array. I do know that it can handle ~50,000 elements without any trouble, but I will keep my eye on it nonetheless.
Hopefully this post will be the first of several regarding programming topics. I know I always say that, but this time I mean it (right).
This does not happen to me very often. I've been recently putting together some AJAX code for one of my programming projects, and have so far found an irritating bug, and a nasty gotcha.
First the irritant.
I was setting up a form that had two text boxes, and one drop down menu. Now, the idea was to have a person enter some value into one or the other of the two text boxes, and when they clicked away from it, the drop down menu would automatically select some option based on another value from my database. It seemed simple enough. I used the onBlur method in both of the textfields, and told it to call a function that used AJAX to get some value. When I first coded it out, I decided to alert() the responseText value to see how it worked. Lo and behold, when I ran the script, the alert box came up like I expected. However, when I clicked "OK", a new box appeared immediately spouting the same value. I wasn't able to get out of it until I went into the Task Manager and manually ended the process. All of this is happening on a machine with Windows 2000 and Firefox 1.5.0.3, by the way.
After looking things over to make sure everything was alright, I decided to try it in Internet Explorer. I didn't have the same issue, it only happened in Firefox! I also looked at the Javascript Console, and happened upon this nasty looking error message that consisted of XUL element sand selectedIndex stuff and more.
I did some searching on Google and someone mentioned putting autocomplete="OFF" into the text box code. This didn't have any affect. I then decided to try onChange instead of onBlur, which for some reason worked just fine. As a note, I later changed the field from onChange to onKeyUp so that when a user entered a number in, it would immediately make the calculations.
The second bug turned out to be much nastier. This is an IE-only bug, and I believe it is restricted to IE 6.0.2800 (and possibly higher), though I did not test any other versions. The problem arose when I tried to spit out an alert() of the same text that I tried to alert() at the beginning. My code seemed fine, indeed, I went through it with a fine-tooth comb to see what I had done wrong. Looking at the javascript error dialog wasn't much help, as all it said was "System error: -1072896658". After some agonizing and some google searching (look for "xmlhttprequest System error 1072896658"), I finally found some helpful information. The problem turned out to be that I had to manually set the character set to "UTF-8" in the PHP file that AJAX was calling. Here is the line I put in my PHP file: header("Content-Type: text/plain; charset=UTF-8");. It worked, and after that the IE bug disappeared.
First the irritant.
I was setting up a form that had two text boxes, and one drop down menu. Now, the idea was to have a person enter some value into one or the other of the two text boxes, and when they clicked away from it, the drop down menu would automatically select some option based on another value from my database. It seemed simple enough. I used the onBlur method in both of the textfields, and told it to call a function that used AJAX to get some value. When I first coded it out, I decided to alert() the responseText value to see how it worked. Lo and behold, when I ran the script, the alert box came up like I expected. However, when I clicked "OK", a new box appeared immediately spouting the same value. I wasn't able to get out of it until I went into the Task Manager and manually ended the process. All of this is happening on a machine with Windows 2000 and Firefox 1.5.0.3, by the way.
After looking things over to make sure everything was alright, I decided to try it in Internet Explorer. I didn't have the same issue, it only happened in Firefox! I also looked at the Javascript Console, and happened upon this nasty looking error message that consisted of XUL element sand selectedIndex stuff and more.
I did some searching on Google and someone mentioned putting autocomplete="OFF" into the text box code. This didn't have any affect. I then decided to try onChange instead of onBlur, which for some reason worked just fine. As a note, I later changed the field from onChange to onKeyUp so that when a user entered a number in, it would immediately make the calculations.
The second bug turned out to be much nastier. This is an IE-only bug, and I believe it is restricted to IE 6.0.2800 (and possibly higher), though I did not test any other versions. The problem arose when I tried to spit out an alert() of the same text that I tried to alert() at the beginning. My code seemed fine, indeed, I went through it with a fine-tooth comb to see what I had done wrong. Looking at the javascript error dialog wasn't much help, as all it said was "System error: -1072896658". After some agonizing and some google searching (look for "xmlhttprequest System error 1072896658"), I finally found some helpful information. The problem turned out to be that I had to manually set the character set to "UTF-8" in the PHP file that AJAX was calling. Here is the line I put in my PHP file: header("Content-Type: text/plain; charset=UTF-8");. It worked, and after that the IE bug disappeared.
I haven't been on here in quite a while. Probably over a month. I've been considering a renewed interest in this site recently, possibly to post my resume and some other job related stuff, and maybe more pictures stuff. We'll have to see how that goes. Right now I'm just procrastinating doing some real work. Ho hum...
I just got my wisdom teeth out, two of them a few weeks ago, and two of them yesterday. Believe me when I say this, it sucks. My teeth and jaw are hurting like hell, and straining my muscles so much in the chair yesterday has me tired and sore today (nobody told me vitamin C/orange juice messed with novacaine..ouch)
I haven't done much on the site since forever, but I was really bored tonight and decided to make a post. Don't expect me to make a habit of it!
I'm deciding whether or not to renew my domain registration. It is around $14 for two years, which I suppose isn't such a large amount. On the other hand, I haven't done anything with this space in many months. I still have another month or two to decide. I guess if you have trouble getting here in another month or two, you'll know what choice I've made!
I haven't done much on the site since forever, but I was really bored tonight and decided to make a post. Don't expect me to make a habit of it!
I'm deciding whether or not to renew my domain registration. It is around $14 for two years, which I suppose isn't such a large amount. On the other hand, I haven't done anything with this space in many months. I still have another month or two to decide. I guess if you have trouble getting here in another month or two, you'll know what choice I've made!
Cookies go to you if you recognize the source of that title!
I've been hiding out in the DC area for the past three weeks or so, alternatively going on adventures and then doing nothing for long stretches of time. I received my wireless router about two weeks ago, and since then have been online, but I just haven't been interested in website stuff. I'm still not really, but this is one of those somewhat boring days where the day passes ever so slowly and none of it is of any interest.
I've been hiding out in the DC area for the past three weeks or so, alternatively going on adventures and then doing nothing for long stretches of time. I received my wireless router about two weeks ago, and since then have been online, but I just haven't been interested in website stuff. I'm still not really, but this is one of those somewhat boring days where the day passes ever so slowly and none of it is of any interest.
So my evil plans to become a vagrant are finally coming to fruition. What I mean by this is that I'm headed down to Washington DC on Monday to spend a couple months living aimlessly. I'll still have my web development work to keep me entertained, but for the most part I will just be doing handyman type stuff around my aunt/uncle's house.
I was going to write some big long post about my plans, but I don't really have any big plans, and I don't feel much like writing :) OK just a little bit.
I'm ordering a cheap wireless router so I can use my laptop anywhere around the house, and I just got my EZPass in the mail today!
Oh man, my brain isn't working today. I think I got too much sun.
I was going to write some big long post about my plans, but I don't really have any big plans, and I don't feel much like writing :) OK just a little bit.
I'm ordering a cheap wireless router so I can use my laptop anywhere around the house, and I just got my EZPass in the mail today!
Oh man, my brain isn't working today. I think I got too much sun.
I don't really have a whole lot to say today, however I did want to share this with everyone. It's an "abridged" version of the Revenge of the Sith script, and it makes fun of the movie. It pretty much nailed the movie perfectly and I couldn't stop laughing.
---
In real life stuff, I got my car back on the road and fixed all the annoying little electrical problems it was having (sort of). Now I'm just sort of hanging out at home doing various things to pass the time.
Less than a week until my trip to DC!
Update: New drawing up! Finally :)
---
In real life stuff, I got my car back on the road and fixed all the annoying little electrical problems it was having (sort of). Now I'm just sort of hanging out at home doing various things to pass the time.
Less than a week until my trip to DC!
Update: New drawing up! Finally :)
I don't have a camera to post cool pictures quite yet, but I put together a little photography gallery today. It works much like the drawings section. Indeed, I reused the drawings gallery code for the photo gallery, and pretty much left it untouched. The only difference between the two is that the photography gallery is broken up into folders/groups of similar pictures, while the drawings are just all bunched together. This may change in the future, with drawings getting folders, but as of yet there aren't really enough drawings to justify that.
I say curses to the weather we're having this week. I want to go outside and do summer things, but I can't even go out without a coat or sweater! Pshaw.
I say curses to the weather we're having this week. I want to go outside and do summer things, but I can't even go out without a coat or sweater! Pshaw.