Skip to content

Instantly share code, notes, and snippets.

@serek
serek / 01_scalyr_dependencies.config
Last active April 5, 2017 15:12
scalyr ebextension for docker logs or any (put these files into .ebextensions folder)
packages:
yum:
python26: []
@serek
serek / migration.rb
Created April 22, 2010 13:15 — forked from firebelly/paperclip_migrations.rb
Migration from attachment_fu to paperclip.
class ConvertImagesToPaperclip < ActiveRecord::Migration
include PaperclipMigrations
def self.up
# Paperclip
add_column :images, :data_file_name, :string
add_column :images, :data_content_type, :string
add_column :images, :data_file_size, :integer
add_column :images, :data_updated_at, :datetime
@serek
serek / sms.rb
Last active December 30, 2015 12:39
Simple Twilio wrapper for Sending SMS.
#
# Usage:
# sms = SMS.new('+1XXXXXX', 'Message')
# sms = SMS.new('+1XXXXXX', 'Message', :full_sms_queue, :invalid)
# sms.data - results in hash
#
class SMS
def initialize(number, message, from_error=nil, to_error=nil)
@client = SMS.client
send_sms(number, message, from_error, to_error)
@serek
serek / sessions_controller.rb
Created May 16, 2013 11:37
Sample sessions controller for Devise APIs based on tokens.
class Api::V1::SessionsController < Api::V1::BaseController
skip_before_filter :verify_authenticity_token, only: :create
skip_before_filter :authenticate_user!, only: :create
before_filter :ensure_params_exist, only: :create
before_filter :ensure_token_exist, only: :destroy
def create
resource = User.find_for_database_authentication(email: params[:user][:email])
return invalid_login_attempt unless resource
#Session controller provides a token
#/controllers/api/sessions_controller.rb
class Api::SessionsController < Devise::SessionsController
before_filter :authenticate_user!, :except => [:create]
before_filter :ensure_params_exist, :except => [:destroy]
respond_to :json
def create
resource = User.find_for_database_authentication(:email => params[:user_login][:email])
return invalid_login_attempt unless resource
@serek
serek / installation.sh
Created August 10, 2011 16:55 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
$ cd /usr/src
$ wget http://nginx.org/download/nginx-0.8.52.tar.gz
$ tar xzvf ./nginx-0.8.52.tar.gz
$ rm ./nginx-0.8.52.tar.gz
$ gem install s3sync capistrano capistrano-ext passenger --no-ri --no-rdoc
$ passenger-install-nginx-module
# Automatically download and install Nginx? 2. No: I want to customize my Nginx installation
# Where is your Nginx source code located?: /usr/src/nginx-0.8.52
# Where do you want to install Nginx to?: /opt/nginx
@serek
serek / paperclip.rb
Created April 19, 2011 15:32
Paperclip initializer for S3 Europe.
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://s3-eu-west-1.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
}
require 'aws/s3'
AWS::S3::DEFAULT_HOST.replace "s3-eu-west-1.amazonaws.com"
@serek
serek / Gemfile
Created June 11, 2010 13:32 — forked from indirect/Gemfile
# include at least one source and the rails gem
source :gemcutter
gem 'rails', '~> 2.3.5', :require => nil
gem 'sqlite3-ruby', :require => 'sqlite3'
# Devise 1.0.2 is not a valid gem plugin for Rails, so use git until 1.0.3
# gem 'devise', :git => 'git://github.com/plataformatec/devise.git', :ref => 'v1.0'
group :development do
# bundler requires these gems in development
# part of config/enviroment.rb
...
Rails::Initializer.run do |config|
# Load model files from sub folders
config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }
# Load middleware - initially used by flash-session-hack
config.load_paths << "#{RAILS_ROOT}/app/middleware"
@serek
serek / application_helper.rb
Created April 8, 2010 08:26
Polymorphic file upload with paperclip, delayed_job, has_many_polymorphs, swfupload, formtastic and haml. Make same for any other types like Image, Audio, Document and so on.
module ApplicationHelper
# Access Levels
ACCESS_LEVELS = { :private => 0, :friends => 1, :public => 2 }
# Access levels i18n translation
def access_levels
ACCESS_LEVELS.collect{|k,v| [I18n.t("access." + k.to_s), v]}
end
end