query stringlengths 7 9.5k | document stringlengths 10 1.07M | negatives listlengths 19 19 | metadata dict |
|---|---|---|---|
PUT /content_types/1 PUT /content_types/1.xml | def update
@content_type = ContentType.find(params[:id])
respond_to do |format|
if @content_type.update_attributes(params[:content_type])
flash[:notice] = 'ContentType was successfully updated.'
format.html { redirect_to(@content_type) }
format.xml { head :ok }
else
... | [
"def update\n @content_type = ContentType.find(params[:id])\n\n respond_to do |format|\n if @content_type.update_attributes(params[:content_type])\n format.html { redirect_to(@content_type, :notice => 'Content type was successfully updated.') }\n format.xml { head :ok }\n else\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /content_types/1 DELETE /content_types/1.xml | def destroy
@content_type = ContentType.find(params[:id])
@content_type.destroy
respond_to do |format|
format.html { redirect_to(content_types_url) }
format.xml { head :ok }
end
end | [
"def destroy\n @content_type = ContentType.get(params[:id])\n @content_type.destroy\n\n respond_to do |format|\n format.html { redirect_to(admin_content_types_url) }\n format.xml { head :ok }\n end\n end",
"def destroy\n @content_type = ContentType.find(params[:id])\n @content_type.d... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
buy a number of shares (potentially on margin) or none at all | def buy(account, ticker, shares, timestamp, on_margin = false)
cost = exchange.quote(ticker, timestamp) * shares
if cost >= 0 && (account.cash >= cost + buy_commission || on_margin)
account.cash -= (cost + buy_commission)
account.portfolio[ticker] += shares
account.commission_paid += buy_commi... | [
"def buy_margin(account, ticker, shares, bar_index)\n cost = exchange.quote(ticker, bar_index) * shares\n if cost >= 0\n account.cash -= (cost + buy_commission)\n account.portfolio[ticker] += shares\n account.commission_paid += buy_commission\n shares # return the number of shares bough... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Get single workflow in a repository | def workflow(repo, id, options = {})
get "#{Repository.path repo}/actions/workflows/#{id}", options
end | [
"def find(workflow_id)\n end",
"def get_workflow\n return @workflow\n end",
"def retrieve_workflow(id)\n @url = \"#{@url}/#{id}\"\n retrieve_resource\n end",
"def workflow\n if @workflow == \"\"\n @workflow = @server.get_run_attribute(@uuid, @links[:workflow])\n end\n @wo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
write a method that will take an array of numbers, and only return those that are prime | def select_primes(array)
array.select { |num| is_prime?(num) }
end | [
"def primes_in_array(array)\n array.select { |num| prime?(num) }\n end",
"def select_primes(array)\n array.delete(1)\n array.select do |num|\n (2...num).to_a.all? {|int| num % int != 0}\n end\nend",
"def pick_primes(arr)\n arr.select{|num| is_prime?(num)}\nend",
"def select_primes(arr)\n arr.sel... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
write a method that will take an array of numbers, and return the number of primes in the array | def count_primes(array)
select_primes(array).count
end | [
"def count_primes(array)\n array.delete_if {|num| num <= 1}\n primes = array.select do |num|\n (2...num).to_a.all? {|integer| num % integer != 0}\n end\n primes.count\nend",
"def number_of_primes(array)\n count = 0\n array.each { |num| count += 1 if prime?(num) }\n count \n end",
"def primes_in... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the api url used in all Mailgun API calls | def api_url
"#{protocol}://api:#{api_key}@#{host}/#{api_version}"
end | [
"def base_url\n \"#{Mailgun.protocol}://api:#{Mailgun.api_key}@#{Mailgun.mailgun_host}/#{Mailgun.api_version}\"\n end",
"def api_url\n @api_url ||= Addressable::URI.new(\n :scheme => scheme, :host => host, :port => port,\n :path => path_with_base(\"/_api\", resource_path)\n ).norma... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /short_messages/1 PATCH/PUT /short_messages/1.json | def update
respond_to do |format|
if @short_message.update(short_message_params)
format.html { redirect_to @short_message, notice: 'Short message was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render ... | [
"def update\n respond_to do |format|\n @message.update!(message_params)\n format.json { head :no_content }\n end\n end",
"def update\n respond_to do |format|\n if @boardshortmessage.update(boardshortmessage_params) && Boardshortmessage.encode_4_board(@boardshortmessage)\n format.ht... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /short_messages/1 DELETE /short_messages/1.json | def destroy
@short_message.destroy
respond_to do |format|
format.html { redirect_to short_messages_url }
format.json { head :no_content }
end
end | [
"def destroy\n @boardshortmessage.destroy\n respond_to do |format|\n format.html { redirect_to boardshortmessages_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @message.destroy\n respond_to do |format|\n format.json { head :no_content }\n end\n end",
"d... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /drivers GET /drivers.json | def index
@drivers = Driver.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @drivers }
end
end | [
"def index\n @drivers = Driver.all\n render json: @drivers\n end",
"def get_drivers\n taxi_id = params[:taxi_id]\n @drivers = Driver.get_by_taxi_id(taxi_id)\n render_as_json @drivers\n end",
"def show\n @driver = Driver.find(params[:id])\n\n respond_to do |format|\n format.html # sho... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
task_array: array of [name, url] pairs, or array of urls | def run(task_array)
pool = Thread.pool(@thread_count)
task_array.each do |task|
case task
when Array
pool.process {@archiever.read_and_save_url(task[1], task[0])}
when String
pool.process {@archiever.read_and_save_url(task)}
end
end
pool.shutdown()
... | [
"def tasks=( array )\n @tasks = array\n update_internal_task_lists()\n end",
"def get_taskarray\n @task_array\n end",
"def push_taskarray(task)\n @task_array << task\n end",
"def run_tasks(description, tasks)\n result = Array.new\n \n tasks.each do |task|\n puts \"submitting... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Gets trace id from input line | def get_trace_id(line)
return line.split("\t")[1].to_i
end | [
"def line_id\n @line_number - 1\n end",
"def extract_id(line)\n line.split('(')[1].split(',')[0].split(').')[0]\n end",
"def trace_id\n trace_context.trace_id\n end",
"def trace_id\n self.current_trace ? self.current_trace.id : nil\n end",
"def trace_number(trace_... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Reads the input from the first file, and then outputs the lines from the input which are sampled to the outputfile | def sample(inputfile, outputfile)
File.open(outputfile, 'w') do |out_file|
trace_list = []
File.open(inputfile, 'r').each do |line|
trace_list = trace_list << get_trace_id(line)
end
sampled = sampled_traces(trace_list)
File.open(inputfile, 'r').each do |line|
if (sampled.include?(get_t... | [
"def mutate_file\n File.open(INPUT_FILE,'r') do |input|\n File.open(OUTPUT_FILE,'w') do |output|\n while line = input.gets\n mutate_line line if rand(15) == 0\n output.puts(line)\n end\n end\n end\nend",
"def combine_seriell(filename1, filename2, outdir)\n f1 = ::File.new(filena... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /resumes/1 DELETE /resumes/1.json | def destroy
@resume.destroy
respond_to do |format|
format.html { redirect_to resumes_url }
format.json { head :no_content }
end
end | [
"def destroy\n @resume = @user.resumes.find(params[:id])\n @resume.destroy\n\n respond_to do |format|\n format.html { redirect_to resumes_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @resume = Resume.find(params[:id])\n @resume.destroy\n\n respond_to do |fo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /clients POST /clients.json | def create
@client = Client.new(client_params)
respond_to do |format|
if @client.save
format.html { redirect_to clients_url, notice: 'El cliente se creó correctamente' }
format.json { render :index, status: :created, location: @client }
else
format.html { render :new }
... | [
"def create\n @client = current_user.clients.build(client_params)\n\n respond_to do |format|\n if @client.save\n format.html { redirect_to @client, notice: 'Client was successfully created.' }\n format.json { render :show, status: :created, location: @client }\n else\n format.ht... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Retrieves metadata on article from DynamoDB. | def get_article_metadata(article_id)
if $ddb_client.nil?
$ddb_client = Aws::DynamoDB::Client.new
end
resp = $ddb_client.get_item({
key: { id: article_id },
projection_expression: "contentUri",
table_name: ARTICLES_TABLE
})
Article.new(resp.item['contentUri'])
end | [
"def get_article_metadata(article_id, size)\n if $ddb_client.nil?\n $ddb_client = Aws::DynamoDB::Client.new\n end\n\n size ||= 'md' # for cases in which size is not assigned\n\n resp = $ddb_client.get_item({\n key: { id: article_id },\n projection_expression: \"contentUri, sizedImage.#{size}\",\n t... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Retrieve object from S3, convert from Markdown to HTML, and return. | def respond_with_content(uri:)
if $renderer.nil?
$renderer = get_renderer
end
begin
resp = $s3_client.get_object({
bucket: CONTENT_BUCKET,
key: "public/#{uri}"
})
{
isBase64Encoded: false,
statusCode: 200,
headers: {
'Content-Type': 'text/html',
'Cac... | [
"def respond_with_content(uri:)\n begin\n resp = $s3_client.get_object({\n bucket: CONTENT_BUCKET,\n key: \"public/#{uri}\"\n })\n\n {\n isBase64Encoded: false,\n statusCode: 200,\n headers: {\n 'Content-Type': 'text/html'\n },\n body: Kramdown::Document.new(resp.... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /favor_users POST /favor_users.json | def create
@favor_user = FavorUser.new(favor_user_params)
respond_to do |format|
if @favor_user.save
format.html { redirect_to @favor_user, notice: 'Favor user was successfully created.' }
format.json { render :show, status: :created, location: @favor_user }
else
format.html... | [
"def create\n @favorite = Favorite.new({user_id: params[:user_id], announcement_id: params[:announcement_id]})\n @favorite.save\n render json:@favorite\n end",
"def create\n @favorit = Favorit.new(favorit_params)\n @favorit.user = current_user\n\n respond_to do |format|\n if @favorit... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /favor_users/1 PATCH/PUT /favor_users/1.json | def update
respond_to do |format|
if @favor_user.update(favor_user_params)
format.html { redirect_to @favor_user, notice: 'Favor user was successfully updated.' }
format.json { render :show, status: :ok, location: @favor_user }
else
format.html { render :edit }
format.jso... | [
"def update\n respond_with Favor.update(params[:id], params[:favor])\n end",
"def update\n @favorite = Favorite.find(params[:id])\n @favorite.user_id = params[:user_id]\n @favorite.announcement_id = params[:announcement_id]\n @favorite.save\n render json:@favorite\n end",
"def update... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /favor_users/1 DELETE /favor_users/1.json | def destroy
@favor_user.destroy
respond_to do |format|
format.html { redirect_to favor_users_url, notice: 'Favor user was successfully destroyed.' }
format.json { head :no_content }
end
end | [
"def destroy\n favor = Favor.where(:user_id => params[:user_id], :post_id => params[:post_id])\n favor.destroy\n render :json => {:ok => true}, :head => :no_content\n end",
"def destroy\n @favorite_user = FavoriteUser.find(params[:id])\n @favorite_user.destroy\n\n respond_to do |format|\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Force x position to be a float between 0 and 1 | def x=(x)
x = x.to_f
fail RangeError, 'X position not between 0 and 1' unless x.between?(0.0, 1.0)
@x = x
end | [
"def x=(x)\n @x = x.to_f\n end",
"def x=(x)\n @x = x.to_f\n end",
"def x\n position.x if position?\n end",
"def x_offset() @x_offset || 0.5; end",
"def x\n x_value = bounds.x\n x_value -= parent.absolute_x if parent.is_a?(Shape)\n x_value\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Force y position to be a float between 0 and 1 | def y=(y)
y = y.to_f
fail RangeError, 'Y position not between 0 and 1' unless y.between?(0.0, 1.0)
@y = y
end | [
"def y=(y)\n origin.y = coerce_float(y)\n end",
"def test_set_y_as_float\n obj = Geom::Vector3d.new\n obj.y = 1000.0\n result = obj.y\n expected = 1000.0\n assert_equal(expected, result, 'expected does not match result.')\n end",
"def y=(y)\n @y = y.to_f\n end",
"def y=(y)\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Map of lifecycle events | def events
@events ||= LIFECYCLE_EVENTS.each_with_object({}) { |e, a| a[e] = [] }
end | [
"def events\n @events ||= Array(context[:events]).reverse.map { |event| Concierge::SafeAccessHash.new(event) }\n end",
"def initialize\n @hooks_map = Concurrent::Map.new do |events_hash, hook_event|\n events_hash[hook_event] = Concurrent::Map.new do |state_hash, name|\n state_hash[nam... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set the logger and also set Nsq.logger | def logger=(new_logger)
@logger = Nsq.logger = new_logger
end | [
"def logger=(logger); end",
"def log=(logger); end",
"def log= logger\n @log = logger\n end",
"def configure_logging\n @logger = Logging.logger[self]\n end",
"def logger=(logger)\n @logger = logger || @logger\n end",
"def set_logger(logger)\n ActiveSupport::LogSubscriber.log... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns a new FastlyNsq::Manager or the memoized | def manager
@manager ||= FastlyNsq::Manager.new
end | [
"def base_cache_manager\n @cache_manager ||= PublicEarth::Db::MemcacheManager.new\n end",
"def get_pool_manager(owner); end",
"def manager_instance(which, *args)\n which.new(@http_client, self, *args) if which.respond_to?(:new)\n end",
"def cached_instance; end",
"def memoize_cla... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set a new manager and transfer listeners to the new manager. | def manager=(manager)
@manager&.transfer(manager)
@manager = manager
end | [
"def set_manager(manager) #:nodoc\n @manager = manager\n end",
"def manager=(value)\n @manager = value\n end",
"def manager=(manager)\n raise \"Slot #{@path} already has an active manager: #{@manager}\" if @manager\n @manager = manager\n notify(:notify_slot... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Maximum requeue timeout in milliseconds. This setting controls the maximum value that will be sent from FastlyNsq::Messagerequeue This value should be less than or equal to the nsqd command line option +maxreqtimeout+. The default setting is 1 hour. | def max_req_timeout
@max_req_timeout ||= ENV.fetch("MAX_REQ_TIMEOUT", 60 * 60 * 1_000).to_i
end | [
"def queue_timeout(queue_name)\n (config_value(queue_name, 'timeout') || Chore.config.default_queue_timeout).to_i\n end",
"def requeue(timeout = nil)\n return managed if managed\n timeout ||= requeue_period\n\n timeout = [timeout, FastlyNsq.max_req_timeout].min\n\n @managed = :requeued\n nsq_me... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Maximum number of threads for FastlyNsq::PriorityThreadPool Default setting is 5 and can be set via ENV['MAX_PROCESSING_POOL_THREADS'] | def max_processing_pool_threads
@max_processing_pool_threads ||= ENV.fetch("MAX_PROCESSING_POOL_THREADS", 5).to_i
end | [
"def threadpool_size; end",
"def worker_pool_size; end",
"def max_threads\n @max_threads\n end",
"def max_threads\n @max_threads\n end",
"def max_threads\n\t\t\t@max_threads ||= 30\n\t\tend",
"def default_pool_size\n defined?(Rails) ? 5 : 1\n end",
"def parallel_limit\n @paralle... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Return an array of NSQ lookupd http addresses sourced from ENV['NSQLOOKUPD_HTTP_ADDRESS'] | def lookupd_http_addresses
@lookups ||= ENV.fetch("NSQLOOKUPD_HTTP_ADDRESS", "").split(/, ?|\s+/).map(&:strip)
end | [
"def option_values_target_addrs\n\t\tres = [ ]\n\t\tres << Rex::Socket.source_address()\n\t\treturn res if not framework.db.active\n\n\t\t# List only those hosts with matching open ports?\n\t\tmport = self.active_module.datastore['RPORT']\n\t\tif (mport)\n\t\t\tmport = mport.to_i\n\t\t\thosts = {}\n\t\t\tframework.... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Return an array of NSQD TCP addresses for NSQ consumers. Defaults to the value of ENV['NSQD_CONSUMERS']. ENV['NSQD_CONSUMERS'] must be a comma or space seperated string of NSQD addresses | def consumer_nsqds
@consumer_nsqds ||= ENV.fetch("NSQD_CONSUMERS", "").split(/, ?|\s+/).map(&:strip)
end | [
"def producer_nsqds\n @producer_nsqds ||= ENV.fetch(\"NSQD_PRODUCERS\", \"\").split(/, ?|\\s+/).map(&:strip)\n end",
"def consumer_nsqds=(nsqd_addresses)\n @consumer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)\n end",
"def broker_list\n l = brokers.map do | host, port |\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set the consumer_nsqd addresses | def consumer_nsqds=(nsqd_addresses)
@consumer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)
end | [
"def producer_nsqds=(nsqd_addresses)\n @producer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)\n end",
"def consumer_nsqds\n @consumer_nsqds ||= ENV.fetch(\"NSQD_CONSUMERS\", \"\").split(/, ?|\\s+/).map(&:strip)\n end",
"def addresses=(addrs)\n @sender.addresses = addrs\n end... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Return an array of NSQD TCP addresses for NSQ producers. Defaults to the value of ENV['NSQD_PRODUCERS']. ENV['NSQD_PRODUCERS'] must be a comma or space seperated string of NSQD addresses | def producer_nsqds
@producer_nsqds ||= ENV.fetch("NSQD_PRODUCERS", "").split(/, ?|\s+/).map(&:strip)
end | [
"def consumer_nsqds\n @consumer_nsqds ||= ENV.fetch(\"NSQD_CONSUMERS\", \"\").split(/, ?|\\s+/).map(&:strip)\n end",
"def producer_nsqds=(nsqd_addresses)\n @producer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)\n end",
"def kafka_hosts\n host = \"#{options[:mq_host]}:#{opti... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set the producer_nsqd addresses | def producer_nsqds=(nsqd_addresses)
@producer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)
end | [
"def consumer_nsqds=(nsqd_addresses)\n @consumer_nsqds = nsqd_addresses.nil? ? nil : Array(nsqd_addresses)\n end",
"def producer_nsqds\n @producer_nsqds ||= ENV.fetch(\"NSQD_PRODUCERS\", \"\").split(/, ?|\\s+/).map(&:strip)\n end",
"def addresses=(addrs)\n @sender.addresses = addrs\n end... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /ayuda_localidads GET /ayuda_localidads.json | def index
@ayuda_localidads = AyudaLocalidad.all
end | [
"def index\n render json: @ads = Ad.all\n end",
"def ad_list(ads)\n request(:get, \"/api/ad-get/\", {:ads=>ads}).data\n end",
"def index\n @digiramp_ads = DigirampAd.all\n end",
"def index\n @ads = Ad.all\n respond_to do |format|\n format.html # index.html.erb\n format.json { r... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /ayuda_localidads POST /ayuda_localidads.json | def create
@ayuda_localidad = AyudaLocalidad.new(ayuda_localidad_params)
respond_to do |format|
if @ayuda_localidad.save
format.html { redirect_to @ayuda_localidad, notice: 'Ayuda localidad was successfully created.' }
format.json { render :show, status: :created, location: @ayuda_localid... | [
"def create_ad(params={})\n request(:post, '/api/ad-create/', params).data\n end",
"def create\n @ad = Ad.new(ad_params)\n\n if @ad.save\n render json: @ad, status: :created, location: @ad\n else\n render json: @ad.errors, status: :unprocessable_entity\n end\n end",
"def create\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Takes either a hash or a block and initializes config(). | def setup_config(config=nil, &block)
@config = config || ConfigStruct.block_to_hash(block)
end | [
"def configure(config = nil, &block)\n config ||= Util::BlockHashBuilder.build(&block)\n @config = config.dup.freeze\n end",
"def config(&block)\n if block_given?\n block.call(@config)\n else\n @config\n end\n end",
"def configure(&block)\n @configure_bloc... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Loads the local gem if found or defaults to a normal gem call. | def local_gem(*args)
load_local_gem(args[0]) || gem(*args)
end | [
"def gem(*args)\n LocalGem::Singleton.load_local_gem(args[0]) || old_gem(*args)\n end",
"def try_local(gem_name)\n if ENV['USE_LOCAL_GEMS']\n gem gem_name, path: \"../#{gem_name}\"\n else\n gem gem_name, github: \"omniscrapper/#{gem_name}\"\n end\nend",
"def local_require(lib)\n load_local_gem... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Loads the local gem if found and then does a normal require on it. | def local_require(lib)
load_local_gem(lib)
require(lib)
end | [
"def require(lib)\n LocalGem::Singleton.load_local_gem(lib)\n old_require(lib)\n end",
"def local_gem(*args)\n load_local_gem(args[0]) || gem(*args)\n end",
"def require(path) # :nodoc:\n gem_original_require path\n rescue LoadError => load_error\n if File.basename(path).match(... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /promos/1 GET /promos/1.xml | def show
@promos = Promos.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @promos }
end
end | [
"def show\n @promocao = Promocao.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.xml { render :xml => @promocao }\n end\n end",
"def index\n @offre_promos = OffrePromo.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.xm... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /promos/new GET /promos/new.xml | def new
@promos = Promos.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @promos }
end
end | [
"def new\n @promocao = Promocao.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @promocao }\n end\n end",
"def create\n @promos = Promos.new(params[:promos])\n\n respond_to do |format|\n if @promos.save\n flash[:notice] = 'Promos was... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /promos POST /promos.xml | def create
@promos = Promos.new(params[:promos])
respond_to do |format|
if @promos.save
flash[:notice] = 'Promos was successfully created.'
format.html { redirect_to(@promos) }
format.xml { render :xml => @promos, :status => :created, :location => @promos }
else
for... | [
"def create\n @promocao = Promocao.new(params[:promocao])\n\n respond_to do |format|\n if @promocao.save\n format.html { redirect_to(@promocao, :notice => 'Promocção criada com sucesso!') }\n format.xml { render :xml => @promocao, :status => :created, :location => @promocao }\n else\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PUT /promos/1 PUT /promos/1.xml | def update
@promos = Promos.find(params[:id])
respond_to do |format|
if @promos.update_attributes(params[:promos])
flash[:notice] = 'Promos was successfully updated.'
format.html { redirect_to(@promos) }
format.xml { head :ok }
else
format.html { render :action => "... | [
"def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post 'update', opts\n end",
"def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post opts.fetch(:path, update_path), opts\n end",
"def update\n @prom... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /promos/1 DELETE /promos/1.xml | def destroy
@promos = Promos.find(params[:id])
@promos.destroy
respond_to do |format|
format.html { redirect_to(promos_url) }
format.xml { head :ok }
end
end | [
"def destroy\n @promo = Promo.find(params[:id])\n @promo.destroy\n\n respond_to do |format|\n format.html { redirect_to(promos_url) }\n format.xml { head :ok }\n end\n end",
"def destroy\n @promotion1 = Promotion1.find(params[:id])\n @promotion1.destroy\n\n respond_to do |format|\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /knowledge_articles GET /knowledge_articles.json | def index
@knowledge_articles = KnowledgeArticle.all
end | [
"def show\n @articles = Article.find(params[:id])\n render json: @articles\n end",
"def index\n @articles = Article.all\n\n respond_to do |format|\n format.json { render json: @articles }\n end\n end",
"def articles\n self.class.get(\"/articles\").tap { |z| ForemLite::Article.new(z) }... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /knowledge_articles POST /knowledge_articles.json | def create
if params[:workflow_step_id].present?
@knowledge_article = KnowledgeArticle.new(knowledge_article_params)
@workflow_step = WorkflowStep.find(params[:workflow_step_id])
respond_to do |format|
if @knowledge_article.save
WorkflowStepKnowledgeArticle.create!(workflow_step_... | [
"def create\n @knowledge_topic = KnowledgeTopic.new(knowledge_topic_params)\n\n respond_to do |format|\n if @knowledge_topic.save\n format.html { redirect_to @knowledge_topic, notice: 'Knowledge topic was successfully created.' }\n format.json { render :show, status: :created, location: @kn... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /knowledge_articles/1 DELETE /knowledge_articles/1.json | def destroy
@knowledge_article.destroy
respond_to do |format|
format.html { redirect_to knowledge_articles_url, notice: 'Knowledge article was successfully destroyed.' }
format.json { head :no_content }
end
end | [
"def destroy\n @articles1.destroy\n respond_to do |format|\n format.html { redirect_to articles1s_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @articles123.destroy\n respond_to do |format|\n format.html { redirect_to articles123s_url }\n format.json { h... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
this method should be called any time the job processing goes wrong; it will log the error and email the user. Don't forget to return after calling this! | def jobfail(log,msg)
Rails.logger.error("#{log} #{self.id}")
self.update_attributes(:status =>'error',:errormsg => msg)
user = User.find_by_email(self.email)
UserMailer.job_failed(user,self).deliver
UserMailer.admin_job_failed(self).deliver
end | [
"def job_error_handler(err)\n\tUserMailer.job_notification_email(job_spec, @job_log_s3_full_path).deliver\n self.update(status: ERROR, status_message: error_message(err))\n @job_log.error error_message(err)\n raise err\n end",
"def on_failure(e)\n #e.instance_variable_set :@job_progress, @optio... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /expedients POST /expedients.json | def create
@expedient = Expedient.new(expedient_params)
respond_to do |format|
if @expedient.save
format.html { redirect_to expedients_url, notice: 'Se creó un nuevo expediente' }
format.json { render :show, status: :created, location: @expedient }
else
format.html { render ... | [
"def create\n @expedient = Expedient.new(params[:expedient])\n\n respond_to do |format|\n if @expedient.save\n format.html { redirect_to @expedient, :notice => 'Expedient was successfully created.' }\n format.json { render :json => @expedient, :status => :created, :location => @expedient }\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the access rank of the current user | def get_access_rank
guest_user_rank = 4
user = get_user()
if user != nil
current_user = User.find_by user_id: "#{user}"
user_rank = current_user.access_rank
#Handler if user access rank missing
if user_rank === nil
flash[:notice] = "Problem getting user access level.
... | [
"def getAccessRank\n guest_user_rank = 4\n user = getUser()\n if user != nil\n current_user = User.find_by userid: \"#{user}\"\n user_rank = current_user.access_rank\n\n #Handler if user access rank missing\n if user_rank === nil\n flash[:notice] = \"Problem getting user access l... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks current user rank against argument value. Returns boolean | def allow_access_if_user_rank_at_least(access_rank_value)
user_rank = get_access_rank()
if user_rank <= access_rank_value
true
else
false
end
end | [
"def rank?(rank=:any, options={}, &block)\n return false if current_user.nil?\n options = {\n :user_id => nil,\n :user => nil,\n :allow => nil,\n }.update options \n #allow rank to be a user object.\n if rank.is_a? User\n options[:user] = rank\n rank = :owner\n end\n o... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks if user has sufficient rank or if user is owner. Returns boolean | def allow_access_if_owner_name_is_or_rank_at_least(entity_owner, access_rank_value)
if ( belongs_to_current_user(entity_owner) ||
allow_access_if_user_rank_at_least(access_rank_value) )
true
else
false
end
end | [
"def has_owner? user\n self.account_users.where(user: user, is_owner: true).count > 0\n end",
"def allowAccessIfOwnerNameIsOrRankAtLeast(entity_owner, access_rank_value)\n if ( belongsToCurrentUser(entity_owner) || \n allowAccessIfUserRankAtLeast(access_rank_value) )\n true\n else\n f... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /meibos POST /meibos.json | def create
@meibo = Meibo.new(meibo_params)
respond_to do |format|
if @meibo.save
format.html { redirect_to @meibo, notice: '名簿は正常に作成されました。' }
format.json { render :show, status: :created, location: @meibo }
else
format.html { @meibos = Meibo.page(params[:page]).per(@@kensu)... | [
"def create\n @meupedido = Meupedido.new(meupedido_params)\n\n respond_to do |format|\n if @meupedido.save\n format.html { redirect_to @meupedido, notice: 'Meupedido was successfully created.' }\n format.json { render :show, status: :created, location: @meupedido }\n else\n form... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /meibos/1 PATCH/PUT /meibos/1.json | def update
respond_to do |format|
if @meibo.update(meibo_params)
format.html { redirect_to @meibo, notice: '名簿は正常に更新されました。' }
format.json { render :show, status: :ok, location: @meibo }
else
format.html { render :edit }
format.json { render json: @meibo.errors, status: :u... | [
"def update\n respond_to do |format|\n if @melo.update(melo_params)\n format.html { redirect_to @melo, notice: 'Melo was successfully updated.' }\n format.json { head :no_content }\n else\n format.html { render action: 'edit' }\n format.json { render json: @melo.errors, stat... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
recalculates same tip percent with new totals | def recalc
# Removes previous total and tax, then prompts user to enter new info
total
user_tax = get_input
tax
user_tax = get_input
$user_totals.pop
$user_totals = [user_input, user_tax]
# Gets previous selected tip from cache and calculates correct percentage
case $cached_tip
... | [
"def calculate_tip\n (bill_amount * @tip_percent / 100).round(2)\n end",
"def tip_amount\n (subtotal * ((tip || 0) / 100.0)).round\n end",
"def tip_calc\n if @tip >= 1 \n @tip / 100.0\n else\n @tip\n end\n end",
"def adjust_tips\n #get the tip pools \n tip_pools = self.tip_po... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
If the percentage is in the cache, set to last used. If not, stores it in the cache | def cached?(percentage)
if @tip_cache.has_key?(percentage)
else
@tip_cache.store("percentage", percentage)
end
set_last_used(percentage)
end | [
"def cache_accounts_above_disk_free_percentage=(value)\n @cache_accounts_above_disk_free_percentage = value\n end",
"def cache_value?; end",
"def assign_cached(value)\n uploaded_file = uploaded_file(value)\n set(uploaded_file) if cache.uploaded?(uploaded_file)\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns all the keys in the bucket. | def all_keys
@cluster.client.list_keys(@name)
end | [
"def list\n keys = []\n @s3.incrementally_list_bucket(@bucket_name) {|key_set|\n keys << key_set[:contents].map {|key|\n key\n }\n }\n keys.flatten\n end",
"def keys\n jiak.client.keys(jiak.bucket)\n end",
"def list_keys(bucket)\n message = Mess... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Searches for a key in this bucket and returns an RpbFetchResp compatible class or hash. | def find(key, options = {})
result = @cluster.client.fetch options.merge(bucket: @name, key: key)
if result.content.length == 0
nil
elsif result.content.length > 1
# Resolve siblings... some way
else
result
end
end | [
"def find(key)\n entity_class.new Hyperion.find_by_key(key)\n end",
"def fetch(key)\n return @keys[key] ? @keys[key] : \"value not found\"\n end",
"def bucket_object(bucket, key)\n S3Object.find key, bucket\n end",
"def find(*args)\n request = RubyKongAuth::Request::KeyAuth.... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
mixes in WillPaginate::Finder in ActiveRecord::Base and classes that deal with associations | def enable_activerecord
return if ActiveRecord::Base.respond_to? :paginate
require 'will_paginate/finder'
ActiveRecord::Base.class_eval { include Finder }
# support pagination on associations
a = ActiveRecord::Associations
returning([ a::AssociationCollection ]) { |classes|
... | [
"def defines_belongs_to_finder_method(reflection); end",
"def method_missing(method, *args)\n if method.to_s.index('find_by_') == 0\n model_class.send(method, *args).to_activerecord_proxies\n else\n super\n end\n end",
"def paginate\n target_class.paginate(pagina... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Enable named_scope, a feature of Rails 2.1, even if you have older Rails (tested on Rails 2.0.2 and 1.2.6). You can pass +false+ for +patch+ parameter to skip monkeypatching associations. Use this if you feel that named_scope broke has_many, has_many :through or has_and_belongs_to_many associations in your app. By pass... | def enable_named_scope(patch = true)
return if defined? ActiveRecord::NamedScope
require 'will_paginate/named_scope'
require 'will_paginate/named_scope_patch' if patch
ActiveRecord::Base.class_eval do
include WillPaginate::NamedScope
end
end | [
"def enable_named_scope(patch = true)\n return if defined? ActiveRecord::NamedScope\n require File.join(File.dirname(__FILE__), 'will_paginate', 'named_scope.rb')\n require File.join(File.dirname(__FILE__), 'will_paginate', 'named_scope_patch.rb') if patch\n\n ActiveRecord::Base.send :include, W... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Convert the block block_size : size of the block blocks : number of blocks returns a human readable size and the size unit (MB or GB) | def convert_size(block_size,blocks)
size = block_size * blocks
if size > SIZE_GB
return [(size / SIZE_GB).to_i,"GB"]
else
return [(size / SIZE_MB).to_i,"MB"]
end
end | [
"def blocks_to_bytes(block_size, qty)\n size = ( block_size / 1024 ) * qty\n if size < 1000\n output = \"#{size} KB\"\n elsif size < 1000000\n output = \"#{size / 1000} MB\"\n elsif size < 1000000000\n output = \"#{size / 1000000} GB\"\n else\n output = \"#{size / 1000000000} TB\"\n end\n\n retur... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /dutydeals GET /dutydeals.json | def index
@dutydeals = Dutydeal.all
end | [
"def index\n @deals = @business.deals \n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @deals }\n end\n end",
"def show\n @d_duty = DDuty.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render jso... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /dutydeals POST /dutydeals.json | def create
@dutydeal = Dutydeal.new(dutydeal_params)
respond_to do |format|
if @dutydeal.save
format.html { redirect_to @dutydeal, notice: 'Dutydeal was successfully created.' }
format.json { render :show, status: :created, location: @dutydeal }
else
format.html { render :ne... | [
"def create\n @d_duty = DDuty.new(params[:d_duty])\n\n respond_to do |format|\n if @d_duty.save\n format.html { redirect_to @d_duty, notice: 'D duty was successfully created.' }\n format.json { render json: @d_duty, status: :created, location: @d_duty }\n else\n format.html { re... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /dutydeals/1 DELETE /dutydeals/1.json | def destroy
@dutydeal.destroy
respond_to do |format|
format.html { redirect_to dutydeals_url, notice: 'Dutydeal was successfully destroyed.' }
format.json { head :no_content }
end
end | [
"def destroy\n @cleaning_duty = CleaningDuty.find(params[:id])\n @cleaning_duty.destroy\n\n respond_to do |format|\n format.html { redirect_to cleaning_duties_url }\n format.json { head :ok }\n end\n end",
"def destroy\n @dutyitem.destroy\n respond_to do |format|\n format.html { ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
sets venue.is_wishlist for list of venues | def set_is_wishlist(venues, user_id)
return venues if user_id.nil?
if venues.respond_to?(:each)
venue_ids = Wish.where(user_id: user_id).pluck(:venue_id)
venues.each do |v|
v.is_wishlist = venue_ids.include?(v.id)
end
else
venues.is_wishlist = is_wish?(venues... | [
"def add_to_wishlist(product)\n wishlist.products << product unless wishlist.products.include?(product)\n wishlist.save\n end",
"def add_item_to_wishlist(item)\n self.items << item if !self.items.include?(item)\n end",
"def check_wishlist(item)\n #Query wish lists to see if the criteria matches\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
to check if a user did wish or not | def is_wish?(venue_id, user_id)
Wish.exists?(venue_id:venue_id, user_id: user_id)
end | [
"def show_wishlist?\n if event.is_public?\n return true\n else\n user and (event.is_owner?(user) or event.user_invited?(user) or event.user_joined?(user))\n end \n end",
"def is_favorite_of user\n\t fave = get_favorite_for user\n\t fave ? true : false\n\tend",
"def needs_thanks?\n gr... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Get num of users who wish list a venue | def num_wishlist_venue (venue_id)
num = Wish.where(:venue_id => venue_id)
num.count
end | [
"def likes\n likers(User).count\n end",
"def wishlisted_count\n self.wishlisted.count\n end",
"def get_win_count(username)\n get_count(username, 'Wins')\n end",
"def interested_users_count\n self.users.size\n end",
"def user_count\n @filtered_users.count\n end",
"def user_cou... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Sort tasks by their labels, rather than by type. Constructs a string of all task types sorted by their labels for postgres to use as a reference for sorting as a task's label is not stored in the database. | def task_type_order_clause
task_types_sorted_by_label = Task.descendants.sort_by(&:label).map(&:name)
task_types_sql_array = "array#{task_types_sorted_by_label}::varchar[]".tr('"', "'")
task_type_sort_position = "#{task_types_sql_array}, tasks.type"
"array_position(#{task_type_sort_position}) #{sort_ord... | [
"def by_label\n labelled = Hash.new\n @tasks.each { |t|\n t.label.each { |t_label|\n unless labelled.include? t_label\n labelled[t_label] = []\n end\n unless t_label.nil?\n labelled[t_label] << t\n end\n }\n }\n labelled\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
find plugins in defined paths | def add_plugins_from_lookup_folders
@plugin_lookup_folders.each do |folder|
if File.directory?(folder)
#TODO: add gem root to load path ? and require short folder ?
#$LOAD_PATH.push(folder) if i[:add_path]
Dir.entries(folder).select{|file|file.end_with?(RU... | [
"def locate_plugins_under(base_path)\r\n Dir.glob(File.join(base_path, '*')).sort.inject([]) do |plugins, path|\r\n if plugin = create_plugin(path)\r\n plugins << plugin\r\n elsif File.directory?(path)\r\n plugins.concat locate_plugins_under(path)\r\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Sharing fees between actors (insurance, assistance, drivy) | def fees
@fees ||= {
"insurance_fee" => (commission * ASSURANCE_SHARE).round(0),
"assistance_fee" => (ASSISTANCE_COST * rental.duration).round(0)
}.tap { |fees| fees["drivy_fee"] = commission - fees.values.inject(:+) }
end | [
"def fees\n total_input - total_output\n end",
"def assistance_fee\n ROADSIDE_ASSISSTANCE_FEE_PER_DAY * duration\n end",
"def apply_fees\n remove_fees\n unless waive_fees\n #CHALKLE\n self.chalkle_gst_number = Finance::CHALKLE_GST_NUMBER\n self.chalkle_fee = course.chalkle_fee... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Add a run, or runs, to the cache. | def add_run(runs, credentials = nil)
cache = user_cache(credentials)
[*runs].each do |run|
cache[run.id] = run
end
end | [
"def add_to_cache(entry)\n raise ArgumentError, \"entry can't be nil\" unless entry\n @cache[entry.hash_id] = entry\n end",
"def add(el)\n element_in_cache?(el) ? update_last_usage!(el) : add_element_to_cache(el)\n end",
"def cache\n @runner.cache[:runs] ||= {} \n @runner.cache[:runs][@id] ||... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This method adds all new runs (creating instances where required) in the list provided AND removes any runs no longer in the list. | def refresh_all!(run_list, credentials = nil)
cache = user_cache(credentials)
# Add new runs to the user cache.
run_list.each_key do |id|
if !cache.has_key? id
cache[id] = Run.create(@server, "", credentials, run_list[id])
end
end
# Clear out the... | [
"def delete_all_runs\n # first refresh run list\n runs.each {|run| run.delete}\n end",
"def generate_run_lists\n @tasks.each do |name, obj|\n @completed_tasks = []\n obj.make_list(name)\n @run_list[name] = @completed_tasks\n end\n end",
"def set_run_list(node, entr... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Build a payment to be added to an order prior to moving into the "payment" state. | def build
credit_card = order.user.try!(:default_credit_card)
if credit_card.try!(:valid?) && order.payments.from_credit_card.count == 0
Spree::Payment.new(
payment_method_id: credit_card.payment_method_id,
source: credit_card,
)
end
end | [
"def build\n @payment ||= order.payments.new\n @payment.request_env = @request_env if @request_env\n @payment.attributes = @attributes\n\n if source_attributes[:existing_card_id].present?\n Spree::Deprecation.warn(\n \"Passing existing_card_id to PaymentCreate is deprecated. Use ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Turn a flag on or off | def switch_flag
@flag = !@flag
end | [
"def change_flag\n @flagged = !@flagged unless revealed?\n end",
"def toggle!\n if on?\n off!\n elsif off?\n on!\n end\n end",
"def turn_on!\n @turned_off = false\n end",
"def toggle\n if on?\n off\n else\n on\n end\n end",
... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Show a square as displayed | def display_square
@displayed = true
end | [
"def print_square\n\t\tprint \"#{@displayed_contents}\"\n\tend",
"def draw_square(size, row, col)\n raise \"Cannot draw outside graph bounds.\" if row < 0 or col < 0 or row >= @height or col >= @width or row + size > @height or col + size > @width\n\n size.times do |i| \n hor = \"-\"\n vert = \"|\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Get adjacent squares NOTE: For this method we don't need to put this on the square class should probably be part of the board. | def get_adjacent_squares(coords)
x, y, adj_squares = coords[0], coords[1], []
# Loop through the columns
(x-1).upto(x+1) do |column|
# Loop through the rows
(y-1).upto(y+1) do |row|
(adj_squares << [column, row]) if (row >= 1 && row <= @size) && (column >= 1 && column <= @size) && !(column == x && row =... | [
"def adjacent_neighbors cell\n neighbors = []\n\n neighbors << [cell.x, cell.y + 1] unless cell.y == grid.height - 1\n neighbors << [cell.x + 1, cell.y] unless cell.x == grid.width - 1\n neighbors << [cell.x, cell.y - 1] unless cell.y == 0\n neighbors << [cell.x - 1, cell.y] unless cell.x == 0\n\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Client initialization Usage: client = Hall::Client.new('room_token', 'from_name', 'url to the picture') Params: +room_token+:: token for your room grab it through the Add integration > Other or +from_name+:: defines the name used for message posting +from_picture+:: add picture to the post | def initialize(room_token, from_name, from_picture = nil)
@room_token = room_token
@from_name = from_name
@from_picture = from_picture
end | [
"def initialize_client\n @client = RobinhoodClient.interactively_create_client\n end",
"def initialize(client_id: nil, access_token: nil)\n if client_id.nil? && access_token.nil?\n raise \"An identifier token (client ID or bearer token) is required\"\n elsif !!client_id && !!access_token\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Post a message. Usage: client = post_message 'plain text' Params: +text+:: plain text to be send to the chat | def post_message(text)
body ={
"title" => @from_name,
"picture" => @from_picture,
"message" => text
}
self.class.post(room_path, request_options(body))
end | [
"def post_text(text)\n post_message({ :text => text }) if text\n end",
"def post_message(message)\n # https://api.slack.com/methods/chat.postMessage\n # scopes: chat:write\n slack_client.chat_postMessage(\n channel: channel_id,\n thread_ts: slack_ts,\n text: message\n )\n end",
"... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /iots POST /iots.json | def create
@iot = Iot.new(iot_params)
respond_to do |format|
if @iot.save
format.html { redirect_to @iot, notice: 'Iot was successfully created.' }
format.json { render :show, status: :created, location: @iot }
else
format.html { render :new }
format.json { render js... | [
"def post_spoonacular\n # %encode ingredients to url\n encoded_ingr = URI.escape(@translated_recipe[:ingredients_list])\n # post call block :\n url = URI(\"https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/parseIngredients?includeNutrition=true\")\n http = Net::HTTP.new(url.host, ur... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
def initialize(bits: 128, length: nil, alphabet: DEFAULT_ALPHABET) | def initialize(options = {})
bits = options[:bits] || 128
length = options[:length]
alphabet = options[:alphabet] || DEFAULT_ALPHABET
alphabet.size > 1 or raise ArgumentError, 'need at least 2 symbols in alphabet'
if length
length > 0 or raise ArgumentError, 'length has to be... | [
"def initialize(alphabet=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n @alphabet = alphabet\n @key = 0\n end",
"def initialize(alphabet=\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n @alphabet = alphabet\n @key = \"\"\n end",
"def initialize(size)\n @bits = 0\n @size = size\n end",
"def initialize( len = 8, optio... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Go to the page url given by the yaml_data key | def go_to(yaml_data_key)
$driver.navigate.to get_yaml_data( yaml_data_key, 0 )
quiesce
$driver.current_url.should =~ Regexp.new(get_yaml_data(yaml_data_key, 1), Regexp::MULTILINE)
end | [
"def page_url(url)\n define_method(\"goto\") do\n lookup = url.kind_of?(Symbol) ? self.send(url) : url\n erb = ERB.new(%Q{#{lookup}})\n merged_params = self.class.instance_variable_get(\"@merged_params\")\n params = merged_params ? merged_params : self.class.params\n platform... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Click on the given element It's called "no_move" because there's no expectation of a page transition for these clicks, i.e. fast javascript response is expected. | def no_move_click(yaml_data_key)
no_move_click_raw(
get_yaml_data( yaml_data_key, 0 ).to_sym,
get_yaml_data( yaml_data_key, 1 ),
get_yaml_data( yaml_data_key, 2 )
)
end | [
"def multi_no_move_click( elements, before = false, after = false )\n elements.each do |how, what, tag_name|\n $debug and print \"In multi_no_move_click: #{how}, #{what}, #{tag_name}\\n\"\n if before\n $debug and print \"In multi_no_move_click, calling before\\n\"\n before.call\n end... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Takes a list of how, what, and tag_name, which work as usual. For each such element, runs the "before" function, if any, then click on the element, then run the "after" function, if any. It's called "no_move" because there's no expectation of a page transition for these clicks, i.e. fast javascript response is expected... | def multi_no_move_click( elements, before = false, after = false )
elements.each do |how, what, tag_name|
$debug and print "In multi_no_move_click: #{how}, #{what}, #{tag_name}\n"
if before
$debug and print "In multi_no_move_click, calling before\n"
before.call
end
no_move_cl... | [
"def drag_and_drop_element_to(*args)\r\n begin\r\n how = args[0]\r\n what =args[1]\r\n mid_how= args[2]\r\n mid_what=args[3]\r\n to_how = args[4]\r\n to_what= args[5]\r\n msg=\"\"\r\n if args.size ==7\r\n msg= args[6] + \" ---->\"\r\n end\r\n if @@debug==... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Clicks on an element and expects that to cause a new window to popup, which it then switches to. | def click_and_change_window(how, what, tag_name, resulting_url)
e = $driver.find_element(how, what)
3.times do
e.tag_name.should == tag_name
e.click.should be_nil
quiesce
if $driver.window_handles.length > 1
break
end
end
# The actual window switching
$drive... | [
"def open_window_with_click(win_name)\n wait_start\n click\n wait_for_window_shown(win_name)\n end",
"def click!\n fire_event :click\n browser.after_hooks.run\n end",
"def click\n @mech.click self\n end",
"def open_window_with_double_click(win_name)\n wait_start\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Switches to an open alert, checks that it has the given text, and clicks "yes" or similar. | def eat_alert(text)
if $browser.to_sym == :chrome
print "ALERT HANDLING IS BROKEN ON CHROME, so I'm pausing for you to click the alert. Hit enter when ready to continue: "
File.open("/dev/tty", "r").gets
quiesce
else
begin
a = $driver.switch_to.alert
a.text.should == te... | [
"def check_alert_text text\n\tif get_alert_text!=text\n \t\traise TestCaseFailed , \"Text on alert pop up not matched\"\n \tend\nend",
"def process_confirm_alert_cmd(text)\n text = text.eql?(true) ? nil : text\n driver = @driver_helpers.driver\n alert = driver.switch_to.alert rescue nil\n if !alert\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Basic debugging tool; prints information about the element. | def print_element_info(element)
print "\n\n"
print "== Element Info ==\n"
print "tag name: #{element.tag_name}\n"
print "value: #{element['value']}\n"
print "text: #{element.text}\n"
print "location: #{element.location}\n"
print "\n\n"
end | [
"def print_widget_info\n puts \" Name: \" + name\n puts \" Text: \" + text\n puts \" Type: \" + type.to_s\n puts \" Parent: \" + element.getParentName()\n puts \"Visible: \" + visible?.to_s\n puts \"Enabled: \" + enabled?.to_s\n puts \" Pos: x=\" + element.getRect().x.to_... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks that the current page title equals the given text | def check_page_title(text)
$driver.title.should == text
end | [
"def page_title_is_correct\n ( text =~ self.class.page_title_validation_value ) !=nil\n end",
"def assert_page_title(text)\n assert_selector 'h2#page_title', text: text\n end",
"def verify_page?(key, exit = true)\n base_title = wait_for_title(exit)\n puts \"Verify Title - Desired Prefix: #{sit... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks that the current page url matches the given text when treated as a regex | def check_url_match(string)
$driver.current_url.should =~ Regexp.new(string, Regexp::MULTILINE)
end | [
"def url_should_contain(text)\n raise(Exception::UrlMatchError, \"The URL #{@browser.url} is not correct; it should contain #{text}\") unless\n @browser.url.include?(text)\n end",
"def blury_verify_text(text)\n page = get_body_text\n check_page(page)\n p(\"-- searching for text using... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks that the current page source matches the given text when treated as a regex. This is used for things like watching for javascript "Loading..." messages to see when things are done | def check_page_source_match(string)
$driver.page_source.should =~ Regexp.new(string, Regexp::MULTILINE)
end | [
"def blury_verify_text(text)\n page = get_body_text\n check_page(page)\n p(\"-- searching for text using pattern matching, text: {#{text}}\")\n if !/#{text}/.match(page)\n raise \"-- [ERROR]: not able to find text: {#{text}} anywhere in the page\"\n end\n p(\"-- OK: text {#{tex... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks that the value of an attribute on an element is equal to the given text | def check_attribute(how, what, attribute, string)
e = $driver.find_element(how, what)
e.attribute(attribute).should == string
end | [
"def check_attribute_match(how, what, attribute, string)\n e = $driver.find_element(how, what)\n if e.attribute(attribute) !~ Regexp.new(string, Regexp::MULTILINE) and $debug\n wait_for_user()\n end\n e.attribute(attribute).should =~ Regexp.new(string, Regexp::MULTILINE)\n end",
"def check_eleme... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Checks that the value of an attribute on an element matches the given text treated as a regex | def check_attribute_match(how, what, attribute, string)
e = $driver.find_element(how, what)
if e.attribute(attribute) !~ Regexp.new(string, Regexp::MULTILINE) and $debug
wait_for_user()
end
e.attribute(attribute).should =~ Regexp.new(string, Regexp::MULTILINE)
end | [
"def attribute_match(equality, value)\n regexp = value.is_a?(Regexp) ? value : Regexp.escape(value.to_s)\n case equality\n when \"=\" then\n # Match the attribute value in full\n Regexp.new(\"^#{regexp}$\")\n when \"~=\" then\n # Match a space-separated word within... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Waits until an element appears for the given amount of ten second waits | def long_wait_for_element(yaml_data_key, times = 6)
how = get_yaml_data( yaml_data_key, 0 )
what = get_yaml_data( yaml_data_key, 1 )
e = nil
times.times do
# note that find-element auto-waits
begin
e = $driver.find_element(how, what)
rescue Exception => error
$debug and... | [
"def wait_until_displayed(element, timeout=10)\n wait_until(timeout) { element.displayed? }\nend",
"def Wait_For_Element(locator_type, locator_value)\n for iSecond in 0..$config['Longwait']\n sleep 1\n if(@driver.find_element(\"#{locator_type}\", \"#{locator_value}\").displayed?)\n\tbreak\n else \t... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Dumps the entire source of the current page, as seen by Selenium so this includes the effects of javascript and so on, to the given file. | def dump_page_source(file)
File.open(file, 'w') {|f| f.write($driver.page_source) }
end | [
"def save_current_page(options = {})\r\n default_options = {:replacement => true}\r\n options = default_options.merge(options)\r\n to_dir = options[:dir] || default_dump_dir\r\n\r\n if options[:filename]\r\n file_name = options[:filename]\r\n else\r\n file_name = Time.now.strf... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Given an array of strings, check that all those bits of text are present in the page source. | def multi_source_text_check(texts)
texts.each do |text|
page_text = $driver.page_source
page_text.gsub!(/<[^>]*>/, '')
page_text.gsub!(/\s+/, ' ')
page_text.should include( text )
print "."
end
end | [
"def assert_text_in_page_source(text)\r\n perform_assertion { assert((@web_browser.page_source.include? text), 'expected html: ' + text + ' not found') }\r\n end",
"def assert_text_not_in_page_source(text)\r\n perform_assertion { assert(!(@web_browser.page_source.include? text), 'expected html: ' + t... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Runs manipulate_option over a list of lists of 5 elements, corresponding to the arguments to manipulate_option ; see manipulate_option (obviously) for details. | def multi_manipulate_option(options)
if options == nil
return
end
options.each do |manip_type, *args|
if manip_type != nil
manipulate_option_raw(manip_type.to_sym, *args )
print "."
end
end
end | [
"def execute_multiple_switches(option, argument, index); end",
"def process\n begin\n aux_option = remove_unwanted_chars(@_option)\n\n # unprocessed option list\n option_list = aux_option.split(%r{\\*/|\\];})\n\n option_list.each do |op|\n begin\n if op.to_s.index('=[') != n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This script is given a set of elements that can all be javascriptily dragged to each other's location, and makes them appear in the order listed. First argument is the axis (:x or :y) to do the ordering. OK, we get called like this: drag_to_order( :x, [ [ :name, "Channels[]" ], [ :name, "Conditions[]" ], [ :name, "Popu... | def drag_to_order( dimension, items )
positions = Array.new
items.each_index do |n|
item=$driver.find_element( items[n][0].to_sym, items[n][1] )
positions[n] = item.location.send( dimension )
end
positions.sort!
$debug and print "In drag_to_order: items: #{YAML.dump(items)}\n"
$debug... | [
"def order_elements!()\n #This is a stub, used for indexing\n end",
"def reorder\n respond_to do |format|\n format.js do\n render 'reorder_fail' and return if params[:drag_id].blank? || params[:drop_id].blank?\n @drag_req = Requirement.find(params[:drag_id].first)\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Set all of the options to unselected in a multiple select tag | def clear_multi_option_select(how, what)
select_element=$driver.find_element(how, what)
select_element.find_elements(:tag_name, "option").each do |option|
if option.selected?
option.toggle
end
end
end | [
"def unselect_all\n self.itineraries.selected.each do |i|\n i.update_attribute :selected, false\n end\n end",
"def unselect_option\n unless select_node.multiple_select?\n raise Capybara::UnselectNotAllowed, \"Cannot unselect option from single select box.\"\n end\n\n native.unsel... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Takes an array of how, what and a string, and makes sure that each element's text is string equal to the given string | def multi_element_text_check( elements )
wanted = Array.new
found = Array.new
elements.each do |element|
print "."
e = $driver.find_element(element[0].to_sym, element[1])
wanted << [ element[1], element[2] ]
found << [ element[1], e.text ]
end
found.should == wanted
end | [
"def arr_in_phrase? (arr, string)\n\t#might be unefficient to recreate the reg each time, maybe better to return a regex?\n\treg = arr.map {|str| Regexp.escape(str)}\n\treg = /#{arr.join(\"|\")}/ \n\treturn reg === string\nend",
"def mutation(array)\n p first_word = array[0].downcase.chars.sort.join(\" \")\n p ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Takes an array of how, what, attribute name, and attribute value, and checks that each element's value for the given attribute name is string equal to the given value | def multi_element_attr_check( elements )
wanted = Array.new
found = Array.new
elements.each do |element|
print "."
e = $driver.find_element(element[0].to_sym, element[1])
wanted << [ element[1], element[2], element[3] ]
found << [ element[1], element[2], e.attribute(element[2]) ]
... | [
"def attr_set?(cards, attr)\n array = []\n cards.each do |card|\n # evalutes the string 'attr' and returns the value\n array << card.send(attr)\n end\n\n # only return true if it's all the same or totally different\n return true if array.uniq.count == 1\n return true if array.uniq.count ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Same as multi_element_attr_check but with regexes | def multi_element_attr_match( elements )
elements.each do |element|
print "."
wait_for_element(element[0].to_sym, element[1])
check_attribute_match(element[0].to_sym, element[1], element[2], element[3])
end
end | [
"def multi_element_attr_check( elements )\n wanted = Array.new\n found = Array.new\n elements.each do |element|\n print \".\"\n e = $driver.find_element(element[0].to_sym, element[1])\n wanted << [ element[1], element[2], element[3] ]\n found << [ element[1], element[2], e.attribute(el... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Enters text into a javascriptbased editing element, rather than a normal text field. This is for dealing with situations where javascript makes significant manipulations to the elements after typing, so that references to the elements are lost and so on, so this code goes back and refinds the elements after typing to t... | def js_element_text_edit( startelem,
elemtype, elemloc,
pchildtype, pchildloc,
text )
parent = startelem.find_element(:xpath, '..')
startelem.click.should == nil
input = parent.find_element(elemtype, elemloc)
input.clea... | [
"def enter_text(*args)\r\n begin\r\n how = args[0]\r\n what =args[1]\r\n message =args[2]\r\n msg=\"\"\r\n sendTextDirect = false\r\n\r\n if (how.is_a? String)\r\n nLookup = get_element_from_navigation2(how,what)\r\n how = nLookup[0]\r\n what = nLookup[1]\r\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.