Saturday, August 23, 2014

Template method pattern ruby



class ReportGenerator
  
  def initialize
    @report = ""
  end
  
  def output
    prepare_header
    prepare_body
    prepare_footer
    @report
  end
  
  def prepare_header
    raise "Prepare header should be implemented"
  end
  def prepare_body
    raise "Prepare body should be implemented"
  end
  def prepare_footer
    raise "Prepare footer should be implemented"
  end
end

class TxtReportGenerator < ReportGenerator
  def prepare_header
    @report << "Txt Report header \n"
  end
  def prepare_body
    @report << "body \n"
  end
  def prepare_footer
    @report << "footer \n"
  end
end

class PdfReportGenerator < ReportGenerator
  def prepare_header
    @report << "Pdf Report header \n"
  end
  def prepare_body
    @report << "some encoded body \n"
  end
  def prepare_footer
    @report << "encoded footer \n"
  end
end

txt = TxtReportGenerator.new
pdf = PdfReportGenerator.new

puts txt.output
puts pdf.output

Saturday, March 22, 2014

Mac OS Vagrant interfaces failure

If You see this:
....
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
Just do this:
$ sudo /Library/StartupItems/VirtualBox/VirtualBox restart
It will re-create virtual adapters for VB installation.

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/