This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create_table :products do |t| | |
# t.integer :price_in_cents | |
# ... | |
# end | |
class Product < ApplicationRecord | |
VAT = 25 # % | |
def price_in_eur | |
price_in_cents / 100.0 | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchForm | |
include ActiveModel::Model | |
%i[query lat lng].each do |name| | |
define_method name do | |
@params[name] | |
end | |
end | |
def initialize(params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= mdc_form_with model: @my_model do |f| %> | |
<%= f.mdc_text_field :last_name %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Extend Chosen with custom method or owerwrite existing methods | |
class CustomChosen extends Chosen | |
show_search_field_default: -> | |
# ... | |
# original method updated | |
# ... | |
some_new_method: -> | |
# ... | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# fake_sign_in | |
# fake_sign_in(@user) | |
# fake_sign_in(@admin) | |
# fake_sign_in(:admin) | |
# fake_sign_in(@some_object, :scope => :user) | |
# fake_sign_out | |
# fake_sign_out :admin | |
module ControllerHelpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Encrypt | |
openssl aes-256-cbc -salt -in filename.ext -out filename.enc | |
# Decrypt | |
openssl aes-256-cbc -d -salt -in filename.enc -out filename.ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ** ERROR 1 ** | |
# FATAL: lock file "postmaster.pid" already exists | |
# HINT: Is another postmaster (PID 4646) running in data directory "/usr/local/var/postgres"? | |
# | |
# ** ERROR 2 ** | |
# Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? | |
# | |
# To fix one of this errors: | |
cat /usr/local/var/postgres/postmaster.pid # pid is the number on first line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Appointment < ApplicationRecord | |
belongs_to :inquiry | |
enum appointment_type: { default: 0, q1: 1, q2: 2 } | |
scope :q1, -> { where(appointment_type: q1) } | |
scope :on_date, -> (date) { where(scheduled_date: date) } | |
before_validation :set_start_and_end_time | |
def duration | |
[15, 30, 45].sample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
video_code, video_width, video_height = 'nkYA1xqrdGw', 938, 555 | |
video_embed_params = { :fs => 1, :rel => 0, :hd => 1, :autoplay => 1, :modestbranding => 1, :version => 3, :enablejsapi => 1, :playerapiid => "ytplayer" } | |
player_wrapper_id, player_id = 'ytPlayerWrapper', 'ytPlayer' | |
%> | |
<% unless mobile_safari_request? %> | |
<% content_for :head do %> | |
<%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
set -e | |
source /opt/change-java-version.sh | |
change-java-version 8 | |
wget -O - https://debian.neo4j.org/neotechnology.gpg.key | sudo apt-key add - | |
echo 'deb http://debian.neo4j.org/repo stable/' >/tmp/neo4j.list | |
sudo mv /tmp/neo4j.list /etc/apt/sources.list.d | |
sudo apt-get update |
NewerOlder