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
calls a method that returns the correct set of initial coordinates for rovers
def rovers_position @input.values_at(* @input.each_index.select {|i| i.odd?}) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_start_coordinates\n start_coord = []\n until start_coord_valid?(start_coord)\n puts \"START COORDINATES\"\n start_coord = @current_player.get_user_input\n start_coord = [] if [\"reset\", \"save\", []].include?(do_special_input_stuff(start_coord)) #hackhackhack\n end\n print_board...
[ "0.6441579", "0.6155435", "0.6121421", "0.6082642", "0.60728574", "0.60302186", "0.6018562", "0.59347737", "0.5893265", "0.58911645", "0.58599764", "0.58001256", "0.5798502", "0.5781993", "0.5779179", "0.5774772", "0.57696486", "0.57679284", "0.5749286", "0.5731001", "0.57166...
0.0
-1
We create an instance of 1 or more rovers and land them in the plateu with their initial position
def landing_rovers(rovers) rovers.each do |rover| @rovers << Rover.new(rover.split(" ")[0].to_i, rover.split(" ")[1].to_i, rover.split(" ")[2].upcase) end @map.rovers_initial_position(@rovers) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create_rover(c)\n @rover_bay = []\n c.each_with_index do |x,i|\n @rover_bay.push(Rover.new(x.movement,x.position,i+1))\n end\n end", "def initialize(commands)\n m = commands.shift\n @map = Plateau.new(m[0],m[1])\n create_rover(commands)\n initial_placement\n end", "def initial...
[ "0.65657604", "0.63672507", "0.623502", "0.62035996", "0.6146246", "0.61115557", "0.60550874", "0.6046997", "0.602119", "0.5972263", "0.59538275", "0.59399813", "0.59078526", "0.5874867", "0.5873017", "0.58685315", "0.5863173", "0.5849323", "0.584719", "0.5812066", "0.5800934...
0.7028696
0
Outputs the final position of the Roverss
def output @rovers.each do |rover| puts '%d %d %s' %rover.position if @map.rover_inside_plateu?(rover) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def rover_positions_as_string\n @maxX = @file[0]\n @maxY = @file[1]\n while @more\n\n set_initial_position\n move_rover(@file[1 + 4 * @roverCount])\n puts \"#{@x} #{@y} #{@face}\"\n if @file[6 + 3 * @roverCount] == nil\n @more = false\n else\n @roverCount = @roverCou...
[ "0.69368005", "0.64545393", "0.64132243", "0.62468153", "0.61611396", "0.6037876", "0.6035448", "0.5863661", "0.58489615", "0.5789229", "0.5774937", "0.5762583", "0.5734968", "0.5715904", "0.56647027", "0.56647027", "0.56647027", "0.56647027", "0.5651878", "0.56428796", "0.56...
0.71878767
0
Never trust parameters from the scary internet, only allow the white list through.
def listing_params params.require(:listing).permit(:title, :description, :picture, :price, :category_id) 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
Return a rowkey for a specific date an optional user as well as payload
def sensation_create_key(ts_sec, user_id = nil, payload = nil) key = (ts_sec / 86400) << 64 if user_id key += (user_id << 32) end if payload key += Zlib::crc32(payload) end key.to_java.toByteArray end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def rowkey type = :string\n Util.from_bytes type, @result.getRow\n end", "def rowkey type = :raw\n Util.from_bytes type, @java.getRow\n end", "def key_by_date\n self.strftime('%Y-%m-%d')\n end", "def original_key(row)\n end", "def get_key record\n record\n end", "def key_name...
[ "0.6144664", "0.5930717", "0.5823994", "0.5760261", "0.55676514", "0.5500636", "0.5498921", "0.5495736", "0.5444512", "0.54259473", "0.54196036", "0.5337861", "0.53022885", "0.52933615", "0.52769846", "0.5215267", "0.5195172", "0.5192802", "0.5181331", "0.51695144", "0.515735...
0.0
-1
Return sensation message as hash or nil if message doesn't pass validation
def sensation_parse_message(json_str) m = JSON.parse(json_str) if m["duration_watched"] > 100000 @logger.warn "Dropping message '#{m.inspect}'" return nil end m end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def not_valid_message; nil; end", "def not_valid_message; nil; end", "def message\n @props.fetch(:message, \"must be valid\")\n end", "def pretty_hash_message(msg_hash)\n message = msg_hash['message']\n if msg_hash['errors']\n msg_hash['errors'].each do |k,v|\n if ms...
[ "0.6303842", "0.6303842", "0.62383", "0.6177175", "0.60714173", "0.60374236", "0.59985685", "0.58875865", "0.57260877", "0.57145226", "0.56530577", "0.5616187", "0.5566198", "0.55635315", "0.55509686", "0.5525495", "0.546277", "0.54585195", "0.54477084", "0.54362965", "0.5432...
0.52458584
37
This is needed because preexisting theses (i.e., fixtures) will have a whodunnit of nil, and we use whodunnit to identify theses that were created/modified by students.
def create_thesis_with_whodunnit(user) sign_in user title = 'Spacecraft avoidance: a short' post '/thesis', params: { thesis: { title: title, abstract: 'Frook.', department_ids: departments(:one).id.to_s, degree_ids: degrees(:one).id.to_s, graduation_year: (Time.current.year + 1).to_s, graduation_month: 'September', files: fixture_file_upload('a_pdf.pdf', 'application/pdf') } } sign_out user end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def whodunnit=(value)\n store[:whodunnit] = value\n end", "def whodunnit\n who = store[:whodunnit]\n who.respond_to?(:call) ? who.call : who\n end", "def set_draftsman_whodunnit\n ::Draftsman.whodunnit = user_for_draftsman if ::Draftsman.enabled?\n end", "def set_paper_...
[ "0.6163376", "0.60241485", "0.60174096", "0.55981964", "0.54135853", "0.5244939", "0.5080941", "0.50778824", "0.5072127", "0.50627047", "0.50503325", "0.5044354", "0.49970937", "0.49710506", "0.4968792", "0.49450892", "0.49242803", "0.4924096", "0.4889686", "0.48631865", "0.4...
0.5169116
6
if desiredHeight.to_i < upSpeed.to_i return 1 else return (desiredHeight.to_i/(upSpeed.to_i downSpeed.to_i)).ceil end end
def growing_plant(upSpeed, downSpeed, desiredHeight) difference = desiredHeight - upSpeed if difference <= 0 return 1 else return (difference.to_f/(upSpeed - downSpeed)).ceil + 1 end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def speed_of_spread\n #in months\n # We are still perfecting our formula here. The speed is also affected\n # by additional factors we haven't added into this functionality.\n speed = 0.0\n\n if @population_density >= 200\n speed += 0.5\n elsif @population_density >= 150\n speed += 1\n ...
[ "0.68641603", "0.68641603", "0.68449426", "0.68273604", "0.68135566", "0.6750255", "0.6743047", "0.67339194", "0.67282027", "0.67111313", "0.6703598", "0.666615", "0.666615", "0.666615", "0.6664342", "0.66427684", "0.6619947", "0.66180277", "0.659593", "0.65779155", "0.656878...
0.7932343
0
Before filters Confirms a loggedin user.
def logged_in_user unless logged_in? store_location flash[:danger] = "Please log in." redirect_to login_url end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def signed_in_user_filter\n if signed_in?\n redirect_to root_path, notice: \"Already logged in\"\n end\n end", "def appctrl_confirm_user\n redirect_to( signin_path() ) unless @current_user\n end", "def confirm_logged_in\n unless session[:user_id]\n flash[:notice] = \"Please log in.\"\...
[ "0.6569166", "0.6430658", "0.6423167", "0.64137745", "0.63995165", "0.62902534", "0.6249426", "0.6248803", "0.6218758", "0.6173909", "0.612472", "0.61157626", "0.60806084", "0.6062998", "0.6040006", "0.60308075", "0.6022445", "0.60193825", "0.6015744", "0.6000973", "0.5993021...
0.0
-1
Confirms an admin user.
def admin_user redirect_to(root_url) unless current_user.admin? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def confirm_admin\n \tunless session[:admin]\n \t\tflash[:notice] = \"You are not an admin.\"\n \t\tredirect_to(user_path( :id => session[:user_id]))\n \tend\n end", "def admin_user\n\t\t\tflash_text = \"Administrative privilege required to perform this action.\"\n\t\t\tflash[:danger] = flash_text unless cu...
[ "0.79044944", "0.767215", "0.76483077", "0.76210374", "0.7605678", "0.7605678", "0.75945777", "0.7588445", "0.7588445", "0.7503662", "0.74675834", "0.7451482", "0.7424005", "0.7411313", "0.74107665", "0.7402138", "0.73993605", "0.7358812", "0.7329228", "0.73179626", "0.731276...
0.0
-1
Maps single value or array with given map.
def map_with(map, val) if val.is_a?(Array) val.map { |x| map.fetch(x, x) } else map.fetch(val, val) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def map_converter(map)\n lambda do |value|\n map.key?(value) ? map[value] : value\n end\n end", "def map_value(key, value)\n case value\n when Array\n value.map { |v| map_value(nil, v) }\n when Hash\n return custom_deep_symbolic_hash(value) unles...
[ "0.6903637", "0.6730288", "0.6639748", "0.6348998", "0.6162186", "0.61468923", "0.6084565", "0.5985755", "0.596113", "0.5901821", "0.5827685", "0.581829", "0.5814871", "0.5795801", "0.5753037", "0.57480794", "0.57296085", "0.5722526", "0.5704943", "0.5689017", "0.56621367", ...
0.72425926
0
Don't put anything above this
def to_param to_s end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def placebo?; false end", "def ignores; end", "def ignore; end", "def under; end", "def before; end", "def naked_top_level?; end", "def extra; end", "def anchored; end", "def naked_top_level; end", "def private; end", "def take_place\n super(1)\n end", "def before() ; end", "def possibl...
[ "0.6983753", "0.68186224", "0.65628606", "0.65336007", "0.65008503", "0.6331195", "0.61877555", "0.6150585", "0.61462843", "0.61148465", "0.61089253", "0.6101437", "0.6092034", "0.60492635", "0.6045511", "0.6038447", "0.6035159", "0.6018995", "0.6018995", "0.6009316", "0.6007...
0.0
-1
PUT /albums/:id/photo/:id def add_photo
def index @albums = Album.all render json: @albums end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_photo(album_id, photo_id, file, filename)\n \n end", "def album_add_photo(photo_data, photo_file)\n \n if album \n album.add_or_update_photo(photo_data, photo_file) \n end\n\n end", "def album_update_photo!(photo_data, photo_file)\n\n if al...
[ "0.74968123", "0.74792707", "0.74052936", "0.7179552", "0.7034533", "0.702723", "0.7009274", "0.70063096", "0.6963821", "0.6924226", "0.6905011", "0.69028205", "0.68879515", "0.68671876", "0.6852506", "0.6795133", "0.6764911", "0.67525536", "0.6748545", "0.6739652", "0.673654...
0.0
-1
Variable Number of Parameters:
def sample (*test) puts "The number of parameters is #{test.length}" for i in 0...test.length puts "The parameters are #{test[i]}" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def params(*); {}; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters; end", "def parameters=(_arg0); end", "def params; end", "def params; end", "def params; ...
[ "0.73681694", "0.7285299", "0.7285299", "0.7285299", "0.7285299", "0.7285299", "0.7285299", "0.7285299", "0.7285299", "0.7177535", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079", "0.7079",...
0.63810915
52
Mocks the publishing action by returning a successful response. Ensures that object was preserved before "publishing".
def publish_impl(publish_target, digital_object) return [false, "Never preserved"] if digital_object.first_preserved_at.blank? [true, ["https://example.com/#{publish_target.string_key}/#{digital_object.uid}"]] rescue StandardError => e [false, [e.message]] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def publish\n render json: ErrorSerializer.serialize(resource_name => \"is already published\"), status: 422 and return if resource.published\n\n if ResourcePublisher.new(resource).publish\n render json: resource, status: 200\n else\n render json: ErrorSerializer.serialize(resource.errors), stat...
[ "0.6512109", "0.6229609", "0.6133528", "0.60332346", "0.60195404", "0.60032", "0.5996588", "0.5963195", "0.5963195", "0.5963195", "0.5942456", "0.5929674", "0.5917891", "0.58916396", "0.58579963", "0.58444", "0.58398545", "0.58053714", "0.5742436", "0.5741883", "0.5730103", ...
0.0
-1
Mocks unpublishing action by returning a successful response. Ensures that object was preserved before "unpublishing".
def unpublish_impl(_publish_target, digital_object) return [false, "Never preserved"] if digital_object.first_preserved_at.blank? [true] rescue StandardError => e [false, [e.message]] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def unpublish\n resp = connection.post do |req|\n req.url \"#{object_path}/unpublish\"\n end\n return resp.headers['Location'] if resp.success?\n\n raise_exception_based_on_response!(resp)\n end", "def unpublish\n render json: ErrorSerializer.serialize(res...
[ "0.7353392", "0.69257766", "0.6307171", "0.6158235", "0.60561085", "0.6035002", "0.59197724", "0.59108645", "0.5898508", "0.5866198", "0.58503836", "0.57605773", "0.57605773", "0.57282877", "0.56828463", "0.5632164", "0.5623674", "0.56220675", "0.5612857", "0.56006116", "0.55...
0.60547495
5
Look for (created) files and return an array of them
def files_from_generator_output(output, type = 'create') output.to_a.map { |line| line.scan(/#{type}\s+([^\s]+)$/).flatten.first }.compact.select { |f| File.exist?(f) and !File.directory?(f) } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def find_files()\n require 'find'\n directory = File.dirname(__FILE__) + '/../templates/' + @template\n @files = Array.new()\n Find.find(directory) do |f|\n if FileTest.file?f\n @files.push(f)\n end\n end\n @files\n end", "def new_files(recursive=false)\n newfiles = Arr...
[ "0.7534025", "0.7484491", "0.73708737", "0.7169759", "0.7063935", "0.7007023", "0.69530255", "0.6934759", "0.6908982", "0.6849017", "0.68456334", "0.67937595", "0.6765696", "0.6699068", "0.6687819", "0.6673477", "0.66475064", "0.663096", "0.66131145", "0.660652", "0.66002196"...
0.0
-1
Read a schema and return it as hash. You can supply a path or the global path defined in SchemaTools.schema_path is used. Schemata are returned from cache(registry) if present to prevent filesystem roundtrips. The cache can be reset with registry_reset
def read(schema_name, path_or_schema=nil) schema_name = schema_name.to_sym return registry[schema_name] if registry[schema_name] if path_or_schema.is_a?(::Hash) schema = Schema.new(path_or_schema) elsif path_or_schema.is_a?(::String) || path_or_schema.nil? path = path_or_schema file_path = File.join(path || SchemaTools.schema_path, "#{schema_name}.json") unless File.exist?(file_path) # check if file exists else try to find first real path in sub-dirs recursive_search = Dir.glob( File.join(SchemaTools.schema_path, '**/*', "#{schema_name}.json"))[0] # use only if we found something, else keep path which will throw error on file.open later file_path = recursive_search || file_path end schema = Schema.new(file_path) else raise ArgumentError, 'Second parameter must be a path or a schema!' end # only import object definitions, shared property definitions are handled separate return unless schema[:type] == 'object' registry[ schema_name ] = schema return schema end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read(schema_name, path_or_schema=nil)\n schema_name = schema_name.to_sym\n return registry[schema_name] if registry[schema_name]\n\n if path_or_schema.is_a? ::Hash\n path = nil\n plain_data = path_or_schema.to_json\n elsif path_or_schema.is_a?(::String) || pa...
[ "0.7322842", "0.6627524", "0.6444558", "0.6206617", "0.5869633", "0.5861695", "0.58348566", "0.5834792", "0.57522136", "0.5748341", "0.5669684", "0.5666222", "0.5665055", "0.56551075", "0.5646316", "0.55099773", "0.54240626", "0.54197365", "0.5403963", "0.53944737", "0.536936...
0.72458535
1
Read all available schemas from a given path(folder +subfolders) and return the found object definitions them as array. Also populates the registry
def read_all(path=nil) schemas = [] file_paths = if path [File.join(path, '*.json')] else [ File.join( SchemaTools.schema_path, '*.json'), File.join( SchemaTools.schema_path, '**/*', '*.json') ] end Dir.glob( file_paths ).each do |file| schema_name = File.basename(file, '.json').to_sym schemas << read(schema_name, path) end schemas.compact! schemas end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read_all(path=nil)\n schemas = []\n file_path = File.join(path || SchemaTools.schema_path, '*.json')\n Dir.glob( file_path ).each do |file|\n schema_name = File.basename(file, '.json').to_sym\n schemas << read(schema_name, path)\n end\n schemas\n end", ...
[ "0.7620456", "0.7197721", "0.6732453", "0.6582576", "0.6375825", "0.6230478", "0.6207903", "0.60985315", "0.60227495", "0.59406567", "0.59406567", "0.5905173", "0.5891718", "0.5759424", "0.5728217", "0.5716922", "0.561308", "0.5540385", "0.5516461", "0.5498072", "0.5477079", ...
0.75102854
1
Print something palatable when we're called in a string context.
def to_s fullname = "#{self.class.shortname}" if !@cloudobj.nil? and !@cloudobj.mu_name.nil? @mu_name ||= @cloudobj.mu_name end if !@mu_name.nil? and !@mu_name.empty? fullname = fullname + " '#{@mu_name}'" end if !@cloud_id.nil? fullname = fullname + " (#{@cloud_id})" end return fullname end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def print_good(string)\n\tputs \"[*] \".light_green + \"#{string}\".white\nend", "def print\n puts string\n end", "def safe_print(text, color=nil)\n CLIColorize.safe_print(text, color)\n end", "def print_something(string)\n puts string\nend", "def print_caution(string)\n\tputs \"[*] \".light_yello...
[ "0.66480553", "0.64950675", "0.6160164", "0.6108199", "0.6082032", "0.6071154", "0.6039109", "0.6009597", "0.59706074", "0.5941802", "0.5915249", "0.5911708", "0.58542436", "0.58384925", "0.58263177", "0.58236414", "0.58164465", "0.58119774", "0.5806907", "0.5804204", "0.5782...
0.0
-1
Remove all metadata and cloud resources associated with this object
def destroy if !@cloudobj.nil? and !@cloudobj.groomer.nil? @cloudobj.groomer.cleanup elsif !@groomer.nil? @groomer.cleanup end if !@deploy.nil? if !@cloudobj.nil? and !@config.nil? and !@cloudobj.mu_name.nil? @deploy.notify(self.class.cfg_plural, @config['name'], nil, mu_name: @cloudobj.mu_name, remove: true, triggering_node: @cloudobj, delayed_save: @delayed_save) elsif !@mu_name.nil? @deploy.notify(self.class.cfg_plural, @config['name'], nil, mu_name: @mu_name, remove: true, triggering_node: self, delayed_save: @delayed_save) end @deploy.removeKitten(self) end # Make sure that if notify gets called again it won't go returning a # bunch of now-bogus metadata. @destroyed = true if !@cloudobj.nil? def @cloudobj.notify {} end else def notify {} end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def clear\r\n @resources.clear\r\n end", "def cleanup\n self.objectives.destroy_all\n end", "def before_destroy\n super\n self.remove_all_owners\n self.remove_all_members\n self.remove_all_account_configs\n self.delete_all_custom_services\n en...
[ "0.7032609", "0.70075995", "0.6844842", "0.67235875", "0.6597906", "0.65899825", "0.6572161", "0.65710497", "0.65578175", "0.65307754", "0.65224427", "0.6491524", "0.64746004", "0.6470902", "0.6460612", "0.6445363", "0.6432943", "0.6400638", "0.6383446", "0.63720167", "0.6366...
0.6458706
15
Retrieve all of the known metadata for this resource.
def describe(cloud_id: nil, update_cache: false) if cloud_id.nil? and !@cloudobj.nil? @cloud_id ||= @cloudobj.cloud_id end res_type = self.class.cfg_plural res_name = @config['name'] if !@config.nil? @credentials ||= @config['credentials'] if !@config.nil? deploydata = nil if !@deploy.nil? and @deploy.is_a?(MU::MommaCat) and !@deploy.deployment.nil? and !@deploy.deployment[res_type].nil? and !@deploy.deployment[res_type][res_name].nil? deploydata = @deploy.deployment[res_type][res_name] else # XXX This should only happen on a brand new resource, but we should # probably complain under other circumstances, if we can # differentiate them. end if self.class.has_multiples and !@mu_name.nil? and deploydata.is_a?(Hash) and deploydata.has_key?(@mu_name) @deploydata = deploydata[@mu_name] elsif deploydata.is_a?(Hash) @deploydata = deploydata end if @cloud_id.nil? and @deploydata.is_a?(Hash) if @mu_name.nil? and @deploydata.has_key?('#MU_NAME') @mu_name = @deploydata['#MU_NAME'] end if @deploydata.has_key?('cloud_id') @cloud_id ||= @deploydata['cloud_id'] else # XXX temp hack to catch old Amazon-style identifiers. Remove this # before supporting any other cloud layers, otherwise name # collision is possible. ["group_id", "instance_id", "awsname", "identifier", "vpc_id", "id"].each { |identifier| if @deploydata.has_key?(identifier) @cloud_id ||= @deploydata[identifier] if @mu_name.nil? and (identifier == "awsname" or identifier == "identifier" or identifier == "group_id") @mu_name = @deploydata[identifier] end break end } end end return [@mu_name, @config, @deploydata] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def metadata\n if any? && metadata_schema\n response = api('request',\n :uri => \"hm://metadata/#{resource_name}s\",\n :batch => true,\n :payload => map {|resource| {:uri => resource.metadata_uri}},\n :response_schema => metadata_schema\n )\n response['...
[ "0.81967825", "0.7298892", "0.71711236", "0.69588125", "0.69500613", "0.69442254", "0.68584573", "0.68483347", "0.68483347", "0.68343735", "0.6819617", "0.6819617", "0.67309433", "0.6696641", "0.6684028", "0.6645099", "0.6645099", "0.6629881", "0.6618217", "0.66083354", "0.65...
0.0
-1
Fetch MU::Cloud objects for each of this object's dependencies, and return in an easilynavigable Hash. This can include things listed in
def dependencies(use_cache: false) @dependencies = {} if @dependencies.nil? @loadbalancers = [] if @loadbalancers.nil? if @config.nil? return [@dependencies, @vpc, @loadbalancers] end if use_cache and @dependencies.size > 0 return [@dependencies, @vpc, @loadbalancers] end @config['dependencies'] = [] if @config['dependencies'].nil? # First, general dependencies. These should all be fellow members of # the current deployment. @config['dependencies'].each { |dep| @dependencies[dep['type']] ||= {} next if @dependencies[dep['type']].has_key?(dep['name']) handle = @deploy.findLitterMate(type: dep['type'], name: dep['name']) if !@deploy.nil? if !handle.nil? MU.log "Loaded dependency for #{self}: #{dep['name']} => #{handle}", MU::DEBUG @dependencies[dep['type']][dep['name']] = handle else # XXX yell under circumstances where we should expect to have # our stuff available already? end } # Special dependencies: my containing VPC if self.class.can_live_in_vpc and !@config['vpc'].nil? MU.log "Loading VPC for #{self}", MU::DEBUG, details: @config['vpc'] if !@config['vpc']["vpc_name"].nil? and @deploy sib_by_name = @deploy.findLitterMate(name: @config['vpc']['vpc_name'], type: "vpcs", return_all: true) if sib_by_name.is_a?(Array) if sib_by_name.size == 1 @vpc = matches.first else # XXX ok but this is the wrong place for this really the config parser needs to sort this out somehow # we got multiple matches, try to pick one by preferred subnet # behavior sib_by_name.each { |sibling| all_private = sibling.subnets.map { |s| s.private? }.all?(true) all_public = sibling.subnets.map { |s| s.private? }.all?(false) if all_private and ["private", "all_private"].include?(@config['vpc']['subnet_pref']) @vpc = sibling break elsif all_public and ["public", "all_public"].include?(@config['vpc']['subnet_pref']) @vpc = sibling break else MU.log "Got multiple matching VPCs for #{@mu_name}, so I'm arbitrarily choosing #{sibling.mu_name}" @vpc = sibling break end } end else @vpc = sib_by_name end end if !@vpc and !@config['vpc']["vpc_name"].nil? and @dependencies.has_key?("vpc") and @dependencies["vpc"].has_key?(@config['vpc']["vpc_name"]) @vpc = @dependencies["vpc"][@config['vpc']["vpc_name"]] elsif !@vpc tag_key, tag_value = @config['vpc']['tag'].split(/=/, 2) if !@config['vpc']['tag'].nil? if !@config['vpc'].has_key?("vpc_id") and !@config['vpc'].has_key?("deploy_id") and !@deploy.nil? @config['vpc']["deploy_id"] = @deploy.deploy_id end vpcs = MU::MommaCat.findStray( @config['cloud'], "vpc", deploy_id: @config['vpc']["deploy_id"], cloud_id: @config['vpc']["vpc_id"], name: @config['vpc']["vpc_name"], tag_key: tag_key, tag_value: tag_value, region: @config['vpc']["region"], calling_deploy: @deploy, dummy_ok: true ) @vpc = vpcs.first if !vpcs.nil? and vpcs.size > 0 end if !@vpc.nil? and ( @config['vpc'].has_key?("nat_host_id") or @config['vpc'].has_key?("nat_host_tag") or @config['vpc'].has_key?("nat_host_ip") or @config['vpc'].has_key?("nat_host_name") ) nat_tag_key, nat_tag_value = @config['vpc']['nat_host_tag'].split(/=/, 2) if !@config['vpc']['nat_host_tag'].nil? @nat = @vpc.findBastion( nat_name: @config['vpc']['nat_host_name'], nat_cloud_id: @config['vpc']['nat_host_id'], nat_tag_key: nat_tag_key, nat_tag_value: nat_tag_value, nat_ip: @config['vpc']['nat_host_ip'] ) if @nat.nil? if !@vpc.cloud_desc.nil? @nat = @vpc.findNat( nat_cloud_id: @config['vpc']['nat_host_id'], nat_filter_key: "vpc-id", region: @config['vpc']["region"], nat_filter_value: @vpc.cloud_id, credentials: @config['credentials'] ) else @nat = @vpc.findNat( nat_cloud_id: @config['vpc']['nat_host_id'], region: @config['vpc']["region"], credentials: @config['credentials'] ) end end end elsif self.class.cfg_name == "vpc" @vpc = self end # Special dependencies: LoadBalancers I've asked to attach to an # instance. if @config.has_key?("loadbalancers") @loadbalancers = [] if !@loadbalancers @config['loadbalancers'].each { |lb| MU.log "Loading LoadBalancer for #{self}", MU::DEBUG, details: lb if @dependencies.has_key?("loadbalancer") and @dependencies["loadbalancer"].has_key?(lb['concurrent_load_balancer']) @loadbalancers << @dependencies["loadbalancer"][lb['concurrent_load_balancer']] else if !lb.has_key?("existing_load_balancer") and !lb.has_key?("deploy_id") and !@deploy.nil? lb["deploy_id"] = @deploy.deploy_id end lbs = MU::MommaCat.findStray( @config['cloud'], "loadbalancer", deploy_id: lb["deploy_id"], cloud_id: lb['existing_load_balancer'], name: lb['concurrent_load_balancer'], region: @config["region"], calling_deploy: @deploy, dummy_ok: true ) @loadbalancers << lbs.first if !lbs.nil? and lbs.size > 0 end } end return [@dependencies, @vpc, @loadbalancers] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def dependencies\n members.each_with_object([]) do |attr_name, depends|\n value = send(attr_name)\n value = pipeline.objects.fetch(value) if value.is_a?(Symbol)\n depends << value.dependencies << value if value.is_a?(PipelineObject)\n end.flatten\n end", "def dependencies\n ...
[ "0.62361485", "0.60153943", "0.59339017", "0.5908636", "0.59030503", "0.5897442", "0.57837886", "0.57519805", "0.5749725", "0.57481766", "0.57382226", "0.5702137", "0.5699113", "0.5689912", "0.5643434", "0.5596091", "0.5585197", "0.55752015", "0.5563395", "0.5547067", "0.5543...
0.5396942
40
Gracefully message and attempt to accommodate the common transient errors peculiar to Windows nodes
def handleWindowsFail(e, retries, rebootable_fails, max_retries: 30, reboot_on_problems: false, retry_interval: 45) msg = "WinRM connection to https://"+@mu_name+":5986/wsman: #{e.message}, waiting #{retry_interval}s (attempt #{retries}/#{max_retries})" if e.class.name == "WinRM::WinRMAuthorizationError" or e.message.match(/execution expired/) and reboot_on_problems if rebootable_fails > 0 and (rebootable_fails % 5) == 0 MU.log "#{@mu_name} still misbehaving, forcing Stop and Start from API", MU::WARN reboot(true) # vicious API stop/start sleep retry_interval*3 rebootable_fails = 0 else if rebootable_fails == 3 MU.log "#{@mu_name} misbehaving, attempting to reboot from API", MU::WARN reboot # graceful API restart sleep retry_interval*2 end rebootable_fails = rebootable_fails + 1 end end if retries < max_retries if retries == 1 or (retries/max_retries <= 0.5 and (retries % 3) == 0 and retries != 0) MU.log msg, MU::NOTICE elsif retries/max_retries > 0.5 MU.log msg, MU::WARN, details: e.inspect end sleep retry_interval retries = retries + 1 else raise MuError, "#{@mu_name}: #{e.inspect} trying to connect with WinRM, max_retries exceeded", e.backtrace end return [retries, rebootable_fails] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def recoverable_error e, msg = \"Error\", bt = []\n puts \"#{msg} at time #{clock}\"\n puts \"From \" + bt[0..2].join(\"\\n \") unless bt.empty\n puts \" ...\" if bt.length > 3\n shell.run\n end", "def fatal; end", "def fatal?; end", "def fatal?; end", "def emergency(msg) log(0, msg); ...
[ "0.6470674", "0.6298678", "0.60889536", "0.60889536", "0.6025011", "0.59492826", "0.59469736", "0.5946252", "0.5928967", "0.5901154", "0.5887963", "0.58577347", "0.5852414", "0.5804016", "0.5784455", "0.57779163", "0.5771938", "0.5756146", "0.57371813", "0.5733984", "0.570250...
0.0
-1
Basic setup tasks performed on a new node during its first WinRM connection. Most of this is terrible Windows glue.
def initialWinRMTasks(shell) retries = 0 rebootable_fails = 0 begin if !@config['use_cloud_provider_windows_password'] pw = @groomer.getSecret( vault: @config['mu_name'], item: "windows_credentials", field: "password" ) win_check_for_pw = %Q{Add-Type -AssemblyName System.DirectoryServices.AccountManagement; $Creds = (New-Object System.Management.Automation.PSCredential("#{@config["windows_admin_username"]}", (ConvertTo-SecureString "#{pw}" -AsPlainText -Force)));$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine); $DS.ValidateCredentials($Creds.GetNetworkCredential().UserName, $Creds.GetNetworkCredential().password); echo $Result} resp = shell.run(win_check_for_pw) if resp.stdout.chomp != "True" win_set_pw = %Q{(([adsi]('WinNT://./#{@config["windows_admin_username"]}, user')).psbase.invoke('SetPassword', '#{pw}'))} resp = shell.run(win_set_pw) puts resp.stdout MU.log "Resetting Windows host password", MU::NOTICE, details: resp.stdout end end # Install Cygwin here, because for some reason it breaks inside Chef # XXX would love to not do this here pkgs = ["bash", "mintty", "vim", "curl", "openssl", "wget", "lynx", "openssh"] admin_home = "c:/bin/cygwin/home/#{@config["windows_admin_username"]}" install_cygwin = %Q{ If (!(Test-Path "c:/bin/cygwin/Cygwin.bat")){ $WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("http://cygwin.com/setup-x86_64.exe","$env:Temp/setup-x86_64.exe") Start-Process -wait -FilePath $env:Temp/setup-x86_64.exe -ArgumentList "-q -n -l $env:Temp/cygwin -R c:/bin/cygwin -s http://mirror.cs.vt.edu/pub/cygwin/cygwin/ -P #{pkgs.join(',')}" } if(!(Test-Path #{admin_home})){ New-Item -type directory -path #{admin_home} } if(!(Test-Path #{admin_home}/.ssh)){ New-Item -type directory -path #{admin_home}/.ssh } if(!(Test-Path #{admin_home}/.ssh/authorized_keys)){ New-Item #{admin_home}/.ssh/authorized_keys -type file -force -value "#{@deploy.ssh_public_key}" } } resp = shell.run(install_cygwin) if resp.exitcode != 0 MU.log "Failed at installing Cygwin", MU::ERR, details: resp end set_hostname = true hostname = nil if !@config['active_directory'].nil? if @config['active_directory']['node_type'] == "domain_controller" && @config['active_directory']['domain_controller_hostname'] hostname = @config['active_directory']['domain_controller_hostname'] @mu_windows_name = hostname set_hostname = true else # Do we have an AD specific hostname? hostname = @mu_windows_name set_hostname = true end else hostname = @mu_windows_name end resp = shell.run(%Q{hostname}) if resp.stdout.chomp != hostname resp = shell.run(%Q{Rename-Computer -NewName '#{hostname}' -Force -PassThru -Restart; Restart-Computer -Force}) MU.log "Renaming Windows host to #{hostname}; this will trigger a reboot", MU::NOTICE, details: resp.stdout reboot(true) sleep 30 end rescue WinRM::WinRMError, HTTPClient::ConnectTimeoutError => e retries, rebootable_fails = handleWindowsFail(e, retries, rebootable_fails, max_retries: 10, reboot_on_problems: true, retry_interval: 30) retry end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def SetUpNodes\n \n @nodes.each do |node|\n\n if node.type==\"R\" or node.type==\"A\" or node.type==\"G\"\n \t\n\tSetMode(node)\n\n\tEnforceChannels(node)\n\t\n\tSetEssid(node) # after this stage, with omf-5.4 the wlan interface is created.\n\t\n\tSetWifiPower(node)\n\n\tSetMtu(node)\n\t\n\tSetIp(n...
[ "0.6613323", "0.65186834", "0.6492129", "0.6326467", "0.63023156", "0.6208451", "0.6206191", "0.6199062", "0.61709434", "0.6152944", "0.6065814", "0.6042249", "0.5961434", "0.592379", "0.5896963", "0.5888718", "0.5888718", "0.5888718", "0.5888718", "0.5888718", "0.5876143", ...
0.6526297
1
Basic setup tasks performed on a new node during its first initial ssh connection. Most of this is terrible Windows glue.
def initialSSHTasks(ssh) win_env_fix = %q{echo 'export PATH="$PATH:/cygdrive/c/opscode/chef/embedded/bin"' > "$HOME/chef-client"; echo 'prev_dir="`pwd`"; for __dir in /proc/registry/HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/Session\ Manager/Environment;do cd "$__dir"; for __var in `ls * | grep -v TEMP | grep -v TMP`;do __var=`echo $__var | tr "[a-z]" "[A-Z]"`; test -z "${!__var}" && export $__var="`cat $__var`" >/dev/null 2>&1; done; done; cd "$prev_dir"; /cygdrive/c/opscode/chef/bin/chef-client.bat $@' >> "$HOME/chef-client"; chmod 700 "$HOME/chef-client"; ( grep "^alias chef-client=" "$HOME/.bashrc" || echo 'alias chef-client="$HOME/chef-client"' >> "$HOME/.bashrc" ) ; ( grep "^alias mu-groom=" "$HOME/.bashrc" || echo 'alias mu-groom="powershell -File \"c:/Program Files/Amazon/Ec2ConfigService/Scripts/UserScript.ps1\""' >> "$HOME/.bashrc" )} win_installer_check = %q{ls /proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Installer/} lnx_installer_check = %q{ps auxww | awk '{print $11}' | egrep '(/usr/bin/yum|apt-get|dpkg)'} lnx_updates_check = %q{( test -f /.mu-installer-ran-updates || ! test -d /var/lib/cloud/instance ) || echo "userdata still running"} win_set_pw = nil if windows? and !@config['use_cloud_provider_windows_password'] # This covers both the case where we have a windows password passed from a vault and where we need to use a a random Windows Admin password generated by MU::Cloud::Server.generateWindowsPassword pw = @groomer.getSecret( vault: @config['mu_name'], item: "windows_credentials", field: "password" ) win_check_for_pw = %Q{powershell -Command '& {Add-Type -AssemblyName System.DirectoryServices.AccountManagement; $Creds = (New-Object System.Management.Automation.PSCredential("#{@config["windows_admin_username"]}", (ConvertTo-SecureString "#{pw}" -AsPlainText -Force)));$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine); $DS.ValidateCredentials($Creds.GetNetworkCredential().UserName, $Creds.GetNetworkCredential().password); echo $Result}'} win_set_pw = %Q{powershell -Command "& {(([adsi]('WinNT://./#{@config["windows_admin_username"]}, user')).psbase.invoke('SetPassword', '#{pw}'))}"} end # There shouldn't be a use case where a domain joined computer goes through initialSSHTasks. Removing Active Directory specific computer rename. set_hostname = true hostname = nil if !@config['active_directory'].nil? if @config['active_directory']['node_type'] == "domain_controller" && @config['active_directory']['domain_controller_hostname'] hostname = @config['active_directory']['domain_controller_hostname'] @mu_windows_name = hostname set_hostname = true else # Do we have an AD specific hostname? hostname = @mu_windows_name set_hostname = true end else hostname = @mu_windows_name end win_check_for_hostname = %Q{powershell -Command '& {hostname}'} win_set_hostname = %Q{powershell -Command "& {Rename-Computer -NewName '#{hostname}' -Force -PassThru -Restart; Restart-Computer -Force }"} begin # Set our admin password first, if we need to if windows? and !win_set_pw.nil? and !win_check_for_pw.nil? output = ssh.exec!(win_check_for_pw) raise MU::Cloud::BootstrapTempFail, "Got nil output from ssh session, waiting and retrying" if output.nil? if !output.match(/True/) MU.log "Setting Windows password for user #{@config['windows_admin_username']}", details: ssh.exec!(win_set_pw) end end if windows? output = ssh.exec!(win_env_fix) output = ssh.exec!(win_installer_check) raise MU::Cloud::BootstrapTempFail, "Got nil output from ssh session, waiting and retrying" if output.nil? if output.match(/InProgress/) raise MU::Cloud::BootstrapTempFail, "Windows Installer service is still doing something, need to wait" end if set_hostname and !@hostname_set and @mu_windows_name output = ssh.exec!(win_check_for_hostname) raise MU::Cloud::BootstrapTempFail, "Got nil output from ssh session, waiting and retrying" if output.nil? if !output.match(/#{@mu_windows_name}/) MU.log "Setting Windows hostname to #{@mu_windows_name}", details: ssh.exec!(win_set_hostname) @hostname_set = true # Reboot from the API too, in case Windows is flailing if !@cloudobj.nil? @cloudobj.reboot else reboot end raise MU::Cloud::BootstrapTempFail, "Set hostname in Windows, waiting for reboot" end end else output = ssh.exec!(lnx_installer_check) if !output.nil? and !output.empty? raise MU::Cloud::BootstrapTempFail, "Linux package manager is still doing something, need to wait (#{output})" end if !@config['skipinitialupdates'] output = ssh.exec!(lnx_updates_check) if !output.nil? and output.match(/userdata still running/) raise MU::Cloud::BootstrapTempFail, "Waiting for initial userdata system updates to complete" end end end rescue RuntimeError => e raise MU::Cloud::BootstrapTempFail, "Got #{e.inspect} performing initial SSH connect tasks, will try again" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def setup\n create_vagrantfile()\n\n teardown()\n\n output << bold(color(\"localhost$\", :green)) << \" vagrant up\\n\"\n vagrant(\"up\")\n\n # Establish ssh connectivity\n nodes.each do |k,v|\n output << bold(color(\"localhost$\", :green)) << \" ssh #{k}\\n\"\n chan = N...
[ "0.71319485", "0.68619806", "0.6611577", "0.65918165", "0.65398633", "0.6499428", "0.6360139", "0.6351897", "0.63481176", "0.6339559", "0.6328013", "0.63023007", "0.6292811", "0.6223144", "0.6216185", "0.6192764", "0.6182316", "0.61616516", "0.61466134", "0.61063254", "0.6080...
0.6566243
4
Get a privileged Powershell session on the server in question, using SSLencrypted WinRM with certificate authentication.
def getWinRMSession(max_retries = 40, retry_interval = 60, timeout: 30, winrm_retries: 5, reboot_on_problems: false) nat_ssh_key, nat_ssh_user, nat_ssh_host, canonical_ip, ssh_user, ssh_key_name = getSSHConfig @mu_name ||= @config['mu_name'] conn = nil shell = nil opts = nil # and now, a thing I really don't want to do MU::MommaCat.addInstanceToEtcHosts(canonical_ip, @mu_name) # catch exceptions that circumvent our regular call stack Thread.abort_on_exception = false Thread.handle_interrupt(WinRM::WinRMWSManFault => :never) { begin Thread.handle_interrupt(WinRM::WinRMWSManFault => :immediate) { MU.log "(Probably harmless) Caught a WinRM::WinRMWSManFault in #{Thread.current.inspect}", MU::DEBUG, details: Thread.current.backtrace } ensure # Reraise something useful end } retries = 0 rebootable_fails = 0 begin MU.log "Calling WinRM on #{@mu_name}", MU::DEBUG, details: opts opts = { endpoint: 'https://'+@mu_name+':5986/wsman', retry_limit: winrm_retries, no_ssl_peer_verification: true, # XXX this should not be necessary; we get 'hostname "foo" does not match the server certificate' even when it clearly does match ca_trust_path: "#{MU.mySSLDir}/Mu_CA.pem", transport: :ssl, operation_timeout: timeout, client_cert: "#{MU.mySSLDir}/#{@mu_name}-winrm.crt", client_key: "#{MU.mySSLDir}/#{@mu_name}-winrm.key" } conn = WinRM::Connection.new(opts) MU.log "WinRM connection to #{@mu_name} created", MU::DEBUG, details: conn shell = conn.shell(:powershell) shell.run('ipconfig') # verify that we can do something rescue Errno::EHOSTUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError, OpenSSL::SSL::SSLError, SocketError, WinRM::WinRMError, Timeout::Error => e retries, rebootable_fails = handleWindowsFail(e, retries, rebootable_fails, max_retries: max_retries, reboot_on_problems: reboot_on_problems, retry_interval: retry_interval) retry ensure MU::MommaCat.removeInstanceFromEtcHosts(@mu_name) end shell end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def unelevated_session(retry_options = {})\n @unelevated_session ||= connection(retry_options).shell(:powershell)\n end", "def elevated_session(retry_options = {})\n @elevated_session ||= begin\n connection(retry_options).shell(:elevated).tap do |shell|\n shell.us...
[ "0.63803524", "0.5970169", "0.5886548", "0.56767565", "0.5490591", "0.54741263", "0.5374985", "0.533177", "0.5331369", "0.52885836", "0.5272939", "0.5250367", "0.523512", "0.52097565", "0.52004594", "0.51988655", "0.51868457", "0.51745814", "0.51243347", "0.510269", "0.505408...
0.5647581
4
The function is used to show student details for admin
def show if(session[:user]==nil) redirect_to "/login" and return end check=Auth.where(:username =>session[:user]).select('DISTINCT ON (username) *').pluck(:role) if(check[0]=='S' or check[0]=='Student' ) redirect_to studet_path(check,:uin =>session[:user]) and return end if params[:uin] == nil params[:uin] = session[:pdf_user] end @detail=Review.rev_func(params[:uin]).select('DISTINCT ON (reviews.user_id,reviews.year) *').limit(1) @revs=Review.rev_func(params[:uin]).select('DISTINCT ON (reviews.user_id,reviews.year) *') temp=@detail.pluck(:user_id) temp2=User.where(:uin => temp[0]).pluck(:advisor) temp3=User.where(:uin => temp2[0]).pluck(:first_name) temp4=User.where(:uin => temp2[0]).pluck(:last_name) if temp3!=[] and temp4!=[] temp5=temp3[0]+' '+temp4[0] @tempad=temp5 else @tempad="" end session[:pdf_user]= params[:uin] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n \n @student= Student.find(params[:id])\n \n \n end", "def show\n @student = set_student\n end", "def show\n @student = Student.find(params[:id])\n end", "def show\n @student = Student.find(params[:id])\n end", "def show\n @student = Student.find(params[:id])\n end", ...
[ "0.7845689", "0.7670518", "0.7561679", "0.7561679", "0.7561679", "0.7561679", "0.7561679", "0.7555189", "0.75509953", "0.7446141", "0.7432485", "0.74153227", "0.7347893", "0.734584", "0.7314786", "0.7312629", "0.72835207", "0.7276926", "0.72599614", "0.7254376", "0.72220767",...
0.0
-1
def user_create if params[:uin]=="" or params[:first_name]=="" or params[:last_name]=="" or params[:review_year]=="" or params[:email]=="" or params[:password]=="" or params[:c_password]=="" flash[:notice] = "No field can be empty" render '/searches/add_user' and return end if params[:password]!=params[:c_password] flash[:notice] = "Password and Confirm password Should Match" render '/searches/add_user' and return end temp2=Review.rev_func(params[:uin]) if temp2!=[] flash[:notice] = "User Already Exists" render '/searches/new' and return end params[:uin]=params[:uin].delete(' ') params[:first_name]=params[:first_name].delete(' ') params[:first_name]=params[:first_name].upcase params[:last_name]=params[:last_name].delete(' ') params[:email]=params[:email].delete(' ') params[:password]=params[:password].delete(' ') params[:c_password]=params[:c_password].delete(' ') params[:last_name]=params[:last_name].upcase temp=params[:advisor].match(/(\w+) (\w+)/) params[:advisor]=User.where(:first_name => temp[1] , :last_name => temp[2]).pluck(:uin) params[:advisor]=params[:advisor][0] Auth.create(:username => params[:uin],:role => params[:role],:password => params[:password],:email => params[:email]) User.create(:uin => params[:uin],:first_name => params[:first_name],:last_name => params[:last_name],:review_year => params[:review_year],:advisor => params[:advisor]) Review.create(:user_id => params[:uin],:year => params[:review_year]) flash[:notice] = "User Created Successfully" render '/searches/new' end
def user_create if(session[:user]==nil) redirect_to "/login" and return end if params[:uin]=="" or params[:first_name]=="" or params[:last_name]=="" or params[:review_year]=="" or params[:email]=="" flash[:notice] = "No field can be empty" redirect_to '/add_user' and return end temp2=Review.rev_func(params[:uin]) if temp2!=[] flash[:notice] = "User Already Exists" render '/searches/new' and return end params[:uin]=params[:uin].delete(' ') params[:first_name]=params[:first_name].delete(' ') params[:first_name]=params[:first_name].upcase params[:last_name]=params[:last_name].delete(' ') params[:email]=params[:email].delete(' ') params[:password]='0000' params[:c_password]='0000' params[:last_name]=params[:last_name].upcase temp=params[:advisor].match(/(\w+) (\w+)/) params[:advisor]=User.where(:first_name => temp[1] , :last_name => temp[2]).pluck(:uin) params[:advisor]=params[:advisor][0] Auth.create(:username => params[:uin],:role => params[:role],:password => params[:password],:email => params[:email]) User.create(:uin => params[:uin],:first_name => params[:first_name],:last_name => params[:last_name],:review_year => params[:review_year],:advisor => params[:advisor]) Review.create(:user_id => params[:uin],:year => params[:review_year]) flash[:notice] = "User Created Successfully" render '/searches/new' end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create\n if false\n render :text => params\n else\n\n @user = User.new(user_params)\n @user.create_user_id = session[:user_id]\n if params[\"user\"][:password] == params[\"user\"][:re_password]\n\n if @user.save\n #流水號\n insert_id_s...
[ "0.7465248", "0.72754776", "0.72232455", "0.722255", "0.72185504", "0.72101617", "0.7157568", "0.71543765", "0.7148023", "0.71327424", "0.71242887", "0.70432186", "0.70357424", "0.7023778", "0.6994198", "0.6982247", "0.69782555", "0.6976764", "0.694743", "0.6927086", "0.69054...
0.9730793
0
Checks javascript files for Prettier compliance. Generates `errors` based on file differences from prettier.
def check check_results .reject { |r| r.length.zero? } .map { |r| send_comment r } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def lint\n javascript_files.each do |file|\n file_content = get_file_content_as_json(file)\n code = %(\n JSHINT(#{file_content}, #{jshint_options}, #{jshint_globals});\n return JSHINT.errors;\n )\n errors[file] = context.exec(code)\n end\n end", "def lin...
[ "0.696745", "0.6866762", "0.63773096", "0.5973031", "0.5968085", "0.5746366", "0.5734438", "0.5637119", "0.55822057", "0.5515528", "0.5487848", "0.5458454", "0.5310359", "0.53018683", "0.5265963", "0.5255382", "0.51963586", "0.51767755", "0.5172092", "0.5165406", "0.51620585"...
0.0
-1
Get prettier's bin path return [String]
def prettier_path local = executable_path ? executable_path : "./node_modules/.bin/prettier" File.exist?(local) ? local : "prettier" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def bin\n return \"#{@protk_dir}/bin\"\n end", "def bin_path\n '/usr/local/bin'.p\n end", "def bin_path(_opts)\n '/bin'\n end", "def bin_path(_opts)\n '/bin'\n end", "def bin_path(_opts)\n '/bin'\n end", "def bin\n File.join(@root, 'bin')\n end", "def alternate_bin_p...
[ "0.75942713", "0.7016835", "0.67043364", "0.67043364", "0.67043364", "0.6454652", "0.64151555", "0.6294758", "0.62662596", "0.6254949", "0.6242533", "0.6204057", "0.61977947", "0.61323047", "0.61317647", "0.6051488", "0.6038188", "0.6008746", "0.60053265", "0.5954648", "0.595...
0.80149716
0
Get prettier' file pattern regex return [String]
def matching_file_regex file_regex ? file_regex : /\.js$/ end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def pattern\n segs = @tags.map { |tagged_segment| build_segment(tagged_segment) }\n segs.last.gsub!(/\\.$/, '')\n segs.unshift \"^\"\n segs.push \"\\\\.?$\"\n Regexp.new(segs.join)\n end", "def pattern2regex(pattern); end", "def regex_for(pattern)\n return pattern if Regexp ===...
[ "0.6581316", "0.6571851", "0.6422006", "0.63691014", "0.6294881", "0.6283125", "0.6200961", "0.61400735", "0.61400735", "0.60605747", "0.60070354", "0.60021055", "0.5992989", "0.5977307", "0.5896867", "0.58847535", "0.5863952", "0.5861991", "0.5838673", "0.579815", "0.5782388...
0.6700715
0
Get lint result regards the filtering option return [Hash]
def check_results bin = prettier_path raise "prettier is not installed" unless bin return run_check(bin, ".") unless filtering ((git.modified_files - git.deleted_files) + git.added_files) .select { |f| f[matching_file_regex] } .map { |f| f.gsub("#{Dir.pwd}/", "") } .map { |f| run_check(bin, f) } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def lint\n lint_results\n .reject { |r| r.nil? || r['messages'].length.zero? }\n .reject { |r| r['messages'].first['message'].include? 'matching ignore pattern' }\n .map { |r| send_comment r }\n end", "def lint\n []\n end", "def lint_results\n bin = eslint_path\n ...
[ "0.6210377", "0.6112849", "0.5698051", "0.5629338", "0.56079626", "0.54661274", "0.5461848", "0.5377522", "0.53758997", "0.5374422", "0.5374422", "0.5374422", "0.5370254", "0.5370254", "0.53580415", "0.53332967", "0.5286536", "0.52781713", "0.519369", "0.5193552", "0.5186186"...
0.53520733
15
Run prettier aginst a single file.
def run_check(bin, file) command = "#{bin} --list-different" command << " --config #{config_file}" if config_file command << " #{additional_args}" if additional_args result = `#{command} #{file}` result end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def prettier_path\n local = executable_path ? executable_path : \"./node_modules/.bin/prettier\"\n File.exist?(local) ? local : \"prettier\"\n end", "def pygmentize(file_name, code, lexer = nil)\n if lexer.present?\n Gitlab::Highlight.highlight(file_name, code)\n else\n ...
[ "0.6585797", "0.59290314", "0.5559853", "0.5299781", "0.52497834", "0.5212173", "0.5137138", "0.5120828", "0.5104793", "0.50013024", "0.4977718", "0.49138522", "0.48643175", "0.48254505", "0.48222095", "0.48161235", "0.47753114", "0.47721133", "0.47719726", "0.47668064", "0.4...
0.0
-1
Send comment with danger's fail method.
def send_comment(results) dir = "#{Dir.pwd}/" results.each do |r| filename = results["filePath"].gsub(dir, "") fail("File not formatted with Prettier", file: filename, line: 0) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def fail(reason)\n end", "def post_fail_message; end", "def fail!(exception = nil, comment: nil, backtrace: nil)\n self.status = \"Fail\"\n self.end_time = Time.now\n\n unless exception.blank?\n self.comment = exception.to_s\n self.backtrace = exception.backtrace.join(\"\\n\")\n...
[ "0.6847041", "0.68063587", "0.6464484", "0.6438094", "0.64310247", "0.6412582", "0.6343649", "0.6308159", "0.62753516", "0.6269057", "0.6269057", "0.62167585", "0.61927426", "0.61858547", "0.6170798", "0.6160426", "0.6160426", "0.6160426", "0.6160426", "0.61388856", "0.612582...
0.0
-1
def click(mode, pos) case mode when :f switch_flagged(pos) kina when :r reveal_tile(pos) end end
def reveal_tile(pos = self.cursor.pos) raise "spot taken" if revealed?(pos) reveal_bombs if bomb?(pos) cascade(pos) unless bomb?(pos) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def reveal_clicked(x,y)\n tile = get_tile([(x.fdiv(@rat)).to_i,(y.fdiv(@rat)).to_i])\n value = reveal_tile(tile.pos)\n paint\n return value\n end", "def click(x, y)\n clicked = @board.click(x, y) == 'bomb'\n game_over if clicked == 'bomb'\n revealed if clicked == 'revealed'\n @board.pri...
[ "0.668992", "0.6445191", "0.62971115", "0.61620724", "0.61620724", "0.61620724", "0.6070173", "0.6004642", "0.59994096", "0.59135616", "0.5874616", "0.58592874", "0.57553566", "0.5644016", "0.56031275", "0.55518633", "0.5517743", "0.5459609", "0.5449553", "0.5439518", "0.5410...
0.61166674
6
Ensure valid credentials, either by restoring from the saved credentials files or intitiating an OAuth2 authorization. If authorization is required, the user's default browser will be launched to approve the request.
def authorize client_id = Google::Auth::ClientId.from_file(CREDENTIALS_PATH) token_store = Google::Auth::Stores::FileTokenStore.new(file: TOKEN_PATH) authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store) user_id = 'default' credentials = authorizer.get_credentials(user_id) if credentials.nil? url = authorizer.get_authorization_url(base_url: OOB_URI) puts 'Open the following URL in the browser and enter the ' \ "resulting code after authorization:\n" + url code = gets credentials = authorizer.get_and_store_credentials_from_code( user_id: user_id, code: code, base_url: OOB_URI ) end credentials end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def authorize\r\n client_id = Google::Auth::ClientId.from_file CREDENTIALS_PATH\r\n token_store = Google::Auth::Stores::FileTokenStore.new file: TOKEN_PATH\r\n authorizer = Google::Auth::UserAuthorizer.new client_id, SCOPE, token_store\r\n user_id = \"default\"\r\n credentials = authorizer.get_credentials use...
[ "0.69332373", "0.6722061", "0.6658772", "0.66525155", "0.6556611", "0.65258646", "0.649897", "0.64935994", "0.6472398", "0.64645433", "0.6456058", "0.64552265", "0.6452492", "0.64505297", "0.64492494", "0.64413005", "0.6438607", "0.6409508", "0.6401031", "0.6395657", "0.63947...
0.6328389
38
Subject can be set in your I18n file at config/locales/en.yml with the following lookup: en.notifications.invitation.subject
def invitation(user) @user = user mail to: user.email end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def subject\n @options.fetch(:subject) { \"Invitation\" }\n end", "def deliver_invitation(options = {})\n super(options.merge(subject: _('A Data Management Plan in %{application_name} has been shared with you') % {application_name: Rails.configuration.branding[:application][:name]}))\n end", "def subje...
[ "0.7471469", "0.7104286", "0.703749", "0.68265396", "0.6792275", "0.6746061", "0.66665125", "0.65584445", "0.6527312", "0.6372968", "0.6371469", "0.63520604", "0.63486785", "0.63220483", "0.63106805", "0.63035166", "0.63015187", "0.62751955", "0.62705505", "0.62181646", "0.62...
0.0
-1
Only allow a trusted parameter "allowed list" through.
def invitation_params params.require(:invitation).permit(:slack_uid, :invitee_name, :invitee_email, :invitee_title, :invitee_company, :invitation) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def allowed_params\n ALLOWED_PARAMS\n end", "def expected_permitted_parameter_names; end", "def permitted_params\n []\n end", "def parameters_list_params\n params.require(:parameters_list).permit(:name, :description, :is_user_specific)\n end", "def param_whitelist\n [:role, :titl...
[ "0.75540984", "0.7406233", "0.6965594", "0.68537813", "0.68317914", "0.66484946", "0.6635215", "0.658638", "0.65657544", "0.6522243", "0.6512206", "0.64110196", "0.6384892", "0.6380021", "0.6354687", "0.6343312", "0.6336751", "0.6328964", "0.6328964", "0.62808925", "0.6274692...
0.0
-1
validates :area, presence: true
def pretty_time hour = created_at.strftime("%l").to_i - 5 created_at.strftime("%A, %b %d, %Y") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def valid?\n\t\tarea != 0\n\tend", "def check\n @area = Area.new(params[:area])\n render :action => :new, :status => 400 and return unless @area.valid?\n end", "def area_params\n params.require(:area).permit(:name)\n end", "def create\n @area = Area.new(area_params)\n if @area.save\n ...
[ "0.7490956", "0.7239055", "0.71439475", "0.6708339", "0.6646442", "0.66171443", "0.6616461", "0.65914965", "0.6460093", "0.6460093", "0.6454851", "0.6422755", "0.641047", "0.6397817", "0.63694984", "0.6369254", "0.63685596", "0.6331007", "0.6304981", "0.62905884", "0.62887615...
0.0
-1
GET /post245s/1 GET /post245s/1.xml
def show @post245 = Post245.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @post245 } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n @post246 = Post246.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.xml { render :xml => @post246 }\n end\n end", "def show\n @post253 = Post253.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.x...
[ "0.6550024", "0.65199137", "0.64973384", "0.6492459", "0.6473633", "0.64673334", "0.6465491", "0.64645696", "0.64496744", "0.6449018", "0.6437833", "0.64361906", "0.6434007", "0.6431821", "0.6431296", "0.6429372", "0.64283544", "0.64221495", "0.6415135", "0.64117503", "0.6411...
0.66521925
0
GET /post245s/new GET /post245s/new.xml
def new @post245 = Post245.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @post245 } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def new\n @post227 = Post227.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @post227 }\n end\n end", "def new\n @post181 = Post181.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @post181 }\...
[ "0.75468683", "0.7529592", "0.7527816", "0.7523501", "0.75135404", "0.7512198", "0.75068295", "0.74971044", "0.74957514", "0.7480228", "0.747276", "0.74702656", "0.74669313", "0.7466168", "0.7459356", "0.74566287", "0.7451512", "0.744815", "0.7447317", "0.7440483", "0.7439383...
0.7602735
0
POST /post245s POST /post245s.xml
def create @post245 = Post245.new(params[:post245]) respond_to do |format| if @post245.save format.html { redirect_to(@post245, :notice => 'Post245 was successfully created.') } format.xml { render :xml => @post245, :status => :created, :location => @post245 } else format.html { render :action => "new" } format.xml { render :xml => @post245.errors, :status => :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def post(uri, xml)\r\n req = Net::HTTP::Post.new(uri)\r\n req[\"content-type\"] = \"application/xml\"\r\n req.body = xml\r\n request(req)\r\n end", "def post(xmldoc)\n headers = {'Content-Type' => 'text/xml'}\n check_response( @httpcli.post(@endpoint, xmldoc, headers) )\n end", "d...
[ "0.64290154", "0.6066192", "0.5991393", "0.59452283", "0.5931579", "0.59171975", "0.59149444", "0.5834256", "0.5820395", "0.58191323", "0.579816", "0.57885826", "0.5755538", "0.5749679", "0.5731428", "0.5725543", "0.57033277", "0.5695275", "0.5694588", "0.5684866", "0.568192"...
0.6251423
1
PUT /post245s/1 PUT /post245s/1.xml
def update @post245 = Post245.find(params[:id]) respond_to do |format| if @post245.update_attributes(params[:post245]) format.html { redirect_to(@post245, :notice => 'Post245 was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @post245.errors, :status => :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def put(uri, xml)\r\n req = Net::HTTP::Put.new(uri)\r\n req[\"content-type\"] = \"application/xml\"\r\n req.body = xml\r\n request(req)\r\n end", "def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post 'update', opts\n end", "def res...
[ "0.67700464", "0.65570354", "0.6190327", "0.6136941", "0.5965138", "0.58659875", "0.58550537", "0.58450973", "0.5836433", "0.57615495", "0.57425874", "0.5738284", "0.5732333", "0.57172805", "0.56996405", "0.5687494", "0.5683028", "0.56753576", "0.5673552", "0.5662", "0.565083...
0.61452556
3
DELETE /post245s/1 DELETE /post245s/1.xml
def destroy @post245 = Post245.find(params[:id]) @post245.destroy respond_to do |format| format.html { redirect_to(post245s_url) } format.xml { head :ok } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy\n @post445 = Post445.find(params[:id])\n @post445.destroy\n\n respond_to do |format|\n format.html { redirect_to(post445s_url) }\n format.xml { head :ok }\n end\n end", "def destroy\n @post154 = Post154.find(params[:id])\n @post154.destroy\n\n respond_to do |format|\n...
[ "0.70254713", "0.69918907", "0.6966926", "0.6956578", "0.69497263", "0.6944906", "0.6921125", "0.69131374", "0.6908971", "0.6908146", "0.6903623", "0.68766314", "0.6868062", "0.6864705", "0.685421", "0.6849582", "0.68486106", "0.68477213", "0.6847519", "0.68396556", "0.682568...
0.70457685
0
Called after every test method runs. Can be used to tear down fixture information.
def teardown # Do nothing end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def after_teardown; end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def teardown\n end", "def tear...
[ "0.8025238", "0.79543626", "0.79543626", "0.78571093", "0.7845288", "0.7845288", "0.7845288", "0.7845288", "0.7845288", "0.7845288", "0.7845288", "0.7845288", "0.78336143", "0.78336143", "0.7750328", "0.77483624", "0.77483624", "0.7734571", "0.7713144", "0.7711698", "0.771169...
0.7384664
73
called recursively to collect all the graphable numeric field names
def add_field_names depth, attributes, field_hash, filter_hash if field_hash[depth] == nil field_hash[depth] = Array.new end attributes.each do |key, value| if value.is_a? Hash if filter_hash[depth] != nil and filter_hash[depth].include?(key) field_hash = add_field_names(depth+1, value, field_hash, filter_hash) end end unless value.is_a? String field_hash[depth] << key end end return field_hash end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def fix_numerals\n hash = self.clone\n traverse hash\n hash\n end", "def process_header_repeatable_field_names_do_not_have_numbers(header)\n\n child_field_group = nil\n\n first_field, rest_of_header = header.split(':',2)\n\n if first_field == header\n\n # we have a field name, i.e. a dyna...
[ "0.5432866", "0.53102565", "0.52796835", "0.52709085", "0.522065", "0.5217539", "0.5139538", "0.5131412", "0.5102048", "0.5074465", "0.50738597", "0.5064006", "0.5051592", "0.50502515", "0.50409746", "0.5034112", "0.5014364", "0.49989843", "0.49852598", "0.49756688", "0.49630...
0.5048839
14
GET /product_use_printruns GET /product_use_printruns.xml
def index @product_use_printruns = ProductUsePrintrun.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @product_use_printruns } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n @product_use_printrun = ProductUsePrintrun.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.xml { render :xml => @product_use_printrun }\n end\n end", "def onix_xml_for_product(product_or_rr, full_message = false) #:nodoc:\n if product_o...
[ "0.7011666", "0.61986554", "0.61970097", "0.61491007", "0.6111791", "0.5969342", "0.5935867", "0.59034646", "0.5873566", "0.58492506", "0.5834952", "0.58194816", "0.58069474", "0.5805488", "0.57976824", "0.5793734", "0.57750386", "0.5768335", "0.5760595", "0.5740809", "0.5737...
0.7536538
0
GET /product_use_printruns/1 GET /product_use_printruns/1.xml
def show @product_use_printrun = ProductUsePrintrun.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @product_use_printrun } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @product_use_printruns = ProductUsePrintrun.find(:all)\n\n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @product_use_printruns }\n end\n end", "def onix_xml_for_product(product_or_rr, full_message = false) #:nodoc:\n if product_or_r...
[ "0.7466165", "0.6433961", "0.6245989", "0.6226469", "0.6208665", "0.6183744", "0.61757606", "0.6167591", "0.61493796", "0.6140269", "0.61345553", "0.612788", "0.6125291", "0.6104269", "0.6099971", "0.605909", "0.60544336", "0.6052511", "0.60518193", "0.60450006", "0.6041839",...
0.7193476
1
GET /product_use_printruns/new GET /product_use_printruns/new.xml
def new @product_use_printrun = ProductUsePrintrun.new @product_categories = ProductCategory.find(:all) @product_use_printrun.product_categories << @product_categories[params[:id].to_i-1] if params[:id] respond_to do |format| format.html # new.html.erb format.xml { render :xml => @product_use_printrun } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def new\n\t\t@produt = Produt.new\n\t\trespond_to do |format|\n\t\t\tformat.html # new.html.erb\n\t\t\tformat.xml {render :xml => @produt}\n\t\tend\n\tend", "def new\n respond_to do |format|\n format.html { render_template } # new.html.erb\n format.xml { render xml: @product_software }\n end\n ...
[ "0.70992976", "0.7025299", "0.6998484", "0.6950256", "0.6943805", "0.6932873", "0.6849657", "0.68334633", "0.6822813", "0.67955315", "0.67910445", "0.67889583", "0.67810893", "0.677286", "0.6757612", "0.6757612", "0.6757612", "0.6757612", "0.6757612", "0.6757612", "0.6757612"...
0.6875149
6
POST /product_use_printruns POST /product_use_printruns.xml
def create @product_use_printrun = ProductUsePrintrun.new(params[:product_use_printrun]) @product_categories = ProductCategory.find(:all) checked_features = check_features_using_helper( params[:product_prints_list], ProductCategory, @product_use_printrun.product_categories ) respond_to do |format| if @product_use_printrun.save flash[:notice] = 'ProductUsePrintrun was successfully created.' format.html { redirect_to :controller => 'product_categories', :action => "index" } format.xml { render :xml => @product_use_printrun, :status => :created, :location => @product_use_printrun } else format.html { render :action => "new" } format.xml { render :xml => @product_use_printrun.errors, :status => :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @product_use_printruns = ProductUsePrintrun.find(:all)\n\n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @product_use_printruns }\n end\n end", "def create\r\n @se_use_product = SeUseProduct.new(params[:se_use_product])\r\n\r\n respond_...
[ "0.61316276", "0.5775731", "0.57378286", "0.5716126", "0.5703085", "0.56346285", "0.5615487", "0.55764484", "0.5542313", "0.5537466", "0.55358696", "0.5517816", "0.54330254", "0.5428313", "0.5417166", "0.5409969", "0.53628206", "0.5361887", "0.5352742", "0.534611", "0.5324688...
0.6349668
0
PUT /product_use_printruns/1 PUT /product_use_printruns/1.xml
def update @product_use_printrun = ProductUsePrintrun.find(params[:id]) @product_categories = ProductCategory.find(:all) checked_features = check_features_using_helper( params[:product_prints_list], ProductCategory, @product_use_printrun.product_categories ) uncheck_missing_features_helper( @product_categories, checked_features, @product_use_printrun.product_categories ) respond_to do |format| if @product_use_printrun.update_attributes(params[:product_use_printrun]) flash[:notice] = 'ProductUsePrintrun was successfully updated.' format.html { redirect_to :controller => 'product_categories', :action => "index" } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @product_use_printrun.errors, :status => :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\r\n @se_use_product = SeUseProduct.find(params[:id])\r\n\r\n respond_to do |format|\r\n if @se_use_product.update_attributes(params[:se_use_product])\r\n format.html { redirect_to(@se_use_product, :notice => 'Se use product was successfully updated.') }\r\n format.xml { head :o...
[ "0.64690864", "0.63131523", "0.61795145", "0.6139256", "0.612022", "0.5986314", "0.59827644", "0.5952095", "0.59461963", "0.5909815", "0.5894153", "0.5893239", "0.5877406", "0.5874254", "0.58695847", "0.5865181", "0.5834475", "0.5824009", "0.5818453", "0.5813305", "0.5793699"...
0.6055777
5
DELETE /product_use_printruns/1 DELETE /product_use_printruns/1.xml
def destroy @product_use_printrun = ProductUsePrintrun.find(params[:id]) @product_use_printrun.destroy respond_to do |format| format.html { redirect_to(product_use_printruns_url) } format.xml { head :ok } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def remove_configuration_product\r\n # node = ProductPackageProduct.find(params[:id].to_i).destroy\r\n # redirect_to :action => \"configuration_products\", :id => node.parent_id\r\n ExampleConfigurationProduct.delete params[:id]\r\n redirect_to :action => \"configuration_products\", :id => params[:id]\...
[ "0.6926008", "0.68583083", "0.6710689", "0.65532064", "0.65359986", "0.6492066", "0.63858956", "0.63825035", "0.6372587", "0.6358469", "0.6333777", "0.63296753", "0.6324634", "0.6320933", "0.6292747", "0.6269973", "0.62526375", "0.62462", "0.62445104", "0.62292045", "0.620576...
0.6962447
0
=== We translate to === 0, 1, 1, D, A, !D, !A, D, A, D+1, A+1, D1, A1, D+A, DA, AD, D&A, D|A M, !M, M, M+1, D+M, DM, MD, D&M, D|M null, JGT, JEQ, JGE, JLT, JNE, JLE, JMP R0, R1, ..., R15, SP, LCL, ARG, THIS, THAT SCREEN, KBD
def parse(input_file, label_count) output = [] input_file.each_line do |line| next if line.match(/\/\/.*/) if match = line.match(/push (?<segment>.+) (?<index>.+)/) push_constant_asm = %{ @%s D=A @SP A=M M=D @SP M=M+1 } push_relative_asm = %{ @%s D=A @%s A=D+M D=M @SP A=M M=D @SP M=M+1 } push_pointer_asm = %{ @%s D=A @L#{label_count} D;JEQ @THAT D=M @L#{label_count + 1} 0;JMP (L#{label_count}) @THIS D=M (L#{label_count + 1}) @SP A=M M=D @SP M=M+1 } push_indirect_asm = %{ @%s D=A @%s A=D+A D=M @SP A=M M=D @SP M=M+1 } case match[:segment] when "constant" output << (push_constant_asm % match[:index].strip).split when "local" output << (push_relative_asm % [match[:index].strip, "LCL"]).split when "argument" output << (push_relative_asm % [match[:index].strip, "ARG"]).split when "this" output << (push_relative_asm % [match[:index].strip, "THIS"]).split when "that" output << (push_relative_asm % [match[:index].strip, "THAT"]).split when "pointer" output << (push_pointer_asm % match[:index].strip).split label_count = label_count + 2 when "temp" output << (push_indirect_asm % [match[:index].strip, "R5"]).split when "static" output << (push_indirect_asm % [match[:index].strip, "16"]).split end end pop_relative_asm = %{ @%s D=M @%s D=D+A @R13 M=D @SP AM=M-1 D=M @R13 A=M M=D } pop_pointer_asm = %{ @%s D=A @L#{label_count} D;JEQ @THAT D=A @L#{label_count + 1} 0;JMP (L#{label_count}) @THIS D=A (L#{label_count + 1}) @R13 M=D @SP AM=M-1 D=M @R13 A=M M=D } pop_indirect_asm = %{ @%s D=A @%s D=D+A @R13 M=D @SP AM=M-1 D=M @R13 A=M M=D } if match = line.match(/pop (?<segment>.+) (?<index>.+)/) case match[:segment] when "local" output << (pop_relative_asm % ["LCL", match[:index].strip]).split when "argument" output << (pop_relative_asm % ["ARG", match[:index].strip]).split when "this" output << (pop_relative_asm % ["THIS", match[:index].strip]).split when "that" output << (pop_relative_asm % ["THAT", match[:index].strip]).split when "pointer" output << (pop_pointer_asm % match[:index].strip).split label_count = label_count + 2 when "temp" output << (pop_indirect_asm % [match[:index].strip, "R5"]).split when "static" output << (pop_indirect_asm % [match[:index].strip, "16"]).split end end math_asm = %{ @SP D=M AM=D-1 D=M A=A-1 M=M%sD } output << (math_asm % "+").split if line.match(/add/) output << (math_asm % "-").split if line.match(/sub/) binary_logic_asm = %{ @SP D=M AM=D-1 D=M A=A-1 M=D%sM } output << (binary_logic_asm % "|").split if line.match(/or/) output << (binary_logic_asm % "&").split if line.match(/and/) unary_logic_asm = %{ @SP A=M-1 D=M M=%sD } output << (unary_logic_asm % "-").split if line.match(/neg/) output << (unary_logic_asm % "!").split if line.match(/not/) comp_asm = %{ @SP AM=M-1 D=M A=A-1 D=M-D @L#{label_count} D;%s D=0 @L#{label_count + 1} 0;JMP (L#{label_count}) D=-1 (L#{label_count + 1}) @SP A=M-1 M=D } if line.match(/eq/) output << (comp_asm % "JEQ").split label_count = label_count + 2 end if line.match(/gt/) output << (comp_asm % "JGT").split label_count = label_count + 2 end if line.match(/lt/) output << (comp_asm % "JLT").split label_count = label_count + 2 end end return [output, label_count] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def jump(_jump)\n j1 = '0'\n j2 = '0'\n j3 = '0'\n\n if (_jump == 'null')\n #Do nothing\n elsif (_jump == 'JGT')\n j3 = '1'\n elsif (_jump == 'JEQ')\n j2 = '1'\n elsif (_jump == 'JGE')\n j2 = '1'\n j3 = '1'\n ...
[ "0.54872876", "0.54670274", "0.54568046", "0.54090965", "0.5392224", "0.53543544", "0.5337828", "0.5335366", "0.52676237", "0.5257896", "0.5230528", "0.5226921", "0.5214803", "0.5211178", "0.5151794", "0.5124544", "0.5120772", "0.5113183", "0.51086766", "0.5092279", "0.509048...
0.0
-1
Takes a file and loads the properties in that file
def initialize file EasyTranslate.api_key = 'AIzaSyDrbD0AfKHiMZTYoite-ec4byLNlPxoX8k' @file = file @properties = [] File.open(file, "r:UTF-8").each do |line| @properties << line end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def load_properties(properties_filename)\n properties = {}\n File.open(properties_filename, 'r') do |properties_file|\n properties_file.read.each_line do |line|\n line.strip!\n if (line[0] != ?# and line[0] != ?=)\n Chef::Log.info \"line : #{line}\"\n i = li...
[ "0.74696195", "0.7174317", "0.7119959", "0.70425785", "0.70245683", "0.6925434", "0.68896997", "0.6869388", "0.68276376", "0.6787021", "0.6736639", "0.670938", "0.6686991", "0.6632225", "0.6617322", "0.6617322", "0.6609608", "0.6599762", "0.6575841", "0.6575123", "0.6553132",...
0.7158013
2
Save the properties back to file
def save filename File.open(filename, 'w') { |file| @translated.each {|value| file.write("#{value}") } } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def save\n file = File.new(@file, 'w+')\n @properties.each { |key, value| file.puts \"#{key}=#{value}\\n\" }\n end", "def save\n file = File.new(@file,\"w+\")\n @properties.each {|key,value| file.puts \"#{key}=#{value}\\n\" }\n file.close\n end", "def save\n file = File.new(@file,\"w+\")\n @...
[ "0.8571951", "0.8441881", "0.8173245", "0.80819947", "0.7161865", "0.7098612", "0.7059542", "0.70456755", "0.7007282", "0.6993434", "0.6984136", "0.6939637", "0.67711157", "0.67557836", "0.67557836", "0.6670473", "0.6650842", "0.6626342", "0.6620851", "0.65961033", "0.6574523...
0.5759022
100
Check whether the path is correct, particularly if we are making a webbased report
def allow_path(path) unless @web_document_root.nil? unless ancestor?(@web_document_root, path) raise OperationalError, "Report #{path} is not an ancestor of the web root #{@web_document_root}" end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def user_path?(file); end", "def valid_path path\n path and File.exists? path\n end", "def validate_file_path\n base_path = ::File.realpath(self.class.temp_dir)\n @path = ::File.realpath(params.permit(:file)[:file], base_path)\n unless @path.start_with?(base_path)\n raise ViewComponent::S...
[ "0.68995434", "0.68869215", "0.6711418", "0.65979177", "0.65624976", "0.65154403", "0.6491817", "0.64865386", "0.6483319", "0.64182436", "0.63812447", "0.63698685", "0.6332655", "0.63273966", "0.6303586", "0.6292887", "0.6274326", "0.62506956", "0.6212557", "0.6189066", "0.61...
0.66717005
3
TODO add configuration to allow custom selection of what types of cards are accepted
def validate cc = self.credit_card cc.validate cc.errors.full_messages.each do |e| self.errors.add_to_base(e) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def card_types\n card_types = [\"Visa\", \"Mastercard\", \"Discover\", \"American Express\"]\n end", "def set_card_types\r\n credit_cards = 'vi-mc'\r\n credit_cards.concat('-di') if @PARAM_HASH['DISCOVER_IMAGE'] == 'discvr.gif'\r\n credit_cards.concat('-am') if @PARAM_HASH['AMEX_IMAGE'] == 'amex.gif...
[ "0.7482183", "0.72688854", "0.72688854", "0.7063475", "0.704859", "0.6933525", "0.68257904", "0.6736885", "0.6682585", "0.66658336", "0.66642684", "0.6643928", "0.66120166", "0.66077936", "0.6528977", "0.6513891", "0.64979213", "0.6483292", "0.6478766", "0.6461557", "0.643860...
0.0
-1
METODOS Falta agregar mas parametros para todos los tipos de udpate
def registrar_log(tipo) logd = Logdocumento.new(:usuario_id => Usuario.current.id, :documento_id => self.id, :tipo => tipo, :producto_id => self.producto_id, :nusuario => Usuario.current.nombre, :ndocumento => self.TipoDocumento.descripcion, :nproducto => self.producto.nombre) return logd.save end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update!(**args)\n @create_time = args[:create_time] if args.key?(:create_time)\n @data = args[:data] if args.key?(:data)\n @labels = args[:labels] if args.key?(:labels)\n @message_type = args[:message_type] if args.key?(:message_type)\n @name = args[:name] if args.k...
[ "0.61294025", "0.58743984", "0.5829069", "0.5815044", "0.5808111", "0.5784111", "0.57625055", "0.57401234", "0.56835395", "0.5667101", "0.56587625", "0.56413907", "0.56222713", "0.5607583", "0.55950594", "0.5585658", "0.5584783", "0.5583478", "0.5568475", "0.55607265", "0.556...
0.0
-1
GET /dairy_plans GET /dairy_plans.json
def index @dairy_plans = DairyPlan.where(:student_id => @student.id) respond_to do |format| format.html # index.html.erb format.json { render json: @dairy_plans } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def plans(params = {})\n scope 'default'\n get('plans/', params)\n end", "def index\n @plans = Plan.all\n\n render json: @plans\n end", "def show\n @plans = Stripe::Plan.all\n end", "def index\n @plans = Plan.all\n\n respond_to do |format|\n format.html # index.html.erb\n ...
[ "0.75700945", "0.7391554", "0.7041859", "0.7036185", "0.7015556", "0.6997302", "0.6970295", "0.6969083", "0.68498033", "0.6761254", "0.67324084", "0.67324084", "0.66956884", "0.668163", "0.6630735", "0.6614019", "0.65910304", "0.65895116", "0.6586368", "0.6580148", "0.6560861...
0.7008957
5
GET /dairy_plans/1 GET /dairy_plans/1.json
def show @dairy_plan = DairyPlan.find(params[:id]) @simple_view = params[:cal] ? false : true # 查询所有的课程内容安排 一天五节课 @course_content_1 = CourseContent.where(:dairy_plan_id => @dairy_plan.id, :course_num => 1).first @course_content_2 = CourseContent.where(:dairy_plan_id => @dairy_plan.id, :course_num => 2).first @course_content_3 = CourseContent.where(:dairy_plan_id => @dairy_plan.id, :course_num => 3).first @course_content_4 = CourseContent.where(:dairy_plan_id => @dairy_plan.id, :course_num => 4).first @course_content_5 = CourseContent.where(:dairy_plan_id => @dairy_plan.id, :course_num => 5).first respond_to do |format| format.html # show.html.erb format.json { render json: @dairy_plan } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @plans = Plan.all\n\n render json: @plans\n end", "def show\n @plan = Plan.find(params[:id])\n\n render json: @plan\n end", "def plans(params = {})\n scope 'default'\n get('plans/', params)\n end", "def show\n render json: @plan\n end", "def index\n @plans = Pl...
[ "0.7467771", "0.73599935", "0.7338609", "0.72477686", "0.7201629", "0.70725435", "0.70584136", "0.696558", "0.69240564", "0.6923742", "0.6899089", "0.68976045", "0.68830913", "0.68632334", "0.6847939", "0.6836914", "0.68143326", "0.6783236", "0.6772346", "0.676304", "0.676304...
0.0
-1
GET /dairy_plans/new GET /dairy_plans/new.json
def new @dairy_plan = DairyPlan.new respond_to do |format| format.html # new.html.erb format.json { render json: @dairy_plan } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def new\n @plan = Plan.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @plan }\n end\n end", "def new\n @plan = Plan.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @plan }\n end\n end", "d...
[ "0.77941835", "0.77941835", "0.754383", "0.7536883", "0.7500785", "0.74407995", "0.7434541", "0.7434278", "0.73549443", "0.73378897", "0.7290985", "0.7289623", "0.7209163", "0.7165532", "0.7118802", "0.7093485", "0.7091816", "0.70862377", "0.70838434", "0.7062924", "0.7021278...
0.7748617
2
POST /dairy_plans POST /dairy_plans.json
def create @dairy_plan = DairyPlan.new(params[:dairy_plan]) @dairy_plan.spm = @student.spm @dairy_plan.student = @student # 时间处理 需要判断是否填写 if params[:dairy_plan][:plan_date].to_s != "" date1 = DateTime.strptime(params[:dairy_plan][:plan_date] + " CCT", "%Y-%m-%d %Z") @dairy_plan.plan_date = date1 end respond_to do |format| if @dairy_plan.save format.html { redirect_to student_dairy_plans_path(@student), notice: 'Dairy plan was successfully created.' } format.json { render json: student_dairy_plans_path(@student), status: :created, location: @dairy_plan } else format.html { render action: "new" } format.json { render json: @dairy_plan.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create\n @plan = Plan.new(params[:plan])\n\n if @plan.save\n render json: @plan, status: :created, location: @plan\n else\n render json: @plan.errors, status: :unprocessable_entity\n end\n end", "def create\n @plan = Plan.new(plan_params)\n\n if @plan.save\n render json: @pl...
[ "0.685176", "0.6822982", "0.6627809", "0.6565976", "0.6561254", "0.65425974", "0.65425974", "0.6534557", "0.6455788", "0.6432151", "0.64318585", "0.6369616", "0.63623357", "0.63617617", "0.633691", "0.6321141", "0.6305228", "0.6272402", "0.62480885", "0.62048316", "0.62039655...
0.61757267
25
PUT /dairy_plans/1 PUT /dairy_plans/1.json
def update @dairy_plan = DairyPlan.find(params[:id]) if params[:dairy_plan][:plan_date].to_s != "" date1 = DateTime.strptime(params[:dairy_plan][:plan_date] + " CCT", "%Y-%m-%d %Z") params[:dairy_plan][:plan_date] = date1 end respond_to do |format| if @dairy_plan.update_attributes(params[:dairy_plan]) # 更新所有此计划下的课程 CourseContent.where(:dairy_plan_id => @dairy_plan.id).update_all(:plan_date => date1) format.html { redirect_to student_dairy_plan_path(@student,@dairy_plan), notice: 'Dairy plan was successfully updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @dairy_plan.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n @plan = Plan.find(params[:id])\n\n if @plan.update(params[:plan])\n head :no_content\n else\n render json: @plan.errors, status: :unprocessable_entity\n end\n end", "def update\n @plan = Plan.find(params[:id])\n\n if @plan.update(plan_params)\n head :no_content\n ...
[ "0.7073873", "0.7072488", "0.6765213", "0.6765213", "0.6737903", "0.67075473", "0.66997933", "0.66997933", "0.66997933", "0.66997933", "0.66997933", "0.66792053", "0.664666", "0.6628924", "0.659729", "0.6558785", "0.65347445", "0.6520873", "0.64665", "0.6445309", "0.643712", ...
0.62970966
29
DELETE /dairy_plans/1 DELETE /dairy_plans/1.json
def destroy # 先删除所有课程 CourseContent.where(:dairy_plan_id => params[:id]).delete_all @dairy_plan = DairyPlan.find(params[:id]) @dairy_plan.destroy respond_to do |format| format.html { redirect_to student_dairy_plans_url(@student) } format.json { head :no_content } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy\n @plan.destroy\n respond_to do |format|\n format.html { redirect_to plans_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @plan.destroy\n respond_to do |format|\n format.html { redirect_to plans_url }\n format.json { head :no_content }\n e...
[ "0.723193", "0.723193", "0.7202914", "0.7196423", "0.719517", "0.7103689", "0.7103689", "0.7103689", "0.70369637", "0.69917995", "0.6977669", "0.69722354", "0.697045", "0.69504213", "0.69504213", "0.69504213", "0.69504213", "0.69504213", "0.69504213", "0.69504213", "0.6950421...
0.66822433
44
Use callbacks to share common setup or constraints between actions.
def set_contact @contact = Contact.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
Andreas Landgrebe Method to create a list input: string of items separated by spaces (example: "carrots apples cereal pizza") steps: [fill in any steps here] list[array] = string.split set default quantity = 1 print the list to the console [can you use one of your other methods here?] output: [what data type goes here, array or hash?] convert your item string into an array of strings for each element in the array of strings, => create a list_item so that quantity is 1 and the item is the element => push the list_item into the $list array
def new_list(item_String, quantity = 1) $list = [] array_strings = item_String.split array_strings.each do |element| list_item = { quantity: quantity, item: element } $list.push(list_item) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def createlist(str)\r\n# steps:\r\n# break the string into an array\r\n items = str.split\r\n item_list = {}\r\n\r\n\t# iterate through array and build hash\r\n items.each do |item|\r\n\r\n\t\t# iterate through array and build hash\r\n\t\t# set default quantity to 1\r\n \titem_list[item] = 1\r\n e...
[ "0.7801356", "0.77147293", "0.7586138", "0.7570771", "0.75119305", "0.7508747", "0.7478245", "0.7356043", "0.72952074", "0.72460777", "0.7242356", "0.7232883", "0.72121054", "0.7211208", "0.72045326", "0.72030073", "0.7180621", "0.7168537", "0.7162864", "0.71596295", "0.71543...
0.82552314
0
Method to remove an item from the list input: item and using array as a global variable steps: use delete or delete_if to remove an item from array output: remove the item from the list.
def update_quantity (quantity, item) $list.each do |list_item| if list_item[:item] == item list_item[:quantity] = quantity end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def remove_item(list, item)\r\n# input: shopping list and item to be removed\r\n# steps: \r\n # Use shopping list as input\r\n # Use item to be removed as input\r\n # Remove the item from the list if it exists on the list\r\n list.delete(item)\r\n# output: shopping list with item removed\r\n printlist(list)\r\...
[ "0.7834404", "0.77775735", "0.7642866", "0.76408964", "0.761684", "0.75751555", "0.7536048", "0.7534931", "0.753271", "0.75189275", "0.7515666", "0.7510993", "0.7510993", "0.75000894", "0.74992365", "0.74992365", "0.74992365", "0.74992365", "0.7493865", "0.74800575", "0.74795...
0.0
-1
Method to update the quantity of an item input: item. quantity steps: iterate through the array specify a specific item, then specify the quantity that you want to change it to. output: update the quantity for the item
def print_list $list.each {|list_item| puts "#{list_item[:quantity]} #{list_item[:item]}"} end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_quantity(item, list, quantity)\n add_item(item, list, quantity)\nend", "def update_item_quantity(hash_of_items, item, quantity)\n hash_of_items[item] = quantity\n hash_of_items\nend", "def update_qty(item_list, item, qty)\r\n item_list[item] = qty\r\n item_list\r\nend", "def update_quantity(l...
[ "0.8330185", "0.80823916", "0.8067333", "0.8055857", "0.79930395", "0.7991231", "0.7922875", "0.78572524", "0.7840745", "0.78269565", "0.7822994", "0.7815355", "0.78030574", "0.7783645", "0.77762747", "0.776459", "0.776459", "0.77624035", "0.773304", "0.77022994", "0.7699319"...
0.0
-1
[1,2,3,4,5,6,7,8,9,10] 1st round => counter = 5 + binary_search(r, target) 2nd round => [7, 8, 9, 10] => counter = [1,2,3] target = 1
def merge_sort(array) middle = array.length/2-1 left = [0..middle] right = [middle+1..[-1]] merge_sort(left) + merge_sort(right) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def binary_search(arr, l, r, target)\n return [-1, l, r] if l > r\n mid = l + (r - l) / 2\n return [mid, l, r] if (arr[mid] == target) # Found match!\n (arr[mid] > target) ? binary_search(arr, l, mid - 1, target) : binary_search(arr, mid + 1, r, target)\nend", "def two_sum(numbers, target)\n\n numbers.each_...
[ "0.7189106", "0.704484", "0.70417106", "0.7000531", "0.6976238", "0.69514835", "0.69466114", "0.6943729", "0.6914668", "0.6890714", "0.6873347", "0.68276197", "0.6796265", "0.6781647", "0.67814535", "0.67701", "0.6766559", "0.67529154", "0.67468077", "0.6730454", "0.672938", ...
0.0
-1
returns the sample looping type (:none, :forward, or :pingpong)
def looping_type ExtendedModule::Helpers.sample_looping_type(type) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def sample_looping_type(sample_type_byte)\n case sample_type_byte & 0b11\n when 0 then :none\n when 1 then :forward\n when 2 then :pingpong\n else\n raise \"this should never happen(tm)\"\n end\n end", "def loop_status\n player_iface[...
[ "0.7823311", "0.60263973", "0.59129345", "0.5838798", "0.56941515", "0.56842494", "0.555724", "0.5548535", "0.5480717", "0.5436601", "0.5373245", "0.5355251", "0.5346695", "0.5327974", "0.53050274", "0.529965", "0.5285641", "0.52448773", "0.52398396", "0.52189696", "0.5211999...
0.77532566
1
returns the sample type (8 bit or 16 bit)
def sample_type ExtendedModule::Helpers.sample_type(type) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def sample_type(sample_type_byte)\n ((sample_type_byte & 0b1000) >> 3).zero? ? 8 : 16\n end", "def get_sample_types\r\n # Check if sample belongs to new_record? line\r\n if self.line.new_record? || self.line.samples.count == 0\r\n worker_no = 0\r\n SAMPLE_CONFIG[worker_no]\r\n ...
[ "0.818099", "0.6927985", "0.6841041", "0.6293227", "0.6231982", "0.6161671", "0.6108571", "0.6021802", "0.5987624", "0.59841275", "0.59746885", "0.59542084", "0.59508646", "0.5914328", "0.58874506", "0.5880191", "0.58469415", "0.58356065", "0.5828858", "0.5796033", "0.5785344...
0.69286966
1
returns if this sample is to be looped
def looping? !sample_loop_length.zero? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def is_loop\n\n true\n end", "def is_loop\n\n false\n end", "def loop_wait_before_first_iteration?\n true\n end", "def loop_wait_before_first_iteration?\n true\n end", "def loop?\n get_animloop_array[0][0] && @battle_phase != :covered\n end", "def keep_looping?...
[ "0.79150504", "0.77989495", "0.74996406", "0.7498008", "0.72575146", "0.7124311", "0.7112785", "0.69494814", "0.69441617", "0.6933494", "0.6903892", "0.683247", "0.6804792", "0.6692807", "0.66304135", "0.65197235", "0.64781904", "0.64695287", "0.64695287", "0.6453863", "0.642...
0.8665534
0
HACK: to remove :data from inspect output as sample data is really too spammy
def inspect klass = self.class attrs = klass .attribute_names .reject { |key| key == :data } .map { |key| " #{key}=#{@attributes[key].inspect}" } .join "#<#{klass.name || klass.inspect}#{attrs}>" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inspect\n \"#{to_s.chomp(\">\")} @data=#{data.inspect}>\"\n end", "def inspect\n tmp = @data\n begin\n @data = nil\n @data_summary = (\"#{tmp.size},#{tmp[0,256]}\" if tmp)\n return super\n ensure\n @data = tmp\n @data_summary = nil\n end\...
[ "0.7105124", "0.6555798", "0.635008", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.620551", "0.5986539", "0.5986539", "0.5986539", "0.5986539", "0.5986539", "0.5986539", "0.5986539", ...
0.0
-1
represented by hash containing it's suit, rank and value. It is used +++ as a default deck, it is copied later in an other deck to be manipulated.
def deck_creator deck = [] suits = ["♠", "♥", "♦", "♣"] ranks = ["A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"] suits.each do |value| current_suit = value ranks.each do |value| card = {} card[:suit] = current_suit card[:rank] = value if value === "A" card[:value] = 1 elsif ["J", "Q", "K"].include?(value) card[:value] = 10 else card[:value] = value.to_i end deck.push(card) end end return deck end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def hash\n [rank, suit].hash\n end", "def hash\n @rank.hash ^ @suit.hash\n end", "def hash\n # Memoizing such a simple hash value seems silly, however the\n # profiler showed the Card#hash method as having 22% of the runtime. My\n # memoizing the hash value that was reduced to 12%.\n r...
[ "0.72963434", "0.71565443", "0.6813369", "0.65381444", "0.64920425", "0.64325", "0.6323177", "0.6031956", "0.59799117", "0.59735", "0.5952395", "0.5934461", "0.5933255", "0.59240896", "0.5922261", "0.591961", "0.5916267", "0.59093463", "0.59002066", "0.5890908", "0.587227", ...
0.59665966
10
Grab (delete) a card from the current deck, and put it in one of the hands. it takes one argument: which_hand: choose which to put the card in, accepts either "dealer" or "player"
def get_card_and_put_in_hand(which_hand) the_card = @deck_current.delete_at(rand(@deck_current.length)) if which_hand === "dealer" @hand_dealer.push(the_card) elsif which_hand === "player" @hand_player.push(the_card) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def deal_card(hand)\n #hand is a string whose valid values are 'player_cards' and 'dealer_cards' \n\n if !['player_cards','dealer_cards'].include?(hand)\n raise \"Unknown hand #{hand}\"\n end \n\n #Check for an empty deck and reshuffle if necessary\n if (session['game_cards'].length ...
[ "0.77481", "0.7680469", "0.7536351", "0.7524528", "0.7336696", "0.7224235", "0.7190329", "0.7046859", "0.70179915", "0.7007015", "0.6979283", "0.6972773", "0.69470227", "0.6920806", "0.69164044", "0.6900499", "0.68818873", "0.6860713", "0.68602693", "0.6842921", "0.68108547",...
0.8126879
0
Once a game is lost this function is called to determine the amount of money +++ that should be taken or given to the player.
def bet_attribution(state_of_game) if state_of_game === "lose" @money_current = @money_current - @money_bet elsif state_of_game === "win" @money_current = @money_current + (@money_bet * 0.5) @money_current = @money_current.to_i end @money_bet = 0 end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def amount_remaining\n @desired_amount - @bought_amount\n end", "def player_lost\n\t\tputs \"\\nI am sorry, but you have lost!\"\n\t\tputs \"The secret number was #{self.secret_number}\"\n\t\tself.player_record[\"Losses\"] += 1\n\tend", "def put_money(amount, player)\n if amount > player.money\n am...
[ "0.7134356", "0.705395", "0.6893566", "0.68753844", "0.687292", "0.68616587", "0.68588024", "0.67827606", "0.6753296", "0.6708872", "0.66422164", "0.66082793", "0.65958095", "0.6580925", "0.657832", "0.65631205", "0.65486443", "0.65404534", "0.65316814", "0.65110064", "0.6497...
0.6539575
18
Calculate the cumulated value of the card in a given hand, it is given an array +++ representing the hand, and return an array of two integers, the first represent +++ the soft hand (a hand without ace or ace but valued as 1), the second represent +++ the hard hand (a hand with an ace valued as 11). If there is no aces the soft +++ hand is returned normally and the hard hand value set at 999. it takes one +++ argument: hand_array: represent a player hand, accept an array.
def calculate_hand_total_value(hand_array) total_value = 0 is_there_an_ace = false hand_array.each do |card| if card[:rank] === "A" is_there_an_ace = true end card_value = card[:value] total_value += card_value end if is_there_an_ace return [total_value, total_value + 10] else return [total_value, 999] end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def hand_value(hand)\n sum = 0\n hand.each do |card|\n sum += card\n end\n sum\n end", "def get_hand_value\n cards.reduce(0) { |hand_value, card| hand_value += card.value }\n end", "def hand_value(hand)\n return 0 if hand.empty?\n value = 0\n\n # Add up the ...
[ "0.73332304", "0.7060396", "0.70585316", "0.6870108", "0.6807099", "0.67277795", "0.66802436", "0.66329956", "0.66262686", "0.65868926", "0.65823126", "0.65536934", "0.6508829", "0.63910216", "0.6365068", "0.6349529", "0.63408023", "0.6327891", "0.6324644", "0.6221742", "0.62...
0.7102609
1
Ask the user for input and check if it fit one of the accepted input +++ takes one argument: acceptable_input: an array representing the accepted answers
def get_user_input_and_check(acceptable_input) input = gets.chomp.downcase if acceptable_input.include? input return input else puts "This is not an acceptable input ('#{acceptable_input.join("', '")}'), please try again:" get_user_input_and_check(acceptable_input) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def validate(answers, input)\n until answers.include?(input)\n puts \"#Invalid input: #{input}\"\n input_answer\n end\n end", "def check_input(valid_inputs)\n input = \"\"\n loop do\n input = gets.chomp.upcase\n break if (valid_inputs).include?(input)\n puts \"Sorry. One more time:\...
[ "0.70334756", "0.6751104", "0.66059357", "0.6561781", "0.65116155", "0.65024185", "0.6497687", "0.6416686", "0.6403159", "0.63869214", "0.6302562", "0.6284568", "0.62813675", "0.62699306", "0.62043387", "0.6189875", "0.61859614", "0.6183914", "0.616486", "0.6107275", "0.61010...
0.71899784
0
check if a string represent an integer, return true or false accepts one argument: string: the string to be check for integer
def is_integer(string) string.to_i.to_s == string end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def integer?(string)\n true if Integer(string)\n rescue\n false\n end", "def is_integer? string\n true if Integer(string) rescue false\n end", "def integer?(str)\n true if Integer(str)\n rescue ArgumentError, TypeError\n false\n end", "def is_string_int?(string)\n string.to_i...
[ "0.8923635", "0.89192915", "0.871536", "0.8708371", "0.866758", "0.86365867", "0.86365867", "0.85735655", "0.85603905", "0.8511508", "0.84299916", "0.8405471", "0.83855855", "0.8354983", "0.8340767", "0.8289857", "0.8281372", "0.8222823", "0.8176003", "0.8169893", "0.8067446"...
0.8531283
9
Display the betting screen and call the method for the betting input then +++ if the input is acceptable launch the game. it takes one argument: first_time: Display the welcome string if true
def display_betting_screen(first_time) system "clear" or system "cls" if first_time puts "*** Welcome to Ruby Blackjack ***" end puts "You have #{@money_current} €." puts "Place your bet (min: 5€, max: 100€) or press (q)uit to exit" @money_bet = get_betting_input_and_check start_game end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def first_spin\n puts \"Welcome to the Slots!\".magenta\n puts \"You currently have $#{$wallet}\".green\n puts \"How much money would you like to bet today?\".magenta\n puts \" \"\n @bet_amount = gets.to_i\n puts \" \"\n# if user tries to bet anything less than $1, it will...
[ "0.7454799", "0.6708229", "0.6477216", "0.6459236", "0.6425022", "0.6409845", "0.64087886", "0.63530004", "0.6330695", "0.6300474", "0.62683123", "0.62398016", "0.62346554", "0.6215031", "0.6194557", "0.6191934", "0.61730045", "0.61709076", "0.6167473", "0.6154076", "0.615043...
0.82758874
0
Display (and refresh) the board screen, call the generate_ASCII_card method +++ and the concatenate_cards to display the player hands, it takes one argument: hidden_dealer: accept true or false, if true the second card of the dealer +++ will be hidden.
def display_board_screen(hidden_dealer) display_hand_dealer = [] display_hand_player = [] if hidden_dealer dealer_card = [generate_ASCII_card(@hand_dealer[0]),generate_ASCII_card(@hidden_card)] display_hand_dealer = concatenate_cards(dealer_card) else dealer_card = [] @hand_dealer.each do |card| dealer_card.push(generate_ASCII_card(card)) end display_hand_dealer = concatenate_cards(dealer_card) end @hand_player.each do |card| player_card = [] @hand_player.each do |card| player_card.push(generate_ASCII_card(card)) end display_hand_player = concatenate_cards(player_card) end system "clear" or system "cls" puts "Dealer:" puts display_hand_dealer puts puts "Player:" puts display_hand_player puts puts "Do you want to (h)it or (s)tay?" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def display_hands(player_hand, dealer_hand, hide_dealer=false)\n system('clear') || system('cls')\n puts \">>>>>> Twenty-One <<<<<<\"\n prompt(\"Dealer's Hand:\")\n print_cards(dealer_hand, hide_dealer)\n puts\n prompt(\"Player's Hand:\")\n print_cards(player_hand)\nend", "def display_hands\n @output...
[ "0.7267893", "0.7048758", "0.69489825", "0.69288224", "0.69288003", "0.6913045", "0.6892421", "0.67482597", "0.666768", "0.66470236", "0.6635782", "0.66275775", "0.65575665", "0.6553606", "0.65479076", "0.65011793", "0.6487321", "0.6477688", "0.6410497", "0.6400801", "0.63951...
0.81121224
0
Check if a given hand has a total over 21, both hard and soft hand needs +++ to be higher than 21. Takes one argument: hand_total: accept an array representing the total value of a given hand.
def check_if_over_21(hand_total) if hand_total[0] > 21 && hand_total[1] > 21 return true else return false end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_if_over_17(hand_total)\n if hand_total[1] === 999\n if hand_total[0] >= 17\n return true\n end\n\n else\n if hand_total[0] >= 17 || hand_total[1] >= 17\n return true\n end\n\n end\n\n return false\n\nend", "def bust?(hand)\n return hand_total( hand ) > WIN_VALUE \n\n e...
[ "0.7555504", "0.6689158", "0.6543822", "0.6280151", "0.6223152", "0.61925024", "0.6177859", "0.6166044", "0.6115651", "0.60773134", "0.60630304", "0.6017149", "0.6002817", "0.5996013", "0.5956973", "0.58738285", "0.5794578", "0.576753", "0.5765908", "0.5753785", "0.5749009", ...
0.7920512
0
Check if a given hand has a total over 17, either hard or soft hand can +++ be higher than 17, only used for the dealer. Takes one argument: hand_total: accept an array representing the total value of a given hand.
def check_if_over_17(hand_total) if hand_total[1] === 999 if hand_total[0] >= 17 return true end else if hand_total[0] >= 17 || hand_total[1] >= 17 return true end end return false end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_if_over_21(hand_total)\n if hand_total[0] > 21 && hand_total[1] > 21\n return true\n\n else\n return false\n\n end\nend", "def bust?(hand)\n return hand_total( hand ) > WIN_VALUE \n\n end", "def calculate_hand_value(hand)\n value = 0\n if hand.values.reduce(:+) <= 21\n value = h...
[ "0.7502731", "0.6977029", "0.6482885", "0.6364178", "0.62731576", "0.62155086", "0.62040573", "0.61447674", "0.61328185", "0.61140895", "0.61138225", "0.61091626", "0.60509753", "0.60326463", "0.60163355", "0.59590805", "0.59103787", "0.5881814", "0.5846648", "0.58366174", "0...
0.7662556
0
Compare the dealer and the player hands to determine who wins, it +++ returns either the winner ("dealer" or "player") or draw if it's +++ the case, takes two arguments: hand_total_dealer: an array representing the the total value of +++ the dealer hand. hand_total_player: an array representing the the total value of +++ the player hand.
def check_who_wins(hand_total_dealer, hand_total_player) hand_to_use_dealer = 0 hand_to_use_player = 0 if hand_total_dealer[1] <= 21 hand_to_use_dealer = hand_total_dealer[1] else hand_to_use_dealer = hand_total_dealer[0] end if hand_total_player[1] <= 21 hand_to_use_player = hand_total_player[1] else hand_to_use_player = hand_total_player[0] end if hand_to_use_player < hand_to_use_dealer return "dealer" elsif hand_to_use_dealer < hand_to_use_player return "player" elsif hand_to_use_player = hand_to_use_dealer return "draw" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def winner\n if (win?(player) == true) && (win?(dealer) == false)\n show_hands_final\n puts \"#{player.name} wins!!!\\n\" ;player.score += 1\n elsif (win?(dealer) == true) && (win?(player) == false)\n show_hands_final\n puts \"#{dealer.name} wins!!!\\n\" ;dealer.score += 1\n elsif (win...
[ "0.772229", "0.7402753", "0.7275999", "0.7234823", "0.721427", "0.7202804", "0.7175807", "0.7173135", "0.7154482", "0.71470463", "0.71427435", "0.7127447", "0.7071624", "0.70313543", "0.7009237", "0.69736373", "0.69388634", "0.68992245", "0.68079597", "0.6791086", "0.67867047...
0.80908495
0
Asks the player for input, to choose if the player want to hit +++ or stay, it returns "over" if the player is over 21 and stay if +++ the player stays. recursively calls itself if the previous +++ conditions are not met.
def turn_player input = get_user_input_and_check(["h","s"]) if input === "h" get_card_and_put_in_hand("player") display_board_screen("hidden") hand_total = calculate_hand_total_value(@hand_player) if check_if_over_21(hand_total) return "over" else turn_player end elsif input === "s" return "stay" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def hit_or_stay_cont\n puts \"Would you like to hit or stay\"\n input = gets.chomp.to_s\n input.upcase!\n @dealer.update_deck if @deck.cards_left < 1 # rebuilds deck if empty\n if input == \"HIT\" || input == \"H\"\n @player.hand.hit\n show_player_hand\n return if @player.hand.bust # ...
[ "0.66261643", "0.63764685", "0.6215423", "0.6140505", "0.6108753", "0.6041891", "0.6037034", "0.60302997", "0.59977007", "0.59604657", "0.5959852", "0.5958253", "0.5917129", "0.59132934", "0.59018487", "0.5894895", "0.58785677", "0.5858814", "0.5857725", "0.5847214", "0.58379...
0.6056319
5
get card for the dealer until their value is higher than 21 +++ (returns "over21") or 17 (returns "over17"). reccursively calls +++ itself if the previous conditions are not met.
def turn_dealer display_board_screen(false) hand_total = calculate_hand_total_value(@hand_dealer) if check_if_over_21(hand_total) return "over21" elsif check_if_over_17(hand_total) return "over17" else get_card_and_put_in_hand("dealer") sleep 1 turn_dealer end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def dealer_sequence d_cards, p_cards\r\n deal_dealer d_cards, p_cards\r\n value = card_total d_cards\r\n while value <= 21\r\n if value < 17\r\n\t deal_dealer d_cards, p_cards\r\n value = card_total d_cards\r\n \t else\r\n \t\t return value\r\n \t end\r\n end\r\n\treturn value\t\r\ne...
[ "0.70306516", "0.69132245", "0.6642561", "0.6584686", "0.6581807", "0.65543157", "0.64530617", "0.6376934", "0.6368452", "0.63640773", "0.62796205", "0.62616646", "0.62452143", "0.6220503", "0.6219451", "0.6202824", "0.6173652", "0.61607015", "0.6152943", "0.612068", "0.60320...
0.5959363
22
Generate one ASCII card, returns an array representing the seven +++ strings needed to build the cards. Accepts one argument: card: a hash representing a single card
def generate_ASCII_card(card) if card[:rank] === "10" rank = card[:rank] else rank = " " + card[:rank] end suit = card[:suit] array_card = [] array_card.push(".-------.") array_card.push("| #{rank} #{suit} |") array_card.push("| |") array_card.push("| |") array_card.push("| |") array_card.push("| #{rank} #{suit} |") array_card.push("'-------'") return array_card end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def gen_cards\n # done in a verbose manner so that code is easy to understand\n %w[H D S C].each do |suit|\n @cards.push(Card.new('Ace', suit, 1))\n @cards.push(Card.new('Two', suit, 2))\n @cards.push(Card.new('Three', suit, 3))\n @cards.push(Card.new('Four', suit, 4))\n @cards.push(...
[ "0.70849264", "0.6963799", "0.66808844", "0.6618843", "0.6483757", "0.6405916", "0.6321119", "0.62832785", "0.6283159", "0.62633914", "0.61936915", "0.61551416", "0.61413616", "0.6129733", "0.6129733", "0.60908484", "0.60771435", "0.6055965", "0.6016967", "0.596967", "0.59529...
0.79195845
0
Concatenate the previously created ASCII cards. returns an array +++ representing the seven strings needed to build the hands. Accepts+++ one argument: cards: an array of arrays representing each ASCII card in hand.
def concatenate_cards(cards) array_hand = ["","","","","","",""] cards.each do |value| value.each_with_index do |string, index| array_hand[index] = array_hand[index] + " " + string end end return array_hand end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def cards_in_hand_to_string(cards)\n suits = [\"club\", \"diamond\", \"heart\", \"spade\"]\n numbers = [\"A\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"10\", \"J\", \"Q\", \"K\"]\n\n card_strings = []\n cards.each do |card|\n card_strings.push(suits[card / 13] + numbers[card % 13])\n end\n...
[ "0.71125185", "0.68591887", "0.6783962", "0.6570963", "0.6558313", "0.64254916", "0.6419686", "0.6400856", "0.63796675", "0.6365292", "0.63648283", "0.63531643", "0.6239246", "0.6226797", "0.6154203", "0.6152053", "0.6138451", "0.6113538", "0.61042136", "0.6055579", "0.602662...
0.80107224
0
Start a game round and launch the apropriate methods to display +++ the diverse screens.
def start_game @deck_current = @deck_default @hand_dealer = [] @hand_player = [] get_card_and_put_in_hand("dealer") get_card_and_put_in_hand("dealer") get_card_and_put_in_hand("player") get_card_and_put_in_hand("player") display_board_screen(true) result_player = turn_player if result_player === "over" puts "player is over 21, press enter to continue" gets bet_attribution("lose") display_betting_screen(false) elsif result_player === "stay" result_dealer = turn_dealer end if result_dealer === "over21" puts "Dealer over 21, press enter to continue" gets bet_attribution("win") display_betting_screen(false) elsif result_dealer === "over17" final_result = check_who_wins(calculate_hand_total_value(@hand_dealer), calculate_hand_total_value(@hand_player)) if final_result === "draw" puts "It's a draw, press enter to continue" bet_attribution("push") elsif final_result === "player" puts "Player wins, press enter to continue" bet_attribution("win") elsif final_result === "dealer" puts "Dealer wins, press enter to continue" bet_attribution("lose") end gets display_betting_screen(false) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def start_game\n @new_prompt.title_screen\n @new_commands.create_new_board(5)\n select_mode\n end", "def game_start\n game_setup\n @console_delegate.show\n end", "def start_game\n game_logo\n game_start_screen\n game_rules\n last_rules\n choice = maker_breaker\n ...
[ "0.74574393", "0.7404887", "0.7362211", "0.71779186", "0.71309316", "0.70909154", "0.6946057", "0.6932117", "0.6874877", "0.6832797", "0.68295884", "0.6801718", "0.67965597", "0.6779961", "0.6773878", "0.6771051", "0.6764847", "0.67632306", "0.6755659", "0.67508954", "0.67288...
0.0
-1
Factory(:payture_charge), build(:order) create(:order, :pnr_number => '234DDK') people = build_list(:person, 5)
def factories! require 'factory_girl' require './spec/factories' extend FactoryGirl::Syntax::Methods end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create_orders_over_time(amount)\n amount.times do\n profile = UserProfile.all.sample\n created = Faker::Time.between(1.years.ago, Time.now)\n updated = Faker::Time.between(created, Time.now)\n Order.create(\n user_id: profile.id,\n shipping_address_id: profile.shipping_address_id,\n ...
[ "0.5927258", "0.5917945", "0.5855215", "0.5825372", "0.57786", "0.57766527", "0.57391596", "0.56728065", "0.5666374", "0.56610984", "0.56579834", "0.56411433", "0.563297", "0.5628647", "0.5628038", "0.5617984", "0.5571768", "0.55717117", "0.55683845", "0.5564358", "0.5552982"...
0.0
-1
GET /key_indicate_map/indicator_files GET /key_indicate_map/indicator_files.json
def index @key_indicate_map_indicator_files = KeyIndicateMap::IndicatorFile.all end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set_key_indicate_map_indicator_file\n @key_indicate_map_indicator_file = KeyIndicateMap::IndicatorFile.find(params[:id])\n end", "def index\n @key_indicate_dictionary = KeyIndicate::Dictionary.first || KeyIndicate::Dictionary.create\n @keys = @key_indicate_dictionary.key_indicate_dictionary_fil...
[ "0.6914745", "0.61449116", "0.6086906", "0.6046348", "0.5938401", "0.5832913", "0.5746459", "0.57271", "0.57237226", "0.571251", "0.56377894", "0.5605269", "0.5459627", "0.5448437", "0.54066503", "0.5355175", "0.52721626", "0.52664214", "0.5260905", "0.5250922", "0.523955", ...
0.8079902
0
GET /key_indicate_map/indicator_files/1 GET /key_indicate_map/indicator_files/1.json
def show end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @key_indicate_map_indicator_files = KeyIndicateMap::IndicatorFile.all\n end", "def set_key_indicate_map_indicator_file\n @key_indicate_map_indicator_file = KeyIndicateMap::IndicatorFile.find(params[:id])\n end", "def set_key_indicate_map_indicator\n @key_indicate_map_indicator = Ke...
[ "0.774561", "0.70164704", "0.60870147", "0.59591174", "0.5858484", "0.58546704", "0.5783305", "0.5767306", "0.56435364", "0.56258774", "0.56010115", "0.55970347", "0.5554699", "0.5545462", "0.54905003", "0.5460784", "0.5391124", "0.5319879", "0.5316548", "0.52659726", "0.5248...
0.0
-1
POST /key_indicate_map/indicator_files POST /key_indicate_map/indicator_files.json
def create @indicator_files = [] params['indicate_file'].each do |f| doc = KeyIndicateMap::IndicatorFile.new doc.indicate_file = f params[:key_indicate_map_indicator_file][:title].blank? ? doc.title = f.original_filename : doc.title = params[:key_indicate_map_indicator_file][:title] doc.description = params[:key_indicate_map_indicator_file][:description] doc.year = params[:year] doc.author = current_user.email if !doc.save respond_to do |format| format.js {render :js=> 'alert("' + doc.errors.messages[:year][0] + '");' } format.json { head :no_content, status: :unprocessable_entity } end return end @indicator_files << doc table = read_table_from_file 'public/uploads/key_indicate_map/indicator_file/indicate_file/' + doc._id.to_s + '/' + doc.indicate_file.filename @errors = doc.import table, doc.year.to_s end unless params['indicate_file'].nil? respond_to do |format| format.js {} format.json { head :no_content, status: :created } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def index\n @key_indicate_map_indicator_files = KeyIndicateMap::IndicatorFile.all\n end", "def set_key_indicate_map_indicator_file\n @key_indicate_map_indicator_file = KeyIndicateMap::IndicatorFile.find(params[:id])\n end", "def create\n @key_indicate_map_indicator = KeyIndicateMap::Indicator.ne...
[ "0.70102364", "0.69004107", "0.6490646", "0.6423121", "0.62466806", "0.5724219", "0.56532186", "0.55923367", "0.55429876", "0.5466905", "0.54266614", "0.54100823", "0.53066623", "0.5304282", "0.52869374", "0.5243609", "0.5232075", "0.50919414", "0.5084649", "0.5079669", "0.50...
0.6845506
2
PATCH/PUT /key_indicate_map/indicator_files/1 PATCH/PUT /key_indicate_map/indicator_files/1.json
def update if key_indicate_map_indicator_file_params[:year] year = @key_indicate_map_indicator_file.year.to_s KeyIndicateMap::IndicatorKey.each{|key| if key['history'] && key['history'][year] attrs = key['history'].reject{|key, value| key == year } attrs[key_indicate_map_indicator_file_params[:year]] = key['history'][year] key.update_attributes({:history => attrs}) end } end respond_to do |format| if @key_indicate_map_indicator_file.update(key_indicate_map_indicator_file_params) format.js {} format.json { head :no_content, status: :updated } else format.html { render :edit } format.json { render json: @key_indicate_map_indicator_file.errors, status: :unprocessable_entity } end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n respond_to do |format|\n if @key_indicate_map_indicator.update(key_indicate_map_indicator_params)\n format.html { redirect_to @key_indicate_map_indicator, notice: 'Indicator was successfully updated.' }\n format.json { render :show, status: :ok, location: @key_indicate_map_indica...
[ "0.6834086", "0.6758704", "0.6632669", "0.6277231", "0.5995237", "0.59481645", "0.59226865", "0.575027", "0.5668214", "0.563646", "0.5607483", "0.5581408", "0.5570466", "0.5543815", "0.55378723", "0.550864", "0.54820126", "0.54721797", "0.545447", "0.5443919", "0.5437441", ...
0.69110155
0
DELETE /key_indicate_map/indicator_files/1 DELETE /key_indicate_map/indicator_files/1.json
def destroy year = @key_indicate_map_indicator_file['year'].to_s KeyIndicateMap::IndicatorKey.each{|key| if !key['history'].nil? && !key['history'][year].nil? attrs = {:history => key['history'].reject{|key, value| key == year }} key.update_attributes(attrs) end } @key_indicate_map_indicator_file.destroy respond_to do |format| format.js {} format.json { head :no_content, status: :destroy } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy\n @key_indicate_map_indicator.destroy\n respond_to do |format|\n format.html { redirect_to key_indicate_map_indicators_url, notice: 'Indicator was successfully destroyed.' }\n format.json { head :no_content }\n end\n end", "def destroy\n @key_indicate_map_indicator_key.destroy\...
[ "0.6914691", "0.6685721", "0.66480047", "0.64276147", "0.6400769", "0.6387019", "0.6386406", "0.63785565", "0.63294405", "0.62385285", "0.6215934", "0.61841404", "0.60876375", "0.6071649", "0.6021739", "0.6012763", "0.5966819", "0.5965109", "0.5964459", "0.59622705", "0.59534...
0.66440237
3
Use callbacks to share common setup or constraints between actions.
def set_key_indicate_map_indicator_file @key_indicate_map_indicator_file = KeyIndicateMap::IndicatorFile.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 key_indicate_map_indicator_file_params params.require(:key_indicate_map_indicator_file).permit(:title, :description, :year, :town, :old_town, :indicator_key, :old_key) 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
This should return the minimal set of attributes required to create a valid Task. As you add validations to Task, be sure to update the return value of this method accordingly.
def valid_attributes { :tag_id => FactoryGirl.create(:tag), :start_time => Time.now, :user_id => @user.id } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def required_attributes\n self.class::REQUIRED_ATTRIBUTES\n end", "def required_attributes\n self.class.required_attributes\n end", "def valid_attributes\n {\n completed: false,\n cancelled: false,\n transaction_id: nil,\n completed_date: Date.new(2012, 1, 30)\n }\n e...
[ "0.6684837", "0.6405162", "0.6246577", "0.61095375", "0.61023605", "0.6090421", "0.60467744", "0.6036887", "0.603539", "0.60320985", "0.60178727", "0.5993932", "0.5979589", "0.59729147", "0.59482586", "0.5944408", "0.5944408", "0.5935087", "0.5923774", "0.5917335", "0.5916025...
0.0
-1
GET /badges GET /badges.json
def index session[:admin] = true @badges = Badge.order('approved_at desc,id') @fri_count = Badge.select { |b| b.friday? }.size @sat_count = Badge.select { |b| b.saturday? }.size respond_to do |format| format.html # index.html.erb format.json { render :json => @badges } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def badges\n get(\"user/#{user_id}/badges.json\")\n end", "def badges(id)\n get(\"users/#{id}/badges\")\n end", "def badges(user_id: '-')\n return get(\"#{API_URI}/#{PROFILE_API_VERSION}/user/#{user_id}/badges.json\")\n end", "def badges(options={})\n self.class.parse_badges(...
[ "0.87536204", "0.8055727", "0.77719414", "0.7684046", "0.7552645", "0.74981487", "0.72334045", "0.713744", "0.6892226", "0.6846787", "0.68157053", "0.67125493", "0.6708214", "0.66353303", "0.6620842", "0.65226746", "0.65138704", "0.65126044", "0.64222705", "0.64106536", "0.63...
0.64497757
18