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
Assignment: Program 1: Hailstones
def getstr (n) str=n.to_s len=str.length s='' for i in 1...(7-len) s+=' ' end #end of the for loop s+str #return the spaces and the number combined as a string end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def hailstone1(num)\n count = 0\n\n if num == 1\n print \"#{num} \"\n num = (num * 3) + 1\n count += 1\n end\n\n print \"#{num} \"\n\n hailoop(num, count)\n\n puts\n puts \"HAILSTONE 1 - Number of steps: #{count}\"\nend", "def hailstone2(num)\n count = 0\n\n if num == 1\n puts '1'\n puts ...
[ "0.6845783", "0.65137035", "0.6459161", "0.6175092", "0.60107255", "0.5992998", "0.5946953", "0.5946953", "0.5946953", "0.5890106", "0.58691543", "0.58542675", "0.58384573", "0.5821024", "0.58177483", "0.58144003", "0.5809673", "0.58038896", "0.5771129", "0.57525194", "0.5739...
0.0
-1
To calculate entropy we have to check how many yes and how many no
def entropy(attr,labels) # check binary attributes mapped = parse_attr(attr) if mapped.keys.size == 2 #Binary attributes return gain([mapped.values[0],mapped.values[1]]) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def entropy\r\n e = 0\r\n 0.upto(255) do |i|\r\n x = count(i.chr)/size.to_f\r\n if x > 0\r\n e += - x * Math.log2(x)\r\n end\r\n end\r\n\r\n return e\r\n end", "def entropy\n raise RuntimeError...
[ "0.703899", "0.6958269", "0.69497454", "0.6832341", "0.65735626", "0.653201", "0.6388338", "0.62381035", "0.61947054", "0.6100469", "0.60650676", "0.59896576", "0.5953643", "0.5829537", "0.5820378", "0.57959795", "0.5758573", "0.5724886", "0.56860954", "0.56620425", "0.562399...
0.627472
7
Calculate the gain value
def gain(array) sum = array.inject(0) {|sum,x| sum + x } gain = 0.0 array.each do |num| gain += (num.to_f/sum.to_f) * calcLog2(num.to_f/sum.to_f) end return -gain.round(3) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def eth_gain\n return ((eth_value - eth_initial) / eth_value) * 100\n end", "def gain_relative_to_current\n -1+(post_heal / pre_heal)\n end", "def gain \n self.gain_price > 0\n end", "def calculate_gain(change_ratio, previous_gains, new_investment)\n return (previous_gains + new_investmen...
[ "0.7547266", "0.7131599", "0.7094297", "0.69958085", "0.6987576", "0.69728124", "0.69590926", "0.688296", "0.6865635", "0.6839346", "0.65968174", "0.657625", "0.65370315", "0.63976383", "0.6334745", "0.6330103", "0.6274322", "0.6229076", "0.62153864", "0.6119123", "0.6073507"...
0.734633
1
GET /course_details GET /course_details.json
def index @course_details = CourseDetail.all end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show_course\n\t\t@course = Course.find(params[:course_id])\n\t\trender json: @course\n\tend", "def show\n render json: @course\n end", "def show\n @course = Course.find(params[:id])\n \n respond_to do |format|\n format.html # show.html.erb\n format.json { render :json => @cours...
[ "0.79487604", "0.7706528", "0.76640576", "0.7650653", "0.7647611", "0.7647611", "0.7647611", "0.7647611", "0.7647611", "0.7647611", "0.7631062", "0.76037455", "0.7561829", "0.7549183", "0.7541099", "0.75176364", "0.7500165", "0.7487145", "0.7459454", "0.7455666", "0.7441441",...
0.7430759
21
def show_details course_id = params[:id]
def show end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n @id = params[:id] #this is the id of the course, used in template to create a link to show the studetns of a course\n @course = Course.find_by_id(params[:id])\n end", "def showCourseInfo\n cid = params[:cid]\n @course = Course.find_by_id(cid)\n @course\n end", "def show\n ...
[ "0.81074244", "0.78657037", "0.7706588", "0.77056456", "0.7620139", "0.7571347", "0.7571347", "0.7551699", "0.7551699", "0.7548128", "0.7545138", "0.7508093", "0.74920636", "0.746864", "0.7455164", "0.7435587", "0.7388884", "0.7368002", "0.7340948", "0.72901034", "0.72758305"...
0.0
-1
POST /course_details POST /course_details.json
def create @course_detail = CourseDetail.new(course_detail_params) respond_to do |format| if @course_detail.save format.html { redirect_to @course_detail, notice: 'Course detail was successfully created.' } format.json { render :show, status: :created, location: @course_detail } else format.html { render :new } format.json { render json: @course_detail.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create\n @course = Course.new(course_params)\n @course.save\n render_jsonapi_response(@course)\n end", "def create\n @course = Course.new(course_params)\n \n respond_to do |format|\n if @course.save\n #format.html { redirect_to course_build_path(:id =>\"courseinfo\", :course_id =...
[ "0.73757744", "0.724687", "0.71371424", "0.71125907", "0.7096257", "0.709046", "0.7084844", "0.70800143", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7080009", "0.7073378", ...
0.7764854
0
PATCH/PUT /course_details/1 PATCH/PUT /course_details/1.json
def update respond_to do |format| if @course_detail.update(course_detail_params) format.html { redirect_to @course_detail, notice: 'Course detail was successfully updated.' } format.json { render :show, status: :ok, location: @course_detail } else format.html { render :edit } format.json { render json: @course_detail.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n @course.update(course_params)\n render_jsonapi_response(@course)\n end", "def update\n @course = Course.find(params[:id])\n\n respond_to do |format|\n if @course.update_attributes(params[:course])\n format.html { redirect_to @course, notice: 'course was successfully updated....
[ "0.741992", "0.71803397", "0.7139961", "0.7138965", "0.7122452", "0.7122452", "0.7122452", "0.7122452", "0.7122452", "0.7122452", "0.7122452", "0.7122452", "0.70819736", "0.7025524", "0.70238686", "0.70217466", "0.7011266", "0.70058805", "0.6986386", "0.6986386", "0.6986386",...
0.7266102
1
DELETE /course_details/1 DELETE /course_details/1.json
def destroy @course_detail.destroy respond_to do |format| format.html { redirect_to course_details_url, notice: 'Course detail was successfully destroyed.' } format.json { head :no_content } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def delete_course_by_id(org_unit_id)\n path = \"/d2l/api/lp/#{$lp_ver}/courses/#{org_unit_id}\" # setup user path\n # ap path\n _delete(path)\n puts '[+] Course data deleted successfully'.green\nend", "def destroy\n @course.destroy\n respond_to do |format|\n format.html { redirect_to cours...
[ "0.7589887", "0.75089705", "0.75089705", "0.75089705", "0.75089705", "0.75086683", "0.74994606", "0.7490716", "0.7482792", "0.74788755", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", "0.74788475", ...
0.76634425
0
Use callbacks to share common setup or constraints between actions.
def set_course_detail @course_detail = CourseDetail.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 course_detail_params params.require(:course_detail).permit(:course_id, :course_description, :course_duration, :lecture_hours, :course_curriculum) 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
the command to run the queue worker for a single job
def queue_worker_once_command(tries) if version < "5.3.0" "php artisan queue:work --tries=#{tries}" else "php artisan queue:work --once --tries=#{tries}" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def run(job)\n resp = command %{run job=\"#{job}\" yes}\n expr = /^Job queued. JobId=(\\d+)$/\n if resp =~ expr\n $1.to_i\n else\n raise \"Command error:\" + \\\n \" expected #{expr.inspect},\" + \\\n \" got #{resp.inspect}\"\n end\n end", "def queue_job; end", "...
[ "0.72984415", "0.7027433", "0.7011132", "0.67913514", "0.67155504", "0.66397303", "0.66106826", "0.65535975", "0.65250164", "0.6418476", "0.6356912", "0.63447195", "0.63333327", "0.6317735", "0.63035905", "0.62847155", "0.6284654", "0.6283367", "0.62675995", "0.62551653", "0....
0.6779741
4
the command to run the queue worker as a daemon
def queue_worker_daemon_command(tries) # the command to run the queue worker was 'queue:listen' but changed to # 'queue:work' in Laravel 5.3 ('queue:work' exists on older Laravels, but # is not quite equivalent) if version < "5.3.0" "php artisan queue:listen --tries=#{tries}" else "php artisan queue:work --tries=#{tries}" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def worker_runner\n $daemon[:logger_msg_prefix] = 'TaskQueueWorker'\n\n worker_install_signal_handler\n daemon_log :msg => \"Start working...\"\n\n # Fetch pending task queues and start working\n while $worker[:work] do\n # Get next pending taskqueue\n $worker[:task_queue] = $daemon[:task_queue_model].g...
[ "0.6433425", "0.62297183", "0.62180203", "0.60811204", "0.608085", "0.6062228", "0.59475344", "0.59433043", "0.59429485", "0.593314", "0.59301656", "0.59292936", "0.5912724", "0.58959633", "0.58687276", "0.58432704", "0.58268744", "0.57881963", "0.57687324", "0.573599", "0.57...
0.7530096
0
the composer package name of the framework being used (Lumen or Laravel)
def framework_package_name if lumen? "laravel/lumen-framework" else "laravel/framework" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def package_name\n @version ? \"#{@name}-#{@version}\" : @name\n end", "def fmri_package_name\n version = project.build_version.split(/[^\\d]/)[0..2].join(\".\")\n platform = Ohai[\"platform_version\"]\n \"#{safe_base_package_name}@#{version},#{platform}-#{project.build_iteration}\"\n e...
[ "0.71210504", "0.7083871", "0.7019944", "0.69562906", "0.69562906", "0.68332326", "0.68081033", "0.67278403", "0.6711989", "0.6581796", "0.6513474", "0.64460266", "0.6443253", "0.64212006", "0.6410663", "0.6388863", "0.6343966", "0.63339984", "0.6327246", "0.6286161", "0.6259...
0.8604468
0
Show an emotion to an event or the player
def emotion(type, wait = 34, params = {}) Yuki::Particles.add_particle(self, type, params) @wait_count = wait @move_type_custom_special_result = true if wait > 0 end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def emotion(type, char_id = 0, wait = 34, params = {})\n Yuki::Particles.add_particle(get_character(char_id), type, params)\n @wait_count = wait\n end", "def subcommand event\n\t\treturn \"\" if @scene.love_scene?\n\t\tif event.is_a?(CharacterPoseEvent)\n\t\t raw('<a data-character-id=\"'+event.character...
[ "0.6222672", "0.6061678", "0.58666503", "0.58279973", "0.5801685", "0.5710038", "0.567981", "0.55938524", "0.5574042", "0.549475", "0.54903185", "0.5486874", "0.5485495", "0.54301393", "0.542893", "0.542806", "0.5426025", "0.54177064", "0.54059494", "0.53962797", "0.5368881",...
0.5606599
7
Push a particle to the particle stack if possible
def particle_push return if @particles_disabled method_name = PARTICLES_METHODS[system_tag] send(method_name) if method_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push\n each_follower(&:particle_push) if @was_fighting\n @was_fighting = false\n end", "def spawn(particle)\n particles << particle\n end", "def particle_push_grass\n Yuki::Particles.add_particle(self, 1)\n end", "def particle_push_sand\n particle = SAND_PARTICLE_...
[ "0.78883904", "0.76454055", "0.7617378", "0.7607724", "0.74604976", "0.7282778", "0.7205836", "0.7102537", "0.6346233", "0.6279557", "0.62702876", "0.6171346", "0.616924", "0.61665905", "0.6163213", "0.61335117", "0.6113619", "0.6108243", "0.6074436", "0.6061983", "0.60581815...
0.7561732
4
Push a grass particle
def particle_push_grass Yuki::Particles.add_particle(self, 1) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_tall_grass\n Yuki::Particles.add_particle(self, 2)\n end", "def particle_push_pond\n Yuki::Particles.add_particle(self, :pond) if surfing?\n end", "def particle_push\n each_follower(&:particle_push) if @was_fighting\n @was_fighting = false\n end", "def particle_push_sno...
[ "0.7899721", "0.7473281", "0.71971273", "0.7111376", "0.70544726", "0.70337105", "0.69937944", "0.68497926", "0.652442", "0.6133504", "0.59186596", "0.59133583", "0.58863616", "0.58314884", "0.57970226", "0.57179147", "0.57179147", "0.56605875", "0.5648924", "0.56052035", "0....
0.86558145
0
Push a tall grass particle
def particle_push_tall_grass Yuki::Particles.add_particle(self, 2) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_grass\n Yuki::Particles.add_particle(self, 1)\n end", "def particle_push_snow\n particle = SNOW_PARTICLE_NAME[@direction]\n Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint\n end", "def particle_push_pond\n Yuki::Particles.add_particle(self, :pond)...
[ "0.85040885", "0.7428584", "0.72696924", "0.7268677", "0.72321516", "0.6787711", "0.66412735", "0.6522081", "0.64814717", "0.6225192", "0.6119624", "0.59810144", "0.5842998", "0.58385265", "0.5691491", "0.56210035", "0.5606605", "0.5574522", "0.55692756", "0.5553393", "0.5546...
0.85724854
0
Push a sand particle
def particle_push_sand particle = SAND_PARTICLE_NAME[@direction] Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_grass\n Yuki::Particles.add_particle(self, 1)\n end", "def particle_push_snow\n particle = SNOW_PARTICLE_NAME[@direction]\n Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint\n end", "def particle_push_tall_grass\n Yuki::Particles.add_particle(self, ...
[ "0.7893507", "0.7847404", "0.764713", "0.7588251", "0.7211023", "0.7189409", "0.68805707", "0.67624724", "0.66524947", "0.61862355", "0.6150742", "0.60802644", "0.59520453", "0.58432", "0.58345675", "0.57905686", "0.5781934", "0.57767373", "0.5702231", "0.5701284", "0.5698077...
0.8514672
0
Push a wet sand particle
def particle_push_wetsand Yuki::Particles.add_particle(self, :wetsand) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_sand\n particle = SAND_PARTICLE_NAME[@direction]\n Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint\n end", "def particle_push_snow\n particle = SNOW_PARTICLE_NAME[@direction]\n Yuki::Particles.add_particle(self, particle) if particle && @can_make_foo...
[ "0.81337667", "0.77533", "0.76495045", "0.7631777", "0.7323322", "0.7224696", "0.6594687", "0.6319146", "0.629046", "0.6181985", "0.58692914", "0.5839518", "0.57865816", "0.5774425", "0.56944484", "0.5654183", "0.56420416", "0.56036663", "0.56036663", "0.5602012", "0.5574995"...
0.80618197
1
Push a snow particle
def particle_push_snow particle = SNOW_PARTICLE_NAME[@direction] Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_grass\n Yuki::Particles.add_particle(self, 1)\n end", "def particle_push_sand\n particle = SAND_PARTICLE_NAME[@direction]\n Yuki::Particles.add_particle(self, particle) if particle && @can_make_footprint\n end", "def particle_push_tall_grass\n Yuki::Particles.add_particle(self, ...
[ "0.79327005", "0.76966494", "0.758137", "0.7374655", "0.73626745", "0.7179793", "0.67375046", "0.6530833", "0.6226729", "0.6179542", "0.6110857", "0.598629", "0.59386104", "0.586246", "0.5751026", "0.57352513", "0.56319237", "0.5631753", "0.5614198", "0.5467212", "0.53751385"...
0.8774217
0
Push a pond particle
def particle_push_pond Yuki::Particles.add_particle(self, :pond) if surfing? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def particle_push_grass\n Yuki::Particles.add_particle(self, 1)\n end", "def particle_push\n each_follower(&:particle_push) if @was_fighting\n @was_fighting = false\n end", "def particle_push_wetsand\n Yuki::Particles.add_particle(self, :wetsand)\n end", "def particle_push_snow\n part...
[ "0.78028107", "0.751103", "0.7354351", "0.7301683", "0.7288687", "0.7227129", "0.7203078", "0.6907009", "0.68383837", "0.61162937", "0.5981317", "0.5958065", "0.5949874", "0.59319884", "0.59284127", "0.58236897", "0.5799785", "0.57977515", "0.56844825", "0.559143", "0.5543229...
0.88972324
0
Initialize CatalogItems with a catalog name and item ID currently in Beta only
def initialize(catalog, conf = nil) @catalog = catalog super conf end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize(catalog, item_id = nil, conf = nil)\n @catalog = catalog\n @item_id = item_id\n super conf\n end", "def set_catalog_item\n @catalog_item = CatalogItem.find(params[:id])\n end", "def setup_catalog\n [\n {product_name: 'bamba', photo_url: 'dummy_url1', bar...
[ "0.7555834", "0.7309986", "0.6295489", "0.609162", "0.6056877", "0.5972658", "0.5966236", "0.5961284", "0.5958327", "0.5940787", "0.5940787", "0.59370995", "0.5803671", "0.57907885", "0.5759341", "0.5744592", "0.5732159", "0.57195455", "0.5696623", "0.5693051", "0.5691073", ...
0.56652313
21
Bulk delete catalog items
def delete(item_ids = []) body = { itemIds: item_ids } Iterable.request(conf, base_path).delete(body) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def deleteItems\n self.items.each do |item|\n item.delete\n end\n end", "def delete!\n uniq.bulk_job { |e| e.delete! }\n end", "def delete\n blacklight_items.each do |r|\n solr.delete_by_id r[\"id\"]\n solr.commit\n end\n end", "def batch_delete(config, items)\n begi...
[ "0.6837122", "0.68367153", "0.6684596", "0.6639312", "0.66354644", "0.65910995", "0.64246243", "0.6396807", "0.63745314", "0.6328284", "0.63267463", "0.6318603", "0.63055533", "0.62892663", "0.6268405", "0.6261704", "0.6255814", "0.625426", "0.6246471", "0.6232475", "0.622530...
0.617884
22
add any new content to the database, identified by the given key. returns false if the key is already existing.
def set key, data @data_base[ key ] = data update_database end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def add_content_key content_key\n return unless content_key\n self.transaction do\n content_key = content_key.versions.latest if ContentKey === content_key\n raise ArgumentError, \"Expected ContentKey or ContentKey::Version\" unless ContentKey::Version === content_key\n\n save! unless self.id\...
[ "0.69996715", "0.646594", "0.63816655", "0.6284466", "0.60284156", "0.5997813", "0.5965322", "0.5925923", "0.5904836", "0.59005827", "0.58622074", "0.58169615", "0.57639265", "0.5695502", "0.5671685", "0.56706035", "0.5632471", "0.56315494", "0.5613224", "0.5610761", "0.56096...
0.52837634
66
a shorthand method for the set method
def []=(key, data) set key, data end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set(*args)\n # not supported\n end", "def set(*args)\n # not supported\n end", "def set(object, value); end", "def set; end", "def set; end", "def set=(_arg0); end", "def set!(*args)\n end", "def set(*args, &block)\n update(*args, &block)\n end", "def set(key, value); e...
[ "0.82947886", "0.82947886", "0.8263663", "0.80374503", "0.80374503", "0.77948207", "0.77820826", "0.74962837", "0.74458224", "0.74458224", "0.74219626", "0.72579", "0.722857", "0.7207558", "0.70739955", "0.7044611", "0.70134306", "0.7012719", "0.70014685", "0.6994915", "0.697...
0.0
-1
return the data corresponding to the given key.
def get key @data_base[ key ] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_data(key) \n return @data[key]\n end", "def get(key)\n return @data[key.to_s]\n end", "def get_data(key=nil)\n @data ||= {}\n @data[key]\n end", "def get(key)\n (self.data ||= {})[key.to_s]\n end", "def get_data(key)\n raise 'The get_data met...
[ "0.8780693", "0.8015584", "0.80073243", "0.772336", "0.7644937", "0.7636809", "0.76137006", "0.7554726", "0.7552696", "0.75188327", "0.75188327", "0.7513735", "0.7481359", "0.7481359", "0.7481359", "0.7481359", "0.7481359", "0.7481359", "0.74174577", "0.73690724", "0.7336741"...
0.75370073
9
a shorthand method for the get method
def [](key) get key end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get; end", "def _get\n http_method(:get)\n end", "def get\n end", "def get()\n \n end", "def get(object); end", "def get\n end", "def get\n end", "def get!\n clear and get\n end", "def get\n raise NotImplementedError\n end", "def get(*args, &block)\n ...
[ "0.8119521", "0.7788669", "0.7597123", "0.7590859", "0.7547613", "0.75299144", "0.75064594", "0.749706", "0.7470075", "0.74652797", "0.73841846", "0.73681563", "0.73452073", "0.73452073", "0.72694683", "0.72305644", "0.7167413", "0.7167413", "0.7122239", "0.7103687", "0.70965...
0.64878464
71
delete the key and all associated data
def delete key data = @data_base.delete key update_database data end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def delete _key\n store.transaction() { |s| s.delete(prepare_key(_key)) }\n end", "def delete(key)\n data.delete(key)\n @deleted_hash[key] = nil\n end", "def delete_key(key)\n end", "def delete(key); end", "def delete(key); end", "def delete(key); end", "def delete(k...
[ "0.84242046", "0.83794314", "0.8365561", "0.8339432", "0.8339432", "0.8339432", "0.8339432", "0.8339432", "0.8215476", "0.8170543", "0.81325805", "0.81083655", "0.8029733", "0.79742086", "0.79505277", "0.7945828", "0.7903513", "0.78803533", "0.7869478", "0.7869478", "0.786660...
0.82522625
8
remove all datasets from the database
def clear @data_base = {} update_database end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def clear_all_training_data\n @redis.flushdb\n end", "def clear_all\n data.delete_all\n self\n end", "def db_clear\n [Project, Milestone, Category, Version, LoaderRelease].each {|x| x.delete_all}\n end", "def delete_data\n Report.plugin_matrix.each do |resource_name, measurements|\n ...
[ "0.7491438", "0.74581385", "0.7424967", "0.7386387", "0.7274484", "0.7266756", "0.7218508", "0.7147363", "0.7147363", "0.7122354", "0.7034323", "0.70120376", "0.6946944", "0.6871233", "0.6861377", "0.6859725", "0.6848152", "0.68355423", "0.6832847", "0.6832847", "0.6814514", ...
0.67337245
28
deletes the current database file and locks the databaseobject so it can't be used anymore
def destroy File.delete @filepath @data_base = nil @data_base.freeze self.freeze end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy_file\n db_file.destroy if db_file\n end", "def remove_database\n FileUtils.rm_rf(path) if File.exist? File.join(path, \"record.DB\")\n @database = nil\n @writable_database = nil\n end", "def db_remove!( db_file )\n ####db = SQLite3::Database.new( db_...
[ "0.7697805", "0.75146294", "0.7470848", "0.7455033", "0.7455033", "0.7414859", "0.7325822", "0.73124635", "0.7200124", "0.7042714", "0.70140195", "0.7002019", "0.6919434", "0.6894008", "0.683676", "0.6791752", "0.67685956", "0.6756731", "0.6742149", "0.6736616", "0.6731226", ...
0.6431535
43
returns all keys which are actually in the database
def all @data_base.keys.dup || [] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def keys\n db.keys\n end", "def keys\n in_transaction\n @table.keys\n end", "def key_ids\n @keys.keys\n end", "def keys\n @keys ||= [column_for_order_by(relation), primary_key].compact.uniq\n end", "def list_keys()\n # TODO\n end", "def list_keys\n @key...
[ "0.8418037", "0.79051006", "0.7659759", "0.7601798", "0.748141", "0.743819", "0.733117", "0.73159903", "0.7309677", "0.72958034", "0.7214971", "0.7214971", "0.7214971", "0.7199356", "0.7184442", "0.7184442", "0.71515733", "0.7144018", "0.7110938", "0.6998609", "0.6985973", ...
0.0
-1
returns all keys in the database that matches the given patternstring
def search pattern results = all.map {|key| key if key.to_s =~ /#{pattern}/i } results.delete nil results end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def search(pattern)\n # Initialize loop variables\n cursor = nil\n list = []\n\n # Scan and capture matching keys\n client.with do |conn|\n while cursor != 0\n scan = conn.scan(cursor || 0, match: pattern)\n list += scan[1]\n cursor = scan[0].to_i\n ...
[ "0.7021113", "0.66334707", "0.62938374", "0.603842", "0.5994442", "0.5990652", "0.5965526", "0.5960227", "0.5935934", "0.5688341", "0.56434625", "0.56318486", "0.56202286", "0.558281", "0.55575246", "0.55171186", "0.54890215", "0.5447953", "0.5431533", "0.54214734", "0.541031...
0.7493812
0
ask the database if exactly this key is already used in it.
def include? key @data_base.has_key? key end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def used_key?(key)\n @used_keys ||= find_source_keys.to_set\n @used_keys.include?(key)\n end", "def no_duplicate_key_for_project\n project = Project.find(project_id)\n key = project.keys.find_by(name: name)\n\n if key.present?\n updating_key = key.id == id\n\n errors.add(:na...
[ "0.6791715", "0.6708791", "0.65402406", "0.649873", "0.6380017", "0.6342208", "0.63250047", "0.6259866", "0.62287414", "0.6206142", "0.6191808", "0.616828", "0.61108756", "0.61031026", "0.6081358", "0.6081358", "0.6081358", "0.6081358", "0.6081358", "0.6081358", "0.6050091", ...
0.0
-1
If the string already ends with a number, the number should be incremented by 1. If the string does not end with a number the number 1 should be appended to the new string. Examples: foo > foo1 foobar23 > foobar24 foo0042 > foo0043 foo9 > foo10 foo099 > foo100 Attention: If the number has leading zeros the amount of digits should be considered.
def increment_string(input) n = input.size i = n - 1 numbers = '0'..'9' while i >= 0 if !numbers.include?(input[i]) break end i -= 1 end numbers_size = input[i + 1..-1].size last_numbers = input[i + 1..-1].to_i + 1 string = i == -1 ? '' : input[0..i] [string, "%.#{numbers_size}d" % last_numbers].join end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def increment_string(s)\n s.sub(/\\d*$/) {|n| n.empty? ? 1 : n.succ}\nend", "def increment_string(input)\n return input + '1' if !(input[-1] =~ /[0-9]/)\n split = input.scan(/\\d+|\\D+/)\n no_num = true\n res = ''\n split.each do |item|\n if (item.scan(/\\D/).empty?)\n item = it...
[ "0.72642416", "0.72478485", "0.7205423", "0.71259904", "0.7067354", "0.6921847", "0.68015295", "0.63036674", "0.60132045", "0.59779274", "0.594273", "0.5876225", "0.5876225", "0.5861947", "0.58377105", "0.57949567", "0.57454807", "0.5724523", "0.5686575", "0.5681013", "0.5648...
0.7189041
3
tells the stats to add a visit
def add_visit(db_connection=nil) Stats.add_visit(db_connection) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def add_visit\n self.increment!(:visits, 1)\n end", "def add_visit\n self.visits += 1\n self.date_last_visit = DateTime.now\n end", "def visit\n self.update(last_visit: DateTime.now);\n self.update(visit_count: (self.visit_count + 1));\n end", "def add_visitor(id, activity, time)\n\t\...
[ "0.800227", "0.7901515", "0.69909644", "0.67208576", "0.6693521", "0.6503604", "0.6364461", "0.6364461", "0.6182799", "0.6151161", "0.61395323", "0.61348635", "0.6118528", "0.5959411", "0.59488004", "0.5932659", "0.58932513", "0.5881809", "0.5870586", "0.58602935", "0.5859802...
0.75461507
2
tells the stats to add a visit
def add_pending(db_connection=nil) Stats.add_pending(db_connection) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def add_visit\n self.increment!(:visits, 1)\n end", "def add_visit\n self.visits += 1\n self.date_last_visit = DateTime.now\n end", "def add_visit(db_connection=nil)\n\t\t\t\tStats.add_visit(db_connection)\n\t\t\tend", "def visit\n self.update(last_visit: DateTime.now);\n self.update(vis...
[ "0.800227", "0.7901515", "0.75461507", "0.69909644", "0.67208576", "0.6693521", "0.6503604", "0.6364461", "0.6364461", "0.6182799", "0.6151161", "0.61395323", "0.61348635", "0.6118528", "0.5959411", "0.59488004", "0.5932659", "0.58932513", "0.5881809", "0.5870586", "0.5860293...
0.0
-1
tells the stats to add a visit
def add_completed(db_connection=nil) Stats.add_completed(db_connection) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def add_visit\n self.increment!(:visits, 1)\n end", "def add_visit\n self.visits += 1\n self.date_last_visit = DateTime.now\n end", "def add_visit(db_connection=nil)\n\t\t\t\tStats.add_visit(db_connection)\n\t\t\tend", "def visit\n self.update(last_visit: DateTime.now);\n self.update(vis...
[ "0.800227", "0.7901515", "0.75461507", "0.69909644", "0.67208576", "0.6693521", "0.6503604", "0.6364461", "0.6364461", "0.6182799", "0.6151161", "0.61395323", "0.61348635", "0.6118528", "0.5959411", "0.59488004", "0.5932659", "0.58932513", "0.5881809", "0.5870586", "0.5860293...
0.0
-1
get totals from stats
def total_pending(db_connection=nil) pending = Stats.pending(db_connection) pending.nil? ? 0 : pending end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def stats\n\t\t@counts\n\tend", "def getTotals\n totals = calculateTotals(@bankAccountBalances)\n @totalAvailable = totals[:totalAvailable]\n @totalCreditUsed = totals[:totalCreditUsed]\n @totalCredit = totals[:totalCredit]\n @totalCash = totals[:totalCash]...
[ "0.7074802", "0.70418394", "0.703028", "0.697963", "0.68875206", "0.68605363", "0.6840074", "0.68275374", "0.6809145", "0.6776142", "0.67570454", "0.672349", "0.67095876", "0.6676943", "0.6660788", "0.66296667", "0.66234577", "0.6602263", "0.65994245", "0.6541505", "0.6534887...
0.0
-1
get totals from stats
def total_visits(db_connection=nil) visits = Stats.visits(db_connection) visits.nil? ? 0 : visits end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def stats\n\t\t@counts\n\tend", "def getTotals\n totals = calculateTotals(@bankAccountBalances)\n @totalAvailable = totals[:totalAvailable]\n @totalCreditUsed = totals[:totalCreditUsed]\n @totalCredit = totals[:totalCredit]\n @totalCash = totals[:totalCash]...
[ "0.7074802", "0.70418394", "0.703028", "0.697963", "0.68875206", "0.68605363", "0.6840074", "0.68275374", "0.6809145", "0.6776142", "0.67570454", "0.672349", "0.67095876", "0.6676943", "0.6660788", "0.66296667", "0.66234577", "0.6602263", "0.65994245", "0.6541505", "0.6534887...
0.0
-1
helper method to interact with Stats and get completed transactions
def total_completed(db_connection=nil) completed = Stats.completed(db_connection) completed.nil? ? 0 : completed end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def getTransactions\n\t\t\n\tend", "def tally\n\t\t\treturn if completed?\n\t\t\tcomplete if consensus?\n\t\tend", "def audit\n\t\t\treturn if completed?\n\t\t\trefresh\n\t\t\ttally\n\t\tend", "def eth_pendingTransactions()\r\n response = do_request(\"eth_pendingTransactions\")\r\n response[\"result\"]...
[ "0.59353656", "0.58025336", "0.57140356", "0.565213", "0.56452537", "0.56288785", "0.56140333", "0.5603004", "0.5591703", "0.5591273", "0.5590241", "0.557806", "0.55635965", "0.5536177", "0.552484", "0.5502738", "0.5486632", "0.5478328", "0.5476234", "0.54564375", "0.5433997"...
0.56642926
3
Prints details if we're in debug mode This method is also the primary way for logging information. As such, we don't return immediately if debug is false. We let the system log properly, and skip display info if debug is false.
def debug(str, use_title=false, use_prefix=true, log_type="info") title = "DEBUG: " if use_title prefix = str_prefix.brown if use_prefix # print to screen # puts "#{title}#{str}" if Config.debug # strip of colors and log each line str.split("\n").each do |line| puts "#{prefix}#{title}#{line}" if Config.debug case log_type when "warn" logger.warn "#{prefix}#{line}".no_colors when "error" logger.error "#{prefix}#{line}".no_colors when "fatal" logger.fatal "#{prefix}#{line}".no_colors else logger.info "#{prefix}#{line}".no_colors end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def debug(info)\n puts(info) if @debug\n end", "def debug?; @logger.debug? end", "def debug(message)\n puts message if debug?\n end", "def debug_msg msg\n puts msg if @options[:debug]\n end", "def debug(*info)\n puts(info) if debug_mode?\n end", "def debug(message)\n puts \"#...
[ "0.76799315", "0.73318917", "0.73278046", "0.7297717", "0.72073233", "0.7188241", "0.717657", "0.717657", "0.71580017", "0.7121736", "0.7079596", "0.7079596", "0.70756656", "0.70756656", "0.70190936", "0.69965464", "0.6991957", "0.69879776", "0.6981324", "0.69742274", "0.6935...
0.0
-1
Used to define prefixes for strings, useful for prepending strings when logging on an API.
def str_prefix "" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def prefixes; end", "def prefixes; end", "def set_prefix\n @prefix = @str[@i_last_real_word...@i]\n end", "def prefix\n regexify(bothify(fetch('aircraft.prefix')))\n end", "def set_prefix\n if self.prefix.nil? && self.title.present?\n self.prefix = self.title.to_s.gsub(/\\W/, '').do...
[ "0.74268776", "0.74268776", "0.7346762", "0.7153151", "0.6973243", "0.694192", "0.68892187", "0.6860686", "0.6839256", "0.6782157", "0.6774691", "0.67715603", "0.6761287", "0.67492497", "0.67492497", "0.67492497", "0.67492497", "0.67492497", "0.67492497", "0.67492497", "0.674...
0.69233906
6
expects seconds, returns pretty string of how long ago event happened
def ago(seconds) a = seconds case a when 0 then "just now" when 1 then "a second ago" when 2..59 then a.to_s+" seconds ago" when 60..119 then "a minute ago" #120 = 2 minutes when 120..3540 then (a/60).to_i.to_s+" minutes ago" when 3541..7100 then "an hour ago" # 3600 = 1 hour when 7101..82800 then ((a+99)/3600).to_i.to_s+" hours ago" when 82801..172000 then "a day ago" # 86400 = 1 day when 172001..518400 then ((a+800)/(60*60*24)).to_i.to_s+" days ago" when 518400..1036800 then "a week ago" else ((a+180000)/(60*60*24*7)).to_i.to_s+" weeks ago" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def str_elapsed(t)\n seconds = Time.now.to_i - t\n return \"now\" if seconds <= 1\n\n length,label = time_lengths.select{|length,label| seconds >= length }.first\n units = seconds/length\n \"#{units} #{label}#{'s' if units > 1} ago\"\nend", "def time_delta_string( seconds )\n\t\treturn 'less than ...
[ "0.7721816", "0.74875385", "0.74875385", "0.72973007", "0.72705775", "0.72553474", "0.7114658", "0.71025014", "0.7084227", "0.7083646", "0.7047309", "0.7047309", "0.7004769", "0.69620675", "0.6959345", "0.6830403", "0.6817629", "0.66736764", "0.66571516", "0.6635283", "0.6629...
0.7444513
3
expects seconds, returns pretty string of expected time
def time_from_now(a) # where a is seconds case a when -1 then "never" when 0 then "just now" when 1 then "in one second" when 2..59 then "in #{a.to_s} seconds" when 60..119 then "in a minute" #120 = 2 minutes when 120..3540 then "in #{(a/60).to_i.to_s} minutes" when 3541..7100 then "in an hour" # 3600 = 1 hour when 7101..82800 then "in #{((a+99)/3600).to_i.to_s} hours" when 82801..172000 then "in one day" # 86400 = 1 day when 172001..518400 then "in #{((a+800)/(60*60*24)).to_i.to_s} days" when 518401..1036800 then "in a week" when 1036801..2433600 then "in #{((a+180000)/(60*60*24*7)).to_i.to_s} weeks" else "in #{((a+180000)/(60*60*24*7) / 4).to_i.to_s} month(s)" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def to_s(pretty=true)\n d, h, m, s, ms = elapsed\n e_t = (d > 0) ? \"#{d.to_s}d \" : ''\n if pretty\n e_t += ('%02u:' % [h]) if (d + h) > 0\n e_t += ('%02u:' % [m]) if (d + h + m) > 0\n e_t += '%02u.%03u' % [s, ms]\n else\n e_t << '%02u:%02u:%02u.%03u' % [h,m,s, ms]\n e...
[ "0.78108263", "0.7705276", "0.7663069", "0.75919735", "0.75919735", "0.7461361", "0.74610966", "0.7408606", "0.7369918", "0.732313", "0.732313", "0.73185545", "0.7310012", "0.7278474", "0.72704077", "0.725364", "0.7241579", "0.7231101", "0.7203659", "0.7192034", "0.7183426", ...
0.0
-1
Returns the allowed parameters for searching Override this method in each API controller to permit additional parameters to search on
def query_params {} end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def fetch_custom_search_params; end", "def allowed_params\n ALLOWED_PARAMS\n end", "def allowed_query_params\n %w[include fields filter sort page]\n end", "def search_params\n return {} unless params[:q]\n params.require(:q).permit!\n end", "def authorize_params\n supe...
[ "0.7116965", "0.7063077", "0.70261276", "0.69101655", "0.6675816", "0.66757613", "0.66730446", "0.6590211", "0.6570296", "0.65337676", "0.65146834", "0.6493318", "0.6491095", "0.6453244", "0.6448963", "0.6441784", "0.6441784", "0.6441512", "0.6432283", "0.63979596", "0.638511...
0.0
-1
Returns the allowed parameters for pagination
def page_params params.permit(:page, :page_size) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def page_params\n []\n end", "def pagination_params()\n normalize_param_value(:_pg).permit(:_s, :_p, :_c)\n end", "def page_params \n params.has_key?(:pagination) ? get_page_params( params.require(:pagination) ) : {}\n end", "def resource_filter_permitted_pa...
[ "0.76857114", "0.7512498", "0.75010765", "0.7465051", "0.7355113", "0.73507315", "0.72727937", "0.72162175", "0.7178052", "0.7162399", "0.7093898", "0.7074553", "0.7042996", "0.69556296", "0.6861541", "0.6791525", "0.6772349", "0.675252", "0.6740167", "0.67333084", "0.6706315...
0.63966185
43
The resource class based on the controller
def resource_class @resource_class ||= resource_name.classify.constantize end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def resource_class\n @resource_class ||= self.controller_name.singularize.classify.constantize\n end", "def resource_class\n name = controller.controller_name\n return \"active\" if name == \"resources\"\n end", "def resource_klass\n resource_klass_name.constantize\n end", "def resource_cl...
[ "0.8618411", "0.8433249", "0.82288253", "0.81042385", "0.80751187", "0.8063445", "0.8029621", "0.8029621", "0.8029621", "0.8021062", "0.8001003", "0.7984989", "0.79841983", "0.7955573", "0.791964", "0.7886186", "0.78640455", "0.78640455", "0.7859555", "0.7833819", "0.7816878"...
0.80970544
6
The singular name for the resource class based on the controller
def resource_name @resource_name ||= self.controller_name.singularize end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def resource_name\n name.to_s.chomp('Controller').demodulize.singularize\n end", "def get_resource_name\n \tself.controller_name.singularize\n end", "def resource_name\n @resource_name ||= controller_name.singularize\n end", "def resource_name\n @resource_name...
[ "0.861274", "0.85466033", "0.8507382", "0.8507382", "0.84701234", "0.84701234", "0.84701234", "0.8435745", "0.8435745", "0.8416853", "0.84051806", "0.83983785", "0.8360254", "0.83439785", "0.8292862", "0.8278734", "0.8278734", "0.8278734", "0.8240594", "0.8230048", "0.8191882...
0.85093474
3
Use callbacks to share common setup or constraints between actions.
def set_resource(resource = nil) resource ||= resource_class.find(params[:id]) instance_variable_set("@#{resource_name}", resource) 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
Ignores paths that match one of the +patterns+, where each pattern is either a String or Regexp
def ignore(*patterns) @ignore_patterns += patterns end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def filepath_pattern(filepaths)\n return \"\" if filepaths.nil?\n\n filepaths.map! { |path| '^' + path + '$' }\n filepaths.join('|')\n end", "def except(files,patterns)\n if !patterns.kind_of?(Array)\n patterns = [patterns]\n end\n files.select do...
[ "0.64656574", "0.6440371", "0.62837595", "0.616731", "0.61536866", "0.61519104", "0.61386895", "0.6123225", "0.6095911", "0.6093292", "0.608335", "0.6010574", "0.600144", "0.60002035", "0.5984666", "0.59718233", "0.59432685", "0.5871464", "0.58667815", "0.58551836", "0.581249...
0.6767975
0
Initialize sequence === Parameter bundle(RightScale::ExecutableBundle):: Bundle to be run
def initialize(bundle) @description = bundle.to_s @thread_name = get_thread_name_from_bundle(bundle) @right_scripts_cookbook = RightScriptsCookbook.new(@thread_name) @scripts = bundle.executables.select { |e| e.is_a?(RightScriptInstantiation) } @only_scripts = bundle.executables.all? { |e| e.is_a?(RightScriptInstantiation) } run_list_recipes = bundle.executables.map { |e| e.is_a?(RecipeInstantiation) ? e : @right_scripts_cookbook.recipe_from_right_script(e) } @cookbooks = bundle.cookbooks @downloader = ReposeDownloader.new(bundle.repose_servers) @downloader.logger = Log @download_path = File.join(AgentConfig.cookbook_download_dir, @thread_name) @ohai_retry_delay = OHAI_RETRY_MIN_DELAY @audit = AuditStub.instance @logger = Log @cookbook_repo_retriever= CookbookRepoRetriever.new(@download_path, bundle.dev_cookbooks) # Determine which inputs are sensitive sensitive = Set.new([]) bundle.executables.each do |e| next unless e.input_flags.respond_to?(:each_pair) e.input_flags.each_pair do |name, flags| sensitive << name if flags.include?(SENSITIVE) end end @sensitive_inputs = sensitive.to_a # Initialize run list for this sequence (partial converge support) @run_list = [] @inputs = { } breakpoint_recipe = CookState.breakpoint_recipe run_list_recipes.each do |recipe| if recipe.nickname == breakpoint_recipe @audit.append_info("Breakpoint set to < #{breakpoint_recipe} >") break end @run_list << recipe.nickname ::RightSupport::Data::HashTools.deep_merge!(@inputs, recipe.attributes) end # Retrieve node attributes and deep merge in inputs @attributes = ChefState.attributes ::RightSupport::Data::HashTools.deep_merge!(@attributes, @inputs) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def run_bundle ; end", "def run_bundle ; end", "def run_bundle; end", "def run_bundle\n end", "def bundle()\n puts \"TODO\"\n end", "def run_boot_bundle(bundle)\n @got_boot_bundle = true\n\n # Force full converge on boot so that Chef state gets persisted\n context = RightScale::Op...
[ "0.75413233", "0.75413233", "0.75091153", "0.7491439", "0.6779649", "0.64694744", "0.6198821", "0.618599", "0.6156915", "0.6085191", "0.5987268", "0.5946747", "0.59432334", "0.5778806", "0.57550746", "0.5745821", "0.5745821", "0.5723512", "0.5723512", "0.5704936", "0.5665234"...
0.6900627
4
FIX: thread_name should never be nil from the core in future, but temporarily we must supply the default thread_name before if nil. in future we should fail execution when thread_name is reliably present and for any reason does not match ::RightScale::AgentConfig.valid_thread_name see also ExecutableSequenceProxyinitialize === Parameters bundle(ExecutableBundle):: An executable bundle === Return result(String):: Thread name of this bundle
def get_thread_name_from_bundle(bundle) thread_name = nil thread_name = bundle.runlist_policy.thread_name if bundle.respond_to?(:runlist_policy) && bundle.runlist_policy Log.warn("Encountered a nil thread name unexpectedly, defaulting to '#{RightScale::AgentConfig.default_thread_name}'") unless thread_name thread_name ||= RightScale::AgentConfig.default_thread_name unless thread_name =~ RightScale::AgentConfig.valid_thread_name raise ArgumentError, "Invalid thread name #{thread_name.inspect}" end thread_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set_thread_name(name); end", "def update_native_thread_name\n thread = JRuby.reference(Thread.current)\n set_thread_name = Proc.new do |prefix, suffix|\n self.class.with_global_lock do\n count = self.class.system_registered_workers.size\n thread.native_thread.name = \"#{pre...
[ "0.640239", "0.6320803", "0.56889015", "0.5569603", "0.55232155", "0.54864717", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.54715884", "0.5448868", "0.5353114", "0.5353114", "0.5308361", "0.5...
0.8200282
0
FIX: This code can be removed once the core sends a runlist policy === Parameters bundle(ExecutableBundle):: An executable bundle === Return result(String):: Policy name of this bundle
def get_policy_name_from_bundle(bundle) policy_name = nil policy_name ||= bundle.runlist_policy.policy_name if bundle.respond_to?(:runlist_policy) && bundle.runlist_policy policy_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def bundle_name; bundle.bundle_name; end", "def bundle\n content.split('bundle ').last.split(\",\").map(&:to_i).to_s\n end", "def policy_run_list(policy)\n # Read the policy file\n dsl_parser = DslParser.new\n policy_file = \"#{@repository_path}/policyfiles/#{policy}.rb\"\n ...
[ "0.6721721", "0.59534883", "0.5902903", "0.58423495", "0.58411974", "0.5492809", "0.54894054", "0.5396483", "0.5368266", "0.5364853", "0.5329899", "0.5309622", "0.5301748", "0.5301748", "0.5277199", "0.5234763", "0.52341723", "0.5187355", "0.51717234", "0.5171046", "0.5155853...
0.8014939
0
Run given executable bundle Asynchronous, set deferrable object's disposition === Return true:: Always return true
def run @ok = true if @run_list.empty? # Deliberately avoid auditing anything since we did not run any recipes # Still download the cookbooks repos if in dev mode checkout_cookbook_repos download_cookbooks if CookState.cookbooks_path report_success(nil) else configure_ohai configure_logging configure_chef download_attachments if @ok install_packages if @ok checkout_cookbook_repos if @ok download_cookbooks if @ok update_cookbook_path if @ok # note that chef normally enforces path sanity before executing ohai in # the client run method. we create ohai before client run and some ohai # plugins behave badly when there is no ruby on the PATH. we need to do # a pre-emptive path sanity here before we start ohai and chef. enforce_path_sanity check_ohai { |o| converge(o) } if @ok end true rescue Exception => e report_failure('Execution failed', "The following exception was caught while preparing for execution: (#{e.message}) from\n#{e.backtrace.join("\n")}") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def executable?; true; end", "def executable?; true; end", "def executable?\n true\n end", "def executable?() end", "def run_bundle; end", "def executable_real?() end", "def run_bundle ; end", "def run_bundle ; end", "def run_bundle\n end", "def run_executable(full_commandline)\n ...
[ "0.62251294", "0.62251294", "0.58608675", "0.5798406", "0.57856154", "0.568163", "0.564137", "0.564137", "0.56192416", "0.5449035", "0.53158593", "0.52779496", "0.52674556", "0.52387947", "0.5236254", "0.52262443", "0.5202567", "0.5181976", "0.514788", "0.5141558", "0.5135659...
0.0
-1
Determine inputs that need special security treatment.
def sensitive_inputs inputs = {} if @attributes @attributes.values.select { |attr| attr.respond_to?(:has_key?) && attr.has_key?("parameters") }.each do |has_params| has_params.each_pair do |_, params| sensitive = params.select { |name, _| @sensitive_inputs.include?(name) } inputs.merge!(sensitive) { |key, old, new| [old].flatten.push(new) } end end end inputs end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_against_input_for_specials(data)\r\n @field_names[1..-1].each do |f|\r\n raise(ArgumentError,\r\n 'You cannot input a value for this field: %s' % f) if \\\r\n @field_extras[@field_names.index(f)].has_key?('Calculated') \\\r\n or @field_extras[@field_n...
[ "0.59796464", "0.5875326", "0.5870655", "0.58400524", "0.57902145", "0.5767832", "0.57079715", "0.5677019", "0.56409985", "0.55715865", "0.553905", "0.5531774", "0.5480904", "0.5476154", "0.5475008", "0.5467877", "0.54595494", "0.5458006", "0.54439867", "0.54326093", "0.54203...
0.57491654
6
Initialize and configure the logger
def configure_logging Chef::Log.logger = AuditLogger.new(sensitive_inputs) Chef::Log.logger.level = Log.level_from_sym(Log.level) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def setup\n self.logger.reopen(File.open(File.join(Lokii::Config.root, Lokii::Config.log), \"a\")) if daemon? && self.logger\n self.logger ||= ::Logger.new(File.join(Lokii::Config.root, Lokii::Config.log))\n end", "def configure_logging\n @logger = Logging.logger[self]\n end", "def i...
[ "0.80824965", "0.79576933", "0.7717282", "0.7610356", "0.7602989", "0.7549991", "0.7451713", "0.7442536", "0.7437525", "0.7384599", "0.7384599", "0.7384599", "0.7345961", "0.73392206", "0.7306794", "0.72627014", "0.72408885", "0.7193096", "0.7170017", "0.71616703", "0.7159710...
0.65032643
79
Configure chef so it can find cookbooks and so its logs go to the audits === Return true:: Always return true
def configure_chef # setup logger for mixlib-shellout gem to consume instead of the chef # v0.10.10 behavior of not logging ShellOut calls by default. also setup # command failure exception and callback for legacy reasons. ::Mixlib::ShellOut.default_logger = ::Chef::Log ::Mixlib::ShellOut.command_failure_callback = lambda do |params| failure_reason = ::RightScale::SubprocessFormatting.reason(params[:status]) expected_error_codes = Array(params[:args][:returns]).join(' or ') ::RightScale::Exceptions::Exec.new("\"#{params[:args][:command]}\" #{failure_reason}, expected #{expected_error_codes}.", params[:args][:cwd]) end # Chef run mode is always solo for cook Chef::Config[:solo] = true # determine default cookbooks path. If debugging cookbooks, place the debug pat(s) first, otherwise # clear out the list as it will be filled out with cookbooks needed for this converge as they are downloaded. if CookState.use_cookbooks_path? Chef::Config[:cookbook_path] = [CookState.cookbooks_path].flatten @audit.append_info("Using development cookbooks repositories path:\n\t- #{Chef::Config[:cookbook_path].join("\n\t- ")}") else # reset the cookbook path. Will be filled out with cookbooks needed for this execution Chef::Config[:cookbook_path] = [] end # add the rightscript cookbook if there are rightscripts in this converge Chef::Config[:cookbook_path] << @right_scripts_cookbook.repo_dir unless @right_scripts_cookbook.empty? # must set file cache path and ensure it exists otherwise evented run_command will fail file_cache_path = File.join(AgentConfig.cache_dir, 'chef') Chef::Config[:file_cache_path] = file_cache_path FileUtils.mkdir_p(Chef::Config[:file_cache_path]) Chef::Config[:cache_options][:path] = File.join(file_cache_path, 'checksums') FileUtils.mkdir_p(Chef::Config[:cache_options][:path]) # Where backups of chef-managed files should go. Set to nil to backup to the same directory the file being backed up is in. Chef::Config[:file_backup_path] = nil # Chef 11+ defaults client_fork to true which cause Chef::Client to fork # This create problems with right_popen - right_popen expects to be used inside running EM reactor # EM seems not to play well with forking Chef::Config[:client_fork] = false # Chef 11+ allow concurrent execution of the recipes in different theads, # by setting different lockfile per thread. Chef::Config[:lockfile] = File.join(Chef::Config[:file_cache_path], "chef-client-#{@thread_name}-running.pid") true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def cookbooks_repo_installed?\n cmd_test %{-d \"#{cookbooks_path}\"}\nend", "def init\n clone_appd_cookbook\n chef_gem \"install berkshelf\"\n end", "def cookbook?\n File.exist? \"#{@config.workspace}/metadata.rb\"\n end", "def run\n @ok = true\n if @run_list.empty?\n ...
[ "0.66979605", "0.66466534", "0.65091324", "0.64699507", "0.6458503", "0.6396524", "0.6339164", "0.6301655", "0.6281023", "0.6260288", "0.6243344", "0.6239237", "0.6176029", "0.61685616", "0.61540645", "0.61425656", "0.6122556", "0.60796165", "0.60473883", "0.60473704", "0.600...
0.71186686
0
Update the Chef cookbook_path based on the cookbooks in the bundle. === Return true:: Always return true
def update_cookbook_path # both cookbook sequences and paths are listed in same order as # presented in repo UI. previous to RL v5.7 we received cookbook sequences # in an arbitrary order, but this has been fixed as of the release of v5.8 # (we will not change the order for v5.7-). # for chef to execute repos and paths in the order listed, both of these # ordered lists need to be inserted in reverse order because the chef code # replaces cookbook paths as it reads the array from beginning to end. @cookbooks.reverse.each do |cookbook_sequence| local_basedir = File.join(@download_path, cookbook_sequence.hash) cookbook_sequence.paths.reverse.each do |path| dir = File.expand_path(File.join(local_basedir, path)) unless Chef::Config[:cookbook_path].include?(dir) if File.directory?(dir) Chef::Config[:cookbook_path] << dir else RightScale::Log.info("Excluding #{path} from chef cookbooks_path because it was not downloaded") end end end end RightScale::Log.info("Updated cookbook_path to: #{Chef::Config[:cookbook_path].join(", ")}") true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_cookbooks()\n self.resolver.debug = self.options[:debug]\n unless File.exists?(\"cookbooks\")\n\tKitchenplan::Log.info \"No cookbooks directory found. Running Librarian to download necessary cookbooks.\"\n\tself.normaldo self.resolver.fetch_dependencies()\n\t#self.normaldo \"bin/librarian-che...
[ "0.7329989", "0.72830844", "0.707539", "0.7008509", "0.7007884", "0.6989867", "0.6899714", "0.6713638", "0.6699426", "0.650239", "0.6456651", "0.640919", "0.64003813", "0.63994443", "0.63476104", "0.63256276", "0.6310758", "0.63061094", "0.627209", "0.6270353", "0.62605184", ...
0.798844
0
Checkout repositories for selected cookbooks. Audit progress and errors, do not fail on checkout error. === Return true:: Always return true
def checkout_cookbook_repos return true unless @cookbook_repo_retriever.has_cookbooks? @audit.create_new_section('Checking out cookbooks for development') @audit.append_info("Cookbook repositories will be checked out to #{@cookbook_repo_retriever.checkout_root}") audit_time do # only create a scraper if there are dev cookbooks @cookbook_repo_retriever.checkout_cookbook_repos do |state, operation, explanation, exception| # audit progress case state when :begin @audit.append_info("start #{operation} #{explanation}") if AUDIT_BEGIN_OPERATIONS.include?(operation) when :commit @audit.append_info("finish #{operation} #{explanation}") if AUDIT_COMMIT_OPERATIONS.include?(operation) when :abort @audit.append_error("Failed #{operation} #{explanation}") Log.error(Log.format("Failed #{operation} #{explanation}", exception, :trace)) end end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def downloadAndCheckout\n if Dir.exist?(SRC_DIR)\n puts \"Already downloaded sane-projets/backends\"\n puts \"\"\n return\n end\n\n puts \"Cloning sane-projets/backends\"\n systemWithLog(\"git clone https://gitlab.com/sane-project/backends.git \\\"#{SRC_DIR}\\\"\")\n\n puts \"Ch...
[ "0.66081643", "0.6218496", "0.6163712", "0.6094106", "0.608661", "0.60530233", "0.6049368", "0.6037005", "0.5935852", "0.5921821", "0.58933836", "0.5891284", "0.5875168", "0.5850343", "0.5825168", "0.57862204", "0.5715695", "0.57004106", "0.5679497", "0.5599189", "0.55912733"...
0.8333094
0
Download a cookbook from Repose mirror and extract it to the filesystem. === Parameters root_dir(String):: subdir of basedir into which this cookbook goes cookbook(Cookbook):: cookbook === Raise Propagates exceptions raised by callees, namely DownloadFailure and ReposeServerFailure === Return true:: always returns true
def download_cookbook(root_dir, cookbook) cache_dir = File.join(AgentConfig.cache_dir, "right_link", "cookbooks") cookbook_tarball = File.join(cache_dir, "#{cookbook.hash.split('?').first}.tar") begin FileUtils.mkdir_p(cache_dir) File.open(cookbook_tarball, "ab") do |tarball| if tarball.stat.size == 0 #audit cookbook name & part of hash (as a disambiguator) name = cookbook.name ; tag = cookbook.hash[0..4] @audit.append_info("Downloading cookbook '#{name}' (#{tag})") @downloader.download("/cookbooks/#{cookbook.hash}") do |response| tarball << response end @audit.append_info(@downloader.details) end end rescue Exception => e File.unlink(cookbook_tarball) if File.exists?(cookbook_tarball) raise end @audit.append_info("Success; unarchiving cookbook") # The local basedir is the faux "repository root" into which we extract all related # cookbooks in that set, "related" meaning a set of cookbooks that originally came # from the same Chef cookbooks repository as observed by the scraper. # # Even though we are pulling individually-packaged cookbooks and not the whole repository, # we preserve the position of cookbooks in the directory hierarchy such that a given cookbook # has the same path relative to the local basedir as the original cookbook had relative to the # base directory of its repository. # # This ensures we will be able to deal with future changes to the Chef merge algorithm, # as well as accommodate "naughty" cookbooks that side-load data from the filesystem # using relative paths to other cookbooks. FileUtils.mkdir_p(root_dir) Dir.chdir(root_dir) do # note that Windows uses a "tar.cmd" file which is found via the PATH # used by the command interpreter. cmd = "tar xf #{cookbook_tarball.inspect} 2>&1" Log.debug(cmd) output = `#{cmd}` @audit.append_info(output) unless $?.success? report_failure("Unknown error", SubprocessFormatting.reason($?)) end end return true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def download_and_unpack_archive(uri, root)\n # all file types filtered here should be handled inside block.\n if uri.end_with?('.tgz', '.tar.gz', '.zip', 'jar')\n if uri.include? '://'\n print \"-----> Downloading from #{uri} ... \"\n else\n filename = File.basename(uri)\n...
[ "0.6004282", "0.5999161", "0.59020424", "0.5853307", "0.56942135", "0.56353956", "0.5630361", "0.5417467", "0.5308786", "0.52756333", "0.526868", "0.5203322", "0.5171715", "0.5154514", "0.51472116", "0.50985366", "0.507656", "0.5074247", "0.5065257", "0.5059091", "0.5058809",...
0.7174289
0
Checks whether Ohai is ready and calls given block with it if that's the case otherwise schedules itself to try again indefinitely === Block Given block should take one argument which corresponds to ohai instance === Return true:: Always return true
def check_ohai(&block) ohai = create_ohai if ohai[:hostname] block.call(ohai) else Log.warning("Could not determine node name from Ohai, will retry in #{@ohai_retry_delay}s...") # Need to execute on defer thread consistent with where ExecutableSequence is running # otherwise EM main thread command client activity will block EM.add_timer(@ohai_retry_delay) { EM.defer { check_ohai(&block) } } @ohai_retry_delay = [2 * @ohai_retry_delay, OHAI_RETRY_MAX_DELAY].min end true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def when_ready(&block)\n handle :ready, &block\n end", "def chef_ready?(host, timeout = 60, sleep_time = 10, options = {})\n timeout_at = Time.now + timeout\n ip = resolve_host(host)\n return false if ip.empty?\n msg = \"Waiting for already running chef-client on #{host} (#{ip}); next attempt...
[ "0.67343044", "0.60743815", "0.60704017", "0.60315657", "0.5968648", "0.5927596", "0.5809332", "0.578909", "0.56926954", "0.56846344", "0.56846344", "0.56833845", "0.5632724", "0.5606714", "0.56066644", "0.559929", "0.5578644", "0.5570312", "0.5567273", "0.5565425", "0.555684...
0.75591075
0
Creates a new ohai and configures it. === Return ohai(Ohai::System):: configured ohai
def create_ohai ohai = Ohai::System.new ohai.require_plugin('os') ohai.require_plugin('hostname') return ohai end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def setup_ohai\n Ohai::Config[:plugin_path] << ohai_plugin_path\n @ohai = Ohai::System.new\n @ohai.all_plugins\n end", "def initialize\n setup_ohai\n configure\n end", "def oai_config\n blacklight_config.oai || {}\n end", "def oai_config\n blacklight_config.oai || ...
[ "0.7730221", "0.743171", "0.64666766", "0.64666766", "0.6456146", "0.61655563", "0.6115309", "0.6115309", "0.59822303", "0.59393525", "0.58116955", "0.5810276", "0.56208444", "0.5574301", "0.5523388", "0.54178774", "0.5361537", "0.5348073", "0.53393084", "0.5323571", "0.53047...
0.85369354
0
Chef converge === Parameters ohai(Ohai):: Ohai instance to be used by Chef === Return true:: Always return true
def converge(ohai) begin # When the run_list consists solely of RightScripts, adding error or report # handlers is not possible. Suppress these extra features as they can # be confusing to users. Also makes for cleaner logs. if @only_scripts ::Chef::Client.clear_notifications end if @cookbooks.size > 0 @audit.create_new_section('Converging') else @audit.create_new_section('Preparing execution') end log_desc = "Log level is #{Log.level_to_sym(CookState.log_level)}" if CookState.dev_log_level log_desc << " (overridden by #{CookState::LOG_LEVEL_TAG}=#{CookState.dev_log_level})" end log_desc << '.' @audit.append_info(log_desc) @audit.append_info('The download once flag is set.') if CookState.download_once? @audit.append_info("Run list for thread #{@thread_name.inspect} contains #{@run_list.size} items.") @audit.append_info(@run_list.join(', ')) attribs = { 'run_list' => @run_list } attribs.merge!(@attributes) if @attributes c = Chef::Client.new(attribs) c.ohai = ohai audit_time do # Ensure that Ruby subprocesses invoked by Chef do not inherit our # RubyGems/Bundler environment. without_bundler_env do c.run end end rescue SystemExit => e # exit is expected in case where a script has invoked rs_shutdown # (command line tool or Chef resource). exit is considered to be # unexpected if rs_shutdown has not been called. note that it is # possible, but not a 'best practice', for a recipe (but not a # RightScript) to call rs_shutdown as an external command line utility # without calling exit (i.e. request a deferred reboot) and continue # running recipes until the list of recipes is complete. in this case, # the shutdown occurs after subsequent recipes have finished. the best # practice for a recipe is to use the rs_shutdown chef resource which # calls exit when appropriate. shutdown_request = RightScale::ShutdownRequestProxy.instance if shutdown_request.continue? report_failure('Execution failed due to rs_shutdown not being called before exit', chef_error(e)) Log.debug(Log.format("Execution failed", e, :trace)) else Log.info("Shutdown requested by script: #{shutdown_request}") end rescue Exception => e report_failure('Execution failed', chef_error(e)) Log.debug(Log.format("Execution failed", e, :trace)) ensure # kill the chef node provider RightScale::Windows::ChefNodeServer.instance.stop rescue nil if RightScale::Platform.windows? end report_success(c.node) if @ok true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def run\n @ok = true\n if @run_list.empty?\n # Deliberately avoid auditing anything since we did not run any recipes\n # Still download the cookbooks repos if in dev mode\n checkout_cookbook_repos\n download_cookbooks if CookState.cookbooks_path\n report_success(nil)\n ...
[ "0.64964914", "0.6309633", "0.6277236", "0.5994281", "0.5949486", "0.5912061", "0.5908381", "0.5879068", "0.5838477", "0.5749964", "0.5733629", "0.5725772", "0.57029873", "0.5683211", "0.56782246", "0.5675652", "0.56678057", "0.56612784", "0.5623351", "0.56047046", "0.5566636...
0.66310173
0
Initialize inputs patch and report success === Parameters node(ChefNode):: Chef node used to converge, can be nil (patch is empty in this case) === Return true:: Always return true
def report_success(node) ChefState.merge_attributes(node.normal_attrs) if node remove_right_script_params_from_chef_state patch = ::RightSupport::Data::HashTools.deep_create_patch(@inputs, ChefState.attributes) # We don't want to send back new attributes (ohai etc.) patch[:right_only] = { } @inputs_patch = patch EM.next_tick { succeed } true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def upload_cookbook_to_chef_server?(node)\n node['delivery']['config']['build_attributes']['publish']['chef_server']\n rescue\n false\n end", "def _update_chef_node\n step(\" updating chef node\", :blue)\n set_chef_node_attributes\n set_chef_node_environment\n sync_ip...
[ "0.55819607", "0.5518793", "0.54970145", "0.5335577", "0.52906305", "0.52667856", "0.5217386", "0.5143377", "0.5126166", "0.5075825", "0.50422454", "0.5018467", "0.50147533", "0.5009857", "0.50082636", "0.49759746", "0.49400288", "0.48829067", "0.48577815", "0.48217958", "0.4...
0.67314655
0
Set status with failure message and audit it === Parameters title(String):: Title used to update audit status msg(String):: Failure message === Return true:: Always return true
def report_failure(title, msg) @ok = false @failure_title = title @failure_message = msg # note that the errback handler is expected to audit the message based on # the preserved title and message and so we don't audit it here. EM.next_tick { fail } true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def failure\n @status = FAILURE_FLAG if @status == SUCCESS_FLAG\n end", "def set_failure_message(msg)\n @failure_message = \"#{FailureMessages::OBJECT_PREFIX} #{msg}\"\n false\n end", "def set_failure_message(msg)\n @failure_message = \"#{FailureMessages::GENERAL_PREFIX} #{msg}\"\n false\n...
[ "0.65329105", "0.62726337", "0.6233729", "0.61961967", "0.59666854", "0.59659576", "0.59659576", "0.5956677", "0.5956677", "0.5956677", "0.5956677", "0.5924393", "0.59160507", "0.59160507", "0.5875771", "0.58397436", "0.5789085", "0.5691932", "0.56825507", "0.5661255", "0.565...
0.71330917
0
Wrap chef exception with explanatory information and show context of failure === Parameters e(Exception):: Exception raised while executing Chef recipe === Return msg(String):: Human friendly error message
def chef_error(e) if e.is_a?(::RightScale::Exceptions::Exec) msg = "External command error: " if match = /RightScale::Exceptions::Exec: (.*)/.match(e.message) cmd_output = match[1] else cmd_output = e.message end msg += cmd_output msg += "\nThe command was run from \"#{e.path}\"" if e.path elsif e.is_a?(::Chef::Exceptions::ValidationFailed) && (e.message =~ /Option action must be equal to one of:/) msg = "[chef] recipe references an action that does not exist. #{e.message}" elsif e.is_a?(::NoMethodError) && (missing_action_match = /undefined method .action_(\S*)' for #<\S*:\S*>/.match(e.message)) && missing_action_match[1] msg = "[chef] recipe references the action <#{missing_action_match[1]}> which is missing an implementation" else msg = "Execution error:\n" msg += e.message file, line, meth = e.backtrace[0].scan(BACKTRACE_LINE_REGEXP).flatten line_number = line.to_i if file && line && (line_number.to_s == line) dir = AgentConfig.cookbook_download_dir if file[0..dir.size - 1] == dir path = "[COOKBOOKS]/" + file[dir.size..file.size] else path = file end msg += "\n\nThe error occurred line #{line} of #{path}" msg += " in method '#{meth}'" if meth context = "" if File.readable?(file) File.open(file, 'r') do |f| lines = f.readlines lines_count = lines.size if lines_count >= line_number upper = [lines_count, line_number + 2].max padding = upper.to_s.size context += context_line(lines, line_number - 2, padding) context += context_line(lines, line_number - 1, padding) context += context_line(lines, line_number, padding, '*') context += context_line(lines, line_number + 1, padding) context += context_line(lines, line_number + 2, padding) end end end msg += " while executing:\n\n#{context}" unless context.empty? end end msg end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def error_message(e)\n fail e\n end", "def humanize_exception(e)\n case e\n when SystemExit\n raise # make sure exit passes through.\n when Net::HTTPServerException, Net::HTTPFatalError\n humanize_http_exception(e)\n when Errno::ECONNREFUSED, Timeout::Error, Errn...
[ "0.68915695", "0.675157", "0.66563547", "0.6628109", "0.6610589", "0.6366542", "0.6328576", "0.6193008", "0.61456233", "0.60928696", "0.6085846", "0.6077272", "0.60675967", "0.60619193", "0.6035297", "0.60298836", "0.5959834", "0.59528303", "0.59461224", "0.5945109", "0.58976...
0.7788316
0
Format a single line for the error context, return empty string if given index is negative or greater than the lines array size === Parameters lines(Array):: Lines of text index(Integer):: Index of line that should be formatted for context padding(Integer):: Number of character to pad line with (includes prefix) prefix(String):: Single character string used to prefix line use line number if not specified
def context_line(lines, index, padding, prefix=nil) return '' if index < 1 || index > lines.size margin = prefix ? prefix * index.to_s.size : index.to_s "#{margin}#{' ' * ([padding - margin.size, 0].max)} #{lines[index - 1]}" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def formatted_context_lines\n if @formatted_context_lines.empty? then\n number_width = (\"%d\" % @context_line_numbers.last).length\n @context_lines.each_with_index do |line, idx|\n prefix = (idx == @context_index) ? CallSiteContext.pointer : CallSiteContext.not_pointer\n numbe...
[ "0.6097551", "0.57317483", "0.54719496", "0.5414139", "0.53927034", "0.53721607", "0.5290704", "0.5264514", "0.52496743", "0.52489656", "0.52433044", "0.5218234", "0.5193774", "0.5180323", "0.517801", "0.5127595", "0.5116125", "0.5109216", "0.51034284", "0.50819236", "0.50813...
0.765352
0
Retry executing given block given number of times Block should return true when it succeeds === Parameters retry_message(String):: Message to audit before retrying times(Integer):: Number of times block should be retried before giving up === Block Block to be executed === Return success(Boolean):: true if execution was successful, false otherwise.
def retry_execution(retry_message, times = AgentConfig.max_packages_install_retries) count = 0 success = false begin count += 1 success = yield @audit.append_info("\n#{retry_message}\n") unless success || count > times end while !success && count <= times success end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def retry_method(retry_time=1.minute)\n log(:info, \"Retrying in #{retry_time} seconds\")\n $evm.root['ae_result'] = 'retry'\n $evm.root['ae_retry_interval'] = retry_time\n exit MIQ_OK\n end", "def retry_on_error(retry_count, &block)\n block.call\n rescue ActiveRecord::Stat...
[ "0.6573847", "0.6314921", "0.6267273", "0.6244391", "0.6137222", "0.61286056", "0.60280174", "0.5956715", "0.5929349", "0.5891765", "0.5830872", "0.58248234", "0.58199006", "0.57952094", "0.5779256", "0.57612973", "0.5752444", "0.5716422", "0.5715196", "0.56979144", "0.569227...
0.7254494
0
Audit startup time and duration of given action === Block Block whose execution should be timed === Return res(Object):: Result returned by given block
def audit_time start_time = Time.now @audit.append_info("Starting at #{start_time}") res = yield @audit.append_info("Duration: #{'%.2f' % (Time.now - start_time)} seconds\n\n") res end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def profile block_description, &block\n start_time = Time.new\n block.call\n duration = Time.new - start_time\n puts \"#{block_description}: #{duration} seconds\"\nend", "def profile(description_of_block, &block)\n start_time = Time.now \n block.call \n duration = Time.now - start_time\n puts description...
[ "0.67223084", "0.67002195", "0.6694352", "0.6691383", "0.64139223", "0.6407259", "0.6311599", "0.6279347", "0.6105256", "0.6099677", "0.6046026", "0.6031701", "0.5894842", "0.58091223", "0.5806019", "0.5787548", "0.5772087", "0.5748335", "0.5730784", "0.5728183", "0.5728033",...
0.6849022
0
Use callbacks to share common setup or constraints between actions.
def set_laboratorio @laboratorio = Laboratorio.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
Only allow a list of trusted parameters through.
def laboratorio_create_params params.require(:laboratorio).permit(:nome, :endereco) 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.6946679", "0.6811753", "0.67995036", "0.679359", "0.67437977", "0.6738685", "0.6525698", "0.65186113", "0.6492684", "0.64316213", "0.64316213", "0.64316213", "0.6397299", "0.63539475", "0.63526994", "0.6344162", "0.63427454", "0.6336022", "0.63279474", "0.63279474", "0.632...
0.0
-1
GET /student/courses/1/notifies GET /student/courses/1/notifies.json
def index @notifies = Notify.where(:course_id => @course.id).order('created_at DESC').page(params[:page]) respond_to do |format| format.html # index.html.erb format.json { render :json => @course.notifies } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n @notify = @course.notifies.find(params[:id])\n @notify.readed_times += 1\n @notify.save\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render :json => @notify }\n end\n end", "def get_students\n @course = Course.find(params[:course_id])\n\n ren...
[ "0.6628242", "0.5992978", "0.5920972", "0.5898188", "0.56956017", "0.5682218", "0.56499547", "0.5628513", "0.55831057", "0.5578123", "0.5577918", "0.5563755", "0.5543339", "0.55387527", "0.5535542", "0.55277157", "0.5511556", "0.550621", "0.5493791", "0.548643", "0.5483326", ...
0.73090625
0
GET /student/courses/1/notifies/1 GET /student/courses/1/notifies/1.json
def show @notify = @course.notifies.find(params[:id]) @notify.readed_times += 1 @notify.save respond_to do |format| format.html # show.html.erb format.json { render :json => @notify } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @notifies = Notify.where(:course_id => @course.id).order('created_at DESC').page(params[:page])\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render :json => @course.notifies }\n end\n end", "def show\n\t\t@course = @teacher.courses.find(params[:id])\n ...
[ "0.73028", "0.6063595", "0.5954679", "0.57766", "0.57257307", "0.56969017", "0.56859833", "0.5672302", "0.56459886", "0.557358", "0.5566916", "0.5566569", "0.55643594", "0.556032", "0.55569553", "0.5553068", "0.5551902", "0.55361044", "0.55321205", "0.5516702", "0.55101675", ...
0.6735157
1
Use callbacks to share common setup or constraints between actions.
def set_bovino @bovino = Bovino.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
Only allow a trusted parameter "white list" through.
def bovino_params params.require(:bovino).permit( :fazenda_id, :numero, :nome, :pai, :mae, :raca, :pelagem, :sexo, :data_nascimento) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def allowed_params\n ALLOWED_PARAMS\n end", "def expected_permitted_parameter_names; end", "def param_whitelist\n [:role, :title]\n end", "def default_param_whitelist\n [\"mode\"]\n end", "def permitir_parametros\n \t\tparams.permit!\n \tend", "def permitted_params\n []\n end", ...
[ "0.7123669", "0.7054077", "0.69472784", "0.6902165", "0.6736001", "0.671985", "0.6687218", "0.6676269", "0.66602534", "0.6556639", "0.6527985", "0.645892", "0.645072", "0.64494324", "0.6445436", "0.64350927", "0.6415061", "0.6415061", "0.6393001", "0.6378958", "0.6378958", ...
0.0
-1
actual implementation Create the application, this initializes ncurses, but does not yet do anything. Call the `run!` method to start the run loop.
def initialize FFI::NCurses.initscr #FFI::NCurses.start_color FFI::NCurses.curs_set(0) FFI::NCurses.nodelay(FFI::NCurses.stdscr, true) FFI::NCurses.cbreak FFI::NCurses.raw FFI::NCurses.noecho FFI::NCurses.start_color FFI::NCurses.clear end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def run\n Curses.init_screen\n\n init_style\n\n Curses.noecho\n Curses.curs_set 0 # invisible\n\n @message = RDoc::RI::Browser::Message.new\n\n @display = RDoc::RI::Browser::Display.new self\n @display.show HELP, nil, false\n\n trap_resume do\n event_loop\n end\n end", "def start...
[ "0.65677", "0.6310792", "0.63034433", "0.6206924", "0.61951464", "0.61521083", "0.6143157", "0.6052809", "0.5981758", "0.5938708", "0.5934868", "0.59213585", "0.59194714", "0.5916802", "0.5908448", "0.5897135", "0.5892482", "0.58676094", "0.58614576", "0.585437", "0.58447474"...
0.6075175
7
This creates and starts the run loop, this is the root method of the entire application's lifetime.
def run! @queue = [] queue do @controller = Controller.new end catch :exit do while true tick FFI::NCurses.refresh end end rescue Exception => e Logger.log(e.message) Logger.log(e.backtrace.join("\n")) FFI::NCurses.clear FFI::NCurses.endwin raise end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def start\n main_loop\n end", "def run\n loop do\n break unless app_loop\n end\n end", "def run_loop\n end", "def start\n loop do\n run\n end\n end", "def initiate_event_loop!\n @active = true\n\n @thread = Thread.new do\n while @active\n ...
[ "0.76874024", "0.7627782", "0.74616414", "0.7288077", "0.70878", "0.704647", "0.704647", "0.7032069", "0.6966873", "0.69425726", "0.6888637", "0.6778653", "0.6745711", "0.67007434", "0.66867816", "0.66662717", "0.6652542", "0.6640722", "0.6639121", "0.66359", "0.6583568", "...
0.60531247
61
This closes the app, and clears the app from the terminal.
def close! @controller.close! if @controller FFI::NCurses.endwin Process.exit! end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def close_app\n abort(\"See you next time!\")\n end", "def close_app\n @bridge.close_app\n end", "def quit\n system('clear')\n exit\n end", "def exit_app\n puts \"Chuck Norris disapproves of your choice...\\n\\n\"\n exit!\n end", "def stop; self.app.stop en...
[ "0.7303801", "0.72290736", "0.7154724", "0.68897575", "0.6859435", "0.67201513", "0.6715591", "0.67003924", "0.66538674", "0.66344565", "0.648091", "0.6463893", "0.6407236", "0.6321186", "0.6299884", "0.62751174", "0.6268066", "0.6250179", "0.6237145", "0.6204369", "0.6186141...
0.6205297
19
This method gets executed for every iteration of the run loop.
def tick unless @queue.empty? @queue.shift.call else unless (c = FFI::NCurses.getch) == FFI::NCurses::ERR @controller.handle_char(c) else sleep(0.1) end end h, w = FFI::NCurses.getmaxyx(FFI::NCurses.stdscr) @controller.size(w,h) @controller.draw end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def post_loop; end", "def loop\n end", "def loop\n end", "def loop\n end", "def run_loop\n end", "def loop; end", "def pre_loop; end", "def prepare_each_run\n # puts \"prepare_each_run called\"\n if @initial_run\n @interval_index = 0\n @initial_run = false\n end\n end", "d...
[ "0.74975574", "0.748716", "0.748716", "0.7458823", "0.74177057", "0.7310963", "0.7181589", "0.69595563", "0.68384945", "0.6818517", "0.6753431", "0.67372525", "0.67372525", "0.67142296", "0.6698502", "0.6698502", "0.6698502", "0.6698502", "0.6698502", "0.6698502", "0.6698502"...
0.0
-1
Queue a block for the next available tick.
def queue(&b) @queue << b end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def queue(*args, &block)\n self.queued_blocks << self.define_block_container(*args, &block)\n nil\n end", "def next_tick(&block)\n @run_queue << block\n if reactor_thread?\n # Create a next tick timer\n if not @next_tick_scheduled\n ...
[ "0.6732435", "0.669901", "0.66985625", "0.6426117", "0.6343995", "0.6218101", "0.6176801", "0.6171527", "0.6171527", "0.61623657", "0.6135814", "0.60379535", "0.6005709", "0.5994062", "0.599354", "0.59897953", "0.5971159", "0.5946648", "0.5916586", "0.59014136", "0.59014136",...
0.6343754
5
GET /orders GET /orders.json
def index session[:showing_user] = nil # make sure this session variable is cleared out if admin_user? @orders = Order.all else @orders = current_user.orders.to_a end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def getorders(args={})\n {\n :method=> \"GetOrders\"\n }.to_json\n end", "def orders\n params = { command: 'account_orders' }\n get('/json.php', params)\n end", "def index\n @orders = Order.all\n render json: @orders\n end", "def index\n @orders = Order.all\n ...
[ "0.83267236", "0.815406", "0.80041754", "0.7947603", "0.7846487", "0.7823147", "0.78028905", "0.76992875", "0.76980406", "0.7682792", "0.7682792", "0.7682792", "0.7682792", "0.76827645", "0.75880665", "0.7574349", "0.756171", "0.7531827", "0.74860185", "0.7432208", "0.7369724...
0.0
-1
GET /orders/1 GET /orders/1.json
def show end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def getorders(args={})\n {\n :method=> \"GetOrders\"\n }.to_json\n end", "def index\n @orders = Order.all\n render json: @orders\n end", "def index\n @orders = Order.all\n render json: @orders, status: 200\n end", "def index\n @orders = Order.order(\"id\").all\n\n resp...
[ "0.7554187", "0.7488565", "0.7475228", "0.73777765", "0.73714006", "0.7341344", "0.73384553", "0.73168725", "0.73018956", "0.7291244", "0.7291244", "0.7291244", "0.7291244", "0.72911215", "0.7281374", "0.7266143", "0.72498786", "0.7228276", "0.7213504", "0.71842283", "0.71261...
0.0
-1
POST /orders POST /orders.json
def create unless logged_in? session[:checking_out] = true redirect_to login_path, notice: t('orders.must_log_in') # "You must log in before placing an order." else @order = current_user.orders.new(order_params) @order.earliest_pickup_date = calculate_earliest_pickup_date(:create) # User could have place product in cart days ago, make sure still available okay = true index = (session[:shopping_cart].size - 1) while (index >= 0) element = session[:shopping_cart][index] product = Product.find(element[:product_id]) quantity = element[:quantity] if (product.quantity_in_stock == 0) okay = false if (okay) session[:shopping_cart].delete_at(index) # If cart empty as a result of the deletion, redirect user to product index redirect_to(products_path, notice: t('orders.not_in_stock')) and return if session[:shopping_cart].empty? # "The product(s) ordered are no longer in stock; order cannot be placed." elsif (product.quantity_in_stock < quantity) okay = false if (okay) # Update quantity in shopping cart based on quantity available new_product_hash = { product_id: product.id, quantity: product.quantity_in_stock } session[:shopping_cart][index] = new_product_hash end index -= 1 end redirect_to(new_order_path, notice: t('orders.please_review')) and return if (!okay) # "One or more of the products you selected is either out of stock or not available in the desired quantity. Please review the updated order and resubmit if okay." # Proceed to save order respond_to do |format| if @order.save @order.update_attributes(order_date: Date.today, order_status_id: 1) # set order date to today, status to New session[:shopping_cart].each do |element| # create an order_product record for each product in the shopping cart and update quantity in stock of products product = Product.find(element[:product_id]) quantity = element[:quantity] @order.order_products.create(product_id: product.id, quantity: quantity) new_quantity_in_stock = (product.quantity_in_stock - quantity) product.update_attributes(quantity_in_stock: new_quantity_in_stock) end session[:shopping_cart].clear format.html { redirect_to root_path, notice: t('orders.create') } # "Your order was successfully submitted!" format.json { render action: 'index', status: :created, location: @order } else format.html { render action: 'new' } format.json { render json: @order.errors, status: :unprocessable_entity } end end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def orders\n authenticated_post(\"orders\").body\n end", "def orders\n authenticated_post(\"auth/r/orders\").body\n end", "def create\n order = Order.create(order_params)\n render json: order\nend", "def submit_order()\n\tputs \"Submitting order\"\n\tdata = create_order()\n\tresponse = ...
[ "0.75886714", "0.7490972", "0.7488501", "0.74664384", "0.72739846", "0.7195349", "0.7063682", "0.69745994", "0.6910657", "0.68880194", "0.68747663", "0.685004", "0.6840204", "0.6838178", "0.6838178", "0.6838178", "0.6838178", "0.682244", "0.6790037", "0.67793274", "0.6779247"...
0.0
-1
PATCH/PUT /orders/1 PATCH/PUT /orders/1.json
def update @order.earliest_pickup_date = calculate_earliest_pickup_date(:update) # Save off original quantity for order_products original_quantities = {} @order.order_products.each { |order_product| original_quantities[order_product.id] = order_product.quantity } respond_to do |format| if @order.update(order_params) okay = true @order.order_products.each do |order_product| new_quantity = order_product.quantity original_quantity = original_quantities[order_product.id] unless (new_quantity == original_quantity) product = order_product.product new_quantity_in_stock = (product.quantity_in_stock + original_quantity - new_quantity) if new_quantity_in_stock < 0 # Desired quantity no longer available okay = false if okay # Update the order the best we can and notify user of discrepancy new_quantity_in_stock = 0 # The original quantity was already subtracted from the stock; quantity should never have to decrease below what was previously ordered new_quantity = original_quantity + product.quantity_in_stock order_product.update_attributes(quantity: new_quantity) end product.update_attributes(quantity_in_stock: new_quantity_in_stock) end end redirect_to(edit_order_path(@order), notice: t('orders.not_available')) and return if (!okay) # "One or more of the products you selected is not available in the desired quantity. Please review the updated order." if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.create') } # "Order was successfully updated." format.json { head :no_content } else format.html { redirect_to orders_path, notice: t('orders.create') } # "Order was successfully updated." format.json { head :no_content } end else format.html { render action: 'edit' } format.json { render json: @order.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n @order = Order.find(params[:id])\n\n if @order.update(order_params)\n head :no_content\n else\n render json: @order.errors, status: :unprocessable_entity\n end\n end", "def update\n @order = Order.find(params[:id])\n\n if @order.update(order_params)\n head :no_conte...
[ "0.6803119", "0.6803119", "0.67749745", "0.6743427", "0.67353284", "0.6726928", "0.6723453", "0.6719653", "0.67047364", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", "0.6704673", ...
0.0
-1
GET /orders/1/cancel Action to cancel an order
def cancel if admin_user? cancel_reason_id = 2 # Product Not Available else cancel_reason_id = 1 # Customer end respond_to do |format| if @order.update_attributes(order_status_id: 4, cancel_reason_id: cancel_reason_id) @order.order_products.each do |order_product| product = order_product.product quantity = order_product.quantity new_quantity_in_stock = (product.quantity_in_stock + quantity) product.update_attributes(quantity_in_stock: new_quantity_in_stock) end if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.cancel') } # "Order was successfully canceled." format.json { head :no_content } else format.html { redirect_to orders_path, notice: t('orders.cancel') } # "Order was successfully canceled." format.json { head :no_content } end else if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.cancel_error') } # "Error canceling order." format.json { render json: @order.errors, status: :unprocessable_entity } else format.html { redirect_to orders_path, notice: t('orders.cancel_error') } # "Error canceling order." format.json { render json: @order.errors, status: :unprocessable_entity } end end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def cancel\n @order.cancel\n render_update @order\n end", "def cancel\n @order.cancel!\n return redirect_to order_path(@order), :notice => t(:update_success)\n end", "def cancel_order(source_account, order_id)\n\tputs \"Canceling order: \" + order_id + \" from: \" + source_account\n\tresponse = r...
[ "0.83766294", "0.8328993", "0.83165467", "0.8259385", "0.8060947", "0.8056739", "0.79556245", "0.7937675", "0.7889207", "0.7704625", "0.7684916", "0.76410836", "0.76165944", "0.76073503", "0.75853264", "0.7573648", "0.74859345", "0.7469339", "0.7436711", "0.73285186", "0.7297...
0.7088942
29
GET /orders/1/fill Action to mark an order as filled
def fill respond_to do |format| if @order.update_attributes(order_status_id: 2) if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.fill') } # "Order was successfully filled." format.json { head :no_content } else format.html { redirect_to orders_path, notice: t('orders.fill') } # "Order was successfully filled." format.json { head :no_content } end else if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.fill_error') } # "Error filling order." format.json { render json: @order.errors, status: :unprocessable_entity } else format.html { redirect_to orders_path, notice: t('orders.fill_error') } # "Error filling order." format.json { render json: @order.errors, status: :unprocessable_entity } end end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @orders = Order.all\n\n respond_to do |format|\n format.html # fill.html.erb format.json { render json: @orders }\n end\n end", "def fulfill\n @order.approx_cost = (@order.approx_cost.to_f * 100.0).floor\n @order.fulfill\n render 'status'\n end", "def complete\n @or...
[ "0.64807355", "0.6358297", "0.6179632", "0.60929006", "0.6070743", "0.60581785", "0.601386", "0.5903681", "0.58837223", "0.5876553", "0.5705469", "0.5680885", "0.5624723", "0.5598343", "0.5590752", "0.5572215", "0.5520645", "0.5479345", "0.5473462", "0.5458701", "0.5444692", ...
0.73977673
0
GET /orders/1/pickup Action that indicates the user picked up the order
def pickup respond_to do |format| if @order.update_attributes(order_status_id: 3) @order.order_products.each { |order_product| order_product.update_attributes(unit_price: order_product.product.price) } # Save off the price of each product at the time the order was completed totals = @order.calculate_totals attributes_hash = { product_total: totals[:product_total], tax: totals[:tax], amount_due: totals[:amount_due] } @order.update_attributes(attributes_hash) # save off the order totals as of the time the customer paid if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.pickup') } # "Order was successfully picked up." format.json { head :no_content } else format.html { redirect_to orders_path, notice: t('orders.pickup') } # "Order was successfully picked up." format.json { head :no_content } end else if session[:showing_user] format.html { redirect_to @order.user, notice: t('orders.pickup_error') } # "Error picking up order." format.json { render json: @order.errors, status: :unprocessable_entity } else format.html { redirect_to orders_path, notice: t('orders.pickup_error') } # "Error picking up order." format.json { render json: @order.errors, status: :unprocessable_entity } end end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create\n @pickup = Pickup.new(pickup_params)\n respond_to do |format|\n if @pickup.save\n flash[:success] = \"Pickup Process Submitted\"\n format.html { redirect_to @pickup }\n format.json { render :show, status: :created, location: @pickup }\n else\n flash[:danger] ...
[ "0.66564935", "0.6537134", "0.65014297", "0.64913434", "0.6477746", "0.6422516", "0.6391295", "0.634611", "0.6343771", "0.63203853", "0.6285775", "0.62836057", "0.6283334", "0.6221181", "0.6205514", "0.6202973", "0.61586756", "0.61123186", "0.6045168", "0.6042664", "0.6002398...
0.7309258
0
Use callbacks to share common setup or constraints between actions.
def set_order if admin_user? @order = Order.find(params[:id]) else @order = current_user.orders.find(params[:id]) end 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 order_params params.require(:order).permit(:order_status_id, :pickup_date, :order_date, :cancel_reason_id, :user_id, order_products_attributes: [:id, :order_id, :product_id, :quantity]) 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
Calculates the earliest pickup date the user is allowed to select based on the release dates of the products in the order If all products are released, it returns today
def calculate_earliest_pickup_date(action) earliest_date = Date.today case action when :create session[:shopping_cart].each do |element| product = Product.find(element[:product_id]) earliest_date = product.release_date unless ((product.release_date.nil?)||(product.release_date <= earliest_date)) end when :update @order.order_products.each do |order_product| product = order_product.product earliest_date = product.release_date unless ((product.release_date.nil?)||(product.release_date <= earliest_date)) end end return earliest_date end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def future_pickup_date\n # Model does not have access to session (and thus the products in the shopping cart);\n # need to pass in the earliest allowable pickup date\n earliest_date = earliest_pickup_date\n earliest_date = Date.today if earliest_date.nil?\n if pickup_date < earliest_date\n erro...
[ "0.72513336", "0.65709716", "0.6528208", "0.6472871", "0.6381875", "0.63790286", "0.6329364", "0.62186205", "0.6162764", "0.6139217", "0.6132429", "0.60227215", "0.6014947", "0.5988343", "0.59766185", "0.59418064", "0.59226227", "0.5864893", "0.58451134", "0.58407176", "0.575...
0.7973873
0
GET /comp_todos GET /comp_todos.json
def index @comp_todos = CompTodo.all end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @todos = @list.todos\n render json: @todos\n end", "def index\n @todos = Todo.all\n json_response(@todos)\n end", "def index\n @todos = Todo.all\n render json: @todos\n end", "def index\n @todos = @list.todos.all\n\n respond_to do |format|\n for...
[ "0.7726261", "0.769814", "0.76290953", "0.7547973", "0.7533638", "0.74411786", "0.74133193", "0.7360034", "0.7328136", "0.7318569", "0.7195852", "0.71294045", "0.7115585", "0.7115585", "0.7115585", "0.7115585", "0.7115585", "0.7115585", "0.71140933", "0.70713526", "0.7056049"...
0.7464356
5
GET /comp_todos/1 GET /comp_todos/1.json
def show end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n todo = Todo.find_by_id(params[:id])\n render json: todo.todos\n end", "def index\n @api_v1_todos = Todo.all\n render json: @api_v1_todos\n end", "def index\n @todos = @list.todos\n render json: @todos\n end", "def index\n @todos = Todo.all\n json_response(@todos...
[ "0.77153873", "0.76070887", "0.7580189", "0.74932814", "0.74737227", "0.7443191", "0.7389884", "0.7315143", "0.7278766", "0.72512364", "0.72201115", "0.72179747", "0.7214718", "0.71603507", "0.7151156", "0.71400535", "0.71298856", "0.71298856", "0.70993096", "0.7062288", "0.7...
0.0
-1
POST /comp_todos POST /comp_todos.json
def create @comp_todo = CompTodo.new(comp_todo_params) respond_to do |format| if @comp_todo.save format.html { redirect_to component_path(@comp_todo.component_id), notice: 'Task was successfully created.' } format.json { render action: 'show', status: :created, location: @comp_todo } else format.html { redirect_to component_path(@comp_todo.component_id), alert: 'Task was not created please fill inn all the fields when making a task.' } format.json { render json: @comp_todo.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create\n @todo = Todo.new(todo_params)\n if @todo.save\n render json: @todo, status: :created, location: @todo\n else\n render json: @todo.errors, status: :unprocessable_entity\n end\n end", "def create\n @todo = Todo.create(todo_params)\n render json: @todo\n end", ...
[ "0.7418844", "0.74054307", "0.7391095", "0.72325015", "0.71386534", "0.71325785", "0.7123821", "0.71069294", "0.709838", "0.7069516", "0.7017764", "0.70014924", "0.6996688", "0.6945557", "0.6945557", "0.6945557", "0.6916414", "0.69146615", "0.688272", "0.6878567", "0.6874665"...
0.6694779
32
PATCH/PUT /comp_todos/1 PATCH/PUT /comp_todos/1.json
def update respond_to do |format| if @comp_todo.update(comp_todo_params) format.html { redirect_to @comp_todo, notice: 'Task was updated' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @comp_todo.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n respond_to do |format|\n if @api_v1_todo.update(api_v1_todo_params)\n format.json { render json: @api_v1_todo, status: :ok }\n else\n format.json { render json: @api_v1_todo.errors, status: :unprocessable_entity }\n end\n end\n end", "def update\n @todo = Todo....
[ "0.73243624", "0.7291732", "0.7143031", "0.71299255", "0.708796", "0.68649495", "0.68567395", "0.68242896", "0.6817726", "0.6777837", "0.6777837", "0.6752419", "0.6744201", "0.6724362", "0.67008257", "0.66901624", "0.6661214", "0.66555446", "0.66526043", "0.66526043", "0.6629...
0.6962183
5
DELETE /comp_todos/1 DELETE /comp_todos/1.json
def destroy @comp_todo.destroy respond_to do |format| format.html { redirect_to component_path(@comp_todo.component), notice: "Task was deleted" } format.json { head :no_content } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy\n @api_v1_todo.destroy\n respond_to do |format|\n format.json { head :no_content }\n end\n end", "def destroy\n @todo = Todo.find(params[:id])\n @todo.destroy\n render json: nil, status: :ok\n end", "def destroy\n @todo.destroy\n render json: [\"Deleted successfully.\...
[ "0.7693994", "0.75196457", "0.7487525", "0.7447232", "0.7401911", "0.7391261", "0.7391261", "0.7379672", "0.7333956", "0.72758555", "0.72699696", "0.72650933", "0.7247442", "0.72076076", "0.72018856", "0.7197758", "0.7175244", "0.7170617", "0.7143933", "0.71374494", "0.711486...
0.70497465
33
Use callbacks to share common setup or constraints between actions.
def set_comp_todo @comp_todo = CompTodo.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 comp_todo_params params.require(:comp_todo).permit(:todo_id, :level, :task, :component_id, :title) 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
Game with fake players User can easily leave it and start other game
def demonstration # todo nice link here https://github.com/plataformatec/devise/wiki/How-Tos # todo we can use this https://github.com/plataformatec/devise/wiki/How-To:-Create-a-guest-user # todo ask only email in registration https://github.com/plataformatec/devise/wiki/How-To:-Email-only-sign-up @game = DemoGameSession.create @player = Player.create(user_id: @user.id, game_session_id: @game.id) GameSession.other_players_count.times do |i| # TODO we need create module with Strategies samples in lib # TODO store class as file (it will be executable) and read it as string to here random_password = SecureRandom.hex(8) fake_user_id = User.maximum('id') + 1 fake_user = User.create(email: "bot#{fake_user_id.to_s}@example.com", :password => random_password, :password_confirmation => random_password, is_bot: true) fake_player = Player.create(game_session_id: @game.id, code: Codes::CIRCLE, user_id: fake_user.id) # todo leave players not deleted and show list of them to see player's code end redirect_to :game_page end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def gameover\n self.users.each do |user|\n user.leave_game\n end\n self.done = true\n self.save\n\n Game.del(self.id)\n end", "def end_game()\n get_winners()\n end", "def start_game(user)\n $game_session = nil\n UserGuess.delete_all\n\n initiate_game(user)\n question_loop\n end_me...
[ "0.7148639", "0.7049287", "0.69784564", "0.6907024", "0.68080115", "0.67895114", "0.67125255", "0.6684467", "0.66752124", "0.6670761", "0.66706204", "0.6664571", "0.6653038", "0.66508955", "0.6641613", "0.66195625", "0.6609346", "0.65844166", "0.65809464", "0.65449494", "0.65...
0.64789224
25
it was a part of finish_game action, but it caused an interesting behaviour:
def destroy if @game.is_empty? increment_winner_statistic # destroy bots users bots_ids = @game.users.collect {|user| user.id if user.is_bot} User.where(id: bots_ids).destroy_all @game.players.destroy_all # todo use it in future @game.destroy end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def finalize_game\n\n end", "def end_game\n end", "def end_game\n\n end", "def game_finished\n\tif @skip == true\n \t@game_finished = true\n end\nend", "def finish\n\t\t@frame = @frame + 1\n\t\tdone = false\n\t\tif @frame % 120 == 0 \n\t\t\tdone = !@dialogueText.next\n\t\tend\n\t\tif done\n\t\t\t@...
[ "0.7656726", "0.7593404", "0.7495847", "0.7230328", "0.7096871", "0.7090365", "0.70173144", "0.69982433", "0.6875973", "0.6860952", "0.6860755", "0.683648", "0.6811705", "0.6748169", "0.6744747", "0.674331", "0.6735735", "0.6725964", "0.6696944", "0.6636259", "0.66244215", ...
0.0
-1
Player has game already
def check_has_no_game @game = @user.game redirect_to action: :start_game if @game.present? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def game_over?\n alive_players.count == 1\n end", "def check_game\n self.game ||= begin\n #TODO get player from last game\n # TODO write test where \"Player 3\" already exits\n player = Player.find_or_create_by(:name => \"Player #{self.slot}\")\n Game.create!(:player => player, ...
[ "0.7864108", "0.77740085", "0.76320934", "0.76305974", "0.7589592", "0.75812817", "0.74742323", "0.7471257", "0.7399684", "0.73738366", "0.7293877", "0.72911024", "0.7282076", "0.727625", "0.72567964", "0.72502875", "0.7240427", "0.7215449", "0.7210768", "0.7190772", "0.71432...
0.6875497
41