query
stringlengths
7
9.5k
document
stringlengths
10
1.07M
negatives
listlengths
19
19
metadata
dict
test the detached_copy method.
def test_detached_copy setup_test_tree assert(@root.has_children?, "The root should have children") copy_of_root = @root.detached_copy assert(!copy_of_root.has_children?, "The copy should not have children") assert_equal(@root.name, copy_of_root.name, "The names should be equal") #...
[ "def test_detached_subtree_copy\n setup_test_tree\n\n assert(@root.has_children?, \"The root should have children.\")\n tree_copy = @root.detached_subtree_copy\n\n assert_equal(@root.name, tree_copy.name, \"The names should be equal.\")\n assert_not_equal(@root.object_id, tree_copy.object_i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the detached_subtree_copy method.
def test_detached_subtree_copy setup_test_tree assert(@root.has_children?, "The root should have children.") tree_copy = @root.detached_subtree_copy assert_equal(@root.name, tree_copy.name, "The names should be equal.") assert_not_equal(@root.object_id, tree_copy.object_id, "Object_ids s...
[ "def test_detached_copy\n setup_test_tree\n\n assert(@root.has_children?, \"The root should have children\")\n copy_of_root = @root.detached_copy\n assert(!copy_of_root.has_children?, \"The copy should not have children\")\n assert_equal(@root.name, copy_of_root.name, \"The names should be ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the is_root? method.
def test_is_root_eh setup_test_tree assert(@root.is_root?, "The ROOT node must respond as the root node") end
[ "def root?\n root == self\n end", "def root?\n @type == ROOT\n end", "def root?\n ROOT == self\n end", "def is_root?(node)\n\t\treturn @root.object_id == node.object_id\n\tend", "def isRoot?\n @parent == nil\n end", "def root_node?\r\n name == ROOT_NAME\r\n end", "def is_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the in_degree method.
def test_in_degree setup_test_tree assert_equal(0, @root.in_degree, "Root's in-degree should be zero") assert_equal(1, @child1.in_degree, "Child 1's in-degree should be 1") assert_equal(1, @child2.in_degree, "Child 2's in-degree should be 1") assert_equal(1, @child3.in_degree, "Child 3's ...
[ "def in_degree(vertex)\n end", "def in_degree(vertex)\n\tend", "def indegree node\n return unless @nodes[node]\n @nodes[node][:indegree]\n end", "def test_out_degree\n setup_test_tree\n\n assert_equal(3, @root.out_degree, \"Root's out-degree should be 3\")\n assert_equal(0, @child1.out_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the out_degree method.
def test_out_degree setup_test_tree assert_equal(3, @root.out_degree, "Root's out-degree should be 3") assert_equal(0, @child1.out_degree, "Child 1's out-degree should be 0") assert_equal(0, @child2.out_degree, "Child 2's out-degree should be 0") assert_equal(1, @child3.out_degree, "Child...
[ "def outdegree node\n return unless @nodes[node]\n @nodes[node][:outdegree]\n end", "def outdegree(node)\n\t\toutdegree = 0\n\t\tif is_node_valid(node)\n\t\t\tni = indexing.index_of(node)\n\t\t\t(0..size - 1).each {|i|\n\t\t\t\tif arc_exists_private(ni, i)\n\t\t\t\t\toutdegree += 1\n\t\t\t\tend\n\t\t\t}\n\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test usage of integers as node names
def test_integer_node_names require 'structured_warnings' assert_warn(StandardWarning) do @n_root = Tree::TreeNode.new(0, "Root Node") @n_child1 = Tree::TreeNode.new(1, "Child Node 1") @n_child2 = Tree::TreeNode.new(2, "Child Node 2") @n_child3 = Tree::TreeNode.new("three", ...
[ "def visit_int(node); end", "def test_node_autonumber\r\n nodelist = @mymodel.node_list\r\n \r\n proc3 = nodelist.add_node('autonum', 'process 3', PROCESS);\r\n assert(proc3.ident == 3)\r\n \r\n node4 = nodelist.add_node('autonum', 'node 4');\r\n assert(node4.ident == 4)\r\n\r\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the addition of a node to itself as a child
def test_add_node_to_self_as_child root = Tree::TreeNode.new("root") # Lets check the direct parentage scenario assert_raise(ArgumentError) {root << root} # And now a scenario where the node addition is done down the hierarchy # @todo This scenario is not yet fixed. child = Tree:...
[ "def valid_child(le)\n\t\t\treturn false\n\t\tend", "def test_left_child\n @root << @left_child1\n @root << @right_child1\n assert_same(@left_child1, @root.left_child, \"The left child should be 'left_child1\")\n assert_not_same(@right_child1, @root.left_child, \"The right_child1 is not the le...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
STEPS: 1. login on turtle using facebook account 2. search for listing 3. upload image to listing 4. check image 5. hide image
def test_fb_sign_up_and_upload_monkey_image # Step 1 @user.email = @fb_user['email'] login_fb_user!(@fb_user, @user) # Step 2 assign_http(Config["panda"]["host"]) opts = { 'vrid' => @user.vrid } get_consumer_search_resp('ramen', 'glendale, ca', opts) assert_response(@response, :succes...
[ "def atest_ID_25836_edit_profile_pic_03\n login_as_user1\n go_to_edit_profile_page\n verify_user_able_to_close_photo_upload_dialog\n end", "def uploading_pictures\n end", "def avatar_iterator\n# select the fb_people table and get the all table\nresult = @@client.query(\"SELECT * FROM crawler.avatar\"...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the list of partition types supported by the Device
def partition_types_ext ptr1 = MemoryPointer::new( :size_t, 1) error = OpenCL.clGetDeviceInfo(self, PARTITION_TYPES_EXT, 0, nil, ptr1) error_check(error) ptr2 = MemoryPointer::new( ptr1.read_size_t ) error = OpenCL.clGetDeviceInfo(self, PARTITION_TYPES_EXT, ptr1.read_size_t, ptr2...
[ "def supported_types\n StorageController::SATA_CONTROLLER_TYPES + StorageController::IDE_CONTROLLER_TYPES +\n StorageController::SCSI_CONTROLLER_TYPES\n end", "def partition_properties_names\n prop_names = []\n props = self.partition_properties\n %w( PARTITION_EQUALLY PAR...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the parent Device if it exists
def parent_device_ext ptr = MemoryPointer::new( Device ) error = OpenCL.clGetDeviceInfo(self, PARENT_DEVICE_EXT, Device.size, ptr, nil) error_check(error) return nil if ptr.null? return Device::new(ptr.read_pointer) end
[ "def parent_device\n @parent_device\n end", "def parent_device\n ptr = MemoryPointer::new( Device )\n error = OpenCL.clGetDeviceInfo(self, PARENT_DEVICE, Device.size, ptr, nil)\n error_check(error)\n return nil if ptr.null?\n return Device::new(ptr.read_pointer)\n e...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Emit the CSS classes for inclusion in the '' element definition.
def emit_page_classes @page_classes ||= default_page_classes @page_classes.flatten! @page_classes.compact_blank! @page_classes.map! { |c| c.to_s.gsub(/[^a-z_0-9-]/i, '_') } @page_classes.uniq! @page_classes.join(' ') end
[ "def write_class_names\n @element['class'] = @class_names.join(' ')\n end", "def classes\n @class_list ||= Element::Classes.new(self)\n end", "def css_class *a; CssString.new a.flatten.unshift(self).join '.' end", "def add_class class_name\n each do |el|\n next unless el.respond_to? ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /euclid_users/1 GET /euclid_users/1.json
def show @euclid_user = EuclidUser.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @euclid_user } end end
[ "def index\n if params[:single]\n\t url = \"#{API_BASE_URL}/users/#{params[:id]}.json\"\n\t response = RestClient.get(url)\n\t @user = JSON.parse(response.body)\n\telse\n\t url = \"#{API_BASE_URL}/users.json\"\t \n response = RestClient.get(url)\n @users = JSON.parse(response.body)\t\t \n\tend\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /euclid_users/new GET /euclid_users/new.json
def new @euclid_user = EuclidUser.new respond_to do |format| format.html # new.html.erb format.json { render json: @euclid_user } end end
[ "def new\n @new_user = NewUser.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @new_user }\n end\n end", "def new\n @newuser = Newuser.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @newuser }\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /euclid_users POST /euclid_users.json
def create @euclid_user = EuclidUser.new(params[:euclid_user]) @euclid_user.proximity = "distant"; respond_to do |format| if @euclid_user.save format.html { redirect_to @euclid_user, notice: 'Euclid user was successfully created.' } format.json { render json: @euclid_user, status: :cr...
[ "def create_user(params)\n url = \"https://users.authentise.com/users/\"\n options = {\n content_type: :json,\n accept: :json,\n open_timeout: 2,\n timeout: 2,\n }\n body = params.to_json\n\n RestClient.post(url, body, options) do |response, _re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PUT /euclid_users/1 PUT /euclid_users/1.json
def update @euclid_user = EuclidUser.find(params[:id]) respond_to do |format| if @euclid_user.update_attributes(params[:euclid_user]) format.html { redirect_to @euclid_user, notice: 'Euclid user was successfully updated.' } format.json { head :no_content } else format.html {...
[ "def update\n @user = User.find(params[:id])\n @user.name = params[:name]\n @user.email = params[:email]\n @user.password = params[:password]\n @user.photo = params[:photo]\n @user.role = params[:type]\n @user.save\n render json:@user\n end", "def update_user id, payload\n\t\t\t\t\t(@conn...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /euclid_users/1 DELETE /euclid_users/1.json
def destroy @euclid_user = EuclidUser.find(params[:id]) @euclid_user.destroy respond_to do |format| format.html { redirect_to euclid_users_url } format.json { head :no_content } end end
[ "def delete_user_for_tenant(args = {}) \n delete(\"/tenants.json/#{args[:tenantId]}/users/#{args[:userId]}\", args)\nend", "def delete(user)\n Rails.logger.debug \"Call to election.delete\"\n reqUrl = \"/api/election/#{self.id}\" #Set the request url\n rest_response = MwHttpRequest.http_delete_request(re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /quandaries GET /quandaries.json
def index @quandaries = Quandary.all end
[ "def index\n @quarries = Quarry.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @quarries }\n end\n end", "def show\n @quarry = Quarry.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render js...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /quandaries POST /quandaries.json
def create @quandary= current_user.quandaries.build(quandary_params) respond_to do |format| if @quandary.save format.html { redirect_to @quandary, notice: 'Quandary was successfully created.' } format.json { render :show, status: :created, location: @quandary } else format.h...
[ "def create\n @quarry = Quarry.new(params[:quarry])\n\n respond_to do |format|\n if @quarry.save\n format.html { redirect_to @quarry, notice: 'Quarry was successfully created.' }\n format.json { render json: @quarry, status: :created, location: @quarry }\n else\n format.html { r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /quandaries/1 PATCH/PUT /quandaries/1.json
def update respond_to do |format| if @quandary.update(quandary_params) format.html { redirect_to @quandary, notice: 'Quandary was successfully updated.' } format.json { render :show, status: :ok, location: @quandary } else format.html { render :edit } format.json { render...
[ "def update\n @quarry = Quarry.find(params[:id])\n\n respond_to do |format|\n if @quarry.update_attributes(params[:quarry])\n format.html { redirect_to @quarry, notice: 'Quarry was successfully updated.' }\n format.json { head :no_content }\n else\n format.html { render action: ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /quandaries/1 DELETE /quandaries/1.json
def destroy @quandary.destroy respond_to do |format| format.html { redirect_to quandaries_url, notice: 'Quandary was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @quarry = Quarry.find(params[:id])\n @quarry.destroy\n\n respond_to do |format|\n format.html { redirect_to quarries_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @quatum.destroy\n respond_to do |format|\n format.html { redirect_to quata_url...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with minute precision as a string Returns: A humanreadable string representing the Date
def minute(date) time = [pad(date.hour.to_s), pad(date.minute.to_s)].join(':') [time, day(date)].join(' ') end
[ "def formatted_time_checked_in_on_date(date)\n total_minutes = minutes_checked_in_on_date(date)\n format_minutes(total_minutes)\n end", "def minute; '%02d' % min; end", "def pretty_date\n return Time.at(self.execution_date).strftime(\"%m/%d/%Y - %l:%M:%S %p\")\n end", "def pretty_start_date\n s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with century precision Returns: A humanreadable string representing the Date
def century(date) c = ((date.year.abs.to_i / 100) + 1).ordinalize + ' century' return [c, BCE_SUFFIX].join(' ') if (date.year <= -1) c end
[ "def display_str_for_century\n return unless orig_date_str\n return if orig_date_str =~ /B\\.C\\./\n\n century_str_matches = orig_date_str.match(CENTURY_WORD_REGEXP)\n return century_str_matches.to_s if century_str_matches\n\n century_matches = orig_date_str.match(CENTURY_4CHAR_RE...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with ten_thousand_years precision Returns: A humanreadable string representing the Date
def ten_thousand_years(date) coarse_precision(date.year, 10e3.to_i) end
[ "def ten_million_years(date)\n coarse_precision(date.year, 10e6.to_i)\n end", "def hundred_thousand_years(date)\n coarse_precision(date.year, 100e3.to_i)\n end", "def hundred_million_years(date)\n coarse_precision(date.year, 100e6.to_i)\n end", "def billion_years(date)\n coarse_pr...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with hundred_thousand_years precision Returns: A humanreadable string representing the Date
def hundred_thousand_years(date) coarse_precision(date.year, 100e3.to_i) end
[ "def ten_thousand_years(date)\n coarse_precision(date.year, 10e3.to_i)\n end", "def hundred_million_years(date)\n coarse_precision(date.year, 100e6.to_i)\n end", "def billion_years(date)\n coarse_precision(date.year, 1e9.to_i)\n end", "def ten_million_years(date)\n coarse_precisio...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with million_years precision Returns: A humanreadable string representing the Date
def million_years(date) coarse_precision(date.year, 1e6.to_i) end
[ "def ten_million_years(date)\n coarse_precision(date.year, 10e6.to_i)\n end", "def hundred_million_years(date)\n coarse_precision(date.year, 100e6.to_i)\n end", "def billion_years(date)\n coarse_precision(date.year, 1e9.to_i)\n end", "def ten_thousand_years(date)\n coarse_precisio...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with ten_million_years precision Returns: A humanreadable string representing the Date
def ten_million_years(date) coarse_precision(date.year, 10e6.to_i) end
[ "def ten_thousand_years(date)\n coarse_precision(date.year, 10e3.to_i)\n end", "def hundred_million_years(date)\n coarse_precision(date.year, 100e6.to_i)\n end", "def million_years(date)\n coarse_precision(date.year, 1e6.to_i)\n end", "def billion_years(date)\n coarse_precision(da...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with hundred_million_years precision Returns: A humanreadable string representing the Date
def hundred_million_years(date) coarse_precision(date.year, 100e6.to_i) end
[ "def hundred_thousand_years(date)\n coarse_precision(date.year, 100e3.to_i)\n end", "def ten_million_years(date)\n coarse_precision(date.year, 10e6.to_i)\n end", "def million_years(date)\n coarse_precision(date.year, 1e6.to_i)\n end", "def billion_years(date)\n coarse_precision(da...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Formats a CarbonDate::Date with billion_years precision Returns: A humanreadable string representing the Date
def billion_years(date) coarse_precision(date.year, 1e9.to_i) end
[ "def ten_million_years(date)\n coarse_precision(date.year, 10e6.to_i)\n end", "def hundred_million_years(date)\n coarse_precision(date.year, 100e6.to_i)\n end", "def million_years(date)\n coarse_precision(date.year, 1e6.to_i)\n end", "def pretty_date(input_date)\n return input_date....
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
A helper function used to format dates that have less than millenium precision Params: +date_year+ The year component of the CarbonDate::Date being formatted +interval+ The precision in years Returns: A humanreadable string representing the Date
def coarse_precision(date_year, interval) date_year = date_year.to_i interval = interval.to_i year_diff = date_year - ::Date.today.year return "Within the last #{number_with_delimiter(interval)} years" if (-(interval - 1)..0).include? year_diff return "Within the next #{number_with_delim...
[ "def format_year\n int_year = @year.to_i\n @year = int_year if int_year.between?(1900, Time.now.year + 2)\n end", "def yearstring\n if year\n \"(#{year})\"\n end\n end", "def estimated_deathyear_range_to_s\n result = \"\"\n \n # only bother with this calculation if this person is dea...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Converts an integer number into a humanreadable string with thousands delimiters. Example: number_with_delimiter(1234567890, ',') => 1,234,567,890 Params: +n+ the number to be delimited. Will be converted to an integer +delim+ the string to be used as the thousands delimiter. Defaults to ','
def number_with_delimiter(n, delim = ',') n.to_i.to_s.reverse.chars.each_slice(3).map(&:join).join(delim).reverse end
[ "def number_with_delimiter(number, delimiter=\",\", separator=\".\")\n begin\n parts = number.to_s.split('.')\n parts[0].gsub!(/(\\d)(?=(\\d\\d\\d)+(?!\\d))/, \"\\\\1#{delimiter}\")\n parts.join separator\n rescue\n number\n end\n end", "def format_num(num); number_wi...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Pad a string with '0' to ensure it has two characters. If a string of 2 or more characters is used as parameter, will not alter the string. Example: pad('1') => "01" Params: +s+ The string to pad. Returns: A string of at least 2 characters
def pad(s) s.rjust(2, '0') end
[ "def fill_zero string\n if string.size % 2 != 0\n string = '0' + string\n string\n else\n string\n end\n end", "def pad(string)\n until string.length == 6\n string += \" \"\n end\n string\n end", "def pad_string_to(ret, length)\n\n until(ret.length % length =...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
diff a +Roomorama::Diff+ object On initialization the +validate!+ method of the diff is called therefore, an operation cannot be built unless the property given is conformant to the basic validations performed on that class.
def initialize(diff) @property_diff = diff property_diff.validate! end
[ "def validate_diff\n if diff.present? and !diff.valid?\n errors.add(:diff, \"not valid\")\n end\n end", "def do_diff(a, b)\r\n DiffBuilder.new(a, b).build\r\n end", "def diff(start_rev, end_rev=nil)\n Diff.new(self, start_rev, end_rev)\n end", "def diff(other)\n Distance.d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Asynchronously upgrade an environment
def async_upgrade(environment, plugin, options = {}) job = Job.new(:upgrade) async(:upgrade, job, environment, plugin, options) job.ticket end
[ "def async_upgrade_omnibus(version, nodes, options = {})\n job = Job.new(:upgrade_omnibus)\n async(:upgrade_omnibus, job, version, nodes, options)\n job.ticket\n end", "def sync_gem_environments\n resync = []\n environments.each do |name|\n env = environment(name)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
create a new db if needed and connect to it db file is named procname.db
def connect(processName) @procName = processName @db_name = processName + ".db" # create the new db if it doesn't exist if(!File.exists?(@db_name)) create_db end @db = SQLite3::Database.open(@db_name) end
[ "def setup_db\n @db = @connection.db(@db_name)\n end", "def create_db(db_name)\n request = 'create_db ' + db_name\n send_to_server request\n end", "def db_setup\n log_debug\n db_file = find_db\n db_tmp = '/tmp/plex_missing_tmp.db'\n @db = ''\n \n # cp to tmp as the db...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /raw_foods POST /raw_foods.json
def create @raw_food = current_merchant.raw_foods.new(raw_food_params) respond_to do |format| if @raw_food.save format.html { redirect_to @raw_food, notice: 'Raw food was successfully created.' } format.json { render :show, status: :created, location: @raw_food } else format...
[ "def create_food(body)\n post(\"user/#{user_id}/foods.json\", body)\n end", "def create\n @food = @fridge.foods.create(food_params)\n respond_with @food, location: -> { kitchen_board_path }\n end", "def create\n results = food_params.to_h\n results[\"tags\"] = Tag.where(id: [results[\"tags\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /raw_foods/1 DELETE /raw_foods/1.json
def destroy @raw_food.destroy respond_to do |format| format.html { redirect_to raw_foods_url, notice: 'Raw food was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @line_food = LineFood.find(params[:id])\n @line_food.destroy\n\n respond_to do |format|\n format.html { redirect_to line_foods_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @dish_food.destroy\n respond_to do |format|\n format.html { redirect...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sets the local path of the s3 downloaded object file
def set_path @file_path = @s3_local_object.body.path end
[ "def download_from_s3\n temp_path_to_file = \"#{PublicEarth::Db::Photo.working_directory}/#{filename}\"\n File.open(temp_path_to_file, 'w') do |file|\n S3Object.stream(s3_key, s3_bucket) do |chunk|\n file.write chunk\n end\n end\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /train_locomotives GET /train_locomotives.json
def index @train_locomotives = TrainLocomotive.all end
[ "def index\n @lovs = Lov.all\n end", "def index\n @lops = Lop.all\n end", "def create\n @train_locomotive = TrainLocomotive.new(train_locomotive_params)\n\n respond_to do |format|\n if @train_locomotive.save\n format.html { redirect_to @train_locomotive, notice: 'Train locomotive was s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /train_locomotives POST /train_locomotives.json
def create @train_locomotive = TrainLocomotive.new(train_locomotive_params) respond_to do |format| if @train_locomotive.save format.html { redirect_to @train_locomotive, notice: 'Train locomotive was successfully created.' } format.json { render action: 'show', status: :created, location:...
[ "def train\n training = @prediction.trainedmodels.insert.request_schema.new\n training.id = 'preconceito-nordeste'\n training.storage_data_location = DATA_OBJECT\n result = @client.execute(\n :api_method => @prediction.trainedmodels.insert,\n :parameters => {'project' => PROJECT_ID},\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /train_locomotives/1 PATCH/PUT /train_locomotives/1.json
def update respond_to do |format| if @train_locomotive.update(train_locomotive_params) format.html { redirect_to @train_locomotive, notice: 'Train locomotive was successfully updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.js...
[ "def update\n respond_to do |format|\n if @longtrain.update(longtrain_params)\n format.html { redirect_to @longtrain, notice: 'Longtrain was successfully updated.' }\n format.json { render :show, status: :ok, location: @longtrain }\n else\n format.html { render :edit }\n for...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /train_locomotives/1 DELETE /train_locomotives/1.json
def destroy @train_locomotive.destroy respond_to do |format| format.html { redirect_to train_locomotives_url } format.json { head :no_content } end end
[ "def destroy\n @path_train = PathTrain.find(params[:id])\n @path_train.destroy\n\n respond_to do |format|\n format.html { redirect_to path_trains_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @train_line = TrainLine.find(params[:id])\n @train_line.destroy\n\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
=== list Shows list of Workflows.
def list Log.add_info(request, params.inspect) @tmpl_folder, @tmpl_workflows_folder = TemplatesHelper.get_tmpl_subfolder(TemplatesHelper::TMPL_WORKFLOWS) my_wf_folder = WorkflowsHelper.get_my_wf_folder(@login_user.id) sql = WorkflowsHelper.get_list_sql(@login_user.id, my_wf_folder.id) @workflows ...
[ "def index\n @workflows = Workflow.all\n \n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @workflows }\n end\n end", "def index\n @active_workflows = ActiveWorkflow.all\n end", "def index\n @workflow_states = WorkflowState.all\n end",...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
=== move Moves Workflow to the specified Folder.
def move Log.add_info(request, params.inspect) raise(RequestPostOnlyException) unless request.post? unless params[:tree_node_id].nil? folder_id = params[:tree_node_id] SqlHelper.validate_token([folder_id]) workflow = Workflow.find(params[:id]) workflow.item.update_attribute(:fold...
[ "def move_to_folder=(value)\n @move_to_folder = value\n end", "def move_to_folder\n return @move_to_folder\n end", "def move_to(folder)\r\n destination =\r\n if folder.is_a?(RExchange::Folder)\r\n folder.to_s.ensure_ends_with('...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
=== check_owner Filter method to check if the current User is owner of the specified Workflow.
def check_owner return if params[:id].blank? or @login_user.nil? begin owner_id = Workflow.find(params[:id]).user_id rescue owner_id = -1 end if !@login_user.admin?(User::AUTH_WORKFLOW) and owner_id != @login_user.id Log.add_check(request, '[check_owner]'+request.to_s) flas...
[ "def user_is_owner(job)\n current_user && current_user.id == job.user_id\n end", "def is_owner?(obj)\n obj.user_id == current_user.id\n end", "def owner_check\n if current_user\n return true if current_user.evil_master\n return true if current_user.site_admin\n return tru...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Expected output: ['tea', 'water', 'soda water'] psuedo create my method going with are_you_in_here use select method to pull out items in array see how to use value to use includes method perhaps p my result with test arrays first snag .includes only returns true or false not sure how to get that to retrurn the array i...
def are_you_in_here letter, arr arr.select { |arr| arr.include?(letter) } end
[ "def got_it(array, string)\n #need to iterate across array and look at the values\n array.select do |value|\n #returns words that contain a particular letter\n value.include? string\n end\nend", "def letter_select (array, letter)\n newArray = []\n array.each do |value|\n if value.include? lett...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
API method should be derived from the class name. eg: Host => "host.get"
def api_method @_api_method ||= "#{method_from_class_name}.get" end
[ "def _method_name(klass)\n klass.to_s.downcase.gsub(\"::\", \"_\")\n end", "def api_method_instance(method_name)\n api_methods[method_name]\n end", "def api_base\n self.class.name.split('::').last.downcase\n end", "def class_name method_name\n segments = method_nam...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /mt_manufacturings/new GET /mt_manufacturings/new.xml
def new @mt_manufacturing = MtManufacturing.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @mt_manufacturing } end end
[ "def new\n @manufacturing_data = ManufacturingData.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @manufacturing_data }\n end\n end", "def new\n @mt_manufacturing_resource_data = MtManufacturingResourceData.new\n\n respond_to do |format|\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /mt_manufacturings POST /mt_manufacturings.xml
def create @mt_manufacturing = MtManufacturing.new(params[:mt_manufacturing]) respond_to do |format| if @mt_manufacturing.save format.html { redirect_to(@mt_manufacturing, :notice => 'Mt manufacturing was successfully created.') } format.xml { render :xml => @mt_manufacturing, :status =>...
[ "def new\n @mt_manufacturing = MtManufacturing.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @mt_manufacturing }\n end\n end", "def create\n @manufacturer = Manufacturer.new(params[:manufacturer])\n\n respond_to do |format|\n if @manufact...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /mt_manufacturings/1 DELETE /mt_manufacturings/1.xml
def destroy @mt_manufacturing = MtManufacturing.find(params[:id]) @mt_manufacturing.destroy respond_to do |format| format.html { redirect_to(mt_manufacturings_url) } format.xml { head :ok } end end
[ "def destroy\n @manufacturer = Manufacturer.find(params[:id])\n @manufacturer.destroy\n\n respond_to do |format|\n format.html { redirect_to(manufacturers_url) }\n format.xml { head :ok }\n end\n end", "def destroy\n @manufacturer = Manufacturer.find(params[:id])\n @manufacturer.destr...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns a string of all the log output from the import. Or returns nothing if a custom logger was used.
def log @log_output.string end
[ "def logger_output; end", "def logger_output\n @@logger_output\n end", "def getLog\r\n return filename\r\n end", "def get_log\n # TODO: implement get log\n end", "def combined_log\n messages.join.strip\n end", "def log_path\n @log_path || STDOUT\n end", "def logs_of(s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add includes options which will be used when querying records. Useful to avoid N+1 type problems. Configured has_manys are automaticaly included and don't need to be specified here.
def includes(options) @includes = options end
[ "def add_includes(&block)\n if include_associations = options.delete(:include)\n base_only_or_except = { :except => options[:except],\n :only => options[:only] }\n\n include_has_options = include_associations.is_a?(Hash)\n associations = include_has...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add eager_load options which will be used when querying records.
def eager_load(options) @eager_load = options end
[ "def eager_load!\n super\n ActiveFedora::Scoping.eager_load!\n ActiveFedora::Aggregation.eager_load!\n ActiveFedora::Associations.eager_load!\n ActiveFedora::Attributes.eager_load!\n ActiveFedora::AttributeMethods.eager_load!\n ActiveFedora::Indexers.eager_load!\n ActiveFedor...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Process a cluster message
def process_message(message) # Extract fields from message begin data = JSON.parse message rescue JSON::ParserError Logger.error log_message("JSON Parse error on cluster message: '" + msg + "'") return end sender = data['sender'] return if sender == no...
[ "def confirm_message\n cluster = Cluster.new\n\n case self.type\n when 'Elasticrawl::ParseJob'\n message = segment_list\n else\n message = []\n end\n\n message.push('Job configuration')\n message.push(self.job_desc)\n message.push('')\n message.push(cluster...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
The node_id of the current master
def master_id() @master_id ||= "" end
[ "def node_id\n return @node_id\n end", "def flume_master_id\n flume_masters.find_index( Ironfan::NodeUtils.private_ip_of( node ) )\n end", "def flume_master_id\n flume_masters.find_index( ClusterChef::NodeUtils.private_ip_of( node ) )\n end", "def neo_node_id\n @internal_node.getId()\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sends a cluster message
def send_message(event, payload = nil, destination = nil) Redis.publish('slanger:cluster', {sender: node_id, destination: destination, event: event, payload: payload}.to_json) end
[ "def send_message(message)\n client.puts message\n end", "def cluster() node[:cluster_name] ; end", "def cluster=(value)\n @cluster = value\n end", "def cluster(subcommand, *args)\n subcommand = subcommand.to_s.downcase\n block = case subcommand\n when 'slots'\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
The last time a "election victory" occured. Upon receiving a new election victory, if the last one is old we forget the old master If he's still around and still the highest key he'll send a fresh election victory anyway.
def master_last_seen_unix_timestamp() @master_last_seen_unix_timestamp ||= 0 end
[ "def last_state_change\n if self.alive? and @thread.key?(:last_state_change)\n return @thread[:last_state_change]\n else\n return nil\n end\n end", "def previous_ticket\n Cassy::TicketGrantingTicket.where(:username => username.to_s).where(\"id <> ?\",self.id).where(\"created_o...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Reply to enquiry. Sent by the master if its key is greater than the enquirer's
def send_enquiry_reply(enquirer) send_message(:election_enquiry_reply, nil, enquirer) end
[ "def hi_enquiry(*args)\n self.update_attribute(:bot_response, hi_response)\n return false\n end", "def answer_confirmation_of_supplied_details\n user = @respondent\n confirmation_of_supplied_details_page.email_receipt_question.set(user.email_receipt)\n confirmation_of_supplied_details_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Method to see whether all of the predictions on a tip are won or not and if they are, this will set the tip to won
def tip_won @tip = Tip.find(params[:tip][:tip_id]) @prediction = [] @tip.predictions.each do |prediction| @prediction.push(prediction.result.betWon) end if @prediction.all? @tip.won = true elsif @prediction.include? false @tip.won = false else @tip.won = nil end ...
[ "def have_they_won?\n if @winHomeTeam\n @prediction.result.betWon = true\n elsif @winAwayTeam\n @prediction.result.betWon = true\n elsif @draw\n @prediction.result.betWon = true\n elsif @bothTeamsToScore\n @prediction.result.betWon = true\n elsif @over0_5\n @prediction.resul...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test the creation of the find args count only
def test_count_find_articles_for_user_args_with_feed feed = UserFeed.find(5) #New York Times args = VwArticlesForUser.find_articles_for_user_args(true, feed, :feed, 3, nil, nil) assert args[:select] == "DISTINCT id" assert args[:conditions] == ["feed_id = ? AND (article_user_id = ? OR article_user_id IS...
[ "def test_check_arg_count_empty\n @args_empty = ArgChecker.new([])\n refute @args_empty.check_arg_count\n end", "def test_check_arg_count_short\n @args_short = ArgChecker.new([1, 1])\n refute @args_short.check_arg_count\n end", "def test_check_arg_count_long\n @args_long = ArgChecker.new([1, 1,...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test counting articles now
def test_count_articles_for_user_with_feed feed = UserFeed.find(6) #NErr the Blog count = VwArticlesForUser.count_articles_for_user(feed, :feed, 3) assert count == 2 end
[ "def article_count(response, data, count)\n data.count.should == count.to_i\n end", "def view_count\n Article.increment_counter(:views, self.id)\n end", "def site_stats\n @today = Article.where(publish: 'Yes').where(\"DATE(date_published) = ?\", Time.zone.now.to_date).count\n @yesterday = Article....
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Test finding the articles
def test_find_articles_for_user_with_feed feed = UserFeed.find(6) #Err the Blog articles = VwArticlesForUser.find_articles_for_user(feed, :feed, 3) assert articles.size == 2 assert !articles.has_next_page assert !articles.has_prev_page assert articles.prev_page.nil? assert articles.next_page...
[ "def find_articles(*args)\n (1..@how_many).each { |n| Article.create(:name => n, :author_id => 1) }\n results = Article.find(*args)\n if results.size > results.page_size\n page_count, num_on_last_page = how_many.divmod(results.page_size)\n page_count = page_count + 1 if num_on_last_page > 0\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Purpose: due_date setter Signature: takes date string in "YYYYMMDD" format
def set_due_date(date_string) @due_date = Date.parse(date_string) end
[ "def change_due_date(date)\n @due_date = Date.parse(date)\n end", "def set_due_date(month,day,year)\n @due_date = Date.new(year, month, day)\n end", "def set_due_date\n if created_at.day >= 29\n y = created_at.year\n m = created_at.next_month.month\n d = 28\n x = Date.new(y, m, d)...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Adding points against and points for to rankings hash
def add_points(team) games_played = Game.where("team_one = #{team.id} or team_two = #{team.id}") @rankings[team.name]["points_for"] = 0 @rankings[team.name]["points_against"] = 0 if !games_played.nil? games_played.each do |game| if !game.winner.nil? && !game.winner_score.nil? if ...
[ "def get_rankings\n #create tmp hash storage for all the rows in the rankings table\n row_holder = Hash.new { |hash, key| hash[key] =\n {'played' => 0, '3_points' => 0, '2_points' => 0, '1_point' => 0,\n '0_points' => 0, 'won_sets' => 0, 'lost_sets' => 0, 'points' => 0,\n 'nam...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /plans/new GET /plans/new.json
def new @plan = Plan.new respond_to do |format| format.html # new.html.erb format.json { render json: @plan } end end
[ "def new\n @plan_resource = PlanResource.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @plan_resource }\n end\n end", "def new\n @plantype = Plantype.new\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Start our ldap connection.
def start case ssl when :tls @connection = LDAP::SSLConn.new(host, port, true) when true @connection = LDAP::SSLConn.new(host, port) else @connection = LDAP::Conn.new(host, port) end @connection.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION, 3) @connection....
[ "def ldap_connect\n ldap = Net::LDAP.new(host: host, port: Net::LDAP::DefaultPort)\n ldap\n end", "def config_ldap_start\n\n\t\t`chkconfig --level 3 ldap on`\n\t\t`service ldap start`\n\n\t\tldap_status = `service ldap status`\n\n\t\tif ldap_status.include? \"running\"\n\t\t\tputs \"LDAP Server was s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
create logger based on a given configration
def create_logger(conf) name = self.class.to_s @logger = Patriot::Util::Logger::Factory.create_logger(name, conf) end
[ "def configure_logger_for(classname)\n # handle case in which log path does not exists\n begin\n logger = Logger.new(@log_path)\n rescue Errno::ENOENT\n FileUtils.mkdir_p File.dirname @log_path\n retry\n end\n\n logger.progname = classname\n logge...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the current state the object is in, as a Ruby symbol.
def current_state self.send(self.class.state_column).to_sym end
[ "def state_name\n @curr.state.state\n end", "def current_state_name\n begin\n current_state.name.to_sym\n rescue NoMethodError\n nil\n end\n end", "def get_state(symbol)\n states[normalize_text(symbol)]\n end", "def current_state_s\n \"#{self.current_state}\"...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns what the next state for a given event would be, as a Ruby symbol.
def next_state_for_event(event) ns = next_states_for_event(event) ns.empty? ? nil : ns.first.to end
[ "def next_state_for_event(event)\n ns = next_states_for_event(event)\n ns.empty? ? nil : ns.first.to\n end", "def next_state_for_event(event)\n ns = next_states_for_event(event)\n ns.empty? ? nil : ns.first.to\n end", "def next_state(state, event)\n transition = next_s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Wraps ActiveRecord::Base.find to conveniently find all records in a given state. Options: +number+ This is just :first or :all from ActiveRecord +find+ +state+ The state to find +args+ The rest of the args are passed down to ActiveRecord +find+
def find_in_state(number, state, *args) with_state_scope state do find(number, *args) end end
[ "def find_in_state(number, state, *args)\n raise InvalidState unless states.include?(state)\n \n options = args.last.is_a?(Hash) ? args.pop : {}\n if options[:conditions]\n options[:conditions].first << \" AND #{self.state_column} = ?\"\n options[:conditions...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Wraps ActiveRecord::Base.count to conveniently count all records in a given state. Options: +state+ The state to find +args+ The rest of the args are passed down to ActiveRecord +find+
def count_in_state(state, *args) with_state_scope state do count(*args) end end
[ "def count(*args)\n all(*args).size\n end", "def count_by_state\n count_params = params.merge(state: nil, sort: nil, force_cte: true)\n finder = self.class.new(current_user, count_params)\n\n state_counts = finder\n .execute\n .reorder(nil)\n .group(:state_id)\n .count\n\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Wraps ActiveRecord::Base.calculate to conveniently calculate all records in a given state. Options: +state+ The state to find +args+ The rest of the args are passed down to ActiveRecord +calculate+
def calculate_in_state(state, *args) with_state_scope state do calculate(*args) end end
[ "def calc state\n calc_pos state\n calc_wrap state\nend", "def all(*args)\n multi_calc(args)\n end", "def calculate_all(options = {})\n calculator = BonnieBackendCalculator.new\n query = {}\n query[:user_id] = User.where(email: options[:user_email]).first.try(:id) if options[:user_email]\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Function that create channel with rest_api and check if channel exsists first
def create_channel(channel) puts "running create_channel, channel = #{channel.inspect}" key_check = RestClient.get "#{$base_url}/channels/#{channel["key"]}" #space should be escaped :) if key_check.nil? || key_check['key'].nil? #params = { 'key' => channel["key"], 'name' => channel["name"], 'description' =>...
[ "def _create_channel(name)\n\t\tresponse = @client.post(\n\t\t\t@session[\"resources\"][\"channels\"][\"url\"],\n\t\t\t:body => { :name => name }.to_json,\n\t\t\t:headers => {\n\t\t\t\t\"Authorization\" => \"Capability #{@session[\"resources\"][\"channels\"][\"capability\"]}\",\n\t\t\t\t\"Accept\" => mediaType(\"ch...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /suppliers/remove DELETE /suppliers/remove.xml
def remove @reorder_url = reorder_suppliers_url @ids = selected_ids(:supplier_ids) respond_to do |format| if(Supplier.remove(@ids)) flash[:notice] = "Suppliers removed (#{@ids.size})." format.html { redirect_to suppliers_url } format.xml { head :ok } format.js { ...
[ "def destroy\n @supplier = Supplier.find(params[:id])\n @supplier.destroy\n\n respond_to do |format|\n format.html { redirect_to(admin_suppliers_url) }\n format.xml { head :ok }\n end\n end", "def destroy\n @supplier = Supplier.find(params[:id])\n @supplier.destroy\n\n respond_to ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
"The value of avgLoad(s_i), in case of plugbased prediction, is calculated as the average of all load values reported by the given plug with timestamps in s_i."
def get_plug_avgLoad(s_i, h_id = house_id, hh_id = household_id, p_id = plug_id) query = "SELECT load FROM AveragePlugLoads WHERE house_id = %d " \ "AND household_id = %d "\ "AND plug_id = %d "\ "AND slice_index = %d" % [h_id, hh_id, p_id, s_i] results = execute_query(query) if results.cou...
[ "def calculate_house_avgLoad(s_i)\n query = \"SELECT load FROM AveragePlugLoads WHERE house_id = %d \" \\\n \"AND slice_index = %d\" % [house_id, s_i]\n\n results = execute_query(query)\n loads = results.map{|row| row[\"load\"]}\n puts \"EXECUTED: #{query}, GOT #{loads}\" if DEBUG\n sum(loads)\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
"In case of a housebased prediction the avgLoad(s_i) is calculated as a sum of average values for each plug within the house."
def calculate_house_avgLoad(s_i) query = "SELECT load FROM AveragePlugLoads WHERE house_id = %d " \ "AND slice_index = %d" % [house_id, s_i] results = execute_query(query) loads = results.map{|row| row["load"]} puts "EXECUTED: #{query}, GOT #{loads}" if DEBUG sum(loads) end
[ "def get_plug_avgLoad(s_i, h_id = house_id, hh_id = household_id, p_id = plug_id)\n query = \"SELECT load FROM AveragePlugLoads WHERE house_id = %d \" \\\n \"AND household_id = %d \"\\\n \"AND plug_id = %d \"\\\n \"AND slice_index = %d\" % [h_id, hh_id, p_id, s_i]\n results = execute_query(quer...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
return linked post types
def oz_post_types(sep = ', ') TYPES.dup.keys.map { |type| post_type_link(type + 's', type) }.join(sep) end
[ "def oz_post_types(sep = ', ')\r\n TYPES.dup.keys.map { |type| post_type_link(type + 's', type) }.join(sep)\r\n end", "def post_types\n [\n {type: \"note\", name: \"Note\", properties: %w[content category]},\n {type: \"article\", name: \"Article\", properties: %w[name content category]},\n {...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
builds a link to a list of posts for a type
def post_type_link(text, type = nil) type = text if type.nil? link_to text, :controller => 'tumble', :action => 'list_by_post_type', :type => type end
[ "def post_type_link(text, type = nil)\r\n type = text if type.nil?\r\n link_to text, :controller => 'post', :action => 'list_by_type',\r\n :type => type\r\n end", "def url_for_list(type); end", "def list_by_post_type\n list :conditions => ['post_type = ?', params[:type]]\n end", "d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
add a + or in front of tags if we're looking at a tag's listing
def add_tag_link(tag) cur_tag = params[:tag] if cur_tag and !cur_tag.split.select { |x| x =~ /^#{tag}$/ }.empty? link = cur_tag.split if link.size == 1 link_to('-', { :controller => 'tumble', :action => 'list' }, :class => 'remove-tag') else link = link.reject { |x| x =~ /^#{ta...
[ "def add_tag_link(tag)\r\n cur_tag = params[:tag]\r\n if cur_tag and !cur_tag.split.select { |x| x =~ /^#{tag}$/ }.empty?\r\n link = cur_tag.split\r\n if link.size == 1\r\n link_to('-', '/', :class => 'remove-tag')\r\n else\r\n link = link.reject { |x| x =~ /^#{tag}$/ } * '+'\r\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Freeze nested_attributes_module when freezing model class.
def freeze @nested_attributes_module.freeze if @nested_attributes_module super end
[ "def freeze\n @lazy_attributes_module.freeze if @lazy_attributes_module\n\n super\n end", "def deep_freeze!\n replace deep_thaw.deep_freeze\n end", "def freeze\n freeze!\n attributes.freeze\n super\n end", "def freeze\n @attributes = @attributes.clone.freeze...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Allow nested attributes to be set for the given associations. Options: :destroy :: Allow destruction of nested records. :fields :: If provided, should be an Array or proc. If it is an array, restricts the fields allowed to be modified through the association_attributes= method to the specific fields given. If it is a p...
def nested_attributes(*associations, &block) include(@nested_attributes_module ||= Module.new) unless @nested_attributes_module opts = associations.last.is_a?(Hash) ? associations.pop : {} reflections = associations.map{|a| association_reflection(a) || raise(Error, "no association named #{...
[ "def nested_attributes(*associations, &block)\n include(self.nested_attributes_module ||= Module.new) unless nested_attributes_module\n opts = associations.last.is_a?(Hash) ? associations.pop : {}\n reflections = associations.map{|a| association_reflection(a) || raise(Error, \"no associat...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add a nested attribute setter method to a module included in the class.
def def_nested_attribute_method(reflection) @nested_attributes_module.class_eval do define_method("#{reflection[:name]}_attributes=") do |v| set_nested_attributes(reflection[:name], v) end end end
[ "def def_nested_attribute_method(reflection)\n nested_attributes_module.class_eval do\n if reflection.returns_array?\n define_method(\"#{reflection[:name]}_attributes=\") do |array|\n nested_attributes_list_setter(reflection, array)\n end\n els...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Check that the keys related to the association are not modified inside the block. Does not use an ensure block, so callers should be careful.
def nested_attributes_check_key_modifications(meta, obj) reflection = meta[:reflection] keys = reflection.associated_object_keys.map{|x| obj.get_column_value(x)} yield unless keys == reflection.associated_object_keys.map{|x| obj.get_column_value(x)} raise(Error, "Modi...
[ "def nested_attributes_check_key_modifications(reflection, obj)\n keys = reflection.associated_object_keys.map{|x| obj.send(x)}\n yield\n raise(Error, \"Modifying association dependent key(s) when updating associated objects is not allowed\") unless keys == reflection.associated_object_ke...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Take an array or hash of attribute hashes and set each one individually. If a hash is provided it, sort it by key and then use the values. If there is a limit on the nested attributes for this association, make sure the length of the attributes_list is not greater than the limit.
def nested_attributes_list_setter(meta, attributes_list) attributes_list = attributes_list.sort_by(&:to_s).map{|k,v| v} if attributes_list.is_a?(Hash) if (limit = meta[:limit]) && attributes_list.length > limit raise(Error, "number of nested attributes (#{attributes_list.length}) exceeds...
[ "def nested_attributes_list_setter(reflection, attributes_list)\n attributes_list = attributes_list.sort_by{|x| x.to_s}.map{|k,v| v} if attributes_list.is_a?(Hash)\n if (limit = reflection[:nested_attributes][:limit]) && attributes_list.length > limit\n raise(Error, \"number of nested a...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Modify the associated object based on the contents of the attributes hash: If a :transform block was given to nested_attributes, use it to modify the attribute hash. If a block was given to nested_attributes, call it with the attributes and return immediately if the block returns true. If a primary key exists in the at...
def nested_attributes_setter(meta, attributes) if a = meta[:transform] attributes = a.call(self, attributes) end return if (b = meta[:reject_if]) && b.call(attributes) modified! reflection = meta[:reflection] klass = reflection.associated_class ...
[ "def nested_attributes_setter(reflection, attributes)\n return if (b = reflection[:nested_attributes][:reject_if]) && b.call(attributes)\n modified!\n klass = reflection.associated_class\n if pk = attributes.delete(klass.primary_key) || attributes.delete(klass.primary_key.to_s)\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Update the given object with the attributes, validating it when the parent object is validated and saving it when the parent is saved. Returns the object updated.
def nested_attributes_update(meta, obj, attributes) nested_attributes_update_attributes(meta, obj, attributes) delay_validate_associated_object(meta[:reflection], obj) # Don't need to validate the object twice if :validate association option is not false # and don't want to valid...
[ "def update\n @parent = Parent.find(params[:id])\n\n respond_to do |format|\n if @parent.update_attributes(params[:parent])\n format.html { redirect_to(@parent, :notice => 'Parent was successfully updated.') }\n format.xml { head :ok }\n else\n format.html { render :action => \...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
call processing for the given events list and release locks
def process( events, process_stat, settings = { :keep_processed => true} ) successfull = [] unsuccessfull = [] process_stat.start( events.length ) events.each do |event| begin if yield event # should be commented to keep processed records @conn.exec(...
[ "def process_events\n\t\tnow = Time.now\n\n\t\tevents_to_delete = []\n\t\tevents_to_add = []\n\t\tself.queue.each do |ev|\n\t\t\tnext unless now >= ev.runtime\n\n\t\t\tevents_to_delete << ev\n\t\t\trv = ev.fire( &@proc )\n\n\t\t\t# Reschedule the event and place it back on the queue.\n\t\t\t#\n\t\t\tif ev.event.rec...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
ex. arr=[1, 3, 5] and Y=2 should count 2
def greater_than(arr, y) count = 0 arr.each { |i| count +=1 if i > y} count end
[ "def greater_than_y(arr, y)\n\tcount = 0\n\tarr.each do |num|\n\t\tcount += 1 if num > y\n\tend\n\treturn count\nend", "def cnts a\n r = []\n found = false\n a.each do |x|\n r.each do |y|\n if y[0] === x\n y[1] += 1\n found = true\n break\n end\n end\n if !found\n r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Override this method so that we can provide a fake file name. Several views depend on the datastream label, which is just the the original_filename of the file. This allows you to effectively change what label is displayed in those views. Otherwise, you will see the same label for every file.
def original_filename fake_file_name || super end
[ "def display_filename\n original_name || file_file_name\n end", "def display_filename=(filename)\n self.original_name = filename\n end", "def label_for(file)\n if file.is_a?(Hyrax::UploadedFile) # filename not present for uncached remote file!\n file.uploader.filename.present? ? file...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates or finds an object by id. If an actor is given, will use the actor to create the object. Otherwise, will just use the new method on the model given
def find_or_create(model, actor, id, user, params) curation_concern = model.where(desc_metadata__identifier_tesim: id).first if curation_concern.nil? curation_concern = model.new(identifier: id) if actor.present? actor.new(curation_concern, user, params).create else curation_concern.attribut...
[ "def find_or_create( id )\n begin\n get( id )\n rescue\n create!( :id => id )\n end \n end", "def find_or_reflect_by_id!(*args)\n record = find_or_initialize_by_id(*args)\n record.reflect! if record.new_record?\n record\n end...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates or finds a library collection by description. If an actor is given, will use the actor to create the object. Otherwise, will just use the new method on the model given
def find_or_create_library_collection(description, user, params) collection = LibraryCollection.where(desc_metadata__description_tesim: description).first if collection.nil? collection = LibraryCollection.new collection.attributes = params collection.apply_depositor_metadata(user.user_key) collectio...
[ "def find_or_create_resource_for_collection(name); end", "def new_collection\n Models::Collection.new\n end", "def find_or_create_resource_for_collection(name)\r\n find_or_create_resource_for(name.to_s.singularize)\r\n end", "def build(attrs, collection)\n collection.new(attrs)\n e...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Checkin date should not be less than today's date.
def checkin_at_after_or_on_today return if dates_blank if checkin_at < Date.today self.errors.add(:checkin_at, ": Should be greater than or equal to today's date") end end
[ "def checkin_before_checkout\n if self.checkin && self.checkout && self.checkin >= self.checkout\n errors.add(:guest, \"Your checkin date must be before your checkout date\")\n end\n end", "def check_in_cannot_be_in_the_past\n if check_in.present? && check_in < Date.today\n errors.add(:check_i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Restriction to book only upto 6 months. User can do checkin within 6 months. Checkout is not restricted.
def checkin_before_6_months return if dates_blank if checkin_at >= (Date.today + 6.months) self.errors.add(:checkin_at, ': Should be less than or equal to 6 months') end end
[ "def check_out_cannot_be_more_than_6_months\n if check_out.present? && check_out > Date.today+6.months\n errors.add(:check_out, \"can't be more than 6 months. Booking up to 6 months in advance.\")\n end\n end", "def time_period_for_room_reservation\n time_period = (self.start_date.year * 12 + self....
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Checks if the system is properly setup. This method is used by the bootstrapper to see if the system should be initialized. If the system is not properly setup, the bootstrapper will crash. Checks are performed to see if all the tables exists.
def check unless check_tables puts "CBAC: not properly initialized: one or more tables are missing. Did you install it correctly? (run generate)" return false end return true end
[ "def check\n if check_tables == false\n puts \"CBAC: not properly initialized: one or more tables are missing. Did you install it correctly? (run generate)\"\n return false\n end\n true\n end", "def check_setup\n set_config_file_options\n check_project_name\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
get counts of various records belonging to a repository
def get_counts(repo_uri) types = %w(pui_collection pui_archival_object pui_record_group pui_accession pui_digital_object pui_agent pui_subject) counts = archivesspace.get_types_counts(types, repo_uri) # 'pui_record' as defined in AppConfig ('record_badge') is intended for archival objects only, # which ...
[ "def count\n size = 0\n core_search.group(\"name.id, #{main_group_by_columns}\").each do |_x|\n size += 1\n end\n size\n end", "def project_counts\n @project_counts ||= Kithe::Model.joins(:contains_contained_by).\n where(published: true, contains_contained_by: {container_id: project_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
find a team's updated events, for the schedule.
def updated_events(team) return team.future_events if team.schedule_last_sent.nil? team.future_events.select do |event| !event.last_edited.nil? && event.last_edited > team.schedule_last_sent end end
[ "def team_schedules\n\t\t@team_schedules ||= teams.map { |team|\n\t\t\tputs \" ### GETTING GAMES FOR: #{team[:info][:full_name]}\"\n\t\t\turl = \"http://www.vegasinsider.com/#{sport_name}/teams/team-page.cfm/team/#{team[:info][:identifier]}\"\n\t\t\tscrape_team_page(url, team[:info][:identifier])\n\t\t}\n\tend", ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Render straight markdown partial templates. As no ruby will be evaluated the locals and content block will be ignored.
def partial(template_name, locals, &content) self.kramdown_source.render(template_name) end
[ "def render markdown_source\n markdown.render \"#{markdown_source}\"\n end", "def partial(input, opts={})\n haml(input, opts.merge(:layout => false))\n end", "def render_partial(context, options, &block); end", "def markdown(&block)\n filter :markdown, &block\n end", "def ren...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
check if chapter is completed
def completed?(chapter) chapters_completed.include? chapter end
[ "def whole_chapter?\n starting_bibleverse.verse.zero?\n end", "def is_only_chapter?\n self.work.chapters.count == 1\n end", "def whole_book?\n starting_bibleverse.chapter.zero?\n end", "def chapter_valid?(chapter)\n chapter.positive? && chapter <= nr_of_chapters\n end", "def chapters?\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
calculate progress of lesson
def progress(lesson) "%0.2f%" % (chapters_completed.where(lesson: lesson).count / lesson.chapters.count.to_f * 100) end
[ "def progress\n total_steps_count = self.steps.count\n\n if total_steps_count.zero?\n 0.0\n else\n approved_steps_count = self.steps.where(state: 'approved').count\n (approved_steps_count * 100.0 / total_steps_count).round(2)\n end\n end", "def calculate_progress(course, user)\n total...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
calculate if the lesson is completed
def completed_lesson?(lesson) chapters_completed.where(lesson: lesson).count == lesson.chapters.count end
[ "def can_progress?\n lesson < 100 || lesson_part < 3\n end", "def completed?\n @assessment.status == :complete\n end", "def completed\n completed_steps && completed_steps.length\n end", "def is_completed?(assignment)\n !assignment.first.t_completed.nil?\n end", "def crawling_complete?\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
set role to student prior to initial registration
def ensure_there_is_a_role if role.blank? self.role = "student" end end
[ "def set_default_role\n self.role ||= :student\n end", "def change_default_user_role_to_tutor\n if self.user.role == 'student'\n self.user.update(role: 'tutor')\n end\n end", "def setup_role \n if self.role.to_s.empty? \n self.role = 'member' \n end\n end", "def assign_initial_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }