The way to store config options in ruby without using ENV variables

# my_project/config.rb
module MyProject
  class Config
    attr_accessor :my_cool_option, :my_other_option

# my_project.rb
module MyProject
  def self.config
    @config ||=

  def self.configure

locales error after runing psql

To fix this really annoying bug:

vim /etc/environment
// Add to the end:

karma start not running any js tests

We should start karma directly from test folder or from root with next code:

karma start test/karma.conf.js

php mail() script with attachment

    if ((isset($_POST['contact_phone']) && !empty($_POST['contact_phone'])) || (isset($_POST['contact_email']) && !empty($_POST['contact_email']))){
      $tmpName = $_FILES['attachment']['tmp_name'];
      $fileType = $_FILES['attachment']['type'];
      $fileName = $_FILES['attachment']['name'];

      $headers = "From:";

      $message = '<h2>Получено новое сообщение. Данные:</h2><br><br><b>Имя: </b>'.$_POST['contact_name'].'<br><b>Телефон: </b>'.$_POST['contact_phone'].'<br><b>Email: </b>'.$_POST['contact_email']."<br><br><hr><p style='color: #ccc;'>Это письмо автоматическое и не требует ответа.</p><br>";

      if (file($tmpName)) {
        /* Reading file ('rb' = read binary)  */
        $file = fopen($tmpName,'rb');
        $data = fread($file,filesize($tmpName));

        /* a boundary string */
        $randomVal = md5(time());
        $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

        /* Header for File Attachment */
        $headers .= "\nMIME-Version: 1.0\n";
        $headers .= "Content-Type: multipart/mixed;\n" ;
        $headers .= " boundary=\"{$mimeBoundary}\"";

        /* Multipart Boundary above message */
        $message = "This is a multi-part message in MIME format.\n\n" .
        "--{$mimeBoundary}\n" .
        "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
        "Content-Transfer-Encoding: 7bit\n\n" .
        $message . "\n\n";

        /* Encoding file data */
        $data = chunk_split(base64_encode($data));

        /* Adding attchment-file to message*/
        $message .= "--{$mimeBoundary}\n" .
        "Content-Type: {$fileType};\n" .
        " name=\"{$fileName}\"\n" .
        "Content-Transfer-Encoding: base64\n\n" .
        $data . "\n\n" .

      mail('', 'Новое сообщение из формы сайта', $message, $headers);

Find/replace with regexp in sublime text example

find         - unless (.*)(blank\?$)
replace      - if $1present?

rake db cheatsheet

db:migrate runs (single) migrations that have not run yet.
db:create creates the database
db:drop deletes the database
db:schema:load creates tables and columns within the (existing) database following schema.rb

db:setup does db:create, db:schema:load, db:seed

db:reset does db:drop, db:setup

CKeditor rails gem with sourcedialog plugin

I’ve pushed CKeditor v. 4.0.11 with added sourcedialog plugin (allows you to edit code source).