Coding

MySQL Pop Quiz

When we are learning something new we’re going through the next steps.

  • Reading manual, books, trying samples from there
  • Doing something, basing on the knowledge we already have
  • Solving/answering interesting quizes/questions

But there is not much questions/quizes about MySQL, and the recent one is a popular Carsten’s MySQL Pop Quiz serie. We can get a lot off usefull information from such quizes . So, I’ve translated it to russian. I hope it could be usefull for some of us how doesn’t know english well :)

Starting Grails application with custom path

I am speaking about development mode. When you start your application with “grails run-app” by default it will be located at http://localhost:8080/[your application name]. But what if we’d like to start our aplication for example in a server root? Or in any other custom path?

Lets try to do this! The steps are following:

  • application.properties - add the value app.path=/MyApp, where /MyApp is the path with which you’re going to access your web-application
  • Then you should need to modify some scripts in your Grails installation. The first one is $GRAILS_HOME/scripts/Init.groovy. Add: grailsAppPath = “/” (near of “grailsAppName = null”, in 1.0.2 it is line 75), and grailsAppPath = props.’app.path’ (line 101, near of grailsAppName = props.’app.name’)
  • The rest is to modify $GRAILS_HOME/scripts/RunApp.groovy: event(”StatusFinal”, [”Server running. Browse to http://localhost:$serverPort${grailsAppPath}”]) (line 70) and webContext = new WebAppContext(”${basedir}/web-app”, “${grailsAppPath}”) (line 117)

Now you can start your application with “grails run-app”! Notice that if you want use https then you should also make similar changes in $GRAILS_HOME/scripts/RunAppHttps.groovy file. I’ve mentioned line numbers but it is for 1.0.2 version only.

Exception #07

You can read in russian my report on Exception #07 conference. In brief - this was a great experience for me. And in the nearest future I’ll share all materials.

Opensource GoogleGears

The last day I’m suffering from different thoughts. So I’ve decided to share’em with you.

It is really possible to create the application such as gears, but independent from Google, that will run on most platofrms and browsers. What we need:

  • Compile embeded MySQL (very lite edition) for most platforms (Windows, Linux and MacOSX, I believe that would be enough)
  • Create Java Applet and JNI-wrapping library to access MySQL
  • Create JavaScript library that will access MySQL through the applet

And that’s all. To use it you will need just to include the applet and JS-library into your page, after the first load applet will detect platform and will download embeded MySQL and native libraries.

Firebug on FF3

Since you are happy Firefox 3 user - you can not use Firebug, official firebug. But I’ve found FF3 compatible one. Of course, all changes in Fireclipse are trivial enough, but it is a pleasure when something is already done before you.

Enjoy!

PHP + MySQL on Leopard

I’ve just tried to run PHP with MySQL on my Leopard and the first problem: “Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’”

I’ve just changed php.ini to:
mysql.default_socket = /tmp/mysql.sock
The same situation with mysqli settings - be default it is not set so you should update it to the real path.
And it works!

Profiling MySQL/Hibernate applications

Last week we’ve found that our application runs not so fast as we wished. This was a complicated webservice application with many services/methods and each serivce method is accessing MySQL (InnoDB) database through the Hibernate layer.
In Hibernate layer we used Criteria API to make queries, so in the source code is impossible to view exact queries which will run.
So I’ve found two solutions how can we profile our application.

1. It is possible to turn on hibernate option “hibernate.show_sql=false” and check each query in the mysql console with MySQL query profiling

2. And the second solution was Elvyx.

I’ve chose the second one.

It is needed just to replace jdbc driver with the Elvyx’s one, setup Elvyx driver to use the driver you used before (in my case that was com.mysql.jdbc.Driver), and start Elvyx server (with GUI) to see profiling results.

Small tip for blogger.com users

If you do not like the navigation panel (the bar in the top of the page) - you can hide it.
Just add the following javascript in your site template:

function hidenav() {
document.getElementById(’navbar’).style.display=’none’;
}

Then add onload=”hidenav()” to the body HTML tag

That’s all. Have fun.

MyWebER is going to die

My google summer of code project called MyWebER is going to die. The reason - I have no time to proceed developing it. I have a lot of ideas, but not sure that I’ll find any time to implement them.

As I can see, MySQL AB is not interested in this project. If anyone wants to help me - you’re welcome.
“Skilled JavaScript developers are wanted.” (C)

JS delay

    var ss = “qq”;
    for (ii = 0; ii < 1000; ii++) {
        ss += “ffff”;
    }

An interesting way…

Luhn (scheme implementation)

(define luhn-check
  (lambda (ccn)
    (define csum 0)
    (define num 0)

    (do ((i (string-length ccn) (- i 1)))
      ((<= i 0) (print csum))

      (set! num (string->number (substring ccn (- i 1) i)))
      (if (> (modulo i 2) 0)
                        (begin

                         (set! num ( * 2 num))
                         (if (> num 9) (set! num (- num 9)))))

      (set! csum (+ num csum))
      )))
;; test case
(luhn-check “4561261212345467″)



And here is implemented with MySQL.

JavaScript onLoad problem

Sometimes we have to open new browser window and invoke some code in it when it loads.

The first thing I’ve tried was: childWindow.onload = function () {/* Action goes here */;};

But it doesn’t work in IE! At first look it could seem strange. But the solution is very simple.

childWindow.onload = function () {/* Action goes here */;};

if (childWindow.attachEvent) {childWindow.attachEvent(”onload”, childWindow.onload);};

The second line will be executed in IE only and will solve the problem. Actually this is due its event model and nothing more :)

MyWebEr - creating documentation on the fly

In my last post I’ve asked for any help on my project. So, tanks to Jay Pipes for his tip.
One of most developer problems is documentation. And a good solution was initially appeared in Java with javadoc. At now many languages have special javadoc-like tools. I’ve made a little research, and decided to use jsdoc and phpdoc in my project. I am still open for any suggestions :)

MyWebEr - info

So, now I am working on this project. This project is a part of google SoC. I believe in the end it should be something like mysql workbench, but web-two-zerofied. At current moment there is not much to look into (http://myweber.googlecode.com/svn/trunk/). But I will be very grateful to you for any comments, questions and suggestions.

Eval is evil

A piece of JavaScript:
var total = total + parseFloat(eval(’document.frm.smth’ + x + ‘.value’));

var tmpTotal = eval(’parseFloat(document.frm.smth.value)’ + action + ‘parseFloat(price)’);

- Next »