_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q3400
SOAP.Request.call
train
def call( methodName, args ) args = (args || {}) #.keys_to_sym! # Get Binding binding = @wsdl.bindings.getBindingForOperationName( @binding, methodName ) if binding.size == 0 raise SOAP::LCNoMethodError, "Undefined method `#{methodName}'" elsif binding.size > 1 raise SOAP::LCError, "Ambigous method name `#{methodName}', please, specify a binding name" else binding = binding[0] @binding = binding.name end # Get Binding Operation binding_operation = binding.operations[methodName] # Get PortType portType = @wsdl.portTypes[binding.type.nns] portType_operation = portType.operations[methodName] # Get message for input operation input_message = @wsdl.messages[portType_operation[:input][:message].nns] # Create method soap_method = "<#{methodName} xmlns=\"#{@wsdl.targetNamespace}\">\n" input_message.parts.each do |_, attrs| case attrs[:mode] when :type if SOAP::XSD::ANY_SIMPLE_TYPE.include?( attrs[attrs[:mode]].nns ) # Part refer to a builtin SimpleType soap_method << SOAP::XSD.displayBuiltinType( attrs[:name], args, 1, 1 ) else # Part refer to an XSD simpleType or complexType defined in types element = @wsdl.types[attrs[attrs[:mode]].nns][:value] case element[:type] when :simpleType soap_method << "<#{attrs[:name]}>\n#{element.display( @wsdl.types, args )}\n</#{attrs[:name]}>\n" # MAYBE ########## when :complexType soap_method << "<#{attrs[:name]}>\n#{element.display( @wsdl.types, args )}\n</#{attrs[:name]}>\n" # MAYBE ########## else raise SOAP::LCWSDLError, "Malformated part #{attrs[:name]}" end end when :element # Part refer to an XSD element element = @wsdl.types[attrs[attrs[:mode]].nns][:value] case element[:type] when :simpleType soap_method << element[element[:type]].display( @wsdl.types, args ) when :complexType soap_method <<
ruby
{ "resource": "" }
q3401
LDAPGroupsLookup.Search.lookup_dn
train
def lookup_dn(cn) service.search(base: tree, filter:
ruby
{ "resource": "" }
q3402
LDAPGroupsLookup.Search.lookup_mail
train
def lookup_mail(cn) service&.search(base: tree, filter: Net::LDAP::Filter.equals('cn', cn),
ruby
{ "resource": "" }
q3403
LDAPGroupsLookup.Search.walk_ldap_members
train
def walk_ldap_members(groups, dn, seen = []) groups.each do |g| members = ldap_members(g) return true if members.include? dn next if seen.include? g seen << g
ruby
{ "resource": "" }
q3404
LDAPGroupsLookup.Search.ldap_members
train
def ldap_members(cn, start=0) return [] if service.nil? # print "Getting members of #{cn} at index #{start}\n" entry = service.search(base: tree, filter: Net::LDAP::Filter.equals('cn', cn), attributes: ["member;range=#{start}-*"]).first return [] if entry.nil? field_name = entry.attribute_names[1] # Is this always ordered [dn, member]? return [] if field_name.nil? # Sometimes member is not present.
ruby
{ "resource": "" }
q3405
Singularity.Request.deploy
train
def deploy if is_paused puts ' PAUSED, SKIPPING.' return else @data['requestId'] = @data['id'] @data['id'] = "#{@release}.#{Time.now.to_i}" @data['containerInfo']['docker']['image'] = File.exist?('dcos-deploy/config.yml') ? YAML.load_file(File.join(Dir.pwd, 'dcos-deploy/config.yml'))['repo']+":#{@release}" : "#{JSON.parse(File.read('.mescal.json'))['image'].split(':').first}:#{@release}" @deploy = { 'deploy'
ruby
{ "resource": "" }
q3406
Outbox.Message.body
train
def body(value) each_message_type do |_, message| next if message.nil?
ruby
{ "resource": "" }
q3407
Outbox.Message.deliver
train
def deliver(audience) audience = Outbox::Accessor.new(audience) each_message_type do |message_type, message| next if message.nil?
ruby
{ "resource": "" }
q3408
Hicube.ApplicationController.notify
train
def notify(type, message, options = {}) options[:now] ||= false # Convert and cleanup. type = type.to_s.downcase.to_sym # Sanity check for type. unless FLASH_TYPES.include?(type) raise ArgumentError, "Invalid value for argument type: #{type}, expected one of: #{FLASH_TYPES.to_sentence}." end logger.info("FLASH (#{options.inspect}) #{type.to_s.upcase}: #{message}") if options[:now] == true
ruby
{ "resource": "" }
q3409
ParallelAppium.Android.start_emulators
train
def start_emulators emulators = `emulator -list-avds`.split("\n") emulators = emulators[0, ENV['THREADS'].to_i] Parallel.map(emulators, in_threads:
ruby
{ "resource": "" }
q3410
ShakeTheCounter.Section.make_reservation
train
def make_reservation(price_type_list: {}, affiliate: '', first_name: '', last_name: '', email: '') # step 1: make the reservation path = "event/#{performance.event.key}/performance/#{performance.key}/section/#{performance_section_key}/reservation/#{performance.event.client.language_code}" body = { PriceTypeList: price_type_list } result = performance.event.client.call(path, http_method: :post, body: body.to_json) reservation = ShakeTheCounter::Reservation.new(result) # step 2: create a contact path = "contact/#{performance.event.client.language_code}" body = { FirstName: first_name, LastName: last_name, MailAddress: email, LanguageCode: performance.event.client.language_code
ruby
{ "resource": "" }
q3411
Modelish.Base.to_hash
train
def to_hash out = {} self.class.properties.each
ruby
{ "resource": "" }
q3412
GitFeats.Checker.check
train
def check(args) # Load history and completed Completed.unserialize History.unserialize # request flag upload = false # Check for feats and update history Feats.all.each do |pattern, feats| if args.match?(pattern) History.add(pattern) feats.each do |feat, value| if History.count(pattern) >= value[:count] unless Completed.exists?(feat) Completed.add(feat) Reporter.report(value)
ruby
{ "resource": "" }
q3413
Shack.Stamp.rounded_corner
train
def rounded_corner(horizontal, vertical) css = [] << "border" attrs = { top: "bottom", bottom: "top", left: "right", right: "left" }
ruby
{ "resource": "" }
q3414
Imgurr.Storage.bootstrap
train
def bootstrap return if File.exist?(json_file) FileUtils.touch
ruby
{ "resource": "" }
q3415
GraphStarter.ApplicationHelper.asset_icon
train
def asset_icon(asset, image = (image_unspecified = true; nil)) image_url = if !image_unspecified image.source.url if image.present? elsif (asset.class.has_images? || asset.class.has_image?) && asset.first_image_source_url.present? asset.first_image_source_url
ruby
{ "resource": "" }
q3416
Beaker.GoogleComputeHelper.get_platform_project
train
def get_platform_project(name) if name =~ /debian/ return DEBIAN_PROJECT elsif name =~ /centos/ return CENTOS_PROJECT elsif name =~ /rhel/ return RHEL_PROJECT elsif name =~ /sles/
ruby
{ "resource": "" }
q3417
Beaker.GoogleComputeHelper.set_compute_api
train
def set_compute_api version, start, attempts try = (Time.now - start)/SLEEPWAIT while try <= attempts begin @compute = @client.discovered_api('compute', version) @logger.debug("Google Compute API discovered") return rescue => e
ruby
{ "resource": "" }
q3418
Beaker.GoogleComputeHelper.authenticate
train
def authenticate(keyfile, password, email, start, attempts) # OAuth authentication, using the service account key = ::Google::APIClient::PKCS12.load_key(keyfile, password) service_account = ::Google::APIClient::JWTAsserter.new( email, AUTH_URL,
ruby
{ "resource": "" }
q3419
Beaker.GoogleComputeHelper.execute
train
def execute req, start, attempts last_error = parsed = nil try = (Time.now - start) / SLEEPWAIT while try <= attempts begin result = @client.execute(req) parsed = JSON.parse(result.body) if not result.success? error_code = parsed["error"] ? parsed["error"]["code"] : 0 if error_code == 404 raise GoogleComputeError, "Resource Not Found: #{result.body}" elsif error_code == 400 raise GoogleComputeError, "Bad Request: #{result.body}" else raise GoogleComputeError, "Error attempting Google Compute API execute:
ruby
{ "resource": "" }
q3420
Beaker.GoogleComputeHelper.list_firewalls
train
def list_firewalls(start, attempts) result = execute( firewall_list_req(), start, attempts )
ruby
{ "resource": "" }
q3421
Beaker.GoogleComputeHelper.create_firewall
train
def create_firewall(name, network, start, attempts) execute( firewall_insert_req( name,
ruby
{ "resource": "" }
q3422
Beaker.GoogleComputeHelper.create_disk
train
def create_disk(name, img, start, attempts) #create a new boot disk for this instance disk = execute( disk_insert_req( name, img['selfLink'] ), start, attempts ) status = '' try = (Time.now - start) / SLEEPWAIT while status !~ /READY/ and try <= attempts
ruby
{ "resource": "" }
q3423
Beaker.GoogleComputeHelper.create_instance
train
def create_instance(name, img, machineType, disk, start, attempts) #add a new instance of the image instance = execute( instance_insert_req( name, img['selfLink'], machineType['selfLink'], disk['selfLink'] ), start, attempts) status = '' try = (Time.now - start) / SLEEPWAIT while status !~ /RUNNING/ and try <= attempts begin instance = execute( instance_get_req( name ), start, attempts ) status = instance['status'] rescue GoogleComputeError => e
ruby
{ "resource": "" }
q3424
Beaker.GoogleComputeHelper.delete_instance
train
def delete_instance(name, start, attempts) result = execute( instance_delete_req( name ), start, attempts ) # Ensure deletion of instance try = (Time.now - start) / SLEEPWAIT while try <= attempts begin result = execute( instance_get_req( name ), start, attempts ) @logger.debug("Waiting for #{name} instance deletion") sleep(SLEEPWAIT)
ruby
{ "resource": "" }
q3425
Beaker.GoogleComputeHelper.delete_disk
train
def delete_disk(name, start, attempts) result = execute( disk_delete_req( name ), start, attempts ) # Ensure deletion of disk try = (Time.now - start) / SLEEPWAIT while try <= attempts begin disk = execute( disk_get_req( name ), start, attempts ) @logger.debug("Waiting for #{name} disk deletion") sleep(SLEEPWAIT)
ruby
{ "resource": "" }
q3426
Beaker.GoogleComputeHelper.delete_firewall
train
def delete_firewall(name, start, attempts) result = execute( firewall_delete_req( name ), start, attempts ) #ensure deletion of disk try = (Time.now - start) / SLEEPWAIT while try <= attempts begin firewall = execute( firewall_get_req( name ), start, attempts ) @logger.debug("Waiting for #{name} firewall deletion") sleep(SLEEPWAIT)
ruby
{ "resource": "" }
q3427
Beaker.GoogleComputeHelper.instance_setMetadata_req
train
def instance_setMetadata_req(name, fingerprint, data) { :api_method => @compute.instances.set_metadata, :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME, 'instance' => name }, :body_object => {
ruby
{ "resource": "" }
q3428
Beaker.GoogleComputeHelper.instance_insert_req
train
def instance_insert_req(name, image, machineType, disk) { :api_method => @compute.instances.insert, :parameters => { 'project' => @options[:gce_project], 'zone' => DEFAULT_ZONE_NAME }, :body_object => { 'name' => name, 'image' => image, 'zone' => default_zone,
ruby
{ "resource": "" }
q3429
LetItGo.MethodCall.method_array
train
def method_array @parser = nil @caller_lines.each do |kaller| code = Ripper.sexp(kaller.contents) code ||= Ripper.sexp(kaller.contents.sub(/^\W*(if|unless)/, ''.freeze)) # if and unless "block" statements aren't valid one line ruby code code ||= Ripper.sexp(kaller.contents.sub(/do \|.*\|$/, ''.freeze)) # remove trailing do |thing| to make valid code code ||= Ripper.sexp(kaller.contents.sub(/(and|or)\W*$/, ''.freeze))# trailing and || or code ||= Ripper.sexp(kaller.contents.sub(/:\W*$/, ''.freeze)) # multi line ternary statements code ||= Ripper.sexp(kaller.contents.sub(/(^\W*)|({ \|?.*\|?)}/, ''.freeze)) # multi line blocks using {} puts
ruby
{ "resource": "" }
q3430
LetItGo.MethodCall.called_with_string_literal?
train
def called_with_string_literal? @string_allocation_count = 0 method_array.each do |m| positions.each {|position| @string_allocation_count +=
ruby
{ "resource": "" }
q3431
Maximus.Lint.refine
train
def refine(data) @task ||= '' data = parse_data(data) return puts data if data.is_a?(String) evaluate_severities(data) puts summarize if @config.is_dev? puts dev_format(data) ceiling_warning else
ruby
{ "resource": "" }
q3432
Maximus.Lint.files_inspected
train
def files_inspected(ext, delimiter = ',', remove = @config.working_dir) @path.is_a?(Array)
ruby
{ "resource": "" }
q3433
Maximus.Lint.relevant_output
train
def relevant_output(lint, files) all_files = {} files.each do |file| # sometimes data will be blank but this is good - it means no errors were raised in the lint next if lint.blank? || file.blank? || !file.is_a?(Hash) || !file.key?(:filename) lint_file = lint[file[:filename]] next if lint_file.blank? expanded = lines_added_to_range(file) revert_name = strip_working_dir(file[:filename]) all_files[revert_name] = [] lint_file.each do |l| if expanded.include?(l['line'].to_i)
ruby
{ "resource": "" }
q3434
Maximus.Lint.evaluate_severities
train
def evaluate_severities(data) @output[:lint_warnings] = [] @output[:lint_errors] = [] @output[:lint_conventions] = [] @output[:lint_refactors] = [] @output[:lint_fatals] = [] return if data.blank? data.each do |filename, error_list| error_list.each do |message|
ruby
{ "resource": "" }
q3435
Maximus.Lint.summarize
train
def summarize success = @task.color(:green) success << ": " success << "[#{@output[:lint_warnings].length}]".color(:yellow) success << " [#{@output[:lint_errors].length}]".color(:red) if @task == 'rubocop' success << " [#{@output[:lint_conventions].length}]".color(:cyan) success << " [#{@output[:lint_refactors].length}]".color(:white)
ruby
{ "resource": "" }
q3436
Maximus.Lint.ceiling_warning
train
def ceiling_warning lint_length = (@output[:lint_errors].length + @output[:lint_warnings].length + @output[:lint_conventions].length + @output[:lint_refactors].length + @output[:lint_fatals].length) return unless lint_length > 100 failed_task = @task.color(:green) errors = "#{lint_length} failures.".color(:red) errormsg = [ "You wouldn't stand a chance in Rome.\nResolve thy errors and train with #{failed_task} again.", "The gods frown upon you, mortal.\n#{failed_task}. Again.", "Do not embarrass the city. Fight another day. Use #{failed_task}.", "You are without honor. Replenish it with another #{failed_task}.",
ruby
{ "resource": "" }
q3437
Maximus.Lint.dev_format
train
def dev_format(errors = @output[:raw_data]) return if errors.blank? pretty_output = '' errors.each do |filename, error_list| filename = strip_working_dir(filename) pretty_output << "\n#{filename.color(:cyan).underline} \n" error_list.each do |message| pretty_output << severity_color(message['severity'])
ruby
{ "resource": "" }
q3438
Maximus.Lint.parse_data
train
def parse_data(data) # Prevent abortive empty JSON.parse error data = '{}' if data.blank? return "Error from #{@task}: #{data}" if data.is_a?(String) && data.include?('No such') data = JSON.parse(data) if data.is_a?(String)
ruby
{ "resource": "" }
q3439
Biffbot.Bulk.generate_post_body
train
def generate_post_body name, api_url, urls = [], options = {} post_body = {token: @token, name: name, apiUrl: api_url, urls: urls} options.each do |key, value|
ruby
{ "resource": "" }
q3440
Biffbot.Bulk.retrieve_data
train
def retrieve_data jobName, _options = {} # TODO: add support for csv endpoint = "http://api.diffbot.com/v3/bulk/download/#{@token}-#{jobName}_data.json"
ruby
{ "resource": "" }
q3441
Maximus.Config.evaluate_settings
train
def evaluate_settings(settings_data = @settings) settings_data.each do |key, value| next if value.is_a?(FalseClass) value = {} if value.is_a?(TrueClass) case key when :jshint, :JSHint, :JShint value = load_config(value) jshint_ignore settings_data[key] @settings[:jshint] = temp_it('jshint.json', value.to_json) when :scsslint, :SCSSlint value = load_config(value) @settings[:scsslint] = temp_it('scsslint.yml', value.to_yaml) when :rubocop, :Rubocop, :RuboCop value = load_config(value)
ruby
{ "resource": "" }
q3442
Maximus.Config.destroy_temp
train
def destroy_temp(filename = nil) if filename.nil? @temp_files.each { |filename, file| file.unlink } @temp_files = {} else return
ruby
{ "resource": "" }
q3443
Maximus.Config.load_config_file
train
def load_config_file(file_path, root) conf_location = if file_path.present? && File.exist?(file_path) file_path else config_exists('.maximus.yml', root) || config_exists('maximus.yml', root) || config_exists('config/maximus.yml', root) end
ruby
{ "resource": "" }
q3444
Maximus.Config.set_families
train
def set_families(head_of_house, family) if @settings.key?(head_of_house)
ruby
{ "resource": "" }
q3445
Maximus.Config.load_config
train
def load_config(value) return value unless value.is_a?(String) if value =~ /^http/ begin open(value) YAML.load open(value).read rescue puts "#{value} not accessible"
ruby
{ "resource": "" }
q3446
Maximus.Config.temp_it
train
def temp_it(filename, data) ext = filename.split('.') file = Tempfile.new([filename, ".#{ext[1]}"]).tap do |f| f.rewind f.write(data) f.close
ruby
{ "resource": "" }
q3447
Maximus.Config.split_paths
train
def split_paths(paths) new_paths = {} paths.each do |p| if p.split('/').length > 1 new_paths[p.split('/').last.to_s] = p else
ruby
{ "resource": "" }
q3448
Maximus.Config.wraith_setup
train
def wraith_setup(value, name = 'phantomjs') if @settings.key?(:urls) value['domains'] = @settings[:urls] else value['domains'] = {} # @see #domain value['domains']['main'] = domain end # Set wraith defaults unless they're already defined # Wraith requires
ruby
{ "resource": "" }
q3449
Maximus.Config.config_exists
train
def config_exists(file, root) present_location = File.join(root, file)
ruby
{ "resource": "" }
q3450
Maximus.Config.jshint_ignore
train
def jshint_ignore(settings_data_key) return unless settings_data_key.is_a?(Hash) && settings_data_key.key?('jshintignore') jshintignore_file = [] settings_data_key['jshintignore'].each { |i| jshintignore_file
ruby
{ "resource": "" }
q3451
CEF.Event.format_prefix
train
def format_prefix values = CEF::PREFIX_ATTRIBUTES.keys.map { |k| self.send(k) } escaped = values.map do |value|
ruby
{ "resource": "" }
q3452
CEF.Event.format_extension
train
def format_extension extensions = CEF::EXTENSION_ATTRIBUTES.keys.map do |meth| value = self.send(meth) next if value.nil? shortname = CEF::EXTENSION_ATTRIBUTES[meth] [shortname, escape_extension_value(value)].join("=")
ruby
{ "resource": "" }
q3453
Unsakini.ShareBoardController.validate_params
train
def validate_params if params[:encrypted_password].nil? or params[:shared_user_ids].nil? or params[:board].nil? render json: {}, status: 422 return end result = has_board_access(params[:board][:id]) if result[:status] != :ok render json: {}, status: result[:status] return else if !result[:user_board].is_admin render json: {}, status: :forbidden return
ruby
{ "resource": "" }
q3454
Unsakini.UsersController.create
train
def create user = User.new(user_params) if user.save UserMailer.confirm_account(user).deliver_now
ruby
{ "resource": "" }
q3455
Unsakini.UsersController.confirm
train
def confirm token = params[:token].to_s user = User.find_by(confirmation_token: token) if user.present? && user.confirmation_token_valid? if user.mark_as_confirmed! render json: {status: 'Account confirmed successfully.'} else
ruby
{ "resource": "" }
q3456
Unsakini.UsersController.search
train
def search user = User.where("email = ? AND id != ?", params[:email], @user.id).first if user render json:
ruby
{ "resource": "" }
q3457
Maximus.GitControl.commit_export
train
def commit_export(commit_sha = head_sha) commit_sha = commit_sha.to_s ce_commit = @g.gcommit(commit_sha) if first_commit == commit_sha ce_diff = diff_initial(first_commit) else last_commit = @g.gcommit(previous_commit(commit_sha))
ruby
{ "resource": "" }
q3458
Maximus.GitControl.compare
train
def compare(sha1 = master_commit_sha, sha2 = head_sha) diff_return = {} sha1 = define_psuedo_commit if @settings[:commit] # Reverse so that we go in chronological order git_spread = commit_range(sha1, sha2).reverse git_spread.each do |git_sha| # Grab all files in that commit and group them by extension
ruby
{ "resource": "" }
q3459
Maximus.GitControl.lints_and_stats
train
def lints_and_stats(lint_by_path = false, git_shas = compare, nuclear = false) return false if git_shas.blank? base_branch = branch git_ouput = {} git_shas.each do |sha, exts| create_branch(sha) unless @psuedo_commit sha = sha.to_s puts sha.color(:blue) exts.each do |ext, files| # For relevant_lines data lint_opts = { git_files: files, config: @config,
ruby
{ "resource": "" }
q3460
Maximus.GitControl.associations
train
def associations { css: ['css'], scss: ['scss', 'sass'], js: ['js'], ruby: ['rb', 'Gemfile', 'lock', 'yml', 'Rakefile', 'ru', 'rdoc', 'rake', 'Capfile', 'jbuilder'], rails: ['slim', 'haml', 'jbuilder', 'erb'], images: ['png', 'jpg', 'jpeg', 'gif'], static:
ruby
{ "resource": "" }
q3461
Maximus.GitControl.diff
train
def diff(old_commit, new_commit) stats = @g.diff(old_commit, new_commit).stats lines = lines_added(new_commit.sha) return if !lines.is_a?(Hash) || stats.blank? lines.each do |filename, filelines|
ruby
{ "resource": "" }
q3462
Maximus.GitControl.diff_initial
train
def diff_initial(commit_sha) data = commit_information(commit_sha) value = { total: { insertions: 0, deletions: 0, lines: 0, files: data.length }, files: {} }
ruby
{ "resource": "" }
q3463
Maximus.GitControl.match_associations
train
def match_associations(commit_sha, files) new_lines = lines_added(commit_sha) files = files.split("\n").group_by { |f| f.split('.').pop } associations.each do |ext, related| files[ext] ||= [] related.each do |child| next if files[child].blank? files[child].each do |c| # hack to ignore deleted files
ruby
{ "resource": "" }
q3464
Maximus.GitControl.lints_and_stats_nuclear
train
def lints_and_stats_nuclear(lint_opts) { lints: { scsslint: Maximus::Scsslint.new(lint_opts).result, jshint: Maximus::Jshint.new(lint_opts).result, rubocop: Maximus::Rubocop.new(lint_opts).result, railsbp: Maximus::Railsbp.new(lint_opts).result, brakeman: Maximus::Brakeman.new(lint_opts).result },
ruby
{ "resource": "" }
q3465
Maximus.GitControl.lints_and_stats_switch
train
def lints_and_stats_switch(ext, lint_opts) result = { lints: {}, statistics: {} } lints = result[:lints] statistics = result[:statistics] case ext when :scss lints[:scsslint] = Maximus::Scsslint.new(lint_opts).result # @todo stylestat is singular here because model name in Rails is singular. # But adding a .classify when it's converted to a model chops off the end s on 'phantomas', # which breaks the model name. statistics[:stylestat] = Maximus::Stylestats.new({config: @config}).result # @todo double pipe here is best way to say, if it's already run, don't run again, right? statistics[:phantomas] ||= Maximus::Phantomas.new({config: @config}).result statistics[:wraith] ||= Maximus::Wraith.new({config: @config}).result when :js lints[:jshint] =
ruby
{ "resource": "" }
q3466
Maximus.GitControl.destroy_branch
train
def destroy_branch(base_branch, sha) if base_branch == "maximus_#{sha}" @g.branch('master').checkout else
ruby
{ "resource": "" }
q3467
Maximus.GitControl.lint_file_paths
train
def lint_file_paths(files, ext) file_list = files.map { |f| f[:filename] }.compact # Lints accept files differently
ruby
{ "resource": "" }
q3468
Ronin.Path.join
train
def join(*names) joined_path = if root? then '' else self.to_s end names.each do |name|
ruby
{ "resource": "" }
q3469
Sandal.Claims.validate_claims
train
def validate_claims(options = {}) validate_exp(options[:max_clock_skew]) unless options[:ignore_exp] validate_nbf(options[:max_clock_skew]) unless options[:ignore_nbf]
ruby
{ "resource": "" }
q3470
Sandal.Claims.validate_exp
train
def validate_exp(max_clock_skew = 0) max_clock_skew ||= 0 exp = time_claim("exp") if exp && exp <= (Time.now - max_clock_skew)
ruby
{ "resource": "" }
q3471
Sandal.Claims.validate_nbf
train
def validate_nbf(max_clock_skew = 0) max_clock_skew ||= 0 nbf = time_claim("nbf") if nbf && nbf > (Time.now + max_clock_skew)
ruby
{ "resource": "" }
q3472
Sandal.Claims.validate_iss
train
def validate_iss(valid_iss) return unless valid_iss && valid_iss.length > 0 unless valid_iss.include?(self["iss"]) raise
ruby
{ "resource": "" }
q3473
Sandal.Claims.validate_aud
train
def validate_aud(valid_aud) return unless valid_aud && valid_aud.length > 0 aud = self["aud"] aud = [aud] unless aud.is_a?(Array) unless (aud
ruby
{ "resource": "" }
q3474
Sandal.Claims.time_claim
train
def time_claim(name) claim = self[name] if claim begin Time.at(claim) rescue
ruby
{ "resource": "" }
q3475
Xcunique.Sorter.sort
train
def sort objects.values.each do |object| SORTABLE_ITEMS.select { |key| object.has_key?(key) }.each do |key|
ruby
{ "resource": "" }
q3476
Xcunique.Sorter.comparator
train
def comparator uuid prefix = objects[uuid][Keys::ISA] == Keys::PBXGroup
ruby
{ "resource": "" }
q3477
CodeAnalyzer::CheckingVisitor.Default.check
train
def check(filename, content) node = parse(filename, content) node.file =
ruby
{ "resource": "" }
q3478
CodeAnalyzer::CheckingVisitor.Default.after_check
train
def after_check @checkers.each do |checker| after_check_callbacks = checker.class.get_callbacks(:after_check) after_check_callbacks.each
ruby
{ "resource": "" }
q3479
CodeAnalyzer::CheckingVisitor.Default.parse
train
def parse(filename, content) Sexp.from_array(Ripper::SexpBuilder.new(content).parse) rescue Exception
ruby
{ "resource": "" }
q3480
CodeAnalyzer::CheckingVisitor.Default.check_node
train
def check_node(node) checkers = @checks[node.sexp_type] if checkers checkers.each { |checker| checker.node_start(node) if checker.parse_file?(node.file) } end node.children.each { |child_node| child_node.file = node.file
ruby
{ "resource": "" }
q3481
CEF.UDPSender.emit
train
def emit(event) self.socksetup if self.sock.nil? # process eventDefaults - we are expecting a hash here. These will # override any values in the events passed to us. i know. brutal. unless self.eventDefaults.nil?
ruby
{ "resource": "" }
q3482
Librevox.Applications.bind_meta_app
train
def bind_meta_app args={}, &block arg_string = args.values_at(:key, :listen_to, :respond_on, :application).join(" ") arg_string
ruby
{ "resource": "" }
q3483
Librevox.Applications.bridge
train
def bridge *args, &block variables = if args.last.is_a? Hash # We need to sort the key/value pairs to facilitate testing. # This can be removed once 1.8-compat is dropped. key_value_pairs = args.pop.sort {|x,y| x.to_s <=> y.to_s} key_value_pairs.map! {|k,v| "#{k}=#{v}"} "{#{key_value_pairs.join(",")}}" else
ruby
{ "resource": "" }
q3484
Librevox.Applications.play_and_get_digits
train
def play_and_get_digits file, invalid_file, args={}, &block min = args[:min] || 1 max = args[:max] || 2 tries = args[:tries] || 3 terminators = args[:terminators] || "#" timeout
ruby
{ "resource": "" }
q3485
Librevox.Applications.record
train
def record path, params={}, &block args = [path,
ruby
{ "resource": "" }
q3486
Quantile.Estimator.query
train
def query(rank) flush current = @head return unless current mid_rank = (rank * @observations).floor max_rank = mid_rank + (invariant(mid_rank, @observations) / 2).floor rank = 0.0 while current.successor rank += current.rank
ruby
{ "resource": "" }
q3487
Maximus.Helper.file_list
train
def file_list(path, ext = 'scss', remover = '') # Necessary so that directories aren't counted collect_path = path.include?("*") ? path : "#{path}/**/*.#{ext}" # Remove first slash from path if present. probably a better
ruby
{ "resource": "" }
q3488
Maximus.Helper.truthy?
train
def truthy?(str) return true if str == true || str =~ (/^(true|t|yes|y|1)$/i) return false if
ruby
{ "resource": "" }
q3489
Maximus.Helper.edit_yaml
train
def edit_yaml(yaml_location, &block) d = YAML.load_file(yaml_location) block.call(d)
ruby
{ "resource": "" }
q3490
Maximus.Helper.path_exists?
train
def path_exists?(path = @path) path = path.split(' ') if path.is_a?(String) && path.include?(' ') if path.is_a?(Array) path.each do |p| unless File.exist?(p) puts "#{p} does not exist" return false end end
ruby
{ "resource": "" }
q3491
Maximus.Helper.discover_path
train
def discover_path(root = @config.working_dir, folder = '', extension = '') return @path unless @path.blank? if is_middleman? File.join(root, 'source', folder) elsif is_rails?
ruby
{ "resource": "" }
q3492
Unsakini.CommentOwnerControllerConcern.ensure_comment
train
def ensure_comment post_id = params[:post_id] comment_id = params[:comment_id] || params[:id] result = has_comment_access post_id, comment_id @comment =
ruby
{ "resource": "" }
q3493
Unsakini.CommentOwnerControllerConcern.has_comment_access
train
def has_comment_access(post_id, comment_id) comment = Unsakini::Comment.where(id: comment_id, post_id: post_id, user_id: @user.id).first if comment.nil?
ruby
{ "resource": "" }
q3494
RipperPlus.ScopeStack.with_closed_scope
train
def with_closed_scope(is_method = false) old_in_method = @in_method @in_method ||= is_method @stack.push(SCOPE_BLOCKER_9000) @stack.push(Set.new) yield
ruby
{ "resource": "" }
q3495
RipperPlus.ScopeStack.has_variable?
train
def has_variable?(var) @stack.reverse_each do |scope| if SCOPE_BLOCKER_9000 == scope return false
ruby
{ "resource": "" }
q3496
Unsakini.CommentsController.create
train
def create @comment = Comment.new(params.permit(:content)) @comment.user = @user @comment.post = @post if @comment.save
ruby
{ "resource": "" }
q3497
Unsakini.CommentsController.update
train
def update if @comment.update(params.permit(:content)) render json: @comment else
ruby
{ "resource": "" }
q3498
Unsakini.BoardOwnerControllerConcern.ensure_board
train
def ensure_board board_id = params[:board_id] || params[:id] result = has_board_access(board_id)
ruby
{ "resource": "" }
q3499
Unsakini.BoardOwnerControllerConcern.has_board_access
train
def has_board_access(board_id) board = nil if !board_id.nil? board = Unsakini::Board.find_by_id(board_id) else return {status: :bad_request} end if (board) user_board = Unsakini::UserBoard.where(user_id: @user.id, board_id: board_id).first
ruby
{ "resource": "" }