query stringlengths 7 9.55k | document stringlengths 10 363k | metadata dict | negatives listlengths 0 101 | negative_scores listlengths 0 101 | document_score stringlengths 3 10 | document_rank stringclasses 102 values |
|---|---|---|---|---|---|---|
POST /posts POST /posts.xml | def create
@post = Post.new(params[:post])
@post.user_id = session[:user_id]
respond_to do |format|
if @post.save
flash[:notice] = 'Post was successfully created.'
if params[:images]
counter = 0
for image in params[:images]["file_data"]
if image != ""
@image = Image.create(:file_data => image, :owner_id => @post.id, :owner_type => 'Post', :filename => image.original_filename,
:body => params[:images]["body"][counter] )
counter = counter + 1
end
end
end
format.html { redirect_to :controller => "posts" }
format.xml { head :created, :location => post_url(:id => @post) }
else
format.html { render :action => "new" }
format.xml { render :xml => @post.errors.to_xml }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def post(uri, xml)\r\n req = Net::HTTP::Post.new(uri)\r\n req[\"content-type\"] = \"application/xml\"\r\n req.body = xml\r\n request(req)\r\n end",
"def test_should_create_post_via_API_XML\r\n get \"/logout\"\r\n post \"/forum_posts.xml\", :api_key=>'testapikey',\r\n ... | [
"0.68471384",
"0.68003213",
"0.66374344",
"0.66279626",
"0.6584102",
"0.63851535",
"0.63196474",
"0.6277413",
"0.6249678",
"0.62304235",
"0.6226135",
"0.62150663",
"0.6205251",
"0.61857855",
"0.6185225",
"0.6155584",
"0.61525047",
"0.6142964",
"0.61428297",
"0.6131127",
"0.61... | 0.0 | -1 |
PUT /posts/1 PUT /posts/1.xml | def update
respond_to do |format|
if @post.update_attributes(params[:post])
flash[:notice] = 'Post was successfully updated.'
if params[:images]
counter = 0
for image in params[:images]["file_data"]
if image != ""
@image = Image.create(:file_data => image, :owner_id => @post.id, :owner_type => 'Post', :filename => image.original_filename,
:body => params[:images]["body"][counter] )
counter = counter + 1
end
end
end
format.html { redirect_to posts_path }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @post.errors.to_xml }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def put(uri, xml)\r\n req = Net::HTTP::Put.new(uri)\r\n req[\"content-type\"] = \"application/xml\"\r\n req.body = xml\r\n request(req)\r\n end",
"def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post 'update', opts\n end",
"def upd... | [
"0.6867673",
"0.66907144",
"0.6294395",
"0.62794256",
"0.6099675",
"0.6098852",
"0.6035446",
"0.59057415",
"0.590173",
"0.58895403",
"0.5880021",
"0.58741546",
"0.5867954",
"0.5849058",
"0.5837317",
"0.5833679",
"0.58261484",
"0.5825736",
"0.5818691",
"0.58159804",
"0.5810053... | 0.0 | -1 |
DELETE /posts/1 DELETE /posts/1.xml | def destroy
@post.destroy
respond_to do |format|
format.html { redirect_to posts_url }
format.xml { head :ok }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def destroy\n r = PostRepository.new\n @post = r.GetPost(\"PostID\", params[:id].to_i)\n r.delete @post\n\n respond_to do |format|\n format.html { redirect_to(posts_url) }\n format.xml { head :ok }\n end\n end",
"def destroy\n @post = Post.find(params[:id])\n @post.deleted = 1\n ... | [
"0.7365624",
"0.7322596",
"0.715179",
"0.715179",
"0.70919865",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.7068259",
"0.70451736",
"... | 0.72059286 | 2 |
Remove comment from GitHub and then remove from database if successful. comment_id is unique identifier within repo scope. | def remove_comment repo, comment_id
response = @@connection.delete do | request |
request.url "repos/#{repo}/issues/comments/#{comment_id}"
request.headers['Authorization'] = "token #{@@token}"
end
# look for Status: 204 No Content
return if response.env[:status] != 204
# Comment successfully deleted from GitHub so remove from comment.db
@@db.execute "delete from comment where id == #{comment_id}"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_pull_request_comment(repo, comment_id, options = {})\n boolean_from_response(:delete, \"#{Repository.path repo}/pulls/comments/#{comment_id}\", options)\n end",
"def delete_comment(user_name, repo_name, comment_id, params={})\n _update_user_repo_params(user_name, repo_name)\n ... | [
"0.7429408",
"0.73979867",
"0.72943497",
"0.72670454",
"0.72373676",
"0.71700996",
"0.71538055",
"0.709939",
"0.70149136",
"0.70120627",
"0.7011715",
"0.6923734",
"0.6894902",
"0.6873935",
"0.68291354",
"0.6713199",
"0.67110544",
"0.664785",
"0.66473407",
"0.6607416",
"0.6529... | 0.8985965 | 0 |
Returns head of pull request. Head represents the last SHA1 of the pull request. nil is returned on failure. repo the repo name. Example: owner/repo issue the issue number. Example: 3 | def get_last_sha repo, issue
response = @@connection.get do | request |
request.url "repos/#{repo}/pulls/#{issue}"
request.headers['Authorization'] = "token #{@@token}"
end
return nil if response.env[:status] != 200
body = MultiJson.load(response.env[:body])
return body['head']['sha']
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def head\n git.get_head(branch)\n end",
"def head\n git.get_head(branch)\n end",
"def head_path\n \"#{path}/refs/heads/#{branch}\"\n end",
"def getHeadTag\n head_commit_id = @gop.revparse(\"HEAD\")\n\n begin\n @gop.describe(head_commit_id, :contains => true)\n re... | [
"0.69913304",
"0.69913304",
"0.6551737",
"0.6510847",
"0.6499988",
"0.6362922",
"0.63157475",
"0.620106",
"0.6129432",
"0.6128853",
"0.6098599",
"0.6092042",
"0.59948915",
"0.5931964",
"0.5805091",
"0.5797808",
"0.5781474",
"0.5738283",
"0.5711827",
"0.5678033",
"0.56583184",... | 0.68978834 | 2 |
2. I can find a list of exercises I did on a day | def exercise_on_a_day(date)
#iterate through workouts and find workouts.user_id == self
my_workouts = Workout.all.select do |workout|
workout["user_id"] == self["id"]
end
# find where date == workout date
workouts_for_date = my_workouts.find_all do |workouts|
workouts["date"] == date
end.map {|workout_instance| workout_instance.exercise_id}
exercise_array = []
exercise_list = workouts_for_date.each do |exercise_id|
Exercise.all.each do |exercise_instances|
exercise_array << exercise_instances.name if (exercise_instances.id == exercise_id)
end
end
if exercise_array == []
return "Sorry. Doesn't look like you worked out on #{date}.".colorize(:light_cyan)
else
return exercise_array
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_exercises_list\n exercises_list = []\n inst_sections.each do |inst_section|\n exercises_ids = inst_section.inst_book_section_exercises.collect(&:inst_exercise_id).compact\n exercises_objs = InstExercise.where(id: exercises_ids)\n exercises_list.concat exercises_objs.collect(&:short_nam... | [
"0.69004864",
"0.66495",
"0.6513002",
"0.6421902",
"0.6390747",
"0.62667465",
"0.62470347",
"0.62356615",
"0.613157",
"0.61276317",
"0.6090618",
"0.60681695",
"0.6051292",
"0.60158235",
"0.60089785",
"0.600201",
"0.5993537",
"0.5925204",
"0.58687156",
"0.58635896",
"0.5845356... | 0.67958313 | 1 |
3. I can see what muscle_groups I'm working on, ON a specific day | def muscle_groups_on_given_day(date)
# exercise_name = self.exercise_on_a_day(date)
my_workouts = Workout.all.select do |workout|
workout["user_id"] == self["id"]
end
# find where date == workout date
workouts_for_date = my_workouts.find_all do |workouts|
workouts["date"] == date
end.map {|workout_instance| workout_instance.exercise_id}
exercise_array = []
muscle_groups = workouts_for_date.each do |exercise|
Exercise.all.each do |exercise_instances|
exercise_array << exercise_instances.muscle_group if (exercise_instances.id == exercise)
end
end
if exercise_array == []
return "Sorry. Doesn't look like you worked out on #{date}.".colorize(:light_cyan)
else
exercise_array
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def group_by_day\n\n\tend",
"def create_groups\n Group.create(name: \"MWF Morning\", days: [\"Monday\", \"Wednesday\", \"Friday\"], \n start_time: Time.local(2014, 8, 25, 8, 30, 0),\n end_time: Time.local(2014, 8, 25, 11, 30, 0)\n )\n Group.create(name: \"TTH Morning\", days: [\"Tuesday\", \"Thursday\... | [
"0.6002566",
"0.58569956",
"0.56904715",
"0.5617393",
"0.5524284",
"0.54171973",
"0.54171973",
"0.54171973",
"0.5362645",
"0.5356421",
"0.5317589",
"0.52978045",
"0.5297365",
"0.5277178",
"0.52527046",
"0.5252113",
"0.5245826",
"0.5243614",
"0.52301645",
"0.5191251",
"0.51689... | 0.75964785 | 0 |
1. I can return the list of all the days I worked out | def list_of_days_worked_out
array = []
workouts = Workout.all.find_all do |workout|
workout.user_id == self.id
end
dates = workouts.each do |workout|
array << workout.date
end
array
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_work_days\n puts \"Getting work days...\"\n work_days = []\n biweek = get_biweek\n week_1 = @schedule[biweek[0]].compact.uniq\n week_2 = @schedule[biweek[1]].compact.uniq\n\n @schedule.each_with_index do |row, i|\n DAYS.each_with_index do |day, j|\n date = ( i < biweek[1] ? week_1[j] : week_2... | [
"0.7537419",
"0.74122226",
"0.69411093",
"0.69009703",
"0.6840075",
"0.67987645",
"0.6758112",
"0.67461383",
"0.67197204",
"0.66970515",
"0.6687425",
"0.6684145",
"0.6677571",
"0.6666544",
"0.6649977",
"0.66175944",
"0.66120136",
"0.6600144",
"0.6588766",
"0.657634",
"0.65615... | 0.72278166 | 2 |
5. I can log my weight at the end of the week | def log_my_weight(weight)
self.current_weight = weight
self.save
puts "Current weight #{weight}"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def weight_on_date(date)\n get_call(\"/1/user/#{@user_id}/body/log/weight/date/#{format_date(date)}.json\")\n end",
"def add_demand(date, kwh)\n return 0 unless level(date) != :off_peak\n\n if kwh > 20\n p [kwh, date, level(date)]\n end\n\n super\n end",
"def l... | [
"0.6330222",
"0.6330165",
"0.6274216",
"0.6186279",
"0.61630857",
"0.61469686",
"0.61299884",
"0.6126017",
"0.6092013",
"0.6082499",
"0.60398006",
"0.6024036",
"0.601397",
"0.601093",
"0.59977376",
"0.59683645",
"0.596083",
"0.5955692",
"0.59257203",
"0.5868628",
"0.58673453"... | 0.6470833 | 0 |
6. I can also find out how much I lost compared to my starting weight | def weight_lost
weight_fluctuate = current_weight - start_weight
if current_weight < start_weight
return "Down #{weight_fluctuate}. We are making progress!"
else
return "Up #{weight_fluctuate}. We are making gains!"
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def remaining_pints\n ((current_weight-14.25)/0.45).to_i > 0 ? ((current_weight-14.25)/0.45).to_i : 0\n end",
"def weight_until_goal\n if weigh_ins.count > 0 && goal_weight > 0\n weigh_ins.first.current_weight - goal_weight\n elsif goal_weight > 0\n start_weight - goal_weight\n end\n end"... | [
"0.72903585",
"0.71990526",
"0.7162943",
"0.71080804",
"0.7094358",
"0.706027",
"0.69335914",
"0.6790681",
"0.6746478",
"0.6721428",
"0.66577303",
"0.65615785",
"0.65615785",
"0.6550891",
"0.65034646",
"0.6503012",
"0.64950174",
"0.6450043",
"0.6445826",
"0.64377886",
"0.6429... | 0.7574595 | 0 |
8. A user can create a new exercise to add to the database | def create_new_exercise(exercise, muscle_group)
Exercise.create(name: exercise, muscle_group: muscle_group)
puts "Thank you for sharing!"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create_exercise()\n\n #Gets all the information from the user\n message(\"Please enter a name for this new exercise: \")\n name = gets.chomp\n message(\"Please enter a description for \" + name)\n description = gets.chomp\n message(\"Please enter a duration (in seconds... | [
"0.74751145",
"0.7390913",
"0.7354178",
"0.7330593",
"0.70201266",
"0.69600165",
"0.69432503",
"0.68735874",
"0.68717223",
"0.6845112",
"0.6839777",
"0.6768515",
"0.6760509",
"0.6731401",
"0.6701907",
"0.66982186",
"0.66973287",
"0.6657908",
"0.6627169",
"0.6590854",
"0.65851... | 0.7617992 | 0 |
7. a user can log a new workout | def log_new_workout(exercise, date)
exercise_check = Exercise.search_exercise_by_name(exercise)
exercise_instance = Exercise.all.find{|exercises| exercises.name == exercise}
if exercise_check == "Sorry. We don't have any workouts called #{exercise}. Please return to the main menu to create this new exercise and share with the rest of our FitMePan crew."
return exercise_check
else
Workout.create(user_id: self.id, exercise_id: exercise_instance.id, date: date)
end
puts "Thanks for logging your workout!"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def checkin\n if self.current_user == nil\n redirect_to \"/account/login\"\n end\n @workout = Workout.new\n @workout.workout_date = Time.now.to_date #.strftime(\"%x\")\n end",
"def create\n @workout = Workout.new(workout_params)\n @workout.user = current_user!\n if @workout.save\n ... | [
"0.6320663",
"0.62286055",
"0.62044215",
"0.6171314",
"0.6063468",
"0.60554296",
"0.60316205",
"0.59912103",
"0.59694797",
"0.5917017",
"0.59159213",
"0.59057707",
"0.59057707",
"0.587342",
"0.587342",
"0.5847069",
"0.583834",
"0.5815662",
"0.5815662",
"0.580446",
"0.57572347... | 0.7286219 | 0 |
GET /internships/1 GET /internships/1.json | def show
@internship = Internship.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @internship }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @intern = Intern.find(params[:id])\n @internships = Internship.where(intern_id: @intern.id)\n respond_to do |format|\n format.html #show.html.erb\n format.json { render json: @intern }\n end\n end",
"def index\n @internships = Internship.all\n @current_user = User.find(cur... | [
"0.7740879",
"0.69764984",
"0.6767799",
"0.67013353",
"0.63916594",
"0.6220732",
"0.61513543",
"0.61513543",
"0.60837674",
"0.6080233",
"0.59437764",
"0.592135",
"0.59164244",
"0.5878888",
"0.56879574",
"0.5631579",
"0.55941236",
"0.5592559",
"0.55666196",
"0.55666196",
"0.55... | 0.70109886 | 1 |
GET /internships/new GET /internships/new.json | def new
@internship = Internship.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @internship }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def new\n if User.find(current_user.id).internship_authorization\n @internship = Internship.new\n respond_with(@internship)\n else\n flash[:notice] = \"You cannot create an internship\"\n redirect_to internships_url\n end\n end",
"def new\n @internships_user = InternshipsUser.new... | [
"0.73454684",
"0.7180421",
"0.70278883",
"0.69433635",
"0.68479043",
"0.64587957",
"0.64562577",
"0.64349633",
"0.6387319",
"0.6384726",
"0.6348978",
"0.62818676",
"0.6273575",
"0.6244404",
"0.61915636",
"0.61668205",
"0.61668205",
"0.6164066",
"0.6134938",
"0.60961914",
"0.6... | 0.7488251 | 1 |
POST /internships POST /internships.json | def create
@internship = Internship.new(params[:internship])
respond_to do |format|
if @internship.save
format.html { redirect_to @internship, notice: 'Internship was successfully created.' }
format.json { render json: @internship, status: :created, location: @internship }
else
format.html { render action: "new" }
format.json { render json: @internship.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @user = current_user\n @internship = @user.internships.build(params[:internship])\n #@internship = Internship.new(params[:internship])\n\n respond_to do |format|\n if @internship.save\n format.html { redirect_to @internship, notice: 'Internship was successfully created.' }\n ... | [
"0.73136866",
"0.6690699",
"0.66506475",
"0.62748206",
"0.6123335",
"0.6034088",
"0.5963591",
"0.5963591",
"0.5858024",
"0.58463675",
"0.58346415",
"0.5827366",
"0.5743004",
"0.5739911",
"0.57243204",
"0.555894",
"0.54834324",
"0.5419208",
"0.5410784",
"0.5372609",
"0.5342743... | 0.7115359 | 1 |
PUT /internships/1 PUT /internships/1.json | def update
@internship = Internship.find(params[:id])
respond_to do |format|
if @internship.update_attributes(params[:internship])
format.html { redirect_to @internship, notice: 'Internship was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @internship.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n @internship = Internship.find(params[:id])\n\n if @internship.update_attributes(params[:internship])\n flash[:notice] = 'Internship was successfully updated.'\n end\n respond_with(@internship)\n end",
"def update\n @internship = Internship.find(params[:id])\n respond_to do |f... | [
"0.67898536",
"0.6564102",
"0.6362706",
"0.63572764",
"0.6338132",
"0.62355536",
"0.6099583",
"0.5964067",
"0.57670724",
"0.576195",
"0.57573897",
"0.57526064",
"0.57436526",
"0.5684591",
"0.56517744",
"0.5623222",
"0.5623222",
"0.5623222",
"0.55432534",
"0.54426694",
"0.5334... | 0.68532103 | 1 |
DELETE /internships/1 DELETE /internships/1.json | def destroy
@internship = Internship.find(params[:id])
@internship.destroy
respond_to do |format|
format.html { redirect_to internships_url }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def destroy\n @internship = Internship.find(params[:id])\n @internship.destroy\n\n respond_to do |format|\n format.html { redirect_to(internships_url) }\n format.json { head :ok }\n end\n end",
"def destroy\n @internship = Internship.find(params[:id])\n @internship.destroy\n\n re... | [
"0.78914624",
"0.7535926",
"0.7308347",
"0.71867704",
"0.71607774",
"0.70696986",
"0.7039584",
"0.69174975",
"0.67235",
"0.6676366",
"0.66549057",
"0.65720695",
"0.6568648",
"0.65589327",
"0.65444845",
"0.65444845",
"0.6520607",
"0.6461024",
"0.64312166",
"0.64290196",
"0.642... | 0.789848 | 2 |
TODO: Check whether this can be deleted | def hydra
Restulicious.config.hydra
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete\n \n end",
"def delete\n # TODO: implement delete\n end",
"def deletedaysedit\n end",
"def delete\n \n end",
"def delete_operations; end",
"def delete\n end",
"def delete\n end",
"def delete\n end",
"def delete\n end",
"def delete\n end",
"... | [
"0.7630774",
"0.7286127",
"0.7017122",
"0.6984595",
"0.69741404",
"0.69398296",
"0.6926708",
"0.6914731",
"0.69043946",
"0.69043946",
"0.69043946",
"0.69043946",
"0.69043946",
"0.69043946",
"0.69043946",
"0.688594",
"0.68819296",
"0.68800443",
"0.68800443",
"0.68800443",
"0.6... | 0.0 | -1 |
join all the rows separated by newlines | def to_s
@image.map { |row| row.join }.join("\n")
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def join_cr\n self.compact.reject { |element| element.to_s.empty? || element.to_s.strip == \"\\n\" }.join(\"\\n\")\n end",
"def csv(rows)\n rows.map { |r| r.join(';') }.join(\"\\n\")\n end",
"def join_lines\n\t\toutput = []\n\t\tn = 0\n\t\twhile n < @lines.length do\n\t\t\tcur_line = n \n\t\t\tlonger_l... | [
"0.7148511",
"0.7127152",
"0.6800459",
"0.67851365",
"0.6634408",
"0.6582164",
"0.6520546",
"0.63280714",
"0.62706",
"0.61845845",
"0.60294646",
"0.6021414",
"0.59976083",
"0.5965973",
"0.5934499",
"0.59138894",
"0.5909701",
"0.58726776",
"0.5868856",
"0.5864222",
"0.5846963"... | 0.0 | -1 |
set pixels left, right, up and down of a '1' to 1 unless out of bounds | def blur(distance)
find_ones.each do |one|
spread(one, distance)
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_to_one(coords)\n if (0..@max_x).include?(coords[:x]) && (0..@max_y).include?(coords[:y])\n @image[coords[:y]][coords[:x]] = 1\n end\n end",
"def set_one(row,col)\n\t\tpixels[row][col] = 1\n\tend",
"def count_left(x, y)\n if x - 1 < 0\n return 0\n end\n return $canvas[x - 1][y] == 1 ? ... | [
"0.6460228",
"0.6400039",
"0.60692316",
"0.6062662",
"0.60308903",
"0.5995022",
"0.59543717",
"0.5893334",
"0.58867455",
"0.5814616",
"0.57997775",
"0.5773628",
"0.5760343",
"0.5665251",
"0.5665251",
"0.55761063",
"0.55661297",
"0.5562214",
"0.55349624",
"0.5527016",
"0.55260... | 0.0 | -1 |
calculates and sets ones in a cardinal direction from a pixel then spreads out on the other axis | def spread(pixel, distance)
xforms = [{:pri => 'x', :sec => 'y', :mod => '-'},
{:pri => 'x', :sec => 'y', :mod => '+'},
{:pri => 'y', :sec => 'x', :mod => '-'},
{:pri => 'y', :sec => 'x', :mod => '+'}]
xforms.each do |xform|
distance.times do |i|
if xform[:pri] == 'y'
pcoords = { :y => pixel[:y] + "#{xform[:mod]}#{i + 1}".to_i,
:x => pixel[:x] }
else
pcoords = { :x => pixel[:x] + "#{xform[:mod]}#{i + 1}".to_i,
:y => pixel[:y] }
end
set_to_one(pcoords)
(distance - (i + 1)).times do |j|
['+', '-'].each do |sign|
if xform[:sec] == 'y'
scoords = { :y => pcoords[:y] + "#{sign}#{j + 1}".to_i,
:x => pcoords[:x] }
else
scoords = { :x => pcoords[:x] + "#{sign}#{j + 1}".to_i,
:y => pcoords[:y] }
end
set_to_one(scoords)
end
end
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def transform(row_index,col_index)\n\n if row_index-1 >= 0\n @image[row_index-1][col_index] = 1\n end\n if col_index - 1 >= 0\n @image[row_index][col_index-1] = 1\n end\n if row_index + 1 <= @image.length - 1\n @image[row_index+1][col_index] = 1\n end\n if col_index + 1 <= @imag... | [
"0.6275838",
"0.6157626",
"0.61439157",
"0.61123776",
"0.60569835",
"0.60523635",
"0.60075986",
"0.5824565",
"0.5805831",
"0.56577843",
"0.5632394",
"0.55982554",
"0.5561984",
"0.55500764",
"0.5532906",
"0.55228615",
"0.5511399",
"0.5493891",
"0.5481292",
"0.5443608",
"0.5429... | 0.5156745 | 31 |
returns an array with coordinates of the 1's | def find_ones
ones_arr = []
@image.each_index do |row|
@image[row].each_index do |column|
if @image[row][column] == 1
ones_arr << { :x => column, :y => row }
end
end
end
return ones_arr
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def coordinate_array\n\t\t[latitude,longitude]\n\tend",
"def coord_to_array(coordinates)\n x = coordinates[1]\n y = coordinates[0]\n conversion = ((x-1) * @size) + (y -1)\n end",
"def find_ones\n ones_locations = []\n # => finding index of ROW and COL for each 1 in grid and storing as r... | [
"0.6963766",
"0.69543713",
"0.6941461",
"0.68731517",
"0.68238306",
"0.6740419",
"0.67121387",
"0.67001784",
"0.66407365",
"0.66257495",
"0.6544557",
"0.6529268",
"0.6504515",
"0.6445447",
"0.643228",
"0.639688",
"0.63561594",
"0.6343164",
"0.6342545",
"0.63340247",
"0.631005... | 0.70944625 | 0 |
checks if pixel to set within bounds and sets to 1 | def set_to_one(coords)
if (0..@max_x).include?(coords[:x]) && (0..@max_y).include?(coords[:y])
@image[coords[:y]][coords[:x]] = 1
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def restricted?(x, y)\n out_of_bounds?(x, y) || @image.color(x, y) == 0\n end",
"def check_bounds\n\t\tif @x + SUB_TILE_WIDTH > @game_state.width\n\t\t\tupdate_x( -(@x + SUB_TILE_WIDTH - @game_state.width) )\n\t\telsif @x < 0\n\t\t\tupdate_x( @x.abs )\n\t\tend\n\t\tif @y + SUB_TILE_HEIGHT > @game_state.h... | [
"0.67354137",
"0.6292363",
"0.62778795",
"0.62744015",
"0.62700045",
"0.6262882",
"0.61338806",
"0.61217105",
"0.6086573",
"0.60591453",
"0.60400254",
"0.60179925",
"0.5917836",
"0.59105843",
"0.5884694",
"0.58763045",
"0.5857608",
"0.58433056",
"0.58242935",
"0.5818207",
"0.... | 0.6581896 | 1 |
Flush the property hash once done. | def flush
debug("[flush]")
if @property_hash.delete(:needs_change)
notice("Properties changed - updating rule")
update
end
@property_hash.clear
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def flush\n @property_hash.clear\n end",
"def flush\n @property_hash.clear\n end",
"def flush\n @property_hash.clear\n end",
"def flush\n flush_instance\n\n # Collect the resources again once they've been changed (that way `puppet\n # resource` will show the correct values after changes ... | [
"0.8413692",
"0.8413692",
"0.8413692",
"0.71584415",
"0.70628494",
"0.67690057",
"0.6648237",
"0.65687156",
"0.65156287",
"0.6180863",
"0.6067176",
"0.60429865",
"0.60282236",
"0.5885799",
"0.58702165",
"0.5868587",
"0.5849365",
"0.58389866",
"0.5838821",
"0.5763673",
"0.5754... | 0.74039364 | 3 |
randomly generates an image from template (random values are normally distributed with mean = characetristic , deviation = sigma) | def create_sample_image_from_template(image_template, sigma)
random_characteristics = image_template.ideal_characteristics.map do |val|
deviated = RandomGaussian.new(val, sigma).rand
deviated = 0.0 if deviated < 0
deviated = 1 if deviated > 1
deviated
end
# values = image_template.ideal_characteristics.each { |val| values << val + 5*rand(sigma) }
ImageSample.new(image_template.image_class, random_characteristics)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def generate\n MiniMagick::Tool::Convert.new do |i|\n i.font random_font\n i.size image_size\n i.pointsize config[:font_size]\n i.fill config[:font_color]\n i.gravity \"center\"\n i.canvas config[:background]\n i.draw \"text 0,0 '#{text... | [
"0.57630605",
"0.57064486",
"0.5657136",
"0.5654884",
"0.5636625",
"0.5624686",
"0.5582114",
"0.5519244",
"0.5509578",
"0.55075866",
"0.54679877",
"0.546257",
"0.54451126",
"0.5421123",
"0.53978896",
"0.53797156",
"0.5363218",
"0.5353453",
"0.5342196",
"0.53372324",
"0.533225... | 0.839465 | 0 |
pattern adjusted because removing the zeros from the front | def digit(i, input, pattern)
temp = input.dup
temp.shift(i-1) # this removes the first i-1 which will be multiplied by zero
result = temp.each_slice(i).each_with_index.map{|group,i| group.sum* pattern[ i % 4]}.sum.abs % 10
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def simplified_pattern\n pattern\n end",
"def simplified_pattern\n pattern\n end",
"def pattern\n @nz.map { |nz_cell| nz_cell[0..1] }\n end",
"def update_anime_pattern\n @pattern = (@pattern + 1) % 8# not need to calculate because char takes all the patterns % 4\n end",
... | [
"0.6137649",
"0.6137649",
"0.5982036",
"0.58614016",
"0.5802679",
"0.5708617",
"0.56372696",
"0.5508636",
"0.5459506",
"0.545827",
"0.5450568",
"0.54478693",
"0.54478693",
"0.5424999",
"0.53882015",
"0.5375077",
"0.5353378",
"0.53281593",
"0.5320903",
"0.53133154",
"0.5295863... | 0.485959 | 82 |
Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? | def problem3(num)
prime = num
while num%2==0 do num/=2 end
(3..Math.sqrt(num).to_i).step(2).each { |pf|
break if num < pf
while num%pf==0 do
num/=pf
prime = pf
end
}
prime
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def largest_prime_factor\n number = 600851475143\n n = 2\n while n < number\n if number % n == 0\n factor = number / n\n return factor if is_prime?(factor)\n end\n n += 1\n end\nend",
"def largestPrimeFactor\n\tn = 600851475143\n\tfactor = 2\n\tlastFactor = 1\n\n\twhile n > 1\n\t\tif n % f... | [
"0.8555166",
"0.844039",
"0.8025793",
"0.7937887",
"0.7920968",
"0.7901872",
"0.7878956",
"0.78620994",
"0.78613913",
"0.78487843",
"0.784481",
"0.78425133",
"0.7822209",
"0.7820768",
"0.7819627",
"0.77966636",
"0.77774906",
"0.77731633",
"0.77730536",
"0.77686644",
"0.776829... | 0.0 | -1 |
Restarts the SSH service | def ssh_service_restart
exec(Beaker::Command.new("stopsrc -g ssh"))
exec(Beaker::Command.new("startsrc -g ssh"))
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def ssh_service_restart\n case self['platform']\n when /debian|ubuntu|cumulus|huaweios/\n exec(Beaker::Command.new(\"service ssh restart\"))\n when /(el|centos|redhat|oracle|scientific)-[7-9]|eos-7|fedora-(1[4-9]|2[0-9]|3[0-9])|archlinux-/\n exec(Beaker::Command.new(\"systemctl restart sshd.serv... | [
"0.7639621",
"0.72693604",
"0.72511095",
"0.7150708",
"0.7125923",
"0.71143454",
"0.70740026",
"0.70478565",
"0.7003857",
"0.6952376",
"0.69177526",
"0.6909844",
"0.6908254",
"0.68483293",
"0.6836116",
"0.6815306",
"0.6783975",
"0.67428356",
"0.6728189",
"0.6716245",
"0.67110... | 0.8223676 | 0 |
Override in child class | def properties
{}
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def inherited(base); end",
"def overrides; end",
"def proxy\n super\n end",
"def special\n override\n end",
"def inherited(subclass); end",
"def super_method; end",
"def superclass() end",
"def inherited(klass); end",
"def inherited(klass); end",
"def tag; raise 'Override this method'... | [
"0.76180625",
"0.75793505",
"0.7573107",
"0.7354282",
"0.7263426",
"0.7262659",
"0.72217387",
"0.72018504",
"0.72018504",
"0.7142683",
"0.70852363",
"0.70852363",
"0.70607585",
"0.69983846",
"0.6961868",
"0.6924328",
"0.68898886",
"0.6792732",
"0.6756192",
"0.67481977",
"0.67... | 0.0 | -1 |
0, 1, 1, 2, 3, 5, 8... p fib(7) | def fib(n)
return nil if n < 1
return [0] if n == 1
return [0, 1] if n == 2
result = fib(n - 1)
result.push(result[-1] + result[-2])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fib (x)\n y = x-2\nfib_sequence = y.times.inject(%5B0,1%5D) do |a, idx|\n a << a[-2] + a[-1]\nend",
"def fib(n)\n n.times.each_with_object([0,1]) { |_, results| results << results[-2] + results[-1] }\nend",
"def fib(n)\n n.times.each_with_object([0,1]) { |num, obj| obj << obj[-2]+obj[-1]}\nend",
... | [
"0.82837903",
"0.8271113",
"0.8182883",
"0.8158846",
"0.8139834",
"0.8118301",
"0.8103211",
"0.8073873",
"0.8012003",
"0.8005307",
"0.79900986",
"0.7981789",
"0.7980134",
"0.7980134",
"0.7980134",
"0.7980134",
"0.7980134",
"0.79609305",
"0.7926039",
"0.792596",
"0.79142034",
... | 0.0 | -1 |
The maximum slack_before such that there is no collision with (the slack of) another reservation before the begins_at time This value could be negative, indicating that the begins_at value always collides with (the slack of) another reservation | def max_slack_before(begins_at)
previous_reservation = Reservation.new(entity: self, begins_at: begins_at).previous
(begins_at - previous_reservation.ends_at - previous_reservation.slack_after.minutes) / 1.minute if previous_reservation.present?
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def max_slack_after(ends_at)\n next_reservation = Reservation.new(entity: self, ends_at: ends_at).next\n (next_reservation.begins_at - next_reservation.slack_before.minutes - ends_at) / 1.minute if next_reservation.present?\n end",
"def prev_max() self.scheduling.prev_max end",
"... | [
"0.6944257",
"0.5714198",
"0.5533224",
"0.5465341",
"0.5334713",
"0.530633",
"0.5301486",
"0.52935106",
"0.5217383",
"0.5196414",
"0.5178257",
"0.51396817",
"0.51160175",
"0.5105772",
"0.5103186",
"0.50833255",
"0.5077038",
"0.50707185",
"0.506407",
"0.50526756",
"0.5044178",... | 0.79211324 | 0 |
The maximum slack_after such that there is no collision with (the slack of) another reservation after the ends_at time This value could be negative, indicating that the ends_at value always collides with (the slack of) another reservation | def max_slack_after(ends_at)
next_reservation = Reservation.new(entity: self, ends_at: ends_at).next
(next_reservation.begins_at - next_reservation.slack_before.minutes - ends_at) / 1.minute if next_reservation.present?
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def max_slack_before(begins_at)\n previous_reservation = Reservation.new(entity: self, begins_at: begins_at).previous\n (begins_at - previous_reservation.ends_at - previous_reservation.slack_after.minutes) / 1.minute if previous_reservation.present?\n end",
"def down_boundary\n Time.new - down_interv... | [
"0.677644",
"0.5843807",
"0.57572776",
"0.5753104",
"0.57078505",
"0.56829065",
"0.5681175",
"0.5587056",
"0.541402",
"0.5399369",
"0.5351964",
"0.5346725",
"0.53122896",
"0.5284753",
"0.5260341",
"0.52282315",
"0.5228178",
"0.5179661",
"0.51731735",
"0.51653385",
"0.51583165... | 0.7936712 | 0 |
Set property values by an list/array (matching array index on property index) or hash (matching hash key on property name or index depending on key type) | def set_properties(*values)
if values.size == 1 && values.first.is_a?(Hash)
# We are dealing with a hash
values.first.each do |key, index|
self.set_property(key, value)
end
else
# We are dealing with a list/array
values.flatten.each_with_index do |value, index|
self.set_property(index, value)
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def []=(property, value); end",
"def []=(key, value)\n k = key.to_s\n if value.nil?\n remove_property(k)\n elsif (Array === value)\n case value[0]\n when NilClass\n set_property(k, [].to_java(:string))\n when String\n set_property(k, value.to_j... | [
"0.63857895",
"0.6379823",
"0.6344935",
"0.62090087",
"0.6051336",
"0.59849536",
"0.59822863",
"0.59011275",
"0.58627415",
"0.5824263",
"0.58038026",
"0.5799478",
"0.5796597",
"0.579442",
"0.5773002",
"0.57089293",
"0.57089293",
"0.56992245",
"0.5680076",
"0.5680076",
"0.5680... | 0.7385258 | 0 |
def before_create_save(record) if ! current_user.data_entry_only record.approved = 0 end end | def add_dynamic_columns
organism = Organism.find(:first, :conditions => ["project_id = ?", current_project_id])
c = active_scaffold_config
for cp in [c.list, c.update, c.create, c]
columns_for_deletion = (cp.columns.map(&:name).map(&:to_sym) - Organism.columns.map(&:name).map(&:to_sym))
cp.columns.exclude *columns_for_deletion
if organism
dynamic_columns ||= organism.dynamic_attributes.map(&:name)
cp.columns.add dynamic_columns
end
end
true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def save\n self.approved = true\n super\n end",
"def set_approved\n if not self.approved # don't want to run with seed file\n self.approved = false\n end\n end",
"def approve!\n self.approved = true\n self.save\n end",
"def approve_setup_fee_collection( current_user )\n ... | [
"0.75614184",
"0.68679637",
"0.66747713",
"0.66095054",
"0.6549236",
"0.65282166",
"0.64734954",
"0.64690673",
"0.64510965",
"0.6448938",
"0.6432727",
"0.6431113",
"0.63685566",
"0.6328542",
"0.63144296",
"0.62947196",
"0.6260362",
"0.62288254",
"0.62211394",
"0.62189066",
"0... | 0.0 | -1 |
TO: tenants, reservers, searchers | def tenant_notification(tenant)
@header_img_name = 'rental_confirm'
setup_email tenant.email, 'USSelfStorageLocator.com <info@usselfstoragelocator.com>', "Your #{tenant.listing.storage_type.try(:titleize) || 'Self Storage'} Rental"
@body[:tenant] = tenant
@body[:rental] = tenant.rental
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @consultant_customer_destinations = ConsultantCustomerDestination.all\n end",
"def index\n @user = current_user\n @destinations = Destination.search(params[:search])\n end",
"def index\n @license_tos = LicenseTo.all\n end",
"def index\n if current_user.user_type_id == 1 #SUPER U... | [
"0.57205874",
"0.559882",
"0.55944085",
"0.55601573",
"0.55466485",
"0.55219793",
"0.5500766",
"0.5480267",
"0.54621303",
"0.5458389",
"0.5401559",
"0.5373629",
"0.5370903",
"0.5336728",
"0.5313613",
"0.5306105",
"0.52884793",
"0.5270205",
"0.52602905",
"0.52560216",
"0.52451... | 0.0 | -1 |
Returns an array 'board' of rows Each row is an array with randomly assigned values from 'colours' array | def get_board(width, height)
# Create a new 2D array
board = Array.new($board_height) {Array.new($board_width)}
# Each element will be assigned a random value from 'colours'
# That is done by choosing a random index of the 'colours' array
(0...$board_height).each do |row|
(0...$board_width).each do |cell|
board[row][cell] = $colours[rand(6)]
end
end
# Return board
return board
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_board(width, height)\n #array with all possible colors\n colors = [:red, :blue, :green, :yellow, :cyan, :magenta]\n\n board = Array.new(height)\n (0..height-1).each do |i|\n board[i] = Array.new(width)\n (0..width-1).each do |j|\n board[i][j] = colors.sample\n end\n end\n\n return board... | [
"0.7755951",
"0.77496403",
"0.76519626",
"0.7622318",
"0.7169492",
"0.696025",
"0.68786216",
"0.667716",
"0.65812236",
"0.65675664",
"0.65639997",
"0.64597964",
"0.64535964",
"0.64436233",
"0.6436676",
"0.6432895",
"0.6426898",
"0.6418176",
"0.6403544",
"0.63710356",
"0.63389... | 0.8066209 | 0 |
update_board method used to update the board after the user choose a new colours First the top left field is updated to the new colour For each neighbour field that has the same colour as the first field had before changing it, recursively update that field as well | def update_board(board,new_colour,old_colour,i,j)
# Update field colour
board[i][j]= new_colour
# Check if there is a neighbour on top and if that neighbour has the same colour as the previous colour
# If yes, then that neighbour is chosen to be updated in turn
if (i-1) >=0 && board[i-1][j] == old_colour
board = update_board(board,new_colour,old_colour,i-1,j)
end
# Check if there is a neighbour on the right and if that neighbour has the same colour as the previous colour
# If yes, then that neighbour is chosen to be updated in turn
if (j+1) < $board_width && board[i][j+1] == old_colour
board = update_board(board,new_colour,old_colour,i,j+1)
end
# Check if there is a neighbour on the buttom and if that neighbour has the same colour as the previous colour
# If yes, then that neighbour is chosen to be updated in turn
if (i+1) <$board_height && board[i+1][j] == old_colour
board = update_board(board,new_colour,old_colour,i+1,j)
end
# Check if there is a neighbour on the left and if that neighbour has the same colour as the previous colour
# If yes, then that neighbour is chosen to be updated in turn
if (j-1) >=0 && board[i][j-1] == old_colour
board = update_board(board,new_colour,old_colour,i,j-1)
end
# return board
return board
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def neighbour_update(board,width,height,next_colour,i,j,count,first_block,finished_game_counter,current_score)\n \n #if condition checking if field at i,j has the same colour as the top-left field\n if board[i][j] == first_block\n \n #checks if it is the correct element and changes its colour, (c == j ?) ... | [
"0.7696163",
"0.7116067",
"0.7082177",
"0.7061606",
"0.6974447",
"0.69378155",
"0.6806526",
"0.65437865",
"0.65291166",
"0.64986086",
"0.64369404",
"0.63301635",
"0.629596",
"0.6283609",
"0.6259597",
"0.6253917",
"0.62289274",
"0.6198834",
"0.6178496",
"0.61703223",
"0.612284... | 0.8346162 | 0 |
Method used to display the menu | def display_menu
# print the options
puts "Main menu:"
puts "s = Start game"
puts "c = Change size"
puts "q = Quit"
# print the best score
# if there is no best score yet a message is displayed instead
if $best_score == 0
puts "No games played yet"
else
puts "Best game: #{$best_score} turns"
end
# Then ask for input for one of the options
print "Please enter your choice: "
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show # Show method\n menu # Show menu method above\n end",
"def displaymenu # Console only\r\n\t\t @output.puts \"Menu: (1) Play | (2) New | (3) Analysis | (9) Exit\"\r\n\t\t end",
"def menu\n \n \n\nend",
"def menu\n \nend",
"def list_menu\n puts \"\\nMain Menu\"\n ... | [
"0.7839964",
"0.7779688",
"0.7712035",
"0.7701799",
"0.76952076",
"0.76749206",
"0.7627202",
"0.74744934",
"0.7403855",
"0.74017036",
"0.7373082",
"0.7348887",
"0.7304579",
"0.72313625",
"0.7227436",
"0.71691966",
"0.71471554",
"0.7143775",
"0.7114401",
"0.708735",
"0.7065980... | 0.0 | -1 |
Method used to find the option selected by the user in main menu | def get_choice input
if input == "s"
# clear the screen
system "clear"
# start game
start_game
elsif input == "c"
change_size
elsif input == "q"
# terminate the program
exit
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def select_option\n print_menu\n @choice = gets.chomp\n perform_selection\n end",
"def selected\r\n assert_exists\r\n #@option.selected\r\n option_selected\r\n end",
"def menu_selection \nend",
"def object_value_of_selected_item\n if @options_menu.nil?\n ... | [
"0.6969514",
"0.69674706",
"0.6882983",
"0.683777",
"0.6820131",
"0.6818304",
"0.6800789",
"0.6790584",
"0.6784321",
"0.6749808",
"0.6729305",
"0.6708531",
"0.668289",
"0.6673356",
"0.6627128",
"0.66109484",
"0.6586145",
"0.6578587",
"0.6479397",
"0.64680403",
"0.6424982",
... | 0.0 | -1 |
Method used to calculate the completion of the game Count all the blocks the have the same colour as the topleft corner The completion is then calculated by diving the counter by the total number of blocks 100 The result is then converted to an integer | def get_progress(board)
counter = 0
total = $board_width * $board_height
board.each do |row|
row.each do |cell|
if cell == board[0][0]
counter+=1
end
end
end
return (counter/total.to_f * 100).to_i
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def completion(boardGame, oldColor)\n count = 0.0;\n (0..boardGame.length - 1).each do |i|\n (0..boardGame[i].length - 1).each do |j|\n if boardGame[i][j] == oldColor then\n count += 1\n end\n end \n end\n return ((count/(boardGame.length*boardGame[0].length))*100.0).floor\nend",
"def... | [
"0.71532583",
"0.7041949",
"0.64696425",
"0.6386704",
"0.6215267",
"0.618034",
"0.61584073",
"0.60580087",
"0.60290825",
"0.59197974",
"0.58793455",
"0.5822503",
"0.5808183",
"0.57963943",
"0.5786179",
"0.5769555",
"0.5712118",
"0.5695716",
"0.56662923",
"0.566162",
"0.565554... | 0.6809332 | 2 |
Method used to return the colour given by the user | def get_colour
colour = gets.chomp.downcase
if colour =="q" then
colour = "q"
elsif colour == "r"
colour = :red
elsif colour == "b"
colour = :blue
elsif colour == "g"
colour = :green
elsif colour == "y"
colour = :yellow
elsif colour == "c"
colour = :cyan
elsif colour == "m"
colour = :magenta
else
# if the input is none of the above colours or 'q'
# then the input must be invalid
colour = "invalid"
end
# return colour
return colour
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def getColor(c)\n if c == \"r\" then return :red\n elsif c == \"b\" then return :blue\n elsif c == \"g\" then return :green\n elsif c == \"y\" then return :yellow\n elsif c == \"c\" then return :cyan\n elsif c == \"m\" then return :magenta\n end\nend",
"def get_color\n @color\n end",
"def color\... | [
"0.7778326",
"0.75625",
"0.7505634",
"0.7385949",
"0.7374629",
"0.7374629",
"0.7343969",
"0.72700876",
"0.72700876",
"0.72321415",
"0.721719",
"0.72035575",
"0.716802",
"0.7166885",
"0.71456116",
"0.7118985",
"0.70945656",
"0.7090077",
"0.7090077",
"0.7090077",
"0.70468515",
... | 0.7542151 | 2 |
Method used to display the board on the screen | def display_board(board,number_of_turns,progress)
board.each do |row|
row.each do |cell|
# Each element of the board contains 2 space characters
# 'colorize' gem is used to print coloured text
# and 'cell' contains the colour which to be used
print " ".colorize(:background=>cell)
end
puts ""
end
# Show the number of turns and completion
puts "Current number of turns: #{number_of_turns}"
puts "Current completion: #{progress}%"
# Ask the user to input the colour as long as the game is not finished
if progress < 100
print "Choose a colour: "
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def display_board\n puts \" #{@board[0]} | #{@board[1]} | #{@board[2]} \"\n puts \"-----------\"\n puts \" #{@board[3]} | #{@board[4]} | #{@board[5]} \"\n puts \"-----------\"\n puts \" #{@board[6]} | #{@board[7]} | #{@board[8]} \"\n end",
"def display_board\n puts \" #{@board[... | [
"0.82833374",
"0.8256956",
"0.8243903",
"0.8239019",
"0.8234275",
"0.8234275",
"0.82334036",
"0.82197326",
"0.8208226",
"0.81796664",
"0.8175248",
"0.8175248",
"0.8108998",
"0.8099377",
"0.80955386",
"0.80955386",
"0.80955386",
"0.80955386",
"0.80955386",
"0.80955386",
"0.809... | 0.0 | -1 |
Method used to change the size of the board | def change_size()
print "Width (Currently #{$board_width})? "
# Validate the input
# If the user input is invalid, the user will be asked to try again
valid = false
until valid == true do
input = gets.chomp
if input.to_i.to_s == input then
$board_width = input.to_i
valid = true
else
puts "Input is not an integer! Try again: "
end
end
print "Height (Currently #{$board_height})? "
# Validate the input
# If the user input is invalid, the user will be asked to try again
valid = false
until valid == true do
input = gets.chomp
if input.to_i.to_s == input then
$board_height = input.to_i
valid = true
else
puts "Input is not an integer! Try again: "
end
end
# The best score is reset when the board size is changed
$best_score = 0
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def board_size\n\t\t@board.size\n\tend",
"def size \n\n\t\t# Set the basic metrics\n\t\tcase @board_size\n\t\twhen :small \t\t\t\t# A 20x20 grid\n\t\t\t@width = 30\n\t\t\t@height = 20\n\t\t\t@dragon_count = 50 * @board_level\n\t\t\t@cell_size = 30\n\t\t\t@cover_png = 'sprites/cover_30.png'\n\t\t\t@dragon_png = '... | [
"0.7331184",
"0.714792",
"0.6797675",
"0.67375064",
"0.663364",
"0.6601978",
"0.655269",
"0.65476507",
"0.65396357",
"0.6520203",
"0.6486752",
"0.64289594",
"0.6415148",
"0.639494",
"0.6390217",
"0.63797843",
"0.6369863",
"0.63569635",
"0.6338497",
"0.63159657",
"0.62864286",... | 0.6025228 | 44 |
Method used to create the splash screen | def start_splash
# Clear the console
puts "\e[H\e[2J"
# Create a new splash object
splash = ConsoleSplash.new(13, 40) # 13 lines, 40 columns
# Add header to the splash console
splash.write_header("Welcome to Flood-It", "Georgica Bors", "1.0")
# Add text to the splash console
splash.write_center(-3, "<Press enter to continue>")
# Select the pattern of the border of the splash screen
splash.write_horizontal_pattern("*")
splash.write_vertical_pattern("*")
# Draw the splash screen
splash.splash
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def splash_page\n end",
"def makeSplash\n clearScreen\n splash = ConsoleSplash.new(15,70)\n splash.write_header(\"Welcome to Sokoban\",\"Ben Cornforth\",\"Alpha Build, November 2015\",{:nameFg=>:green,:authorFg=>:green, :versionFg=>:green, :bg=>:black})\n splash.write_horizontal_pattern(\"/*\",{:fg=>:white,... | [
"0.7778994",
"0.7694187",
"0.7559071",
"0.7246392",
"0.7219365",
"0.70114976",
"0.6934593",
"0.67861134",
"0.65907055",
"0.6573216",
"0.6390458",
"0.6226434",
"0.6164103",
"0.6083253",
"0.60094047",
"0.6004784",
"0.5908802",
"0.59075403",
"0.5855139",
"0.58454245",
"0.5845424... | 0.7462053 | 3 |
Write a method(s) that takes a real name and outputs a fake name. First and last name is swapped first, change each vowel (aeiou) to the next vowel, and then all of the constanants to the next constanant in the alphabet. 'a' would be come 'e' 'u' would become 'a' 'd' would become 'f' example: mickey mouse ==> mouse mickey ==> muasi mockiy ==> nuati nodliz BUSINESS LOGIC | def change_char(char)
vowels = ["a", "e", "i", "o", "u"]
constanants = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"]
alphabet = 'abcdefghijklmnopqrstuvwxyz'
index_of_char = alphabet.index(char) # check for any non-alphabet characters
is_vowel = vowels.index(char) # check any vowels
is_constanant = constanants.index(char) # check for any constanants
if index_of_char == nil
char
# letter is not in alphabet, returns same character
elsif is_vowel
vowels.rotate(1)[vowels.index(char)]
# if letter is a vowel, returns next vowel
elsif is_constanant
constanants.rotate(1)[constanants.index(char)]
# if letter is a constanant, returns next constanant
else
char
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def make_fake_name (name)\n\t# Swap first & last name\n\tswap_name = name.split(' ').reverse.join(' ')\n\n\t# Swap characters - change all vowels to next vowel,\n\t# and all consonants to next consonant\n\n\t# Initialize fake_name & index (counter) variables \n\tfake_name = ''\n\tindex = 0\n\twhile index < swap_na... | [
"0.85889745",
"0.8385649",
"0.8339667",
"0.8332656",
"0.82483995",
"0.8244456",
"0.82370883",
"0.8107916",
"0.7957297",
"0.7950305",
"0.7928797",
"0.7904246",
"0.7896411",
"0.78897744",
"0.7872509",
"0.7835217",
"0.7814281",
"0.78140986",
"0.77419764",
"0.77310944",
"0.771591... | 0.0 | -1 |
does it return 'true' | def test_true
assert_equal(true, winning_numbers(4,[1,2,3,4]))
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def success?() end",
"def result?\n true\n end",
"def check ; true ; end",
"def test?\n false\n end",
"def success?\n return true\n end",
"def result?\n false\n end",
"def test?\n true\n end",
"def success?(*) end",
"def success?\n got.eq... | [
"0.74962187",
"0.7423751",
"0.7372601",
"0.73342854",
"0.7276631",
"0.7243044",
"0.72150457",
"0.70859176",
"0.70450646",
"0.69838965",
"0.69821954",
"0.6960472",
"0.695637",
"0.6946914",
"0.6946914",
"0.6932129",
"0.6924612",
"0.6914291",
"0.69130504",
"0.69049275",
"0.68903... | 0.0 | -1 |
def select_category_from_projects "SELECT category FROM projects;" end Make sure each ruby method returns a string containing a valid SQL statement. | def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabetized_by_name
"SELECT projects.title, sum(pledges.amount) FROM projects INNER JOIN pledges on pledges.project_id=projects.id group by pledges.project_id ORDER BY projects.title ASC"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def select_category_from_projects\n\"SELECT category FROM projects;\"\nend",
"def selects_the_category_names_and_pledge_amounts_of_all_pledges_in_the_music_category\n\"SELECT projects.category, pledges.amount\nFROM pledges\nINNER JOIN projects\nON projects.id = pledges.project_id\nWHERE projects.category = 'musi... | [
"0.9198005",
"0.7067772",
"0.69905335",
"0.66503316",
"0.66215897",
"0.65129244",
"0.6485903",
"0.6323661",
"0.6060154",
"0.59388006",
"0.59372574",
"0.59352744",
"0.5899834",
"0.58821833",
"0.58694905",
"0.58531743",
"0.5852905",
"0.58394325",
"0.5818256",
"0.5783734",
"0.57... | 0.53057444 | 83 |
GET /bingos or /bingos.json | def index
@bingos = Bingo.all
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_brandings\n request :get, \"/v3/brandings.json\"\n end",
"def index\n @brags = Brag.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @brags }\n end\n end",
"def list_active_aos_versions(args = {}) \n get(\"/aosversions.json/\", arg... | [
"0.6548724",
"0.6278269",
"0.6238488",
"0.61362135",
"0.6104914",
"0.6090801",
"0.6024141",
"0.59705967",
"0.5969265",
"0.59434414",
"0.5928445",
"0.58192694",
"0.57806283",
"0.57772",
"0.5764335",
"0.5763125",
"0.57601833",
"0.575247",
"0.5748528",
"0.5716802",
"0.57164854",... | 0.5804119 | 12 |
GET /bingos/1 or /bingos/1.json | def show
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def list_active_aos_versions(args = {}) \n get(\"/aosversions.json/\", args)\nend",
"def get_aos_version_box_by_name(args = {}) \n get(\"/aosversions.json/aosversionbox/name/#{args[:aosVersionBoxName]}\", args)\nend",
"def get_brandings\n request :get, \"/v3/brandings.json\"\n end",
"def get_aos_ve... | [
"0.6444401",
"0.6403265",
"0.6371681",
"0.6245945",
"0.6212942",
"0.62011105",
"0.61603516",
"0.6127232",
"0.61207837",
"0.6028157",
"0.59965247",
"0.5916836",
"0.5856851",
"0.58536226",
"0.5846458",
"0.58419615",
"0.5839283",
"0.58358264",
"0.5835792",
"0.5830779",
"0.581747... | 0.0 | -1 |
POST /bingos or /bingos.json | def create
@bingo = Bingo.new(bingo_params)
respond_to do |format|
if @bingo.save
format.html { redirect_to @bingo, notice: "Bingo was successfully created." }
format.json { render :show, status: :created, location: @bingo }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @bingo.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create(bin_params)\n @rest.post('save', bin_params)\n end",
"def api_gateway_post(path, params)\n api_gateway_body_fwd = params.to_json\n rack_input = StringIO.new(api_gateway_body_fwd)\n\n post path, real_params = {}, 'rack.input' => rack_input\nend",
"def post(path, data = {})\n request 'POST... | [
"0.60138226",
"0.59686786",
"0.5959125",
"0.59083915",
"0.5904262",
"0.5836802",
"0.5806822",
"0.5793631",
"0.5792562",
"0.57917786",
"0.5762452",
"0.57120883",
"0.5661779",
"0.5615058",
"0.55956227",
"0.5592449",
"0.55892354",
"0.55570793",
"0.5538656",
"0.55330443",
"0.5530... | 0.6080252 | 0 |
PATCH/PUT /bingos/1 or /bingos/1.json | def update
respond_to do |format|
if @bingo.update(bingo_params)
format.html { redirect_to @bingo, notice: "Bingo was successfully updated." }
format.json { render :show, status: :ok, location: @bingo }
else
format.html { render :edit, status: :unprocessable_entity }
format.json { render json: @bingo.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n if @boat.update(boat_params)\n head :no_content\n else\n render json: @boat.errors, status: :unprocessable_entity\n end\n end",
"def update\n @bingo = Bingo.find(params[:id])\n\n respond_to do |format|\n if @bingo.update_attributes(params[:bingo])\n format.html ... | [
"0.63641137",
"0.61937726",
"0.6184194",
"0.61706156",
"0.60791093",
"0.60707104",
"0.6046116",
"0.60317063",
"0.6023285",
"0.6017018",
"0.60140634",
"0.6006524",
"0.6001912",
"0.5988944",
"0.5987002",
"0.5956738",
"0.5949767",
"0.59442556",
"0.5937486",
"0.59274864",
"0.5908... | 0.6497161 | 0 |
DELETE /bingos/1 or /bingos/1.json | def destroy
@bingo.destroy
respond_to do |format|
format.html { redirect_to bingos_url, notice: "Bingo was successfully destroyed." }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_aos_version(args = {}) \n delete(\"/aosversions.json/#{args[:aosVersionId]}\", args)\nend",
"def delete()\n @api.do_request(\"DELETE\", get_base_api_path())\n end",
"def delete()\n @api.do_request(\"DELETE\", get_base_api_path())\n end",
"def delete()\n @api.do_request(\... | [
"0.7174855",
"0.6819275",
"0.6819275",
"0.6819275",
"0.6819275",
"0.6779041",
"0.67647356",
"0.6686858",
"0.6672149",
"0.66356415",
"0.65998554",
"0.6573875",
"0.65631115",
"0.65615565",
"0.6554658",
"0.6531609",
"0.6522462",
"0.6522462",
"0.6522094",
"0.65001297",
"0.6486295... | 0.65921074 | 11 |
Use callbacks to share common setup or constraints between actions. | def set_bingo
@bingo = Bingo.find(params[:id])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_required_actions\n # TODO: check what fields change to asign required fields\n end",
"def action_hook; end",
"def run_actions; end",
"def define_action_hook; end",
"def actions; end",
"def define_action_helpers\n if super && action == :save\n @instance_helper_module.class_... | [
"0.6165152",
"0.60463154",
"0.59467196",
"0.5917112",
"0.5890387",
"0.58345735",
"0.57773316",
"0.56991524",
"0.56991524",
"0.565454",
"0.5622282",
"0.54232633",
"0.54119074",
"0.54119074",
"0.54119074",
"0.53937256",
"0.53801376",
"0.5358599",
"0.53412294",
"0.5340814",
"0.5... | 0.0 | -1 |
Only allow a list of trusted parameters through. | def bingo_params
params.fetch(:bingo, {})
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def allowed_params\n ALLOWED_PARAMS\n end",
"def strong_params\n params.require(:listing_member).permit(param_whitelist)\n end",
"def parameters_list_params\n params.require(:parameters_list).permit(:name, :description, :is_user_specific)\n end",
"def param_whitelist\n [:role, :title]\... | [
"0.69497335",
"0.6812623",
"0.6803639",
"0.6795365",
"0.67448795",
"0.67399913",
"0.6526815",
"0.6518771",
"0.64931697",
"0.6430388",
"0.6430388",
"0.6430388",
"0.63983387",
"0.6356042",
"0.63535863",
"0.63464934",
"0.63444513",
"0.6337208",
"0.6326454",
"0.6326454",
"0.63264... | 0.0 | -1 |
Get the object with the given name. | def get(name, &constructor)
hashed[name] || if constructor
obj = constructor.call(name)
add(obj)
obj
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def find name\n object = objects.find { |o| o.name == name.to_s }\n end",
"def find_object(name); end",
"def find_obj_for_name(name)\n idx = @field_names.index(name)\n if idx\n instantiate_obj(idx)\n @field_objs[idx].obj\n else\n nil\n end\n end",
"def ... | [
"0.82078433",
"0.7963105",
"0.7895797",
"0.7325606",
"0.7305935",
"0.7161962",
"0.71344703",
"0.70946926",
"0.70404834",
"0.6965126",
"0.6944315",
"0.6825027",
"0.67925805",
"0.67812896",
"0.673814",
"0.67343986",
"0.6720087",
"0.67141956",
"0.66879404",
"0.66870683",
"0.6642... | 0.60384387 | 72 |
The index as a sorted list. All Enumerable methods act on this list. | def list
@list ||= []
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def sort_index\n pos = nil\n pos ||= self.position if self.respond_to?(:position)\n [pos || 9999, self.id]\n end",
"def sort_index\n self.index || 0\n end",
"def zindexed\n all.sort_by(&:zindex)\n end",
"def sorted_indices\n return method_missing(:sorted_indices) unless vect... | [
"0.7057693",
"0.6644014",
"0.64960253",
"0.63106245",
"0.62940466",
"0.6220144",
"0.61537105",
"0.6112791",
"0.6035116",
"0.6032387",
"0.6009315",
"0.595714",
"0.5952997",
"0.59483504",
"0.59429246",
"0.5929319",
"0.5913949",
"0.5910413",
"0.58835936",
"0.58468324",
"0.581704... | 0.0 | -1 |
Clear all the elements of this index | def clear
hashed.clear
list.clear
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def clear_index\n @index = nil\n end",
"def clear\n @hash.del\n @index.del\n end",
"def clear\n @values.clear\n end",
"def clear\n @store.fill(nil,0...@size)\n end",
"def clear\n @field.each_index { |i| @field[i] = 0 }\n end",
"def clear\n @a... | [
"0.7990437",
"0.7962762",
"0.7558882",
"0.75502926",
"0.75215465",
"0.7488922",
"0.7482482",
"0.7476773",
"0.7476773",
"0.7474873",
"0.7455337",
"0.74487585",
"0.73992544",
"0.73864233",
"0.735399",
"0.7347851",
"0.7338201",
"0.7338201",
"0.7321778",
"0.7310709",
"0.730543",
... | 0.682065 | 77 |
The size of the index | def size
list.size
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def size\n index.size\n end",
"def size\n index.size\n end",
"def size\n @index.size\n end",
"def size\n @index.size\n end",
"def size\n @index.keys.uniq.count\n end",
"def size()\n #This is a stub, used for indexing\n end",
"def size()\... | [
"0.9004925",
"0.9004925",
"0.8971291",
"0.8921261",
"0.8371172",
"0.8232891",
"0.8232891",
"0.81063324",
"0.80845815",
"0.78683794",
"0.78486717",
"0.77066845",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265",
"0.7670265"... | 0.0 | -1 |
Test inclusion, given an object. | def include?(el)
list.include?(el)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def assert_include collection, obj, msg = nil\n assert_respond_to collection, :include?\n\n message ||= \"#{collection.inspect}\\ndoes not include\\n#{obj.inspect}.\"\n assert_block message do collection.include?(obj) end\n end",
"def assert_include(collection, object, message=nil)\n _wr... | [
"0.70792687",
"0.68800586",
"0.67808855",
"0.66712016",
"0.66225934",
"0.6603678",
"0.65995663",
"0.6597239",
"0.6597239",
"0.64808583",
"0.6416508",
"0.63551056",
"0.63488597",
"0.6271307",
"0.6248458",
"0.6222926",
"0.6210622",
"0.62017757",
"0.6195194",
"0.6175727",
"0.617... | 0.0 | -1 |
Test inclusion, given a key | def has_key?(name)
hashed.has_key? name
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def include?(key); end",
"def include?(key); end",
"def include_key?(key)\n\t\t\ttrue\n\t\tend",
"def include?(key)\n has_key?(key)\n end",
"def include?(key)\n Options.check_valid_key(key)\n @data.include?(key.to_sym)\n end",
"def include?(key)\n # Ensure a Ruby true is ret... | [
"0.819327",
"0.819327",
"0.80304337",
"0.7812022",
"0.7755964",
"0.75676215",
"0.754065",
"0.754065",
"0.7508924",
"0.74936813",
"0.74640435",
"0.7443972",
"0.73460233",
"0.7286211",
"0.71615535",
"0.7156305",
"0.71237874",
"0.710555",
"0.710555",
"0.7105036",
"0.7067437",
... | 0.0 | -1 |
Add an object to the index. | def add(obj)
return self if self.has_key? name_of(obj)
hook_wrap :add, obj do
begin
name = name_of(obj)
insert_sorted(obj)
hashed[name] = obj
obj
rescue Exception => e
delete(name)
raise e
end
end
self
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index(object)\n push(new_entry_for_object(object))\n end",
"def add_object(object, objectID = nil, request_options = {})\n check_object(object)\n if objectID.nil? || objectID.to_s.empty?\n client.post(Protocol.index_uri(name), object.to_json, :write, request_options)\n else\... | [
"0.7751373",
"0.73306346",
"0.70778215",
"0.70624447",
"0.6873763",
"0.6865473",
"0.6857407",
"0.6839746",
"0.68336",
"0.6792281",
"0.6666518",
"0.6590304",
"0.65871",
"0.6554562",
"0.65218407",
"0.6465241",
"0.643733",
"0.6417968",
"0.64040816",
"0.6394342",
"0.63657916",
... | 0.67861485 | 10 |
use this on an object if its name_key changes. also pass in an optional condition of whether to add it back in at all. | def update_membership(obj, &filter)
remove(obj)
add(obj) if !filter || filter.call(obj)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_name\n self.update(name: \"Large Washer ##{self.id}\") unless self.name\n end",
"def change_item_name(new_name:, **)\n self.name = new_name # This will generate the event!\n end",
"def set_name\n self.update(name: \"Medium Washer ##{self.id}\") unless self.name\n end",
"def name=(str); di... | [
"0.58451056",
"0.5655675",
"0.56235176",
"0.5548807",
"0.55246174",
"0.5492181",
"0.5488547",
"0.54154384",
"0.5407909",
"0.54022133",
"0.53728545",
"0.5352485",
"0.5331546",
"0.5311049",
"0.5290392",
"0.528614",
"0.52859455",
"0.52735215",
"0.5268705",
"0.5265434",
"0.526543... | 0.0 | -1 |
removes an object by pointer. works even if the name has changed | def remove(obj)
hashed.each do |k,v|
hashed.delete(k) if v == obj
end
list.reject! { |el| el == obj }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete(o); removeObject o end",
"def delete(obj) ; end",
"def remove!\n zombie_check\n self.class.remove(@name)\n end",
"def delete(name); end",
"def delete(name); end",
"def delete(object); end",
"def remove_from(type, name)\n\n #Find if the object exists\n index = searc... | [
"0.76384354",
"0.7224725",
"0.7088",
"0.7037573",
"0.7037573",
"0.6959646",
"0.69035685",
"0.6873145",
"0.67518795",
"0.6738451",
"0.6647451",
"0.6647451",
"0.6647451",
"0.6647451",
"0.6643777",
"0.66262174",
"0.6613068",
"0.66075796",
"0.6552178",
"0.65274876",
"0.6516173",
... | 0.0 | -1 |
Perform a task on every object in the index, and on every object that will be added. | def always(&blk)
each(&blk)
hook(:add, &blk)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_all\n helper.index_write do |index|\n index.add_all\n index.update_all\n end\n\n self\n end",
"def process tweet, *_\n @aggregator << tweet.to_hash\n if @aggregator.size == options.buffered_docs\n response = @indexer.index_array(@aggregator)\n raise \"Your motherfuckin... | [
"0.637425",
"0.6295339",
"0.6145428",
"0.6056693",
"0.5921263",
"0.5916757",
"0.59163386",
"0.58987886",
"0.583899",
"0.5810647",
"0.57923144",
"0.57892627",
"0.5765518",
"0.57614255",
"0.57206905",
"0.5717567",
"0.57149637",
"0.57055455",
"0.57003844",
"0.56529224",
"0.56334... | 0.0 | -1 |
TODO: binary search, but let's not preoptimize | def insert_sorted(obj)
raise IndexError, <<-msg.squish if include? obj
Tried to insert #{obj.inspect} into #{self.inspect},
which is a duplicate of #{self[name_of(obj)].inspect}.
msg
name = name_of(obj)
inserted = false
list.each_with_index do |e, i|
if name_of(e) > name
list.insert i, obj
inserted = true
break
end
end
list << obj unless inserted
list
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def binary_search(ary, value); end",
"def binsearch(ary, x)\n left = 0\n right = ary.length - 1\n while left < right\n middle = (left + right) / 2\n Tanj.array :ary, index: [:left..:right, :middle]\n if ary[middle] == x\n Tanj.message \"found it!\"\n return middle\n elsif ary[middle] < x... | [
"0.7601672",
"0.7488068",
"0.7453648",
"0.7381466",
"0.7360346",
"0.7343364",
"0.73351985",
"0.7304209",
"0.7291085",
"0.7281542",
"0.7275073",
"0.72715867",
"0.72685564",
"0.7256332",
"0.72517395",
"0.7227592",
"0.7223801",
"0.7218236",
"0.7212643",
"0.7205586",
"0.7197354",... | 0.0 | -1 |
Return bool indicating if spec file satisfies any file in gem | def has_file_satisfied_by?(spec_file)
file_paths.any? { |gem_file| RPM::Spec.file_satisfies?(spec_file, gem_file) }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def has_file_satisfied_by?(spec_file)\n file_paths.any? { |gem_file| RPM::Spec.file_satisfies?(spec_file, gem_file) }\n end",
"def gemspec?\n !gemspecs.empty?\n end",
"def gem?\n #return true if Dir[File.join(location, '*.gemspec')].first\n pkgname = File.basename(location)\n ... | [
"0.79255515",
"0.77250177",
"0.7615491",
"0.7449048",
"0.7422652",
"0.73918724",
"0.73804665",
"0.73491824",
"0.73491824",
"0.73491824",
"0.7323001",
"0.7234387",
"0.71082455",
"0.70332307",
"0.69598573",
"0.69517666",
"0.6900563",
"0.68946946",
"0.68860674",
"0.68841285",
"0... | 0.78640854 | 1 |
Download the local gem and return it as a string | def download_gem
self.class.download_gem @name, @version
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def download_gem\n self.class.download_gem @name, @version\n end",
"def gem_path\n @path || downloaded_gem_path\n end",
"def package_url\n \"https://github.com/arduino/arduino-cli/releases/download/#{@desired_version}/#{package_file}\"\n end",
"def downloaded_gem_path\n self.clas... | [
"0.7534541",
"0.67299455",
"0.67081475",
"0.6692183",
"0.6659706",
"0.6656821",
"0.6645297",
"0.6597834",
"0.6492952",
"0.6471331",
"0.6405053",
"0.62191784",
"0.62173826",
"0.6206112",
"0.6204636",
"0.6111781",
"0.6081143",
"0.60659784",
"0.60081154",
"0.60081154",
"0.600643... | 0.74488395 | 1 |
Return path to downloaded gem | def downloaded_gem_path
self.class.downloaded_gem_path @name, @version
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def gem_path\n @path || downloaded_gem_path\n end",
"def downloaded_gem_path\n self.class.downloaded_gem_path @name, @version\n end",
"def gem_path\n @path || downloaded_gem_path\n end",
"def downloaded_gem_path(name, version)\n # ensure gem is downloaded\n download_... | [
"0.86328757",
"0.8569027",
"0.8511787",
"0.764266",
"0.7624339",
"0.7498303",
"0.71763456",
"0.70950896",
"0.70950896",
"0.7091811",
"0.7047844",
"0.7008313",
"0.7005286",
"0.69122773",
"0.6885031",
"0.6885031",
"0.68829566",
"0.68764734",
"0.6868022",
"0.68548036",
"0.678479... | 0.8444249 | 3 |
Returns path to gem, either specified one of downloaded one | def gem_path
@path || downloaded_gem_path
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def gem_path\n @path || downloaded_gem_path\n end",
"def downloaded_gem_path\n self.class.downloaded_gem_path @name, @version\n end",
"def downloaded_gem_path\n self.class.downloaded_gem_path @name, @version\n end",
"def get_path(gemname, version_req)\n return gemname if ge... | [
"0.8079479",
"0.75119436",
"0.7334652",
"0.7258571",
"0.7078767",
"0.70415556",
"0.70225894",
"0.69959354",
"0.699445",
"0.69817716",
"0.69349766",
"0.69349766",
"0.69193554",
"0.6903768",
"0.68749917",
"0.68707067",
"0.6867492",
"0.674238",
"0.6721111",
"0.6708973",
"0.66696... | 0.79183096 | 1 |
Unpack files & return unpacked directory If block is specified, it will be invoked with directory after which directory will be removed | def unpack(&bl)
dir = nil
pkg = ::Gem::Installer.new gem_path, :unpack => true
if bl
Dir.mktmpdir do |tmpdir|
pkg.unpack tmpdir
bl.call tmpdir
end
else
dir = Dir.mktmpdir
pkg.unpack dir
end
dir
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def unpack(args)\n full_path, file = args[:full_path], args[:file]\n \n # Is unpack activated?\n if self.config[:unpack][:active]\n self.files = File.directory?(full_path) ? Unpack.runner!(full_path, self.config[:unpack]) : []\n else\n self.files = []\n end\n \n if files.any?\n ... | [
"0.6768916",
"0.66020393",
"0.6573681",
"0.64379764",
"0.6370169",
"0.62573236",
"0.6100926",
"0.60210377",
"0.59827924",
"0.59468234",
"0.58653903",
"0.58344775",
"0.58059204",
"0.5795933",
"0.5757779",
"0.57250017",
"0.5668835",
"0.5661736",
"0.55946493",
"0.5581571",
"0.55... | 0.6281311 | 5 |
Iterate over each file in gem invoking block with path | def each_file(&bl)
unpack do |dir|
Pathname(dir).find do |path|
next if path.to_s == dir.to_s
pathstr = path.to_s.gsub("#{dir}/", '')
bl.call pathstr unless pathstr.blank?
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def each_advisory_path(&block)\n Dir.glob(File.join(@path,'gems','*','*.yml'),&block)\n end",
"def each_file\n return to_enum(__method__) unless block_given?\n\n paths.each do |root|\n stat_tree(root).each do |filename, stat|\n if stat.file?\n yield filename\n ... | [
"0.7070386",
"0.6996039",
"0.69045496",
"0.68982726",
"0.68819165",
"0.686839",
"0.6828378",
"0.6794561",
"0.67542773",
"0.67044747",
"0.6674731",
"0.66717",
"0.66653067",
"0.6623254",
"0.66205245",
"0.6605908",
"0.655058",
"0.65376604",
"0.65147406",
"0.65110606",
"0.6502455... | 0.6865856 | 6 |
Retrieve the list of paths to files in the gem | def file_paths
@file_paths ||= begin
files = []
each_file do |path|
files << path
end
files
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def files\n entries.map(&:filepath)\n end",
"def paths_from_software_gems\n @paths_from_software_gems ||=\n Array(Config.software_gems).inject([]) do |array, name|\n if (spec = Gem::Specification.find_all_by_name(name).first)\n array << File.expand_path(spec.ge... | [
"0.7420614",
"0.72867376",
"0.7222215",
"0.720861",
"0.71873003",
"0.71671003",
"0.71605766",
"0.7147663",
"0.7143445",
"0.7109207",
"0.7037739",
"0.70111775",
"0.69997823",
"0.69755334",
"0.695947",
"0.6948758",
"0.6928298",
"0.6908902",
"0.6896523",
"0.6893822",
"0.688396",... | 0.7225063 | 2 |
Retreive versions of gem available in all configured targets (optionally recursively) | def dependency_versions(args = {}, &bl)
versions = args[:versions] || {}
check_deps = args[:dev] ? dev_deps : deps
check_deps.each do |dep|
unless versions.key?(dep.name)
begin
gem = Polisher::Gem.retrieve(dep.name)
versions.merge! gem.versions(args, &bl)
rescue
unknown = Polisher::VersionChecker.unknown_version(:all, dep.name, &bl)
versions.merge! dep.name => unknown
end
end
args[:versions] = versions
end
versions
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def versions_for_targets\n versions_for_targets = []\n target_version_array.each_with_index do |target_version, i|\n if !target_version.nil?\n versions_for_targets.push(target_version)\n else\n versions_for_targets.push(nil) if allow_nils?\n end\n ... | [
"0.69748926",
"0.6747975",
"0.67198837",
"0.65630853",
"0.6534792",
"0.6527612",
"0.6520567",
"0.6399236",
"0.6348885",
"0.6348494",
"0.6296808",
"0.61587715",
"0.6118991",
"0.60960525",
"0.6090008",
"0.60530555",
"0.6030857",
"0.6023128",
"0.60221905",
"0.6021368",
"0.602056... | 0.63326913 | 10 |
(and dependencies if specified) | def versions(args = {}, &bl)
local_args = Hash[args]
recursive = local_args[:recursive]
dev_deps = local_args[:dev_deps]
versions = local_args[:versions] || {}
gem_versions = Polisher::VersionChecker.versions_for(name, &bl)
versions.merge! name => gem_versions
local_args[:versions] = versions
if recursive
versions.merge! dependency_versions local_args, &bl
versions.merge! dependency_versions local_args.merge(:dev => true), &bl if dev_deps
end
versions
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def dependencies; end",
"def dependencies; end",
"def dependencies; end",
"def direct_dependencies; end",
"def dependencies=(_arg0); end",
"def adopt_dependencies\n super if defined? super\n end",
"def request_dependencies\n end",
"def install_dependencies\n raise 'Not implemented'\n end",
... | [
"0.83350015",
"0.83350015",
"0.83350015",
"0.8048307",
"0.74851626",
"0.69822156",
"0.6963211",
"0.6946507",
"0.6849558",
"0.68485314",
"0.6848463",
"0.68482226",
"0.68170995",
"0.6816483",
"0.67942774",
"0.6782293",
"0.678214",
"0.6765038",
"0.67462504",
"0.6739112",
"0.6625... | 0.0 | -1 |
Return diff of content in this gem against other | def diff(other)
require_cmd! diff_cmd
out = nil
begin
this_dir = unpack
other_dir = other.is_a?(Polisher::Gem) ? other.unpack :
(other.is_a?(Polisher::Git::Repo) ? other.path : other)
result = AwesomeSpawn.run("#{diff_cmd} -r #{this_dir} #{other_dir}")
out = result.output.gsub("#{this_dir}", 'a').gsub("#{other_dir}", 'b')
rescue
ensure
FileUtils.rm_rf this_dir unless this_dir.nil?
FileUtils.rm_rf other_dir unless other_dir.nil? ||
!other.is_a?(Polisher::Gem)
end
out
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def generate_diff wA, wB\n\n # puts \"---------------------------------> generating diff for #{wA} and #{wB}\"\n # sort by magnitude of id\n # returns w1 has earlier id than w2\n wA < wB ? w1id = wA : w1id = wB\n wA < wB ? w2id = wB : w2id = wA\n\n # get refs to whole works\n w1 = Work.find(w1... | [
"0.6789137",
"0.67606056",
"0.6752636",
"0.66995335",
"0.6696369",
"0.6584416",
"0.65363497",
"0.6480649",
"0.6407898",
"0.6405153",
"0.63680464",
"0.63475615",
"0.6333311",
"0.63078976",
"0.63058686",
"0.6257464",
"0.6254554",
"0.6252139",
"0.6249316",
"0.6248344",
"0.622299... | 0.7319598 | 0 |
The normal method retrieves a Vector3d that is perpendicular to the plane of the arc. | def normal
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def normal(p)\n return (p - @centre).unit\n end",
"def estimate_normal(\n p # vec3\n)\n Vec3.new(\n scene_sdf(Vec3.new(p.x + $EPSILON, p.y, p.z)) - scene_sdf(Vec3.new(p.x - $EPSILON, p.y, p.z)),\n scene_sdf(Vec3.new(p.x, p.y + $EPSILON, p.z)) - scene_sdf(Vec3.new(p.x, p.y - $EPSILON, p.z)),... | [
"0.6813453",
"0.6705782",
"0.64586323",
"0.64090943",
"0.6406997",
"0.6405543",
"0.6400595",
"0.63889956",
"0.63841814",
"0.6344507",
"0.6282347",
"0.6210597",
"0.6161307",
"0.6129256",
"0.61140496",
"0.5892716",
"0.5867458",
"0.58625585",
"0.58217424",
"0.58077574",
"0.57748... | 0.0 | -1 |
The plane method is used to retrieve the plane of the arc. Refer to the Geom module for instructions to create a plane. | def plane
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def plane\n return nil if @vertices.length < 3\n Plane.three_points(*@vertices[0..2])\n end",
"def distance_to_plane(plane)\n end",
"def add_plane()\n planes << Plane.new(\n gen_location,\n 0,\n width,\n height,\n gen_speed(),\n true\n )\n end",
"def add_p... | [
"0.7409262",
"0.6844087",
"0.6587345",
"0.649445",
"0.63328856",
"0.62948936",
"0.6240347",
"0.6212489",
"0.6106073",
"0.609031",
"0.60835725",
"0.5778194",
"0.5769269",
"0.57184255",
"0.55684406",
"0.5518494",
"0.5518494",
"0.5484175",
"0.5458743",
"0.54289806",
"0.5363179",... | 0.70926946 | 1 |
The radius method is used to retrieve the radius of the arc. | def radius
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def radius #:nodoc:\n 0\n end",
"def radius #:nodoc:\n 0\n end",
"def c_radius \n Math.sqrt((@x*@x)+(@y*@y))\n end",
"def angle_of_specified_radius\n @angle_of_radius\n end",
"def radius\n \twidth / 2\n end",
"def radius\n radius = (@cubic_root.to_f * 0.1).to_i\... | [
"0.7484214",
"0.7484214",
"0.71898097",
"0.7043045",
"0.68739986",
"0.6802838",
"0.67836565",
"0.6706568",
"0.66439414",
"0.66078806",
"0.65697163",
"0.6569488",
"0.65577185",
"0.6551047",
"0.6422337",
"0.6412117",
"0.6405594",
"0.6403764",
"0.6375612",
"0.63689554",
"0.63616... | 0.7225848 | 2 |
The start_angle method is used to retrieve the angle of the start of the arc, measured from the X axis in radians. | def start_angle
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def start_angle\n MSPhysics::Newton::Hinge.get_start_angle(@address)\n end",
"def start_angle=(angle)\n MSPhysics::Newton::Hinge.set_start_angle(@address, angle)\n end",
"def test_start_angle_large_angle\n start_angle = nil\n assert_nothing_raised do\n # Create a 1/2 circle perpendicu... | [
"0.7077961",
"0.6539086",
"0.64301413",
"0.6416333",
"0.640749",
"0.6346705",
"0.62377787",
"0.62319887",
"0.6158887",
"0.61364585",
"0.60976297",
"0.59716296",
"0.58776385",
"0.5831484",
"0.57564276",
"0.57015544",
"0.5690798",
"0.5688671",
"0.56833404",
"0.5678322",
"0.5658... | 0.7093622 | 0 |
The xaxis method is used to retrieve the X axis of the coordinate system for the curve. Note that the length of the returned vector is equal to the radius of the underlying curve. | def xaxis
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_x_axis(params = {})\n @x_axis = convert_axis_args(@x_axis, params)\n end",
"def axis\n axes = Sketchup.active_model.axes\n\n axes.axes.find do |axis|\n position.on_line?([axes.origin, axis])\n end\n end",
"def get_x_axis_labels\n 5\n end",
"def x\n @point[0... | [
"0.62835145",
"0.60586345",
"0.59716743",
"0.5947001",
"0.5842188",
"0.5832786",
"0.58136344",
"0.57748896",
"0.5742154",
"0.571066",
"0.5696833",
"0.5691088",
"0.56574905",
"0.56332403",
"0.5585058",
"0.5582857",
"0.5582857",
"0.55502814",
"0.5471296",
"0.5453739",
"0.543304... | 0.6580192 | 0 |
The yaxis method is used to retrieve the Y axis of the coordinate system for the curve. Note that the length of the returned vector is equal to the radius of the underlying curve. | def yaxis
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_y_axis(params = {})\n @y_axis = convert_axis_args(@y_axis, params)\n end",
"def vector_y max_value = 1\n max_value * Math.sin(self.to_radians)\n end",
"def set_y2_axis(params = {})\n @y2_axis = convert_axis_args(@y2_axis, params)\n end",
"def test_yaxis_api_example\n v = nil\n ... | [
"0.6863317",
"0.67769736",
"0.65913993",
"0.64641255",
"0.646231",
"0.61885643",
"0.61414677",
"0.60565275",
"0.5988228",
"0.5988228",
"0.5984578",
"0.59601915",
"0.59322524",
"0.59203273",
"0.59192294",
"0.59120923",
"0.59009117",
"0.58864105",
"0.5878128",
"0.58259577",
"0.... | 0.7082605 | 0 |
Use callbacks to share common setup or constraints between actions. | def set_address
@address = Address.find_by(id: params[:id], user_profile_id: current_user.user_profile_id)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_required_actions\n # TODO: check what fields change to asign required fields\n end",
"def action_hook; end",
"def run_actions; end",
"def define_action_hook; end",
"def actions; end",
"def define_action_helpers\n if super && action == :save\n @instance_helper_module.class_... | [
"0.6163163",
"0.6045976",
"0.5946146",
"0.591683",
"0.5890051",
"0.58349305",
"0.5776858",
"0.5703237",
"0.5703237",
"0.5652805",
"0.5621621",
"0.54210985",
"0.5411113",
"0.5411113",
"0.5411113",
"0.5391541",
"0.53794575",
"0.5357573",
"0.53402257",
"0.53394014",
"0.53321576"... | 0.0 | -1 |
helper for authorization_rules clarity | def is_news?
category.sysname == 'news'
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def authorization; end",
"def authorize \n self.make 'authorization' \n end",
"def authorize_access\r\n # authorize!(action_name.to_sym, \"#{controller_name}_controller\".camelcase.constantize)\r\n end",
"def authorization(*args, &block); end",
"def authorize\n end",
"def authorize\n end",
"d... | [
"0.73058826",
"0.69267124",
"0.6898613",
"0.68878627",
"0.68675417",
"0.68675417",
"0.6804562",
"0.6719275",
"0.6694463",
"0.6649856",
"0.66285",
"0.65633136",
"0.6540686",
"0.6540686",
"0.647341",
"0.647341",
"0.643564",
"0.6389",
"0.6342609",
"0.62998927",
"0.6275286",
"0... | 0.0 | -1 |
4 5 1 3 7 1 2 My final solution | def two_d_sum(arr)
i = 0
sum=0
while i < arr.length
arr[i].each do |num|
sum += num
end
i += 1
end
return sum
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def solution(a)\r\n # write your code in Ruby 2.2\r\n #trangular\r\n # a[0] = 10\r\n # a[2] = 5\r\n # a[4] = 8\r\n # 10 + 5 > 8\r\n # 5 + 8 > 10\r\n #8 + 10 > 5\r\n \r\n \r\n l=a.count\r\n \r\n i=0\r\n while(i<l) do\r\n j=i+1\r\n while(j<l) do\r\n k=j+1\... | [
"0.692498",
"0.69127625",
"0.6904588",
"0.6846181",
"0.68335927",
"0.6831962",
"0.6790998",
"0.67720103",
"0.6753366",
"0.67121804",
"0.67085856",
"0.66864455",
"0.66341823",
"0.66310537",
"0.6619364",
"0.6617434",
"0.66060287",
"0.6588998",
"0.65856344",
"0.65853643",
"0.658... | 0.0 | -1 |
=> 1 Teacher's solution | def two_d_sum(arr)
total = 0
arr.each do |sub_array|
sub_array.each do |num|
total += num
end
end
return total
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def solution4(input)\n end",
"def faculty(i)\n result = 1\n i.times do |index|\n result *= (index + 1)\n end\n result\n end",
"def solve\n solution_candidate(intersections.next_people_with_similar_tastes)\n end",
"def acmTeam(topic)\n num_of_attendees = topic.count\n\n permut... | [
"0.6101889",
"0.60088825",
"0.5942575",
"0.590028",
"0.5887425",
"0.57310027",
"0.5698055",
"0.56876075",
"0.5654702",
"0.56482345",
"0.5637539",
"0.56293404",
"0.5621347",
"0.5604939",
"0.55854684",
"0.5580631",
"0.55686224",
"0.55631375",
"0.5537981",
"0.5536098",
"0.553355... | 0.0 | -1 |
Set the needed paths. install_dir: The gems will be temporarily installed into this directory. Caution: Before installing the directory will be delete. jar_dir: The directory where the JAR files will be put. | def setup(install_dir, jar_dir)
@install_dir = install_dir
@jar_dir = jar_dir
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def bundle\n raise \"Paths not given! Call setup first.\" if @install_dir.nil? || @jar_dir.nil?\n gems_jar = File.join(jar_dir, 'gems.jar')\n default_options = { :generate_rdoc => false, \n :generate_ri => false,\n :install_dir => install_dir }\n FileUtils.... | [
"0.67380136",
"0.5933493",
"0.58997345",
"0.58959854",
"0.5750506",
"0.5717784",
"0.568383",
"0.5610892",
"0.55940956",
"0.55603445",
"0.5547495",
"0.55282176",
"0.5518102",
"0.5503688",
"0.5503688",
"0.5475778",
"0.5475611",
"0.546512",
"0.5462571",
"0.544692",
"0.5440849",
... | 0.7811157 | 0 |
Adds a gem gem "activerecord", ">= 2.3.1" | def gem(name, version = Gem::Requirement.default)
@gems ||= {}
@gems[name] = version
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def initialize\n optional_gem 'dbd-sqlite3', requires: 'dbd/SQLite3'\n optional_gem 'activerecord', '~> 4.0', requires: 'active_record'\n optional_gem 'dbi'\n optional_gem 'sqlite3'\n end",
"def pluggable!\n abort \"update rubygems to >= 1.3.1\" unless Gem.respond_t... | [
"0.6080091",
"0.59166825",
"0.5808521",
"0.5752241",
"0.5741924",
"0.57120377",
"0.5498059",
"0.5481172",
"0.5466027",
"0.5450201",
"0.5450201",
"0.544846",
"0.54423153",
"0.5436339",
"0.5412091",
"0.54072344",
"0.53560114",
"0.5349064",
"0.5325636",
"0.53213996",
"0.53133416... | 0.53928715 | 16 |
Checks if all required gems are installed and returns gems that miss. | def check_gems
@gems ||= {}
@gems.keys.select { |g| Gem.source_index.find_name(g, @gems[g]).size == 0 }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def dep_check\n $gems_required.each do |current_gem|\n begin\n if current_gem.include? \",\"\n tokens = current_gem.split(\",\")\n gem tokens[0], tokens[1]\n else\n gem current_gem\n end\n rescue Gem::LoadError\n if current_gem.include? \",\"\n $gems_missing_v... | [
"0.7633258",
"0.7436955",
"0.74197423",
"0.72621655",
"0.7222977",
"0.70317864",
"0.69449383",
"0.68607575",
"0.67814004",
"0.67673004",
"0.6764804",
"0.67586553",
"0.6703803",
"0.65185887",
"0.6488151",
"0.6456092",
"0.6430396",
"0.64253855",
"0.6414735",
"0.6352877",
"0.631... | 0.731619 | 3 |
Bundles the required gems into a JAR file. Before the gems are packed into the JAR, all JARs inside the gems are moved to the jar_dir. | def bundle
raise "Paths not given! Call setup first." if @install_dir.nil? || @jar_dir.nil?
gems_jar = File.join(jar_dir, 'gems.jar')
default_options = { :generate_rdoc => false,
:generate_ri => false,
:install_dir => install_dir }
FileUtils.rm_rf install_dir if File.exists? install_dir
FileUtils.mkdir_p install_dir
installer = Gem::DependencyInstaller.new(default_options)
@gems.each do |name, version|
puts "Installing #{name} (#{version})"
installer.install(name, version || Gem::Requirement.default)
end
Dir.glob("#{install_dir}/**/*.jar").each do |jar|
FileUtils.mv jar, File.join(jar_dir, jar.split("/").last)
end
FileUtils.rm gems_jar if File.exists? gems_jar
`jar cf #{gems_jar} -C #{install_dir} .`
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_bundled_gems\n return unless bundle_gems\n\n if bundle_local\n logger.trace 'Adding bundler filer to jar locally...'\n else\n logger.trace 'Adding bundler files to jar...'\n end\n\n require 'bundler'\n begin\n gemfile_path, lockfile_path ... | [
"0.7421737",
"0.68111247",
"0.6689431",
"0.6677503",
"0.64717484",
"0.63810694",
"0.634262",
"0.6281837",
"0.62714773",
"0.6116783",
"0.60159737",
"0.5992325",
"0.59511906",
"0.5786924",
"0.5767364",
"0.5765505",
"0.57531726",
"0.56808",
"0.55749744",
"0.5507944",
"0.54144675... | 0.74910843 | 0 |
GET /daties GET /daties.json | def index
@daties = Daty.all.order(updated_at: :desc)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n render json: WeatherDatum.all\n end",
"def index\n @dossiers = Dossier.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @dossiers }\n end\n end",
"def index\n @data = Datum.all\n\n respond_to do |format|\n format.html ... | [
"0.66285557",
"0.65773255",
"0.6513484",
"0.64763695",
"0.63176906",
"0.61696565",
"0.6093377",
"0.6087909",
"0.6086818",
"0.60836077",
"0.60710794",
"0.60710794",
"0.60502076",
"0.60462576",
"0.60323244",
"0.6015316",
"0.6012293",
"0.60026836",
"0.59943765",
"0.5985998",
"0.... | 0.5953204 | 22 |
GET /daties/1 GET /daties/1.json | def show
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @data = Datum.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @data }\n end\n end",
"def show\n @datum = Datum.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @datum ... | [
"0.65137297",
"0.63814336",
"0.63814336",
"0.63604116",
"0.63084036",
"0.6123568",
"0.6097422",
"0.60878927",
"0.6086345",
"0.60814965",
"0.6051762",
"0.60254365",
"0.59646183",
"0.5955802",
"0.5940997",
"0.5923522",
"0.5884963",
"0.58788383",
"0.58704484",
"0.58594525",
"0.5... | 0.0 | -1 |
POST /daties POST /daties.json | def create
@daty = current_user.daties.build(daty_params)
respond_to do |format|
if @daty.save
format.html { redirect_to @daty, notice: 'Daty was successfully created.' }
format.json { render :show, status: :created, location: @daty }
else
format.html { render :new }
format.json { render json: @daty.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @meteo_datum = MeteoDatum.new(meteodatum_params)\n @meteo_datum.weather_station_id = params[:weather_station_id]\n\n if @meteo_datum.save\n render json: @meteo_datum, status: :created\n else\n render json: @meteo_datum.errors, status: :unprocessable_entity\n end\n end",
"de... | [
"0.5969446",
"0.5880498",
"0.5841724",
"0.5801228",
"0.5745463",
"0.5705525",
"0.5697604",
"0.56937057",
"0.56911564",
"0.5650348",
"0.5620837",
"0.56168604",
"0.56119776",
"0.5587607",
"0.55873734",
"0.5577817",
"0.5567594",
"0.55527216",
"0.55085063",
"0.5497819",
"0.548352... | 0.6704057 | 0 |
PATCH/PUT /daties/1 PATCH/PUT /daties/1.json | def update
respond_to do |format|
if @daty.update(daty_params)
format.html { redirect_to @daty, notice: 'Daty was successfully updated.' }
format.json { render :show, status: :ok, location: @daty }
else
format.html { render :edit }
format.json { render json: @daty.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def patch(path, data)\n request 'PATCH', path, body: data.to_json\n end",
"def api_patch(path, data = {})\n api_request(:patch, path, :data => data)\n end",
"def patch\n headers = {\"If-Match\" => @version}\n response = @context.request :patch, \"#{@path}/#{@id}\", @data.to_json, head... | [
"0.68686336",
"0.6824158",
"0.6794531",
"0.6645903",
"0.64442414",
"0.63872534",
"0.63589317",
"0.6240699",
"0.62149256",
"0.6173382",
"0.61181927",
"0.6105475",
"0.6068339",
"0.60622215",
"0.60581076",
"0.6055442",
"0.60456413",
"0.60319173",
"0.60319173",
"0.6030113",
"0.60... | 0.6466438 | 4 |
DELETE /daties/1 DELETE /daties/1.json | def destroy
@daty.destroy
respond_to do |format|
format.html { redirect_to daties_url, notice: 'Daty was successfully destroyed.' }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_json(path)\n url = [base_url, path].join\n resp = HTTParty.delete(url, headers: standard_headers)\n parse_json(url, resp)\n end",
"def destroy\n @datum = Datum.find(params[:id])\n @datum.destroy\n\n respond_to do |format|\n format.html { redirect_to data_url }\n format.jso... | [
"0.71012366",
"0.69983524",
"0.69983524",
"0.6914332",
"0.68503565",
"0.6837376",
"0.6819457",
"0.68034667",
"0.67860085",
"0.6740459",
"0.6704675",
"0.6671048",
"0.66459",
"0.6619549",
"0.65895253",
"0.656336",
"0.65559727",
"0.65557826",
"0.6552506",
"0.65391463",
"0.652338... | 0.70612794 | 1 |
Use callbacks to share common setup or constraints between actions. | def set_daty
@daty = Daty.find(params[:id])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_required_actions\n # TODO: check what fields change to asign required fields\n end",
"def action_hook; end",
"def run_actions; end",
"def define_action_hook; end",
"def actions; end",
"def define_action_helpers\n if super && action == :save\n @instance_helper_module.class_... | [
"0.6163163",
"0.6045976",
"0.5946146",
"0.591683",
"0.5890051",
"0.58349305",
"0.5776858",
"0.5703237",
"0.5703237",
"0.5652805",
"0.5621621",
"0.54210985",
"0.5411113",
"0.5411113",
"0.5411113",
"0.5391541",
"0.53794575",
"0.5357573",
"0.53402257",
"0.53394014",
"0.53321576"... | 0.0 | -1 |
Never trust parameters from the scary internet, only allow the white list through. | def daty_params
params.require(:daty).permit(:start_date, :end_date, :localisation)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def strong_params\n params.require(:user).permit(param_whitelist)\n end",
"def strong_params\n params.require(:listing_member).permit(param_whitelist)\n end",
"def allow_params_authentication!; end",
"def allowed_params\n ALLOWED_PARAMS\n end",
"def default_param_whitelist\n [\"mode\"]\n... | [
"0.69792545",
"0.6781151",
"0.67419964",
"0.674013",
"0.6734356",
"0.6591046",
"0.6502396",
"0.6496313",
"0.6480641",
"0.6477825",
"0.64565",
"0.6438387",
"0.63791263",
"0.63740575",
"0.6364131",
"0.63192815",
"0.62991166",
"0.62978333",
"0.6292148",
"0.6290449",
"0.6290076",... | 0.0 | -1 |
save format to context | def store_pwfmt_params
Pwfmt::Context.formats = params[:pwfmt][:formats] if params[:pwfmt]
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def format\n @format ||= {}\n end",
"def format\n @_format\n end",
"def format\n @format\n end",
"def convert(format)\n manipulate!(:format => format)\n @format = format\n end",
"def format\n @format ||= properties.format.new self\n end",
"def formats; end... | [
"0.60575414",
"0.60413516",
"0.60328984",
"0.59167314",
"0.5910424",
"0.588435",
"0.588435",
"0.58680737",
"0.5849825",
"0.5843311",
"0.58194053",
"0.58194053",
"0.58194053",
"0.58194053",
"0.58194053",
"0.58194053",
"0.58194053",
"0.58194053",
"0.5767838",
"0.57380444",
"0.5... | 0.53991157 | 60 |
Instantiate Coin with the attributes below, adds + sign for positive change numbers | def initialize(name, price_usd, price_btc, market_cap_usd, percent_change_24h, last_updated_unix)
@name = name
@price_usd = price_usd.to_f.round(2)
@price_btc = price_btc.to_i
@market_cap_usd = market_cap_usd.to_i
@percent_change_24h = percent_change_24h.to_i
@last_updated_unix = last_updated_unix
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create_coin(coin)\n name = coin['name']\n price_usd = coin['price_usd']\n price_btc = coin['price_btc']\n market_cap_usd = coin['market_cap_usd']\n percent_change_24h = coin['percent_change_24h']\n last_updated_unix = coin['last_updated']\n CryptoMarket::Coin.new(name, price_usd, price_btc... | [
"0.62319946",
"0.61666965",
"0.6109753",
"0.60831803",
"0.60831803",
"0.60831803",
"0.5875681",
"0.58481145",
"0.58333826",
"0.57771313",
"0.57499164",
"0.5746851",
"0.5723386",
"0.5706028",
"0.5685634",
"0.56356573",
"0.562961",
"0.5609288",
"0.5599456",
"0.5585126",
"0.5585... | 0.55036384 | 29 |
Prints out the coin attributes for the Coin object with terminaltable gem | def attributes
table = terminal_table do |t|
t.title = name.upcase
t.add_row ["Price USD:", "$#{price_usd}"]
t.add_row ["Price BTC:", "#{price_btc}"]
t.add_row ["Market Cap USD:", "$#{market_cap_usd}"]
t.add_row ["Change Last 24h:", "#{percent_change_24h}%"]
t.add_row ["Last Updated:", "#{Time.at(last_updated_unix.to_i)}"]
t.style = { all_separators: true, width: 60 }
end
puts table
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def print_coin_names\n coin_names_arrays.each do |coin|\n coin.each do |name|\n index = name.slice!(/\\d+\\s/).strip\n table = terminal_table do |t|\n t.add_row [index, name]\n t.style = { all_separators: true, width: 60 }\n end\n puts table\n end\n y... | [
"0.70183617",
"0.68653435",
"0.6565183",
"0.651299",
"0.647336",
"0.6469669",
"0.63120645",
"0.629826",
"0.62857366",
"0.6111504",
"0.6110223",
"0.5978575",
"0.59607655",
"0.59492505",
"0.59262216",
"0.58954006",
"0.58858734",
"0.588126",
"0.5869724",
"0.58365005",
"0.5806135... | 0.746819 | 0 |
(marked 'Start' in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the bottomright corner of the grid (marked 'Finish' in the diagram below). How many possible unique paths are there? input: m (rows), n(cols) output: number, representing number of unique paths from start to end x x x x x x x x x x x x x x x x x x x x x represent as [ [x,x,x,x,x,x,x], [x,x,x,x,x,x,x], [x,x,x,x,x,x,x] ] start: rows=1, cols=1 end: rows=3, cols=7 invalid: col > 7, row > 3 rows=2, cols=4 x x x x x x x x paths(m, n) if m == 0, return 0 if n == 0, return 0 if m == 1 && n == 1, return 1 if memo[row][col] doesnt yet exist, set it memo[row][col] = paths(m 1, n) + paths(m, n 1) return memo[row][col] create_memo for row in rows initialize [] and add it to outer array | def create_memo(rows)
memo = []
(rows + 1).times { |_| memo << []}
memo
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def unique_paths_iterative(m, n)\n return 0 if m == 0 || n == 0\n\n grid = Array.new(m) { Array.new(n) {0} }\n grid[0][0] = 1\n\n row = 0\n column = 0\n\n while row < m\n while column < n\n # check top\n if row > 0\n grid[row][column] += grid[row - 1][c... | [
"0.767142",
"0.7289165",
"0.7219978",
"0.71513057",
"0.7142519",
"0.71173",
"0.71154433",
"0.7064094",
"0.701067",
"0.696083",
"0.68123895",
"0.6756051",
"0.66763",
"0.65197337",
"0.6501298",
"0.644206",
"0.6408541",
"0.6405648",
"0.62281775",
"0.62185156",
"0.6189234",
"0.... | 0.0 | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.