32 cards
Linked contentRepeats

Setting up Javascript environment with NVM on Ubuntu 14.04

NVM provides you more convenient way to manage and set up your Javascript(Node.js) environment.

First install NVM, note git must be installed on your sistem:
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout git describe --abbrev=0 --tags
To activate nvm, you need to source it from your shell:
cd # go to home folder
source ~/.nvm/nvm.sh
If you want to see what versions of Node.js are available to install:
nvm ls-remote
To install Node.js v0.11.14 just run:
nvm install...


Install gems without those which in production group

For that purpose, just use these command:

bundle install --without production

Run rake tasks from ruby script

require 'rake'

rake = Rake.application
# you can import addition *.rake files
# app.add_import 'some/other/file.rake'

Rspec + Capybara + Rails4 + Spork (intergation tests setup with selenium and poltergeist)

Add in Gemfile:

group :development, :test do
  gem 'rspec-rails'
  gem 'spork-rails'

group :test do
  gem 'capybara'
  gem 'database_cleaner'
  gem 'email_spec'
  gem 'poltergeist'
  gem 'launchy'
  gem 'selenium-webdriver'

Run bundle install

Ensure your spec_helper.rb looks similar with this:

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
# require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to ...

ActiveRecord models localization

Suppose we have some model and we want to localize it, first of all we need to now i18n_key for that model. Open rails console rails c, and run:


For example let's do that for model, defined in public_activity gem:

#=> :"public_activity/activity"

Now, we cat easily localize it, by adding this in .yaml file:

    public_activity/activity: 'Our localized model name'

In the same way we can locali...


Ubuntu 12.04 phantomjs installation

Visit PhantomJS site, go to download page and copy link address for Linux, in our case this is https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2

Then go to console and run following commands:

sudo apt-get install libfontconfig libfontconfig-dev libfreetype6-dev

wget https://phantomjs.googlecode.com/files/phantomjs-1.9.2-linux-x86_64.tar.bz2
sudo mv phantomjs-1.9.2-linux-x86_64.tar.bz2 /opt
cd /opt
tar -xvf phantomjs-1.9.2-linux-x86_64.tar.bz2
ln -s /opt/phantomjs-1.9.2-linux-x8...

Linked contentRepeats

Ubuntu 12.04 TeamCity build agent installation

Download build agent archive from your TeamCity server:

wget http://your_teamcity.server.com:8111/update/buildAgent.zip

Unzip it in separate directory:

mkdir buildAgent

mv buildAgent.zip buildAgent
cd buildAgent
unzip buildAgent.zip
chown -R your_user:your_group ../buildAgent

Copy agent's settings file:

cp conf/buildAgent.dist.properties conf/buildAgent.properties

Edit this file:

nano conf/buildAgent.properties

There are fields which you must update:

# your TeamCity server address:


Linked contentRepeats

Jasmine - how to run specific it or describe block?

Just mark needed describes and its as ddiscribe and iit, and next time you run tests only ddiscribes and iits will be executed. In Jasmine version >= 2.0 use fit and fdescribe respectively.


How to create Nokogiri node if node name collide with Nokogiri::XML::Builder methods

Suppose you want to create node with name text, but this method already present in Nokogiri::XML::Builder. The solution is to add underscore after node name:

Nokogiri::XML::Builder.new do |xml|
  xml.text_ 'something' # this should create node with name 'text'

Get node's parent element with Capybara

To get parent of Capybara's node do the following:

node = page.find '#selector'
parent = node.find(:xpath, '..')
parent_of_parent = node.find(:xpath, '../..')


Firefox only css rules

For css rules only for Firefox use this container:

@-moz-document url-prefix() {
    height: auto;

Ant handbook

Check conditions example:

<!-- run command -->
<target name="t_name">
 <exec executable="command" failonerror="true" outputproperty="exec.out" errorproperty="exec.err" resultproperty="exec.rc" >
    <arg value="arg"/>

<!-- check conditions -->
<target name="checkresult">
    <condition property="errors">
            <equals arg1="${exec.err}" arg2="0" />
    <echo message="errors: ${errors}"/>


Linked contentRepeats

Generating SSH Keys

If you don't have ssh key, open terminal and run following commands:

cd ~/.ssh

ssh-keygen -t rsa -C "your_email@example.com"

When you have ssh key, just copy public part to clipboard:

xclip -sel clip < ~/.ssh/id_rsa.pub

To install xclip run:

sudo apt-get install xclip

Then add to GitHub or GitLab keys in profile settings


Prevent outline button shadow in Chrome

      outline-style: none;

Capistrano deploy.rb examples

All examples here for deploy RoR application with unicorn, staging machine (where we deploys) available via ssh by ssh_key.

  1. Deploy via remote_cache:

     require 'rvm/capistrano'
     require 'bundler/capistrano'
     set :application, '_proj_'
     set :rails_env, 'production'
     set :domain, '_user@your_deploy_domain_'
     set :deploy_to, "_path_to_#{application}"
     set :use_sudo, false
     set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb"
     set :unicorn_pid, "#{deploy_to}/shared/pids/u...
Linked contentRepeats

SSH config for simplify connection to many similar hosts

Suppose you have three hosts (host.one.domain.name, host.two.domain.name host.three.domain.name) with the same credentials, with access by ssh key, then any time when you need to connect to host you must type something like this:

ssh user@host.one.domain.name -i path/to/key_file

ssh user@host.one.domain.name -i path/to/key_file

You can simplify your life by creating file ~/.ssh/config, with content:

Host one two three
  HostName host.%h.domain.name
  User user
  IdentityFile path/to/key_file

And now ...


Ubuntu postgresql 9.3 installation for RoR

Add repository and install Postgresql:

sudo sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main' > /etc/apt/sources.list.d/pgdg.list"
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql-common
sudo apt-get install postgresql-9.3 libpq-dev

Then make yourself a Postgresql superuser:

sudo su postgres

createuser your_system_login
ALTER ROLE your_system_login WITH SUPERUS...


Rails migration add float point field with scale and precision

class CreateFakes < ActiveRecord::Migration
  def change
    create_table :fakes do |t|
      t.decimal :float_value, :precision => 4, :scale => 3

This will allow you to have 3 digits after the decimal point and 4 digits max.

This website uses short-lived cookies to improve usability.
Accept or learn more