_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q22400
DICOM.DLibrary.as_name
train
def as_name(value) case true when value.tag? element(value).name when value.dicom_name?
ruby
{ "resource": "" }
q22401
DICOM.DLibrary.as_tag
train
def as_tag(value) case true when value.tag? element(value) ? value : nil when value.dicom_name? get_tag(value) when value.dicom_method?
ruby
{ "resource": "" }
q22402
DICOM.DLibrary.element
train
def element(tag) element = @elements[tag] unless element if tag.group_length? element = DictionaryElement.new(tag, 'Group Length', ['UL'], '1', '') else if tag.private? element
ruby
{ "resource": "" }
q22403
DICOM.DLibrary.extract_transfer_syntaxes_and_sop_classes
train
def extract_transfer_syntaxes_and_sop_classes transfer_syntaxes = Hash.new sop_classes = Hash.new @uids.each_value do |uid| if
ruby
{ "resource": "" }
q22404
DICOM.DLibrary.get_tag
train
def get_tag(name) tag = nil name = name.to_s.downcase @tag_name_pairs_cache ||= Hash.new return @tag_name_pairs_cache[name] unless @tag_name_pairs_cache[name].nil? @elements.each_value do |element| next
ruby
{ "resource": "" }
q22405
DICOM.DLibrary.unknown_or_range_element
train
def unknown_or_range_element(tag) element = nil range_candidates(tag).each do |range_candidate_tag| if de = @elements[range_candidate_tag] element = DictionaryElement.new(tag, de.name, de.vrs, de.vm, de.retired) break end end
ruby
{ "resource": "" }
q22406
AutoNetwork.PoolManager.with_pool_for
train
def with_pool_for(machine, read_only=false) @pool_storage.transaction(read_only) do pool = lookup_pool_for(machine)
ruby
{ "resource": "" }
q22407
AutoNetwork.Action::Base.machine_auto_networks
train
def machine_auto_networks(machine) machine.config.vm.networks.select do |(net_type, options)|
ruby
{ "resource": "" }
q22408
AutoNetwork.Pool.request
train
def request(machine) if (address = address_for(machine)) return address elsif (address = next_available_lease)
ruby
{ "resource": "" }
q22409
AutoNetwork.Pool.address_for
train
def address_for(machine) machine_id = id_for(machine) addr, _ = @pool.find do |(addr, id)| if id.is_a?(String) # Check for old-style UUID values. These should eventually cycle out
ruby
{ "resource": "" }
q22410
AutoNetwork.Settings.default_pool=
train
def default_pool=(pool) # Ensure the pool is valid. begin IPAddr.new pool rescue ArgumentError raise InvalidSettingErrror,
ruby
{ "resource": "" }
q22411
RAutomation.ElementCollections.has_many
train
def has_many(*elements) elements.each do |element| class_name_plural = element.to_s.split("_").map {|e| e.capitalize}.join class_name = class_name_plural.chop adapter_class = self.to_s.scan(/(.*)::/).flatten.first clazz = RAutomation.constants.include?(class_name) ? RAutomation : c...
ruby
{ "resource": "" }
q22412
ActiveEvent.EventSourceServer.process_projection
train
def process_projection(data) mutex.synchronize do projection_status = status[data[:projection]] projection_status.set_error
ruby
{ "resource": "" }
q22413
RallyAPI.RallyRestJson.allowed_values
train
def allowed_values(type, field, workspace = nil) rally_workspace_object(workspace) type_def = get_typedef_for(type, workspace) allowed_vals = {} type_def["Attributes"].each do |attr| next if attr["ElementName"] != field attr["AllowedValues"].each do |val_ref|
ruby
{ "resource": "" }
q22414
RallyAPI.RallyRestJson.check_type
train
def check_type(type_name) alias_name = @rally_alias_types[type_name.downcase.to_s]
ruby
{ "resource": "" }
q22415
RallyAPI.RallyRestJson.check_id
train
def check_id(type, idstring) if idstring.class == Fixnum return make_read_url(type, idstring) end if (idstring.class == String) return idstring if idstring.index("http") == 0
ruby
{ "resource": "" }
q22416
RallyAPI.RallyObject.method_missing
train
def method_missing(sym, *args) ret_val = get_val(sym.to_s) if ret_val.nil? && @rally_rest.rally_rest_api_compat
ruby
{ "resource": "" }
q22417
BunnyMock.Channel.ack
train
def ack(delivery_tag, multiple = false) if multiple @acknowledged_state[:pending].keys.each do |key| ack(key, false) if key <= delivery_tag end
ruby
{ "resource": "" }
q22418
BunnyMock.Channel.nack
train
def nack(delivery_tag, multiple = false, requeue = false) if multiple @acknowledged_state[:pending].keys.each do |key| nack(key, false, requeue) if key <= delivery_tag end elsif @acknowledged_state[:pending].key?(delivery_tag)
ruby
{ "resource": "" }
q22419
BunnyMock.Channel.reject
train
def reject(delivery_tag, requeue = false) if @acknowledged_state[:pending].key?(delivery_tag) delivery, header, body = update_acknowledgement_state(delivery_tag, :rejected)
ruby
{ "resource": "" }
q22420
BunnyMock.Queue.bind
train
def bind(exchange, opts = {}) check_queue_deleted! if exchange.respond_to?(:add_route) # we can do the binding ourselves exchange.add_route opts.fetch(:routing_key, @name), self else
ruby
{ "resource": "" }
q22421
BunnyMock.Queue.unbind
train
def unbind(exchange, opts = {}) check_queue_deleted! if exchange.respond_to?(:remove_route) # we can do the unbinding ourselves
ruby
{ "resource": "" }
q22422
BunnyMock.Queue.pop
train
def pop(opts = { manual_ack: false }, &block) if BunnyMock.use_bunny_queue_pop_api bunny_pop(opts, &block) else
ruby
{ "resource": "" }
q22423
BunnyMock.Exchange.bind
train
def bind(exchange, opts = {}) if exchange.respond_to?(:add_route) # we can do the binding ourselves exchange.add_route opts.fetch(:routing_key, @name), self else
ruby
{ "resource": "" }
q22424
BunnyMock.Exchange.unbind
train
def unbind(exchange, opts = {}) if exchange.respond_to?(:remove_route) # we can do the unbinding ourselves exchange.remove_route opts.fetch(:routing_key, @name), self else
ruby
{ "resource": "" }
q22425
BunnyMock.Exchange.routes_to?
train
def routes_to?(exchange_or_queue, opts = {}) route = exchange_or_queue.respond_to?(:name) ? exchange_or_queue.name : exchange_or_queue rk
ruby
{ "resource": "" }
q22426
TTY.Cursor.move
train
def move(x, y) (x < 0 ? backward(-x) : (x > 0 ?
ruby
{ "resource": "" }
q22427
TTY.Cursor.clear_lines
train
def clear_lines(n, direction = :up) n.times.reduce([]) do |acc, i| dir = direction == :up ? up : down
ruby
{ "resource": "" }
q22428
Jkf::Parser.Kif.transform_move
train
def transform_move(line, c) ret = {} ret["comments"] = c if !c.empty? if line["move"].is_a? Hash ret["move"] = line["move"] else
ruby
{ "resource": "" }
q22429
Jkf::Parser.Kif.transform_teban_fugou_from
train
def transform_teban_fugou_from(teban, fugou, from) ret = { "color" => teban2color(teban.join), "piece" => fugou["piece"] } if fugou["to"] ret["to"] = fugou["to"] else ret["same"] = true
ruby
{ "resource": "" }
q22430
Jkf::Parser.Kif.reverse_color
train
def reverse_color(moves) moves.each do |move| if move["move"] && move["move"]["color"] move["move"]["color"] = (move["move"]["color"] + 1) % 2 end
ruby
{ "resource": "" }
q22431
Jkf::Parser.Ki2.transform_fugou
train
def transform_fugou(pl, pi, sou, dou, pro, da) ret = { "piece" => pi } if pl["same"] ret["same"] = true else ret["to"] = pl end ret["promote"] = (pro == "成") if pro if da ret["relative"]
ruby
{ "resource": "" }
q22432
Jkf::Parser.Base.match_spaces
train
def match_spaces stack = [] matched = match_space while matched != :failed stack << matched
ruby
{ "resource": "" }
q22433
Jkf::Parser.Kifuable.transform_root_forks
train
def transform_root_forks(forks, moves) fork_stack = [{ "te" => 0, "moves" => moves }] forks.each do |f| now_fork = f _fork = fork_stack.pop _fork = fork_stack.pop while _fork["te"] > now_fork["te"] move = _fork["moves"][now_fork["te"] -
ruby
{ "resource": "" }
q22434
Jkf::Parser.Kifuable.transform_initialboard
train
def transform_initialboard(lines) board = [] 9.times do |i| line = [] 9.times do |j| line << lines[j][8 - i] end board <<
ruby
{ "resource": "" }
q22435
Jkf::Parser.Csa.transform_komabetsu_lines
train
def transform_komabetsu_lines(lines) board = generate_empty_board hands = [ { "FU" => 0, "KY" => 0, "KE" => 0, "GI" => 0, "KI" => 0, "KA" => 0, "HI" => 0 }, { "FU" => 0, "KY" => 0, "KE" => 0, "GI" => 0, "KI" => 0, "KA" => 0, "HI" => 0 } ] all = { "FU" => 18, "KY" => 4, "KE" => 4,...
ruby
{ "resource": "" }
q22436
Jkf::Parser.Csa.generate_empty_board
train
def generate_empty_board board = [] 9.times do |_i| line = []
ruby
{ "resource": "" }
q22437
Stellar.Transaction.to_operations
train
def to_operations cloned = Marshal.load Marshal.dump(operations)
ruby
{ "resource": "" }
q22438
Stellar.PathPaymentResult.send_amount
train
def send_amount s = success! return s.last.amount if s.offers.blank? source_asset = s.offers.first.asset_bought source_offers = s.offers.take_while{|o|
ruby
{ "resource": "" }
q22439
Stellar.TransactionEnvelope.signed_correctly?
train
def signed_correctly?(*key_pairs) hash = tx.hash return false if signatures.empty? key_index = key_pairs.index_by(&:signature_hint) signatures.all? do |sig|
ruby
{ "resource": "" }
q22440
Beetle.Client.configure
train
def configure(options={}, &block) configurator = Configurator.new(self, options) if block.arity == 1 yield configurator
ruby
{ "resource": "" }
q22441
Beetle.Client.rpc
train
def rpc(message_name, data=nil, opts={}) message_name =
ruby
{ "resource": "" }
q22442
Beetle.Client.trace
train
def trace(queue_names=self.queues.keys, tracer=nil, &block) queues_to_trace = self.queues.slice(*queue_names) queues_to_trace.each do |name, opts| opts.merge! :durable => false, :auto_delete => true, :amqp_name => queue_name_for_tracing(opts[:amqp_name]) end tracer ||= lambda do ...
ruby
{ "resource": "" }
q22443
Beetle.Client.load
train
def load(glob) b = binding Dir[glob].each do |f|
ruby
{ "resource": "" }
q22444
Beetle.Message.decode
train
def decode #:nodoc: amqp_headers = header.attributes @uuid = amqp_headers[:message_id] @timestamp = amqp_headers[:timestamp] headers = amqp_headers[:headers].symbolize_keys
ruby
{ "resource": "" }
q22445
Beetle.Message.key_exists?
train
def key_exists? old_message = !@store.msetnx(msg_id, :status =>"incomplete", :expires => @expires_at, :timeout => now + timeout) if old_message
ruby
{ "resource": "" }
q22446
Beetle.Message.process
train
def process(handler) logger.debug "Beetle: processing message #{msg_id}" result = nil begin result = process_internal(handler) handler.process_exception(@exception) if @exception handler.process_failure(result) if result.failure?
ruby
{ "resource": "" }
q22447
Beetle.Message.ack!
train
def ack! #:doc: logger.debug "Beetle: ack! for message #{msg_id}" header.ack return if simple? #
ruby
{ "resource": "" }
q22448
Beetle.Publisher.bunny_exceptions
train
def bunny_exceptions [ Bunny::ConnectionError, Bunny::ForcedChannelCloseError, Bunny::ForcedConnectionCloseError, Bunny::MessageError, Bunny::ProtocolError, Bunny::ServerDownError, Bunny::UnsubscribeError,
ruby
{ "resource": "" }
q22449
Beetle.Publisher.recycle_dead_servers
train
def recycle_dead_servers recycle = [] @dead_servers.each do |s, dead_since| recycle << s if dead_since < 10.seconds.ago end if recycle.empty? && @servers.empty?
ruby
{ "resource": "" }
q22450
Beetle.DeduplicationStore.with_failover
train
def with_failover #:nodoc: end_time = Time.now.to_i + @config.redis_failover_timeout.to_i begin yield rescue Exception => e Beetle::reraise_expectation_errors! logger.error "Beetle: redis connection error #{e} #{@config.redis_server} (#{e.backtrace[0]})" if Time.now.to_...
ruby
{ "resource": "" }
q22451
Beetle.DeduplicationStore.extract_redis_master
train
def extract_redis_master(text) system_name = @config.system_name redis_master = "" text.each_line do |line| parts = line.split('/', 2) case parts.size when 1 redis_master = parts[0]
ruby
{ "resource": "" }
q22452
Beetle.Subscriber.close_all_connections
train
def close_all_connections if @connections.empty? EM.stop_event_loop else server, connection
ruby
{ "resource": "" }
q22453
ForemanDigitalocean.Digitalocean.setup_key_pair
train
def setup_key_pair public_key, private_key = generate_key key_name = "foreman-#{id}#{Foreman.uuid}" client.create_ssh_key key_name, public_key KeyPair.create! :name => key_name, :compute_resource_id => id, :secret => private_key rescue StandardError => e
ruby
{ "resource": "" }
q22454
Keen.SavedQueries.clear_nil_attributes
train
def clear_nil_attributes(hash) hash.reject! do |key, value| if value.nil? return true elsif value.is_a? Hash
ruby
{ "resource": "" }
q22455
SugarCRM.ConnectionPool.with_connection
train
def with_connection connection_id = current_connection_id fresh_connection = true unless @reserved_connections[connection_id] yield connection
ruby
{ "resource": "" }
q22456
SugarCRM.ConnectionPool.clear_stale_cached_connections!
train
def clear_stale_cached_connections! keys = @reserved_connections.keys - Thread.list.find_all { |t| t.alive? }.map { |thread| thread.object_id } keys.each do |key|
ruby
{ "resource": "" }
q22457
SugarCRM.AttributeMethods.merge_attributes
train
def merge_attributes(attrs={}) # copy attributes from the parent module fields array @attributes = self.class.attributes_from_module # populate the attributes with values from the attrs provided to init. @attributes.keys.each do |name|
ruby
{ "resource": "" }
q22458
SugarCRM.AttributeMethods.save_modified_attributes!
train
def save_modified_attributes!(opts={}) options = { :validate => true }.merge(opts) if options[:validate] # Complain if we aren't valid raise InvalidRecord, @errors.full_messages.join(", ") unless valid? end # Send the save request response = self.class.session.connection.set_entry(self.c...
ruby
{ "resource": "" }
q22459
SugarCRM.Associations.find!
train
def find!(target) @associations.each do |a| return a if a.include? target
ruby
{ "resource": "" }
q22460
SugarCRM.AssociationMethods.query_association
train
def query_association(assoc, reload=false) association = assoc.to_sym return @association_cache[association] if association_cached?(association) && !reload # TODO: Some relationships aren't fetchable via get_relationship (i.e users.contacts) # even though get_module_fields lists them on the related_fiel...
ruby
{ "resource": "" }
q22461
SugarCRM.AssociationCache.update_association_cache_for
train
def update_association_cache_for(association, target, action=:add) return unless association_cached? association case action when :add return if @association_cache[association].collection.include? target @association_cache[association].push(target) #
ruby
{ "resource": "" }
q22462
SugarCRM.AssociationCollection.changed?
train
def changed? return false unless loaded? return true if added.length > 0
ruby
{ "resource": "" }
q22463
SugarCRM.AssociationCollection.delete
train
def delete(record) load raise InvalidRecord, "#{record.class}
ruby
{ "resource": "" }
q22464
SugarCRM.AssociationCollection.<<
train
def <<(record) load record.save! if record.new? result = true result = false if include?(record) @owner.update_association_cache_for(@association,
ruby
{ "resource": "" }
q22465
SugarCRM.AssociationCollection.method_missing
train
def method_missing(method_name, *args, &block) load
ruby
{ "resource": "" }
q22466
SugarCRM.AssociationCollection.save!
train
def save! load added.each do |record| associate!(record) end removed.each do |record|
ruby
{ "resource": "" }
q22467
SugarCRM.AssociationCollection.load_associated_records
train
def load_associated_records array = @owner.class.session.connection.get_relationships(@owner.class._module.name, @owner.id, @association.to_s) @loaded = true # we use
ruby
{ "resource": "" }
q22468
SugarCRM.Connection.class_for
train
def class_for(module_name) begin class_const = @session.namespace_const.const_get(module_name.classify) klass = class_const.new rescue NameError
ruby
{ "resource": "" }
q22469
SugarCRM.Connection.send!
train
def send!(method, json, max_retry=3) if max_retry == 0 raise SugarCRM::RetryLimitExceeded, "SugarCRM::Connection Errors: \n#{@errors.reverse.join "\n\s\s"}" end @request = SugarCRM::Request.new(@url, method, json, @options[:debug]) # Send Ze Request begin if @request.length > 3900 ...
ruby
{ "resource": "" }
q22470
SugarCRM.Session.reconnect
train
def reconnect(url=nil, user=nil, pass=nil, opts={})
ruby
{ "resource": "" }
q22471
SugarCRM.Session.load_extensions
train
def load_extensions self.class.validate_path @extensions_path
ruby
{ "resource": "" }
q22472
SugarCRM.Association.include?
train
def include?(attribute) return true if attribute.class == @target
ruby
{ "resource": "" }
q22473
SugarCRM.Association.resolve_target
train
def resolve_target # Use the link_field name first klass = @link_field.singularize.camelize namespace = @owner.class.session.namespace_const return namespace.const_get(klass) if namespace.const_defined? klass # Use the link_field attribute "module" if @attributes["module"].length > 0...
ruby
{ "resource": "" }
q22474
SugarCRM.Association.define_methods
train
def define_methods methods = [] pretty_name = @relationship[:target][:name] methods << define_method(@link_field) methods
ruby
{ "resource": "" }
q22475
SugarCRM.Association.define_method
train
def define_method(link_field) raise ArgumentError, "argument cannot be nil" if link_field.nil? if (@owner.respond_to? link_field.to_sym) && @owner.debug warn "Warning: Overriding method: #{@owner.class}##{link_field}"
ruby
{ "resource": "" }
q22476
SugarCRM.Association.cardinality_for
train
def cardinality_for(*args) args.inject([]) {|results,arg| result =
ruby
{ "resource": "" }
q22477
SugarCRM.Request.convert_reserved_characters
train
def convert_reserved_characters(string) string.gsub!(/&quot;/, '\"') string.gsub!(/&apos;/, '\'') string.gsub!(/&amp;/, '\&')
ruby
{ "resource": "" }
q22478
SugarCRM.Module.fields
train
def fields return @fields if fields_registered? all_fields = @session.connection.get_fields(@name) @fields = all_fields["module_fields"].with_indifferent_access
ruby
{ "resource": "" }
q22479
SugarCRM.Module.required_fields
train
def required_fields required_fields = [] ignore_fields = [:id, :date_entered, :date_modified] self.fields.each_value do |field| next if ignore_fields.include? field["name"].to_sym
ruby
{ "resource": "" }
q22480
SugarCRM.Module.deregister
train
def deregister return true unless registered? klass =
ruby
{ "resource": "" }
q22481
SugarCRM.AttributeSerializers.serialize_attribute
train
def serialize_attribute(name,value) attr_value = value attr_type = attr_type_for(name) case attr_type when :bool attr_value = 0 attr_value = 1 if value when :datetime, :datetimecombo begin attr_value = value.strftime("%Y-%m-%d %H:%M:%S") rescue
ruby
{ "resource": "" }
q22482
SugarCRM.Base.save
train
def save(opts={}) options = { :validate => true }.merge(opts) return false if !(new_record? || changed?) if options[:validate] return false if !valid?
ruby
{ "resource": "" }
q22483
SugarCRM.AttributeValidations.valid?
train
def valid? @errors = (defined?(HashWithIndifferentAccess) ? HashWithIndifferentAccess : ActiveSupport::HashWithIndifferentAccess).new self.class._module.required_fields.each do |attribute| valid_attribute?(attribute) end # for rails compatibility def @errors.full_messages # Aft...
ruby
{ "resource": "" }
q22484
SugarCRM.AttributeValidations.validate_class_for
train
def validate_class_for(attribute, class_array) return true if class_array.include? @attributes[attribute].class
ruby
{ "resource": "" }
q22485
SugarCRM.AttributeValidations.add_error
train
def add_error(attribute, message) @errors[attribute] ||= [] @errors[attribute] = @errors[attribute] << message
ruby
{ "resource": "" }
q22486
SugarCRM.Response.to_obj
train
def to_obj # If this is not a "entry_list" response, just return return @response unless @response && @response["entry_list"] objects = [] @response["entry_list"].each do |object| attributes = [] _module = resolve_module(object) attributes = flatten_name_value_list(object) ...
ruby
{ "resource": "" }
q22487
SugarCRM.AttributeTypeCast.attr_type_for
train
def attr_type_for(attribute) fields = self.class._module.fields field = fields[attribute] raise UninitializedModule, "#{self.class.session.namespace_const}Module #{self.class._module.name} was not initialized properly (fields.length == 0)" if fields.length == 0 raise InvalidAttribute, "#{self.class}._m...
ruby
{ "resource": "" }
q22488
SugarCRM.AttributeTypeCast.typecast_attributes
train
def typecast_attributes @attributes.each_pair do |name,value| # skip primary key columns # ajay Singh --> skip the loop if attribute is null (!name.present?) next if (name == "id") or (!name.present?) attr_type = attr_type_for(name) # empty attributes should stay empty (e.g. an ...
ruby
{ "resource": "" }
q22489
Angular.Setup.make_nodes
train
def make_nodes(ids, opt) result = [] ids.each do |id| id = id.tr('"', '') selector = "//*[@capybara-ng-match='#{id}']" nodes = page.driver.find_xpath(selector) raise NotFound.new("Failed to match found id to node") if
ruby
{ "resource": "" }
q22490
Angular.DSL.ng_root_selector
train
def ng_root_selector(root_selector = nil) opt = ng.page.ng_session_options if root_selector opt[:root_selector]
ruby
{ "resource": "" }
q22491
Angular.DSL.ng_binding
train
def ng_binding(binding, opt = {}) opt[:root_selector]
ruby
{ "resource": "" }
q22492
Angular.DSL.ng_bindings
train
def ng_bindings(binding, opt = {}) opt[:root_selector] ||= ng_root_selector
ruby
{ "resource": "" }
q22493
Angular.DSL.ng_model
train
def ng_model(model, opt = {}) opt[:root_selector]
ruby
{ "resource": "" }
q22494
Angular.DSL.has_ng_options?
train
def has_ng_options?(options, opt = {}) opt[:root_selector]
ruby
{ "resource": "" }
q22495
Angular.DSL.ng_option
train
def ng_option(options, opt = {}) opt[:root_selector]
ruby
{ "resource": "" }
q22496
Angular.DSL.ng_repeater_row
train
def ng_repeater_row(repeater, opt = {}) opt[:root_selector] ||= ng_root_selector row = ng.row(opt)
ruby
{ "resource": "" }
q22497
Angular.DSL.ng_repeater_column
train
def ng_repeater_column(repeater, binding, opt = {}) opt[:root_selector] ||= ng_root_selector row = ng.row(opt)
ruby
{ "resource": "" }
q22498
Angular.DSL.ng_repeater_columns
train
def ng_repeater_columns(repeater, binding, opt = {}) opt[:root_selector]
ruby
{ "resource": "" }
q22499
ZBar.Image.set_data
train
def set_data(format, data, width=nil, height=nil) ZBar.zbar_image_set_format(@img, format) # Note the @buffer jog: it's to keep Ruby GC from losing the last # reference to the old @buffer before calling image_set_data. new_buffer = FFI::MemoryPointer.from_string(data)
ruby
{ "resource": "" }