This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
public void test() { | |
System.out.println("Hello world"); | |
} | |
public static void main(String args[]) { | |
A a = new A(); | |
a.testX(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
irb --simple-prompt | |
>> a = [1,2,3] | |
=> [1, 2, 3] | |
>> a.select {|e| e >= 2} | |
=> [2, 3] | |
>> a.detect {|e| e >= 2} | |
=> 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MigrationData | |
def exec_migration(conn, direction) | |
super | |
if direction == :up && respond_to?(:data) | |
data | |
end | |
end | |
end | |
ActiveRecord::Migration.prepend(MigrationData) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Admin | |
class BaseController < ApplicationController | |
def self.inherit_resources(base) | |
InheritedResources::Base.method(:inherit_resources).call(base) | |
end | |
inherit_resources(self) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Country < ActiveRecord::Base | |
attr_accessor :status | |
after_update do | |
Thread.new do | |
self.status = :published | |
BackgroundProcess.new(self).run | |
end.join | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from abc import ABCMeta | |
from random import randint | |
class SortableGoods(object): | |
__metaclass__ = ABCMeta | |
_GOODS_CLASSES_PRIORITY = { | |
'Person': 0, | |
'Container': 1, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def method1 | |
end | |
def method2(default: 1) | |
end | |
method(:method1).arity # => 0 | |
method(:method2).arity # => 0 |