Skip to content

Instantly share code, notes, and snippets.

@serek
serek / 01_scalyr_dependencies.config
Last active Apr 5, 2017
scalyr ebextension for docker logs or any (put these files into .ebextensions folder)
View 01_scalyr_dependencies.config
packages:
yum:
python26: []
@serek
serek / sms.rb
Last active Dec 30, 2015
Simple Twilio wrapper for Sending SMS.
View sms.rb
#
# 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
Sample sessions controller for Devise APIs based on tokens.
View sessions_controller.rb
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
View gist:5508237
#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 Aug 10, 2011 — forked from mikhailov/installation.sh
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details: http://mikhailov.posterous.com/nginx
View installation.sh
$ 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 Apr 19, 2011
Paperclip initializer for S3 Europe.
View paperclip.rb
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"
View 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
@serek
serek / migration.rb
Created Apr 22, 2010 — forked from firebelly/paperclip_migrations.rb
Migration from attachment_fu to paperclip.
View migration.rb
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
View enviroment.rb
# 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 Apr 8, 2010
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.
View application_helper.rb
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