h1

The atom of a molecule ?

September 12, 2008

Well apparently my last post was a tad depressing for some folks. In an attempt to remedy the situation, and because it was stuck in my head for 3.5 minutes prior to me listening to something that could be describe as ‘music’ (as opposed to rhythmic babbling with trumpet), I want to review the so-called ‘song’ ‘Handlebars’ by the so-called band ‘Flobots’ (aka ‘Linkin Park – Musical Quality – meaningful lyrics – good taste + annoying trumpet’).

This amalgamation of 2 crappy mc’s, some out of work violist (really, a violist ? Not even a violinist…) and some ridiculously out of place ‘jazz’ trumpet player sounds exactly as bad as it sounds (that makes sense… trust me)

Anyway, they have this song, if you have had the radio on for more than 2 minutes in the past 4 months, you have probably heard it more than once, possibly more than more than once… maybe every four seconds. It may even be getting old. Its called ‘Handlebars’.

Now this may sound like an inane, happy-go-lucky song about mustaches. But alas, these untalented musicians couldn’t stop at being terrible in their craft, they had to invade the realm of politics. Now by invade I mean they charged the castle and drown in the moat. Anyway, the song sucks. There is really no nice things I could think of to say about it so I am just gonna tell you how I feel.

First off, the song makes no sense. The majority of the song is about being able to do stupid stuff like ride a bike with no handlebars and keep rhythm with no metronome (omg you’re in a band…). Then, in the middle, following some ridiculous trumpet solo that seems so out of place I thought my radio was broken, they go for Bush’s throat. And fall 10 miles short. Into a pit of poor diction, terrible science and a complete lack of understanding of World Issues. We split atoms to create atomic/nuclear/nucular explosions, molecules have very little to do with it. They don’t understand this. Assassination specifically applies to political figures… you can’t assassinate the common folk. Additionally, lacerations are generally minor. You don’t die from them. The song makes no sense. Its ridiculous. Its off-topic, It rhymes words with themselves and nothing else. It has unfitting trumpet solos…. I could go on.

In conclusion: Flobots are not my favorite band.

h1

Redirecting using php

August 15, 2008

I was looking around today for ways to redirect the browser window, and I found a few interesting ones that may come in handy.

There is the standard way of sending the Header with a new location. This will immediately redirect the browser, meaning the redirect page is never seen. This can be a useful way for preventing unauthorized users from getting to a page you don’t want them to view (you should definately use die() or exit() to kill the script though, in case the redirect fails, and so that no data will be changed).
Header('Location:');

Note that Headers MUST be sent before any other data. Meaning that if you want to send headers it needs to be before any html or output (echo, printf ect).

The different, and more interesting, way that I discovered today is using Header to do a delayed redirect.
Header('refresh: 5, url="page.php"');

The number is the number of seconds before the refresh, and the url is the page you want to redirect to. This method will allow people view the content of the page before they are automatically redirected (to a download, away from a ‘Submission complete’ page ect).

h1

More SQL

July 22, 2008

This is a quick addendum to the previous post about using LIKE in a WHERE clause.

LIKE is treated in different ways depending on what database you are using, case sensitivity is a particular area where the differences can be seen and can become important.  MySQL for example, treats like as case-insensitive (you can set it to be case sensitive, but by default it ignores case – see http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html for more information).  But in many other database servers, for example Oracle, LIKE is case-sensitive by default.

While this may seem semi trivial (as I found out today) people often assume searches are case-insensitive and thus having a case sensitive query can be a big problem.

One way to get around this is to use the keyword UPPER to use an all uppercase version of the field to compare with the search string (which you should ensure is also all uppercase.  (LOWER may also be used to compare with all lowercase strings).

It should be noted this is not a great method if you are searching a large database as it will perform a full-text search instead of utilizing indexes, thus increasing the time each query takes.

An example:
SELECT * FROM tablename WHERE UPPER(lastname) LIKE '%SMITH%';
or
DELETE FROM tablename WHERE LOWER(firstname) LIKE '%john%';

Googling UPPER, sql will give you some other methods for case-insensitive searching that utilizes indexes and speeds things up. This is just a base level fix that is useful for smaller databases/tables.

h1

A little SQL

July 13, 2008

Recently I have been learning how very powerful SQL (structured query language) can actually be.  In this post, I would like to focus on the LIKE keyword which allows you to search a database for a pattern or string.

But first, a small amount of introduction.

SQL is a language used (generally) to ‘query’ databases and edit, delete or retrieve information from these databases.  It can be used with a great majority of existing (structured, relational) databases – anything from MySQL to Microsoft Access to Oracle.  It uses keywords in conjunction with ‘field’ names  (fields are represented (generally) by columns inside of a graphical view) and table names (tables are groups of fields somehow related to each other – for example a ‘person’ table might have a first name, a last name, a date of birth, a height ect.).  With these keywords you can do anything from count the number of entries in a table to find everyone (in the person example) whose last name contains an ‘N’.

A more in depth look at all the SQL keywords, what they do, and how they should be used can be found at http://www.w3schools.com/Sql/default.asp.

Some Common Examples: (this is a very minimal list, check the above link for more)

(* is a wildcard representing ‘all’)

SELECT – retrieves rows containing the specified fields from the given table(s). Used when you are trying to get information out of a database.
This will select all the fields and all the rows (it will retrieve ALL the information in a table) named ‘table’
SELECT * FROM table;

INSERT INTO – allows you to insert values into a new row in a table.
INSERT INTO table (field1, field2, field3) VALUES (value1, value2, value3);

UPDATE – allows you to change the values in (a) row(s) that already exist in a table. (the following statement would set ALL field1′s = value1 and ALL field2′s = value2)
UPDATE table SET field1='value1', field2='value2';

WHERE – begins a ‘WHERE clause’ which specifies which rows you want to effect with your query.
SELECT * FROM table WHERE field1='value1';
UPDATE table SET field1='value1', field2='value2' WHERE field3='value3';

Now, the WHERE clause is the place that it gets interesting (at least in terms of using LIKE).

When creating a ‘WHERE clause’ LIKE can be used to search for entries that match a pattern instead of looking for a specific value. This can be done in the following ways:

Using % as a wildcard
WHERE field1 LIKE '%s' – look for entries that have a field1 that ENDS in s – for example: would find ‘words’, ‘values’… would NOT find ‘soon’.
WHERE field1 LIKE 's%' – would find entries with field1 starting with s (like ‘soon’)
WHERE field1 LIKE '%s%' – would find entries that have a field1 which contains s anywhere in it

Using _ to represent an unknown character
WHERE field1 LIKE 's_op' – would find things like slop and stop

Anyway, LIKE can be an extremely useful and effective way to implement a search. An example would be an users admin page which allowed the admin to search for the name/email of the person they wanted to edit. They may not know the persons full name, or they may not want to/know to type it exactly as it is in the database. Adding a LIKE clause to your WHERE clause is an easy and efficient way to provide this capability.

h1

Microsoft Silverlight

July 9, 2008

Recently, Microsoft has released its answer for Adobe (formerly Macromedia) Flash called Silverlight. It, very much like flash, allows for ‘Rich Internet Applications’ – basically interactive, ‘pretty’ web applications, movies and other media.

Silverlight is, in some ways, superior to Flash because it contains textual content that can be searched from your browser… making it easier to interact with. However, this text is in XAML format (visit Wikipedia for an explanation) which is Microsoft’s own proprietary XML based markup language. It is, in some ways, very useful for creating web applications. XAML no doubt will be familiar to people who have worked with asp.

The problem with both Silverlight and XAML is that if these technologies become popular, Microsoft would be able to deny compatibility/accessibility to people who didn’t use windows, or charge for compatible browsers. As far fetched as this may seem, Microsoft did not include support for Opera thus alienating Linux users in current versions of Silverlight…

Both Flash and Silverlight seem rather inaccessible to the general public (or at least to me) in terms of development because of the high cost of development studios for both languages. (Currently you can get a pre-release version of Silverlight’s studio – Microsoft Expressions – for free. The full studio costs $699 though.) While there are free options (such as CoffeeCup for flash) these tend to be… not very useful.

Proprietary languages/technologies seem to be the wrong way to be heading, especially with Microsoft holding the cards. I do think that web designers/developers will shy away from Silverlight if there is any hint that Microsoft intends to deny support to other browsers/operating systems.

h1

Canadian Sailors eh?

July 7, 2008

I was reading my little Vista rss feed today when I saw a headline that said “Stroke Victim Speaks Like Canadian Sailor.” news.com.au reports that a Canadian woman now speaks like she is from the coast.

(http://www.news.com.au/story/0,10117,23981496-401,00.html)

More specifically, the headline said she now speaks like a “sailor” . . . Poorly thought out headlines aside, the idea that someone’s accent can change dramatically following a stroke is relatively weird.

h1

Places you might want to visit (around the web)

July 6, 2008

There are hundreds of thousands of sites around the internet, and most of them are not worth your time (like this one), but a few are worth checking back with every few weeks. Below are a few of my favorites, that other people might enjoy or find educational.

For ease of surfing and later reference for myself (and you) I split these up into categories:

Programming/Web-design
w3schools.com – a great website about all sorts of web related programming, can function as a starting point for learning a web-based language or a useful reference for experts.

php.net – The creators of php have pretty much all the information you’ll ever need about php right on there own site. There are also posts from the community on nearly every reference page, providing helpful advice and additional examples.

AListApart.com – An excellent and extremely literary website with articles about website design and web programming. The articles on this site are works of art and provide expert advice on a variety of issues.

java.sun.com/[...]/api/The java API is one of the most complete and the most accessible references for any programming language (and a far cry from the relatively worthless MSDN developer network…).
______________________________________________

Humorous Sites
Uncyclopedia.org – A sarcastic, uninformative, geeky and yet hilarious wiki abot anything and everything. I would recommend searching for celebrities who you don’t like or, if you just love everyone, fall back on ‘Microsoft’ (always a good bet).

Maddox.xmission.com – Maddox is like… Rush Limbaugh – Politics + even more conceit + more humor.

UrbanDictionary.com – Urban Dictionary… enough said.

ICanHasCheezBurger.com – Cats + Captions + Poor spelling = Hilarious (unless you are a Grammar/Spelling Nazi).

FailBlog.org – Looking at pictures of fails always makes me feel better about myself… and laugh… a lot.
______________________________________________

Others
PSDtuts.com – an excellent site for learning Photoshop techniques.

NewEgg.com – If you need to buy computer/electronic related items… Newegg is the place.

Pandora.com – Pandora creates custom radio channels based on music you like and then streams it for free to your computer. Its a great way to find new artists and songs that you might like.
______________________________________________

I might end up adding more links later, but for right now, this is a short list of my bookmarks.

h1

Div Containers with Floats: clearing

July 6, 2008

If you have ever tried to format a website using floating objects then you have no doubt run into a problem when a ‘container’ div doesn’t stretch to hold the floats. Instead, it has no height at all, pulling any objects below it up into your floated objects and messing up borders.

The popular (though messy) way to fix this is to add a
<div style="clear:both;"></div>to the bottom of the containers code. This gives the container some non-floated content (below the floated objects) and thus expands the size to the correct dimensions.

The main problem with this (from my point of view) is that it looks awfully messy, especially if you are creating a template. Having a bunch of empty divs lying around just seems like poor form.

Anyway, today I found a better solution – a much more thorough explanation of the issue (with pictures), the solution and why it works can be found at www.quirksmode.org.

Basically though, including:
overflow:hidden;
or
overflow:auto;
in the css for the container will force the container to expand to the correct size. You can also use ‘overflow:scroll’ but this will give you scroll bars in the container (which looks bad most of the time). (Using ‘hidden’ seems to be the best option because ‘auto’ can also cause scroll bars to appear in some browsers)

One line of CSS seems preferable to extraneous divs sitting around in the HTML.

h1

Obscuring email addresses from spammers

July 5, 2008

Today (and yesterday and the day before) I was working to upgrade a website’s defenses against spam-bots (web-spiders, bots, ect) which crawl the internets looking for email addresses to scoop up and add to their mailing lists.  Apparently people still don’t know they can buy viagra online (???).

Anyway, I ended up doing quite a bit of research into protecting my site, and those who entrust their emails to me, from spammers.  The site also suddenly began having a problem with bots filling out the ‘contact’ form and submitting it… repeatedly (like once every 2 minutes). Needless to say, this was very annoying. I came up with some solutions (most of these are modified from elsewhere) and some good websites with information about protecting your site.
Read the rest of this entry »

h1

Welcome (Introduction to the blog)

July 5, 2008

Hi everyone who is reading this post/blog (which is mostly myself).

I am starting this blog as a kind of technical notebook for myself.  If anyone else actually reads it, I hope that my learning experiences can be useful to you.  Right now I am working at a government OIT in an application development department.  At work I do some Crystal Reports, work with .NET languages (mostly Visual Basic and C#) and do a small amount of web programming.

In my spare time I do mostly web development, I work mostly in PHP (with HTML and CSS) but would very much like to learn more about javascript and possibly .aspx (though my little experience with it has been relatively negative).

I am also in school, though (currently) it is the summer time and I am back home until late August.  At school I am a Computer Science major and have taken classes in Java and C.

So… those are the things I am interested in from a technical perspective, no doubt this blog will stray from these defined topics (I’ll be amazed if I mention them more then twice), but its nice to have a gameplan.

-Josh

Follow

Get every new post delivered to your Inbox.