Posts tagged Tips
Windows Live Writer (shorter: WLW) is one of the most popular blog authoring tool that I also happen to like and use. And I say this because of its features – I especially enjoy the Preview tab. But what it really lacks is previewing the ENTIRE page – it will get only the html and some css. So no Syntax Highlighting of my code? Let me tell you how I solved this issue.
As a blog writer I searched for something that could allow me to write the articles offline and then upload them in WordPress. I also tried WordPress built-in editor, but the editing box is so small that I couldn’t use it too much.
The most important feature for me is that it retrieves the blog theme and has a preview function that provide you the same look on editor window. So you will be able to write a post with a preview. But when having a more complex theme, using JQuery or Prototype, you will discover that you don’t get any more the same look and feel as in the blog. This is partially ok for editing, but sometimes it is really bad – especially if you’re a programmer and add a lot of code in your page. On blogs there is a solution to show the code with syntax color, but in the Windows Live Writer I couldn’t find one suitable plug-in that does this.
While working on my webslice, I wanted to add some content to let the users know what’s happening on the website. So I was thinking to provide some random posts from my blog. Most of us know how to use the WordPress default methods to get the posts, to ask for random ones, but how to do it outside the warm WordPress environment?
I started digging in MySQL help (soon I should become a guru ) and find out that it is quite simple if all you want to do is to return some random rows from a table, let’s say a collection of random posts in your blog. Easily, MySQL’s base functions like ORDER BY RAND() come to the rescue. I found lots of examples, so I asume that everybody’s doing it. At least on my search on Google, all the PHP programmers did it:
SELECT * FROM wp_posts ORDER BY RAND() LIMIT 3
I set the limit to 3 because I don’t want to bother my users with all my posts, three are more than enough.
So I did it. But wait, there’s a catch! It really does what it’s supposed to. But what will happen when you reach high levels of users? Your webserver probably will suffer a lot from this. OK, it is not the case in articles,
Your social network keeps growing and growing and after about a year and 50000 new users you realize a slow-down on the page where you show random users. You’re thinking of caching it, but what’s the point? It wouldn’t be random. You break it down with EXPLAIN and realize with horror that your fancy query doesn’t use the nice index you placed on the table ages ago. And why would it? It’s calling RAND() for every row in your table, there’s just no way around it. So what to do? One alternative is to fetch random IDs first and then join the IDs found with the USERS table to fetch the real data. How do we do that? Why, using ORDER BY RAND(), of course. Wait, didn’t I just say you’re not supposed to use it? Well, I did say that, but the difference is that we’ll run the ORDER BY RAND() on the best-indexed column there is, the primary key. Let’s break it down and get our hands dirty:
SELECT USERS.* FROM (SELECT ID FROM USERS WHERE IS_ACTIVE = 1 ORDER BY RAND() LIMIT 20) AS RANDOM_USERS JOIN USERS ON USERS.ID = RANDOM_USERS.ID
And with a little bit of thinking we got ourselves a nice and fast way to fetch random data. Most likely there are other ways out there (sometimes I do miss Oracle’s ROWID), but this one worked fairly well for me. It probably won’t scale forever though, so be prepared to get back to it every once in a while.
Cursul oficial BNR
It is very nice and user-friendly to have Webslices on your website. It improves the user experience by allowing visitors to be up to date with the latest content that you provide, assuming that it is fitted to this presentation style. Since my BNR exchange rates page was this kind, I pursued in adding a Webslice especially for it.
Adding a webslice to your website is simple. After you read the main specifications or my previous article, you’ll understand the concept behind: first you signal to the browser that you have a special part of your website by setting to a container element the class “hslice”:
<div id="BNRExchange" class="hslice"> <div style="display: none" class="entry-title"> <img id="image" alt="Radu Poenaru's weblog gives you BNR Exchange rates" src="http://www.radupoenaru.com/bnr/images/radupoenaru.jpg" width="128" height="128" /> <p> Cursul oficial BNR </p> </div> <p> <a style="display: none" href="http://www.radupoenaru.com/bnr/bnr.php" rel="entry-content"> <a style="display: none" href="http://www.radupoenaru.com/bnr/bnr.php" rel="Bookmark" target="_blank"> <span style="display: none" class="ttl">5</span> </p> <div id="updateTrigger" class="entry-content" runat="server" /> ........ your content that you want surrounded by the green webslice part .............. </div>
The brushes used by SyntaxHighlighter are in separate syntax files named brushes. The following can be used to format the <pre class=”brush: brushname”> that you want to use.
Brushes () in alphabetical order:
|Brush name||Brush aliases||File name|
Some while ago, I started publishing code on this website. On that days I used the free WordPress webhosting. But I wasn’t content with the representation of it. After some time, I moved my site to a payed hosting, where I could implement any plugin that I liked.
When I use Mozilla Firefox I want to be able to see the content of pages, not to have my screen cluttered with lots and lots of toolbars. But when doing searches with built-in search area in this browser, I lack the highlighting feature of Google Toolbar. Not to mention the word search, handled so easy in it by pressing auto created buttons for each word.
So I tried to replicate the Google toolbar in the browser interface, but without adding the entire toolbar.
This can be done very easy, by following the next steps:
1. Install Google toolbar if you don’t have it already from http://www.google.com/tools/firefox/toolbar/ . The installation is very well explained, so I will not do it again.
2. In Firefox, with Google Toolbar visible, insert some words into its search area then click the Search button.
3. Right-click on the browser top area and choosing Customize, like in the following picture:
4. Grab the words area from toolbar, like in the pictures below, and move it up, near the Firefox default search area. Do the same with highlighting tool.
5. Now right click like in point 3 and make your Google Toolbar invisible.
And VOILA! You have an uncluttered, clean and neat search area that uses Google’s main interesting features.
From time to time you need to create a GUID (Global Unique IDentifier) in order to mark your dlls. Looking in my Visual Studio 2005 I saw that this command wasn’t available in any tools menu, nor in the Customize toolbars one as a shortcut to a command.
After a quick digging on MSDN site I found this. It is written in Microsoft style – a lot of information, but no solution. It just mentioned something like ”hey, we have something that you want, but guess what – we don’t have it any more”:
On the Tools menu, click Create GUID. The Create GUID tool appears with a GUID in the Result box.
So I started creating my own Create GUID command.
Happily, the Microsoft team provided the tool in the <visual studio install>\Common7\Tools\ directory. Usually, the <visual studio install> dir is C:\Program Files\Microsoft Visual Studio 8.
Actually, there are 2 tools for creation of GUIDs:
- GUI interface: <visual studio install>\Common7\Tools\guidgen.exe
- Console line tool: <visual studio install>\Common7\Tools\uuidgen.exe
At first look, uuidgen seemed the winner. Running uuidgen in command line revealed the needed parameters:
I proceeded to setup the Create GUID command. From Visual Studio 2005 menu > Tools > External tools you can add and setup a new command to an external tool. The setup window is straight forward for experts, but new guys can be impressed by it.
Clicking on Add button will create a new element in the list, called [New tool 1]. This name will be overridden by whatever you write in the Title text box. Next, the command text box will be filled with exact path to the tool. Clicking the ellipsis button, you’ll be sent straight to Tools dir, where you can easily find the tool required. As arguments I put the ‘c’ value which means that the output will be upper case UUID (as you can see in the previous image).
And when clicking OK, the corresponding name, as in my case Create GUID appears in the Tools menu, just above the External Tools menu.
But surprise, when I clicked the menu button, the command prompt flashed and nothing happened.
After a brief investigation, I figured out that the tool worked, but it’s output was retained in the command prompt window. This closes immediately after the tool runes successfully, outputting the GUID.
What to do ? I switched to the next tool, Guidgen. This was simply accomplished by changing the command to the corresponding tool name and removing the argument.
So after clicking on Visual Studio 2005 menu > Tools > Create GUID I got this window, in which I checked, as you can see, Registry format and then click on Copy button. Then clicking on Exit you dismiss the tool. By pasting the Clipboard content into a class, you will get this :
Good luck with the implementation!
If you want to improve your Windows Live Writer experience in blogging by adding some interesting plugins, you’ll be pretty disappointed if you use another browser than Internet Explorer.
First I tried first to enter into Writer gallery with Firefox 3, which is my default browser, on http://gallery.live.com/results.aspx?c=0&bt=9&pl=8 … but surprise !
Below is the same web address, but in IE 7.
If you “insist” to use Firefox, the actual entry point in Windows Live writer plugin website is : http://gallery.live.com/results.aspx?bt=9&pl=8&ds=1&la=en&tier=0&st=3&p=1&c=0
In Windows Vista you are constrained to use the default tool,Windows Updates, which is set to download only the files which need to be updated, by example if xxx.dll exists in Microsoft’s database as a bigger version and needs to be updated, then only this file will be downloaded from the Microsoft servers.
What if you need to reinstall your computer and you don’t have Internet connection available? Sometimes when you don’t know where your work will ask you to be, is better to have all updates archived safely and closely to you, on your harddrive. (more…)
Google has been the most improving mailing web interface that I know. Having a whooping 2 GB storage space when launched, he slapped over the face all his competitors, whom at that time had 4- 5 MB of storage space. Now is 7.5 GB and increasing.
The interface is very clean and intuitive, but not lacking the good looking ( example of bad looking is Squirrel Mail who looks obsolete, due to the right angle corners, opposed to the round corners approach in Gmail). Also the code completion for emails, the spell checker and other goodies makes this interface the most interesting in my opinion.
Recently, I learn about something that is quite hidden in Gmail interface: the plugins.
These can be activated by going into Settings in your Gmail mail account, click on Labs tab and search the desired plugin. In order to add it’s functions on the interface, you must activate first by checking the Enable option. It will be applied as soon as you click ‘Save Changes’ button on the bottom of the page.
I have activated the following plugins:
Give it a try!