_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q8200
Optser.OptSet.get!
train
def get!(key, default=nil, &block) value = get key, default, &block raise "Nil value found for option: #{key}, #{default}" if value.nil? return value end
ruby
{ "resource": "" }
q8201
Solrizer::Fedora.Indexer.connect
train
def connect if defined?(Blacklight) solr_config = Blacklight.solr_config elsif defined?(Rails.root.to_s) solr_config = load_rails_config else solr_config = load_fallback_config end if index_full_text == true && solr_config.has_key?(:fulltext) && solr_config[:fulltext].has_key?...
ruby
{ "resource": "" }
q8202
Solrizer::Fedora.Indexer.generate_dates
train
def generate_dates(solr_doc) # This will check for valid dates, but it seems most of the dates are currently invalid.... #date_check = /^(19|20)\d\d([- \/.])(0[1-9]|1[012])\2(0[1-9]|[12][0-9]|3[01])/ #if there is not date_t, add on with easy-to-find value if solr_doc[:date_t].nil? ::Solrize...
ruby
{ "resource": "" }
q8203
Solrizer::Fedora.Indexer.create_document
train
def create_document( obj ) solr_doc = Hash.new model_klazz_array = ActiveFedora::ContentModel.known_models_for( obj ) model_klazz_array.delete(ActiveFedora::Base) # If the object was passed in as an ActiveFedora::Base, call to_solr in order to get the base field entries from Activ...
ruby
{ "resource": "" }
q8204
Megam.API.post_accounts
train
def post_accounts(new_account) @options = {path: '/accounts/content', body: Megam::JSONCompat.to_json(new_account)}.merge(@options) request( :expects => 201, :method => :post, :body => @options[:body] ) end
ruby
{ "resource": "" }
q8205
MIPPeR.LPSolveModel.store_constraint_matrix
train
def store_constraint_matrix(constr, type) # Initialize arrays used to hold the coefficients for each variable row = [] colno = [] constr.expression.terms.each do |var, coeff| row << coeff * 1.0 colno << var.index end row_buffer = build_pointer_array row, :double ...
ruby
{ "resource": "" }
q8206
IMDB.Person.birthdate
train
def birthdate month_data_element = bio_document.at("td.label[text()*='Date of Birth']"). next_element.first_element_child date_month = month_data_element.inner_text.strip rescue "" year = month_data_element.next_element.inner_text.strip rescue "" Date.parse("#{date_month} #{year}"...
ruby
{ "resource": "" }
q8207
IMDB.Person.deathdate
train
def deathdate date_month = bio_document.at("h5[text()*='Date of Death']").next_element.inner_text.strip rescue "" year = bio_document.at("a[@href*='death_date']").inner_text.strip rescue "" Date.parse("#{date_month} #{year}") rescue nil end
ruby
{ "resource": "" }
q8208
IMDB.Person.filmography
train
def filmography #@return [Hash] # writer: [Movie] # actor: [Movie] # director: [Movie] # composer: [Movie] #as_writer = main_document.at("#filmo-head-Writer").next_element.search('b a').map { |e| e.get_attribute('href')[/tt(\d+)/, 1] } rescue [] #as_actor...
ruby
{ "resource": "" }
q8209
Tay.Specification.all_javascript_paths
train
def all_javascript_paths all_paths = [] all_paths += @javascripts all_paths += @background_scripts all_paths += @content_scripts.map { |cs| cs.javascripts }.compact all_paths.flatten.uniq end
ruby
{ "resource": "" }
q8210
Tay.Specification.all_stylesheet_paths
train
def all_stylesheet_paths all_paths = [] all_paths += @stylesheets all_paths += @content_scripts.map { |cs| cs.stylesheets }.compact all_paths.flatten.uniq end
ruby
{ "resource": "" }
q8211
LatoBlog.Category::SerializerHelpers.serialize
train
def serialize serialized = {} # set basic info serialized[:id] = id serialized[:title] = title serialized[:meta_language] = meta_language serialized[:meta_permalink] = meta_permalink # add category father informations serialized[:category_father] = category_father ? cat...
ruby
{ "resource": "" }
q8212
LatoBlog.Category::SerializerHelpers.serialize_base
train
def serialize_base serialized = {} # set basic info serialized[:id] = id serialized[:title] = title serialized[:meta_language] = meta_language serialized[:meta_permalink] = meta_permalink # return serialized category serialized end
ruby
{ "resource": "" }
q8213
MarkLogic.Collection.from_criteria
train
def from_criteria(criteria) queries = [] criteria.each do |k, v| name, operator, index_type, value = nil query_options = {} if (v.is_a?(Hash)) name = k.to_s query_options.merge!(v.delete(:options) || {}) sub_queries = [] v.each do |kk, vv| ...
ruby
{ "resource": "" }
q8214
RImageAnalysisTools.Drawing.draw
train
def draw(im, draw_value = 255.0) im.each do |ic| if (yield ic) then im.setValue(ic, draw_value) end end end
ruby
{ "resource": "" }
q8215
RImageAnalysisTools.Drawing.draw_shape
train
def draw_shape(im, location, shape_name=:circle, shape_parameters= 10) if self.respond_to?(shape_name) then self.send(shape_name, im, location, shape_parameters) end end
ruby
{ "resource": "" }
q8216
RImageAnalysisTools.Drawing.circle
train
def circle(im, center, radius) lower = ImageCoordinate[center[0]-radius-1, center[1]-radius-1, 0,0,0] upper = ImageCoordinate[center[0]+radius+1, center[1]+radius+1, 0,0,0] im.box_conservative(lower, upper, [:x, :y]) draw(im) do |ic| xdiff = ic[:x] - center[0] ydiff =...
ruby
{ "resource": "" }
q8217
RImageAnalysisTools.Drawing.ellipse
train
def ellipse(im, foci, radius_inc) min_x = foci[0][0] max_x = foci[1][0] min_y = foci[0][1] max_y = foci[1][1] if foci[1][0] < min_x then min_x = foci[1][0] max_x = foci[0][0] end if foci[1][1] < min_y then min_y = foci[1][1] max_y = foci[0][1]...
ruby
{ "resource": "" }
q8218
CSS.Annotate.annotate
train
def annotate(filename) engine = Sass::Engine.new(IO.read(filename), options.merge(:syntax=>guess_syntax(filename))) tree = engine.to_tree tree.perform!(Sass::Environment.new) resolve_rules tree @rows = to_rows(tree) end
ruby
{ "resource": "" }
q8219
CSS.Annotate.to_html
train
def to_html(filename) rows = annotate(filename) ERB.new(IO.read(File.dirname(__FILE__) + "/annotate/template.erb")).result(binding) rescue Sass::SyntaxError=>error error = Sass::SyntaxError.exception_to_css error, @options.merge(:full_exception=>true) ERB.new(IO.read(File.dirname(__FILE__) +...
ruby
{ "resource": "" }
q8220
CSS.Annotate.styles
train
def styles Sass::Engine.new(IO.read(File.dirname(__FILE__) + "/annotate/style.scss"), :syntax=>:scss).render end
ruby
{ "resource": "" }
q8221
Kelp.Visibility.page_contains?
train
def page_contains?(text_or_regexp) if text_or_regexp.class == String return page.has_content?(text_or_regexp) elsif text_or_regexp.class == Regexp return page.has_xpath?('.//*', :text => text_or_regexp) else raise ArgumentError, "Expected String or Regexp, got #{text_or_regexp....
ruby
{ "resource": "" }
q8222
Kelp.Visibility.should_see
train
def should_see(texts, scope={}) in_scope(scope) do texts = [texts] if (texts.class == String || texts.class == Regexp) # Select all expected values that don't appear on the page unexpected = texts.select do |text| !page_contains?(text) end if !unexpected.empty? ...
ruby
{ "resource": "" }
q8223
Kelp.Visibility.should_see_in_same_row
train
def should_see_in_same_row(texts, scope={}) in_scope(scope) do if !page.has_xpath?(xpath_row_containing(texts)) raise Kelp::Unexpected, "Expected, but did not see: #{texts.inspect} in the same row" end end end
ruby
{ "resource": "" }
q8224
VirtualMonkey.EBS.wait_for_snapshots
train
def wait_for_snapshots timeout=1500 step=10 while timeout > 0 puts "Checking for snapshot completed" snapshots = behavior(:find_snapshots) status= snapshots.map { |x| x.aws_status } break unless status.include?("pending") sleep step timeout -= step ...
ruby
{ "resource": "" }
q8225
VirtualMonkey.EBS.find_snapshot_timestamp
train
def find_snapshot_timestamp last_snap = behavior(:find_snapshots).last last_snap.tags.detect { |t| t["name"] =~ /timestamp=(\d+)$/ } timestamp = $1 end
ruby
{ "resource": "" }
q8226
OpenNamespace.ClassMethods.require_file
train
def require_file(name) name = name.to_s path = File.join(namespace_root,File.expand_path(File.join('',name))) begin require path rescue Gem::LoadError => e raise(e) rescue ::LoadError return nil end return true end
ruby
{ "resource": "" }
q8227
OpenNamespace.ClassMethods.const_defined?
train
def const_defined?(name,*inherit) if super(name,*inherit) true else # attempt to load the file that might have the constant require_file(OpenNamespace.const_path(name)) # check for the constant again return super(name,*inherit) end end
ruby
{ "resource": "" }
q8228
TodoLint.Todo.relative_path
train
def relative_path current_dir = Pathname.new(File.expand_path("./")) Pathname.new(path).relative_path_from(current_dir).to_s end
ruby
{ "resource": "" }
q8229
TodoLint.Todo.lookup_tag_due_date
train
def lookup_tag_due_date config.fetch(:tags).fetch(match[:tag]) rescue KeyError msg = "#{match[:tag]} tag not defined in config file" raise KeyError, msg end
ruby
{ "resource": "" }
q8230
DCPU16.Debug.debug
train
def debug(msg = nil, &block) return unless debug? puts "\n[DEBUG] - #{caller.first}" msg.each { |m| puts(m) } if msg.is_a?(Array) if msg.is_a?(Hash) msg.each do |k, v| puts "[#{k.to_s}]" if v.is_a?(Array) v.each {|m| puts(m) } else ...
ruby
{ "resource": "" }
q8231
ICU.Result.rateable=
train
def rateable=(rateable) if opponent.nil? @rateable = false return end @rateable = case rateable when nil then true # default is true when false then false # this is the only way to turn it off else true end end
ruby
{ "resource": "" }
q8232
GroupDocsStorageCloud.Configuration.auth_settings
train
def auth_settings { 'appsid' => { type: 'api_key', in: 'query', key: 'appsid', value: api_key_with_prefix('appsid') }, 'oauth' => { type: 'oauth2', in: 'header', key: 'Authorization', ...
ruby
{ "resource": "" }
q8233
Bixby.HttpChannel.execute_internal
train
def execute_internal(json_request, &block) if json_request.respond_to?(:headers) then # always required for posting to API json_request.headers["Content-Type"] = "application/json" end req = HTTPI::Request.new(:url => @uri, :body => json_request.to_wire) # add in extra headers...
ruby
{ "resource": "" }
q8234
ChronuscopClient.Synchronizer.write_last_update
train
def write_last_update(last_update_at) # Check for the presence of the tmp directory. if(! File::directory?("tmp")) then Dir.mkdir("tmp") end f = File.new("tmp/chronuscop.tmp","w") f.printf("%d",last_update_at.to_i) f.close() end
ruby
{ "resource": "" }
q8235
ChronuscopClient.Synchronizer.xml_time_to_integer
train
def xml_time_to_integer(str) arr = str.gsub(/T|Z|:/,"-").split(/-/) year = arr[0] month = arr[1] day = arr[2] hour = arr[3] min = arr[4] sec = arr[5] Time.utc(year,month,day,hour,min,sec).to_i end
ruby
{ "resource": "" }
q8236
ChronuscopClient.Synchronizer.sync_it_now
train
def sync_it_now puts "Attempt Sync" # Getting the last sync value. last_update_at = get_last_update_at # querying the page. page = @mechanize_agent.get("#{ChronuscopClient.configuration_object.chronuscop_server_address}/projects/#{ChronuscopClient.configuration_object.project_number}/tra...
ruby
{ "resource": "" }
q8237
VimPrinter.CLI.get_input_files
train
def get_input_files(args = {}) command = args.fetch(:command, nil) if command.nil? CodeLister.files(args) else # Note: base_dir must be the the same the directory where the command is executed from CodeLister.files_from_shell(command, args.fetch(:base_dir, ".")) end ...
ruby
{ "resource": "" }
q8238
VimPrinter.CLI.execute
train
def execute(options = {}) input_files = get_input_files(options) # we want to avoid printing the binary file input_files.delete_if do |file| File.binary?(file.gsub(/^\./, options[:base_dir])) end if input_files.empty? puts "No file found for your option: #{options}" ...
ruby
{ "resource": "" }
q8239
VimPrinter.CLI.to_htmls
train
def to_htmls(files, options = {}) FileUtils.chdir(File.expand_path(options[:base_dir])) files.each_with_index do |file, index| puts "FYI: process file #{index + 1} of #{files.size} : #{file}" to_html(file, options) end end
ruby
{ "resource": "" }
q8240
Takeout.Client.substitute_template_values
train
def substitute_template_values(endpoint, request_type, options={}) # Gets the proper template for the give CUSTOM_SCHEMA string for this endpoint and substitutes value for it based on give options endpoint_templates = @schemas.fetch(request_type.to_sym, nil) template = endpoint_templates.fetch(endpoin...
ruby
{ "resource": "" }
q8241
Regenerate.SiteRegenerator.copySrcToOutputFile
train
def copySrcToOutputFile(srcFile, outFile, makeBackup) if makeBackup makeBackupFile(outFile) end FileUtils.cp(srcFile, outFile, :verbose => true) end
ruby
{ "resource": "" }
q8242
BrownPaperTickets.Httpost.handle_deflation
train
def handle_deflation case last_response["content-encoding"] when "gzip" body_io = StringIO.new(last_response.body) last_response.body.replace Zlib::GzipReader.new(body_io).read when "deflate" last_response.body.replace Zlib::Inflate.inflate(last_response.body) end end
ruby
{ "resource": "" }
q8243
Timely.Cell.value_from_redis
train
def value_from_redis if val = Timely.redis.hget(redis_hash_key, redis_value_key) val = val.include?(".") ? val.to_f : val.to_i else val = value_without_caching Timely.redis.hset(redis_hash_key, redis_value_key, val) end val end
ruby
{ "resource": "" }
q8244
UsingYAML.ClassMethods.using_yaml
train
def using_yaml(*args) # Include the instance methods which provide accessors and # mutators for reading/writing from/to the YAML objects. include InstanceMethods # Each argument is either a filename or a :path option args.each do |arg| case arg when Symbol, String ...
ruby
{ "resource": "" }
q8245
RestlessRouter.Route.url_for
train
def url_for(options={}) if templated? template = Addressable::Template.new(base_path) template = template.expand(options) template.to_s else base_path end end
ruby
{ "resource": "" }
q8246
Serket.FieldDecrypter.decrypt
train
def decrypt(field) return if field !~ /\S/ iv, encrypted_aes_key, encrypted_text = parse(field) private_key = OpenSSL::PKey::RSA.new(File.read(private_key_filepath)) decrypted_aes_key = private_key.private_decrypt(Base64.decode64(encrypted_aes_key)) decrypted_field = decrypt_data(iv, decry...
ruby
{ "resource": "" }
q8247
Serket.FieldDecrypter.parse
train
def parse(field) case @format when :delimited field.split(field_delimiter) when :json parsed = JSON.parse(field) [parsed['iv'], parsed['key'], parsed['message']] end end
ruby
{ "resource": "" }
q8248
TJBootstrapHelper.Helper.page_header
train
def page_header *args, &block if block_given? size = (1..6) === args.first ? args.first : 1 content_tag :div, :class => "page-header" do content_tag "h#{size}" do capture(&block) end end else title = args.first size = (1..6) === args.se...
ruby
{ "resource": "" }
q8249
TJBootstrapHelper.Helper.nav_li
train
def nav_li *args, &block options = (block_given? ? args.first : args.second) || {} url = url_for(options) active = "active" if url == request.path || url == request.url content_tag :li, :class => active do link_to *args, &block end end
ruby
{ "resource": "" }
q8250
Services.Connection.find_servers
train
def find_servers # need a run_context to find anything in return nil unless run_context # If there are already servers in attribs use those return node[:etcd][:servers] if node.key?(:etcd) && node[:etcd].key?(:servers) # if we have already searched in...
ruby
{ "resource": "" }
q8251
Services.Connection.try_connect
train
def try_connect(server) c = ::Etcd.client(host: server, port: port, allow_redirect: @redirect) begin c.get '/_etcd/machines' return c rescue puts "ETCD: failed to connect to #{c.host}:#{c.port}" return nil end end
ruby
{ "resource": "" }
q8252
CronR.Cron.run
train
def run time=nil puts "[cron] run called #{Time.now}" if @debug time = self.time if time.nil? self.each { |cron_job| ok,details = cron_job.runnable?(time) if ok then @queue.enq(cron_job) if cron_job.once? then cron_job[:delete] = true end ...
ruby
{ "resource": "" }
q8253
CronR.Cron.start
train
def start debug=false,method=:every_minute,*args @stopped = false @suspended = false @dead = Queue.new @thread = CronR::Utils.send(method,debug,*args) { time = self.time @mutex.synchronize { if @stopped then # It's important we put something on this queue ON...
ruby
{ "resource": "" }
q8254
CronR.Cron.stop
train
def stop &block if block_given? then @stopped = true @suspended = false # Wait till something is put on the dead queue... # This stops us from acquiring the mutex until after @thread # has processed @stopped set to true. sig = @dead.deq # The cron thread sho...
ruby
{ "resource": "" }
q8255
Aker::Form::Middleware.LoginRenderer.provide_login_html
train
def provide_login_html(env) request = ::Rack::Request.new(env) html = login_html(env, :url => request['url'], :session_expired => request['session_expired']) html_response(html).finish end
ruby
{ "resource": "" }
q8256
ActiveAdminSimpleLife.SimpleElements.filter_for_main_fields
train
def filter_for_main_fields(klass, options ={}) klass.main_fields.each do |f| if f == :gender filter ExtensionedSymbol.new(f).cut_id, collection: genders else filter ExtensionedSymbol.new(f).cut_id end end end
ruby
{ "resource": "" }
q8257
ActiveAdminSimpleLife.SimpleElements.nested_form_for_main_fields
train
def nested_form_for_main_fields(klass, nested_klass, options={}) form_for_main_fields(klass,options) do |form_field| nested_table_name = nested_klass.to_s.underscore.pluralize.to_sym main_model_name = klass.to_s.underscore.to_sym form_field.has_many nested_table_name, allow_destroy: true d...
ruby
{ "resource": "" }
q8258
Authpwn.HttpBasicControllerInstanceMethods.authenticate_using_http_basic
train
def authenticate_using_http_basic return if current_user authenticate_with_http_basic do |email, password| signin = Session.new email: email, password: password auth = User.authenticate_signin signin self.current_user = auth unless auth.kind_of? Symbol end end
ruby
{ "resource": "" }
q8259
ActiveRecordTranslatable.ClassMethods.translate
train
def translate(*attributes) self._translatable ||= Hash.new { |h,k| h[k] = [] } self._translatable[base_name] = translatable.concat(attributes).uniq end
ruby
{ "resource": "" }
q8260
EventMachine.SystemCommand.execute
train
def execute &block raise 'Previous process still exists' unless pipes.empty? # clear callbacks @callbacks = [] @errbacks = [] pid, stdin, stdout, stderr = POSIX::Spawn.popen4 @command.to_s @pid = pid @stdin = attach_pipe_handler :stdin, stdin @stdout = attach_pipe_han...
ruby
{ "resource": "" }
q8261
EventMachine.SystemCommand.unbind
train
def unbind name pipes.delete name if pipes.empty? exit_callbacks.each do |cb| EM.next_tick do cb.call status end end if status.exitstatus == 0 EM.next_tick do succeed self end else EM.next_tick do ...
ruby
{ "resource": "" }
q8262
EventMachine.SystemCommand.kill
train
def kill signal = 'TERM', wait = false Process.kill signal, self.pid val = status if wait @stdin.close @stdout.close @stderr.close val end
ruby
{ "resource": "" }
q8263
AiGames.Parser.run
train
def run AiGames::Logger.info 'Parser.run : Starting loop' loop do command = read_from_engine break if command.nil? command.strip! next if command.length == 0 response = parse split_line command write_to_engine response unless response.nil? || response.lengt...
ruby
{ "resource": "" }
q8264
Fried::Typings.EnumeratorOf.valid?
train
def valid?(enumerator) return false unless Is[Enumerator].valid?(enumerator) enumerator.all? { |obj| Is[type].valid?(obj) } end
ruby
{ "resource": "" }
q8265
Activr.Activity.to_hash
train
def to_hash result = { } # id result['_id'] = @_id if @_id # timestamp result['at'] = @at # kind result['kind'] = kind.to_s # entities @entities.each do |entity_name, entity| result[entity_name.to_s] = entity.model_id end # meta result...
ruby
{ "resource": "" }
q8266
Activr.Activity.humanization_bindings
train
def humanization_bindings(options = { }) result = { } @entities.each do |entity_name, entity| result[entity_name] = entity.humanize(options.merge(:activity => self)) result["#{entity_name}_model".to_sym] = entity.model end result.merge(@meta) end
ruby
{ "resource": "" }
q8267
Activr.Activity.humanize
train
def humanize(options = { }) raise "No humanize_tpl defined" if self.humanize_tpl.blank? Activr.sentence(self.humanize_tpl, self.humanization_bindings(options)) end
ruby
{ "resource": "" }
q8268
Activr.Activity.check!
train
def check! # check mandatory entities self.allowed_entities.each do |entity_name, entity_options| if !entity_options[:optional] && @entities[entity_name].blank? raise Activr::Activity::MissingEntityError, "Missing '#{entity_name}' entity in this '#{self.kind}' activity: #{self.inspect}" ...
ruby
{ "resource": "" }
q8269
Confrider.Vault.deep_merge!
train
def deep_merge!(other_hash) other_hash.each_pair do |k,v| tv = self[k] self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? self.class.new(tv).deep_merge(v) : v end self end
ruby
{ "resource": "" }
q8270
Easymongo.Query.ids
train
def ids(data) # Just return if nothing to do return data if data and data.empty? # Support passing id as string data = {'_id' => data} if !data or data.is_a?(String) # Turn all keys to string data = data.stringify_keys # Convert id to _id for mongo data['_id'] = data....
ruby
{ "resource": "" }
q8271
Easymongo.Query.oid
train
def oid(v = nil) return BSON::ObjectId.new if v.nil?; BSON::ObjectId.from_string(v) rescue v end
ruby
{ "resource": "" }
q8272
EncryptedAttributes.MacroMethods.encrypts
train
def encrypts(*attr_names, &config) base_options = attr_names.last.is_a?(Hash) ? attr_names.pop : {} attr_names.each do |attr_name| options = base_options.dup attr_name = attr_name.to_s to_attr_name = (options.delete(:to) || attr_name).to_s # Figure out what ci...
ruby
{ "resource": "" }
q8273
EncryptedAttributes.InstanceMethods.write_encrypted_attribute
train
def write_encrypted_attribute(attr_name, to_attr_name, cipher_class, options) value = send(attr_name) # Only encrypt values that actually have content and have not already # been encrypted unless value.blank? || value.encrypted? callback("before_encrypt_#{attr_name}") ...
ruby
{ "resource": "" }
q8274
EncryptedAttributes.InstanceMethods.read_encrypted_attribute
train
def read_encrypted_attribute(to_attr_name, cipher_class, options) value = read_attribute(to_attr_name) # Make sure we set the cipher for equality comparison when reading # from the database. This should only be done if the value is *not* # blank, is *not* encrypted, and hasn't c...
ruby
{ "resource": "" }
q8275
EncryptedAttributes.InstanceMethods.create_cipher
train
def create_cipher(klass, options, value) options = options.is_a?(Proc) ? options.call(self) : options.dup # Only use the contextual information for this plugin's ciphers klass.parent == EncryptedAttributes ? klass.new(value, options) : klass.new(options) end
ruby
{ "resource": "" }
q8276
Edoors.Room.add_iota
train
def add_iota i raise Edoors::Exception.new "Iota #{i.name} already has #{i.parent.name} as parent" if not i.parent.nil? and i.parent!=self raise Edoors::Exception.new "Iota #{i.name} already exists in #{path}" if @iotas.has_key? i.name i.parent = self if i.parent.nil? @io...
ruby
{ "resource": "" }
q8277
Edoors.Room.add_link
train
def add_link l l.door = @iotas[l.src] raise Edoors::Exception.new "Link source #{l.src} does not exist in #{path}" if l.door.nil? (@links[l.src] ||= [])<< l end
ruby
{ "resource": "" }
q8278
Edoors.Room._try_links
train
def _try_links p puts " -> try_links ..." if @spin.debug_routing links = @links[p.src.name] return false if links.nil? pending_link = nil links.each do |link| if p.link_with? link if pending_link p2...
ruby
{ "resource": "" }
q8279
Edoors.Room._route
train
def _route p if p.room.nil? or p.room==path if door = @iotas[p.door] p.dst_routed! door else p.error! Edoors::ERROR_ROUTE_RRWD end elsif door = @spin.search_world(p.room+Edoors::PATH_SEP+p.door) ...
ruby
{ "resource": "" }
q8280
Edoors.Room._send
train
def _send p, sys=false if not sys and p.src.nil? # do not route non system orphan particles !! p.error! Edoors::ERROR_ROUTE_NS, @spin elsif p.dst # direct routing through pointer return elsif p.door # dir...
ruby
{ "resource": "" }
q8281
Edoors.Room.send_p
train
def send_p p puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing _send p puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_p p end
ruby
{ "resource": "" }
q8282
Edoors.Room.send_sys_p
train
def send_sys_p p puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin.debug_routing _send p, true puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin.debug_routing @spin.post_sys_p p end
ruby
{ "resource": "" }
q8283
Edoors.Room.process_sys_p
train
def process_sys_p p if p.action==Edoors::SYS_ACT_ADD_LINK add_link Edoors::Link.from_particle p elsif p.action==Edoors::SYS_ACT_ADD_ROOM Edoors::Room.from_particle p, self end @spin.release_p p end
ruby
{ "resource": "" }
q8284
Xyml.Document.out_XML
train
def out_XML io,indent=nil if indent Xyml.rawobj2domobj(@root).write(io,indent.to_i) else sio=StringIO.new Xyml.rawobj2domobj(@root).write(sio) sio.rewind io.print sio.read,"\n" end io.close end
ruby
{ "resource": "" }
q8285
Xyml.Document.load_XYML
train
def load_XYML io raw_yaml=YAML.load(io) @root=Xyml.rawobj2element raw_yaml[0] self.clear.push @root io.close end
ruby
{ "resource": "" }
q8286
Xyml.Document.out_JSON
train
def out_JSON io serialized=JSON.generate(Xyml.remove_parent_rcsv(self)) io.print serialized io.close end
ruby
{ "resource": "" }
q8287
Raca.Account.public_endpoint
train
def public_endpoint(service_name, region = nil) return IDENTITY_URL if service_name == "identity" endpoints = service_endpoints(service_name) if endpoints.size > 1 && region region = region.to_s.upcase endpoints = endpoints.select { |e| e["region"] == region } || {} elsif endpoi...
ruby
{ "resource": "" }
q8288
Raca.Account.refresh_cache
train
def refresh_cache # Raca::HttpClient depends on Raca::Account, so we intentionally don't use it here # to avoid a circular dependency Net::HTTP.new(identity_host, 443).tap {|http| http.use_ssl = true }.start {|http| payload = { auth: { 'RAX-KSKEY:apiKeyCrede...
ruby
{ "resource": "" }
q8289
Raca.Account.extract_value
train
def extract_value(data, *keys) if keys.empty? data elsif data.respond_to?(:[]) && data[keys.first] extract_value(data[keys.first], *keys.slice(1,100)) else nil end end
ruby
{ "resource": "" }
q8290
Slackdraft.Message.generate_payload
train
def generate_payload payload = {} payload[:channel] = self.channel unless self.channel.nil? payload[:username] = self.username unless self.username.nil? payload[:icon_url] = self.icon_url unless self.icon_url.nil? payload[:icon_emoji] = self.icon_emoji unless se...
ruby
{ "resource": "" }
q8291
HTTPAccess2.Client.set_basic_auth
train
def set_basic_auth(uri, user, passwd) uri = urify(uri) @www_auth.basic_auth.set(uri, user, passwd) reset_all end
ruby
{ "resource": "" }
q8292
HTTPAccess2.SSLConfig.set_client_cert_file
train
def set_client_cert_file(cert_file, key_file) @client_cert = OpenSSL::X509::Certificate.new(File.open(cert_file).read) @client_key = OpenSSL::PKey::RSA.new(File.open(key_file).read) change_notify end
ruby
{ "resource": "" }
q8293
HTTPAccess2.SSLConfig.set_context
train
def set_context(ctx) # Verification: Use Store#verify_callback instead of SSLContext#verify*? ctx.cert_store = @cert_store ctx.verify_mode = @verify_mode ctx.verify_depth = @verify_depth if @verify_depth ctx.verify_callback = @verify_callback || method(:default_verify_callback) # SSL config ...
ruby
{ "resource": "" }
q8294
HTTPAccess2.BasicAuth.set
train
def set(uri, user, passwd) if uri.nil? @cred = ["#{user}:#{passwd}"].pack('m').tr("\n", '') else uri = Util.uri_dirname(uri) @auth[uri] = ["#{user}:#{passwd}"].pack('m').tr("\n", '') end end
ruby
{ "resource": "" }
q8295
HTTPAccess2.Session.connect
train
def connect site = @proxy || @dest begin retry_number = 0 timeout(@connect_timeout) do @socket = create_socket(site) begin @src.host = @socket.addr[3] @src.port = @socket.addr[1] rescue SocketError # to avoid IPSocket#addr problem on Mac OS X 10....
ruby
{ "resource": "" }
q8296
HTTPAccess2.Session.read_header
train
def read_header if @state == :DATA get_data {} check_state() end unless @state == :META raise InvalidState, 'state != :META' end parse_header(@socket) @content_length = nil @chunked = false @headers.each do |line| case line when /^Content-Length:\s+(\d+)/i ...
ruby
{ "resource": "" }
q8297
Mongolicious.Storage.upload
train
def upload(bucket, key, path) Mongolicious.logger.info("Uploading archive to #{key}") @con.put_object( bucket, key, File.open(path, 'r'), {'x-amz-acl' => 'private', 'Content-Type' => 'application/x-tar'} ) end
ruby
{ "resource": "" }
q8298
Mongolicious.Storage.upload_part
train
def upload_part(bucket, key, upload_id, part_number, data) response = @con.upload_part(bucket, key, upload_id, part_number, data) return response.headers['ETag'] end
ruby
{ "resource": "" }
q8299
Mongolicious.Storage.complete_multipart_upload
train
def complete_multipart_upload(bucket, key, upload_id, parts) response = @con.complete_multipart_upload(bucket, key, upload_id, parts) return response end
ruby
{ "resource": "" }