Skip to content

Instantly share code, notes, and snippets.

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)
View 01_scalyr_dependencies.config
python26: []
serek / sms.rb
Last active December 30, 2015 12:39
Simple Twilio wrapper for Sending SMS.
View sms.rb
# Usage:
# sms ='+1XXXXXX', 'Message')
# sms ='+1XXXXXX', 'Message', :full_sms_queue, :invalid)
# - 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 / sessions_controller.rb
Created May 16, 2013 11:37
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
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 /
Created August 10, 2011 16:55 — forked from mikhailov/
Nginx+passenger application config: ssl redirection, http headers, passenger optimal settings. see details:
$ cd /usr/src
$ wget
$ 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 / paperclip.rb
Created April 19, 2011 15:32
Paperclip initializer for S3 Europe.
View paperclip.rb
Paperclip.interpolates(:s3_eu_url) { |attachment, style|
"#{attachment.s3_protocol}://{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
require 'aws/s3'
AWS::S3::DEFAULT_HOST.replace ""
serek / Gemfile
Created June 11, 2010 13:32 — forked from indirect/Gemfile
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://', :ref => 'v1.0'
group :development do
# bundler requires these gems in development
serek / migration.rb
Created April 22, 2010 13:15 — 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
... 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 / 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.
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]}