Archive for the code monkey Category

I’ve had some requests for my admin_delete_users_bookmarks_and_tags for Scuttle that I hobbled together some time ago. After going through all the files in my scuttle installation, I realized the only hack was that I changed the function isAdmin in the services/userservice.php from this:

function isAdmin($userid) { return false; //not implemented yet }to this:

function isAdmin($userid) { if ( ($userinfo = $this->getUser($userid)) ) { if ( $userinfo['uAdmin'] == 1 ) { return true; } } return false; }

This a really cheap and dirty hack because all it does is give admin privileges to the user with userid 1 in the database (which just happens to be my userid - substitute your own). All the other code was Scuttle 0.7.1 already, just waiting to be used. I don’t even know if this is a hack - more like a piece of duct tape over a leak in the hull of a boat. But it works. If anyone has a better hack, and honestly - a monkey sitting banging his/her head on the keyboard could do better than this - please leave it here or let me know.

UPDATE: Sadly, the spammers figured out a way around this, and even after shutting down registration the bad links kept showing up. The school’s social bookmarking site has been shut down indefinitely. Stinking spammers!

Thanks to Alan:

Hmmm - LISP is obscure, confusing enough to give the appearance of being complex, understood by very few people and used to simulate intelligence. Yep, that sounds like me!

If you’ve read this, consider yourself tagged - take the quiz. Is anybody a Python? That’s what I was hoping for.

As part of my M.Ed. project, I’ll be building a web site. Most sane people would do this using Dreamweaver or some similar product. I, however, am not one of those people - I prefer to create web pages by hand-coding the HTML and CSS files. I suppose if I wanted to be uber-geeky about it, I would write my own text editor (in assembler, if I wanted to be really hard core about it), but I’ll stick with ones that are currently available for the Mac.

My requirements are fairly simple. I need a text editor that I can use to write HTML and CSS files. Any text editor could do this. Heck, I could use vi if I really wanted to geek out. I’d like to have an editor that did some of the coding automagically. I like to hand code, but I don’t mind using some tools that help to automate the typing. I could use the code editor in Dreamweaver - I’ve used it before and its actually very comfortable to use. Using Dreamweaver just to do handcoding is like buying a Ferrari just for driving to the local grocery store - a waste of money and not using the functionality to its fullest. Besides, with Dreamweaver I might decide to use the WYSIWYG mode, and that is the way to the dark side.

I also like to use some open source software, if possible. The free (as in beer) part certainly appeals to me, but so does the speechiness type of freedom. In my experience, a strong user community around an open source project is usually a better source of application support than the support available for commercial software. Also, if I am really stuck on something or I have suggestions to improve the program, I can contact the developer(s) directly. Try that with most commercial software! I did a little bit of research into this, and thought I should share the results with others. Lest you think I am being overly concerned with this, a good text editor is to a coder what power tools are to a carpenter. We can get good results with mediocre tools but its an easier job to do, and more fun, with good tools. Admittedly, my needs as a coder, not to mention my skills, are minimal but I still like to work with proper tools. OK - here are my thoughts on the text editors I reviewed. I won’t claim that I’ve done a thorough job of testing each editor, so some of these descriptions are based on limited experience.

  1. TextEdit Free with Mac OS (equivalent to NotePad in Windows). Nothing fancy for editing tools, just straightforward text editing. Free with all Macs, and apparently the source code is open and distributed with Xcode. TextEdit also has some nice word processing features, but I don’t need those. Rating: 1/5 (as an editor; for other uses it would rate 3.5/5)

  2. JEdit Nice editor, many good plugins available including an XML plugin that does automagic tag closing for HTML tags, and makes tag suggestions when creating tags (similar to Dreamweaver code editor). No built in auto XHTML file templating, but a macro was easily written to do the job. Macro recording (or writing, if you aren’t afraid of a little coding). Feels very Emacs-ish. Open source.

Rating: 4/5

  1. Smultron Open source, Mac OS only. It has a very Mac-ish look and feel to it, with the toolbar at the top. Multiple windows can be open simultaneously, with a pane showing a list of currently open documents. Keyboard shortcuts to move between open documents. There is a built including XHTML template. Full screen edit mode for distraction free writing/coding. Includes a command line tool - this editor has many command line connections, including ability to run shell commands, or run the file or selected text. It can auto-close tags, and can make text suggestions for partially completed word. This would make a really nice HTML editor. There is a lot of well-thought out functionality in this editor and may end up being my choice.

Rating: 4.5/5

  1. TextWrangler Proprietary, but free, from the good folks at Bare Bones Software. This is essentially a limited version of BBEdit. It excels at using regular expressions to transfrom text, but as an HTML editor it isn’t as fully featured for coding HTML as Smultron or JEdit. Has an Emacs-ish feel to it.

Rating: 3/5

  1. BBEdit The 500 pound gorilla of Macintosh text editors. I remember using BBEdit on my old (OS 8 era) Mac, and it was a joy to use as an HTML editor (I didn’t do much coding back then). I’m not sure if my memories of BBEdit are correct or if my expectations of an HTML editor have increased, but I find that BBEdit, like Text Wrangler, is an adequate HTML editor but not a particularly great one. The functionality in BBEdit is perhaps too much for my meagre needs, and it is verging on becoming bloatware (IMHO). It is also the priciest of the Mac text editors at US $125, which works out to $145 Canadian, quite a bit considering the availability of free editors like JEdit and Smultron, and the availability of lower price editors like TextMate. Rating: 4/5

  2. TextMate This is an newer text editor but unlike Smultron, TextMate costs 39 euros, which works out to about $60 Canadian. As an HTML editor, it is as sweet as candy. New (X)HTML documents can be created from a template, which is editable. Keyboard shortcuts are available for almost all standard functions such as moving word by word or to the end of the current line.

An interesting variation on keyboard shortcuts are tab triggers. These are short strings (such as ‘div’ to insert a new div tag) that activate an action when followed by a tab. I typed in ‘div’ followed by a tab, and a pair of div tags were created including a placeholder for an id property; if I want to use it, I tab then type in the id for the div, and if I don’t want it, I hit the delete key then a down arrow and I’m ready to add content inside the div tag. It took me about 30 seconds to create a snippet (piece of text that is used frequently) for a paragraph tag (which suprisingly is not included with the program, or at least I couldn’t find it), then another 10 seconds to assign a tab trigger for it. Sweet!

TextMate was the winner of the Apple Design Award for best developer tool in 2006.

Rating: 5/5

Final thoughts I’d narrow my choices down to JEdit, Smultron and TextMate. TextEdit has no pretense of being a programmer’s editor, even for something as simple as HTML, and would only be suitable if you liked to type everything out one character at a time. I need something with a little bit more HTML programming finesse. Text Wrangler and BBEdit have great text processing capabilities, but feel a little too emacs-ish for me (not to start a series of comment flaming, but I’m more of a vi guy), and aren’t especially welcoming for someone who just wants to do some productive HTML coding. I like JEdit. It is free software/open source. Its extensibility by plugins is terrific, and there seems to be a strong community (always a good thing for an open source project). I have used it in Linux and Windows environments, and will continue to do so. The Mac-ishness of Smultron and TextMate, as well as their design as coding tools, make them my clear choices. Given my preference to use free (as in both beer and speech) software, Smultron will be my first choice. I may still be lured to TextMate, definitely my favourite of the entire bunch.

This is just a quickie braindump post so I have some notes on a bit of tweaking I just did on the school’s installation of Scuttle, an open-source social bookmarking tool similar to del.icio.us.

The problem we were running into was a lack of administrative control to get rid of undesirable (spam) links in the bookmark collection. Looking through the code, I saw that Scuttle does have a stub admin function included, but it isn’t currently implemented.  In a disgustingly quick and dirty hack, I rewrote the code for the admin function so that anyone whose user ID number in the MySQL database is automagically the administrator (and that happen’s to be me in this installation). Nicely enough, once I did that I had edit and delete power over other user’s links - the author of Scuttle has obviously been planning to include some administration tools, and started building a bit of code to do the job.

Samples of code available upon request - if you leave a comment asking for it, I’ll post it up.

I was just taking a look at try ruby! (in your browser), a very cool little programming tutorial for the Ruby language. Normally, I would just add this to my del.icio.us feed, but del.icio.us appears to be well and truly bollixed at the moment. (Sorry if this is offensive language to anyone, but it is the only apt description I could think of). Besides, if I post it here, someone else might get some enlightenment from this tutorial.

Almost forgot credit where it’s due - I found this via a post from David Wiley, who is also upgrading to WordPress 2.0 (which I hope to get done tonight!)