Skip to content

Instantly share code, notes, and snippets.

View ka8725's full-sized avatar
🚀
Ruby on Rails expert with business development mindset | WideFix Founder

Andrei Kaleshka ka8725

🚀
Ruby on Rails expert with business development mindset | WideFix Founder
View GitHub Profile
class A {
public void test() {
System.out.println("Hello world");
}
public static void main(String args[]) {
A a = new A();
a.testX();
}
}
irb --simple-prompt
>> a = [1,2,3]
=> [1, 2, 3]
>> a.select {|e| e >= 2}
=> [2, 3]
>> a.detect {|e| e >= 2}
=> 2
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
module MigrationData
def exec_migration(conn, direction)
super
if direction == :up && respond_to?(:data)
data
end
end
end
ActiveRecord::Migration.prepend(MigrationData)
module RoutesAdaptation
# Extends functionality of polymorphic routes to have ability to define default prefixes
# in the controller.
#
# Examples:
# ActionView::RoutingUrlFor.send(:include, RoutesAdaptation::RoutingUrlFor)
#
# class ApplicationController < ActionController::Base
# def polymorphic_prefixes
# [:client, current_company]
module Admin
class BaseController < ApplicationController
def self.inherit_resources(base)
InheritedResources::Base.method(:inherit_resources).call(base)
end
inherit_resources(self)
end
end
def get_purchase_from_factory(rec):
purchase = Purchase(rec[1], int(rec[2]), int(rec[3]))
if rec[0] != 'Purchase':
cls_obj = globals().get(rec[0], None)
purchase.__class__ = cls_obj
conv_fun = int if rec[0] == 'PricePurchase' else float
purchase.discount = conv_fun(rec[4])
return purchase
class Country < ActiveRecord::Base
attr_accessor :status
after_update do
Thread.new do
self.status = :published
BackgroundProcess.new(self).run
end.join
end
end
@ka8725
ka8725 / model.py
Last active January 2, 2016 10:49
Oop model comparison Ruby and Python
from abc import ABCMeta
from random import randint
class SortableGoods(object):
__metaclass__ = ABCMeta
_GOODS_CLASSES_PRIORITY = {
'Person': 0,
'Container': 1,
def method1
end
def method2(default: 1)
end
method(:method1).arity # => 0
method(:method2).arity # => 0