Skip to content

Instantly share code, notes, and snippets.

.redesign .title {
margin-top: 0;
margin-left: 0;
}
.redesign .segment {
margin-bottom: 0;
}
.redesign .segment-content,
irb(main):010:0> class A; def dupa(x); x; end; end
=> nil
irb(main):012:0> module Over; def dupa(x); x + 1; end; end
=> nil
irb(main):013:0> A.new.dupa(1)
=> 1
irb(main):014:0> A.new.extend(Over).dupa(1)
=> 2
@teamon
teamon / Gemfile
Created April 17, 2014 08:39
Mount Grape API at rails root
source "http://rubygems.org"
gem "railties", '4.0.3', require: %w(action_controller rails)
gem "grape"
sudo apt-get update
# Install java
sudo apt-get install openjdk-7-jre-headless wget curl -y
# Install elasticsearch
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.3.deb
sudo dpkg -i elasticsearch-1.0.3.deb
sudo service elasticsearch start
module CachedDef
def cached(name)
meth = instance_method(name)
raise ArgumentError.new("cached can be used only for method with no arguments") if meth.arity != 0
alias_method "__cached_def_original__#{name}", name
class_eval <<-EOS
def #{name}
@__cached_def_cache__#{name} ||= __cached_def_original__#{name}
@teamon
teamon / gist:6c82cf686291e61bc2fc
Last active August 29, 2015 14:01
Ruby 2.1 method return value use cases
private def foo # make one method private
instrumet def foo # calculates execution time
silent def foo # silences stdout/err output
cached def foo(args...) # caches each invokation with different arguments into redis
memoize def foo # memoizes return value in instance variable
@teamon
teamon / .vimrc
Last active August 29, 2015 14:02
set number
set nowrap
set showbreak
set textwidth=100
set showmatch
set visualbell
set hlsearch
set smartcase
set ignorecase
@teamon
teamon / munin-passenger
Last active August 29, 2015 14:03
Munin passeger 4 plugin
nobody ALL=(ALL) NOPASSWD:/usr/local/bin/passenger-status, /usr/local/bin/passenger-memory-stats
>> Product.properties[:created_at].type
=> DateTime
>> Product.properties[:deleted_at].type
=> DataMapper::Types::ParanoidDateTime
>> Product.properties[:type].type
=> #<Class:0x5cf2ec>
# auto_validate.rb
require "dm-types" # not sure of that...
if property.type.ancestors.include?(Types::Enum)
validates_within property.name, options_with_message({:set => property.type.flag_map.values}, property, :within)
end
# auto -validate_spec
describe 'for Enum properties' do
require 'dm-types' # not sure if it is ok to require dm-types here
before :all do