I’ve just started experimenting with Scheme, specifically to follow Structure and Interpretation of Computer Programs. Here is a Scheme procedure that returns the sum of squares of two larger numbers out of the given three.
Category: Codeprix
'protected’ implementation in Actionscript 3 is BROKEN
Consider following code:
Theoretically, the call at line no. 13 should not cause any error as count is defined for testObj as a field in SubClass, but it gives a Cannot create property count on SubClass. Interestingly if we move modifyProperty method to SubClass or make count public, it works without any error.
So it can be said that we cannot access protected fields dynamically in a subclass.
Bing/Google toggle bookmarklet
I’ve been trying out Bing as my default search engine for last few months and the results are definitely at par with that of Google for most of the consumer categories. But sometimes you just need a quick toggle to see what Google would return for your query. So here is a small bookmarklet that I wrote that toggles from Bing to Google and vice versa.
Drag this to you favourites bar: Bing/Google Toogle
Note: Its tested on IE8 only. A few tweaks might be required for Firefox.
Minifying Javascript/css without changing file references in your source
Rule 10 of Steve Souders High Performance Web Sites: Minify Javascript
The most common problem faced while implemnting this is how you handle the full and minified version and how to change there reference in referencing documents. One of the easier ways to do this is to make it part of the deployment process.
Here are the relevent steps involved.
I’m using YUI Compressor.
Now you don’t want to replace all references to x.css or x.js in your development code with references to x-min.css and x-min.js respectively. So what you can do is rewrite all those filenames at the web server level.
For apache the following rewrite rules work fine:
Caution: Remember to delete existing minified css/js file before running the minifying script or you will end up with file names like x-min-min-min.js and so on. One way to do this is to clear the js/css folder before checking out files from your source repository.
Humanizing the time difference ( in django )
django.contrib.humanize is a set of Django template filters that adds human touch to data. It provides naturalday filter that formats date to ‘yesterday’, ‘today’ or ‘tomorrow’ when applicable.
A similar requirement which the humanize pacakge does not address is to display time difference with this human touch. so here is a snippet that does so.
Running Glassfish as a service on CentOS
Here is how you run glassfish as a service on CentOS:
- Create a user glassfish (you can call it anything you want) under which Glassfish will run.
#useradd glassfish
- Install glassfish in /home/glassfish.
- Create the startup script /etc/init.d/glassfish for glassfish.
- Install the service
#chmod +x /etc/init.d/glassfish #chkconfig --add glassfish #chkconfig --level 3 glassfish on
- Start glassfish.
#/etc/init.d/glassfish start
Embedding flash object in Facebook Apps (FBML)
Yesterday I was trying to include a flash object in a facebook app using FBML fb:swf tag. The flash object needed to change the url of the page it was running on on a particular event. But since facebook prevents direct script access from flash, this could not be done.
Here is a simple workaround:
1. Create a simple html page containing only the flash object that you want to include.
2. Embed this html on the facebook page using the fb:iframe tag.
Now you can make all the Actionscript calls you want to. Only caveat to this approach is that you will no longer be able to make Facebook API calls directly from flash.