Currently selected: programming notes (page 1)

cleverbit icon

Posted on: 21 Feb, 2010
Read more in notebook: cleverbit dev news

Per the encouragement of at least 30% of my readership I've added a cleverbit.org icon. I was thinking of using a professional one I found on line but given how tiny they are it seemed more fitting to make one of my own. I did at least read a tutorial on how to make rounded edges :).

customized image tags

Posted on: 14 Oct, 2009
Read more in notebook: programming bits

As you probably know I've moved and redesigned my website several times since it's original inception and one thing I quickly decided is that it's no good putting real image tags right into my blog posts because then if (or let's face it when) I redesign my website I have to troll through all the posts wrapping the images in html tags or changing them into links for a gallery, or removing the links, or whatever new idea seems desirable at the time. Instead I've replaced the html image tag with a tag of my own. Not to surprisingly this too has gone through several versions but I'm quite proud of the current one and I even wrote proper regular expressions rather than the slightly dubious and a bit hacked together parsing solution I had previously. My current tag looks like this: <my_img id=999>

My parsing code is rather simple, I just go through each my_image tag and replace it with a proper html image tag after retrieving the image name from the database based on it's id. I probably could change it to access the database once for all images but since my posts rarely have more than a few images this seems hardly worth the extra complication.

function replaceImgTags($string) {
      $db = new MySQlImageConnector();
      $found = true;
      $regExpr = '/<[ ]*my_img[ ]+id=\"(\d+)\"[ ]*\/>/';
      $matches;
      preg_match_all($regExpr, $string, $matches, PREG_SET_ORDER);
      foreach ($matches as $matchSet) {
            $loc1 = stripos($string, $matchSet[0]);
            $size = strlen($matchSet[0]);
            $image = $db->getImageById((int)$matchSet[1]);
            $tag = "<p><img src=\"".CB_IMAGE.$image->getFileName()."\"";
            $tag .= " alt=\"".$image->getName()."\" /></p>";
            $string = substr($string, 0, $loc1).$tag.substr($string, $loc1+$size);
      }
      return $string;
}

While I was writing this post I discovered that I don't have a good way of formatting code snipits in my blog and I don't really want to have to hand format each one individually so I added a <my_code> tag with a processor to replace the newlines and spaces and wrap it in a paragraph with a css style.

function replaceCodeBlockTags($string){
      $found = true;
      $reg ='/<[ ]*my_code[ ]*>(.*?)<[ ]*\/[ ]*my_code[ ]*>/s';
      $matches;
      preg_match_all($reg, $string, $matches, PREG_SET_ORDER);
      foreach ($matches as $matchSet) {
            $match = $matchSet[1];
            $loc1 = stripos($string, $match);
            $size = strlen($match);

            //keep all the special characters
            $match = htmlentities($match);
            //replace newlines with breaks
            $match = str_replace("\n", "<br />", $match);
            //replace tabs with a bunch of spaces
            $match = str_replace("   ", "&nbsp;&nbsp;&nbsp;", $match);
            $match = "<p class=\"code\">".$match."</p>";
            
            $string = substr($string, 0, $loc1).$match.substr($string, $loc1+$size);
            
      }
      return $string;
}

Cleverbit 3.0 has arrived

Posted on: 7 Oct, 2009
Read more in notebook: cleverbit dev news

As promised here is cleverbit.org 3.0. I decided to go for a streamlined design both in code and in actual website design. I'm only using code that I wrote myself (much of which has been hanging around in one state or another since cleverbit 1.0). I'm done with spending hours and hours trying to coerce someone else's library into doing what I want while I stumble over load of 'features' that I don't really need. I've also simplified the overall design and user experience of my site; while I still favor a more organized approach to organizing my blog I'm no longer imposing my order on the user. In short my blog feels more like a standard blog now although it doesn't have comments at the moment. But a blog is really more of a one way medium anyway. Also I decided to get rid of galleries since I ended up posting most of my photos within posts anyway so that I could give them a bit of narration. A picture might be worth a thousand words but without a bit of direction how would you know which thousand to pick?

I'm pretty happy with how things turned out. Each notebook/entry/container has a bean like object which may eventually include more validation (although it doesn't include much now, horrors!). Then I have separate logic for retrieving and storing the objects from a mySql database and rendering them in html and rss. The design therefore is quite simple and maintainable and since my site is not particularly high traffic I'd rather have a few extra sql queries then to fight with someone else's optimized framework. I do still want to introduce some more content to my site but its tricky to find the time what with work and knitting and getting distracted by silly things like trying to get with svn in Eclipse to do what I want before finally giving up and using the command line. Also in the spirit of simplicity I've dropped all the icons I gathered (legally) from the web and am using only images which are mine.

cleverbit 3.0

Posted on: 20 Sep, 2009
Read more in notebook: cleverbit dev news

Well, I've had it with Symfony. There is just too little documentation for me to be able to do what I want and whenever I search for a plugin I can only find plugins that only work with version 1.0 and since version 2 has been out since at least the start of the year when I started using Symfony I find that to be extremely frustrating.

I've spent the last weekend or two working with Textpattern but I've finally given up on that as well. Apparently when you write a new blog entry any newline characters are turned into html break tags and since I like to write proper html for my posts I end up with paragraphs and break tags. Of course I could write my posts as one long string with no visual breaks but if I start making compromises now I'll just end up frustrated in 6 months after having invested even more time into trying to manipulate someone else's product into doing what I want.

So, I'm giving up and going back to my own hand written code. Working with frameworks is just not worth the trouble. From now on I'm only using someone elses framework/software if it does what I want exactly out of the box. No more spending hours and hours searching through documentation and forums trying to coerce software written with one paradigm in mind into behaving as if it was constructed under a different paradigm. As a note I also tried Wordpress but at the end of the 'famous 5 minute install' I couldn't find my blog. Clicking on the 'view Cleverbit' link from the admin pages (which were not as easy to find as I would have expected) just took me to a directory listing of my webiste home page. Some 5 minute install. Anyway, my new streamlined, simplified site should be up by the end of the month and I'm putting an emphasis on content rather than structure and organization (which is perhaps the most major flaw with the current cleverbit.org site) and then I can start on my NEW project - reading/parsing knitting patterns and then checking them for errors, providing size and modification suggestions, and other similar tasks.

updates

Posted on: 17 May, 2009
Read more in notebook: cleverbit dev news

As you can see I've added and RSS feed for those of you who prefer to view my blog in your own viewer and I've also added twitter updates to the main page for those of you who prefer not to use a twitter viewer of some kind. One day presumably there will be a sort of single version viewer (sort of like a web browser...) which will let you view all sorts of stuff rather than having to log into a zillion different things just to keep up with your friends. Although after all the hard work I did on my new website it is sort of sad to think that people do just want the content and not all my pretty formatting and whimsical icons. Perhaps after a decade or so of everything being turned into a feed of some kind we'll have a renewal of individuality in presentation and not just content and people will be back viewing my website again.

I'm also working on a search/news page but that hasn't quite been finished yet.

symfony and twitter

Posted on: 16 May, 2009
Read more in notebook: programming bits

I'm currently working on adding my twitters to cleverbit.org and I'm trying to use the idTwitterClientPlugin. I thought it was worth mentioning that there is a bug in this plugin just in case someone can manage to google and come up with this blog entry they can save themselves some time. On line 92 of idTwitterClient.class.php the name of the username-password string should be 'userpwd' if you want to use curl. It needs to match the name of the constant curl expects in order to include the username-password string in GET requests. I think there may also be an issue with the date encoding of the 'since' field in the UserTimeline function but that was one of the first things I commented out and I haven't gone back to check it yet.

undefined symbols

Posted on: 22 Apr, 2009
Read more in notebook: programming bits

What I learned at work this week:

If a method is undefined and the error shows just the method name this is a standard c++ linking error. If the entire method signature is shown this is a good sign that you forgot the extern "C" bit.

Now if only it hadn't taken me half a day to figure that out... Well that and the conversion of strings from C to FORTRAN but lets just not even go there.