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 |
|---|---|---|---|---|---|---|
TEMPLATE_TODO: add here your features calling | def show_subfeature
::Actions::Features::YourFeature1::YourSubfeature1.new(bot: bot, user: user, some_attr: 'attr').show
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_required_features(features)\n end",
"def use(*features); end",
"def list_features *args\r\n puts \"not implemented yet\"\r\n end",
"def loaded_features; end",
"def feature(name, &block); begin; yield; features << name; rescue Exception; end; end",
"def append_features(mod) end",
"def fea... | [
"0.6993579",
"0.6992757",
"0.69449335",
"0.67648554",
"0.66447365",
"0.652486",
"0.64423275",
"0.642723",
"0.6424435",
"0.63547236",
"0.6326754",
"0.6326754",
"0.63130593",
"0.6291767",
"0.62782586",
"0.62742347",
"0.6243633",
"0.62431395",
"0.6201891",
"0.6198012",
"0.618655... | 0.65637267 | 5 |
SimpleCov.start 'rails' do add_filter "/spec" end | def init_db!
UserRole.where("user_id <> #{User.system_user.id}").delete_all
User.unscoped.where("email <> 'app@recognizeapp.com'").delete_all
Company.where("domain <> 'recognizeapp.com'").delete_all
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def start_simplecov\n require 'simplecov'\n SimpleCov.start :rails\n\n RSpec.configure do |config|\n require 'miletus/namespace_helper'\n # Mixin namespace helpers\n config.include Miletus::NamespaceHelper\n end\n\nend",
"def start_coverage_tracking\n if ENV['CI']\n require 'codeclimate-test-rep... | [
"0.7557921",
"0.66823626",
"0.66166043",
"0.63571745",
"0.62090355",
"0.6124846",
"0.60188067",
"0.5969851",
"0.5969851",
"0.5812259",
"0.5812259",
"0.5812259",
"0.57435566",
"0.57435566",
"0.5674276",
"0.5558454",
"0.55144924",
"0.55144924",
"0.5500853",
"0.5495059",
"0.5483... | 0.0 | -1 |
Initializes a new loose object with the given object attributes. The type is the type of the git object, hash is the SHA1 hash of its canonical form, and the dump is its raw dumped contents. | def initialize(hash, type, dump)
self.hash = hash
self.type = type.to_sym
self.dump = dump
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def initialize(reflection, dump)\n @reflection = reflection\n @dump = dump\n @ignore = false\n\n load\n end",
"def initialize(hash)\n # initialize class variable @@extension only once\n @@extension ||= Extension.new\n @@schema ||= @@extension.schema\n\n @hash = hash\n ... | [
"0.6036449",
"0.60343224",
"0.59534585",
"0.5854571",
"0.58459044",
"0.5804494",
"0.57820475",
"0.57795966",
"0.57519525",
"0.5735894",
"0.5706897",
"0.57023257",
"0.5674548",
"0.5672787",
"0.5663475",
"0.56587946",
"0.56345236",
"0.56340677",
"0.5622699",
"0.558676",
"0.5568... | 0.6869003 | 0 |
Saves the contents of the object in a file on disk. Returns self. Raises a CorruptLooseObject exception if the contents don't pass all validations. | def save
unless saved?
# TODO: decide whether or not I should perform validations like this at
# save-time, or only read-time. They can be quite slow.
self.class.verify_type(hash, type)
self.class.verify_length(hash, length, dump)
self.class.verify_hash(hash, type, dump)
contents = OUTPUT_FORMAT % [ type, length, dump ]
self.class.write(hash, contents)
end
self
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def save\n return if !self.valid?\n\n File.open(@file, \"w\") do |f|\n NWN::Gff.write(f, :gff, @obj)\n end\n end",
"def save!\n if save\n self\n else\n raise FileNotSaved\n end\n end",
"def persist!\n ::File.write(self.path, Marshal.dump(self))\n rescue => e... | [
"0.657357",
"0.64548576",
"0.6336848",
"0.630383",
"0.630383",
"0.6233867",
"0.6124418",
"0.60392934",
"0.60140663",
"0.6013492",
"0.57966304",
"0.5791877",
"0.570942",
"0.56664205",
"0.56627685",
"0.5654053",
"0.5654053",
"0.56325155",
"0.5616066",
"0.5612402",
"0.5601673",
... | 0.551841 | 29 |
Removes the loose object's disk entry. Returns self. | def destroy
self.class.destroy(self.hash)
self
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_from_disk; end",
"def delete\n self.store -= self\n end",
"def delete_from_disk\n thread_local_store.destroy\n end",
"def desist\n self.class.delete self\n end",
"def delete\n data.delete( self ); self\n end",
"def destroy\n\t\tFile.delete @filepath\... | [
"0.62435555",
"0.5979203",
"0.59108675",
"0.56676984",
"0.5600519",
"0.55667824",
"0.5546878",
"0.5541785",
"0.55020106",
"0.54964477",
"0.54885924",
"0.54850096",
"0.54787767",
"0.54749465",
"0.54445153",
"0.54406416",
"0.54239947",
"0.5389169",
"0.5384569",
"0.53795516",
"0... | 0.5050324 | 94 |
Returns whether or not there is already a file on disk whose contents match those of the current object. NOTE: Does NOT check to see if the file exists in other storage engines. | def saved?
self.class.exists?(self.hash)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def file_matching_path\n !!container.stored_files.where(file_name: file_name, path: path).first\n end",
"def already_stored?\n !file_uniqueness\n end",
"def has_file\n if id == nil \n false\n else\n FileTest.exists?( local_file_path )\n end\n end",
"def... | [
"0.71777517",
"0.7077234",
"0.6952888",
"0.6926593",
"0.6842355",
"0.6816244",
"0.67670816",
"0.6743153",
"0.67277026",
"0.67154795",
"0.66943",
"0.6692629",
"0.6669686",
"0.66522443",
"0.66437006",
"0.6643556",
"0.6625059",
"0.6599663",
"0.65917885",
"0.6585842",
"0.65828574... | 0.0 | -1 |
Returns the filename of the loose object, based on its current contents. | def filename
self.class.path(hash)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def file_name\n object_file_name\n end",
"def object_name\n @name ||= File.split(@source_path).last.gsub('.txt', '')\n end",
"def infer_name_from_contents(obj, opts={})\n begin\n File.split(obj).last.split('.')[0..-2].join('.').titleize\n rescue\n nil\n ... | [
"0.7476205",
"0.7428346",
"0.73078185",
"0.7105216",
"0.7105216",
"0.7105216",
"0.7080349",
"0.7067844",
"0.7067844",
"0.70336896",
"0.6998489",
"0.68675125",
"0.6820072",
"0.6781976",
"0.66861933",
"0.6616056",
"0.6595698",
"0.6578438",
"0.656219",
"0.65325797",
"0.6522116",... | 0.6655305 | 15 |
The length of the object's contents | def length
dump.length
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def length()\n obj_len = internal_object_length - 1\n return obj_len\n end",
"def length\n\n count_objects()\n end",
"def length\n size\n end",
"def length\n size\n end",
"def size\n self.length\n end",
"def size\r\n self.data.length\r\n end",
... | [
"0.87534845",
"0.85381305",
"0.84476244",
"0.8426257",
"0.83454347",
"0.8338162",
"0.8330837",
"0.8330837",
"0.8330837",
"0.8210907",
"0.82008564",
"0.8188682",
"0.81495756",
"0.81495756",
"0.8145129",
"0.81219476",
"0.81136066",
"0.81136066",
"0.81136066",
"0.81136066",
"0.8... | 0.80257535 | 40 |
GET /abuses/1 GET /abuses/1.json | def show; end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @abuse_category = AbuseCategory.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @abuse_category }\n end\n end",
"def index\n @usages = get_usages\n respond_to do |format|\n format.html # index.html.erb\n format... | [
"0.6322162",
"0.61717236",
"0.60354745",
"0.60228765",
"0.6001939",
"0.5941832",
"0.5924929",
"0.5915531",
"0.59125054",
"0.5895173",
"0.58930033",
"0.587722",
"0.58403426",
"0.5832928",
"0.5806754",
"0.57925195",
"0.5766351",
"0.5737536",
"0.5729858",
"0.5720014",
"0.5717993... | 0.0 | -1 |
POST /abuses POST /abuses.json | def create
@context = context
@abuse = @context.abuses.new(abuse_params)
# we set the current customer
@abuse.customer = current_customer
respond_to do |format|
if @abuse.save
@abuse.receive! # tell the state engine, need the bang! to save in database
# display the new abuse
format.html { redirect_to context_url(context), notice: t('views.flash_create_message') }
format.json { render :show, status: :created, location: @abuse }
# added
format.js do
@current_abuse = @abuse
render :create, flash: {notice: 'Yeepee!'}
end
else
format.html { render :new }
format.json { render json: @abuse.errors, status: :unprocessable_entity }
# needed for errors, cf form_error.coffee
format.js { render json: @abuse.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @abuse = Abuse.new(params[:abuse])\n\n respond_to do |format|\n if @abuse.save\n flash[:notice] = 'Abuse was successfully created.'\n format.html { redirect_to(@abuse) }\n format.xml { render :xml => @abuse, :status => :created, :location => @abuse }\n else\n ... | [
"0.5758231",
"0.5718653",
"0.5228344",
"0.5218636",
"0.52107847",
"0.51617813",
"0.5161337",
"0.5105688",
"0.50966555",
"0.50934285",
"0.50884336",
"0.5051911",
"0.5013992",
"0.49852934",
"0.4970189",
"0.49671233",
"0.49474695",
"0.4944501",
"0.49345642",
"0.49150816",
"0.490... | 0.55611783 | 2 |
PATCH/PUT /abuses/1 PATCH/PUT /abuses/1.json | def update
@context = context
respond_to do |format|
if @abuse.update(abuse_params)
format.html { redirect_to context_url(context), notice: t('views.flash_update_message') }
format.json { render :show, status: :ok, location: @abuse }
else
format.html { render :edit }
format.json { render json: @abuse.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update!(params)\n res = @client.put(path, nil, params, \"Content-Type\" => \"application/json\")\n @attributes = res.json if res.status == 201\n res\n end",
"def update_rest\n @item_usage = ItemUsage.find(params[:id])\n\n respond_to do |format|\n if @item_usage.update_attributes(params[:... | [
"0.635657",
"0.5964342",
"0.59205943",
"0.58420223",
"0.5812599",
"0.5792071",
"0.5788739",
"0.57870173",
"0.5786872",
"0.5786516",
"0.5783263",
"0.57644945",
"0.57624847",
"0.5754723",
"0.57531404",
"0.5742835",
"0.573147",
"0.5694034",
"0.5693799",
"0.5686841",
"0.5683507",... | 0.5729873 | 17 |
DELETE /abuses/1 DELETE /abuses/1.json | def destroy
@abuse.destroy
respond_to do |format|
format.html { redirect_to abuses_url, notice: t('views.flash_delete_message') }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_aos_version(args = {}) \n delete(\"/aosversions.json/#{args[:aosVersionId]}\", args)\nend",
"def destroy\n @abuse = Abuse.find(params[:id])\n @abuse.destroy\n\n respond_to do |format|\n format.html { redirect_to(abuses_url) }\n format.xml { head :ok }\n end\n end",
"def delet... | [
"0.68524104",
"0.68436027",
"0.6732829",
"0.67131406",
"0.66854054",
"0.66555184",
"0.66301304",
"0.6567265",
"0.65449977",
"0.6541967",
"0.6525529",
"0.65178484",
"0.65070254",
"0.6488454",
"0.648435",
"0.6463912",
"0.6456922",
"0.6455644",
"0.6447765",
"0.6442045",
"0.64269... | 0.6789473 | 2 |
Use callbacks to share common setup or constraints between actions. | def set_abuse
@abuse = Abuse.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.61642385",
"0.60448",
"0.5945487",
"0.5915654",
"0.58890367",
"0.58330417",
"0.5776098",
"0.5703048",
"0.5703048",
"0.5654613",
"0.5620029",
"0.5423114",
"0.540998",
"0.540998",
"0.540998",
"0.5393666",
"0.53783023",
"0.53568405",
"0.53391176",
"0.5339061",
"0.53310865",
... | 0.0 | -1 |
Never trust parameters from the scary internet, only allow the white list through. | def abuse_params
params.require(:abuse).permit(:description, :customer_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 |
as a polymorphic object, we need the context | def context
if params[:product_id]
Product.find(params[:product_id])
elsif params[:review_id]
Review.find(params[:review_id])
elsif params[:comment_id]
Comment.find(params[:comment_id])
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def resolve_polymorphic\n end",
"def child_class\n Objekt\n end",
"def object\n raise NotImplementedError\n end",
"def get_type()\n res = super(context,self)\n return res\n end",
"def is_object()\n res = super(context,self)\n return res\n end",
"def type; super; end... | [
"0.65425706",
"0.6458872",
"0.6395807",
"0.6324864",
"0.63201827",
"0.6074924",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
"0.60532355",
... | 0.0 | -1 |
tab completion here is bad because we don't know if the str has a 'cd' before it. That makes us go through the executables as well when we're doing cd str[TAB] | def get_executables(str)
commands = []
ENV["PATH"].split(':').each do |dir|
Dir.glob("#{dir}/*").grep( /#{File::SEPARATOR}?#{Regexp.escape(str)}/ ).each do |file|
begin
stat = File.stat(file)
commands << File::basename(file) if stat.executable? and not stat.directory?
rescue
end
end
end
return commands
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def cmd(str)\n return `cd #{APP_DIR}; #{str}`\nend",
"def cd?(str)\n begin\n Dir.chdir(str)\n rescue => exception\n puts Pastel.new.yellow(\"warning> \") + \"command error: cd \" + str + \" (suppressed)\"\n return false\n end\n return true\nend",
"def exec_on!(command_str,curr... | [
"0.617779",
"0.61223155",
"0.60791004",
"0.60335064",
"0.5959423",
"0.5847998",
"0.58139485",
"0.5635331",
"0.5613804",
"0.54797924",
"0.54789597",
"0.54683423",
"0.546523",
"0.5459164",
"0.5447566",
"0.5428145",
"0.5427144",
"0.5404687",
"0.5362769",
"0.52798414",
"0.527661"... | 0.0 | -1 |
GET /apps/:app_id/activities GET /apps/:app_id/activities.xml GET /apps/:app_id/activities.atom | def index
@app = App.find(params[:app_id])
@activities = @app.activities.all(:order => 'updated_at DESC')
@activity = @app.activities.build
@base_versions = [Activity::NO_BASE_VERSION]
respond_to do |format|
format.html do # index.html.erb
if request.xhr?
render :partial => 'index', :locals => {:app => @app, :activities => @activities}
end
end
format.xml { render :xml => @activities }
format.atom # index.atom.builder
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def activities\n get_call(\"1/activities.json\")\n end",
"def activities(params = {})\n scope 'default'\n get('activities/', params)\n end",
"def activities(options={})\n response = connection.get do |req|\n req.url \"activities\", options\n end\n return_error_or_body... | [
"0.7392114",
"0.7276339",
"0.7108574",
"0.70172095",
"0.70172095",
"0.6907973",
"0.6880106",
"0.6671083",
"0.66608024",
"0.66328317",
"0.6621243",
"0.661175",
"0.66080743",
"0.6604532",
"0.6423977",
"0.6417152",
"0.6400845",
"0.6367281",
"0.62728566",
"0.62728566",
"0.6272856... | 0.71725786 | 2 |
GET /apps/:app_id/activities/1 GET /apps/:app_id/activities/1.xml GET /apps/:app_id/activities/1.atom | def show
@app = App.find(params[:app_id])
@activity = @app.activities.find(params[:id])
@change = @activity.changes.build
latest_change = Change.first(:conditions => {:activity_id => params[:id], :state => [Change::STATE_EXECUTED, Change::STATE_SAVED]}, :order => 'created_at DESC')
if latest_change
@change.developer = latest_change.developer
end
latest_base_version?
respond_to do |format|
format.html do # show.html.erb
if request.xhr?
render :partial => "shared/activity", :locals => {:activity => @activity}
end
end
format.xml { render :xml => @activity }
format.atom # show.atom.builder
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @app = App.find(params[:app_id])\n @activities = @app.activities.all(:order => 'updated_at DESC')\n @activity = @app.activities.build\n @base_versions = [Activity::NO_BASE_VERSION]\n\n respond_to do |format|\n format.html do # index.html.erb\n if request.xhr?\n rende... | [
"0.7122046",
"0.7093402",
"0.7069227",
"0.7069227",
"0.6902973",
"0.6735839",
"0.6721044",
"0.6689738",
"0.6620157",
"0.6468125",
"0.6446982",
"0.63771474",
"0.63581246",
"0.63207895",
"0.6320785",
"0.6316321",
"0.6304927",
"0.623346",
"0.62123066",
"0.61994684",
"0.6161481",... | 0.6117187 | 29 |
GET /apps/:app_id/activities/new GET /apps/:app_id/activities/new.xml | def new
@app = App.find(params[:app_id])
@activity = @app.activities.build
@base_versions = [Activity::NO_BASE_VERSION]
respond_to do |format|
format.html do # new.html.erb
render :layout => false if request.xhr?
end
format.xml { render :xml => @activity }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def new\n @activity = Activity.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @activity }\n end\n end",
"def new\n @activity = Activity.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @activ... | [
"0.71999097",
"0.71999097",
"0.71999097",
"0.7196296",
"0.7073456",
"0.7030201",
"0.69938236",
"0.6947735",
"0.6915419",
"0.6884871",
"0.68651843",
"0.68135357",
"0.68135357",
"0.67920786",
"0.67878574",
"0.6735992",
"0.66985035",
"0.66985035",
"0.66985035",
"0.66825545",
"0.... | 0.7752692 | 0 |
POST /apps/:app_id/activities POST /apps/:app_id/activities.xml | def create
@app = App.find(params[:app_id])
@activity = @app.activities.build(params[:activity])
@activity.state = Activity::STATE_DEVELOPMENT
respond_to do |format|
if @activity.save
flash[:notice] = 'Activity was successfully created.'
format.html do
if request.xhr?
render :partial => 'shared/activity_row', :collection => @app.activities, :as => 'activity'
else
redirect_to app_activity_path(@app, @activity)
end
end
format.xml { render :xml => @activity, :status => :created, :location => @activity }
else
format.html do
@base_versions = ['1_1_0']
if request.xhr?
render :partial => 'new', :locals => {:activity => @activity, :app => @app}, :status => :unprocessable_entity
else
render :action => "new"
end
end
format.xml { render :xml => @activity.errors, :status => :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @app = App.new(params[:app])\n\n respond_to do |format|\n if @app.save\n flash[:notice] = 'App was successfully created.'\n format.html { redirect_to app_activities_path(@app) }\n format.xml { render :xml => @app, :status => :created, :location => @app }\n else\n ... | [
"0.6635357",
"0.63406974",
"0.6203846",
"0.61748",
"0.6168937",
"0.6111531",
"0.603031",
"0.6029051",
"0.6002325",
"0.5982243",
"0.5969993",
"0.59637713",
"0.59147775",
"0.58699477",
"0.58205557",
"0.5809669",
"0.5805476",
"0.5774539",
"0.5753777",
"0.5730264",
"0.5708844",
... | 0.6751496 | 0 |
PUT /apps/:app_id/activities/1 PUT /apps/:app_id/activities/1.xml | def update
@app = App.find(params[:app_id])
@activity = @app.activities.find(params[:id])
if params[:cancel_edit_activity_button]
respond_to do |format|
format.html do
if request.xhr?
render :partial => 'shared/activity', :locals => { :activity => @activity }
else
redirect_to apps_url
end
end
format.xml { head :ok }
end
return
end
@vscm = Brazil::AppSchemaVersionControl.new(:vc_type => Brazil::AppSchemaVersionControl::TYPE_SUBVERSION, :vc_path => @app.vc_path, :vc_uri => ::AppConfig.vc_uri)
@base_versions = @vscm.find_versions(params[:arg])
@base_versions << Activity::NO_BASE_VERSION if @base_versions.count == 0
respond_to do |format|
if @activity.update_attributes(params[:activity])
flash[:notice] = 'Activity was successfully updated.'
format.html do
if request.xhr?
render :partial => "shared/activity", :locals => {:activity => @activity}
else
redirect_to app_activity_path(@app, @activity)
end
end
format.xml { head :ok }
else
format.html do
if request.xhr?
render :action => "edit", :layout => false, :status => :unprocessable_entity
else
render :action => "edit"
end
end
format.xml { render :xml => @activity.errors, :status => :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n @activity = Activity.find(params[:id])\n \n respond_to do |format|\n if @activity.update_attributes(params[:activity])\n format.html { redirect_to activities_path }\n format.xml { render :nothing => true }\n else\n format.html { render :action => \"edit\" }\n ... | [
"0.63192606",
"0.6249981",
"0.6135884",
"0.6096377",
"0.604933",
"0.6016694",
"0.6013294",
"0.59864503",
"0.59864503",
"0.59523326",
"0.59380454",
"0.5912953",
"0.5862933",
"0.5826033",
"0.58185405",
"0.58185405",
"0.5817651",
"0.58114105",
"0.5787126",
"0.576351",
"0.5757025... | 0.64591056 | 0 |
The initial command set | def commands
{
"wmap_website" => "List website structure",
"wmap_targets" => "Targets in the database",
"wmap_sql" => "Query the database",
"wmap_run" => "Automatically test/exploit everything",
"wmap_proxy" => "Run mitm proxy",
"wmap_crawl" => "Crawl website",
"wmap_attack" => "Crawl and Test",
}
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_commands; end",
"def set_commands\n super\n @commands['clear'] = ConsoleCommand_Clear.new(self)\n @commands['confirm'] = ConsoleCommand_Confirm.new(self)\n end",
"def command_start; end",
"def command_start; end",
"def command_start; end",
"def initialize\n load_commands\n end",... | [
"0.7725559",
"0.6881619",
"0.6812177",
"0.6812177",
"0.6812177",
"0.67476165",
"0.6671954",
"0.6669425",
"0.6664881",
"0.6654931",
"0.6617587",
"0.66029453",
"0.66029453",
"0.66029453",
"0.65645075",
"0.6561333",
"0.6554074",
"0.6478962",
"0.6478088",
"0.6392972",
"0.6319513"... | 0.0 | -1 |
A copy of the shotgun approach to website exploitation | def cmd_wmap_run(*args)
stamp = Time.now.to_f
mode = 0
eprofile = []
using_p = false
args.push("-h") if args.length == 0
while (arg = args.shift)
case arg
when '-t'
mode |= WMAP_SHOW
when '-e'
mode |= WMAP_EXPL
profile = args.shift
if profile
print_status("Using profile #{profile}.")
begin
File.open(profile).each do |str|
if not str.include? '#'
# Not a comment
modname = str.strip
if not modname.empty?
eprofile << modname
end
end
using_p = true
end
rescue
print_error("Profile not found or invalid.")
return
end
else
print_status("Using ALL wmap enabled modules.")
end
when '-h'
print_status("Usage: wmap_run [options]")
print_line("\t-h Display this help text")
print_line("\t-t Show all matching exploit modules")
print_line("\t-e [profile] Launch profile test modules against all matched targets.")
print_line("\t No profile runs all enabled modules.")
print_line("")
return
end
end
if selected_host == nil
print_error("Target not selected.")
return
end
# WMAP_DIR, WMAP_FILE
matches = {}
# WMAP_SERVER
matches1 = {}
# WMAP_QUERY
matches2 = {}
# WMAP_BODY
matches3 = {}
# WMAP_HEADERS
matches4 = {}
# WMAP_UNIQUE_QUERY
matches5 = {}
# WMAP_GENERIC
matches10 = {}
# EXPLOIT OPTIONS
opt_str = nil
bg = false
jobify = false
[ [ framework.auxiliary, 'auxiliary' ], [framework.exploits, 'exploit' ] ].each do |mtype|
# Scan all exploit modules for matching references
mtype[0].each_module do |n,m|
e = m.new
# Only include wmap_enabled plugins
if e.respond_to?("wmap_enabled")
penabled = e.wmap_enabled
if penabled
if not using_p or eprofile.include? n.split('/').last
#
# First run the WMAP_SERVER plugins
#
case e.wmap_type
when :WMAP_SERVER
if RUN_WMAP_SERVER
matches1[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_QUERY
if RUN_WMAP_QUERY
matches2[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_BODY
if RUN_WMAP_BODY
matches3[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_HEADERS
if RUN_WMAP_HEADERS
matches4[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_UNIQUE_QUERY
if RUN_WMAP_UNIQUE_QUERY
matches5[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_GENERIC
if RUN_WMAP_GENERIC
matches10[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
when :WMAP_DIR, :WMAP_FILE
if RUN_WMAP_DIR_FILE
matches[[selected_host,selected_port,selected_ssl,mtype[1]+'/'+n]]=true
end
else
# Black Hole
end
end
end
end
end
end
#
# Handle modules that need to be run before all tests, once usually again the web server.
# :WMAP_SERVER
#
idx = 0
matches1.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# For exploits
#
payload = mod.datastore['PAYLOAD']
encoder = mod.datastore['ENCODER']
target = mod.datastore['TARGET']
nop = mod.datastore['NOP']
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins that only need to be
# launched once.
#
wtype = mod.wmap_type
if wtype == :WMAP_SERVER
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
if session
stat = '[*]'
if (session == Msf::Exploit::CheckCode::Vulnerable)
stat = '[+]'
end
print_line(stat + ' ' + session[1])
#
# Exploit if WMAP_RUNEXPL
#
if (session == Msf::Exploit::CheckCode::Vulnerable) and WMAP_RUNEXPL
print_status("Exploiting...")
begin
session = mod.exploit_simple(
'Encoder' => encoder,
'Payload' => payload,
'Target' => target,
'Nop' => nop,
'OptionStr' => opt_str,
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => jobify)
rescue ::Interrupt
raise $!
rescue ::Exception => e
print_error("Exploit failed: #{e.class} #{e}")
if(e.class.to_s != 'Msf::OptionValidateError')
print_error("Call stack:")
e.backtrace.each do |line|
break if line =~ /lib.msf.base.simple/
print_error(" #{line}")
end
end
end
# If we were given a session, let's see what we can do with it
if (session)
# If we aren't told to run in the background and the session can be
# interacted with, start interacting with it by issuing the session
# interaction command.
if (bg == false and session.interactive?)
print_line
driver.run_single("sessions -q -i #{session.sid}")
# Otherwise, log that we created a session
else
print_status("Session #{session.sid} created in the background.")
end
# If we ran the exploit as a job, indicate such so the user doesn't
# wonder what's up.
if WMAP_EXITIFSESS
return
end
elsif (jobify)
print_status("Exploit running as background job.")
# Worst case, the exploit ran but we got no session, bummer.
else
print_status("Exploit completed, but no session was created.")
end
end
else
print_error("Check failed: The state could not be determined.")
end
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Handle modules to be run at every path/file
# WMAP_DIR, WMAP_FILE
#
idx = 0
matches.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins that only need to be
# launched once.
#
wtype = mod.wmap_type
#
#Here is where the fun begins
#
test_tree = load_tree()
test_tree.each do |node|
testpath = Pathname.new(node.current_path)
strpath = testpath.cleanpath(false).to_s
#
# Fixing paths
#
if node.is_leaf? and not node.is_root?
#
# Later we can add here more checks to see if its a file
#
else
if node.is_root?
strpath = "/"
else
strpath = strpath.chomp + "/"
end
end
strpath = strpath.gsub("//", "/")
#print_status("Testing path: #{strpath}")
#
# Launch plugin depending module type.
# Module type depends on main input type.
# Code may be the same but it depend on final
# versions of plugins
#
case wtype
when :WMAP_FILE
if node.is_leaf? and not node.is_root?
#
# Check if an exclusion regex has been defined
#
if self.framework.datastore['WMAP_EXCLUDE_FILE']
excludefilestr = self.framework.datastore['WMAP_EXCLUDE_FILE']
else
excludefilestr = WMAP_EXCLUDE_FILE
end
if not strpath.match(excludefilestr)
mod.datastore['PATH'] = strpath
print_status("Launching #{xref[3]} #{wtype} #{strpath} against #{xref[0]}:#{xref[1]}...")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{name}: #{$!}")
end
end
end
end
when :WMAP_DIR
if not node.is_leaf? or node.is_root?
mod.datastore['PATH'] = strpath
print_status("Launching #{xref[3]} #{wtype} #{strpath} against #{xref[0]}:#{xref[1]}...")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{name}: #{$!}")
end
end
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Run modules for each request to play with URI with UNIQUE query parameters.
# WMAP_UNIQUE_QUERY
#
idx = 0
matches5.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins for each request that have a distinct
# GET/POST URI QUERY string.
#
wtype = mod.wmap_type
utest_query = {}
framework.db.each_request_target_with_query do |req|
#
# Only test unique query strings by comparing signature to previous tested signatures 'path,p1,p2,pn'
#
if (utest_query.has_key?(mod.signature(req.path,req.query)) == false)
#
# Weird bug req.method doesnt work
# collides with some method named 'method'
# column table renamed to 'meth'.
#
mod.datastore['METHOD'] = req.meth.upcase
mod.datastore['PATH'] = req.path
mod.datastore['QUERY'] = req.query
mod.datastore['HEADER_SEP'] = STR_HEADER_SEPARATOR
mod.datastore['HEADERS'] = headers_to_s(req.headers,STR_HEADER_SEPARATOR)
mod.datastore['COOKIE'] = header(req.headers,"Cookie")
mod.datastore['DATA'] = req.body
#
# TODO: Add method, headers, etc.
#
if wtype == :WMAP_UNIQUE_QUERY
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
#
# Unique query tested, actually the value does not matter
#
# print_status("#{mod.signature(req.path,req.query)}")
utest_query[mod.signature(req.path,req.query)]=1
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Run modules for each request to play with URI query parameters.
# This approach will reduce the complexity of the Tree used before
# and will make this shotgun implementation much simple.
# WMAP_QUERY
#
idx = 0
matches2.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins for each request that have a distinct
# GET/POST URI QUERY string.
#
wtype = mod.wmap_type
framework.db.each_request_target_with_query do |req|
#
# Weird bug req.method doesnt work
# collides with some method named 'method'
# column table renamed to 'meth'.
#
mod.datastore['METHOD'] = req.meth.upcase
mod.datastore['PATH'] = req.path
mod.datastore['QUERY'] = req.query
mod.datastore['HEADER_SEP'] = STR_HEADER_SEPARATOR
mod.datastore['HEADERS'] = headers_to_s(req.headers,STR_HEADER_SEPARATOR)
mod.datastore['COOKIE'] = header(req.headers,"Cookie")
mod.datastore['DATA'] = req.body
#
# TODO: Add method, headers, etc.
#
if wtype == :WMAP_QUERY
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Run modules for each request to play with request bodies.
# WMAP_BODY
#
idx = 0
matches3.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins for each request for all headers
# This can be improved alot . Later versions
# Should only tests on unique requests.
#
wtype = mod.wmap_type
framework.db.each_request_target_with_body do |req|
#
# Weird bug req.method doesnt work
# collides with some method named 'method'
# column table renamed to 'meth'.
#
mod.datastore['METHOD'] = req.meth.upcase
mod.datastore['PATH'] = req.path
mod.datastore['QUERY'] = req.query
mod.datastore['HEADER_SEP'] = STR_HEADER_SEPARATOR
mod.datastore['HEADERS'] = headers_to_s(req.headers,STR_HEADER_SEPARATOR)
mod.datastore['COOKIE'] = header(req.headers,"Cookie")
mod.datastore['DATA'] = req.body
#
# TODO: Add method, headers, etc.
#
if wtype == :WMAP_BODY
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Run modules for each request to play with request headers.
# WMAP_HEADERS
#
idx = 0
matches4.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins for each request for all headers
# This can be improved alot . Later versions
# Should only tests on unique requests.
#
wtype = mod.wmap_type
framework.db.each_request_target_with_headers do |req|
#
# Weird bug req.method doesnt work
# collides with some method named 'method'
# column table renamed to 'meth'.
#
mod.datastore['METHOD'] = req.meth.upcase
mod.datastore['PATH'] = req.path
mod.datastore['QUERY'] = req.query
mod.datastore['HEADER_SEP'] = STR_HEADER_SEPARATOR
mod.datastore['HEADERS'] = headers_to_s(req.headers,STR_HEADER_SEPARATOR)
mod.datastore['COOKIE'] = header(req.headers,"Cookie")
mod.datastore['DATA'] = req.body
#
# TODO: Add method, headers, etc.
#
if wtype == :WMAP_HEADERS
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
#
# Handle modules that need to be after all tests, once.
# Good place to have modules that analize the test results and/or
# launch exploits.
# :WMAP_GENERIC
#
idx = 0
matches10.each_key do |xref|
idx += 1
begin
mod = nil
#Carefull with the references on this one
if ((mod = framework.modules.create(xref[3])) == nil)
print_status("Failed to initialize #{xref[3]}")
next
end
if (mode & WMAP_SHOW != 0)
print_status("Loaded #{xref[3]} ...")
end
#
# The code is just a proof-of-concept and will be expanded in the future
#
if (mode & WMAP_EXPL != 0)
#
# For modules to have access to the global datastore
# i.e. set -g DOMAIN test.com
#
self.framework.datastore.each do |gkey,gval|
mod.datastore[gkey]=gval
end
#
# Parameters passed in hash xref
#
mod.datastore['RHOST'] = xref[0]
mod.datastore['RHOSTS'] = xref[0]
mod.datastore['RPORT'] = xref[1].to_s
mod.datastore['SSL'] = xref[2].to_s
#
# Run the plugins that only need to be
# launched once.
#
wtype = mod.wmap_type
if wtype == :WMAP_GENERIC
print_status("Launching #{xref[3]} #{wtype} against #{xref[0]}:#{xref[1]}")
# To run check function for modules that are exploits
if mod.respond_to?("check") and WMAP_CHECK
begin
session = mod.check_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during check launch from #{xref[3]}: #{$!}")
end
else
begin
session = mod.run_simple(
'LocalInput' => driver.input,
'LocalOutput' => driver.output,
'RunAsJob' => false)
rescue ::Exception
print_status(" >> Exception during launch from #{xref[3]}: #{$!}")
end
end
end
end
rescue ::Exception
print_status(" >> Exception from #{xref[3]}: #{$!}")
end
end
if (mode & WMAP_SHOW != 0)
print_status("Analysis completed in #{(Time.now.to_f - stamp)} seconds.")
print_status("Done.")
end
# EOM
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def ygg_attacker() ; return nil ; end",
"def exploit\r\n # Find a valid CGI target\r\n target_uri = find_target_cgi\r\n return unless target_uri\r\n\r\n # Create wrappers for each potential architecture\r\n cycle_possible_payloads do |wrapped_payload|\r\n\r\n # Trigger the vulnerability and r... | [
"0.6546669",
"0.6004632",
"0.58637446",
"0.5750444",
"0.56609607",
"0.5630408",
"0.56231254",
"0.559473",
"0.55572426",
"0.5527703",
"0.5511109",
"0.5511109",
"0.54837406",
"0.5430881",
"0.5426084",
"0.54252076",
"0.54173684",
"0.54162204",
"0.540586",
"0.53855217",
"0.536286... | 0.0 | -1 |
Load website structure into a tree | def load_tree
wtree = Tree.new("ROOT_TREE")
if selected_host == nil
print_error("Target not selected")
else
framework.db.each_request_target do |req|
tarray = req.path.to_s.split(WMAP_PATH)
tarray.delete("")
tpath = Pathname.new(WMAP_PATH)
tarray.each do |df|
wtree.add_at_path(tpath.to_s,df)
tpath = tpath + Pathname.new(df.to_s)
end
end
end
return wtree
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @page_structure = Page.find_by(parent_path: '', csv_id: @page.csv_id).subtree.arrange\n end",
"def parse_tree\n File.open(html_file, 'r') do |file|\n current = nil\n file.each_line do |line|\n line.scan(%r{(<(.*?>.*?)<(\\/.*?)>|<(.*?)>(.*))}).each do |tag|\n if !tag[3]... | [
"0.619226",
"0.604039",
"0.60373944",
"0.60266364",
"0.6025094",
"0.59528786",
"0.5933017",
"0.59258133",
"0.59075695",
"0.58738905",
"0.58695674",
"0.5862803",
"0.5832102",
"0.5750063",
"0.5697035",
"0.568668",
"0.5653639",
"0.5649694",
"0.56235075",
"0.5620256",
"0.5617167"... | 0.605245 | 1 |
Print Tree structure. Ugly | def print_tree(tree)
if tree.is_leaf? and tree.depth > 0
print_line(("|\t"*(tree.depth-1))+"+------"+tree.name)
else
print_line(("|\t"*tree.depth)+tree.name)
end
tree.children.each_pair do |name,child|
print_tree(child)
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def print_tree\n ''\n end",
"def to_tree() = puts(TTY::Tree.new({ '.' => as_tree }).render)",
"def printTree()\n def pTree(node, i)\n puts node.toString i\n node.children.each do|child|\n pTree(child, i+1)\n end\n end\n pTree(@root, 0)\n end",
"def print_tree\n if root.... | [
"0.8491894",
"0.83653766",
"0.82483524",
"0.81755626",
"0.81558853",
"0.81053865",
"0.8093906",
"0.7949422",
"0.7877208",
"0.77357244",
"0.7713521",
"0.7705113",
"0.76802486",
"0.7668137",
"0.7653478",
"0.7545643",
"0.7516405",
"0.7473954",
"0.74318093",
"0.74265295",
"0.7408... | 0.83958703 | 1 |
Method to parse URIs Regex RFC3986 | def uri_parse(uri)
if uri == ''
print_error("URI required")
return
end
regexstr = '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?'
regexurl = Regexp.new(regexstr, false)
ret = regexurl.match(uri)
return ret
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def parse_uri(input)\n lines = parse_input input\n extract_uri lines\n end",
"def sf_uri_regex\n { uri: %r{\\b(\n (((ht|f)tp[s]?://)|([a-z0-9]+\\.))+\n (?<!@)\n ([a-z0-9\\_\\-]+)\n (\\.[a-z]+)+\n ([\\?/\\:][a-z0-9_=%&@\... | [
"0.71318907",
"0.708425",
"0.68115157",
"0.68006647",
"0.68006647",
"0.6790256",
"0.675874",
"0.6650863",
"0.6650863",
"0.66390675",
"0.65618175",
"0.65297836",
"0.65148187",
"0.6428552",
"0.6384321",
"0.6384273",
"0.6337534",
"0.628669",
"0.6256705",
"0.62517905",
"0.6207229... | 0.7141475 | 0 |
Method to transfor headers to string | def headers_to_s(nheaders,hsep)
hstr = ""
nheaders.each_line do |lh|
if hstr.empty?
hstr = lh
else
hstr = lh + hsep + hstr
end
end
return hstr
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def stringify_headers(headers); end",
"def encode_header(s); s; end",
"def to_s\n \"#{headers}\\r\\n\\r\\n#{body}\"\n end",
"def str_headers(env, status, headers, res_info, lines, requests, client); end",
"def header_data\n\t\treturn self.normalized_headers.to_s\n\tend",
"def encode_headers(heade... | [
"0.84644645",
"0.7603626",
"0.75891757",
"0.7425437",
"0.7348725",
"0.72035253",
"0.7171323",
"0.7132802",
"0.7116749",
"0.70277107",
"0.6888649",
"0.68741566",
"0.68358463",
"0.68005425",
"0.6721236",
"0.6680652",
"0.66741914",
"0.6647855",
"0.6635465",
"0.6635465",
"0.66215... | 0.7059619 | 9 |
Method to grab a specific header | def header(nheaders,hname)
nheaders.each_line do |lh|
n,v = lh.split(": ")
if n == hname
return v
end
end
return hstr
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_header name\n request_object.headers[name]\n end",
"def get_header(name)\n headers.each do |key,value|\n if key.casecmp(name) == 0\n return value\n end\n end\n nil\n end",
"def getHeader() @header1 end",
"def header\n return @header\n end",
"def getS... | [
"0.7766357",
"0.7743746",
"0.7737908",
"0.7430421",
"0.7356503",
"0.7327206",
"0.7258677",
"0.7249813",
"0.72410613",
"0.7233088",
"0.71867454",
"0.71505994",
"0.7135848",
"0.7135745",
"0.7124409",
"0.710787",
"0.71030587",
"0.7097704",
"0.7080751",
"0.7058083",
"0.7011392",
... | 0.7181181 | 11 |
Dates come in as yyyyMMdd | def parse_date(date_str)
split = date_str.split('-')
Date.new(split[0].to_i, split[1].to_i, split[2].to_i)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def date_str\n date.strftime(\"%Y%m%d\")\n end",
"def dates\n end",
"def literal_date(v)\n v.strftime(\"{d '%Y-%m-%d'}\")\n end",
"def to_date()\n #This is a stub, used for indexing\n end",
"def date\n \"#{self[:day]}_#{self[:month]}_#{self[:year]}\"\n end",
"def conve... | [
"0.69663465",
"0.69141597",
"0.68581027",
"0.6743142",
"0.6638127",
"0.66007483",
"0.6553421",
"0.6547536",
"0.65246814",
"0.6505308",
"0.6505308",
"0.6505308",
"0.64991856",
"0.6480725",
"0.6457871",
"0.6450041",
"0.6430903",
"0.6419208",
"0.6411209",
"0.64085966",
"0.640729... | 0.0 | -1 |
single String argument, and returns a string that contains the last name, a comma, a space, and the first name. | def swap_name(str)
arr = str.split
p arr[1] + ', ' + arr[0]
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def name\n value = \"#{last_name}, #{first_name}\".strip\n if value == ','\n ''\n else\n value\n end\n end",
"def last_first_name\n ret = \"\"\n ret += name unless name.blank?\n ret += \", \" unless firstname.blank? or name.blank?\n ret += firstname unless firstname.blank?\n ... | [
"0.8231114",
"0.8047538",
"0.80303293",
"0.79766214",
"0.79463255",
"0.7857146",
"0.78483176",
"0.7835235",
"0.77981156",
"0.779684",
"0.777745",
"0.77671796",
"0.7759687",
"0.7759687",
"0.7759687",
"0.7759687",
"0.7759687",
"0.7755722",
"0.77458584",
"0.77458584",
"0.7745858... | 0.0 | -1 |
is_n_palin.rb Checks if a number is palindrome or not by . Using math logic only, and . Not using any Ruby Library | def is_n_palin? n
begin
if Float(n).to_i != n.to_i
abort "'#{n}' is NOT a Whole Number"
end
rescue
abort "'#{n}' is NOT a Number"
end
n = n.to_i
m = n ; r = 0
while m > 0 do
r = 10 * r + m - 10 * (m/10)
m = m/10
end
n==r
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def hack?(n)\n binary_n = n.to_s(2).to_i\n palindrome? binary_n and sum_digits(binary_n).odd?\nend",
"def is_palindrome(number)\n return false if number == nil || number < 0\n\n k = 0\n clone_number = number\n\n until clone_number == 0\n clone_number /= 10\n k += 1\n end\n\n return true if k == 1\n... | [
"0.8149677",
"0.8029579",
"0.80224293",
"0.8011247",
"0.79716575",
"0.7950968",
"0.794412",
"0.78864956",
"0.78726786",
"0.7846578",
"0.7843935",
"0.7839869",
"0.78309005",
"0.7828676",
"0.78216565",
"0.7819166",
"0.7808141",
"0.7804347",
"0.7790963",
"0.7790963",
"0.7774511"... | 0.72213835 | 84 |
Default implementation, to make it easy to override later | def search_for_item
search_service.fetch(params[:id], { fl: ['visibility_ssi'] })
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def overrides; end",
"def custom; end",
"def custom; end",
"def implementation; end",
"def implementation; end",
"def default; end",
"def default; end",
"def special\n override\n end",
"def initialize(*)\n super\n apply_defaults\n end",
"def private; end",
"def initialize\n ... | [
"0.76447266",
"0.73952156",
"0.73952156",
"0.7298986",
"0.7298986",
"0.7187084",
"0.7187084",
"0.7186146",
"0.71053964",
"0.69783044",
"0.69513744",
"0.69513744",
"0.69513744",
"0.6917527",
"0.68233794",
"0.67935646",
"0.67935646",
"0.67935646",
"0.67935646",
"0.67935646",
"0... | 0.0 | -1 |
there is no root for this Action??? we only have pageshome for the root | def index
if params[:s].blank?
@bikes = policy_scope(Bike).order(created_at: :desc)
@bike_locs = @bikes.where.not(latitude: nil, longitude: nil)
@markers = @bike_locs.map do |bike|
{
lat: bike.latitude,
lng: bike.longitude,
infoWindow: render_to_string(partial: "infowindow", locals: { bike: bike })
}
end
@bikes.each { |bike| rating(bike) }
else
@bikes = policy_scope(Bike).search_by_make_and_model(params[:s])
@bike_locs = @bikes.where.not(latitude: nil, longitude: nil)
@markers = @bike_locs.map do |bike|
{
lat: bike.latitude,
lng: bike.longitude,
infoWindow: render_to_string(partial: "infowindow", locals: { bike: bike })
}
end
@bikes.each { |bike| rating(bike) }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def root\n self.home\n self\n end",
"def root_path; end",
"def root_path; end",
"def root_path; end",
"def index\n @root_pages = [fetch_root_page].flatten\n end",
"def root\n @node = DrupalNode.find_root_by_slug(params[:id])\n return if check_and_redirect_node(@node)\n @revision... | [
"0.69357735",
"0.6792352",
"0.6792352",
"0.6792352",
"0.67071843",
"0.6680165",
"0.666075",
"0.6649983",
"0.654493",
"0.6510054",
"0.64853936",
"0.6425894",
"0.6417546",
"0.6417546",
"0.64056313",
"0.6392641",
"0.6388277",
"0.6362583",
"0.636164",
"0.636164",
"0.62807554",
... | 0.0 | -1 |
This method runs the command | def run(args) # :nodoc
if args.size > 1
path = File.expand_path(args[1])
settings[:directory] = "#{path}:#{settings[:directory]}"
msg "Source directories searched: #{settings[:directory]}"
else
if confirm('Reintialize source path to empty?', false)
settings[:directory] = '$cdir:$cwd'
msg 'Source directories searched: $cdir:$cwd'
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def run\n # TODO: include a parse step here and remove duplicate parsing code from\n # individual commands\n execute\n end",
"def execute\n parse_command\n run_command(command)\n end",
"def execute(command)\n end",
"def run_cmd(cmd)\n\tend",
"def run\n \n if pa... | [
"0.7803678",
"0.7514057",
"0.74642265",
"0.73407644",
"0.73103845",
"0.72995764",
"0.72976494",
"0.7269735",
"0.7211652",
"0.7211652",
"0.7145173",
"0.713036",
"0.71010137",
"0.7089392",
"0.7047495",
"0.7036551",
"0.6989219",
"0.69773823",
"0.69773823",
"0.6977335",
"0.697617... | 0.0 | -1 |
Simplify adding filters Returns nothing | def add(name, filter_dsl)
filter = @f.translate(filter_dsl)
filter[:name] = name
@f.add(filter)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_filters(filters); end",
"def filters; end",
"def filters; end",
"def filters\n end",
"def filters=(_arg0); end",
"def filters=(_arg0); end",
"def apply_filter\n end",
"def filter; end",
"def filter; end",
"def filter; end",
"def add_filters\n add_term_filters\n add_t... | [
"0.82883304",
"0.80570495",
"0.80570495",
"0.7806149",
"0.76927644",
"0.76927644",
"0.753796",
"0.72555506",
"0.72555506",
"0.72555506",
"0.72485274",
"0.72464496",
"0.7216015",
"0.7143325",
"0.7089148",
"0.70775014",
"0.7057083",
"0.70180255",
"0.70077485",
"0.6999298",
"0.6... | 0.0 | -1 |
Run the program forever Returns nothing | def foreverize
loop do
run
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def run_forever\n run\n sleep(10) while true\n end",
"def loop_forever; end",
"def run!\n run\n die\n end",
"def run\n while 1\n sleep(0.2)\n #puts \"bezim \"+@pid.to_s\n end\n end",
"def infinite_loop?; end",
"def forever\n raise ArgumentError, \"there's only on... | [
"0.73847866",
"0.7061956",
"0.6839938",
"0.67383045",
"0.65228266",
"0.65196866",
"0.64676213",
"0.6428535",
"0.6426743",
"0.64231485",
"0.6390698",
"0.6367453",
"0.6282011",
"0.6282011",
"0.6277327",
"0.6271219",
"0.6247211",
"0.6241943",
"0.6222305",
"0.6202032",
"0.6180366... | 0.7821829 | 0 |
Collect all the filters and run them Returns nothing | def run
threads = []
filters = @f.all
filters.each do |filter|
threads << Thread.new(filters) do |fi|
@i.move(
filter[:filter],
{
:from => filter[:search_folder],
:to => filter[:destination_folder]
}
)
puts "Applied filter #{filter[:name]}"
end
end
threads.each { |t| t.join }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def filters; end",
"def filters; end",
"def filters\n end",
"def filter *filters\n spawn :@filters, @filters + parse_filter_input(filters)\n end",
"def filters=(_arg0); end",
"def filters=(_arg0); end",
"def apply_filter\n end",
"def all\n @filters\n end",
"def add_filters(filters... | [
"0.78184223",
"0.78184223",
"0.77020943",
"0.74917346",
"0.7317985",
"0.7317985",
"0.7259441",
"0.7165686",
"0.7124948",
"0.69551265",
"0.6943027",
"0.6943027",
"0.69303334",
"0.6907236",
"0.6883502",
"0.6826426",
"0.68248457",
"0.68097115",
"0.6787847",
"0.6787847",
"0.67878... | 0.60883015 | 87 |
Saves the (generic remote) entry identified by +name+ with +body+ into the project +p+, and returns +true+ on success and +false+ otherwise | def save_entry(name, body, p)
cli.say " Locating remote dataset: #{name}"
body[:md][:metadata_only] = true if cli[:only_md]
rd = MiGA::RemoteDataset.new(body[:ids], body[:db], body[:universe])
if cli[:get_md]
cli.say ' Updating dataset'
rd.update_metadata(p.dataset(name), body[:md])
else
cli.say ' Creating dataset'
rd.save_to(p, name, !cli[:query], body[:md])
cli.add_metadata(p.add_dataset(name))
end
true
rescue MiGA::RemoteDataMissingError => e
raise(e) unless cli[:ignore_removed]
cli.say " Removed dataset ignored: #{name}"
false
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def save\n create_ok = exists? ? true : create\n upload_ok = @unwritten_contents ? upload_new_content : true\n\n create_ok && upload_ok\n end",
"def put(text, summary = nil, minor = true, bot = true, password = nil)\n #require login\n @site.login(password)\n ... | [
"0.5888896",
"0.5631738",
"0.5526568",
"0.54915047",
"0.5467293",
"0.52076524",
"0.5180171",
"0.51760274",
"0.5173739",
"0.51665336",
"0.5146987",
"0.5123368",
"0.50474864",
"0.5037744",
"0.5022346",
"0.4903493",
"0.4881037",
"0.48575285",
"0.48368788",
"0.4826065",
"0.482594... | 0.6359997 | 0 |
Get the download crc status | def download_crc_enable
@protocol.download_crc_enable
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_crc\n # We consider the file's modification time\n if (File.exists?(@URL))\n return File.mtime(@URL)\n else\n return 0\n end\n end",
"def crc; end",
"def crc; end",
"def crc; end",
"def checksum\n fil_header[:checksum]\n end",
"... | [
"0.72992194",
"0.6786602",
"0.6786602",
"0.6786602",
"0.6331236",
"0.6293469",
"0.62414277",
"0.62102246",
"0.61419994",
"0.61397487",
"0.6019838",
"0.5991385",
"0.5973111",
"0.5967971",
"0.59239835",
"0.59184915",
"0.5905266",
"0.5863317",
"0.58291817",
"0.5751863",
"0.57349... | 0.6868267 | 1 |
Get the upload crc status | def upload_crc_enable
@protocol.upload_crc_enable
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_crc\n # We consider the file's modification time\n if (File.exists?(@URL))\n return File.mtime(@URL)\n else\n return 0\n end\n end",
"def checksum\n fil_header[:checksum]\n end",
"def crc; end",
"def crc; end",
"def crc; end",
"... | [
"0.690886",
"0.6660133",
"0.66370624",
"0.66370624",
"0.66370624",
"0.6318684",
"0.6291162",
"0.6233824",
"0.6208383",
"0.61668944",
"0.6120207",
"0.60766006",
"0.6051406",
"0.5926534",
"0.5879043",
"0.58259964",
"0.5821737",
"0.5800027",
"0.5795167",
"0.5789673",
"0.5762198"... | 0.64157426 | 5 |
Infer the file's content type using MIME::Types | def get_content_type(file)
t = MIME::Types.of(file)
t.first.content_type unless t.empty?
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def content_type\n file.try(:content_type)\n end",
"def file_content_type\n types = MIME::Types.type_for(original_filename)\n types.first\n end",
"def get_content_type file\n mime_type = MIME::Types.type_for(file.original_filename)\n return mime_type.first ? mime_type.first : nil... | [
"0.83890045",
"0.8295274",
"0.8135005",
"0.8133276",
"0.80336434",
"0.7968352",
"0.79659104",
"0.7941949",
"0.7931513",
"0.79158944",
"0.79158074",
"0.79158074",
"0.79158074",
"0.79031855",
"0.789201",
"0.7882607",
"0.7879156",
"0.78787696",
"0.7862716",
"0.78612816",
"0.7832... | 0.8148018 | 2 |
Get the checkpoint file path for file | def get_cpt_file(file)
"#{File.expand_path(file)}.cpt"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def stored_file_path\n File.join(path, stored_name)\n end",
"def file_path\n @file_path ||= lookup_file_path\n end",
"def current_file_path\n current_file.to_path\n end",
"def datafile_path(file)\n local_profile = \"~/.souschef/#{@opts[:profile]}/#{file}\"\n profile = Fi... | [
"0.66048586",
"0.6537602",
"0.6457375",
"0.63762385",
"0.63531625",
"0.63193935",
"0.63141906",
"0.63119173",
"0.6258782",
"0.6222742",
"0.6210929",
"0.6171818",
"0.61547905",
"0.6152128",
"0.6152128",
"0.6152128",
"0.6119811",
"0.6106538",
"0.6106292",
"0.60969955",
"0.60797... | 0.0 | -1 |
Returns a unique, deterministically reproducible index into an array We are hashing based on strings, let's use thegh ascii value of each string as a starting point. | def index(key, size)
key.sum % size
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def find_unique(array)\n unique_id = 0\n\n array.each do |num|\n unique_id ^= num\n end\n\n unique_id\nend",
"def generateKey(string)\r\n key = {}\r\n stringIterator = 0\r\n\r\n (string.length).times do\r\n charactersIterator = string[stringIterator] - 1\r\n divisorsIterator = 0\r\n divisors =... | [
"0.6362783",
"0.623856",
"0.6134275",
"0.6107789",
"0.6096853",
"0.6065457",
"0.6045744",
"0.59904367",
"0.59751123",
"0.5867098",
"0.58521837",
"0.5842074",
"0.5837003",
"0.58220273",
"0.57587296",
"0.57502437",
"0.57476807",
"0.5727595",
"0.57238585",
"0.5721597",
"0.571107... | 0.0 | -1 |
Calculate the current load factor | def load_factor
total_size = 0
@items.each do |list|
unless list == nil
node = list.head
while node != nil
total_size += 1
node = node.next
end
end
end
total_size.to_f / @items.count
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def load_factor\n puts \"Load Factor: #{new_load_factor = @item_count / @size.to_f}\"\n return new_load_factor\n end",
"def load_factor\n puts \"load_factor: #{@values} / #{@size}\"\n (@values + 0.0) / @size\n end",
"def load_factor\n max_pax / capacity.to_f\n end",
"def load_factor\n @c... | [
"0.8291456",
"0.80895066",
"0.80326515",
"0.7949917",
"0.77805996",
"0.7604256",
"0.7575579",
"0.7466798",
"0.7421441",
"0.7403656",
"0.7399935",
"0.7399935",
"0.73053604",
"0.7291829",
"0.71660674",
"0.7146284",
"0.70975053",
"0.7044498",
"0.70077485",
"0.69255835",
"0.68608... | 0.65408915 | 22 |
Simple method to return the number of items in the hash | def size
@items.count
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def size\n return @hash.length\n end",
"def length\n hash.keys.length\n end",
"def size\n @hash.size\n end",
"def size\n @hash.size\n end",
"def size\n @hash.size\n end",
"def size\n @hash_array.length\n end",
"def size\n @hash_array.length\n end",
"def size\n ... | [
"0.8283178",
"0.82099855",
"0.8110022",
"0.8110022",
"0.8110022",
"0.79692495",
"0.79692495",
"0.7811439",
"0.77484125",
"0.768469",
"0.76760906",
"0.7656256",
"0.763541",
"0.76296425",
"0.7615433",
"0.7615433",
"0.7574384",
"0.7569379",
"0.74782693",
"0.74442446",
"0.7397334... | 0.70070535 | 49 |
GET /braces GET /braces.json | def index
@braces = Brace.all
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @brags = Brag.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @brags }\n end\n end",
"def index\n @brave_bursts = BraveBurst.all\n end",
"def index\n\t\tboats = Boat.all\n \trender json: boats, status: 200\n\tend",
"def show\n ... | [
"0.71092236",
"0.63289505",
"0.63273585",
"0.6258178",
"0.6231472",
"0.61625695",
"0.61600506",
"0.6046012",
"0.60078377",
"0.6006116",
"0.5993438",
"0.59679717",
"0.59507537",
"0.5846685",
"0.5828976",
"0.5809143",
"0.57855755",
"0.5759427",
"0.5747759",
"0.5740776",
"0.5735... | 0.6873456 | 1 |
GET /braces/1 GET /braces/1.json | def show
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @brags = Brag.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @brags }\n end\n end",
"def index\n @braces = Brace.all\n end",
"def show\n @boat = Boat.find(params[:id])\n\n render json: @boat\n end",
"def index\n @brasse... | [
"0.7161646",
"0.67233694",
"0.6514773",
"0.65076214",
"0.6501591",
"0.63281244",
"0.63227427",
"0.6307786",
"0.6247193",
"0.62256",
"0.6166749",
"0.61098003",
"0.60504365",
"0.6036519",
"0.6007228",
"0.6004784",
"0.59831566",
"0.59397614",
"0.5931679",
"0.5927574",
"0.592645"... | 0.0 | -1 |
POST /braces POST /braces.json | def create
@brace = Brace.new(brace_params)
respond_to do |format|
if @brace.save
format.html { redirect_to @brace, notice: 'Brace was successfully created.' }
format.json { render :show, status: :created, location: @brace }
else
format.html { render :new }
format.json { render json: @brace.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @brave_burst = BraveBurst.new(brave_burst_params)\n\n respond_to do |format|\n if @brave_burst.save\n format.html { redirect_to @brave_burst, notice: 'Brave burst was successfully created.' }\n format.json { render action: 'show', status: :created, location: @brave_burst }\n ... | [
"0.68383217",
"0.6507961",
"0.64258444",
"0.64221305",
"0.64090884",
"0.6290803",
"0.62599546",
"0.6158221",
"0.5994533",
"0.59854513",
"0.59560364",
"0.5943507",
"0.59129804",
"0.5825745",
"0.58025044",
"0.5709124",
"0.5690121",
"0.56696236",
"0.5657618",
"0.5627007",
"0.559... | 0.61795694 | 7 |
PATCH/PUT /braces/1 PATCH/PUT /braces/1.json | def update
respond_to do |format|
if @brace.update(brace_params)
format.html { redirect_to @brace, notice: 'Brace was successfully updated.' }
format.json { render :show, status: :ok, location: @brace }
format.js { render :nothing => true }
else
format.html { render :edit }
format.json { render json: @brace.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n authorize @brass\n respond_to do |format|\n if @brass.update(brass_params)\n format.html { redirect_to @brass, notice: \"Brass was successfully updated.\" }\n format.json { render :show, status: :ok, location: @brass }\n else\n format.html { render :edit }\n ... | [
"0.7060333",
"0.67870116",
"0.6723954",
"0.66111386",
"0.6473427",
"0.6465582",
"0.6379323",
"0.6368771",
"0.62927634",
"0.62051696",
"0.61511886",
"0.61005193",
"0.60967565",
"0.6064139",
"0.6064139",
"0.6064139",
"0.6049426",
"0.60372466",
"0.60036004",
"0.5974491",
"0.5971... | 0.6115547 | 11 |
DELETE /braces/1 DELETE /braces/1.json | def destroy
@brace.destroy
respond_to do |format|
format.html { redirect_to braces_url, notice: 'Brace was successfully destroyed.' }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def destroy\n @brave_burst.destroy\n respond_to do |format|\n format.html { redirect_to brave_bursts_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @brag = Brag.find(params[:id])\n @brag.destroy\n\n respond_to do |format|\n format.html { redirect_to brags_... | [
"0.72455966",
"0.7170679",
"0.7013506",
"0.6980244",
"0.69086665",
"0.68296355",
"0.67967016",
"0.6769186",
"0.67485386",
"0.6706543",
"0.67013276",
"0.6685517",
"0.6671952",
"0.6658136",
"0.6643947",
"0.6600839",
"0.65720505",
"0.656156",
"0.655606",
"0.6552598",
"0.65510017... | 0.6828464 | 6 |
Use callbacks to share common setup or constraints between actions. | def set_brace
@brace = Brace.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 brace_params
params.require(:brace).permit(:revit_id, :done, :details, :section, :material, :angle)
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.69780594",
"0.678054",
"0.6742781",
"0.67387927",
"0.67346025",
"0.6590683",
"0.6501642",
"0.6495788",
"0.6479752",
"0.64763314",
"0.645457",
"0.6437739",
"0.6377168",
"0.6372484",
"0.6363871",
"0.63179374",
"0.62981373",
"0.6297456",
"0.62916917",
"0.6290227",
"0.628954",... | 0.0 | -1 |
load balancer pool member | def create_lbpool_member(lbpool, body)
validate([:name, :description, :ip, :port], body)
post(:uri => lbpool_members_uri(lbpool),
:body => body,
:accept => MESSAGE_TYPE,
:content_type => LBPOOL_MEMBER_TYPE)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_member(params)\n pool_name = get_param(params, :pool)\n node_ip = get_ip(params)\n node_port = (params[:port] || 80).to_i\n notify(:msg => \"[#{@name}] Retrieving member #{node_ip}:#{node_port} in pool #{pool_name} on load balancer #{@config[:host]}\",\n :tags => [:f5, :trac... | [
"0.7313905",
"0.679113",
"0.65034807",
"0.6392532",
"0.63496226",
"0.63495713",
"0.6269695",
"0.62072724",
"0.6195781",
"0.6195781",
"0.6105458",
"0.6070292",
"0.6028739",
"0.60098076",
"0.5994445",
"0.5975005",
"0.5931677",
"0.5931387",
"0.5928559",
"0.59130126",
"0.59130126... | 0.61465025 | 10 |
return the amount for item depends on the item quantity | def calculate_item_amount(quantity, price)
if quantity < 1 || price < 0
0
else
quantity * price
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_total_qty\n return self.items.sum(:qty)\n end",
"def total_quantity\n line_items.sum(:quantity)\n end",
"def item_quantity(item_id)\n details.select {|v| v.item_id === item_id}.inject(0) {|s, v| s += v.quantity }\n end",
"def total_items\r\n\t\t@items.inject(0) { |sum, i| sum + i.quantity... | [
"0.80186754",
"0.7972597",
"0.79310995",
"0.779008",
"0.77840984",
"0.7778586",
"0.7778586",
"0.7741598",
"0.7721953",
"0.76698625",
"0.7617446",
"0.76076275",
"0.76076275",
"0.7431918",
"0.73960143",
"0.73926455",
"0.73352253",
"0.7310268",
"0.72948766",
"0.72948766",
"0.728... | 0.75004107 | 13 |
calculate item amount based on user type and item type discount should not applied for grocery item. | def calculate_item_amount_with_discount(item, user)
item_bill_amount = calculate_item_amount(item.quantity, item.price)
return item_bill_amount if item.is_grocery?
return item_bill_amount - (item_bill_amount * get_discount_percentage(user))/100
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def calculate_net_amount\n @items.each do |item|\n item.price_after_discount = @discount_processor.calculate_item_amount_with_discount(item, @user)\n end\n\n #total items bill amount\n items_total = @items.map(&:price_after_discount).reduce(:+)\n\n #applying discount on total amount.\n @disc... | [
"0.7228091",
"0.71397626",
"0.711246",
"0.6921125",
"0.6786587",
"0.6783693",
"0.6768235",
"0.66498154",
"0.66097265",
"0.65182537",
"0.65061027",
"0.64594287",
"0.6436977",
"0.64301085",
"0.636894",
"0.6326934",
"0.6319203",
"0.62810284",
"0.6257304",
"0.62442225",
"0.623895... | 0.8129046 | 0 |
discount applied for every hundred dollar. | def apply_discount_on_total(total_amount)
return total_amount if total_amount < 100
discount_amount = (total_amount.to_i / 100) * EACH_HUNDRED_DOLLAR
total_amount - discount_amount
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def get_every_hundred_discount(total_price)\n self.every_hundred_discount_price = (total_price - (total_price % 100))/100 * 5\n end",
"def collection_discount(total)\n (discount * total) / 100\n end",
"def apply_discount\n if @discount != 0\n @discount = @discount.to_f / 100 # discount is 20%, ... | [
"0.814661",
"0.7683957",
"0.75797004",
"0.74938834",
"0.74754834",
"0.7411756",
"0.73346037",
"0.73089904",
"0.7303228",
"0.7289374",
"0.7238917",
"0.72196484",
"0.7214801",
"0.71834564",
"0.71736383",
"0.7172041",
"0.71614873",
"0.7136958",
"0.7103367",
"0.71018416",
"0.7097... | 0.71936136 | 13 |
Given array 'values', converts array to DAT formatted line and appends it to associate file | def <<(values)
@file_handle << DAT.to_dat_line(Array(values))
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def <<(values)\n\t\t@file_handle << TSV.to_tsv_line(Array(values))\n\tend",
"def chart names, values\n normalized_values = values\n normalized_values = values.map {|v| [v] } if (values.count > 0 && (not values[0].is_a?(Array)))\n write_rows('temp', names, normalized_values)\n `open temp.csv`\nend",
"def wr... | [
"0.65925",
"0.6241588",
"0.5999941",
"0.595335",
"0.5679984",
"0.56630635",
"0.56234163",
"0.56034136",
"0.55729586",
"0.55706155",
"0.55666363",
"0.5565597",
"0.5550712",
"0.5536213",
"0.54972893",
"0.5463082",
"0.54464805",
"0.54124",
"0.5398023",
"0.5388137",
"0.5381048",
... | 0.761556 | 0 |
Closes the underlying file | def close
@file_handle.close
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def close()\n @file.close\n end",
"def close\n @file.close\n end",
"def close\n @handle.closeFile\n @handle = nil\n end",
"def close_file\r\n end",
"def close(filename); end",
"def close_file\n if is_file_open?\n @file_handle.close\n \n # reset 'flags... | [
"0.7995276",
"0.79673207",
"0.7955526",
"0.78110576",
"0.7767101",
"0.7712566",
"0.77116525",
"0.7649897",
"0.754825",
"0.7426402",
"0.72660905",
"0.72397685",
"0.7220902",
"0.715457",
"0.71545345",
"0.7136461",
"0.7069517",
"0.7030324",
"0.68738693",
"0.6817892",
"0.6796484"... | 0.74599284 | 9 |
RELEASE 1 Add a method to your file that takes a number of Fibonacci terms to generate and returns an array of the terms. For example, fib(6) would return [0,1,1,2,3,5]. Your method should work for a large number of terms. To verify your work: the last number in the array generated by fib(100) will be 218922995834555169026. (How can you verify this without having to compare this huge number manually? Be smart with your driver code!) method takes one argument, how many times we want sequence to run | def fib_sequence(x)
array = [0,1]
index = 0
# some loop
while index < x
new_number = array[index] + array[index + 1]
index += 1
# pushes items into array
array << new_number
end
return array
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fibonacci_numbers(num) #method takes one argument. The amount of fibonacci numbers you wish to generate.\r\n\tfib_arr = [0,1] #the fibonacci sequence begins with integers 0 and 1\r\n\t(num-2).times {fib_arr << fib_arr[-1] + fib_arr[-2]} #because the first two numbers are given we subtract 2 from the number of... | [
"0.8033945",
"0.7980956",
"0.78517246",
"0.7827755",
"0.7798108",
"0.7707896",
"0.76919574",
"0.7666367",
"0.7664757",
"0.7645406",
"0.7631438",
"0.7622714",
"0.76158476",
"0.7610143",
"0.75819933",
"0.75800306",
"0.75651425",
"0.7556283",
"0.7553741",
"0.7537208",
"0.7529871... | 0.77626204 | 5 |
def fib_sequence(x) fib_array = [0,1] x.times do |i| next_num = fib_array[i] + fib_array[i + 1] end p next_num end RELEASE 2 Define bubble sort method that takes in an argument of an array. | def bubble_sort(arr)
n = arr.length
loop do
swapped = false
(n-1).times do |index|
if arr[index] > arr[index + 1]
# Swap the numbers!
arr[index], arr[index + 1] = arr[index + 1], arr[index]
swapped = true
end
end
# terminates the program if there is no more sorting
break if not swapped
end
arr
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fib(integer)\n\nfib_arr = [0,1]\n#declaring the beginning portion of the fibanocci sequence\nindex = 2\n#starting at two because the array is already filled with the 0 & 1 index's filled \n\tuntil index == integer \n# the integer will be the fib(x) for the sequence\n\tnext_number = fib_arr[-1] + fib_arr[-2]\n#... | [
"0.76285714",
"0.75869274",
"0.75810534",
"0.75707436",
"0.7458206",
"0.74504924",
"0.7392377",
"0.7391701",
"0.7340637",
"0.7311666",
"0.7303054",
"0.73028815",
"0.7294978",
"0.7289428",
"0.7263721",
"0.72547656",
"0.72335154",
"0.7218501",
"0.7215022",
"0.72120565",
"0.7180... | 0.6829867 | 100 |
Recursively sanitizes the response object by cleaning up any hash keys. | def sanitize_response_keys(response)
if response.is_a?(Hash)
response.inject({}) { |result, (key, value)| result[underscorize(key).to_sym] = sanitize_response_keys(value); result }
elsif response.is_a?(Array)
response.collect { |result| sanitize_response_keys(result) }
else
response
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def parse_response(response)\n response = sanitize_response_keys(response.parsed_response)\n end",
"def sanitize_hash(hash)\n Hash[hash.collect { |k, v| [k.to_s, v.is_a?(Hash) ? sanitize_hash(v) : v] }]\n end",
"def _sanitize(thing)\n # This really needs to go into a class\n i... | [
"0.68997335",
"0.675911",
"0.64415854",
"0.6426498",
"0.62050945",
"0.61626333",
"0.6149324",
"0.6136185",
"0.61153275",
"0.6107102",
"0.60848796",
"0.60813075",
"0.60603553",
"0.60082424",
"0.5998525",
"0.5985959",
"0.59666735",
"0.59123755",
"0.5890838",
"0.5877324",
"0.584... | 0.7712029 | 2 |
Return true if any of the columns except 'is_current' has been changed. | def content_changed?
changed? && changes.keys != ['is_current']
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def has_changes_to_versioned_columns?\n !! changed_versioned_columns.detect do |key|\n send(key).is_a?(Paperclip::Attachment) ? \n send(key).is_a?(Paperclip::Attachment) && send(key).dirty? :\n send(key) != latest_version.send(key)\n end\n end",
"def colu... | [
"0.73533124",
"0.71666604",
"0.7098151",
"0.7041998",
"0.7014735",
"0.7014735",
"0.6967089",
"0.69531494",
"0.6951897",
"0.6911813",
"0.68574905",
"0.68135774",
"0.67586786",
"0.6701765",
"0.6683049",
"0.6655878",
"0.6638147",
"0.66280353",
"0.66280353",
"0.662737",
"0.659840... | 0.6682898 | 15 |
Executes SQL UPDATE statement that sets value of 'is_current' attribute to false for a record that is subject to update. If the record has locking column, will support optimistic locking behavior. | def update_current
statement = current_to_false_sql_statement
affected_rows = self.class.connection.update statement
unless affected_rows == 1
raise ActiveRecord::StaleObjectError.new(self, "update_current (version #{current_lock_value})")
end
true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def current_to_false_sql_statement\n klass = self.class\n lock_column_name = klass.locking_column\n lock_value = current_lock_value\n lock_column = if lock_value\n klass.columns.detect { |c| c.name == lock_column_name }\n ... | [
"0.76800597",
"0.62970346",
"0.6022025",
"0.5888504",
"0.57401156",
"0.573709",
"0.5700082",
"0.5670107",
"0.56435215",
"0.55717546",
"0.5564127",
"0.55591506",
"0.55515206",
"0.55414355",
"0.5526511",
"0.5496184",
"0.54920703",
"0.5433103",
"0.54328364",
"0.54197073",
"0.541... | 0.74924916 | 1 |
Set incremental lock_version column. | def set_lock
klass = self.class
lock_column_name = klass.locking_column
if has_attribute?(lock_column_name) && klass.parent_relation_keys.count > 0
criteria = klass.parent_relation_keys.inject({}) do |result, parent_key|
result[parent_key] = read_attribute(parent_key)
result
end
relation = klass.unscoped.where(criteria)
sql = <<-SQL
#{relation.select("COUNT(#{lock_column_name}) AS value, 0 sort_order").to_sql}
UNION
#{relation.select("MAX(#{lock_column_name}) AS value, 1 sort_order").to_sql}
ORDER BY sort_order
SQL
result = klass.connection.execute(sql)
current_count = result[0]["value"]
current_max = result[1]["value"]
lock_value = (current_count.to_s == "0" ? 0 : current_max.to_i + 1)
write_attribute(lock_column_name, lock_value)
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_new_version\n @saving_version = new_record? || save_version?\n self.send(\"#{self.class.version_column}=\", next_version) if new_record? || (!locking_enabled? && save_version?)\n end",
"def set_version\n self.version ||= latest_version + 1\n end",
"def increment_version!\n ... | [
"0.6691245",
"0.6634699",
"0.6225532",
"0.5993993",
"0.5992661",
"0.59622025",
"0.5909327",
"0.5874653",
"0.58727264",
"0.5861644",
"0.58293986",
"0.57956696",
"0.5767324",
"0.5697613",
"0.56973314",
"0.5648239",
"0.56298023",
"0.5621209",
"0.5620335",
"0.560054",
"0.560054",... | 0.61613697 | 3 |
Generate an arel statement to update the 'is_current' state of the record to false. And perform the very same actions AR does for record update, but using only a single 'is_current' column. Note: the more efficient current_to_false_sql_statement method is used instead. This is left in comments "for some future performance miracle from the arel devs" (c Bruce) a.kuzko 20120307 def current_to_false_arel_statement klass = self.class self.is_current = false current_attribute = arel_attributes_values(false, false, ['is_current']) stmt = klass.unscoped.where(klass.arel_table[klass.primary_key].eq(id)).arel.compile_update(current_attribute) self.is_current = true stmt end private :current_to_false_arel_statement Generate SQL statement to be used to update 'is_current' state of record to false. TODO: need to find way to track stale objects | def current_to_false_sql_statement
klass = self.class
lock_column_name = klass.locking_column
lock_value = current_lock_value
lock_column = if lock_value
klass.columns.detect { |c| c.name == lock_column_name }
else
nil
end
quoted_lock_column = klass.connection.quote_column_name(lock_column_name)
"UPDATE #{klass.quoted_table_name} " \
"SET \"is_current\" = #{klass.connection.quote(false)} ".tap do |sql|
sql << "WHERE #{klass.quoted_primary_key} = " \
"#{klass.connection.quote(@_before_to_new_record_values[:id])}"
if lock_value
sql << " AND \"is_current\" = #{klass.connection.quote(true)}"
sql << " AND #{quoted_lock_column} = #{klass.connection.quote(lock_value)}"
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update_current\n statement = current_to_false_sql_statement\n\n affected_rows = self.class.connection.update statement\n\n unless affected_rows == 1\n raise ActiveRecord::StaleObjectError.new(self, \"update_current (version #{current_lock_value})\")\n end\n true\n end",
"de... | [
"0.57348746",
"0.52383906",
"0.521522",
"0.5141795",
"0.51158303",
"0.50699514",
"0.50699514",
"0.504997",
"0.49879053",
"0.4870549",
"0.47581476",
"0.47256857",
"0.47202697",
"0.47077966",
"0.46664375",
"0.4619221",
"0.45960575",
"0.45876902",
"0.45713708",
"0.45473796",
"0.... | 0.7857318 | 0 |
Returns the current value of the locking column if such exists. | def current_lock_value
lock_column_name = self.class.locking_column
has_attribute?(lock_column_name) && read_attribute(lock_column_name).to_i
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def locking_column=(value)\n reload_schema_from_cache\n @locking_column = value.to_s\n end",
"def locking_enabled?\n lock_optimistically && columns_hash[locking_column]\n end",
"def reset_locking_column\n self.locking_column = DEFAULT_LOCKING_COLUMN... | [
"0.7114523",
"0.6210141",
"0.6036617",
"0.60167223",
"0.59769386",
"0.5797968",
"0.57779825",
"0.5690359",
"0.568033",
"0.5675587",
"0.55958647",
"0.5594214",
"0.55842257",
"0.5571328",
"0.555958",
"0.554024",
"0.55356926",
"0.54689395",
"0.54278004",
"0.5421387",
"0.54060864... | 0.84828675 | 0 |
GET /personalinfos GET /personalinfos.json | def index
@member = Member.find(params[:member_id])
@personalinfos = @member.personalinfo
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @personal_info = current_user.personal_info\n \n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @personal_info }\n end\n end",
"def show\n @personal_info = @user.personal_info\n @user = current_user.id\n respond_to do |format|\n f... | [
"0.7770951",
"0.75828725",
"0.7045277",
"0.6972597",
"0.6758435",
"0.6744808",
"0.6722743",
"0.6644888",
"0.6616176",
"0.6590508",
"0.64647394",
"0.64236355",
"0.6406737",
"0.63883483",
"0.63746375",
"0.63508433",
"0.63008094",
"0.6278248",
"0.6278248",
"0.62700856",
"0.62554... | 0.6722496 | 7 |
GET /personalinfos/1 GET /personalinfos/1.json | def show
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @personal_info = current_user.personal_info\n \n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @personal_info }\n end\n end",
"def show\n @personal_info = @user.personal_info\n @user = current_user.id\n respond_to do |format|\n f... | [
"0.7647759",
"0.7573799",
"0.71958756",
"0.7134851",
"0.68704134",
"0.6855913",
"0.67829305",
"0.67747307",
"0.6724584",
"0.67045647",
"0.6664017",
"0.66102916",
"0.6568933",
"0.656376",
"0.65394586",
"0.6536098",
"0.6536098",
"0.65336704",
"0.6488732",
"0.6481798",
"0.647989... | 0.0 | -1 |
POST /personalinfos POST /personalinfos.json | def create
@member = Member.find(params[:member_id])
@personalinfo = @member.build_personalinfo(personalinfo_params)
respond_to do |format|
if @personalinfo.save
format.html { redirect_to new_member_addressinfo_path(@personalinfo.member.id), notice: 'Personalinfo was successfully created.' }
format.json { render :show, status: :created, location: @personalinfo }
else
format.html { render :new }
format.json { render json: @personalinfo.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n @personal_info = current_user.create_personal_info(params[:personal_info])\n\n respond_to do |format|\n if @personal_info.save\n format.html { redirect_to user_path(current_user), notice: 'Personal info was successfully created.' }\n format.json { render json: @personal_info, ... | [
"0.78123856",
"0.77918065",
"0.76201266",
"0.7273967",
"0.7068449",
"0.70216626",
"0.6949753",
"0.69279236",
"0.69243145",
"0.68569905",
"0.68550813",
"0.6845323",
"0.67927575",
"0.6774816",
"0.6758918",
"0.6713087",
"0.669259",
"0.6628675",
"0.66177505",
"0.6519388",
"0.6477... | 0.66491604 | 17 |
PATCH/PUT /personalinfos/1 PATCH/PUT /personalinfos/1.json | def update
respond_to do |format|
if @personalinfo.update(personalinfo_params)
format.html { redirect_to member_path(@personalinfo.member.id), notice: 'Personalinfo was successfully updated.' }
format.json { render :show, status: :ok, location: @personalinfo }
else
format.html { render :edit }
format.json { render json: @personalinfo.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n user = current_user\n @personal_info = user.personal_info\n\n respond_to do |format|\n if @personal_info.update_attributes(params[:personal_info])\n format.html { redirect_to user_path notice: 'Personal info was successfully updated.' }\n format.json { head :no_content }\n ... | [
"0.7263874",
"0.7209412",
"0.6949237",
"0.68924606",
"0.6855842",
"0.68453014",
"0.6843317",
"0.6773483",
"0.6757944",
"0.6700401",
"0.6698878",
"0.6659041",
"0.66468215",
"0.662662",
"0.65574205",
"0.65355617",
"0.652871",
"0.65081936",
"0.6461914",
"0.6461093",
"0.64547646"... | 0.7043875 | 2 |
DELETE /personalinfos/1 DELETE /personalinfos/1.json | def destroy
@personalinfo.destroy
respond_to do |format|
format.html { redirect_to personalinfos_url, notice: 'Personalinfo was successfully destroyed.' }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def destroy\n @personal_info = PersonalInfo.find(params[:id])\n @personal_info.destroy\n\n respond_to do |format|\n format.html { redirect_to personal_info_index_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @personal_info.destroy\n respond_to do |format|\n ... | [
"0.7814514",
"0.7633795",
"0.7631375",
"0.7581686",
"0.7542011",
"0.73786116",
"0.7331477",
"0.72952306",
"0.7205331",
"0.7204629",
"0.716847",
"0.71445185",
"0.71372503",
"0.7065375",
"0.6969769",
"0.694737",
"0.692791",
"0.6920985",
"0.6903395",
"0.68995625",
"0.6891109",
... | 0.7647394 | 1 |
Use callbacks to share common setup or constraints between actions. | def set_personalinfo
@personalinfo = Personalinfo.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.61637366",
"0.60446453",
"0.59452957",
"0.591511",
"0.58885515",
"0.5834122",
"0.57761765",
"0.5702554",
"0.5702554",
"0.5652102",
"0.5619581",
"0.5423898",
"0.5409782",
"0.5409782",
"0.5409782",
"0.5394745",
"0.53780794",
"0.5356209",
"0.5338898",
"0.53381324",
"0.5328622... | 0.0 | -1 |
Never trust parameters from the scary internet, only allow the white list through. | def personalinfo_params
params.require(:personalinfo).permit(:type_human, :first_name, :middle_name, :last_name, :date_of_birth, :gender, :occupation, :member_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.6981606",
"0.6784227",
"0.6746523",
"0.67439264",
"0.67361516",
"0.6593381",
"0.6506166",
"0.64994407",
"0.6483518",
"0.64797056",
"0.64578557",
"0.6441216",
"0.63811713",
"0.63773805",
"0.6366333",
"0.63217646",
"0.6301816",
"0.63009787",
"0.6294436",
"0.62940663",
"0.629... | 0.0 | -1 |
logs in a user | def log_in(user)
session[:user_id] = user.id
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def user_login(user)\n click_log_in\n fill_login_credentials(user)\n end",
"def login_as(user)\n login(users(user).email, users(user).password)\n end",
"def login_user\n puts \"Please enter your name\"\n name = CLI.gets_with_quit\n\n if self.user_exists(name)\n user = self.find... | [
"0.7697493",
"0.76675546",
"0.7649098",
"0.7620769",
"0.7614958",
"0.74613345",
"0.7436238",
"0.7401111",
"0.7373028",
"0.7365022",
"0.7363507",
"0.7354074",
"0.7345722",
"0.7296095",
"0.7292636",
"0.7275673",
"0.7262599",
"0.72514313",
"0.7251138",
"0.7247492",
"0.72441936",... | 0.72444475 | 33 |
remember the user in a persistent session | def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def remember(user)\n user.remember # Calls model\n cookies.permanent.signed[:user_id] = user.id # Save off encryped user ID\n cookies.permanent[:remember_token] = user.remember_token # Save off random thing for validation\n end",
"def remember(user)\n user.remember\n cookies.permanent.signed[:user_id]... | [
"0.82809645",
"0.8137177",
"0.81280243",
"0.80617476",
"0.8020635",
"0.80165845",
"0.80067235",
"0.7936162",
"0.793354",
"0.79323524",
"0.79067636",
"0.7901528",
"0.7890831",
"0.78838766",
"0.7881998",
"0.78768307",
"0.7864675",
"0.78556675",
"0.78460747",
"0.783433",
"0.7828... | 0.784998 | 39 |
forget the user in a persistent session | def forget(user)
user.forget
cookies.delete(:user_id)
cookies.delete(:remember_token)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def abandon!\n @user = nil\n session.delete\n end",
"def abandon!\n @user = nil\n session.delete\n end",
"def abandon!\n @user = nil\n session.clear\n end",
"def forget(user)\n user.forget # Defined in the User model\n cookies.delete(:user_id)\n cookies.delete(... | [
"0.8350896",
"0.8350896",
"0.82848597",
"0.8258429",
"0.82359964",
"0.8234422",
"0.8234422",
"0.81948006",
"0.8194623",
"0.8193569",
"0.8176546",
"0.81672686",
"0.81621695",
"0.8146295",
"0.8146295",
"0.81335187",
"0.8132459",
"0.81298053",
"0.8119014",
"0.8116069",
"0.809656... | 0.8093384 | 46 |
current loggedin user (if any) | def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: session[:user_id])
elsif (user_id = cookies.signed[:user_id])
user = User.find_by(id: user_id)
if user && user.remember_authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def current_user\n @current_user if logged_in?\n end",
"def current_user\n @current_user if logged_in?\n end",
"def current_user\n User.find_by(uid: session[:user]) if logged_in?\n end",
"def current_user\n\t\tif session[:user_id].present?\n\t\t\tUser.find(session[:user_id])\n\t\tend\n\te... | [
"0.8724011",
"0.8724011",
"0.86331534",
"0.8548699",
"0.8536485",
"0.84780073",
"0.8463275",
"0.8457203",
"0.84535307",
"0.84535307",
"0.84518415",
"0.84499156",
"0.84254134",
"0.8420495",
"0.84195614",
"0.8407769",
"0.8407769",
"0.84049785",
"0.84049785",
"0.8404372",
"0.840... | 0.0 | -1 |
bool for whether a user is logged in | def logged_in?
!current_user.nil?
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def user_is_logged_in()\n user = get_user()\n if user != nil\n true\n else\n false\n end\n end",
"def user_is_logged_in?\n !!session[:user_id]\n end",
"def logged_in?()\n if session[:user_id]\n return true\n else \n return false\n end\n end",
"def _is_logi... | [
"0.8988375",
"0.8708727",
"0.8701367",
"0.8671441",
"0.8654738",
"0.8651593",
"0.8641701",
"0.86358374",
"0.86207443",
"0.8605657",
"0.85970926",
"0.85970926",
"0.8591037",
"0.85674655",
"0.8562716",
"0.8561037",
"0.8557666",
"0.855615",
"0.8539053",
"0.85343224",
"0.8527207"... | 0.0 | -1 |
logs out the current user | def log_out
forget(current_user)
session.delete(:user_id)
@current_user = nil
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def log_out\n\t\t# current_user.delete_auth_token # won't work with curl, but html is good\n\t\tsession.delete(:user_id)\n\t\t@current_user = nil\n\tend",
"def log_out\n\t\tsession.delete(:user_id)\n\t\t@current_user = nil\n\tend",
"def log_out\n\t\tsession.delete(:user_id)\n\t\t@current_user = nil\n\tend",
... | [
"0.8813604",
"0.87599903",
"0.87599903",
"0.87599903",
"0.87599903",
"0.87599033",
"0.873035",
"0.873035",
"0.873035",
"0.873035",
"0.873035",
"0.8706984",
"0.86833966",
"0.8673269",
"0.8673269",
"0.8673269",
"0.8673269",
"0.8673269",
"0.8671673",
"0.86581016",
"0.8656662",
... | 0.85478127 | 79 |
Builds a new comment to store in the database Entry: none Exit: none | def new
@page_title = "New Comment"
@comment = current_recipe.comments.build
@btnText = "Add Comment"
@obj = @comment
respond_to do |f|
f.html {render 'shared/form'}
f.js
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def _comment db, id, text\n rowid = db.sql_comments_insert id, text\n puts \"Comment #{rowid} created\"\n handle = db.db\n \n commcount = handle.get_first_value( \"select count(id) from comments where id = #{id};\" )\n commcount = commcount.to_i\n db.sql_update \"bugs\", id, \"comment_count\",... | [
"0.69336593",
"0.69054496",
"0.65887994",
"0.65831333",
"0.6528773",
"0.6528773",
"0.6528773",
"0.648923",
"0.64724624",
"0.6428166",
"0.6413875",
"0.64122766",
"0.64122766",
"0.6381626",
"0.6371964",
"0.63709855",
"0.6370129",
"0.63162017",
"0.62894386",
"0.6270763",
"0.6247... | 0.0 | -1 |
Builds a comment from the allowed page parameters. If save was successful user is directed back to the recipe they were on otherwise the user is allowed to fix errors on the comment page and resubmit Entry: dirty form Exit: form information saved to database | def create
@recipe = Recipe.find(current_recipe)
@comment = current_recipe.comments.build(comment_params)
@comment.user_id = current_user.id
@obj = @comment
if(@comment.save)
#flash.alert = "New Comment"
respond_to do |f|
f.html {redirect_back_or current_recipe}
f.js {@recipe}
end
else
#flash.now.alert = "Error"
respond_to do |f|
f.html {render 'shared/form'}
f.js {@recipe}
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n # Used in notifications.rb Kind of an ugly hack, but it's fast and\n # direct.\n $SITE_DOMAIN = request.domain\n\n @comment = Comment.new(params[:comment])\n @page = Page.find(params[:page])\n @comment.page = @page\n @comment.user = current_user\n @comment.parent_id = params[:p... | [
"0.6631334",
"0.61435574",
"0.6123313",
"0.605439",
"0.60203224",
"0.59070975",
"0.58645296",
"0.5815562",
"0.5753088",
"0.5752929",
"0.5728203",
"0.57150555",
"0.5694536",
"0.5691775",
"0.5690289",
"0.5664736",
"0.5648191",
"0.56403774",
"0.56299675",
"0.5611897",
"0.5605983... | 0.53265715 | 64 |
Finds a users comment from the current recipe to display on view. Entry: :verify_user Exit: none | def edit
@page_title = "Edit Comment"
@comment = current_recipe.comments.find(params[:id])
@btnText = "Update Comment"
@obj = @comment
respond_to do |f|
f.html {render 'shared/form'}
f.js
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def comments(user)\n self.design_review_comments.to_ary.find_all { |comment| comment.user == user }\n end",
"def comments_given(user_id)\n comments = Comment.where(user_id: user_id)\n end",
"def correct_user\n @comment = current_user.comments.find_by_id(params[:id])\n redirect_to root_url if @com... | [
"0.6562741",
"0.64097023",
"0.62885886",
"0.62335277",
"0.621516",
"0.6109357",
"0.60803723",
"0.60791963",
"0.60751253",
"0.60671467",
"0.60597503",
"0.6051002",
"0.60449135",
"0.60204726",
"0.59751713",
"0.5937676",
"0.59156525",
"0.5902229",
"0.59018505",
"0.58982795",
"0.... | 0.0 | -1 |
Updates comment with new page parameters Entry: :verify_user Exit: returns to current_recipe if successful or allows user to fix errors on the form | def update
@recipe = Recipe.find(current_recipe)
@comment = current_recipe.comments.find(params[:id])
@obj = @comment
if(@comment.update(comment_params))
respond_to do |f|
f.html{redirect_back_or current_recipe}
f.js {@recipe}
end
else
respond_to do |f|
f.html {render 'shared/form'}
f.js {@recipe}
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n @comment = Comment.find(params[:id])\n @comment_indent = params[:indent].to_i\n @page = @comment.page\n\n if @comment.user != current_user\n render(:text => \"You can't edit other people's comments\")\n return false\n end\n\n if !@comment.update_attributes(params[:comment])... | [
"0.6968448",
"0.6952601",
"0.6950016",
"0.690668",
"0.68932337",
"0.6659727",
"0.6640084",
"0.6599651",
"0.65932983",
"0.6585444",
"0.65775275",
"0.6555819",
"0.6545293",
"0.6538876",
"0.6521427",
"0.65142745",
"0.64671767",
"0.6458331",
"0.64573306",
"0.64568216",
"0.6451666... | 0.6567239 | 11 |
Deletes a user comment from the current recipe Entry: :verify_user Exit: comment deleted | def destroy
@recipe = Recipe.find(current_recipe)
current_recipe.comments.find(params[:id]).destroy
respond_to do |f|
f.html {redirect_back_or current_recipe}
f.js {@recipe}
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete_comment user\n edit_comment user, nil\n end",
"def correct_user_for_deleting_comment\n\t @comment = Comment.find(params[:id])\n\t @user = @comment.user\n\t redirect_to(login_url) unless current_user?(@user)\n\t end",
"def destroy\n @recipe = find_by_id(Recipe)\n @comment ... | [
"0.78425044",
"0.7295172",
"0.72299635",
"0.7007244",
"0.6960624",
"0.679178",
"0.67395425",
"0.67214006",
"0.66994196",
"0.6698189",
"0.66914123",
"0.66738886",
"0.666968",
"0.6632829",
"0.66251326",
"0.6589697",
"0.6583161",
"0.6574268",
"0.6560811",
"0.6533175",
"0.6525354... | 0.0 | -1 |
Builds a list of all comments Entry: :admin_user Exit: none | def index
@comments = Comment.all
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def comments\n pull_comments\n @comments_list\n end",
"def getComments(list)\r\n comments = \"\"\r\n dbg(\"Kommentarer:\")\r\n list.each { |s| \r\n dbg(\"Kommentar:\")\r\n dbg(s)\r\n dbg(s[\"comment\"])\r\n \tcomments = comments + \"<p>\" + s[\"author_name\"] + \":\" + s[\"comment\"] + \"</p>... | [
"0.6768369",
"0.6609913",
"0.6609913",
"0.6516182",
"0.64522403",
"0.6437734",
"0.629992",
"0.62773734",
"0.6203413",
"0.6156121",
"0.6156121",
"0.61062205",
"0.60528463",
"0.60528463",
"0.60528463",
"0.60528463",
"0.60528463",
"0.60528463",
"0.60503274",
"0.60166943",
"0.599... | 0.0 | -1 |
Allows only permitted parameters to be submitted and used on the pages | def comment_params
params.require(:comment).permit(:text, :user_id, :recipe_id)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def page_params\n params.require(controller_name.singularize).permit(allowed_page_params)\n end",
"def allowed_params\n ALLOWED_PARAMS\n end",
"def page_params\n field_list = [:id, :meta_keywords, :meta_description, :title, :body, :slug, :parent_id, :page_icon, :template_name,\n ... | [
"0.699642",
"0.685767",
"0.6784887",
"0.6760828",
"0.67046195",
"0.6704342",
"0.6665953",
"0.6663356",
"0.6625206",
"0.6585788",
"0.65836716",
"0.6583191",
"0.65644145",
"0.6563764",
"0.6463545",
"0.6449187",
"0.64450943",
"0.6424146",
"0.6392695",
"0.6359527",
"0.634083",
... | 0.0 | -1 |
generate_chamfers generate chamfers to smoothly join rectangle to polygon | def main(argv = [])
# Parameters and keyway path taken from GMS MX keyway project
width = 2.34
height = 8.56
epsilon = 0.1
path = [
[0.00, 0.00],
[0.00, 0.75], [0.65, 0.75],
[1.41, 2.48], [0.00, 2.48],
[0.00, 5.13],
[1.23, 5.65],
[0.11, 6.97],
[0.75, 8.56], [1.67, 8.56],
[1.11, 7.00],
[2.23, 5.70],
[2.23, 5.38],
[0.81, 4.83],
[0.81, 3.29], [2.15, 3.29],
[2.34, 2.86],
[1.45, 0.75], [2.34, 0.75],
[2.34, 0.00]
]
# This is the target polygon from the path
polygon = Polygon.new(path)
# Find closest point to each corner, so we know which wall to ramp towards
idx_bottom_left = polygon.closest_point_index(0, 0)
idx_top_left = polygon.closest_point_index(0, height)
idx_top_right = polygon.closest_point_index(width, height)
idx_bottom_right = polygon.closest_point_index(width, 0)
puts (<<-"end").gsub(/^ /, ''), ''
// OpenSCAD chamfers() module autogenerated by #{File.basename($0)}
// Andrew Ho (andrew@zeuscat.com)
module chamfers(distance) {
// Epsilon value for creating tiny solid segments from 2D shapes
e = #{epsilon};
// Draw polygons at start (rectangle) and end (polygon) area
module start_polygon(points) {
translate([0, 0, -e]) linear_extrude(e) polygon(points);
}
module end_polygon(points) {
translate([0, 0, distance - e]) linear_extrude(e) polygon(points);
}
// Draw starting cube and extruded polygon
translate([0, 0, -e]) cube([#{width}, #{height}, e]);
linear_extrude(distance) polygon(#{polygon.to_openscad});
end
polygon.lines.each_with_index do |line, i|
# Create epsilon-length vector, starting from midpoint, pointing inwards
perpendicular = line.
scale_to_length(epsilon).
translate_to_point(line.midpoint).
rotate(-Math::PI / 2)
# Create tiny epsilon-height triangle for end polygon
end_vertex = perpendicular.p2
end_polygon = Polygon.new(line, end_vertex)
# Create start polygon with edge points at whichever wall we ramp towards
start_polygon = Polygon.new(line.p2, end_vertex, line.p1)
if i >= idx_bottom_left && i < idx_top_left
start_polygon << Point.new(0, line.y1)
start_polygon << Point.new(0, line.y2)
elsif i >= idx_top_left && i < idx_top_right
start_polygon << Point.new(line.x1, height)
start_polygon << Point.new(line.x2, height)
elsif i >= idx_top_right && i < idx_bottom_right
start_polygon << Point.new(width, line.y1)
start_polygon << Point.new(width, line.y2)
elsif i >= idx_bottom_right && i < idx_bottom_left
start_polygon << Point.new(line.x1, 0)
start_polygon << Point.new(line.x2, 0)
end
# Output hull of start and end polygons
puts (<<-"end").gsub(/^ /, '')
hull() {
start_polygon(#{start_polygon.to_openscad});
end_polygon(#{end_polygon.to_openscad});
}
end
end
# Finish off module definition from above
puts '}'
0
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def step_through_iterative_division_maze_generator(grid, state)\n unless state[:finished_init]\n draw_canvas_border(grid)\n state[:finished_init] = true\n end\n new_chamber = divide(grid, state[:current_chamber])\n if new_chamber\n state[:current_chamber] = new_chamber[0]\n state[:todo_chamber].pus... | [
"0.55205214",
"0.55068207",
"0.54450214",
"0.54365456",
"0.54021704",
"0.53797686",
"0.5346563",
"0.53136116",
"0.5304205",
"0.52691805",
"0.5234088",
"0.5221005",
"0.5218455",
"0.5217157",
"0.51682204",
"0.516174",
"0.51439905",
"0.50967395",
"0.5085835",
"0.50732744",
"0.50... | 0.5908446 | 0 |
Intialize Point from Points, Lines, or arrays thereof | def initialize(*points_or_lines)
@points = []
points_or_lines.each { |pol| self << pol }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def to_point\n if length == 2\n p = Point.new(*self)\n elsif length == 1\n p = self[0].clone\n end\n return p\n end",
"def initialize(pts = nil)\n self.points = Array.new\n self.add_points pts if pts\n end",
"def new_point(p)\n case p\n when :infinity\n infi... | [
"0.6947995",
"0.6769942",
"0.67659384",
"0.6754671",
"0.6568431",
"0.6474308",
"0.6469161",
"0.64626306",
"0.6454281",
"0.64035887",
"0.64035887",
"0.63254845",
"0.62674874",
"0.6257671",
"0.6201543",
"0.6194479",
"0.6188412",
"0.6186483",
"0.6146808",
"0.6071829",
"0.6020835... | 0.7265259 | 0 |
Add a Point, a Line, or arrays thereof | def <<(*things)
if things.size == 1
thing = things.first
if thing.is_a?(Point)
@points << thing
elsif thing.is_a?(Line)
@points << thing.p1
@points << thing.p2
elsif thing.is_a?(Array)
if thing.size == 2 && thing.all? { |e| e.numeric? }
@points << Point.new(thing)
else
thing.each { |e| self << e }
end
else
raise 'arguments must be Points or Lines'
end
else
self << things
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_line(point1, point2)\n end",
"def addPoint( x, y) \n point = PVector.new(x, y)\n @points.push(point)\n end",
"def add_point\n end",
"def add_points *args\n last = self.points.length\n args.each do |arg|\n case arg\n when Point then\n self.points << arg\n ... | [
"0.7973499",
"0.7320993",
"0.71098536",
"0.7055932",
"0.6953176",
"0.6931157",
"0.6827463",
"0.68243515",
"0.67933244",
"0.6787729",
"0.6780399",
"0.6671178",
"0.66279453",
"0.6585384",
"0.6583234",
"0.65784127",
"0.6554195",
"0.65141845",
"0.64701265",
"0.6400137",
"0.639127... | 0.7226617 | 2 |
Return the number of edges/corners that make up this polygon | def n
points.size
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def number_of_corners\n @number_of_sides\n end",
"def edge_count(i)\n\t\t__assert_bounds(i)\n\t\treturn __edge_count(i)\n\tend",
"def vertex_count\n count = \"\\0\" * Fiddle::SIZEOF_INT\n FMOD.invoke(:Geometry_GetPolygonNumVertices, @geometry, @index, count)\n count.unpack1('l')\n ... | [
"0.7755111",
"0.7273399",
"0.71048534",
"0.7068884",
"0.69365317",
"0.687939",
"0.68686765",
"0.6637814",
"0.6637814",
"0.65751547",
"0.6574729",
"0.6527122",
"0.64998233",
"0.6494176",
"0.64571625",
"0.6449052",
"0.6431847",
"0.64228487",
"0.6422015",
"0.64143306",
"0.633991... | 0.5955734 | 36 |
A polygon is only valid if it has three or more sides | def valid?
n >= 3
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def check_polygon\n return false if @points.length < 3\n zpoints = Array.new(@points)\n zpoints += [@points[0], @points[1]]\n side_prev = zcrossproduct(zpoints[0], zpoints[1], zpoints[2])\n for i in 1...(zpoints.length-2)\n side_next = zcrossproduct(zpoints[i], zpoints[i+1], zpoints[i+2])\n ... | [
"0.7654151",
"0.749755",
"0.749755",
"0.724318",
"0.70099074",
"0.70077187",
"0.68784904",
"0.67382795",
"0.6719583",
"0.6645518",
"0.6501534",
"0.6492663",
"0.6486807",
"0.6436987",
"0.64116365",
"0.63345355",
"0.62895596",
"0.62895596",
"0.62502885",
"0.6219711",
"0.6171937... | 0.0 | -1 |
Return Lines that make up this Polygon | def lines
raise 'invalid polygon' unless valid?
0.upto(points.size - 1).collect do |i|
Line.new(points[i % n], points[(i + 1) % n])
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def lines\n points.each_cons(2).map {|a,b| Line.new a, b}\n end",
"def lines\n points.each_cons(2).map {|a,b| Line.new a, b}\n end",
"def lines\n @lines[oy...(oy + bordered_height)] || []\n end",
"def create_polylines\n if @itinerary.legs.nil?\n return []\n end\n\n p... | [
"0.7513468",
"0.7513468",
"0.7019755",
"0.6783955",
"0.6601589",
"0.655898",
"0.650469",
"0.62957513",
"0.6266519",
"0.62311196",
"0.6190895",
"0.61332726",
"0.61256385",
"0.60568005",
"0.5979189",
"0.5932594",
"0.58888686",
"0.5878711",
"0.5857343",
"0.5819795",
"0.5812119",... | 0.8187217 | 0 |
Return the Point closest to the other point specified | def closest_point_index(*other)
other = Point.new(*other)
0.upto(n - 1).sort_by { |i| Line.new(points[i], other).length }.first
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def closest_point(pt)\n if pt.is_valid?\n vect = GeoFunctions.point_minus_point(pt, @origin)\n dist = GeoFunctions.vector_dot_product(vect, @z_axis)\n delta = GeoFunctions.vector_times(@z_axis, dist)\n GeoFunctions.point_minus_vector(pt, delta)\n else\n GeoFunctions.invalid_a_point\n... | [
"0.74211687",
"0.73954296",
"0.7339888",
"0.7203119",
"0.70782834",
"0.6998934",
"0.6876892",
"0.6871238",
"0.6840166",
"0.6777215",
"0.67419094",
"0.6697754",
"0.66575855",
"0.6597428",
"0.6550553",
"0.647421",
"0.6448786",
"0.638093",
"0.63712317",
"0.6370403",
"0.6357801",... | 0.7757485 | 0 |
Show (x1, y1) > (x2, y2) > (x3, y3) | def to_s
if points.empty?
'empty'
elsif !valid?
'invalid ' + points.collect { |p| p.to_s }.join(" \u{2192} ")
else
points.collect { |p| p.to_s }.join(" \u{2192} ")
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def\n\t\tprint_point\n\t\tp \"(#{x}, #{y})\"\t\n\tend",
"def coords; {:x => @x, :y => @y} end",
"def coordinates\n \"Xmin:%s Ymin:%s Xmax:%s Ymax:%s\" % [x_min, y_min, x_max, y_max]\n end",
"def position\n [x, y]\n end",
"def coordinates\n [@y_location, @x_location]\n end",
"def points\n ... | [
"0.66279316",
"0.65801245",
"0.65458864",
"0.6545529",
"0.6491197",
"0.6454017",
"0.64284974",
"0.64284974",
"0.6415961",
"0.63864446",
"0.6327091",
"0.6321283",
"0.6315984",
"0.62678844",
"0.62662977",
"0.6230495",
"0.6213453",
"0.61944973",
"0.61934596",
"0.6182059",
"0.618... | 0.0 | -1 |
Show [[x1, y1], [x2, y2], [x3, y3]] | def to_openscad
"[#{points.collect { |p| p.to_openscad }.join(', ')}]"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def to_xy\n [x, y]\n end",
"def coordinates\n [@y_location, @x_location]\n end",
"def coords\n [x, y]\n end",
"def position\n [x, y]\n end",
"def to_xy\n a = self\n a = [a[0].x, a[0].y] if length == 1\n return *a\n end",
"def coords; {:x => @x, :y => @y} end",
"def... | [
"0.6627265",
"0.65192914",
"0.64338017",
"0.63917947",
"0.6312881",
"0.6258574",
"0.62311906",
"0.6224697",
"0.62112737",
"0.6179311",
"0.61680216",
"0.61649907",
"0.6164595",
"0.6164595",
"0.61631584",
"0.6141595",
"0.61084604",
"0.60713863",
"0.6058649",
"0.60539657",
"0.60... | 0.0 | -1 |
Initialize Line from any two things that could be passed to Point.new() | def initialize(p1, p2)
@p1 = Point.new(p1)
@p2 = Point.new(p2)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def initialize(*points_or_lines)\n @points = []\n points_or_lines.each { |pol| self << pol }\n end",
"def add_line(point1, point2)\n end",
"def initialize(point_xy = [0, 0])\n @point_xy = { x: point_xy[0].to_i, y: point_xy[1].to_i }\n chxyattr\n end",
"def initialize(point1, point2)\n @... | [
"0.7621722",
"0.6834808",
"0.67424166",
"0.6720336",
"0.661806",
"0.6489448",
"0.64776087",
"0.6475861",
"0.6441813",
"0.6435152",
"0.6398432",
"0.63957185",
"0.6394531",
"0.63762444",
"0.6364978",
"0.63598317",
"0.63598317",
"0.63598317",
"0.63598317",
"0.63596445",
"0.63550... | 0.6844954 | 1 |
Getters and setters for individual point components | def x1; p1.x; end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def points; end",
"def points #:nodoc:\n [self]\n end",
"def points #:nodoc:\n [self]\n end",
"def add_points_property(points_gained)\n @points = points_gained\n return @points\nend",
"def setpoint\n @setpoint\n end",
"def points\n @obj['points']\n end",
"def posit... | [
"0.6719668",
"0.66539514",
"0.66539514",
"0.65689564",
"0.65168023",
"0.6497323",
"0.64260155",
"0.62856746",
"0.6282739",
"0.6282739",
"0.6282739",
"0.6282739",
"0.62595975",
"0.6258473",
"0.6258473",
"0.614513",
"0.6130891",
"0.6122417",
"0.61192775",
"0.61156",
"0.61077076... | 0.0 | -1 |
Return numeric length of line | def length
Math.sqrt(((x2 - x1) ** 2) + ((y2 - y1) ** 2))
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def length\n @line.length\n end",
"def line_length(line)\n line.chomp.gsub(/\\e\\[[\\d;]*m/, '').length\n end",
"def line_length(line)\n line.chomp.gsub(/\\e\\[[\\d;]*m/, '').length\n end",
"def line_length_for(line_number)\n line_lengths[line_number]\n end",
"def li... | [
"0.8450855",
"0.83423585",
"0.8297245",
"0.80173683",
"0.8014054",
"0.7817645",
"0.7811232",
"0.7684941",
"0.7684941",
"0.76700956",
"0.76673084",
"0.75815225",
"0.75815225",
"0.7572264",
"0.75344723",
"0.75218225",
"0.73835343",
"0.7291208",
"0.7279528",
"0.7279528",
"0.7220... | 0.0 | -1 |
Return new line scaled by factor | def scale(factor)
x = x2 - x1
y = y2 - y1
Line.new(p1, Point.new(x1 + (x * factor), y1 + (y * factor)))
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def line_multiplier(lines, inverse_slope)\n line_length = lines[0].size.to_f\n (lines.size * inverse_slope / line_length).ceil\nend",
"def scale(factor)\n Point.new(self.x * factor, self.y * factor)\n end",
"def sroke_line_width\n y = 250\n 3.times do |i|\n case i\n # when 0 then line_wid... | [
"0.7109462",
"0.6102679",
"0.6087693",
"0.6077677",
"0.6071776",
"0.57910657",
"0.57636076",
"0.5754377",
"0.57438153",
"0.5672732",
"0.5594533",
"0.5586516",
"0.5538638",
"0.55075943",
"0.5487784",
"0.54781735",
"0.5424996",
"0.54051566",
"0.5357622",
"0.53531015",
"0.533577... | 0.7531384 | 0 |
Scale line to particular length | def scale_to_length(new_length)
self.scale(new_length / length)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def scale(factor)\n x = x2 - x1\n y = y2 - y1\n Line.new(p1, Point.new(x1 + (x * factor), y1 + (y * factor)))\n end",
"def line_multiplier(lines, inverse_slope)\n line_length = lines[0].size.to_f\n (lines.size * inverse_slope / line_length).ceil\nend",
"def sroke_line_width\n y = 250\n 3.time... | [
"0.70781296",
"0.6898793",
"0.6889369",
"0.62676847",
"0.6196294",
"0.6187362",
"0.61773044",
"0.59335494",
"0.57123834",
"0.569301",
"0.5671447",
"0.5651155",
"0.5648258",
"0.56159496",
"0.56060416",
"0.5594959",
"0.5579852",
"0.55762345",
"0.55731726",
"0.554592",
"0.551866... | 0.7055107 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.