Importing/exporting data with MySQL 0

This is more of a note-to-myself entry to dig it up later easily, but the syntax to import dump file to MySQL is:

mysql -p -h database_server -u mysql_user mysql_dbname < file_dbname.sql

The same way mysql dump can be created:

mysqldump -p -h database_server -u mysql_user mysql_dbname > dump_file.sql

Good resource with more on this is here.

Javascript vs. women 0

I am relatively new to Javascript, but I have come to one conclusion already: Javascript is like women – you quickly realize there is some problem with it, but it takes unreasonable amount of time and effort to locate the problem.

Though there is also one major difference – Javascript problems get solved fast once located..

Get query string variables of Javascript files 1

Looking at different scripts linking to Javascript and AJAX frameworks such as Scriptaculous, I noticed that it allows loading of particular parts of it by adding them in the following query string such as this:

<script type="text/javascript" src="scriptaculous.js?load=effects,builder"></script>

Looking at scriptaculous.js itself, it relied on some built-in functionality for that. I was unsuccessful in finding online a ready function to do exactly that, so inspired by this piece of code and borrowing the regex part of it, I wrote a function which grabs the additional parameters and allows using them in the Javascript:

function getJSvars(script_name, var_name, if_empty) {

var script_elements = document.getElementsByTagName(’script’);

if(if_empty == null) {
var if_empty = ;
}

for (a = 0; a < script_elements.length; a++) {
   var source_string = script_elements[a].src;
       if(source_string.indexOf(script_name)>=0) {

       var_name = var_name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
       var regex_string = new RegExp("[\\?&]"+var_name+"=([^&#]*)");
       var parsed_vars = regex_string.exec(source_string);
       if(parsed_vars == null) { return if_empty; }
       else { return parsed_vars[1]; }

      }
   }
}

Usage of it is simple: if you have a Javascript which should parse some dynamic variables (such as user or account ID), you can include it right after the included Javascript like this:

<script type="text/javascript" src="script.js?var1=value1&var2=value2"></script>

instead of creating a server-side generated dynamic Javascript using PHP or other language. The values of variables like var1 can be retrieved like this:

var var1 = getJSvars(’script.js’, ‘var1′);

You can also add a value as third parameter to output in case var1 is empty, but it is optional.

Now this is scary 0

Could you possibly imagine it is this easy to capture what is typed on your keyboard? Wirelessly.. even through a wall!

Read more »

Performance: PHP4 vs. PHP5 0

I was doing optimization of one high-traffic PHP application, which had around 2 million page-views and 20 million MySQL queries per day, and was running on a dedicated Linux server. I listed all the possible sources of high CPU consumption and server load which could be optimized. One of the possibilities was upgrading PHP version as the application was running on PHP4 due to incurred problems with PHP5 when it was previously running on shared hosting. Therefore it used PHP5 only for features that relied on the new functions of it. Also, I had read general conclusions online that performance of PHP5 is better than of PHP4, so I had to look into this. Read more »

Welcome! 1

In this web site you will find different useful on-line tools, code snippets, maybe even different ideas and thoughts on different topics. The purpose of this web site is to serve more like a personal notepad, but it is aimed also to be useful for others.