This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
COLS = 3 # кол-во столбцов | |
# если не указан файл, выводим сообщение и выходим | |
if ARGV.count == 0 | |
puts 'specify a file to output' | |
exit | |
end | |
begin | |
words = IO.readlines(ARGV[0]).each { |word| word.strip! }.sort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
# encoding: utf-8 | |
class FootballParser | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
URL = 'http://www.liveresult.ru/' | |
ITEM_SELECTOR = '#pane_g_172_football_actual .a .item, #pane_g_172_football_actual .b .item' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Kernel.module_eval do | |
def HashStruct(*attributes) | |
Class.new do | |
# keeping keys array in class | |
@keys = attributes.map(&:to_sym) | |
class << self | |
attr_reader :keys | |
end | |
# passing keys to the child class if inherited |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def separate_with_comma(n) | |
n.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, '\1,') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'vkontakte_api' | |
# id группы с минусом | |
GROUP_ID = -1 | |
# id последней новости, сохраненной в БД | |
last_news_id = News.maximum(:vk_id) | |
vk = VK::Client.new | |
all_news = vk.wall.get(owner_id: GROUP_ID).tap(&:shift).reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'hashie' | |
module VK | |
module Resolver | |
NAMESPACES = ['users', 'friends'] | |
def method_missing(method_name, *args, &block) | |
method_name = method_name.to_s | |
if NAMESPACES.include?(method_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class Payment | |
RATE = 3.8 | |
attr_accessor :previous, :current | |
def initialize(params = {}) | |
@previous = params.delete(:previous) | |
@current = params.delete(:current) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PB | |
module SocialNetwork | |
class Twitter | |
include PB::SocialNetwork::Base | |
def initialize(token) | |
@token = token | |
end | |
def update_profile(params = {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fibonacci(numbers_count) | |
sequence = Enumerator.new do |yielder| | |
current_number, next_number = 0, 1 | |
loop do | |
yielder << current_number | |
current_number, next_number = next_number, current_number + next_number | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def defaultify(hash) | |
hash.default_proc = ->(hash, key) { | |
hash[key] = Hash.new | |
} | |
end | |
class UsersController < ActiveRecord::Base | |
def create | |
defaultify(hash) | |
# code |
OlderNewer