216 colors that don’t REALLY matter any more

This table is now only good for a quick lookup of colors. For a few short years it was known as the WebSafe 216 colors. These were the colors that you were suposed to use on your website in order to GUARANTEE that your site would look exactly the same on every computer and with every browser out there. These colors were invented when everybody was only using 256 color monitors. And most monitors and video cards did not allow you to adjust the RGB values. Now however, because no one surfs in 256 color mode any more and everyones monitor contrast is set differently anyway, this color scheme is relatively useles as far as websites are concerned. That said, people STILL try to promote its use and if you are reading this article, now archived, someone probably told you the same thing.

Don’t listen. Make your site plain and simple. If you are using colors that MUST be displayed exactly right for your text to be readable, then you are doing something wrong. Contrast, to a certain extent, is a good thing.

Others, like me, might just want to look up some colors in HEX because you don’t know their official web color names. That’s why this has got a spot in the code cave. If I need a number, I follow the link at the end of this post…

BTW Color names are a myth too. I know there’s a wonderful page out there that has all sorts of colors that work in IE and some other browsers, Colors like “Dark Orange” or “Silver dew on yellow marigolds”, but that’s all a myth too. There are only 16 official web color names. Anything else is added on by the browser’s developers and who knows what color you’ll get if Use hex instead of any color name that is not: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, or yellow.

The 216 Web safe pallete color lookup table can be found here.

Now, go add some color to your life!

“URL vs. URI” = “Caving vs. Spelunking”

aka “URL vs. URI vs. URN”
aka “What does URL stand for?”
aka “What is a URI?”
aka “What is a URN?”

A little bit ago I decided to get to the bottom of the why WordPress (and I think VBulletin) refer to URIs rather than URLs.

And it turns out that the answer is Sociology and Peer Pressure.

See, we all have the need to feel cool and knowledgeable. I suffer from this same affliction. I, too, am a self-proclaimed sciolist (look it up).

It’s a character trait/flaw I have and it is probably one of the reason I have this blog. We all want to better ourselves and get patted on the back for it. It’s human nature.

One place that this can be prominently seen is the caving world. (And YES this does related back to URL vs. URI. just be patient…) When someone first takes you caving, and you like it, you tell all of your friends about visiting a cave. If you do it a few more times, you’ll quickly label yourself a “caver”.

At that point, the caver often starts to do some reading and learns that (“ooooo!”) the scientific term is called spelunking. So, you start calling yourself a Spelunker and talking about how you so enjoy spelunking that you spelunk every chance you get and you’re a guru spelunker because you know the $10 word.

Well, as it turns out, caving by any other name does not smell so sweet. (That phrase works so much better for roses…).

Anyone with a lot of caving experience, who isn’t writing journals that have to sound pretentious in order to get funding, does not call the activity spelunking. Those that do it all the time, the dedicated hobbyists and professionals alike, don’t go spelunking. They are once again going caving. Why? Because spelunking is the word used by relatively new cave geeks.

I’ve got the impression that this whole URL vs. URI thing is following the same pattern. Only this time, URI is the term used by relatively new PHP geeks.

Here’s the low down in one sentence – URI (Uniform Resource Identifiers) are divided into two categories: URLs (Uniform Resource Locations) that describe the location of a something, and URNs (Uniform Resource Names) that identify something but don’t specify the location or method to get to it.

So, what has happened is that in the growing world of PHP whiz kids and Web 2.0 excitement where EVERYONE knows what an URL, someone learned that a URL is really just a type of URI. SO the blogged about a something using the term URI in big fancy sentences. People saw that and then said “oooo, I’m cool too! I’m gonna call these things URIs.” “URL? That’s so Web 1.0 of you!”

Back in the real world, one can almost guarantee that EVERY field you fill in, that asks for a “URI”, is asking for an address not an identifier. It’s asking for a location: a URL.

What we have in the self propogating blogosphere is all of the blogs, CMS sites, open source and public domain projects that are supported by weekend warrior coders referring to URIs because it was deemed by someone to be more correct. Meanwhile, all professionally developed products will ask for URLs. That’s because professionals know that they REALLY want to have a URL and not a URN.

They know asking for a URI is wrong if you cannot accept a URN.

They additionally know one more thing through experience. The professional DOES NOT want to make the user think. If the user has to stop their process (filling in a form or whatever) and ask themselves what the software expects them to do, the developer has failed.


Now, you might be asking yourself: OK, great – at the start of this I just wanted to know what a URI is, now what the heck is a URN????

I’ll answer that, but if you want it in geek speak, look here:

faqs.org
W3

If you want it in plainer English read on, for it is really easier to see it in examples. I can find no other place on the entire net that explains it in the detail I plan to here, so I hope this is helpful.

What is a URI? A Uniform Resource Identifier (URI) is a standardized way to explain the name and/or location name of a resource.

What is a Resource? A resource is a collection of information in any form. It could be a website. It could be a blog. It could be your mother’s 1953 Betty Crocker Cook Book. It could even be this post you are reading now. A resource does NOT have to be related to computers.

There are two types of Uniform Resource Identifier (URI): URLs and URNs.
The first type I’ll cover is the easy one: the URL. We all know that URLs are used to point to a location on the internet. What you may not also realize is that as they are telling you where on the interenet something is, they also tell your computer the method that must be used to reach that location. That’s the “http://” or “ftp://” part of an URL. It’s the part of the URL called a “scheme”.

Here are some examples of URLS with schemes:

ftp://ftp.idsoftware.com/idstuff/quake3/source/Q3A_TA_GameSource_132.exe
gopher://marvel.loc.gov/11/locis
http://www.TheCodeCave.com
mailto:Brian@thecodecave.com
news:alt.caving
telnet://melvyl.ucop.edu/

The Uniform Resource Name (URN) is the second, less common type of URI. Basically a URN is a unique code that identifies a resource. That code will ALWAYS identify the resource even after that resource no longer is available. It does not tell you where you can find that resource. It doesn’t mean that there is only one of that resource available. But if a URI is identified in a document, the reader will know EXACTLY what the author was discussing. Specification documents often have a URN. If I refer to RFC 2648, that has specific meaning. It refers to a specific “Request For Comment” held by “The Internet Society” (I’m sure I have their card in my Illuminati card deck…). If I want to put that reference in the form of an URN, that would be: urn:ietf:rfc:2648

There is a very short list of official URNs. They are:
URNs: Official (according to the RFCs):

‘ietf’, defined by [RFC 2648], URN Namespace for IETF Documents
‘pin’, defined by [RFC 3043], The Network Solutions Personal Internet Name (PIN): A URN Namespace for People and Organizations
‘issn’ defined by [RFC 3043], Using The ISSN as URN within an ISSN-URN Namespace
‘oid’ defined by [RFC 3061], A URN Namespace of Object Identifiers
‘newsml’ defined by [RFC 3085], URN Namespace for NewsML Resources
‘oasis’ defined by [RFC 3121], A URN Namespace for OASIS
‘xmlorg’ defined by [RFC 3120], A URN Namespace for XML.org
‘publicid’ defined by [RFC 3151], A URN Namespace for Public Identifiers

You may not have heard of any of those. However, there are a large number of unofficial or pending URNs that you will have heard of.

ISBN – The International Standard Book Number (http://en.wikipedia.org/wiki/ISBN) allows you to identify a book with an URN. I’ll show the URN first and then a url to get information about that resource.

Here are some example ISBN:

URN:ISBN: 1-5562-2637-3 identifies this book (not the website) Advanced Graphics and Game Programming in Delphi
URN:ISBN:1-5920-0733-3 identifies this book (not the site): Advanced 3d Game programming All in One

Digital Object Identifier (DOI) Read about this one here: http://www.doi.org/ and here: http://en.wikipedia.org/wiki/Digital_object_identifier

ALEXA’s ASIN: Amazon has its own code that will probably never become an officially adopted URN, however it is common on the internet as it is now used to rate websites through Alexa. ASIN stands for Amazon Standard Identification Number. Almost every product on our site has its own ASIN–a unique code we use to identify it. For books, the ASIN is the same as the ISBN number, but for all other products a new ASIN is created when the item is uploaded to our catalogue. Read more: http://en.wikipedia.org/wiki/ASIN &
What is an ASIN?

Here are some example ASIN:

URN:ASIN:B000F2CVYG
URI that is an the URL containing the URN: in this link
URN:ASIN:B000F1J35C
URI that is an the URL containing the URN: in this link

Did you know that songs also have unofficial URNs:

ISRC International Standard Recording Code
ISRC:USPR37300012 – The song “Love’s Theme”, from US’s “The Love Unlimited Orchestra”.
ISRC:BRBMG0300729 – The song “Enquanto Houver Sol”, from the Brazilian group “Titãs”

I think that should make it all clear, but feel free to ask any question you might in the comments. And if you use this info anywhere, please refer back to The Code Cave.


So, back to WordPress and it’s prompt for a URI. It should be clear at this point that when it is asking for the “WordPress address (URI):”. It will not and DOES not accept any old URI. In fact, it will ONLY accept an URL. And THAT’S what it should ask for. But then we wouldn’t have thousands of people blogging about the differences between a URL and a URI would we?

The other Code Cave

Greetz!

This is a support article for my (soon-to-be) new About page. It explains one meaning of a “Code Cave”. It also shows you how to use a Code Cave that was left in Notepad to hack in some new functionality.

You can (soon EDIT: OK, I guess I lied -b) see the about page for an even better description of a Code Cave. I’ll summarize here by saying that taking advantage of a code cave is just one method commonly used by gamers to get past anti-cheat/PunkBuster measures in multiplayer games like Quake I-IV, Return to Castle Wolfenstein, Call of Duty and others.

This site is not going to get into hacking very much. I’ll probably just explain a few website vulnerabilities, just because they are cool and the fact that other sites published them has taught me how to write good code – and that IS a subject covered by this site. So, here is the OTHER meaning of a Code Cave and why I get some stray hits from people searching Google for hacking tools!

NOTE: if you do look for original versions of this article, be aware that:

  • it is full of MS html spam
  • the files it links to are infected with a virus
  • I also censored the language so I could keep my General Audience/Safe for kids rating on my site.
  • the files some how download from the link even though you hit cancel. I wouldn’t have believed it if I hadn’t seen it myself. I am CERTAIN I hit cancel because I didn’t get a save as dialog even though the infected file appeared in my internet cache.

That’s just a BIT bothersome. So, you might want to avoid it all together.

Continue reading The other Code Cave

How to: Creating a unique temporary file and determining the working drive and path

This is a demonstration of how to use a TempFile in a .BAT or .CMD file. The goal of this example is to determine the relative path of the current working directory and assign it to a variable.

Concepts Demonstrated:

  • Generating a unique file names
  • Creating a temp file, using the Windows Naming convetion, and deleting it when done
  • Calling support subroutines in a batch file
  • Using GOTO :EOF to end exit a subroutine but not the batch file
  • Use of the command line “FOR” routine
  • Using Variables with “for /F”
  • How to get the current directory
  • Verbose and Quiet modes for a batch file

Temporary files are incredibly useful in batch files. When used in combination with a “For” loop, you can accomplish some amazing stuff from the command line.

In this example we assign a new file name to the TEMPORARY_FILE variable and then export the current working path to that file by echoing cd environment variable to it:

call :GETTEMPNAME
echo %cd%>%TEMPORARY_FILE%

Once our temp file has contents, the For routine can be used to parse each line and execute a command with the result. So, we use the For command to divide the working directory, lets say it is “C:\WorkingDir” into several peices (aka tokens):

FOR /F “tokens=1* delims=:” %%G IN (%TEMPORARY_FILE%) DO set RelativePath=%%H

Literaly we are telling it to break the line up at every colon ( : ), and to assign the first token to the variable %G. The asterisk (*) indicates that each token after that should be assigned to a new variable letter (H,I,J, and etc.). In our example, our %H will contain “\WorkingDir”.

“For /F” is really most usefull with larger files containing multiple lines. Since our file contains only one line with two tokens, the process stops there but you could, for example, parse all the names of files in a directory (dir *.xyz /b > %TEMPORARY_FILE%), or the contents of a registry key exported to that file using (REG QUERY […] > %TEMPORARY_FILE%). I’ve used both of these methods in the past to do some really neat things that might have otherwise involved creating a custom executible. One advantage of doing it from teh command line is that it keeps the registry clean of all the garbage left behind by Windows anytime you run an exe.

Oh!

Something that is not often emphasized in “For /F” documentation is that it can parse variables as well as files. This could greatly optimize this example. Instead of parsing our file, we would simply put our %CD variable in quotes and call:

FOR /F “tokens=1* delims=:” %%G IN (“%CD%”) DO set RelativePath=%%H

We will get exactly the same results and can cut our batch file size in half! Of course, then we wouldn’t have a good example of temp file usage would we? So, we will do it the hard way.

Thus:
Continue reading How to: Creating a unique temporary file and determining the working drive and path

Binary Blue 1.1.0 Customizations & How to get your link categories to show..

The Count has done it again with another GREAT release of his theme Binary Blue. I thought I would share how I’ve customized it to fit my blog.

This version has several things fixed that I was looking for, including improved localization via a field in the options tab. I haven’t found all of the goodies yet. I haven’t even experimented with the widgets yet. But, I did need to get my customizations back into my blog.
Continue reading Binary Blue 1.1.0 Customizations & How to get your link categories to show..

Using Environment variables to load a file from My Pictures

It’s been a while since I used Environment Variables in Delphi and I had to look it up.

I have a loose rule that anything I have to look up, I want to share on my blog so that I can find it again easily later.

So here you have it: Enviromental Variable expansion ala Delphi.

It’s really not that complex, and it’s possible that this routine could be optimized some. But I think it works well enough as is and demonstrates the use of ExpandEnvironmentStrings quite nicely. If you need to get a list of the variables, you’ll need to do further research on GetEnvironmentStrings and FreeEnvironmentStrings to return the list to you for manipulation. A search for FreeEnvironmentStrings Delphi gives you pleanty of code examples.

Here is my example for ExpandEnvironmentStrings:

[delphi]
var
ImageFileName, FullFileName: string;
BufSize: Integer;
NewPath: String;
begin
// Retrieve the contents of the edit field into a local variable for ease of use.
ImageFileName := Edit1.Text;

// If it exists in the working path, use that as our retrieval point.
// Otherwise, look in the Application directory, then the My Pictures folder,
// then look in the Windows directory
if (FileExists(ImageFileName))
then FullFileName := ImageFileName // Working directory needs no path.
else if (FileExists(ExtractFilePath(Application.ExeName) + ImageFileName))
then FullFileName := ExtractFilePath(Application.ExeName) + ImageFileName // Grab the path from the application executible info
else begin

// Use environmental variables to locate two other possible places
// Allow 254 character paths to be returned.
SetLength(NewPath, 254);

// Call ExpandEnvironmentStrings with string containing environmental variables
BufSize := ExpandEnvironmentStrings(‘%userprofile%\My Documents\My Pictures\’, PChar(NewPath), 254);

// The returned BuffSize must be used to truncate off any extra garbage & injections.
SetLength(NewPath, BufSize – 1);

// Look for it and if it is found, assign the full name otherwise keep looking.
if (FileExists(NewPath + ImageFileName))
then FullFileName := NewPath + ImageFileName
else begin
// Repeat the above process for the Windows Directory.
SetLength(NewPath, 254);
BufSize := ExpandEnvironmentStrings(‘%windir%\’, PChar(NewPath), 254);
SetLength(NewPath, BufSize – 1);
if (FileExists(NewPath + ImageFileName))
then FullFileName := NewPath + ImageFileName
else FullFileName :=’NOT FOUND’;
end;
end;
[/delphi]

Treating a TImage’s loaded JPEG as a Bitmap in Delphi

One problem with the TImage component is that it doesn’t natively support JPegs. JPeg just wasn’t as popular a format back in the early to mid nineties when the Delphi was first developed. Well, today that is a different story. Starting with Delphi 3 , if memory serves (I didn’t every use D2), the TJPegImage component was introduced and the TImage could be extended to allow JPegs to be loaded. Today’s TImage component can load a JPeg straight from the LoadFromFile command. However, you still cannot directly manipulated it as easily as you can a BitMap. This is clear if you look at the structure of a TImage’s Picture property.

A TPicture has a BitMap property and a MetaFile property and a Graphic property that stores everything that isn’t a BitMap or a metafile.

Yet you’ll quickly see that very few routines and example on the web deal with the Graphic property. They can’t! The structure of the information in the Graphic varies depending upon the type of image.

So, the trick of dealing with JPegs, or anything else like TIFFs, GIFS or Targa’s (oh my), is to get their data uncompressed and de-interlaced and back over to the bitmap property. A little known fact is that this is exactly what Windows has to do any time you choose a JPEG as a background. Windows will load the JPEG save it to a BMP and write the name of that BMP to the registry and then display that file instead of the original JPEG. So, we all should quit blaming Borland (DevCo) for a klunky control, they are doing it the right low level way. And that’s, after all, what we like about Delphi right?

So, what we must do is once we allow a user to load a file, we will check to see if the type is a TJPegImage. If it is, then we create a TJPegImage component. We then assign the JPegImage to the BitMap property and we are done! You can now access the image data in the BitMap.

In Delphi, that looks like this:
[delphi]
SourceImage.Picture.LoadFromFile(FullFileName);
if (SourceImage.Picture.Graphic is TJPegImage)
then begin
JpegImage := TJpegImage.Create;
try
JpegImage.Assign(SourceImage.Picture.Graphic);
SourceImage.Picture.Bitmap.Assign(JpegImage);
finally
end;
FreeAndNil(JpegImage);
end;
[/delphi]

Assign is a wonderful little black box function built into many objects. Assign is one of the neatest functions in Delphi. It basically accepts other types of objects as a parameter, and converts as much of that type of object as possible.

Let’s go abstract and say you have two object types TCar and TSuitCase.
C: TCar
S: TSuitcase

Obviously can’t say S := C; or C := S; because they are of different types.
However you can say
C.Assign(S)
and inside the TCar’s Assign method have a statement that looks like:

[delphi]

if (Source is TSuitcase)
then Self.Trunk.Contents := Self.Trunk.Contents + TSuitcase(Source).Contents
else if (Source is TGasolinePump)
then …

[/delphi]

OK, that sounds pretty non-exciting, but it gets better! What if the type of object is unknown? A the TCar routine may know how to assign a TFordPerfect to itself because a TFordPerfect inherits from TCar, but a TCar is NOT going to know how to assign a TFordPrefect to itself now is it? That’s where AssignTo comes in…
[delphi]

if (Source is TSuitcase)
then Self.Trunk.Contents := Self.Trunk.Contents + TSuitcase(Source).Contents
else if (Source is TGasolinePump)
then Self.Tank.Contents := Self.Tank.Contents + TGasolinePump(Source).Gallons[1]
else Source.AssignTo(Self);

[/delphi]

AssignTo goes exactly the OPPOSITE direction. The person writing the new component than then create a routine that will allow his new component to the most common components that already exist. So following our example, TFordPrefect’s AssignTo routine might include something like this:

[delphi]

if (Dest is TCar)
then TCar(Dest).PassengerCompartment := TCar(Dest).PassengerCompartment + TPassenger(Self);

.
[/delphi]

Or in the case of a TJPegImage, the AssignTo method checks to the see if the Dest var is a TBitmap, and if it is, it goes through a long decompression and conversion routine to finally produce a true Device Independant bit map and write those raw bits into the Dest.

And that my friends is how our TImage component, that knows nothing about JPEG to Bitmap conversions gets the job done. It asks the TJPegImage AssignTo method to do all if its work for it.

You can now use the Picture.BitMap image as normal. The neat thing is that you can put those routines in your FormCreate method. So, TImages can be made to contain JPEGs at design time, making your EXE significantly smaller. And then it converts them, if appropriate, to BMPs at Runtime. It’s nice to save 600,000 of image space at next to no cost.

Kinda nifty eh?

(BTW if you are really ambitious, I’m sure you could write that routine above so that it checks to make sure the graphic isn’t a BMP, WMF or empty and then uses the class info routines to request the type of object and instationate a TPersistent variable to contain an object of that type. Then your routine can handle as a bitmap ANY image type you’ve extended your TImage to contain. More on extending TImages later…)

HELP!!! Retrieving the handle of the DLL’s owner -HOW?

I have written a DLL, It needs to access a control in the instance of the application that loaded it. So, I want to get the handle of the application that is currently using that DLL. Or said a different way, the handle of the application that has loaded that instance of the dll. Anyone know how to do this? Solutions in any (major) programming language are acceptible. I should be able to readily translate them to Delphi…

I am building an Maxthon plug-in that adds the missing search buttons from the Google tool bar (search site, search news groups, search images). It is easy enough to search through all windows and get the handle of the maxthon window and then find the value you’ve put in the Maxthon search box. But I want to be certain that I get the right value. I could give myself a unique GUID, search all parent windows till I find that unique GUID and then know that that parent window is my host, however, that seems a pain….

Any thoughts?

The Best Pinger/Update Services List for WordPress 2.02

After some fairly exaustive research and testing, I have come up with the following combined pinger list for WordPress. This took four or five other lists and eliminated duplicates and slow responders (from the US). Many lists contain entries that are already available through Ping-o-matic which goes out and pings the pingers. At the time of this post, this list will not produce any duplicates and will allow WordPress to complete its post before the standard browser will time out. This WILL increase the time it takes to post, however you do not need to wait for the browser to refresh itself. You can usually move on to do other things after the first second or two. At that point the post has been made to the DB and WordPress is off notifying the pingers and will continue that until it is done.

Here is the list of Update Services I use at my blogs:

http://rpc.pingomatic.com
http://1470.net/api/ping
http://bblog.com/ping.php
http://bulkfeeds.net/rpc
http://coreblog.org/ping/
http://xmlrpc.blogg.de

Put these in the “Update Services” field on the Options>Writing tab in your WordPress administrator control panel.