_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q2400
Rley.ParseForestVisitor.traverse_children
train
def traverse_children(aParentNode) children = aParentNode.children broadcast(:before_subnodes, aParentNode, children) # Let's proceed with the visit of children children.each_with_index do |a_node, i| edge_sign = aParentNode.signatures[i] if a_node.kind_of?(SPPF::CompositeNode) push_node(a_node, edge_sign) access_paths = node_accesses[a_node] last_path = legs.last[-1] path_reused = access_paths.include?(last_path) unless path_reused
ruby
{ "resource": "" }
q2401
Celerity.ElementCollection.[]
train
def [](n) if @elements && @elements[n - Celerity.index_offset] element_class.new(@container, :object, @elements[n - Celerity.index_offset])
ruby
{ "resource": "" }
q2402
Celerity.SelectList.selected?
train
def selected?(value) assert_exists raise UnknownObjectException, "unknown option with value #{value.inspect} for select_list #{@conditions.inspect}" unless include?(value)
ruby
{ "resource": "" }
q2403
Celerity.Container.contains_text
train
def contains_text(expected_text) assert_exists return nil unless respond_to? :text case expected_text when Regexp text() =~ expected_text when String text().index(expected_text) else
ruby
{ "resource": "" }
q2404
Rley.Engine.parse
train
def parse(aTokenizer) tokens = [] aTokenizer.each do |a_token| next unless a_token term_name = a_token.terminal term_symb = grammar.name2symbol[term_name] a_token.instance_variable_set(:@terminal, term_symb) tokens << a_token end parser =
ruby
{ "resource": "" }
q2405
Rley.Engine.to_ptree
train
def to_ptree(aRawParse) factory = ParseRep::ParseTreeFactory.new(aRawParse) if configuration.repr_builder == :default result = factory.create(nil)
ruby
{ "resource": "" }
q2406
Rley.Engine.to_pforest
train
def to_pforest(aRawParse) factory = ParseRep::ParseForestFactory.new(aRawParse) if configuration.repr_builder == :default result = factory.create(nil)
ruby
{ "resource": "" }
q2407
Celerity.ElementLocator.with_nullpointer_retry
train
def with_nullpointer_retry(max_retries = 3) tries = 0 yield rescue java.lang.NullPointerException => e raise e if tries >= max_retries
ruby
{ "resource": "" }
q2408
Celerity.ClickableElement.click_and_attach
train
def click_and_attach assert_exists_and_enabled browser = Browser.new(@browser.options.dup) browser.webclient.set_cookie_manager( @browser.webclient.get_cookie_manager ) # hirobumi: we do want cookies as well.
ruby
{ "resource": "" }
q2409
Erlang.Map.value?
train
def value?(value) value = Erlang.from(value) each { |k,v|
ruby
{ "resource": "" }
q2410
Erlang.Map.get
train
def get(key) key = Erlang.from(key) entry = @trie.get(key) if entry return entry[1]
ruby
{ "resource": "" }
q2411
Erlang.Map.fetch
train
def fetch(key, default = Undefined) key = Erlang.from(key) entry = @trie.get(key) if entry return entry[1] elsif block_given? return yield(key)
ruby
{ "resource": "" }
q2412
Erlang.Map.slice
train
def slice(*wanted) trie = Trie.new(0) wanted.each { |key| key = Erlang.from(key)
ruby
{ "resource": "" }
q2413
Hive.Worker.poll_queue
train
def poll_queue @job = reserve_job if @job.nil? @log.info('No job found') else @log.info('Job starting') begin @current_job_start_time = Time.now execute_job rescue => e
ruby
{ "resource": "" }
q2414
Hive.Worker.reserve_job
train
def reserve_job @log.info "Trying to reserve job for queues: #{@queues.join(', ')}" job = job_message_klass.reserve(@queues, reservation_details)
ruby
{ "resource": "" }
q2415
Hive.Worker.diagnostics
train
def diagnostics retn = true protect retn = @diagnostic_runner.run if !@diagnostic_runner.nil? unprotect @log.info('Diagnostics failed') if not retn status = device_status
ruby
{ "resource": "" }
q2416
Hive.Worker.upload_files
train
def upload_files(job, *paths) @log.info("Uploading assets") paths.each do |path| @log.info("Uploading files from #{path}") Dir.foreach(path) do |item| @log.info("File: #{item}") next if item == '.' or item == '..' begin artifact = job.report_artifact("#{path}/#{item}")
ruby
{ "resource": "" }
q2417
Hive.Worker.checkout_code
train
def checkout_code(repository, checkout_directory, branch) CodeCache.repo(repository).checkout(:head,
ruby
{ "resource": "" }
q2418
Remedy.Characters.gremlins
train
def gremlins { space: "\u2420", tab: "\u21B9", carriage_return: "\u23CE", line_feed: "\u240A", control_c: "\u2404", control_d: "\u2403", control_r: "\u2412", escape: "\u238B",
ruby
{ "resource": "" }
q2419
Erlang.Bitstring.bitslice
train
def bitslice(arg, length = (missing_length = true)) if missing_length if arg.is_a?(Range) from, to = arg.begin, arg.end from += bitsize if from < 0 return nil if from < 0 to += bitsize if to < 0 to += 1 if !arg.exclude_end? length = to - from length = 0 if length < 0 length = bitsize - from if (from + length) > bitsize return nil if length < 0 l8 = length.div(8) l1 = length % 8 pad = 8 - l1 enum = each_bit skip = from enum = enum.drop_while { if skip > 0 skip -= 1 next true else next false end } head = enum.take(length) if l1 == 0 return Erlang::Binary[[head.join].pack(BIT_PACK)] else tail = head[-l1..-1]
ruby
{ "resource": "" }
q2420
Erlang.Bitstring.each_bit
train
def each_bit return enum_for(:each_bit) unless block_given? index = 0 headbits = (self.bytesize - 1) * 8 skipbits = 8 - @bits @data.each_byte do |byte| loop do break if index == @bitsize
ruby
{ "resource": "" }
q2421
Capybara::ChromeDevTools.DriverExtensions.start_crmux!
train
def start_crmux!(opts) self.chrome_debugging_port = find_free_port(Capybara::ChromeDevTools.preferred_port) self.crmux_listen_port = find_free_port(chrome_debugging_port + 1) opts[:options].args << "--remote-debugging-port=#{chrome_debugging_port}" #opts[:options].add_preference 'debuggerAddress', "127.0.0.1:#{crmux_listen_port}" @debug_crmux = true command = "npx crmux #{'-d' if @debug_crmux} \ --port=#{chrome_debugging_port} \ --listen=#{crmux_listen_port}" puts %(command: #{command}) if Capybara::ChromeDevTools.verbose >= 3 if @debug_crmux spawn_opts = {[:out, :err] => 'log/crmux.log'} else spawn_opts = {}
ruby
{ "resource": "" }
q2422
Hive.Device.start
train
def start parent_pid = Process.pid @worker_pid = Process.fork do object = Object @worker_class.split('::').each { |sub| object = object.const_get(sub) } object.new(@options.merge('parent_pid' => parent_pid, 'device_identity' => self.identity, 'port_allocator' => self.port_allocator, 'hive_id'
ruby
{ "resource": "" }
q2423
Hive.Device.stop
train
def stop protect_file = File.expand_path("#{@worker_pid}.protect", PIDS_DIRECTORY) Hive.logger.debug("Checking for protected file: #{protect_file}") if File.exists? File.expand_path("#{@worker_pid}.protect", PIDS_DIRECTORY) Hive.logger.debug("PID #{@worker_pid} is protected") false else @stop_count = @stop_count.nil? ? 0 : @stop_count + 1 if self.running? if @stop_count < 30 Hive.logger.info("Attempting to terminate process #{@worker_pid} [#{@stop_count}]") Process.kill 'TERM', @worker_pid
ruby
{ "resource": "" }
q2424
Tqdm.Printer.padded_line
train
def padded_line(iteration, elapsed_time) meter_line = line(iteration, elapsed_time) pad_size = [@last_printed_length - meter_line.size, 0].max
ruby
{ "resource": "" }
q2425
Erlang.Tuple.put
train
def put(index, element = yield(get(index))) raise IndexError, "index #{index} outside of tuple bounds" if index < -@size element = Erlang.from(element) index += @size if index < 0 if index > @size suffix = Array.new(index - @size, nil)
ruby
{ "resource": "" }
q2426
Erlang.Tuple.fetch
train
def fetch(index, default = (missing_default = true)) if index >= -@size && index < @size return get(index) elsif block_given? return Erlang.from(yield(index)) elsif !missing_default
ruby
{ "resource": "" }
q2427
Erlang.Tuple.slice
train
def slice(arg, length = (missing_length = true)) if missing_length if arg.is_a?(Range) from, to = arg.begin, arg.end from += @size if from < 0 to += @size if to < 0
ruby
{ "resource": "" }
q2428
Erlang.Tuple.insert
train
def insert(index, *elements) raise IndexError if index < -@size index += @size if index < 0 elements = elements.map { |element| Erlang.from(element) } if index < @size suffix = flatten_suffix(@root, @levels * BITS_PER_LEVEL, index, []) suffix.unshift(*elements) elsif index == @size suffix =
ruby
{ "resource": "" }
q2429
Erlang.Tuple.delete_at
train
def delete_at(index) return self if index >= @size || index < -@size index += @size if index <
ruby
{ "resource": "" }
q2430
Erlang.Tuple.select
train
def select return enum_for(:select) unless block_given? return reduce(self.class.empty) { |tuple, element|
ruby
{ "resource": "" }
q2431
Erlang.Tuple.shuffle
train
def shuffle return self.class.new(((array = to_a).frozen? ? array.shuffle
ruby
{ "resource": "" }
q2432
Erlang.Tuple.reverse
train
def reverse return self.class.new(((array = to_a).frozen? ? array.reverse
ruby
{ "resource": "" }
q2433
Erlang.Tuple.rotate
train
def rotate(count = 1) return self if (count % @size) == 0 return self.class.new(((array = to_a).frozen? ?
ruby
{ "resource": "" }
q2434
Erlang.Tuple.sort
train
def sort(&comparator) comparator = Erlang.method(:compare) unless block_given? array
ruby
{ "resource": "" }
q2435
Erlang.Tuple.drop
train
def drop(n) return self if n == 0 return self.class.empty if n >= @size raise ArgumentError, "attempt
ruby
{ "resource": "" }
q2436
Erlang.Tuple.*
train
def *(times) return self.class.empty if times == 0 return self if times == 1 result = (to_a * times)
ruby
{ "resource": "" }
q2437
Erlang.Tuple.combination
train
def combination(n) return enum_for(:combination, n) if not block_given? return self if n < 0 || @size < n if n == 0 yield [] elsif n == 1 each { |element| yield [element] } elsif n == @size yield self.to_a else combos = lambda do |result,index,remaining| while @size - index > remaining if remaining == 1 yield result.dup << get(index) else
ruby
{ "resource": "" }
q2438
Erlang.Tuple.repeated_combination
train
def repeated_combination(n) return enum_for(:repeated_combination, n) if not block_given? if n < 0 # yield nothing elsif n == 0 yield [] elsif n == 1 each { |element| yield [element] } elsif @size == 0 # yield nothing else combos = lambda do |result,index,remaining| while index < @size-1 if remaining == 1 yield result.dup << get(index) else
ruby
{ "resource": "" }
q2439
Erlang.Tuple.permutation
train
def permutation(n = @size) return enum_for(:permutation, n) if not block_given? if n < 0 || @size < n # yield nothing elsif n == 0 yield [] elsif n == 1 each { |element| yield [element] } else used, result = [], [] perms = lambda do |index| 0.upto(@size-1) do |i| if !used[i] result[index] = get(i) if index
ruby
{ "resource": "" }
q2440
Erlang.Tuple.product
train
def product(*tuples) tuples = tuples.map { |tuple| Erlang.from(tuple) } # if no tuples passed, return "product" as in result of multiplying all elements return super if tuples.empty? tuples.unshift(self) if tuples.any?(&:empty?) return block_given? ? self : [] end counters = Array.new(tuples.size, 0) bump_counters = lambda do i = tuples.size-1 counters[i] += 1
ruby
{ "resource": "" }
q2441
Erlang.Tuple.rindex
train
def rindex(obj = (missing_arg = true)) obj = Erlang.from(obj) i = @size - 1 if missing_arg if block_given? reverse_each { |element| return i if yield element; i -= 1 } return nil else
ruby
{ "resource": "" }
q2442
Erlang.Enumerable.partition
train
def partition return enum_for(:partition) if not block_given?
ruby
{ "resource": "" }
q2443
Erlang.Enumerable.inspect
train
def inspect result = "#{self.class}[" each_with_index { |obj, i| result << ', ' if i
ruby
{ "resource": "" }
q2444
Erlang.List.each
train
def each raise Erlang::ImproperListError if improper? return to_enum unless block_given? list = self until list.empty?
ruby
{ "resource": "" }
q2445
Erlang.List.flat_map
train
def flat_map(&block) raise Erlang::ImproperListError if improper? return enum_for(:flat_map) unless block_given? return self if empty? out = tail = Erlang::Cons.allocate list = self until list.empty? head_list = Erlang::List.from_enum(yield(list.head)) if head_list.empty? list = list.tail elsif list.tail.empty? tail.instance_variable_set(:@head, head_list.head) tail.instance_variable_set(:@tail, head_list.tail) tail.immutable! list = list.tail else new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@improper, false) tail.instance_variable_set(:@head, head_list.head)
ruby
{ "resource": "" }
q2446
Erlang.List.select
train
def select(&block) raise Erlang::ImproperListError if improper? return enum_for(:select) unless block_given? out = tail = Erlang::Cons.allocate list = self while !list.empty? if yield(list.head) new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) tail.instance_variable_set(:@tail, new_node) tail.instance_variable_set(:@improper,
ruby
{ "resource": "" }
q2447
Erlang.List.drop_while
train
def drop_while(&block) raise Erlang::ImproperListError if improper? return enum_for(:drop_while) unless block_given? list = self list
ruby
{ "resource": "" }
q2448
Erlang.List.pop
train
def pop raise Erlang::ImproperListError if improper? return self if empty?
ruby
{ "resource": "" }
q2449
Erlang.List.drop
train
def drop(number) raise Erlang::ImproperListError if improper? list = self while !list.empty? && number > 0
ruby
{ "resource": "" }
q2450
Erlang.List.append
train
def append(other) # raise Erlang::ImproperListError if improper? other = Erlang.from(other) return self if not improper? and Erlang.is_list(other) and other.empty? return other if Erlang.is_list(other) and empty? is_improper = Erlang.is_list(other) ? other.improper? : true out = tail = Erlang::Cons.allocate list = self until list.empty? new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, is_improper) tail.instance_variable_set(:@tail, new_node) tail.instance_variable_set(:@improper, is_improper) tail.immutable! tail = new_node if not Erlang.is_list(list.tail) new_node = Erlang::Cons.allocate
ruby
{ "resource": "" }
q2451
Erlang.List.transpose
train
def transpose raise Erlang::ImproperListError if improper? return Erlang::Nil if empty? return Erlang::Nil if any? { |list| list.empty? } heads, tails = Erlang::Nil, Erlang::Nil
ruby
{ "resource": "" }
q2452
Erlang.List.rotate
train
def rotate(count = 1) raise Erlang::ImproperListError if improper? raise TypeError, "expected Integer" if not count.is_a?(Integer) return self if empty? || (count % size) == 0
ruby
{ "resource": "" }
q2453
Erlang.List.sort
train
def sort(&comparator) comparator = Erlang.method(:compare) unless block_given? array
ruby
{ "resource": "" }
q2454
Erlang.List.intersperse
train
def intersperse(sep) raise Erlang::ImproperListError if improper? return self if tail.empty? sep = Erlang.from(sep) out = tail = Erlang::Cons.allocate list = self until list.empty? new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) if not list.tail.empty? sep_node = Erlang::Cons.allocate sep_node.instance_variable_set(:@head, sep) sep_node.instance_variable_set(:@improper, false) new_node.instance_variable_set(:@tail, sep_node) new_node.immutable! end tail.instance_variable_set(:@tail, new_node)
ruby
{ "resource": "" }
q2455
Erlang.List.union
train
def union(other) raise Erlang::ImproperListError if improper? other = Erlang.from(other) raise ArgumentError, "other must
ruby
{ "resource": "" }
q2456
Erlang.List.init
train
def init raise Erlang::ImproperListError if improper? return Erlang::Nil if tail.empty? out = tail = Erlang::Cons.allocate list = self until list.tail.empty? new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) tail.instance_variable_set(:@tail, new_node) tail.instance_variable_set(:@improper, false)
ruby
{ "resource": "" }
q2457
Erlang.List.last
train
def last(allow_improper = false) if allow_improper and improper? list = self list = list.tail while list.tail.kind_of?(Erlang::List)
ruby
{ "resource": "" }
q2458
Erlang.List.tails
train
def tails raise Erlang::ImproperListError if improper? return self if empty? out = tail = Erlang::Cons.allocate list = self until list.empty? new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list)
ruby
{ "resource": "" }
q2459
Erlang.List.inits
train
def inits raise Erlang::ImproperListError if improper? return self if empty? prev = nil return map do |head| if prev.nil?
ruby
{ "resource": "" }
q2460
Erlang.List.combination
train
def combination(n) raise Erlang::ImproperListError if improper? return Erlang::Cons.new(Erlang::Nil) if n == 0 return self if empty?
ruby
{ "resource": "" }
q2461
Erlang.List.chunk
train
def chunk(number) raise Erlang::ImproperListError if improper? return self if empty? out = tail = Erlang::Cons.allocate list = self until list.empty? first, list = list.split_at(number) new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, first) new_node.instance_variable_set(:@improper, false)
ruby
{ "resource": "" }
q2462
Erlang.List.flatten
train
def flatten raise Erlang::ImproperListError if improper? return self if empty? out = tail = Erlang::Cons.allocate list = self until list.empty? if list.head.is_a?(Erlang::Cons) list = list.head.append(list.tail) elsif Erlang::Nil.equal?(list.head) list = list.tail
ruby
{ "resource": "" }
q2463
Erlang.List.slice
train
def slice(arg, length = (missing_length = true)) raise Erlang::ImproperListError if improper? if missing_length if arg.is_a?(Range) from, to = arg.begin, arg.end from += size if from < 0 return nil if from < 0 to += size if to < 0 to += 1 if !arg.exclude_end? length = to - from length = 0 if length < 0 list = self while from > 0 return nil if list.empty? list = list.tail from -= 1 end return list.take(length) else return at(arg) end else
ruby
{ "resource": "" }
q2464
Erlang.List.indices
train
def indices(object = Erlang::Undefined, i = 0, &block) raise Erlang::ImproperListError if improper? object = Erlang.from(object) if object != Erlang::Undefined return indices { |item| item == object } if not block_given? return Erlang::Nil if empty? out = tail = Erlang::Cons.allocate list = self until list.empty? if yield(list.head)
ruby
{ "resource": "" }
q2465
Erlang.List.merge
train
def merge(&comparator) raise Erlang::ImproperListError if improper? return merge_by unless block_given? sorted = reject(&:empty?).sort do |a,
ruby
{ "resource": "" }
q2466
Erlang.List.insert
train
def insert(index, *items) raise Erlang::ImproperListError if improper? if index == 0 return Erlang::List.from_enum(items).append(self) elsif index > 0 out = tail = Erlang::Cons.allocate list = self while index > 0 new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) tail.instance_variable_set(:@tail, new_node) tail.instance_variable_set(:@improper, false) tail.immutable! tail = new_node list = list.tail index
ruby
{ "resource": "" }
q2467
Erlang.List.delete_at
train
def delete_at(index) raise Erlang::ImproperListError if improper? if index == 0 tail elsif index < 0 index += size if index < 0 return self if index < 0 delete_at(index) else out = tail = Erlang::Cons.allocate list = self while index > 0 new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) tail.instance_variable_set(:@tail, new_node)
ruby
{ "resource": "" }
q2468
Erlang.List.permutation
train
def permutation(length = size, &block) raise Erlang::ImproperListError if improper? return enum_for(:permutation, length) if not block_given? if length == 0 yield Erlang::Nil elsif length == 1 each { |obj| yield Erlang::Cons.new(obj, Erlang::Nil) } elsif not empty? if length < size tail.permutation(length, &block)
ruby
{ "resource": "" }
q2469
Erlang.List.partition
train
def partition(&block) raise Erlang::ImproperListError if improper? return enum_for(:partition) if not block_given? left = left_tail = Erlang::Cons.allocate right = right_tail = Erlang::Cons.allocate list = self while !list.empty? if yield(list.head) new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head) new_node.instance_variable_set(:@improper, false) left_tail.instance_variable_set(:@tail, new_node) left_tail.instance_variable_set(:@improper, false) left_tail.immutable! left_tail = new_node list = list.tail else new_node = Erlang::Cons.allocate new_node.instance_variable_set(:@head, list.head)
ruby
{ "resource": "" }
q2470
Erlang.List.inspect
train
def inspect if improper? result = 'Erlang::List[' list = to_proper_list list.each_with_index { |obj, i| result << ', ' if i > 0; result << obj.inspect } result << ']'
ruby
{ "resource": "" }
q2471
Erlang.Binary.copy
train
def copy(n = 1) raise ArgumentError, 'n must be a non-negative Integer' if
ruby
{ "resource": "" }
q2472
Erlang.Binary.each_bit
train
def each_bit return enum_for(:each_bit) unless block_given? index = 0 bitsize = self.bitsize @data.each_byte do |byte| loop do break if index == bitsize bit = (byte >> (7
ruby
{ "resource": "" }
q2473
Erlang.Binary.part
train
def part(position, length) raise ArgumentError, 'position must be an Integer' if not position.is_a?(::Integer) raise ArgumentError, 'length must be a
ruby
{ "resource": "" }
q2474
Culerity.RemoteBrowserProxy.wait_until
train
def wait_until time_to_wait=30, &block time_limit = Time.now + time_to_wait until block.call if Time.now > time_limit
ruby
{ "resource": "" }
q2475
Culerity.RemoteBrowserProxy.confirm
train
def confirm(bool, &block) blk = "lambda { #{bool} }" self.send_remote(:add_listener, :confirm)
ruby
{ "resource": "" }
q2476
Pixiv.Page.bind
train
def bind(client) if self.class.const_defined?(:WithClient) mod = self.class.const_get(:WithClient)
ruby
{ "resource": "" }
q2477
Pixiv.Client.login
train
def login(pixiv_id, password) doc = agent.get("https://accounts.pixiv.net/login?lang=ja&source=pc&view_type=page") return if doc && doc.body =~ /logout/ form = doc.forms_with(action: '/login').first
ruby
{ "resource": "" }
q2478
Pixiv.Client.download_illust
train
def download_illust(illust, io_or_filename, size = :original) size = {:s => :small, :m => :medium, :o => :original}[size] || size url = illust.__send__("#{size}_image_url") referer = case size when :small then nil when :medium then illust.url when :original then illust.url else raise ArgumentError, "unknown size `#{size}`" end save_to = io_or_filename
ruby
{ "resource": "" }
q2479
Pixiv.Client.download_manga
train
def download_manga(illust, pattern, &block) action = DownloadActionRegistry.new(&block) illust.original_image_urls.each_with_index do |url, n| begin action.before_each.call(url, n) if action.before_each
ruby
{ "resource": "" }
q2480
Pixiv.Client.filename_from_pattern
train
def filename_from_pattern(pattern, illust, url) pattern.map {|i| if i == :image_name name = File.basename(url) if name =~ /\.(\w+)\?\d+$/ name += '.' + $1 end
ruby
{ "resource": "" }
q2481
DNS.Zone.soa
train
def soa # return the first SOA we find in the records array. rr = @records.find { |rr| rr.type == "SOA" } return rr if rr # otherwise create a new SOA rr = DNS::Zone::RR::SOA.new
ruby
{ "resource": "" }
q2482
DNS.Zone.dump_pretty
train
def dump_pretty content = [] last_type = "SOA" sorted_records.each do |rr| content << '' if last_type != rr.type
ruby
{ "resource": "" }
q2483
DNS.Zone.sorted_records
train
def sorted_records # pull out RRs we want to stick near the top top_rrs = {} top = %w{SOA NS MX SPF TXT} top.each { |t| top_rrs[t] = @records.select { |rr|
ruby
{ "resource": "" }
q2484
Erlang.Associable.update_in
train
def update_in(*key_path, &block) if key_path.empty? raise ArgumentError, "must have at least one key in path" end key = key_path[0] if key_path.size == 1 new_value = block.call(fetch(key, nil)) else
ruby
{ "resource": "" }
q2485
Erlang.Associable.dig
train
def dig(key, *rest) value = get(key) if rest.empty? || value.nil?
ruby
{ "resource": "" }
q2486
Pandata.Scraper.download_all_data
train
def download_all_data(url) next_data_indices = {} while next_data_indices html = Downloader.read_page(url) # Sometimes Pandora returns the same next_data_indices as the previous page. # If we don't check for this, an infinite loop occurs. # This problem occurs with tconrad. prev_next_data_indices = next_data_indices
ruby
{ "resource": "" }
q2487
Pandata.Scraper.get_url
train
def get_url(data_name, next_data_indices = {}) if next_data_indices.empty? next_data_indices = { nextStartIndex: 0, nextLikeStartIndex: 0, nextThumbStartIndex: 0 }
ruby
{ "resource": "" }
q2488
Masq.Account.yubikey_authenticated?
train
def yubikey_authenticated?(otp) if yubico_identity? && Account.verify_yubico_otp(otp) (Account.extract_yubico_identity_from_otp(otp)
ruby
{ "resource": "" }
q2489
Vcard.DirectoryInfo.[]
train
def [](name) enum_by_name(name).each { |f| return f.value if f.value != ""}
ruby
{ "resource": "" }
q2490
Vcard.DirectoryInfo.push_unique
train
def push_unique(field) push(field) unless
ruby
{ "resource": "" }
q2491
Vcard.DirectoryInfo.delete
train
def delete(field) case when field.name?("BEGIN"), field.name?("END")
ruby
{ "resource": "" }
q2492
RandomData.Numbers.number
train
def number(n) n.is_a?(Range)
ruby
{ "resource": "" }
q2493
CSSModules.Rewrite.rewrite_css
train
def rewrite_css(css_module_code) # Parse incoming CSS into an AST css_root = Sass::SCSS::CssParser.new(css_module_code, "(CSSModules)", 1).parse
ruby
{ "resource": "" }
q2494
RandomData.Grammar.grammatical_construct
train
def grammatical_construct(grammar, what=nil) output = "" if what.nil? case grammar when Hash a_key = grammar.keys.sort_by{rand}[0] output += grammatical_construct(grammar, a_key) when Array grammar.each do |item| output += grammatical_construct(item) end when String output += grammar end else rhs = grammar[what] case rhs when Array rhs.each do |item| case item when Symbol output += grammatical_construct(grammar,item) when String output += item when Hash output += grammatical_construct(item) else
ruby
{ "resource": "" }
q2495
GoogleStaticMapsHelper.Location.endpoints_for_circle_with_radius
train
def endpoints_for_circle_with_radius(radius, steps = 30) raise ArgumentError, "Number of points has to be in range of 1..360!" unless (1..360).include?
ruby
{ "resource": "" }
q2496
RandomData.Names.companyname
train
def companyname num = rand(5) if num == 0 num = 1 end final = num.times.collect { @@lastnames.rand.capitalize } if final.count == 1 "#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}" else incorporation_type = rand(17) % 2 == 0 ? @@incorporation_types.rand : nil company_type = rand(17) %
ruby
{ "resource": "" }
q2497
OpenGraphReader.Builder.base
train
def base base = Base.new type = @parser.graph.fetch("og:type", "website").downcase validate_type type @parser.graph.each do |property| build_property base, property
ruby
{ "resource": "" }
q2498
Masq.ApplicationHelper.nav
train
def nav(name, url, pages = nil, active = false) content_tag :li, link_to(name, url), :class =>
ruby
{ "resource": "" }
q2499
Masq.ApplicationHelper.active_page?
train
def active_page?(pages = {}) is_active = pages.include?(params[:controller]) is_active
ruby
{ "resource": "" }