Skip to content

Instantly share code, notes, and snippets.

View edzhelyov's full-sized avatar

Evgeni Dzhelyov edzhelyov

  • Sofia, Bulgaria
View GitHub Profile
@edzhelyov
edzhelyov / app.rb
Created March 8, 2011 14:01
Sinatra inline templates
require 'haml'
get '/' do
haml :overview
end
__END__
@@ overview
%html
@edzhelyov
edzhelyov / 001_create_laptops.rb
Created June 7, 2011 12:54
Sequel migration helpers
module Helper
def create_product(name)
create_table name do
primary_key :id
String :name, :null => false
end
end
end
Sequel.migration do
@edzhelyov
edzhelyov / sequel_display.rb
Created June 8, 2011 12:41
Strange behavior for sequel model
class Laptop < Sequel::Model
end
l = Laptop.new
l.columns
[:id, :hdd, :display]
l.hdd
=> nil
l.display
@edzhelyov
edzhelyov / bg.yml
Created June 22, 2011 08:29
Simple I18n templating
This is the default title: Това е по подразбиране
Project title: Име на проекта
$(function() {
$('select[data-nested-select]').each(function() {
var select = $(this),
groupName = select.data('nested-select'),
optgroups = select.find('optgroup'),
options = select.find('optgroup option'),
groupSelect = $('<select>'),
promptOption = makeOption(groupName, null, false);
groupSelect.append(promptOption);
SVG.draw do
group do
fill :red
nested do
circle ...
end
end
end
@edzhelyov
edzhelyov / product.rb
Created September 26, 2011 13:54
Product initialization
class Product < ActiveRecord::Base
belongs_to :product_type
has_many :product_attributes, :extend => FindersByAtrributeName
def initialize(attributes = nil)
super
define_dynamic_accessors
end
def define_dynamic_accessors
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.10)
actionpack (3.0.10)
activemodel (3.0.10)
activerecord (3.0.10)
activeresource (3.0.10)
activesupport (3.0.10)
arel (2.0.10)
require "thread"
$mutex = Mutex.new
$total = 0
def incr
$mutex.synchronize { $total += 1 }
sleep
end
@edzhelyov
edzhelyov / spec.rb
Created November 22, 2011 12:31
maks birthday
describe '#greets_maks_for_his_birthday' do
context 'on his birthday' do
it 'greets him on facebook' do
maks_birthday = Date.new(2011, 11, 22)
Date.stub(:now).and_return(maks_birthday)
greets_maks_for_his_birthday.should post_to_facebook('Хей, ЧРД, мен')
end
end
end