Tuesday, September 24, 2013

Git reload remote branche list


Tip: When you delete branches using git branch -d <branchname> or git push origin :<branchname> the reference is only deleted locally. This means that for other team members the deleted branches are still visible when they do a git branch -a. To solve this your team members can prune the deleted branches with git remote prune <repository> , this is typically git remote prune origin.

Tuesday, August 27, 2013

Capistrano postgresql error when running cap deploy:update

....
Can't find the 'libpq-fe.h header
....
Fix:
yum install postgresql-devel # or apt-get install ....

Monday, August 12, 2013

Nginx startup scripts

Create nginx startup script in /etc/init.d/nginx
cd /opt
wget -O init-rpm.sh http://library.linode.com/assets/603-init-rpm.sh
mv /opt/init-rpm.sh /etc/rc.d/init.d/nginx
chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

via: linode

Mac os mysql localhost / 127.0.0.1 problem

Mac os fix localhost / 127.0.0.1 problem: Add to php.ini:
pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket = /tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock
restart apache server:
sudo apachectl restart

Thursday, August 1, 2013

Postgres rails socket problem

Postgres problem in rails
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Resolve:
mkdir /var/pgsql_socket/ 
ln -s /private/tmp/.s.PGSQL.5432 /var/pgsql_socket/
via: http://jaygoldman.com/2012/11/fixing-postgres-connection-errors-on-mountain-lion/

Friday, June 14, 2013

Translation problem in mysql phpmyadmin

For new versions of mysql edit /etc/mysql/my.cnf
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
Restart mysql service here Check results using :
mysql> show variables like 'char%';
mysql> show variables like 'collation%';

Friday, May 17, 2013

Cyrilic \w+ problem

Just case. RegExp don't like cyrilic symbols and willn't be processed by '\w+' so use [\u0400-\u04FF] for this case.

Friday, April 19, 2013

Rails forgotten notes

For bulk data inserts within one transaction use:
  ActiveRecord::Base.transaction do
    SomeModel.create()...
  end

Monday, February 4, 2013

Add html element behaviour to drop files

Use for you own risk, early dev version. No iframe, flash or other stuff. Js only.
First create helper object for adding and removing dragenter, dragleave, dragover, drop handlers and form submission using js FormData object. Modules structure code inspired by Raqy.Style code.
App = App || {};

(function($) {'use strict';
    // used to disable <body> files dropping
    function _disableBody() {
    $(document).bind('dragenter', function(e) {
        return false;
    }).bind('dragleave', function(e) {
        return false;
    }).bind('dragover', function(e) {
        var dt = e.originalEvent.dataTransfer;
        if (!dt) {
            return;
        }
        dt.dropEffect = 'none';
        return false;
    }.bind(this));
 }
    // add all handlers for specified selctor
    function _enableDrop(selector, options) {
        $(selector).bind("dragover", function(e) {
            options.dragover && options.dragover(e);
                return false;
            }).bind("dragenter", function(e) {
            options.dragenter && options.dragenter(e);
                return false;
            }).bind('dragleave', function(e) {
                options.dragleave && options.dragleave(e);
                return false;
            }).bind("drop", function(e) {
                options.drop && options.drop(e);
                return false;
            });
    }

 var module = {
  disableBody : _disableBody,
  enableDrop : _enableDrop,
 };

 // register new namespace
 App.DropArea = module;

})(jQuery);
Form sending helper:
(function($) {'use strict';
    var opts = {
        form : null,
        response : null
    }
    function mergeDataToFormData(formData, data) {
        $.each(data, function(k, v) {
            formData.append(k, v);
        });
        return formData;
    }

    function _send(options) {
        var opts = {
            url : options.url,
            type : 'POST',
        };
        if (options.beforeSend) {
            opts.beforeSend = options.beforeSend;
        }
        if (options.error) {
            opts.error = options.error;
        }
        var data = new FormData(options.form ? $(options.form)[0] : {});
        if (options.data && data != undefined) {
            data = mergeDataToFormData(data, options.data);
        }
    return $.ajax($.extend(opts, {
            success : options.success,
            data : data || {},
            cache : false,
            mimeType : 'multipart/form-data',
            contentType : false,
            processData : false
        }));
    }

    var module = {
        send : _send
    };

    App.FormDataSend = module;

})(jQuery);
Add drop behaviour:
"#files-drop-area" - block for adding handlers.
"/FileUpload" - url for submitting file form
App.DropArea.disableBody();
App.DropArea.enableDrop('#files-drop-area', {
    dragenter : function(e) {
        $(e.target).css('border', '1px solid #3F3F3F');
    },
    dragleave : function(e) {
        $(e.target).css('border', '0px');
    },
    drop : function(e) {
        e.preventDefault();
        var dt = e.originalEvent.dataTransfer;
        if (!dt && !dt.files)
            return;

        var root = $(e.target);
        var files = dt.files;
        var cntFinished = 0;

        var finishCallback = function(current, cnt) {
            if (current >= cnt) {
                root.css('border', '0px');
                // restore original state of uploading form: remove progress, hide messages etc ..
            } else {
                // show info about uploading (console)
                console.log('Uploaded: ' + current + ' / ' + cnt + ' images.');
                 // show progress message, loading indicatiors etc...
            }
        }
        for (var i = 0; i < files.length; i++) {
            finishCallback(cntFinished, files.length);
            // max allowed size for file checking, client side, fired immediate after 'drop'
            if (files[i].size > 2097152) {
                cntFinished++;
                finishCallback(cntFinished, files.length);
                console.log('File too big: ' + files[i].name);
                continue;
            }
            // send ajax form with file
            App.FormDataSend.send({
                url : '/FileUpload',
                data : {
                    'id' : 100500, // data for sorm submitting
                    'filename' : files[i]
                },
                error : function(e) {
                    cntFinished++;
                    finishCallback(cntFinished, files.length);
                    // show in form , if you need it
                    console.log('Error uploading file:' + e.responseText);
                },
                success : function(responce) {
                    cntFinished++;
                    finishCallback(cntFinished, files.length);
                    // I have json object as responce
                    var rObjs = jQuery.parseJSON(responce);
                    if (rObjs.error == false) {
                        // process added image object 'rObjs'
                    } else if (rObjs.error == true) {
                        // server-side errors, probably validation or allowed size etc 
                        // captured by form handler code
                    } else {
                        // else server-side errors
                    }
                }
            });
        }
        return false; // use this, or image will be displayed in browser, IMPORTANT !
    }
});

Sunday, January 27, 2013

javascript inheritance example

Js inheritance function, found somewhere in internet, and adapted as helper function for App object in application.
var App = {};

App.inherit = (function() {
 function Nothing() {
 }

 return function(child, parent) {
  Nothing.prototype = parent.prototype;
  child.prototype = new Nothing;
  child.prototype.constructor = child;
  child.superproto = parent.prototype;
  return child;
 };
})();
Simple usage for view and edit modalboxes:
(function($) {'use strict';
 /*
  * SHOW window
  */
 function ModalWindow(options) {
    // init elements and load content here
 }
 ModalWindow.prototype.constructor = ModalWindow;

 ModalWindow.prototype.close = function() {
    // close handlers
 }
 /*
  * EDIT window
  */
 function EditModalWindow(options) {
    // aka parent constructor
    ModalWindow.call(this, options);
    // init save functionality , append buttons, handlers...
 }

 App.inherit(EditModalWindow, ModalWindow);

 EditModalWindow.prototype.save = function(e) {
    // save handler
 };

     App.EditModalWindow = EditModalWindow;
     App.ModalWindow = ModalWindow;
})(jQuery);
var modal = new App.ModalWindow({
    // options
});
var editModal = new App.EditModalWindow({
    // options
});

Php fpm

yum install php-fpm php-common php-gd php-cli php-curl