query
stringlengths
7
9.5k
document
stringlengths
10
1.07M
negatives
listlengths
19
19
metadata
dict
signed int max and min
def bitMaxMin n l=2**n min=-l/2 max=-min-1 return max,min end
[ "def relative_min_max( )\n limits!\n [ @min_assigned_int.to_f/@min_stored_int.to_f, @max_assigned_int.to_f/@max_stored_int.to_f ] \n end", "def define_min_and_max\n @min = acceptable_min\n @max = acceptable_max\n\n # If necessary, adjust a value depending on the other\n @min...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Increments a job try
def increment_try StatsD.increment("#{@prefix}.try") end
[ "def increment\n @mutex.synchronize { @running_jobs += 1 }\n end", "def increment_tries\n @tries += 1\n end", "def increment\n @attempt += 1\n log\n end", "def retry_attempts_for_job(job)\n retry_key = retry_key_for_job(job)\n if retry_key\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Increments a job success rubocop:disable Style/OptionalBooleanParameter
def increment_success(is_bdd = false) StatsD.increment("#{@prefix}.success", tags: ["is_bdd:#{is_bdd}"]) end
[ "def job_success\n upsert_job_status(Form526JobStatus::STATUS[:success])\n log_info('success')\n metrics.increment_success\n rescue => e\n Rails.logger.error('error tracking job success', error: e, class: klass)\n end", "def success(job)\n complete()\n end", "def suc...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Increments a non retryable error with a tag for the specific error
def increment_non_retryable(error, is_bdd = false) StatsD.increment("#{@prefix}.non_retryable_error", tags: error_tags(error, is_bdd)) end
[ "def increment_retryable(error, is_bdd = false)\n StatsD.increment(\"#{@prefix}.retryable_error\", tags: error_tags(error, is_bdd))\n end", "def incr_error\n redis.incr \"polipus:#{@job_name}:errors\" if @options[:stats_enabled]\n end", "def increment_exception(key)\n StatsD.increment...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Increments a retryable error with a tag for the specific error
def increment_retryable(error, is_bdd = false) StatsD.increment("#{@prefix}.retryable_error", tags: error_tags(error, is_bdd)) end
[ "def increment_non_retryable(error, is_bdd = false)\n StatsD.increment(\"#{@prefix}.non_retryable_error\", tags: error_tags(error, is_bdd))\n end", "def retryable_error_handler(error)\n upsert_job_status(Form526JobStatus::STATUS[:retryable_error], error)\n log_error('retryable_error', er...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add a search to the insession search history list.
def add_to_search_history(search) h = session[:history] h = h ? h.reject(&:blank?).unshift(search.id).uniq : [search.id] session[:history] = h.first(blacklight_config.search_history_window) end
[ "def add_to_search_history search\n session[:history] ||= []\n\n session[:history].unshift(search.id)\n\n if session[:history].length > blacklight_config.search_history_window\n session[:history] = session[:history].slice(0, blacklight_config.search_history_window)\n end\n end", "def add_to_sear...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns feeds having given source/topic slugs
def get_feeds(sources, topics) cond = [] cond << '1=1' cond << "topic_id IN (SELECT id FROM topics WHERE slug IN (#{topics}))" if (topics && topics.size > 0) cond << "source_id IN (SELECT id FROM sources WHERE slug IN (#{sources}))" if (sources && sources.size > 0) return Feed.find(:all, :condition...
[ "def get_feeds(source, topic, id = false)\n cond = []\n cond << \"1=1\"\n cond << \"source_id = #{source}\" if source\n cond << \"topic_id = #{topic}\" if topic\n cond << \"id = #{id}\" if id\n \n return Feed.find(:all, :conditions => cond.join(' AND '))\n end", "def feeds\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
We'll try a password with allcaps
def test_rejects_all_caps_passwords result = valid_password?("1ABJILS&A") refute(result, "'1ABJILS&A' should be invalid because it contains no lower-case letters") end
[ "def at_least_one_caps?(password)\n password != password.downcase\nend", "def test_reject_all_upper_case_passwords\n result = at_least_one_lower?(\"1ABJILS&A\")\n refute(result, \"'1ABJILS&A' should be invalid because it contains no caps\")\n end", "def is_password(password)\n if password.downcase ==...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
We try a password of only 7 characters, expecting rejection
def test_rejects_password_of_7_characters result = valid_password?("1Abils&") refute(result, "'1ABils&' should be invalid because it only has 7 characters") end
[ "def test_5_rejects_password_of_7_characters\n result = at_least_eight_characters?(\"1Abils&\")\n refute(result, \"'1ABils&' has 7 characters, should be valid\")\n end", "def test_rejects_password_of_7_characters\n result = at_least_eight_characters?(\"1Abils&\")\n refute(result, \"'1ABils&' has 8 ch...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
We try a password with no numbers on the method that checks for numbers.
def test_rejects_passwords_without_numbers result = valid_password?("Abjils&a") refute(result, "'Abjils&a' should be invalid because it contains no numbers") end
[ "def numbers?(password)\n password.gsub(/[0-9]/, \"\") != password\nend", "def at_least_one_number?(password)\n numbers = password.gsub(/[^0-9]/,\"\")\n numbers.length != 0\nend", "def check_password_contents\n if /[a-zA-Z]+/.match(@password) && /\\d+/.match(@password) && /[[:punct:]]/.match(@password)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
We try an invalid password without nonalphanumeric characters on the method that checks for nonalphanumeric characters.
def test_rejects_passwords_without_non_alphanumerics result = valid_password?("1Abjilsa") refute(result, "'1Abjils&a' should be invalid because it has no non-alphanumeric characters") end
[ "def test_rejects_password_with_no_na_char\n result = at_least_one_na_character?(\"1Abjilsa\")\n refute(result, \"'1Abjilsa should be invalid because it does not contain non-alphanumeric characters\")\n end", "def test_rejects_all_caps_passwords\n result = valid_password?(\"1ABJILS&A\")\n refute(resu...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Method for creating the appropriate MARC::Record based object by inspecting the record's leader
def create_record_for_type(leader) leader = Leader.new(leader) if RECORD_TYPES.has_key?(leader.get_type) record = RECORD_TYPES[leader.get_type].new else record = MARC::Record.new end record.leader = leader record end
[ "def create_leader(user)\n participant = Participant.new(school_id: self.id, user_id: user.id)\n participant.role_id = 1\n participant.accepted = 2\n participant.prereq = true\n participant.save\n end", "def leaderboard\n HQTrivia::User::Leaderboard.new(@data['leaderboard'])\n end", "def cre...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Method for retrieving a record from the opac, decoding it and returning a MARC::Record object
def get_record(bibnumber) if record_exists?(bibnumber) marc_url = URI_FOR_MARC % ([@scope] + Array.new(3, bibnumber)) record_url = URI_FOR_RECORD % [bibnumber, @scope] # Retrieve MARC data and convert to UTF-8 prior to decoding ... record_page = get_page(marc_url) ...
[ "def marc_record_from_marcxml\n id = fetch(_marc_source_field)\n\n response = Faraday.get(\"#{Requests.config['bibdata_base']}/bibliographic/#{id}\")\n response_stream = StringIO.new(response.body)\n marc_reader = MARC::XMLReader.new(response_stream)\n marc_rec...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Method for turning pseudo MARC data from III's OPAC into a MARC::Record object. Only data conversion done is replacing HTML entities with their corresponding characters
def decode_pseudo_marc(pseudo_marc) raise ParserError, "Cannot decode empty string." if pseudo_marc == "" pseudo_marc = pseudo_marc.split("\n") raw_fields = [] if pseudo_marc[0][0..5] == "LEADER" record = create_record_for_type(pseudo_marc[0][7..-1]) else ...
[ "def export_as_refworks_marc_txt\n marc_obj = to_marc\n return unless marc_obj\n fields = marc_obj.find_all { |f| ('000'..'999') === f.tag }\n text = \"LEADER #{to_marc.leader}\"\n fields.each do |field|\n unless [\"940\",\"999\"].include?(field.tag)\n if field.is_a?(MARC::ControlField)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
REZ(16.08) test_hand_value_is_correctly_calculated is to test that a given hand sums up the card values correctly from the Deck
def test_hand_value_is_correctly_calculated @deck = Deck.new @deck = [Card.new(:clubs,:four, 4), Card.new(:diamonds,:ten,10)] assert_equal @deck.value, 14 end
[ "def hand_value(hand)\n sum = 0\n hand.each do |card|\n sum += card\n end\n sum\n end", "def hand_value()\n # First rearrange the cards such that Aces appear at the end of the array\n @cards.sort_by { |card| card.to_i != 0 ? card : card[0] - 81 }.reverse().inject(0) do |total,cur...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
create Instance Method for user subscription status
def subscription_status @user_subscription_status = UserSubscription.where(account_id: self.account_id, currently_active: true).first if !@user_subscription_status.blank? if @user_subscription_status.subscription_id == 1 || @user_subscription_status.subscription.deliveries_included != 0 return "su...
[ "def subscription_created(user_id, discount_code:, products:, subscription_id:, subscription_mrr:, subscription_time_interval:, subscription_value:)\n track(user_id, SubscriptionCreated.new(\n discount_code: discount_code,\n products: products,\n subscription_id: subscription_id,\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Making sure songs are stored in minutes
def check_song_length if self.length > 10 then self.errors.add(:length, "is longer than 10 minutes...Calm down Free Bird.") elsif self.length < 1 then self.errors.add(:length, "is shorter than 1 minute...C'MON MAN!") end end
[ "def should_update_tone_each_minute\n return current_tone_set.size == 24\n end", "def minute? = unit == 'minute'", "def minutes_playing\n self[:min_play]\n end", "def parse_minutes(time)\n minutes = time.strftime(\"%M\").to_i\n minutes == 0 ? [sound_path(\"oclock.ul\")] : sou...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
cancel pipeline jobs for ref named `ref` across all of the group's projects
def cancel!(ref = 'SIMP-7974') warn( "acquiring group projects") projects = select_projects( @client_helper.projects_for_group, SKIPPED_PROJECTS ) pupmod_projects = projects.select{|x| x['name'] =~ /\Apupmod-simp/} warn pupmod_projects.map{|x| x['name']}.sort target_project_pipelines = projects.ma...
[ "def cancel(envid)\n @jobList.each { |job|\n if job.envid == envid && job.status == \"RUNNING\"\n begin\n Process.kill('TERM', job.pid.to_i)\n rescue Errno::ESRCH\n reportDone(job.pid, -1)\n end\n end\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Installs the NginX web server
def perform_install! warning "If you are planning to use #{y('Ruby')} and #{y('Passenger')} then #{r("DON'T")} use this NginX installer." warning "Instead, use the Passenger module to install it." standard "\n\s\s#{y("heavenly passenger install to #{y(e.name)}")}\n\n" message "I...
[ "def install\n (share+\"njs-nginx-module\").install Dir[\"*\"]\n end", "def start_web_server\n options = configuration.web_options.dup\n host = options.delete(:host)\n port = options.delete(:port)\n\n Thin::Logging.silent = true\n Thin::Server.new(host, port, Applicati...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Downloads the NginX configuration file
def perform_download_configuration! find_nginx! if not @nginx_conf error "Could not find the NginX configuration file in #{y(@nginx_conf)}" exit end local_nginx_dir = File.join(local.gitpusshuten_dir, 'nginx') FileUtils.mkdir_p(local_nginx_dir) ...
[ "def config\n get('/_config')\n end", "def config_file\n CONFIG_FILE\n end", "def config_file\n @config_file ||= File.exists?('config/hirb.yml') ? 'config/hirb.yml' :\n File.expand_path(File.join(ENV[\"HOME\"] || \".\", \".hirb.yml\"))\n end", "def conf\n home.join('nginx...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Uploads the NginX configuration file
def perform_upload_configuration! find_nginx! if not e.directory?('/etc/nginx') error "Could not find the NginX installation directory in #{y('/etc/nginx')}" exit end local_configuration_file = File.join(local.gitpusshuten_dir, 'nginx', 'nginx.conf') ...
[ "def configure\n upstream_config, proxy_config = configuration\n begin\n File.open(@config[\"upstream_config\"],\"w\") { |file| file.write upstream_config }\n File.open(@config[\"proxy_config\"],\"w\") { |file| file.write proxy_config }\n\n File.open(@config[\"pid_file\"]) do |file|\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Performs the Update Configuration command This is particularly used when you change Passenger or Ruby versions so these are updated in the nginx.conf file.
def perform_update_configuration! find_nginx! message "Checking the #{y(@nginx_conf)} for current Passenger configuration." config_contents = e.execute_as_root("cat '#{@nginx_conf}'") if not config_contents.include? 'passenger_root' or not config_contents.include?('passenger_rub...
[ "def perform_update_configuration!\n message \"Checking the #{y(@configuration_file)} for current Passenger configuration.\"\n config_contents = e.execute_as_root(\"cat '#{@configuration_file}'\") # prompts root\n if not config_contents.include? 'PassengerRoot' or not config_contents.include?('...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Installs the Nginx executable if it does not exist
def ensure_nginx_executable_is_installed! if not e.file?("/etc/init.d/nginx") message "Installing NginX executable for starting/stopping/restarting/reloading Nginx." e.download_packages!('$HOME', :root) e.execute_as_root("cp $HOME/gitpusshuten-packages/modules/nginx/nginx /etc/init...
[ "def install_nginx(cmd)\n execute 'install_nginx' do\n command \"#{cmd}\"\n end\nend", "def perform_install!\n warning \"If you are planning to use #{y('Ruby')} and #{y('Passenger')} then #{r(\"DON'T\")} use this NginX installer.\"\n warning \"Instead, use the Passenger module to install it.\"\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates a vhost template file if it doesn't already exist.
def create_vhost_template_file! FileUtils.mkdir_p(File.join(local.gitpusshuten_dir, 'nginx')) vhost_file = File.join(local.gitpusshuten_dir, 'nginx', "#{e.name}.vhost") create_file = true if File.exist?(vhost_file) warning "#{y(vhost_file)} already exists, do you want...
[ "def create_vhost_template_file!\n FileUtils.mkdir_p(File.join(local.gitpusshuten_dir, 'apache'))\n vhost_file = File.join(local.gitpusshuten_dir, 'apache', \"#{e.name}.vhost\")\n \n create_file = true\n if File.exist?(vhost_file)\n warning \"#{y(vhost_file)} already exi...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Renders the chord to the given key, with the given color scheme.
def render_into(song_key,color_scheme = ColorScheme.get('default')) if @sub render_color = color_scheme.color_for(song_key) render_key = song_key.transpose(-1) rendered_chord_note_raw = render_key.render_step(@step,color_scheme) rendered_chord_note = Note::get_enharmonic_in_color(rendered_ch...
[ "def color_for(song_key)\n full_scheme[song_key.key_id]\n end", "def add_color_key(key)\n \"\\033[\" + COLORS[@level.to_sym] + \"m\" + key.to_s + \"\\e[0m\"\n end", "def colorize(key, color)\n op = {:operation => :colorize, :key => key, :color => color}\n add_operation op\n end", "def colou...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Retrieve the chord symbol for this Chord instance.
def symbol sub_str = @sub ? "b" : "" chord_str = @@chord_symbols[@mode][@step] modifiers_str = @modifiers.empty? ? "" : "-#{@modifiers * "-"}" inversion_str = @inversion > 1 ? "_#{@inversion}" : "" "#{sub_str}#{chord_str}#{modifiers_str}#{inversion_str}".intern end
[ "def chord_symbol\n @chord_symbol ||= embellishments.select { |e| e.is_a?(ChordSymbol) }[-1]\n end", "def to_sym\n @symbol\n end", "def find_chord_name(t)\n CHORD_TYPES[t.to_sym][:name] rescue raise BadChordType.new(t)\n end", "def as_sym\n self\n end", "def to_sym\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Whether or not the chord is a sub chord. (modulation one halfstep down)
def is_sub? @sub end
[ "def sub?\n bool_property(:rnp_key_is_sub)\n end", "def could_be_subsecond?(subsecond); end", "def is_subsequence(s, t)\n t_id = 0\n s_id = 0\n while t_id < t.length && s_id < s.length\n s_id += 1 if t[t_id] == s[s_id]\n t_id += 1\n end\n s_id == s.length\nend", "def check_chord(chord, chor...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Initialize a new Chord instance with a given chord_symbol. Private method, and should only be
def initialize(chord_symbol) chord_symbol_str = chord_symbol.to_s chord_symbol_str += "_1" unless chord_symbol_str.include? "_" chord_with_mods,inversion_str = chord_symbol_str.split("_") chord_part_str,*@modifiers = chord_with_mods.to_s.split("-") if chord_part_str[0] == "b" ...
[ "def chord_symbol\n @chord_symbol ||= embellishments.select { |e| e.is_a?(ChordSymbol) }[-1]\n end", "def new_from_hash(hash)\n hash[:chords].each do |chord|\n self.chords << Chord.new(root: self.key, scale: chord[:chord_string])\n end\n self.save if hash[:save] == true\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /pastors/1 GET /pastors/1.xml
def show @pastor = Pastor.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @pastor } end end
[ "def new\n @pastor = Pastor.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @pastor }\n end\n end", "def show\n @pastor = Pastor.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @p...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /pastors/new GET /pastors/new.xml
def new @pastor = Pastor.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @pastor } end end
[ "def new\n @pastor = Pastor.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @pastor }\n end\n end", "def new\n @pastproject = Pastproject.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @pastpro...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /pastors POST /pastors.xml
def create @pastor = Pastor.new(params[:pastor]) respond_to do |format| if @pastor.save format.html { redirect_to(@pastor, :notice => 'El párroco fué creado correctamente.') } format.xml { render :xml => @pastor, :status => :created, :location => @pastor } t = Pastor.fin...
[ "def create\n @pastor = Pastor.new(params[:pastor])\n\n respond_to do |format|\n if @pastor.save\n format.html { redirect_to @pastor, notice: 'Pastor was successfully created.' }\n format.json { render json: @pastor, status: :created, location: @pastor }\n else\n format.html { r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PUT /pastors/1 PUT /pastors/1.xml
def update @pastor = Pastor.find(params[:id]) respond_to do |format| if @pastor.update_attributes(params[:pastor]) format.html { redirect_to(@pastor, :notice => 'El párroco se modificó correctamente.') } format.xml { head :ok } else format.html { render :action => "edit" } ...
[ "def update\n @pastor = Pastor.find(params[:id])\n\n respond_to do |format|\n if @pastor.update_attributes(params[:pastor])\n format.html { redirect_to @pastor, notice: 'Pastor was successfully updated.' }\n format.json { head :no_content }\n else\n format.html { render action: ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /pastors/1 DELETE /pastors/1.xml
def destroy @pastor = Pastor.find(params[:id]) @pastor.update_attributes(:state => false) respond_to do |format| format.html { redirect_to(pastors_url) } format.xml { head :ok } end end
[ "def destroy\n @pastor = Pastor.find(params[:id])\n @pastor.destroy\n\n respond_to do |format|\n format.html { redirect_to pastors_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @prior = Prior.find(params[:id])\n @prior.pfts.destroy\n @prior.destroy\n\n re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Build gRPC server parameters
def to_grpc_params { pool_size: rpc_pool_size, max_waiting_requests: rpc_max_waiting_requests, poll_period: rpc_poll_period, pool_keep_alive: rpc_pool_keep_alive, tls_credentials: tls_credentials, server_args: enhance_grpc_server_args(normalized_grpc_s...
[ "def to_grpc_params\n {\n pool_size: rpc_pool_size,\n max_waiting_requests: rpc_max_waiting_requests,\n poll_period: rpc_poll_period,\n pool_keep_alive: rpc_pool_keep_alive,\n server_args: normalized_grpc_server_args\n }\n end", "def to_grpc_params\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
total number of reviews
def reviews_count reviews.size end
[ "def number_of_reviews\n recipe_reviews.size\n end", "def review_count\n self.contractor_reviews.size\n end", "def review_comment_count\n self.reviews.map { |review| review.comments.count }.inject(:+)\n end", "def total_reviewed\n\t\tReview.where(user_id: id).count\n\tend", "def total_num_team_r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sends password reset email.
def send_password_reset_email UserMailer.password_reset(id, self.reset_token).deliver_later end
[ "def send_password_reset_email\n UserMailer.password_reset(self).deliver_now\t\t\t\t# send reset email\n end", "def send_password_reset_email\n UserMailer.password_reset(self, reset_token).deliver_later\n end", "def send_password_reset_mail\n Notifications.deliver_password_reset(self)\n end", "def...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
creates a WePay account for this user with the user's name
def create_wepay_account if self.has_wepay_access_token? && !self.has_wepay_account? params = { :name => self.name, :description => "Selling goods on Tradies " } response = WEPAY.call("/account/create", self.wepay_access_token, params) if response["account_id"] puts "need to get account_id" ...
[ "def create_wepay_account\n if self.has_wepay_access_token? && !self.has_wepay_account?\n params = { :name => self.name, :description => \"Member of the Trade Art Collective\"}\n response = TradeArtCollective::Application::WEPAY.call(\"/account/create\", self.wepay_access_token, params)\n\n if res...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SMS State is stored in a local sqlite db Get the current "state" of the phone number Returns a tuple of (last offset, lat, lng) If the phone number was not already in the db it is added with nil values get_state should have been called before using set_latlng or set_offset
def get_state(phone) db = SQLite3::Database.new( "test.db" ) row = db.get_first_row( "select * from stateinfo where phone=\"#{phone}\"" ) if (row != nil) row[1..3] else db.execute("insert into stateinfo (phone) values ( ? )", phone.to_s) (0,nil,nil) end end
[ "def contact_state\n details? ? details[\"Contact\"][\"state\"] : ''\n end", "def obtain_state(user, shipping_info)\n state_id = (shipping_info && shipping_info.zipcode && shipping_info.zipcode.state.id) ||\n (user && user.zipcode && user.zipcode.state.id)\n\n (state_id && State.find(stat...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST handler Given the place record (dict) and distance to that place (dist), format it into a string appropriate for sending via text message
def format_place(place, dist) dist = '%.2f' % dist.to_f [ place["name"], place["address1"], place["address2"], place["city"] + " " + place["state"] + " " + place["zip"], "#{dist} Miles Away" ].select { |a| a != nil and a.length > 0 }.join("\n") end
[ "def venue_fmt venue, lat, lon\n dist = nil\n dist_str = ''\n location = venue['location'] || {}\n vlat = location['lat']\n vlon = location['lng']\n if vlat and vlon\n dist = distance lat, lon, vlat, vlon\n compass = bearing lat, lon, vlat, vlon\n dist_str = '(%.1f mi %s)<br>' % [dist, compass]\n en...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Return a helpblock for the password field if the institution has a password_help_text translation password_field_help_text Casesensitive
def password_field_help_text help_text = t("application.#{auth_type_with_institution}.password_help_text", raise: true) content_tag(:p, help_text, class: 'help-block') if help_text rescue I18n::MissingTranslationData => e nil end
[ "def password_block_simple\n return @password_block_simple\n end", "def login_help_text\n @attributes[:login_help_text]\n end", "def password_label(password = \"Password\")\n h(password) + minimum_password_length\n end", "def forums_password_field\n # unit_test_no_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
def format_is_a_symbol unless format.is_a? Symbol errors.add(:format, "The format should be a symbol :atom, :rss, etc..") end end This method creates the slug to store on the Inkling::Path (see Inkling::Path)
def generate_path_slug slug = "/#{sluggerize(self.title)}.#{format_class.responds_to.to_s}" end
[ "def slug_generator_class; end", "def create_permalink\n \"#{self.name.latinize.to_ascii}-#{self.edition.latinize.to_ascii}\".gsub(/[^0-9A-Za-z|_\\- ]/,'')\n end", "def openurl_format format\n {\n 'article' => 'journal',\n 'other' => 'journal',\n }[format.to_s] || format.to_s\n end", "d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Find a user by an email.
def find_by_email(email:) users.where(email: email).first end
[ "def find_by_email(email)\n if email.strip.length > 0\n result = Ripple::client.search('users', \"email:#{email.downcase}\")\n if result['response']['numFound'] == 1\n return User.find(result['response']['docs'][0]['id']) # is this the best way?\n end\n end\n nil # Retur...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
set aqi messages based off of aqi index ranking
def aqi_message_set(index) case index.to_i when 0..50 "Good" when 51..100 "Moderate" when 101..150 "Unhealthy For Sensitive Groups" when 151..200 "Unhealthy" when 201..300 "Very Unhealthy" else "Hazardous" end end
[ "def set_rank\n\t\tself.update(:rank => self.game.players_remaining.count)\n\t\t# to be defined: how to rank player who has won game\n\tend", "def notify_over score\n\t\tfinal = Array.new(14){0}\n\t\tfinal[6]=score[0]\n\t\tfinal[13]=score[1]\n\t\tupdate_scores final\n\tend", "def indexdata(keyword,data)\n\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
asks user if they would like additional information on any of the ranked cities, if so, passes selected city instance to the local_aqi method call and then returns instance
def get_more_info? puts "Would you like local information for any of the cities listed? Please enter a numerical value 1-5, type 'exit' to end program, or type return to go to the main menu." puts "" @selected_city = nil user_input = nil #perform until user types a correct response from the avai...
[ "def call_from_ranking(ranked_city)\n\n site_link = 'https://airnow.gov/'\n\n #call scraper class method to access html of page based ranking\n @doc = AirQualityIndex::Scraper.new.nationwide_scraper_more_info(site_link.concat(ranked_city.link))\n\n #return aqi information for ranked city\n self.aqi_i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
method to return the max value in the linked list returns the data value and not the node
def find_max if @head == nil # empty list case # puts "Error: The linked list is empty. Cannot compute max." return nil end current = @head max = current.data current = current.next while current != nil if current.data > max max = current.data end current =...
[ "def max_value\n if @head.nil?\n return nil\n else\n if head.right\n max_value = max_search(head.right).data\n else\n max_value = head.data\n end\n end\n return max_value\n end", "def max\n val = max_node(@root).data if @root\n val\n end", "def find_max\r\n\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
method to return the min value in the linked list returns the data value and not the node
def find_min if @head == nil # empty list case # puts "Error: The linked list is empty. Cannot compute min." return nil end current = @head min = current.data current = current.next while current != nil if current.data < min min = current.data end current =...
[ "def find_min\r\n return nil if !@head\r\n\r\n min_val = @head.data\r\n cur = @head\r\n\r\n while(cur)\r\n min_val = cur.data if cur.data < min_val\r\n cur = cur.next\r\n end\r\n\r\n return min_val\r\n end", "def min\n val = min_node(@root).data if @root\n val\n end", "def fi...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /socks GET /socks.json
def index @socks = Sock.all end
[ "def show\n @sock = Sock.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @sock }\n end\n end", "def list_top_clients(args = {}) \n get(\"/clients.json/stats/top\", args)\nend", "def listproxy\n @proxies = Proxy.all\n\n respond_to ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /socks/1 DELETE /socks/1.json
def destroy @sock.destroy respond_to do |format| format.html { redirect_to socks_url, notice: 'Sock was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @sock = Sock.find(params[:id])\n @sock.destroy\n\n respond_to do |format|\n flash[:success] = \"Deleted successfully \"\n format.html { redirect_to socks_url }\n format.json { head :no_content }\n end\n end", "def delete(path, params={}); make_request(:delete, host, port...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
return an array of user ids blocked by current user
def blocked_user_ids Rails.cache.fetch("blocked_user_ids_#{id}", expires_in: 1.month.from_now) do blocked_users_relationships.pluck(:user_id) end end
[ "def invisible_to_me\n UserBlock.where(blocked_user_id: self.id).pluck(:user_id)\n end", "def banned_user_ids\n Rails.cache.fetch('banned-user-ids', expires_in: 1.week) do\n User.banned.pluck(:id)\n end\n end", "def blocked_users\n find_users_of_type \"USERS_BLOCKED_BY_ME\"\n end...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
public: test configuring a WorkCalendar Returns configured calendar
def test WorkCalendar.configure do |c| c.weekdays = %i(mon tue wed thu fri) c.holidays = [Date.new(2015, 1, 1), Date.new(2015, 7, 3), Date.new(2015, 12, 25)] end end
[ "def test_calendar_init\n assert_equal(1, @cal.get_date)\n end", "def cals\n EventCalendar.new($conf['calendar_files'])\nend", "def create_calendar\n cal = Icalendar::Calendar.new\n cal.event do |e|\n # e.dtstart = Icalendar::Values::self.time Don't know how to implement\n #...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /form_birs GET /form_birs.json
def index @form_birs = FormBir.all end
[ "def new\n @bili = Bili.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @bili }\n end\n end", "def retrieve_forms()\n start.uri('/api/form')\n .get()\n .go()\n end", "def new\n @bof = Bof.new\n\n respond_to do |format|\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /form_birs POST /form_birs.json
def create @form_bir = FormBir.new(form_bir_params) respond_to do |format| if @form_bir.save format.html { redirect_to @form_bir, notice: 'Form bir was successfully created.' } format.json { render :show, status: :created, location: @form_bir } else format.html { render :new...
[ "def submit_form_0966\n ClaimsApi::Logger.log('itf', detail: '0966 - Request Started')\n validate_json_schema\n validate_veteran_identifiers(require_birls: true)\n check_for_invalid_burial_submission! if form_type == 'burial'\n ClaimsApi::Logger.log('itf', detail: '0966 ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /form_birs/1 PATCH/PUT /form_birs/1.json
def update respond_to do |format| if @form_bir.update(form_bir_params) format.html { redirect_to @form_bir, notice: 'Form bir was successfully updated.' } format.json { render :show, status: :ok, location: @form_bir } else format.html { render :edit } format.json { render...
[ "def update\n @bof = Bof.find(params[:id])\n\n respond_to do |format|\n if @bof.update_attributes(params[:bof])\n format.html { redirect_to @bof, notice: 'Bof was successfully updated.' }\n format.json { head :no_content }\n else\n format.html { render action: \"edit\" }\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /form_birs/1 DELETE /form_birs/1.json
def destroy @form_bir.destroy respond_to do |format| format.html { redirect_to form_birs_url, notice: 'Form bir was successfully destroyed.' } format.json { head :no_content } end end
[ "def delete_form(form_id)\n start.uri('/api/form')\n .url_segment(form_id)\n .delete()\n .go()\n end", "def destroy\n @biopsias_form.destroy\n respond_to do |format|\n format.html { redirect_to biopsias_forms_url, notice: 'Biopsias form was successfully destroyed.' }\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
returns an instance of each item from the json, according the instance class passed. either returns a new record, or an instance from the database if the id is present
def find_instance_from_json(json, instance_class) key = instance_class.table_name.singularize details = json[key]&.slice(*REQUIRED_ATTRIBUTES[instance_class]) obj = nil if details obj = instance_class.new(details) obj = instance_class.find(obj.id) if obj.id end obj ...
[ "def find(class_or_classname, record_id)\n class_or_classname = find_or_materialize(class_or_classname)\n result = http_get(\"/services/data/v#{self.version}/sobjects/#{class_or_classname.sobject_name}/#{record_id}\")\n response = JSON.parse(result.body)\n new_record = class_or_classname.new\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /api/v2/dashboard/sub_products/1 PATCH/PUT /api/v2/dashboard/sub_products/1.json
def update render json: @sub_product.errors unless @sub_product.update(sub_product_params) end
[ "def update\n respond_to do |format|\n if @subproduct.update(subproduct_params)\n format.html { redirect_to @subproduct, notice: 'Teilprodukt wurde erfolgreich aktualisiert' }\n format.json { render :show, status: :ok, location: @subproduct }\n else\n format.html { render :edit }\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /api/v2/dashboard/sub_products/1 DELETE /api/v2/dashboard/sub_products/1.json
def destroy render json: { message: 'Sub Product deleted successfully', status: :ok } if @sub_product.destroy end
[ "def destroy\n @sub_product_detail.destroy\n respond_to do |format|\n format.html { redirect_to sub_product_details_url, notice: 'Detalle Sub producto exitosamente borrado.' }\n format.json { head :no_content }\n end\n end", "def destroy\n @subproduct.destroy\n respond_to do |format|\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Concurrency of message processing for a single subscription. 1 means sequential processing 2+ allow processed concurrently and possibly out of order.
def processing_concurrency=(value) raise ArgumentError, "nats: subscription processing concurrency must be positive integer" unless value.positive? return if @processing_concurrency == value @processing_concurrency = value @concurrency_semaphore = Concurrent::Semaphore.new(value) end
[ "def process_next_message\n @subscriptions.each_pair do |channel, session|\n queue = session[:queue]\n message = next_message_from(queue)\n\n process(channel, message) if message\n end\n end", "def perform!\n includes = [:next_caffeinate_mailing]\n preloads = []\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
next_msg blocks and waiting for the next message to be received.
def next_msg(opts={}) timeout = opts[:timeout] ||= 0.5 synchronize do return @pending_queue.pop if not @pending_queue.empty? # Wait for a bit until getting a signal. MonotonicTime::with_nats_timeout(timeout) do wait_for_msgs_cond.wait(timeout) end if not @...
[ "def next_message\n @pipe.receive\n end", "def next_message!\n self.messages.next\n rescue StopIteration\n nil\n end", "def process_next_server_message\n msg = nil\n begin\n @mutex_srvmsg.synchronize{\n if @srv_msg_queue.size > 0 and !is_msg_handler_suspended?\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /inviteds GET /inviteds.json
def index @inviteds = Invited.all end
[ "def index_invites\n puts \"user: #{@current_user.json_hash[:id]}\"\n dinners = []\n @dinners = @current_user.invited_dinners\n @dinners.each do |dinner|\n dinners << dinner.all_info\n end\n render json: dinners\n end", "def received_invitations\n user = User.find(params[:user_id])\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /inviteds/1 PATCH/PUT /inviteds/1.json
def update respond_to do |format| if @invited.update(invited_params) format.html { redirect_to @invited, notice: 'Invited was successfully updated.' } format.json { render :show, status: :ok, location: @invited } else format.html { render :edit } format.json { render json...
[ "def update\n invite = current_user.received_invites.find(params[:id])\n raise PermissionViolation unless current_user.updatable_by?(current_user)\n \n case params[:status].downcase\n when 'accepted' then invite.accept!\n when 'ignored' then invite.ignore!\n end\n \n respond_to do |...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /inviteds/1 DELETE /inviteds/1.json
def destroy @invited.destroy respond_to do |format| format.html { redirect_to inviteds_url, notice: 'Invited was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n invite = current_user.sent_invites.find(params[:id])\n raise PermissionViolation unless invite.destroyable_by?(current_user)\n \n invite.delete\n \n respond_to do |format|\n format.json { render :json => [{'status' => 'ok'}]}\n end\n end", "def destroy\n @invite = Invi...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Set result handler (block). This block is called for each result returned from a worker. The block shall take two parameters, job and result value. The result handler is always invoked in the same thread that calls Workersrun or Workersjob (usually the main thread). Parameters: +block+: Block that handles the result.
def on_result(&block) @result_handler = block end
[ "def set_result(&block)\n @exec_mutex.synchronize do\n raise ArgumentError, \"Must supply block\" unless block_given?\n raise ArgumentError, \"Already supplied block\" if bound?\n raise ArgumentError, \"Promise already executed\" if executed?\n\n _execute(block)\n end\n end", "def on_te...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add a job to the job queue. Will also process results and invoke the result handler if the job queue is full. Parameters: +job+: Job (of any class) to pass to the worker.
def run(job) if @inqueue.size >= @queue_length @result_handler.call(*result) end @inqueue.push(job) @jobcount += 1 nil end
[ "def add_job(job)\n @stream.add_message(job.to_message)\n job\n end", "def queue(job)\n self.class.queue << job\n end", "def push(job)\n if job.is_a? Array\n job.each { |j| self.push(j) }\n elsif job.respond_to? :call\n @jobs_count.increment\n if @latent && !@starte...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Waits for remainings jobs to be processed (and invokes result handler for each result). You can call this to ensure all results have been processed, or you can call Workersjoin which will do the same.
def complete @result_handler.call(*result) while @jobcount > 0 end
[ "def results\n loop do\n queue_pop do |res|\n yield res\n end\n sleep 1\n break if @workers.map {|w| w.alive?}.none?\n end\n # ensure there was nothing added to the queue after the workers completed.\n queue_pop do |res|\n yield res\n end\n @...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Data contained the the payload
def data @payload['data'] end
[ "def payload_data\n reply.documents[0][PAYLOAD].data\n end", "def data\n @data ||= if payload.is_a?(Hash)\n if claim && payload.key?('data')\n payload['data']\n else\n payload.except(*CLAIM_KEYS.map(&:to_s))\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates a new Shoes::Shape object
def shape(shape_style = {}, &blk) Shoes::Shape.new(app, style.merge(shape_style), blk) end
[ "def shape(shape_style={}, &blk)\n Shoes::Shape.new(style.merge(shape_style), blk)\n end", "def shape(left, top)\n # returns Shoes::Shape\n throw NotImplementedError\n end", "def create_shape\n id = rand 7\n @cur_y = 0\n @cur_x = 5\n @shape = SHAPES[id].dup\n end", "def add_s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates a new Shoes::Gradient
def gradient(*args) case args.length when 1 arg = args[0] case arg when Gradient min, max = arg.color1, arg.color2 when Range min, max = arg.first, arg.last else raise ArgumentError, "Can't make gradient out of #{arg.inspect}" end...
[ "def gradient(color1, color2)\n # returns Shoes::Pattern\n throw NotImplementedError\n end", "def fill_gradient(options)\r\n default_options = { :from => Gosu::Color::BLACK,\r\n :to => Gosu::Color::WHITE,\r\n :thickness => 10, \r\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sets the current line cap style
def cap line_cap @style[:cap] = line_cap end
[ "def line_cap_style(style=nil)\n cur_page.line_cap_style(style)\n end", "def linecap(style=:butt)\n case style\n when :round\n cap = KCGLineCapRound\n when :square\n cap = KCGLineCapSquare\n when :butt\n cap = KCGLineCapButt\n else\n raise \"ERROR: line...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests adding a new edge to a directed graph
def test_add_edge @dgraph.add_edge('a', 'b'); # 0 and 1 are indexes of vertex a and vertex b respectively assert(@dgraph.vertices[0].neighbours[1] == true && @dgraph.vertices[1].neighbours[0] == nil) end
[ "def test_insert_edges\n @graph.add_edge('a', 'b', 100)\n assert_equal(100, @graph.get_edge('a', 'b'))\n end", "def test_add_edge\n a = @graph.insertNode(\"A\")\n b = @graph.insertNode(\"B\")\n @graph.insertEdge(a, b)\n assert_equal(a.to[0], b)\n assert_equal(b.from[0], a)\n end", "def te...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests removing an edge from the graph
def test_remove_edge @dgraph.add_edge('a', 'b'); @dgraph.remove_edge('a','b') # 0 and 1 are indexes of vertex a and vertex b respectively assert(@dgraph.vertices[0].neighbours[1] == nil) end
[ "def test_remove_edge\n @graph.remove_edge('a','b')\n\n # 0 and 1 are indexes of vertex a and vertex b respectively\n assert(@graph.vertices[0].neighbours[1] == nil && @graph.vertices[1].neighbours[0] == nil)\n end", "def test_remove_edge_invalid\n\n puts 'Test remove edge invalid'\n graph = Graph...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests performing check if vertex is a source
def test_check_if_vertex_is_source @dgraph = DirectedGraph.new vertex_a = Vertex.new('a') vertex_b = Vertex.new('b') vertex_c = Vertex.new('c') vertex_d = Vertex.new('d') @dgraph.add_vertex(vertex_a).add_vertex(vertex_b).add_vertex(vertex_c).add_vertex(vertex_d) @dgraph.add_edge('a', 'd').ad...
[ "def test_check_if_vertex_is_source_when_not_source\n assert(@dgraph.check_if_vertex_is_source('c') == false && @dgraph.check_if_vertex_is_source('d') == false)\n end", "def source?(v)\n vertex?(v) and pred(v).empty?\n end", "def test_check_if_vertex_is_source_when_it_doesnt_exist\n assert(@dgraph.ch...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests performing check if vertex is a source when it's not depends on setup from previous test
def test_check_if_vertex_is_source_when_not_source assert(@dgraph.check_if_vertex_is_source('c') == false && @dgraph.check_if_vertex_is_source('d') == false) end
[ "def test_check_if_vertex_is_source_when_it_doesnt_exist\n assert(@dgraph.check_if_vertex_is_source('no_vertex') == false)\n end", "def test_check_if_vertex_is_source\n @dgraph = DirectedGraph.new\n vertex_a = Vertex.new('a')\n vertex_b = Vertex.new('b')\n vertex_c = Vertex.new('c')\n vertex_d ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests performing check if vertex is a source when it doesn't exist depends on setup from previous test
def test_check_if_vertex_is_source_when_it_doesnt_exist assert(@dgraph.check_if_vertex_is_source('no_vertex') == false) end
[ "def test_check_if_vertex_is_source_when_not_source\n assert(@dgraph.check_if_vertex_is_source('c') == false && @dgraph.check_if_vertex_is_source('d') == false)\n end", "def test_check_if_vertex_is_source\n @dgraph = DirectedGraph.new\n vertex_a = Vertex.new('a')\n vertex_b = Vertex.new('b')\n ver...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests building string representation of a graph
def test_to_s graph = DirectedGraph.new vertex_a = Vertex.new('a') vertex_b = Vertex.new('b') vertex_c = Vertex.new('c') graph.add_vertex(vertex_a).add_vertex(vertex_b).add_vertex(vertex_c) graph.add_edge('a','b').add_edge('c','b') assert(graph.to_s == 'a=>b,b=>,c=>b') end
[ "def test_to_s\n graph = Graph.new\n vertex_a = Vertex.new('a')\n vertex_b = Vertex.new('b')\n vertex_c = Vertex.new('c')\n graph.add_vertex(vertex_a).add_vertex(vertex_b).add_vertex(vertex_c)\n graph.add_edge('a','b').add_edge('c','b')\n\n assert(graph.to_s == 'a=>b,b=>a,b=>c,c=>b')\n end", ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests building a graph from hash
def test_build_from_hash graph = DirectedGraph.new graph.build({'a'=>nil,'b'=>'c','c'=>nil}) assert(graph.to_s == 'a=>,b=>c,c=>') end
[ "def test_build_from_hash\n graph = Graph.new\n graph.build({'a'=>'b','c'=>'b'})\n\n assert(graph.to_s == 'a=>b,b=>a,b=>c,c=>b')\n end", "def build_test_graph\n graph = OntologyGraph::Graph.new\n \n graph.add_relation('a', 'c')\n graph.add_relation('a', 'd')\n graph.add_relation('d', 'f')...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tests building a graph from string
def test_build_from_string graph = DirectedGraph.new graph.build('a=>,b=>c,c=>') assert(graph.to_s == 'a=>,b=>c,c=>') end
[ "def test_build_from_string\n graph = Graph.new\n graph.build('a=>b,c=>b')\n\n assert(graph.to_s == 'a=>b,b=>a,b=>c,c=>b')\n end", "def build_from_string(data)\n\n # Check if string representation of the graph is valid\n raise ArgumentError, 'String representation of the graph is invalid' unless d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /editoriales GET /editoriales.json
def index @editoriales = Editorial.all end
[ "def index\n @editorias = Editoria.all\n end", "def index\n @site_editorials = SiteEditorial.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @site_editorials }\n end\n end", "def index\n\tadd_breadcrumb \"Listado de editoriales\", :editoriales_i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add a new node to the start of the list
def prepend( value ) new_node = Node.new value # Whatever node was at the start of the list, it # is now the 'next' node for our newly created node new_node.next = @head # The new head of the list is set to be the new # node that we just created @head = new_node end
[ "def prepend( value )\n new_node = Node.new value\n\n # Whatever was at the start of the list, is now the 'next'\n # node for the new node we just created\n new_node.next = @head\n\n # The new head of the list is set to be the new node\n # that we just created\n @head = new_node\n end", "def...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Return the last node in this list
def last node = @head while node.next node = node.next end node end
[ "def last\n return @nodes[-1]\n end", "def last\n node = @head;\n return node if node.next.nil?\n until (node.next.nil?) #until end of list\n node = node.next\n return node if node.next.nil?\n end\n end", "def last_node\n return nil if @head.nil?\n current = @head\n w...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Instantiates the supplied page class, then runs the supplied block of code. Use this method when you are already on the site page you want to interact with.
def on page_class, visit=false, &block $current_page = page_class.new @browser, visit block.call $current_page if block $current_page end
[ "def on(page_class, browser = @browser)\n page = page_class.new(browser)\n yield page if block_given?\n page\n end", "def visit(page_class, &block)\n on page_class, visit = true, in_frame = false, &block\n end", "def method_missing(method, *args, &block)\n page.send(method, *args, &bl...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Will create below tree 3 /\ 9 20 /\ 15 7
def generate_tree root = TreeNode.new(3) root.left = TreeNode.new(9) right = TreeNode.new(20) right.left = TreeNode.new(15) right.right = TreeNode.new(7) root.right = right root end
[ "def get_tree\n n8 = Node.new(8)\n n9 = Node.new(9, n8, nil)\n n4 = Node.new(4)\n n7 = Node.new(7, n4, n9)\n n20 = Node.new(20)\n n11 = Node.new(11)\n n15 = Node.new(15, n11, n20)\n n10 = Node.new(10, n7, n15)\n end", "def build_tree(arr)\n #arr.shuffle!\n arr.each do |x|\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
The elves bought too much eggnog again 150 liters this time. To fit it all into your refrigerator, you'll need to move it into smaller containers. You take an inventory of the capacities of the available containers. For example, suppose you have containers of size 20, 15, 10, 5, and 5 liters. If you need to store 25 li...
def ways_to_fill_a_fridge(amount, available = [5, 5, 10, 15, 20]) containers = 1 ways = [] until containers > available.length schemes = available.combination(containers) schemes.each {|scheme| ways << scheme if scheme.inject(:+) == amount} containers += 1 end ways end
[ "def solve(containers, capacity, i, current_selection, selections)\n if capacity == 0\n selections << current_selection\n return\n elsif i < 0\n return\n elsif containers[i] > capacity # skip this container since it's no use\n solve(containers, capacity, i - 1, current_selection, selections)\n else\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /api/v1/group_messages_segments GET /api/v1/group_messages_segments.json
def index @api_v1_group_messages_segments = Api::V1::GroupMessagesSegment.all end
[ "def get_segments\n return make_request(\"#{self.endpoint}/list/segments\")\n end", "def get_segments(campaign)\n campaign['segments']\n end", "def lists_and_segments\n response = get \"listsandsegments\", {}\n Hashie::Mash.new(response)\n end", "def create\n @api...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /api/v1/group_messages_segments POST /api/v1/group_messages_segments.json
def create @api_v1_group_messages_segment = Api::V1::GroupMessagesSegment.new(api_v1_group_messages_segment_params) respond_to do |format| if @api_v1_group_messages_segment.save format.html { redirect_to @api_v1_group_messages_segment, notice: 'Group messages segment was successfully created.' } ...
[ "def index\n @api_v1_group_messages_segments = Api::V1::GroupMessagesSegment.all\n end", "def create_segment(digest)\n if digest.subscriber_emails.any?\n if digest.listserv.mc_list_id.present?\n detect_error(post(\"/lists/#{digest.listserv.mc_list_id}/segments\", body: {\n name: \"#{di...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /api/v1/group_messages_segments/1 PATCH/PUT /api/v1/group_messages_segments/1.json
def update respond_to do |format| if @api_v1_group_messages_segment.update(api_v1_group_messages_segment_params) format.html { redirect_to @api_v1_group_messages_segment, notice: 'Group messages segment was successfully updated.' } format.json { render :show, status: :ok, location: @api_v1_gro...
[ "def update\n respond_to do |format|\n if @api_v1_invitation_segments_group.update(api_v1_invitation_segments_group_params)\n format.html { redirect_to @api_v1_invitation_segments_group, notice: 'Invitation segments group was successfully updated.' }\n format.json { render :show, status: :ok, ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /api/v1/group_messages_segments/1 DELETE /api/v1/group_messages_segments/1.json
def destroy @api_v1_group_messages_segment.destroy respond_to do |format| format.html { redirect_to api_v1_group_messages_segments_url, notice: 'Group messages segment was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @api_v1_invitation_segments_group.destroy\n respond_to do |format|\n format.html { redirect_to api_v1_invitation_segments_groups_url, notice: 'Invitation segments group was successfully destroyed.' }\n format.json { head :no_content }\n end\n end", "def destroy\n @api_v1_camp...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /publishers/1 GET /publishers/1.xml
def show @publisher = Publisher.find(params[:id]) @users = User.find(:all, :order => :login) joins = nil conditions = [ 'publisher_id = ?', @publisher.id ] @servers = Server.search(params[:search], params[:page], joins, conditions, params[:sort]) respond_to do |format| format.html # sh...
[ "def publishers\n get_publishers_from_url('/publishers')\n end", "def view_publisher(uuid='')\n query('view/publishers/'+uuid,{},{},'GET')\n end", "def publishers\n JSON.parse(Typhoeus::Request.get(\n api_url('publishers'),\n :headers => {'User-Agent' => Punchr::USER_A...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /publishers/1/edit GET /publishers/1/edit.json
def edit @provider_accounts = provider_accounts_for_user @publisher = Publisher.find(params[:id]) @users = User.find(:all, :order => :login) respond_to do |format| format.html # edit.html.erb format.json { render :json => @publisher } end end
[ "def edit(client)\n raise \"Must have an id to edit a post\" unless id\n client.edit(request_parameters)\n end", "def edit\n respond_with(@entry)\n end", "def update\n @publisher = current_user.publishers.find(params[:id])\n\n respond_to do |format|\n if @publisher.update_attributes(...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
output: symbol of either equilateral, isosceles or scalene, or invalid if conditions unsatisfied rules: equilateral is all 3 sides are equal length isosceles is 2 sides are equal but 3rd is different scalene is all sides are different length sum of two shortest sides must be greater than length of longest side all side...
def triangle(first, second, third) sides_array = [first, second, third] max_value = sides_array.max sum_of_smaller_sides = sides_array.sum - max_value check_array = sides_array.uniq if sides_array.include?(0) || sum_of_smaller_sides < max_value return :invalid elsif check_array.size == 1 return :eq...
[ "def triangle(side1, side2, side3)\r\n sides = [side1, side2, side3]\r\n if sides.any? { |side| side < 1}\r\n :invalid\r\n elsif side1 == side2 && side1 == side3\r\n :equilateral\r\n else\r\n longest = sides.max\r\n shortest = sides.min(2)\r\n if shortest.reduce(:+) < longest\r\n :invalid\r\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
the parent prints 3 lines to the child, the child reads1 and 'exits', before it exits it shows the next 100 bytes awaiting it on its stdin, the parent not knowing if the child read all the data
def child io puts "[#{$$}] child: reading" line = io.readline puts "[#{$$}] child: line='#{line}'" extra = io.read_nonblock 100 puts "[#{$$}] child: extra='#{extra}'" exit end
[ "def read(bytes)\n @reader.read_nonblock(bytes)\n rescue Errno::EAGAIN\n # it simply means that there's nothing in\n # the output buffer.\n rescue Errno::EIO => msg\n @pid = nil\n rescue EOFError => msg\n @pid = nil\n end", "def run\n\n cmd = \"true\"\n stdin, stdout, pid = ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Upgrade channel to use SSL/TLS. Be aware that for this to work SSL must be configured.
def upgrade_to_ssl if block_given? @j_del.java_method(:upgradeToSsl, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling upgrade_to_ssl()" end
[ "def swap_sock_plain_to_ssl\n ctx = OpenSSL::SSL::SSLContext.new\n ctx.min_version = OpenSSL::SSL::TLS1_VERSION\n ctx.security_level = datastore['RDP_TLS_SECURITY_LEVEL']\n ssl = OpenSSL::SSL::SSLSocket.new(self.rdp_sock, ctx)\n\n begin\n ssl.connect\n rescue Errno::ECONNRESET\n vprint_e...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Instancelevel access to the marked_records
def marked_records self.class.marked_records end
[ "def marked_records\n (marked_records_proc.call || Set.new) if marked_records_proc\n end", "def assign_marked_records_to_model\n active_scaffold_config.model.marked_records_proc = proc {send(:marked_records)}\n end", "def decorated_record\n __getobj__\n end", "def process_marked_re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
the below test is really superseded by the one after it def test_game_move_places_marker_on_board
def test_first_move_places_x_on_board @game.move(1, 1) assert @game.spaces.include?('X') end
[ "def test_winmove9\n board = [\"x\",\"2\",\"x\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\"]\n player = Playerunbeets.new(\"o\")\n # board.place_marker(player.marker,1)\n # board.place_marker(player.marker,2)\n assert_equal(2, player.win_move(board))\n end", "def test_move_from_location\n @player.visit...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
I want to test computer can make a move, but that needs test in ComputerPlayer 1st
def test_computer_moves_after_opponent @game = Game.new('player_1', 'computer') assert_output(/O/) { @game.move(0, 1) } end
[ "def test_computer_player_wins_if_possible\n @board.place('X', 1, 1)\n @board.place('X', 1, 2)\n @player = ComputerPlayer.new('X')\n assert_equal [1, 0], @player.move(@board)\n end", "def set_computer_moves?(player)\n if player.is_computer?\n move = possible_plays.sample\n player.move...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
this send the instance calling this methid and action depending on what last message that came in form the user that is defined in the WORDS_MEANS_ACTION hash
def tell_me(who_wants_to_know) action_and_options = meaning(@@last_said).pop action = action_and_options.keys.first options = action_and_options.values.first who_wants_to_know.send action, options end
[ "def action_for_message\n val = session.delete(:context)\n @context = val && val.to_sym\n super || context && begin\n handler = handler_for_context\n [true, handler, payload['text'].try!(:split) || []] if handler\n end\n end", "def action(message)\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
returns empty array or words and action that match the message
def meaning(message) WORDS_MEANS_ACTION.find {|words, action| words.match(Regexp.new(message))} || [] end
[ "def words\n @message ? @message.split : []\n end", "def scan_message(message)\n out = []\n out << 'recall_hold' if message =~ /Recall/i\n out << 'recall_hold' if message =~ /hold /\n out << 'borrow_direct' if message =~ /Borrow/\n out << 'ill' if messa...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
283910 91 is the greatest sequence of 2 digits. In the following 10 digit number: 1234567890 67890 is the greatest sequence of 5 digits. Complete the solution so that it returns the largest five digit number found within the number given. The number will be passed in as a string of only digits. It should return a five ...
def solution(digits) greatest = 0 (0..(digits.size - 1)).each do |pos| num = digits[pos..pos+5].to_i greatest = num if num > greatest end greatest end
[ "def solution(digits)\n max_digits = 5 # How many digits\n digits_length = digits.to_s.length\n if digits_length < max_digits\n return digits\n end\n x=0\n y=x+max_digits # Position end of string to 5th digit\n largest_number = 0\n while y<= digits_length\n str_digits = subst...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /owners POST /owners.json
def create @owner = Owner.new(owner_params) respond_to do |format| if @owner.save format.html { redirect_to @owner, notice: 'Owner was successfully created.' } format.json { render :show, status: :created, location: @owner } else format.html { render :new } format.js...
[ "def add_owner(name)\n post :add_owner, :name => name\n end", "def create\n @owner = Owner.new(owner_params)\n\n if @owner.save\n render json: @owner, status: :created, location: @owner\n else\n render json: @owner.errors, status: :unprocessable_entity\n end\n end", "def create\n @...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /post297s/1 GET /post297s/1.xml
def show @post297 = Post297.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @post297 } end end
[ "def show\n @post185 = Post185.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.xml { render :xml => @post185 }\n end\n end", "def show\n @post170 = Post170.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.x...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }