Order by date when stored as a nvarchar
by RedCoupe on Jul.21, 2011, under Web design / development
Just had a MS SQL Server problem where as the title suggests, I wanted to order a query by a date column to show the most recent entry at the top, but it wasn’t working because the date column was stored as a nvarchar instead of a datetime.
I tried various things like CONVERT…. and CAST…AS datetime, but for whatever reason I could not get this to work.
I got round this by doing some string concatenation:
SELECT * FROM tbl_articles
WHERE visible = 1
ORDER BY RIGHT(dateval,4)+SUBSTRING(dateval, 4, 2)+LEFT(dateval,2) ASC
The date was stored in the table as text like 22/10/2011, the above concatenating turns it into 20111022 which can easily be sorted in the proper order.
I know this is more than likely not the best way of doing it and should have persevered with the casts and converts but it works fine for the minimal amount of data I have in that table. No doubt I’ll have to revisit this if the number of records significantly increases.
Modified styles in WordPress
by RedCoupe on Jul.14, 2011, under Web design / development
I have another site produced with WordPress and it uses a modified version of the Twenty Eleven theme.
The trouble was that whenever I applied an update to the theme, it obviously overwrote my modified style.css. I suppose if I wasn’t lazy I could have copied the theme to a new folder and simply used the copied theme. Although I do like getting updates including any improvement tweaks etc.
To get round this I found a great plugin called Style Press which was made by grandslambert who has also produced some other handy plugins. So I installed it, added my custom css, reverted the style.css back to the original version, and it worked perfectly. So in future whenever I apply a new update to this theme, unless class or id names change, the site will always look the same because the extra bit of css is always added at the end of all the other style includes in the html.
Typing umlauts on an English language keyboard
by RedCoupe on Jun.30, 2011, under Web design / development
I’ve had reason to write a title in German that contains umlauts and apart from copying and pasting, I couldnt find a way to do this via my keyboard. By the way I’m using Windows XP.
I know I can use the “Character Map” application under Start>All Programs>Accessories>System Tools>
I found the ü symbol and it said the keystroke was Alt+0252. Well I tried this using the number keys along the top of my keyboard and it didn’t work. So I ended up just selecting what I needed and copying it etc. Since then I found out that if I took numlock off and used that number keypad it works fine.
Aparently on the Mac if you press Alt+u and then typing the following letter; a, u, or o. When the letter is pressed it will display the unlauts over the top as they should be.
Here’s a table of ALT codes for letters with accents:
| Uppercase | Lowercase | ||||
|---|---|---|---|---|---|
| Alt Codes | Symbol | Description | Alt Codes | Symbol | Description |
| Alt 0192 | À | A grave | Alt 0224 | à | a grave |
| Alt 0193 | Á | A acute | Alt 0225 | á | a acute |
| Alt 0194 | Â | A circumflex | Alt 0226 | â | a circumflex |
| Alt 0195 | Ã | A tilde | Alt 0227 | ã | a tilde |
| Alt 0196 | Ä | A umlaut | Alt 0228 | ä | a umlaut |
| Alt 0199 | Ç | C cedilla | Alt 0231 | ç | c cedilla |
| Alt 0200 | È | E grave | Alt 0232 | è | e grave |
| Alt 0201 | É | E acute | Alt 0233 | é | e acute |
| Alt 0202 | Ê | E circumflex | Alt 0234 | ê | e circumflex |
| Alt 0203 | Ë | E umlaut | Alt 0235 | ë | e umlaut |
| Alt 0204 | Ì | I grave | Alt 0236 | ì | i grave |
| Alt 0205 | Í | I acute | Alt 0237 | í | i acute |
| Alt 0206 | Î | I circumflex | Alt 0238 | î | i circumflex |
| Alt 0207 | Ï | I umlaut | Alt 0239 | ï | i umlaut |
| Alt 165 | Ñ | N tilde | Alt 164 | ñ | n tilde |
| Alt 0210 | Ò | O grave | Alt 0242 | ò | o grave |
| Alt 0211 | Ó | O acute | Alt 0243 | ó | o acute |
| Alt 0212 | Ô | O circumflex | Alt 0244 | ô | o circumflex |
| Alt 0213 | Õ | O tilde | Alt 0245 | õ | o tilde |
| Alt 0214 | Ö | O umlaut | Alt 0246 | ö | o umlaut |
| Alt 0138 | Š | S caron | Alt 0154 | š | s caron |
| Alt 0218 | Ú | U acute | Alt 0249 | ù | u grave |
| Alt 0219 | Û | U circumflex | Alt 0250 | ú | u acute |
| Alt 0220 | Ü | U umlaut | Alt 0251 | û | u circumflex |
| Alt 0217 | Ù | U grave | Alt 0252 | ü | u umlaut |
| Alt 0221 | Ý | Y acute | Alt 0253 | ý | y acute |
| Alt 0159 | Ÿ | Y umlaut | Alt 0255 | ÿ | y umlaut |
| Alt 0142 | Ž | Z caron | Alt 0158 | ž | z caron |
Vi / Vim Shortcuts
by RedCoupe on Jun.15, 2011, under Web design / development
Im always forgetting the very useful vi shortcuts, so here’s a list of them:
ˆ = Control key
If you see a 10, this can be replaced by any number
| Operation | Keys |
|---|---|
| Return to Command mode from Insert, overwrite or append mode | Escape |
| Enter Insert mode | i |
| Enter overwRite mode | R |
| Enter append mode | a |
| Enter append mode at end of this line | A |
| Enter Insert mode on a new line after this | o |
| Enter Insert mode on a new line before this | O |
| Delete this word and enter Insert mode here | cw |
| Delete this line and enter Insert mode here | cc |
| Delete the next 10 lines and enter Insert mode here | 10cc |
| Move cursor left one character | left arrow or h |
| Move cursor left e.g. 10 characters | 10h |
| Move cursor down one line | down arrow or j |
| Move cursor down 10 lines | 10j |
| Move cursor up one line | up arrow or k |
| Move cursor right one character | right arrow or l |
| Save this file and continue | :w |
| Save this file and exit | :wq |
| Abort without saving changes to this file | :q! |
| Quit (no changes made) | :q |
| Save as a new file “new-file” | :w new-file |
| Load the file “myfile” into vi | :e myfile |
| Delete the character under the cursor | x or Del |
| Delete the current word (inc. space) | dw |
| Delete the next 10 words | 10dw |
| Delete the current line | dd |
| Delete the next 10 lines | 10dd |
| Delete rest of this line, right of the cursor | d$ |
| Yank the current line onto the clipboard | yy |
| Yank the current word onto the clipboard | yw |
| Paste the clipboard | p |
| Undo | u |
| Redo | ^r |
| Jump to the bottom of the file | G |
| Jump to e.g. the tenth line of the file | 10G |
| Jump to the top of the file | gg |
| Jump one page forward | ^f |
| Jump half a page forward | ^u |
| Jump one page back | ^b |
| Jump half a page back | ^d |
| Search for text from cursor | /text |
| Find next occurrence of text | n |
| Find previous occurrence of text | N |
| Start of next word | w |
| End of next word | e |
| Start of the tenth word forward | 10w |
| Start of next sentence | ) |
| Start of previous sentence | ( |
| Start of line | 0 (zero) |
| End of line | $ |
| Top of screen | H |
| Bottom of screen | L |
| Middle of screen | M |
Welcome back PSN
by RedCoupe on Jun.09, 2011, under PS3
For the ‘Welcome Back’ package I’ve gone for WipeOut HD (with Fury pack) and Infamous, for the PSP I’ll probably go for Little Big Planet and ModNation Racers. As a Playstation Plus subscriber I was pleased to be able to download Burnout Paradise as a freebie, nice one.
Get dropdown list label value
by RedCoupe on Jun.09, 2011, under Web design / development
I was working on a couple of web pages this morning to allow completion of a course booking form, user then submits to a thankyou page, confirmation emails are sent etc.
The problem I faced was that only the course ID was being passed to the thankyou page so in the emails that are generated, it displays Course Details: 7 , instead of Course Details: 12/12/2011 PHP Basics.
So my initial thought was to create a hidden field just before the end form tag together with some javascript that gets the relevant label value:
document.getElementById('coursedetails').value = document.getElementById('training_id')[document.getElementById('training_id').selectedIndex].innerHTML;
Then in the thankyou page I just got Request.Form(“coursedetails”), this is in ASP VBScript just in case you were wondering. Works like a charm.
Since doing this is I should have done it a much easier way and not have to rely on JavaScript being enabled. I already had the value because I was already using it to display the dropdown list label. So the hidden field could have just contained the default value of the currently selected item.