Skip to content

Instantly share code, notes, and snippets.

@Olefine
Olefine / file.rb
Created February 28, 2014 12:30
merging files
require 'pry-debugger'
output = File.new("output.txt", 'a')
nm1 = File.open("names.txt", 'r')
nm2 = File.open("names2.txt", "r")
#binding.pry
nm1.each_line do |n1|
nm2.each_line do |n2|
@Olefine
Olefine / algo.rb
Last active August 29, 2015 13:56
1,11,21,1211 ... sequence
def generate(cardinality=1, result=[1])
if cardinality == 0
return result
else
elem = result.last
sub_ary = elem.to_s.split('').map(&:to_i)
result << group(sub_ary)
generate(cardinality - 1, result)
end
end
@Olefine
Olefine / deploy.rb
Created November 25, 2013 17:04
some deploy from legacy project
# Automatically precompile assets
load "deploy/assets"
# Execute "bundle install" after deploy, but only when really needed
require "bundler/capistrano"
# RVM integration
require "rvm/capistrano"
set :application, "app name"
set :rails_env, :production
require 'minitest/mock'
require 'minitest/unit'
require 'date'
MiniTest::Unit.autorun
class TestMailPurge < MiniTest::Unit::TestCase
class MailPurge
def initialize(imap)
@imap = imap
require "interface"
Strategy = interface {
required_methods :use
}
class StrategyOne
implements Strategy
def use
module Library
# <summary>
# Класс подсистемы
# </summary>
# <remarks>
# <li>
# <lu>реализует функциональность подсистемы;</lu>
# <lu>выполняет работу, порученную объектом <see cref="Facade"/>;</lu>
# <lu>ничего не "знает" о существовании фасада, то есть не хранит ссылок на него;</lu>
@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
@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 / 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
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(