Skip to content

Instantly share code, notes, and snippets.

@zismailov
zismailov / unicorn.rake
Created January 9, 2021 20:03 — forked from mdesantis/unicorn.rake
Rails tasks for managing unicorn server instances
# Tasks for managing Unicorn instances of a Rails application.
# Compatible with Ruby >= 1.9.2 and Rails >= 2 .
# Unicorn signals: http://unicorn.bogomips.org/SIGNALS.html
namespace :unicorn do
class UnicornPIDError < StandardError; end
def rails_env
Rails.env

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@zismailov
zismailov / install.md
Created September 4, 2018 12:00 — forked from srt32/install.md
installing PostGIS on OSX

Installing the Postgres PostGIS extension on OSX

For reference: http://postgis.net/install

If you don’t already have PG installed

The most reliable way to get PostGIS on OSX is to download and install Postgres.app. Great for development and testing. Do not mix with other installations. Select the extension when prompted.

If you already have PG installed

@zismailov
zismailov / attachment.rb
Created July 29, 2017 14:46 — forked from madwork/attachment.rb
Polymorphic attachments with CarrierWave and nested_attributes
class Attachment < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
# Associations
belongs_to :attached_item, polymorphic: true
# Validations
validates_presence_of :attachment
@zismailov
zismailov / embed
Created July 6, 2017 18:00 — forked from stereobooster/embed
share buttons snippet
<iframe frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?hl=ru&amp;ie=UTF8&amp;output=embed&amp;q={address}"></iframe>
@zismailov
zismailov / gist:33db71830bdf9b1dad9c757903f4ea1b
Created December 5, 2016 16:47 — forked from sharshenov/gist:793e6dee2c5bee9d82d6
Конфигурация elasticsearch для нужд небольших проектов(никакого HighAvailability & Load Balancing)
# Добавляем репозиторий для oracle java
add-apt-repository ppa:webupd8team/java
# Добавляем репозиторий для elasticsearch
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
echo "deb http://packages.elastic.co/elasticsearch/2.x/debian stable main" | sudo tee -a /etc/apt/sources.list.d/elasticsearch-2.x.list
# Обновить систему
apt-get update && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get clean
upstream application {
server unix:/home/deploy/apps/APPNAME/shared/tmp/sockets/puma.sock fail_timeout=0;
}
# Optional redirect
#server {
# listen 80;
# server_name www.DOMAIN default;
# return 301 $scheme://DOMAIN$request_uri;
#}
@zismailov
zismailov / backup_standby.sh
Created December 5, 2016 16:44 — forked from sharshenov/backup_standby.sh
Making PostgreSQL backup from standby server
# 1. Pause replication
sudo -u postgres psql -c 'SELECT pg_xlog_replay_pause();'
# 2. Perform backup
sudo -u postgres pg_dump -Fc DBNAME > /path/to/backup
#3. Resume replication
@zismailov
zismailov / .env.production
Created December 5, 2016 16:44 — forked from sharshenov/.env.production
capistrano + foreman deploy for RubyOnRails
SECRET_KEY_BASE=ahsbdjhasbjhdabks # run rake:secret to generate
DATABASE_URL=postgres://user:pass@dbhost/database
#возьмем, например, связь one-to-many и вложенными атрибутами
class Gallery < ActiveRecord::Base
has_many :images
accepts_nested_attributes_for :images
end
class Image < ActiveRecord::Base
belongs_to :gallery, required: true