Skip to content

Instantly share code, notes, and snippets.

View be9's full-sized avatar

Oleg Dashevskii be9

View GitHub Profile
@be9
be9 / gist:12491
Created September 24, 2008 05:47 — forked from anonymous/gist:12490
function cool_cost(cost) {
cost = Number(cost);
c = Math.floor(cost / 1000);
b = String(cost % 1000);
while (b.length < 3)
b = '0' + b;
return c + ',' + b;
}
@be9
be9 / gist:15281
Created October 7, 2008 12:04
Modula-2 lists
MODULE struc;
IMPORT SWholeIO;
FROM Storage IMPORT ALLOCATE, DEALLOCATE;
TYPE
PNode = POINTER TO Node;
Node = RECORD
number : CARDINAL;
next : PNode;
class StubErrors
def on(*args); [] end
end
class MyObject
# .......
def errors; StubErrors.new end
end
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
//$('#victim').hide().fadeIn().pause(1000).remove();
$('#victim').remove();
});
</script>
</head>
def quick(a)
return a if a.min == a.max
m = a[rand(a.size)]
quick( a.select { |i| i <= m } ) + quick( a.select { |i| i > m } )
end
describe "Quicksort" do
it "should sort an empty array" do
quick([]).should == []
end
Функционал: Регистрация
Чтобы входить в систему под своим логином,
будучи в настоящий момент анонимным пользователем,
я хочу зарегистрироваться в системе.
Сценарий: Страница регистрации
Сначала я не залогинен
И я зашел на главную
Если я кликаю на "Регистрация"
То я должен увидеть "Регистрация"
class Blah < ApplicationController
access_control do
default :deny
allow anonymous # аналогично allow nil - пустить анонима
allow :admin # проверяет по глобальной роли
allow :creator, :of => Ruby # проверяет по роли на класс
allow :employed, :by => :company # current_user.has_role? :employed, @company
allow do
current_user.has_role?('lover', Dog) && current_user.has_role?('hater', Cat)
default_run_options[:pty] = true
set :use_sudo, false
set :user, "deploy"
set :application, "flats-hunter.ru"
set :deploy_to, "/home/deploy/#{application}"
# GIT
set :scm, :git
<h1>Войти в систему</h1>
<% form_for @account_session, :url => account_session_path do |f| %>
<%= f.error_messages :header_message => 'Ошибка входа' %>
<%= f.label :email, "E-mail" %><br />
<%= f.text_field :email %><br />
<br />
<%= f.label :password, "Пароль" %><br />
<%= f.password_field :password %><br />
<br />
@be9
be9 / main.c
Created February 10, 2009 12:29
#include <stdio.h>
#define USD_RATE 36.0
double usd2rur(double usd)
{
return usd * USD_RATE;
}
double rur2usd(double rur)