Monday, November 24, 2008

Programing Jokes

another "off topic" post (there isn't anything about any program/project anyone is working on)

anyway i came across this list of programing jokes. i don't want to take any credit for it so here is the link.
http://stackoverflow.com/questions/234075/programmer-jokes-whats-your-best-one

however my two favorite jokes are:

so this programmer goes out on a date with a hot chick

     and

Q: how many Apple programmers does it take to change a light bulb?

A: none, they just make darkness a standard and tell everyone "this behavior is by design"

Thursday, September 11, 2008

HTTP/Socket 3

I had been working on a project, the chain browser mentioned before, and i went back to polish up the socket portion of it. The problem i faced was i would get the right data back from a server but there would be a delay on the last recv() that slowed everything down to a crawl. Initially i discovered that id i put a Shutdown() after i sent the data i would get back the data quickly without that delay. But this was unpredictable because sometimes i wouldn't get anything. So i had to remove it to retain predictability. So after some more studying i learned about using select() to delay the program till there was data ready to recv(). However using select didn't really seem to do much and it wasn't till I added in ioctlsocket(FIONREAD) (or just ioctl() if your using Berkly sockets). the trick was putting the ioctlsocket() in the right spot. At first it would return 0 bytes which meant that there was 0 bytes ready to recv(), which wasn't accurate. the key is to wait with select till there is data available, then figure out how much with ioctlsocket(FIONREAD), and lastly recv() but only the amount of bytes you get from the ioctlsocket(). After playing around with it for a little it worked great about 99% of the time. The socket library is very well documented but how to use it all together isn't. Not to mention there are hundreds of different types of applications using sockets and they all using them differently. whats even worse is that protocols like http use sockets differently throughout the protocol itself.
Lastly i posted a a file, something like Socket.cpp and Socket.h for an example. if you have any questions just email me or leave a comment. also consider that those files are part of a larger project. While i haven't posted an up to date versoin of that project you should be able to plug the "socket files" into one of the other projects i have posted.

Tuesday, September 9, 2008

Chain Browser, AutoBrowser, WebBrowsing made easy with "Botnets" and webcrawlers

This is something i have been working on for a bit and have been posting parts of on for while.
The concept for this project is... well let me back up and explain where the idea came from. Imagine that you check your email 10 times a day and you check your facebook 5 times a day. However both are only updated twice a day so you end up do a lot more checking then necessary. So imaging you have a browser that checks your sites for you and tells you how much has changed since you last checked yourself. this browser you also be able to do things that no current browser can do as well. For example say you wanted to request everyone to be your friend on facebook, well by using a conventional browser this would take forever but you would notice a pattern to how you request everyone. this would be easy for a program to do and quickly.

Monday, July 14, 2008

Legal C++

who = !me?!you?!us:you:!you?me:us;

What is also "cool" is that if you and me are boolean and us is an integer that equals 2 then it returns the number of people involved as well.

Also a cool example i pulled off wikipedia.org.

_(__,___,____){___/__<=1?_(__,___+1,____):!(___%__)?_(__,___+1,0):___%__==___/ __&&!____?(printf("%d\t",___/__),_(__,___+1,0)):___%__>1&&___%__<___/__?_(__,1+>2*b || !(2*b)

float myBoat;
long schlong;
short stuff;
int eresting;

Tuesday, July 1, 2008

HTTP/Socket 2

I again updated the source for the HTTP/Socket "library" i will need for a few projects of mine. By the way for any readers that may have been noticing that the source for certain projects are being updated and changed and would like to see previous versions are more than welcome request them (and i wont turn down such a request).
The most notable addition is that the HTTP class is a part of a broader "webpage" class. the webpage class performs actions based on the response of the HTTP request; such as caching the cookies, and getting the page resources (like images). i also did some work on the foundation. I went back and improved the socket class, however there are still some issues.
The biggest issue I'm having and AM DYING FOR SOME FEEDBACK, is that after I've received all the data there is a waiting time/delay. I don't understand exactly what I'm doing wrong, as i would prefer to just send my data, receive the servers data and close the connection as quick as possible. I did some studying on the web and one answer i found was to use the "shutdown(socket,SD_SEND)" function. HOWEVER this seems to only 50% fix the problem because when using shutdown sometimes i receive 0 bytes back and worse yet its not consistent, so i conjecture as to what the exact problem is. ANY HELP WOULD BE HOT.
Anyway i would check out the source its not to shabby. The next step is going to be the cool one, but the one that will require the most precoding thinking/planning. The next step is to implment the interactions from one site to the next.

Friday, June 13, 2008

HTTP/Socket 1

I finally posted updated source code for the HTTP and socket projects (particularly the web crawler). The code is pretty solid, i think there is a good amount of error handling... but i could be wrong and would appreciated being to sold (and why). It's late so I'm not going to describe what is going on in the code, just take a look for your self. I will, however, describe what it does/can do. It can send GET and POST requests to servers. In addition requests can be encrypted via ssl (i used openSSl so props to them). This means that you can GET and POST from servers using "HTTPS". One should also notice how easy it is to send requests. you pretty much need to define a URL as a string and then send it and you get the response back. Lastly i compiled this on DEV C++ and had to find a special DEV C++ package to get the ssl code to work. you can either head on over to the openSSL site and figure out what you need to do to make it work (it is document pretty well) or search around for the package, try this site.

Tuesday, June 10, 2008

Web Crawler (HTTP) 2

I have worked on the web crawler a considerable amount since i last posted on it. I have even gone as far as to implement ssl (for https). The Project is moving in forward in a positive direction. One compliant i have is the code is getting a bit jumbled, something I'll have to tidy up before i update the source code link.
The newest improvements are:separate handling for the HTTP requested and the addition of ssl. It works well enough that i can get my email. it still is console based and will probably not see any real GUI usage until an "official" release.
The main reason that i have not/will not release the updated source is that i need to clean up some personal information that was used for testing. I plan to work it up some more and then will provide the source.

Thursday, May 29, 2008

Bitmap Loading 1

After hours of aggravation with the Bitmap file format l thought discussing it might be helpful. Perhaps tho most confusing part is the extra bytes added on the end of each Line. The width of each line must be divisible by 4. Also the image is flipped vertically, but not horizontally. I think each rgb value is reversed. check out the source for implementation details.

Tuesday, May 27, 2008

Web Crawler (HTTP) 1

I have been wanting to work on a Web crawler, a program that will go to site automatically and gather information, for quite some time now. There area a number of other projects i want to have it implemented in, but first i need some solid code for the HTTP and socket/TCP part of it. In the Socket (.zip) link you'll find some code that implements a VERY basic socket class. the idea is to incorporate a separate HTTP request class and have the two work together. I ran into some snags, but it works... for now. I need to make it improve the Receive function and build the HTTP request class. Any suggestions just comment or email me. And Btw I'm using some (a very small amount) of code from someone else, I'm not sure who but they deserve some credit (as well as i do if you choose to use this code).

Saturday, May 24, 2008

The Future 1

Plans for discussion and projects i want to work on during the summer.
-A web crawler program, i need to develop some http code that will crawl sites to gather certain data or perform certain online actions. I haven't really discussed this much except for the AI project.
-I also plan to start on the AI conversation project. i will need the web crawler for this so I'll probably develop this second.
-I would also like to talk more about the decrypter and possibly clean the code up.
-I plan to also talk more about the 3D graphics project but only briefly.

Frequency 1

Since I talk about a frequency analyzer in about half of my projects i figured i would single it out and talk about it. Since i am really tired I'll finish this post soon but for now just take a look at the source code.
Okay after some sleep i made this .gif that will hopefully show what I've been talking about. The frequency of the previous character for each letter is measured. this can also applied to sequences other than letters.

Tuesday, May 20, 2008

Decrypter 3

Diving deeper into the decrypter there are some interesting things one could notice. As said before the decrypter analyses the character frequency of a file before solving the encrypted file. When solving the more "previous characters" (i.e. for lunch zero through 3 previous characters: "h", "c'h", "nc'h", "unc'h") analysied the faster and more accurate it will solve. However if too many previous characters are used it wont work. Additionally i think that this program is extremely simaler to a backtracking sudoku solver. If you replace the number 0 through 9 with the frequencies and instead of checking the rows, columns, and indivudal squares you instead check if the last bit you added to your guess exicts in the english language then you have the decrypter. In fact you could probably modify the decrypter's check function (in Guess class) then change the encyrpted file to something like "01234567890123456789 ... 0123456789" (9 sets of zero through 9) and change the file that the frequencies are reading from to "0123456789" (and use zero previous characters), add the givens and it should work.

For any of you who have tried out the decrypter source code (and i know that as I'm typing this no one has) you may run into some bugs and or noticed it can be very slow. I'll take some time to mention why this is and what i plan to do to improve the speed. As far as bugs are concerined a am not aware of any reasons why, other than spectulations, but i do know at least one exicts.

some of the bugs and or reasons that it slow:

1. First known bug is that when it begins to solve there is a possiblity (very,very small that it will blow up). I have no idea why this happened but I didn't persue that individual bug but rather some others, this bug i guess is kind of a left over im not to worried about.
2. right now the source code is set to calculate zero->n previous characters. This is completely unnecessary and is actually a result of me not designing my software well. The result of having the decrypt er use the previous character from zero to n causes it to check the ever single possibility using the previous character up until n in which it only checks the frequencies necessary. Although that last statement may sound bad (or just confusing) it should be noted that doing it this really only creates dramatic slow down when generating the frequencies.
3. lastly is that it requires a extremely large file for the frequencies. the 900 KB file when opened in Word was ~250 pages long. This also causes the program a ridiculous amount of time to create the frequencies.
4. the last problem is that it confuses punctuation. it may produce the right answer but with like commas instead of periods, this isn't that big a deal.


Overall with the bugs and slowdown i still think that using this to solve a cryptogram in the newspaper is worth it. I solved one in about 15 minutes with my 2.16 GHZ processer working at 50%. I did need about 1.1-1.3 GB of RAM though, so watch out if you are using less than 2GB of RAM (what i have).

Monday, May 19, 2008

3D Graphics 1

Today I'm going to move else where. This project displays 3d boxes in 3-point perspective, or at least the edges as lines. This program does not use matrices to display the box. I have little knowledge about how the 3d graphics with matrices work but this uses a much simpler method. This idea came about from a bunch of drawings i had done. I'm having some difficulty explaining the idea so take a look at this picture as reference. As you can see there are three perspective points and a center point. The way i draw just the box/cube is by using the intersections of the the perspective points and points that are on the lines that connect the center point and the perspective points (the red lines). The calculations involved are all relatively simply and include intersections of lines and finding a point a the x% of a line (ie. 50% would be the midpoint and 75% would be between the midpoint and a endpoint). The program uses a line drawing function similar to that of Bresenham's line algorithm but is buggy and wont draw a vertical line (any suggestions or links would be helpful). I doubt that this is A. an efficient way to draw 3d objects or B. that has any potential for any graphical use. With that being said don't get excited over this however it may have potential with devises that aren't capable of fully rendering 3d objects but need simple shapes. also note that it wouldn't be difficult to map a texture to this box. Since all the points are calculated it would be simple to map a texture by using Bresenham's algorithm on a bitmap. Any thoughts on this would be appreciated but i don't think I'm going to pursue this any time soon. the source code is for a program that will just draw out the 3d box. it is setup so that it draws a box where ever the user clicks. It always crashes on my laptop after a little less than a minute so any suggestions on how to fix than would be cool. As always source code is for free use as long as proper credit is given to me and anyone else i borrowed code or ideas from, in this case Bresenham.

Sunday, May 18, 2008

Wav Creater 1

I want to create a program that uses the frequency analyzer but instead it reads in a number of .wav files (music files) and then randomly out puts new music. The process of creating the frequencies is the same as described below. Then it groups the frequencies together based on similar previous characters but it would instead pick a random one using the frequencies as the probability for being picked. I think it would create some interesting music and, if it works as well as i hope, it would sound similar to different kinds of music but different all together... hopefully. I'm not going to post any code for this for a bit until I work out the frequency code a bit better. Also i have no idea how .wav files are formated (replies with helpful links would be appreciated).

Decrypter 2

As you can see to the left i have put up a link for the source code. it was compiled using DevC++, my personal favorite compiler. if you have any questions just ask. And please feel free to use the source code for any means (other than something malicious) *but i do ask that you give proper credit*. I use it for solving the cryptograms (cryptoquotes or cryptoquips, w/e) in the newspaper.

Saturday, May 17, 2008

Decrypter 1

This Decrypter is something i have been working on for a couple of weeks now, on and off. As mentioned before, it's almost finished and just needs some polishing. But before I explain what needs to be done to finish it I'll first go over the nuts and bolts. **Please note that this program is not intended for ANY malicious activities, I use this for solving the cryptograms in the newspaper.**
People seem to have a hard time understanding this program so I'm going to go into the details first then zoom out to the overall picture. First we must understand the frequency calculator. The program first calculates a bunch of frequencies from a really big file. The file is ~900 KB large and is filed with text from books. The program then calculates the frequencies based on this file by taking each character and the characters previous to it.
For example in the sentence:
"Dave Doesn't Dance Daily."
The frequencies would be:
"D'a", "a'v", "v'e", "e' ", " 'D", "D'o", "o'e", "e's", "s'n", "n'", "'t", "t' ", " 'D", "D'a", "a'n", "n'c", "c'e", "e' ", " 'D", "D'a", "a'i", "i'l", "l'y"
if you notice "Da" appears 3 times and " D" appears 3 times. Also notice that "e" is preceded by "v", "o", and "c". So if you see a "e" then there is a 33% chance that there was a "v" before it. Likewise if you see a "D" there is 75% chance that a "a" is after it and a "25%" chance that a "o" follows it. This is only using one previous character if there was two previous characters it would look like this "Dav", "ave", and "ve "... Three characters would look like this "Dave", "ave ", and "ve D"...
So hopefully you can see how this would apply to a larger file with more text. I plan on adding a program that shows how the frequencies of a file can are calculated like this.

With the frequencies we can now attempt to solve the encrypted item. First we need to group all the frequencies together. For example we a group would be all the letters that are preceded by a "D" like "Da" and "Do". Then we need to construct a guess. We add the parts last letter of a frequency like the "a" or "o" and we pick them passed on the last letters we guessed in the guess, like the "D". After this we fill in the rest of the encrypted item with the part we just guessed. Then we have to check the newly add part. Remember that we don't need to check the previous letters in the guess because they will be from a frequency but all the parts afterwards because they may not for a guess. We need to check the guess using the frequencies. if a part of the guess is not in the frequencies then it isn't a valid possibility and we shouldn't go any further with that guess. But if every thing checks out we need to do the same process with the new guess.

This may not be explained the best and hopefully I'll put up a pseudocode algorithm for this program. The pseudocode may clear up things with this above "understanding". Any questions just post and I'll try to respond. Please also understand that this is a brief, poor explanation.

Beginning

I plan to add a number of development projects. I hope that people can learn, enjoy, and leave feedback for all of projects. The first i plan to add is a decrypter that i have been working on. Its 90% finished, and actually does work, but needs some polishing.