Tag: tips

Split SQL dump into smaller files

In larger projects database can grow to impressive sizes of several gigabytes. I recently found myself needing to restore a table from a backup. But my texteditor was unable to open the dump.sql files of several gigabytes. So I whipped up a small PHP script that splits the file into small chunks of 1 MB each.

The table I was looking for was not that big, so the the CREATE and INSERT statements related to the table would end up into one file. A small ‘Find in files’ search would then reveal the file to check.

This method will work for any type of file, not only .sql files.

<?php
$fp = fopen('dump.sql', 'r');

$iter = 1;
while (!feof($fp)) {
    $fpOut = fopen($iter . '.sql', 'w');
    fputs($fpOut, fread($fp, 1024*1024));
    fclose($fpOut);
    $iter++;
}

Leave a Comment

Simple javscript development using http-server

When developing small javascript projects I find the overhead of configuring a
virtual host in Apache or nginx cumbersome. The http-server module in node.js allows
you to easily start a webserver within your project folder.

Make sure node.js is installed and install the following module:

npm install http-server -g

The -g option install the module as a global one, meaning that you can start the
webserver from every folder. You can now go to any folder you’d like and issue the
following command:

http-server

This will result in the following output:

Starting up http-server, serving ./ on: http://0.0.0.0:8080
Hit CTRL-C to stop the server

You can now access all files in the folder via http://127.0.0.1/ in your webbrowser.

More information on this module can be found on the http-server project page. There
are several configuration options for configuration the port, ip address, etc.

Leave a Comment