Friday, November 28, 2008

jQuery 1.2.6 Text Clips for Programmer's Notepad 2

jQuery 1.2.6 Text Clips for Programmer's Notepad 2 are available along with my other text clips. If they don't show when you start PN2, close it and delete installClipCache.xml that is stored within the %APPDATA%\Echo Software\PN2\ directory.

Programmer's Notepad 2 is an open source application that supports syntax highlighting of many file types, project support (using its own project file type), autocompletion, text clips (snippets), automatic indenting among other features. It loads quickly (startup is faster than IDE's like Visual Studio, Eclipse and Komodo have), so is a good lightweight IDE that is also portable (save it on your portable hard drive / memory stick and run on many different PC's).

Friday, November 14, 2008

GIMP Repeating Guidelines

Update (18 Nov): bug fix - guides go up to both edges, if width/height is a multiple of the separation distance. max was set to height (if vertical guide) when it should have been width and vice versa for vertical.

The GIMP photo/image manipulation program allows you to add guides as an aid to image editing. It is fairly simple to add them - Image > Guides > New Guide or click on one of the rulers and drag onto the canvas. However, this can be time consuming if you need to add multiple guides, equally spaced.

Script-Fu however, allows you to do this via scripting. First of all, create a scm file (e.g. guides-repeat.scm) in your script folder (on Windows this would be C:\Program Files\GIMP-2.0\share\gimp\2.0\scripts (all users) or %USERPROFILE%\.gimp-2.6\scripts, then paste in the following code (use a plain text editor like Notepad)

(define (script-fu-guide-repeat image
  (let* (
        (width (car (gimp-image-width image)))
        (height (car (gimp-image-height image)))
  (position 0)
 ; set maximum otherwise the guides will be added indefinitely
 (if (= direction 0)
   (set! max height)
   (set! max width)
 ; while the position is less than the maximum
 (while (<= position max)

  (if (= direction 0)
   ;; check position is inside the image boundaries
   (if (<= position height) (gimp-image-add-hguide image position))
   (if (<= position width) (gimp-image-add-vguide image position))
 ; increment position by defined separation 
 (set! position (+ position separation)))

(script-fu-register "script-fu-guide-repeat"
  _"R_epeating Guide"
  _"Add multiple guides separated by specified number of pixels"
  "Sam Collett"
  "Sam Collett"
  SF-IMAGE      "Image"      0
  SF-DRAWABLE   "Drawable"   0
  SF-OPTION     _"Direction" '(_"Horizontal" _"Vertical")
  SF-ADJUSTMENT _"Separation"  (list 40 1 MAX-IMAGE-SIZE 1 10 0 1)

(script-fu-menu-register "script-fu-guide-repeat"

After saving the script, either restart GIMP or Filters > Script-Fu > Refresh Scripts (GIMP 2.6, earlier versions use Xtns instead of Filters). Repeating Guides should now appear under Image > Guides

Friday, November 07, 2008

Searching Indexing Service (ASP.NET C#)

Windows has an Indexing Service that can be used to index files on the server it is hosted on. Here is a simple way to query any catalogues (in this example, one called Data) you create and display the results in a repeater.

First of all, create a new page (in Visual Studio or Web Developer 2005), e.g. search.aspx. Create the search box and repeater within a form runat="server":

<form id="form1" runat="server">
 <asp:TextBox runat="server" ID="Search" />
 <asp:Button runat="server" Text="Search" OnClick="SearchDocuments" />
 <asp:Repeater ID="ResultsRepeater" runat="server">
       Last Modified
     <%# Eval("Filename") %>
     <%# Eval("size") %>
     <%# Eval("DocTitle") %>
     <%# Eval("path") %>
     <%# Eval("write") %>
     <%# Eval("rank") %>
   </tbody> </table></FooterTemplate>

Then in your code behind (search.aspx.cs) add:

protected void SearchDocuments(object sender, EventArgs e)
 String fileTypes = "\".doc\" OR \".rtf\"";
 String catalog = "Data";
 String q = Search.Text;
 q = q.Replace("'", "''");

 String query = "SELECT DocTitle,Filename,size,path,rank,write,vpath,url from SCOPE() WHERE FREETEXT('"+q+"') AND CONTAINS(Filename, '"+fileTypes+"') ORDER BY rank DESC, write DESC";

 OleDbConnection cn = new OleDbConnection("Provider=MSIDXS.1;Integrated Security .='';Data Source='Data'");

 OleDbDataAdapter cmd = new OleDbDataAdapter(query, cn);

 DataSet data = new DataSet();

 DataView results = new DataView(data.Tables[0]);

 ResultsRepeater.DataSource = results;


The results are sorted by rank (highest first), then date last modified (newest first). Only search Word documents (or more precisely, filenames containing .doc or .rtf) - but you can always add more types and refine the search further.