Wednesday, 11 January 2012

Faster transactions in PostgreSQL

First of all: BE WARNED! 

These settings are not recommended for all of you (if any) in production as they might cause you data corruption or loss in case of sudden hardware failure.
I would on suggest to have these settings used in a development environment, where you have to run many tests for your application which include database side create/drop transactions.

My case here was that I ran so much database inclusive tests, that I got fed up with PostgreSQL's ~6s database creation time. So I just Googled it a few days how this could be done in a dev env. So here it is, you just set these two variables in your postgresql.conf file and reastart the database.

Sunday, 8 January 2012

How do I install my Nginx with Passenger

While there are pretty much use to run a project in standalone Passenger I'd rather run it with the web server of the production environment. My choice is Nginx. Not because of it's high load speed as I do not (yet) run any high visited websites or loaded applications, but I have found it's configuration simpler then Apache's. Yes, not modular, you cannot enable, disable some things in runtime, but hey I do not really need that either.

So basically I download the nginx source, extract it somewhere. Install the passenger gem. Then run this command:

rvmsudo passenger-install-nginx-module


If it finds every package installed - note that you might need libpcre3 and libpcre3-dev packages too on Ubuntu - then I choose the option 2 which will let me configure nginx further. When it asks for the extra arguments for configure I use these:

--prefix=/etc/nginx --user=www-data --group=www-data --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-cpu-opt=amd64 --without-http_userid_module --without-http_upstream_ip_hash_module --without-http_ssi_module --without-http_split_clients_module --without-http_scgi_module --without-http_proxy_module --without-http_geo_module --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/lib/nginx/proxy --with-http_gzip_static_module --with-http_ssl_module --without-http_browser_module --without-http_limit_req_module --without-http_limit_zone_module --without-http_map_module --without-http_memcached_module --without-http_referer_module

Note I have --with-cpu-opt=amd64 enabled as my virtual machine can use my CPU directly, which is now a AMD Phenom X6.

All done, let the compilation begin! When it's finished we are good to go to use nginx by it's command.

If you have questions feel free to ask in a comment!

Thursday, 5 January 2012

Mount Windows share on Ubuntu with CIFS

The package that is needed to be installed is called smbfs.

For permament mount at every boot add something like this to /etc/fstab:

//192.168.0.65/privatefolder /media/servfolder cifs username=xxxxx,password=yyyyyy,uid=1000,gid=1000,file_mode=0777,dir_mode=0777noserverino,rw,nolinux,iocharset=utf8 0 0

As a shell script, the command would be like this:

mount -t cifs //192.168.x.x/hostdir /opt/clientdir -o username=hostuser,password=hostuserpass,uid=1000,gid=1000,file_mode=0664,dir_mode=0775,noserverino,rw,iocharset=utf8

Wednesday, 4 January 2012

How to center a DIV in a DIV

HTML:

<div id="outer" style="width:100%">
    <div id="inner">Foo foo</div>
</div>


CSS:

#inner {
    width: 50%;
    margin: auto;
}

Tuesday, 3 January 2012

Vim: Format different type of code in one file

Let's say you have a PHP file with some HTML code mixed in.

:set filetype=html

And then highlight your text and hit  = . BOOM! HTML formatting succes.