Skip to content

Instantly share code, notes, and snippets.

View skanev's full-sized avatar

Stefan Kanev skanev

View GitHub Profile
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
require 'spec/autorun'
require 'spec/rails'
Dir[File.dirname(__FILE__) + "/spec_helpers/**/*.rb"].each do |file|
require file
end
aquarius@arrakeen ~ $ cat .screenrc | tail -n 19 | head -n 6
# Make shift-PgUp and shift-PgDn work like they do in xterm. (Note that this
# requires xterm to be configured to pass those keys through, and not try to
# act on them itself.)
bindkey "^[[5;2~" eval "copy" "stuff ^u"
bindkey -m "^[[5;2~" stuff ^u
bindkey -m "^[[6;2~" stuff ^d
def egn_valid?
egn =~ /^(\d{2})(\d{2})(\d{2})\d{3}(\d)$/ and
egn.each_char[0...9].zip([2, 4, 8, 5, 10, 9, 7, 3, 6]).sum { |d, w| d.to_i * w } % 11 % 10 == $4.to_i and
Date.valid_civil?($1.to_i, $2.to_i % 20, $3.to_i) and
$2.to_i / 20 <= 2
end
# Алгоритъм от тук: http://www.grao.bg/esgraon.html
sub opening_slide {
$_ = shift;
my ($title, $date, $intro) = (/^(.*?)\n(.*?)\n(.*)$/s);
$intro = html_escape(trim($intro));
$intro =~ s#\n#<br />\n#g;
$intro =~ s# # &nbsp;#g;
html_head($title, $date, $intro);
}
class TopicsController < ApplicationController
before_filter :set_topic, :only => [:show, :edit, :update, :destroy]
def index
@topics = current_user.topics
end
def show
@topic.update_topic_hits
Автоматизирано (unit) тестване
12.04.2009
== Disclaimer ==
Днес няма да си говорим за acceptance testing, quality assurance или нещо, което се прави от "по-низшия" отдел във фирмата. Всичко тук е дело на програмиста.
== Митът ==
Проектът идва с готово, подробно задание. Прави се дизайн. С него работата се разбива на малки задачи. Те се извършват последователно. За всяка от тях пишете кода и приключвате. Изискванията не се променят, нито се добавя нова функционалност.
describe "#overlaps?(span)" do
def span(lower, upper)
Search::Span.new(lower, upper)
end
def overlap(expected)
simple_matcher do |given, matcher|
matcher.description = "overlap with #{expected}"
matcher.failure_message = "expected #{given} to overlap with #{expected}"
matcher.negative_failure_message = "expected #{given} not to overlap with #{expected}"
module Sunglass
module Slave
class WEBrick
def initialize(application, port)
@application = application
@port = port
@mutex = Mutex.new
@condition = ConditionVariable.new
end
class WidgetsController < ApplicationController
before_filter :assign_widget, :only => [:show, :new, :edit, :create:, :update, :destroy]
def show; end
def new; end
def edit; end
def create
if @widget.save
redirect_to(@widget, :notice => 'Widget was successfully created.')
@skanev
skanev / inheritance_vs_types.scala
Created December 4, 2010 16:55
The epic fight between inheritance and type systems, in pseudo-Scala
class StrangeIntQue extends Queue[Int] {
override def append(x: Int) {
println(Math.sqrt(x))
super.append(x)
}
}
val x: Queue[Any] = new StrangeIntQueue
x.append("abc") // Math.sqrt("abc") ?