Skip to content

Instantly share code, notes, and snippets.

@afa
afa / 00_README.md
Created January 20, 2017 08:03 — forked from mikechau/00_README.md
Logging Rails 4 to Syslog, formatted w/ Logstash

Logging Rails 4 to Syslog, formatted w/ Logstash

Getting Started

Steps to get Rails 4 saving its output to Syslog via Rsyslog. This assumes you are on CentOS, but should be pretty adaptable to any other distribution. Ruby 2.0+ is also required.

  1. Add the gems lograge and logstash-event to your Gemfile. Feel free to remove from production if you'd like to test it in development as well or something.
  2. Update production.rb with the lograge settings and set the logger to Syslog::Logger.
  3. Add the conf files to /etc/rsyslog.d/. /etc/rsyslog.conf should have $IncludeConfig /etc/rsyslog.d/*.conf enabled, so it will load any additional configs from /etc/rsyslog.conf.
@afa
afa / Gemfile
Created December 23, 2015 09:40 — forked from gvarela/Gemfile
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"
@afa
afa / feature_macros.rb
Created November 13, 2015 10:23
Tuning capybara + capybara-webkit + database_cleaner + DeferredGarbageCollection + feature macros
# spec/support/feature_macros.rb
module FeatureMacros
extend ActiveSupport::Concern
# get current domain ("lvh.me:12345")
def domain(port = Capybara.current_session.server.try(:port) || 3000)
port &&= ":#{ port }"
"#{ DEFAULT_HOST }#{ port }"
end
# Build an inverted index for a full-text search engine with Redis.
# Copyright (C) 2009 Salvatore Sanfilippo. Under the BSD License.
# USAGE:
#
# ruby invertedindex.rb add somedir/*.c
# ruby invertedindex.rb add somedir/*.txt
# ruby search your query string
require 'rubygems'
require 'redis'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/sh
#
# init.d script for single or multiple unicorn installations. Expects at least one .conf
# file in /etc/unicorn
#
# Modified by [email protected] http://github.com/jaygooby
# based on http://gist.github.com/308216 by http://github.com/mguterl
#
## A sample /etc/unicorn/my_app.conf
##
@afa
afa / gist:8434886
Created January 15, 2014 11:51 — forked from anaumov/gist:8432161
class CarConfig
include ActiveSupport::Configurable
config_accessor :brand
end
class Car
attr_accessor :brand
def initialize
self.brand = self.class.config.brand

Когда мы хотим скопировать данные из production окружения Ruby on Rails приложения в development или staging, обычно, нам нужно скопировать дамп базы данных и статические файлы (например, изображения загруженные пользователями). Копирование базы может не представляет проблем (например, ее можно копировать из бэкапов или резервных серверов БД). А вот копирование статических файлов занимает много времени и ресурсов сервера с которого копируют (и на который копируются) файлы.

В рассылке ror2ru Макс Лапшин предложил

@afa
afa / README
Created May 31, 2013 09:22 — forked from andoriyu/README
unicorn_profiles="dev prod"
unicorn_dev_enable="yes"
unicorn_dev_user="devuser"
unicorn_dev_listen="/tmp/unicorn.dev.socket"
unicorn_dev_dir="/usr/local/www/dev"
unicorn_dev_config="/usr/local/www/dev/config.ru"
unicorn_dev_env="development"
unicorn_dev_flags="" # any additional flags
unicorn_dev_rails="YES" # For rails
class Symbol
def | other
if other.is_a? Proc
-> arg { other.call(arg.send(self)) }
else
-> arg { arg.send(self).send(other) }
end
end
def call *args