Skip to content

Instantly share code, notes, and snippets.

#In class
class AmazonImageUploader
def initialize(id, file)
name = file[0][:image].original_filename
directory = "public/uploads/"
path = File.join(directory, name)
File.open(path, "wb") { |f| f.write(file[0][:image].read) }
@path = path
@id = id
end
@Olefine
Olefine / crete.rb
Created August 26, 2013 11:42
backup message controller action create
def create
@recipient = User.find(params[:message][:recipient_id])
@message = current_user.send_message(@recipient, params[:message][:body])
images_params = params[:message][:images_attributes]
respond_with(@message) do |format|
if @message.save!
if images_params.present?
uploader = AmazonImageUploader.new(@message.id, images_params)
uploader.process
end
require "rvm/capistrano" # Load RVM's capistrano plugin.
require "bundler/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user # Literal ":user"
set :application, "blog_test"
set :repository, "[email protected]:ryancheung/blog.git"
set :scm, :git
# encoding: utf-8
class User < ActiveRecord::Base
attr_accessor :read # user's agreement
scope :unbanned, where(:banned => false)
scope :last_users, ->(count) { order("id DESC").limit(count) }
include Models::User::City
include Models::User::MessageStuff
require 'yandex-translator'
class Translate
attr_accessor :words_for_translate
attr_reader :translated_word
def initialize(words)
set_api_key
@words_for_translate = words
end
def translate(options = nil)
require 'rubygems'
require 'oauth'
# Change the following values to those provided on dev.twitter.com
# The consumer key identifies the application making the request.
# The access token identifies the user making the request.
consumer_key = OAuth::Consumer.new(
"miJSmFqLUEVrY8huJJReZw",
"5ilaj6E2jFFxsd0zdA1wsKqc9dDv7OnjTR86206poQk")
access_token = OAuth::Token.new(
@Olefine
Olefine / file.rb
Created September 25, 2013 19:16
string
class MyString < String
@@array_of_strings ||= []
def self.new(str)
@@array_of_strings << super(str)
p @@array_of_strings
end
private
def self.all_strings
p @@array_of_strings
@Olefine
Olefine / .trabis.yml
Created September 26, 2013 00:14
sample .travis.yml
rvm:
- 1.9.2
before_script: "bundle exec rake db:drop db:create db:migrate"
script: "bundle exec rspec spec/"
@Olefine
Olefine / poll.log
Created September 30, 2013 13:13
polls log
Started GET "/polls/12" for 127.0.0.1 at 2013-09-30 16:51:13 +0400
Processing by PollsController#show as JS
Parameters: {"id"=>"12"}
User Load (2.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10 LIMIT 1
Poll Load (1.7ms) SELECT "polls".* FROM "polls" WHERE "polls"."id" = $1 ORDER BY created_at DESC LIMIT 1 [["id", "12"]]
Client Load (3.2ms) SELECT "clients".* FROM "clients" WHERE "clients"."id" = 64 LIMIT 1
User Load (3.1ms) SELECT "users".* FROM "users" WHERE "users"."profileable_id" = 64 AND "users"."profileable_type" = 'Client' LIMIT 1
(2.9ms) SELECT COUNT(*) FROM "comments" WHERE "comments"."commentable_id" = 12 AND "comments"."commentable_type" = 'Poll'
(2.8ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = 12 AND "votes"."votable_type" = 'Poll' AND "votes"."vote_flag" = 't' AND "votes"."vote_scope" IS NULL
PollImage Load (3.1ms) SELECT "images".* FROM "images" WHERE "images"."type" IN ('PollImage') AND "images"."imageable_id" = 12 AND "images"."imageable_ty
module Library
# <summary>
# Класс подсистемы
# </summary>
# <remarks>
# <li>
# <lu>реализует функциональность подсистемы;</lu>
# <lu>выполняет работу, порученную объектом <see cref="Facade"/>;</lu>
# <lu>ничего не "знает" о существовании фасада, то есть не хранит ссылок на него;</lu>