Have you ever tried to debug javascript that works on focus/blur events? The moment the breakpoint stops on your onFocus method, suddenly the blur event is thrown because hey, the debugger is now focused, and not your element.
And it's not only that, timer events, and others are really tricky to debug, and you would generally just want to trace expressions, preferrably without changing the underlying code.
How can you then create trace calls, to see various variable states?
Well it's relatively simple, we will add tracer breakpoints:
First we will simple evaluate the previous function in the web console of your favourite browser.
Now we can simply add a conditional breakpoint, with a condition such as:
Since the breakpoint is evaluated in the context of the current stack, variables such as node will be accessible, if they are present in the code.
Also, since the function always returns false, the debugger won't stop there, thus no blur/focus events will be triggered.
If you also need a conditional breakpoint exactly at the line where the log is you can use as expression something along these lines:
Thus the log will take place, and since it's false, it will fallback in evaluating the actual value that you want the debugger to stop.
Pretty awesome.
Have fun debugging.
Whenever you want to add a custom style to your's site CSS, I generally see the general "solution" to add the CSS to the template itself, eventually add some extra custom PHP inside your template from the templates folder. I dislike this solution, because then you need to remember that your template is actually tainted, and you can't just install the template and your CSS, you again need to fiddle with its internals.
Don't you just want a simple javascript to add custom CSS to your joomla site, without changing the template source, or dig to its settings?
Thus I preffer to add a module that will add some JavaScript (tested on IE7+, and all normal browsers). I also get for free fine grained control (not that's terribly useful) on where I want my custom CSS, and where not, since now it's just a module I can assign:
<script type="text/javascript"> (function() { addCustomCss("my-custom.css"); function addCustomCss(name) { var css = document.createElement("link"); css.setAttribute("rel", "stylesheet"); css.setAttribute("type", "text/css"); css.setAttribute("href", name); var html = document.body.parentNode; for (var i = 0; i < html.childNodes.length; i++) { if (html.childNodes[i].tagName == "HEAD") { html.childNodes[i].appendChild(css); break; } } } })(); </script>
Obviously it can be seen that I can add multiple custom CSSes, but generally I preffer only one. Since the node is appended to the head later that the head element that was outputted by Joomla, I also get my custom CSS last, which helps when it comes to CSS rules priorities, since the last rule wins for the same selector precision.
I hope it helps, and have fun designing your Joomla site.
I remember once when we needed to deploy an application to a customer on two nodes using its RedHat Enterprise Linux, using JBoss 5.
Our prerequisites:
Because Java - compile once, run anywhere, right?
Wrong!
The customer comes back at us telling that our application deploys fine on one node, doesn't start on the other node - some really random runtime error deep inside JBoss.
"What the hell!" moment.
Obviously an environment difference, but which one?
Ok, can we get SSH access to investigate?
No.
Ok, we start ping-pong-ing emails with commands to give on the command line. Let's get the environment:
cat /etc/*release*
Same RHEL version.
JBoss?
Same exact version.
java -version
Working node: OpenJDK. Failing node: GCJ.
I'm baffled. Does the GCJ project still exists? Is anyone else beside Stallman still using it? Why is it installed?
I check their website thriving with news activity:
September 22, 2009
GCJ support on Windows (Cygwin and MinGW) targets has been enhanced with a number of bugfixes, and the option to build libgcj in DLL form for dynamic runtime linking.
Well, isn't that swell? Three years of nothing. Amazing.
I contact their admins and tell them to switch the failing node to OpenJDK.
What's wrong with this Java? they ask. Because it's in the repository, as java-gcj-compat.
A single tear rolls down my face, while I start typing a document explaining why GCJ is not really Java-Java, and how to upgrade it.
It was a bad day overall that day.
I think everyone needs from time to time this hashing method when it gets to work with user databases, for maintenance purposes.
As one who migrated from mysql to postgres - (actually I'm still dual using them) I was surprised to see this very useful function doesn't exist.
Don't worry, it's easy to add it.
On the terminal we first need to add the cryptographic libraries for postgres. The easiest way is to add the postgresql contrib, that contains a lot of goodies, and, of course, our crypto libraries. Also it is in the repository already.
$ sudo apt-get install postgresql-contrib-8.3
The next step would be exporting the cryptographic methods (except sha1 unfortunatelly) into the template from where each newly created database is derived:
$ sudo -u postgres psql template1 < /usr/share/postgresql/8.3/contrib/pgcrypto.sql
(in case you already have existing databases where you would need these functions, just change template1 to the corresponding database name, e.g.:
$ sudo -u postgres psql proddb < /usr/share/postgresql/8.3/contrib/pgcrypto.sql
)
Now we need to create our sha1 method (I've used the pgadmin3 tool in order to do that, but you can still use the psql approach for that).
As you can see the actual work is done by the more generic "DIGEST" method - which unfortunatelly returns a bytea, and converted to a string by the "ENCODE" method.
CREATE OR REPLACE FUNCTION sha1(bytea) RETURNS character varying AS $BODY$ BEGIN RETURN ENCODE(DIGEST($1, 'sha1'), 'hex'); END; $BODY$ LANGUAGE 'plpgsql'
If you want this method to be in every new table from now on, you could put it in some file (let's say sha1.sql) and run it against the template1.
$ sudo -u postgres psql template1 < ~/sha1.sql
After that, a simple
select sha1('test')
should return as expected:
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
Hoping it helps, I'll end here.
After reading Struts 2 in Action (a definite read for people who have no experience at all using struts 2), and after finishing a project and actually delivering it to the customer, and in the middle of the second one, I've decided to write down the best practices that I follow.
The reason why i'm writing this is that I couldn't find real case examples of good patterns to follow in developing a struts2 application, even the best practices from that book are quite slim, and I'm not going to reiterate them here.
<dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-junit-plugin</artifactId> <version>2.1.8.1</version> </dependency>
A "full" action implementation would be along these lines, so it is imediatelly clear what it does, what validations does it require, and is trivial to test:
public class RegisterUserAction extends ActionSupport { // ... private String username; // + getter/setter @EJB private UserService userService; // no getter/setter, set by interceptor public void validate() { // custom complex validations } @Validations( // ... most of the time validate() is not needed. ) public String registerUser() { try { userService.registerUser(username); } catch (Exception e) { LOG.error(e.getMessage(), e); addFieldError("some_field", getText("some_specific_error_key"); return INPUT; } return SUCCESS; } // execute is mapped as excluded in struts.xml for validations public String execute() { return SUCCESS; } // ... }
That would be it. As usual, I'm extremely interested in your feedback.
Have fun programming with struts 2.
The one to rule them all. The browsers that is.
SharpKnight is an Android chess game.
MagicGroup is an eclipse plugin.