Skip to content

Instantly share code, notes, and snippets.

View 7even's full-sized avatar

Vsevolod Romashov 7even

  • Health Samurai
  • Tbilisi, Georgia
  • 07:39 (UTC +04:00)
View GitHub Profile
@7even
7even / gist:3029301
Created July 1, 2012 19:18
method resolving system prototype
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)
@7even
7even / gist:2597518
Created May 4, 2012 20:27
репликация новостей с вконтакта
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
@7even
7even / gist:2394502
Created April 15, 2012 19:50
number formatting
def separate_with_comma(n)
n.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, '\1,')
end
@7even
7even / hash_struct.rb
Created October 23, 2011 14:44
Struct instantiated with a hash
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
@7even
7even / football results parser
Created April 9, 2011 21:28
football match scores parser
#!/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'
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