Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
require 'net/http'
require 'uri'
TEST_URL = URI.parse('http://nazva.net/logic_test5/')
def correct?( q, a)
response = Net::HTTP.post_form( TEST_URL, { "q#{q}" => "#{q}#{a}"} )
response.body.include? '>1<'
end
# Вынес из content_object без изменений. переписвать страшновато
module Rateable
def self.included(base)
base.extend ClassMethods
base.after_create :increment_user_rating
end
# рейтинг объектов
def rate(user, value)
ru:
devise:
sessions:
link: 'Войти'
signed_in: 'Вы вошли в систему.'
signed_out: 'Вы вышли из системы.'
unauthenticated: 'Необходимо войти в систему или зарегистрироваться.'
unconfirmed: 'Необходимо подтвердить адрес электронной почты.'
locked: 'Ваша учетная запись заблокирована.'
invalid: 'Неверная учетная запись или пароль.'
@codesnik
codesnik / gist:316283
Created February 26, 2010 22:58
WTF ZOMG controller
class CatalogueController < ApplicationController
@@rows_on_page = 50
@@companies_on_page = 20
def firms
# Возвращаем "304 Not Modified" если страница не устарела
if industry.cached_level >= 2 || industry.leaf?
if params[:format] != 'xls'
# если выводится список компаний (причем не в ExCel)
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = off;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET escape_string_warning = off;
class Message < ActiveRecord::Base
# обновляет updated_at у родительского сообщения, нужно для сортировки
belongs_to :parent, :class_name => "Message", :touch => true
belongs_to :sender, :class_name => "User"
belongs_to :recipient, :class_name => "User"
has_many :messages, :foreign_key => :parent_id, :dependent => :delete_all
default_scope order('created_at desc')
scope :threads, where(:parent_id => nil)
scope :unread, where(:unread => true)
class Message
include DataMapper::Resource
property :id, Serial
property :subject, String
property :body, Text
property :unread, Boolean, :default => true, :required => true
property :created_at, DateTime
property :updated_at, DateTime
From f1a4da7b54468f815a8478b774da1e0fe47ff0d2 Mon Sep 17 00:00:00 2001
From: codesnik <[email protected]>
Date: Sat, 6 Mar 2010 23:54:38 +0300
Subject: [PATCH] migrates to datamapper
---
Gemfile | 71 ++++++++----
Gemfile.lock | 174 +++++++++++++++++++++--------
app/controllers/application_controller.rb | 2 +-
app/controllers/messages_controller.rb | 26 ++---
# должно помочь с кириллицей в .to_yml
ruby -lpe 'gsub!(/\\x(..)/){ "%c" % $1.to_i(16) }'
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old." +
"Run `gem install bundler` to upgrade."