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 |
|---|---|---|---|---|---|---|
Sets the textType property value. The type of text being stored. Must be one of plain or richText | def text_type=(value)
@text_type = value
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def text_type=(value)\n self.text_type_ord = @@text_type_to_text_type_ord[value]\n end",
"def text_type\n return @text_type\n end",
"def text_type\n @@text_type_ord_to_text_type[self.text_type_ord]\n end",
"def type_is_text\n self.stimulus_type=\"text\"\n end",
... | [
"0.80638033",
"0.6985656",
"0.6818505",
"0.6489027",
"0.6481006",
"0.6481006",
"0.6481006",
"0.6421707",
"0.6261249",
"0.61800843",
"0.6177417",
"0.6177417",
"0.6166765",
"0.6166765",
"0.6156105",
"0.61229956",
"0.61229956",
"0.6041295",
"0.6033856",
"0.6011113",
"0.6009698",... | 0.86104095 | 0 |
characterizes the file_node passed into this service Default options are: save: true | def characterize(save: true)
new_file = original_file.new(file_characterization_attributes.to_h)
@file_node.file_metadata = @file_node.file_metadata.select { |x| x.id != new_file.id } + [new_file]
@persister.save(resource: @file_node) if save
@file_node
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def characterize(save: true)\n persister.save(resource: @file_node) if save\n @file_node\n end",
"def characterize(save: true)\n @file_characterization_attributes = {\n width: image.width.to_s,\n height: image.height.to_s,\n mime_type: image.mime_type,\n checksum: MultiChecksu... | [
"0.8107187",
"0.7465022",
"0.7455418",
"0.70079046",
"0.6842894",
"0.671131",
"0.6691431",
"0.6597271",
"0.6553364",
"0.64761275",
"0.6470805",
"0.632564",
"0.56703",
"0.55973125",
"0.559209",
"0.547178",
"0.54607815",
"0.54607815",
"0.54392534",
"0.5427715",
"0.54066885",
... | 0.7559292 | 1 |
Determines the location of the file on disk for the file_node | def filename
return Pathname.new(file_object.io.path) if file_object.io.respond_to?(:path) && File.exist?(file_object.io.path)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def file_node(path)\n file_info(path).first[0..19]\n end",
"def file_node\n @file_node ||= file_log.lookup_id(@file_id) if @file_id ||= nil\n @file_node ||= changeset.file_node(@path) unless @file_id\n @file_node ||= NULL_ID\n end",
"def file_path\n @file_path... | [
"0.73050326",
"0.718163",
"0.69369686",
"0.68615794",
"0.68384445",
"0.6807996",
"0.67915744",
"0.66372097",
"0.662526",
"0.6600508",
"0.6589917",
"0.64892787",
"0.64842886",
"0.64646447",
"0.64401823",
"0.6430259",
"0.64272034",
"0.6408255",
"0.64053416",
"0.63689214",
"0.63... | 0.5845561 | 81 |
Provides the file attached to the file_node | def file_object
@file_object ||= Valkyrie::StorageAdapter.find_by(id: original_file.file_identifiers[0])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def file\n file_id = @attributes[\"file\"]\n file_node = NodeCache.find(file_id)\n file_node ? file_node.name : nil\n end",
"def file\n @file\n end",
"def file\n @file\n end",
"def file\n @file\n end",
"def file\n @file\n end",
"def file\n @file\n end... | [
"0.7864179",
"0.778853",
"0.778853",
"0.778853",
"0.778853",
"0.77786046",
"0.77315825",
"0.7651197",
"0.7651197",
"0.7518246",
"0.75115186",
"0.7444192",
"0.74193805",
"0.7356936",
"0.73108476",
"0.7172225",
"0.7167996",
"0.71577895",
"0.70562667",
"0.7043463",
"0.704334",
... | 0.0 | -1 |
Extract the basic SPARQL results into a hash of arrays | def parse_json(json)
return nil if json.nil?
h = JSON.parse(json)
data = h['results']['bindings']
{
:headings => h['head']['vars'],
:rows => data.map {|i| i.to_a.map {|x| x[1]['value']}}
}
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def wikidata_rows\n sparql_client = SPARQL::Client.new(\n \"https://query.wikidata.org/sparql\",\n method: :get,\n headers: { 'User-Agent': \"Connor's Random Ruby Scripts Data Fetcher/1.0 (connor.james.shea@gmail.com) Ruby 3.1\" }\n )\n\n # Get the response from the Wikidata query.\n rows = sparql_cli... | [
"0.6852527",
"0.68460184",
"0.6480743",
"0.6252371",
"0.624222",
"0.60889405",
"0.60440075",
"0.6025583",
"0.5962136",
"0.59437436",
"0.59434444",
"0.5936695",
"0.59107465",
"0.5868845",
"0.58679944",
"0.58495873",
"0.58319855",
"0.5831614",
"0.58106416",
"0.58074385",
"0.578... | 0.0 | -1 |
Interfaces that must be implemented | def triples(triple, context = nil) # :yields: triple, context
raise StoreException, "not implemented"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def included_interfaces; end",
"def interface; end",
"def interface; end",
"def extended_interfaces; end",
"def interface_methods; end",
"def implemented_in; end",
"def protocol\n raise NotImplementedError\n end",
"def implementation; end",
"def implementation; end",
"def traits; end",
... | [
"0.82600135",
"0.8143838",
"0.8143838",
"0.8038053",
"0.7853838",
"0.7488654",
"0.7318818",
"0.7283394",
"0.7283394",
"0.727682",
"0.71640635",
"0.703358",
"0.69493926",
"0.68615085",
"0.67514664",
"0.66650367",
"0.66645813",
"0.65585035",
"0.65585035",
"0.65585035",
"0.65585... | 0.0 | -1 |
Default (suboptimal) implemenations of interfaces | def inspect
"#{self.class}[identifier=#{identifier.inspect}]"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def extended_interfaces; end",
"def interface; end",
"def interface; end",
"def included_interfaces; end",
"def interface_methods; end",
"def interface_decls; end",
"def interface; self.class.interface; end",
"def implements()\n return %i[on_collection on_step on_step_end on_phrase on_source]\n e... | [
"0.7450552",
"0.7291269",
"0.7291269",
"0.71681386",
"0.7043405",
"0.6821416",
"0.66647965",
"0.6574899",
"0.6418984",
"0.6350546",
"0.6274553",
"0.6193343",
"0.6142262",
"0.61030334",
"0.60533035",
"0.5992716",
"0.5972564",
"0.5962646",
"0.590624",
"0.5888034",
"0.5863259",
... | 0.0 | -1 |
Bind namespace to store, returns bound namespace | def bind(namespace)
# Over-write an empty prefix
uri = namespace.uri.to_s
@uri_binding[uri] = namespace unless namespace.prefix.to_s.empty?
@uri_binding[uri] ||= namespace
@nsbinding[namespace.prefix.to_s] = namespace
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def namespace=(ns) @namespace = @store.namespace = ns; end",
"def namespace=(ns); end",
"def namespace=(ns); end",
"def namespace(ns)\n if ns == :interpreter\n self\n else\n @storage[ns]\n end\n end",
"def ns(ns)\n self.namespace = ns\n self\n ... | [
"0.75748473",
"0.67924154",
"0.67924154",
"0.6773763",
"0.626833",
"0.61391336",
"0.60608",
"0.6016561",
"0.60015404",
"0.5988713",
"0.59822154",
"0.5964231",
"0.5939458",
"0.5939458",
"0.5933223",
"0.5912131",
"0.590186",
"0.58406216",
"0.5821093",
"0.5765241",
"0.57619566",... | 0.73962915 | 1 |
Get all BNodes with usage count used within graph | def bnodes(context = nil)
bn = {}
triples(Triple.new(nil, nil, nil), context) do |t, ctx|
if t.subject.is_a?(BNode)
bn[t.subject] ||= 0
bn[t.subject] += 1
end
if t.predicate.is_a?(BNode)
bn[t.predicate] ||= 0
bn[t.predicate] += 1
end
if t.object.is_a?(BNode)
bn[t.object] ||= 0
bn[t.object] += 1
end
end
bn
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def bnodes\n @graphs.inject([]) {|memo, g| memo += g.bnodes}\n end",
"def total_count\n object.nodes.size\n end",
"def nodes\n @grpc.node_count\n end",
"def nodes_percent\n (nodes_used.to_f / nodes_avail.to_f) * 100\n end",
"def nodes\n @graph.keys.length\n end",
"... | [
"0.6935106",
"0.6489301",
"0.6385032",
"0.63119847",
"0.62400883",
"0.6238676",
"0.6103131",
"0.6090946",
"0.6086095",
"0.6050516",
"0.5909553",
"0.5909553",
"0.59008396",
"0.5892348",
"0.58889264",
"0.58889264",
"0.58876914",
"0.58811575",
"0.58577216",
"0.58576155",
"0.5855... | 0.61101085 | 6 |
This is the basic run loop | def run
if ldr.read < 70
led.on!
else
led.off!
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def loop\n end",
"def loop\n end",
"def loop\n end",
"def loop; end",
"def run_loop\n end",
"def loop_forever; end",
"def start\n loop do\n run\n end\n end",
"def run\n raise NotImplementedError, 'Generic loop has nothing to do'\n end",
"def run()\n while(true)\n ... | [
"0.8562568",
"0.85275996",
"0.85275996",
"0.8492353",
"0.84090894",
"0.78792995",
"0.76112187",
"0.75437784",
"0.7529084",
"0.74996686",
"0.7450677",
"0.7414697",
"0.7325195",
"0.7316291",
"0.72435015",
"0.7201449",
"0.7172944",
"0.71346426",
"0.7119451",
"0.70555717",
"0.703... | 0.0 | -1 |
Run manifest when in beaker, skip if local | def run_manifest (manifest)
if ENV.has_key? 'LOCAL_TEST'
print 'Notice: Skipping apply_manifest changes, due to local test. Please run puppet apply manually with the manifest above.\n'
else
# with local tests, we can't use beaker function like apply_manifest
let(:manifest) { manifest }
it 'should run without errors' do
expect(apply_manifest(manifest, :catch_failures => true).exit_code).to eq(2)
end
it 'should re-run without changes' do
expect(apply_manifest(manifest, :catch_changes => true).exit_code).to be_zero
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def run\n if !repo_manifest_exists?\n Rails.logger.info \"Creating manifest for #{manifest['name']}\"\n\n create_repo_manifest!\n elsif repo_manifest_changed?\n Rails.logger.info \"Updating manifest for #{manifest['name']}\"\n\n update_repo_manifest!\n else\n Rails.logger.info \"N... | [
"0.61755157",
"0.59666693",
"0.58966637",
"0.5831655",
"0.572444",
"0.5656573",
"0.5608232",
"0.55745554",
"0.5572072",
"0.5567321",
"0.5537589",
"0.55181247",
"0.5496579",
"0.5436343",
"0.5420179",
"0.54004467",
"0.5374038",
"0.5372747",
"0.53539693",
"0.5348446",
"0.5326189... | 0.6647844 | 0 |
GET /api/v1/users/:user_id/ratings optionally GET /api/v1/users/:user_id/ratings?pending | def index
user = User.find_by(id: params[:user_id])
return :ratings => [], :status => :not_found if user.nil?
result = []
# generate pending ratings
if params.has_key?(:pending)
user.rides_as_passenger.each do |ride|
if Rating.find_by(from_user_id: user.id, to_user_id: ride.driver.id, ride_id: ride.id).nil?
pending_rating = {}
pending_rating[:from_user_id] = user.id
pending_rating[:to_user_id] = ride.driver.id
pending_rating[:ride_id] = ride.id
result.append(pending_rating)
end
end
respond_with ratings: result, status: :ok
else
#generate ratings given
ratings = user.ratings_given + user.ratings_received
result = []
ratings.each do |r|
rating = {}
rating[:from_user_id] = r[:from_user_id]
rating[:to_user_id] = r[:to_user_id]
rating[:ride_id] = r[:ride_id]
result.append(rating)
end
respond_with ratings: result, status: :ok
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reports_user_ratings(user_id, rating, start_date, end_date, options)\n options = {\n user: user_id,\n rating: rating,\n start: start_date,\n end: end_date,\n }\n\n get(\"reports/user/ratings\", options)\n end",
"def rate \n @user = User.find_from_param(params[:id])\n if... | [
"0.72761905",
"0.70632446",
"0.70621264",
"0.6862334",
"0.6861646",
"0.68398154",
"0.6802701",
"0.67433923",
"0.67391413",
"0.6738941",
"0.67291087",
"0.6636356",
"0.6628182",
"0.6609422",
"0.65861154",
"0.6426611",
"0.6391706",
"0.6390171",
"0.63349617",
"0.6309685",
"0.6287... | 0.7492 | 0 |
Modify the sku stock with the associated stock level adjustment value | def adjust_sku_stock
if Store.positive?(self.adjustment)
self.stock_total = self.sku.stock + self.adjustment
self.sku.update_column(:stock, self.sku.stock + self.adjustment)
else
self.stock_total = self.sku.stock - self.adjustment.abs
self.sku.update_column(:stock, self.sku.stock - self.adjustment.abs)
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def stock_adjustment\n if Store.positive?(self.adjustment)\n self.stock_total = self.sku.stock_adjustments.first.stock_total + self.adjustment\n self.sku.update_column(:stock, self.sku.stock + self.adjustment)\n else\n self.stock_total = self.sku.stock_adjustments.first.stock_total - self.adju... | [
"0.7473148",
"0.6869709",
"0.6855044",
"0.68399686",
"0.67062116",
"0.6670519",
"0.6647786",
"0.6543969",
"0.64892733",
"0.64395046",
"0.64172536",
"0.63896203",
"0.63650733",
"0.63606936",
"0.6349294",
"0.63287437",
"0.6267883",
"0.6258074",
"0.6255039",
"0.62529385",
"0.615... | 0.7983519 | 0 |
Validation to check whether the adjustment value is above or below zero | def adjustment_value
if self.adjustment == 0
errors.add(:adjustment, "must be greater or less than zero.")
return false
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def values_positive?\n is_ok = self.start_value > 0.0\n \n if is_ok\n self.value_changes.each do |offset, setting|\n setting.value > 0.0\n end\n end\n return is_ok\n end",
"def adjustment\n return 0 unless eligible?\n\n calculation\n end",
"def adjust_towards_zero(... | [
"0.69621474",
"0.69361496",
"0.6866838",
"0.68578917",
"0.67058533",
"0.66879404",
"0.6675955",
"0.66038287",
"0.65772283",
"0.6557495",
"0.6515033",
"0.6460465",
"0.6390238",
"0.6361851",
"0.630908",
"0.63079137",
"0.63025403",
"0.62806976",
"0.62733424",
"0.6250561",
"0.620... | 0.84540373 | 1 |
Send Stock Notifications to users | def send_stock_notifications
SendStockNotificationsJob.perform_later(sku)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def send_notifications\n end",
"def order_notification(user)\n @user = user\n @items = @user.items.out_of_stock\n\n mail :subject => \"Keep these items in Sto.ck\",\n :to => user.email\n end",
"def send_notification\n\n\n end",
"def push(notif)\n\n end",
"def notify_via_service\n u =... | [
"0.73721886",
"0.73449826",
"0.71610636",
"0.6872814",
"0.6637226",
"0.6635139",
"0.66228795",
"0.6585056",
"0.65536994",
"0.6525725",
"0.6491291",
"0.649094",
"0.64850265",
"0.6447033",
"0.6393853",
"0.63435215",
"0.6330944",
"0.63294995",
"0.63139546",
"0.62862146",
"0.6263... | 0.75482106 | 0 |
Sets the current records adjusted_at attribute to the current time and date | def set_current_time_as_adjusted
self.adjusted_at = Time.current
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def set_sighted_at\n\t\tif @sighted_date.present?\n\t\t\tself[:sighted_at] = Time.zone.parse(\"#{@sighted_date} #{@sighted_time}\")\n\t\tend\n\t\tif self[:sighted_at].blank?\n\t\t\tself[:sighted_at] = Time.zone.now\n\t\tend\n\tend",
"def set_updated_at\n if able_to_set_updated_at?\n self.updated_... | [
"0.5992446",
"0.592903",
"0.5926469",
"0.5919316",
"0.5898268",
"0.58564746",
"0.5724203",
"0.57104325",
"0.57076234",
"0.5667148",
"0.56484866",
"0.56414944",
"0.56326264",
"0.56251705",
"0.5622111",
"0.56204075",
"0.5602487",
"0.559619",
"0.5578143",
"0.5569054",
"0.5498085... | 0.8532305 | 0 |
vi: set ft=ruby : | def gen_node_infos(cluster_yml)
master_n = 1
master_mem = cluster_yml['master_mem']
master_cpus = cluster_yml['master_cpus']
slave_n = cluster_yml['slave_n']
slave_mem = cluster_yml['slave_mem']
slave_cpus = cluster_yml['slave_cpus']
master_ipbase = cluster_yml['master_ipbase']
slave_ipbase = cluster_yml['slave_ipbase']
master_infos = (1..master_n).map do |i|
{ :hostname => "master#{i}",
:ip => master_ipbase + "#{10+i}",
:mem => master_mem,
:cpus => master_cpus
}
end
slave_infos = (1..slave_n).map do |i|
{ :hostname => "slave#{i}",
:ip => slave_ipbase + "#{10+i}",
:mem => slave_mem,
:cpus => slave_cpus
}
end
analytics_node = cluster_yml['analytics_node']
analytics_mem = cluster_yml['analytics_mem']
analytics_cpus = cluster_yml['analytics_cpus']
analytics_info = {
:node => analytics_node,
:mem => analytics_mem,
:cpus => analytics_cpus
}
return { :master => master_infos, :slave=>slave_infos, :analytics=>analytics_info }
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def result_of_executing_the_commands\n @commands = \":set ft=ruby\r\" + @commands\n RobotVim::Runner.new.run(:input_file => @input, :commands => @commands)\nend",
"def ruby\n unless @ruby\n @ruby = \"\"\n @body.each_line do |l|\n @commands << {:ruby => l}\n @ruby << l\n ... | [
"0.5803009",
"0.5457295",
"0.544725",
"0.5440447",
"0.540047",
"0.5387971",
"0.53144646",
"0.520739",
"0.5160547",
"0.5159978",
"0.5159782",
"0.5146485",
"0.5083554",
"0.50814515",
"0.5080929",
"0.5077087",
"0.50639117",
"0.50580174",
"0.50580174",
"0.50380445",
"0.50380445",... | 0.0 | -1 |
Makes callable into a object that responds to call. | def get_callable(callable, scope)
return callable if callable.respond_to?(:call)
if callable.kind_of?(Symbol)
callable = camel_case(callable.to_s).to_sym
if scope.constants.include?(callable)
c = scope.const_get(callable)
callable = c if c.is_a?(Class)
end
end
if callable.kind_of?(Class)
callable = callable.new
end
if callable.respond_to?(:call)
callable
else
raise ArgumentError, "Could not resolve #{callable.inspect}. Callable must be an object that responds to #call or a symbol that resolve to such an object or a class with a #call instance method."
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def be_callable!(thing)\n return if thing.respond_to?(:call)\n return if thing.is_a?(Class) && thing.instance_methods.include?(:call)\n raise TypeError, \"Expecting callable but received `#{thing.class.name}`\"\n end",
"def initialize(callable)\n @callable = callable\n fre... | [
"0.6652214",
"0.6414303",
"0.6276644",
"0.6180409",
"0.60772693",
"0.59773386",
"0.59093136",
"0.589361",
"0.5788253",
"0.5759921",
"0.5759921",
"0.5759921",
"0.57502776",
"0.5727496",
"0.57170016",
"0.5691074",
"0.5691074",
"0.5650693",
"0.56310385",
"0.562612",
"0.56204665"... | 0.64326954 | 1 |
Nothing genius adjusted from: | def camel_case(string)
return string if string !~ /_/ && string =~ /[A-Z]+.*/
string.split('_').map{|e| e.capitalize}.join
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def private; end",
"def probers; end",
"def schubert; end",
"def formation; end",
"def terpene; end",
"def suivre; end",
"def anchored; end",
"def verdi; end",
"def malts; end",
"def specie; end",
"def specie; end",
"def specie; end",
"def specie; end",
"def stderrs; end",
"def berlioz;... | [
"0.71673167",
"0.6739261",
"0.6570794",
"0.65537924",
"0.6510832",
"0.6503343",
"0.6432707",
"0.63185513",
"0.6305521",
"0.62823653",
"0.62823653",
"0.62823653",
"0.62823653",
"0.62667",
"0.6221262",
"0.6205922",
"0.61905235",
"0.6160562",
"0.6121183",
"0.60640156",
"0.605690... | 0.0 | -1 |
Accessor for target_path The target_path is the path where the finalizers will put the release | def target_path
Pathname.new(self.config[:target_path])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def target_path\n Pathname.new(config[:target_path])\n end",
"def target_path(target_name)\r\n File.join(package_dir, target_name)\r\n end",
"def path\n File.join(@base, @target)\n end",
"def getPath(target)\n File.expand_path(File.join(File.dirname(__FILE__), target))\nend",
"def ... | [
"0.7139041",
"0.6819336",
"0.65198714",
"0.64403296",
"0.6364296",
"0.63166183",
"0.6269425",
"0.6257797",
"0.6126756",
"0.59940857",
"0.5950934",
"0.5937046",
"0.59180343",
"0.5803461",
"0.5780271",
"0.57573724",
"0.5749508",
"0.5718683",
"0.57175165",
"0.5708649",
"0.568469... | 0.72300655 | 0 |
Accessor for build_path The build_path is a temporary directory where the release will be built | def build_path
Pathname.new(self.config[:build_path])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def build_path\n @build_path ||= Pathname.new(source_dir).join(data['build_path'] || './build').to_s\n end",
"def build_path\n @build_path ||= \"#{@ant_path}/#{@config[:build_name]}\"\n end",
"def build_path\n Pathname.new(config[:build_path])\n end",
"def build_dir\n @build_... | [
"0.84372586",
"0.8229979",
"0.7963283",
"0.77578425",
"0.7565874",
"0.7471925",
"0.7429258",
"0.7429258",
"0.7265769",
"0.71524256",
"0.7131272",
"0.6965351",
"0.6965163",
"0.6897426",
"0.68804795",
"0.6801705",
"0.67536116",
"0.6709585",
"0.6709585",
"0.6575804",
"0.65496135... | 0.79782736 | 2 |
Accessor for source_path The source path is the root of the mockup | def source_path
Pathname.new(self.config[:source_path])
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def source_path\n source[:path]\n end",
"def source_path\n Pathname.new(config[:source_path])\n end",
"def source_path; end",
"def source_path\n File.expand_path source unless source.nil?\n end",
"def source_path(arg=nil)\n set_or_return(\n :source_path,\n a... | [
"0.8344127",
"0.8238438",
"0.78063005",
"0.7785738",
"0.7176389",
"0.71564126",
"0.71483874",
"0.70960146",
"0.70173323",
"0.6965058",
"0.6963628",
"0.69631183",
"0.6955219",
"0.6911176",
"0.6908136",
"0.68852246",
"0.6868716",
"0.6868716",
"0.68481433",
"0.68187237",
"0.6800... | 0.8326357 | 1 |
Get the current SCM object | def scm(force = false)
return @_scm if @_scm && !force
case self.config[:scm]
when :git
@_scm = Release::Scm::Git.new(:path => self.source_path)
else
raise "Unknown SCM #{options[:scm].inspect}"
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def scm\n @defaults[ :scm ] ||= SCM::Git.new\n end",
"def scm\n if(@scm.nil?)\n path = path_to_git\n raise GitTaskError.new(\"We don't appear to be inside of a git repository\") if path.nil?\n @scm = Git.open(path)\n end\n\n @scm\n end",
"def scm(force =... | [
"0.7458993",
"0.6901301",
"0.67117935",
"0.65891117",
"0.65846723",
"0.653226",
"0.6157386",
"0.6155567",
"0.61297804",
"0.60138744",
"0.59655905",
"0.58169913",
"0.5761971",
"0.5724984",
"0.5682817",
"0.5640998",
"0.55145156",
"0.5508112",
"0.5503778",
"0.5501113",
"0.549963... | 0.6887394 | 2 |
Use a certain preprocessor | def use(processor, options = {})
@stack << [self.class.get_callable(processor, HtmlMockup::Release::Processors), options]
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def preprocess(text, defines={})\n defines = defines.dup\n result = []\n active_stack = []\n active = true\n text.each_line do |line|\n case line\n when /^#\\s*define\\s+(\\w+)\\s+(\\w*)\\s*$/\n defines[$1] = $2 if active\n when /^#\\s*if\\s+(\\w+)\\s*$/\n active_stack.p... | [
"0.63092464",
"0.6140463",
"0.60429186",
"0.60429186",
"0.5984884",
"0.5687321",
"0.5481028",
"0.54745466",
"0.54678714",
"0.54376733",
"0.5428714",
"0.53935945",
"0.5370338",
"0.53387177",
"0.5323118",
"0.52336496",
"0.5167644",
"0.51615936",
"0.5161245",
"0.5158813",
"0.508... | 0.0 | -1 |
Write out the whole release into a directory, zip file or anything you can imagine finalize can be called multiple times, it just will run all of them. The default finalizer is :dir | def finalize(finalizer, options = {})
@finalizers << [self.class.get_callable(finalizer, HtmlMockup::Release::Finalizers), options]
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def write()\n entries = Dir.entries(@inputDir); entries.delete(\".\"); entries.delete(\"..\"); entries.delete(\"yamproject.json\"); entries.delete(\".DS_Store\")\n io = Zip::File.open(@outputFile, Zip::File::CREATE);\n writeEntries(entries, \"\", io)\n io.close();\n end",
"def write\n FileUtils.r... | [
"0.66611975",
"0.63739157",
"0.6354527",
"0.63402337",
"0.63046813",
"0.63046813",
"0.6294696",
"0.6264766",
"0.6196943",
"0.61841553",
"0.6175773",
"0.6059485",
"0.6002328",
"0.59890497",
"0.58571506",
"0.584809",
"0.5838678",
"0.58094",
"0.5797564",
"0.5765324",
"0.5765186"... | 0.5361912 | 69 |
Files to clean up in the build directory just before finalization happens | def cleanup(pattern)
@stack << Cleaner.new(pattern)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def cleanup\n remove_files(TEST_INPUT_DIR)\n remove_files(TEST_OUTPUT_DIR)\nend",
"def clean\n #rm_r(srcdir)\n rm_r(blddir)\n #rm_r(libdir)\n end",
"def cleanup(build_dir)\n build_dir = Pathname(build_dir)\n tmp_build_dir = Pathname('.temp-build')\n\n # copy over files we need to keep\n ... | [
"0.74821997",
"0.73111963",
"0.73092467",
"0.7293423",
"0.72630394",
"0.7204535",
"0.7179331",
"0.71490556",
"0.71440876",
"0.7125522",
"0.7108553",
"0.7068123",
"0.7068123",
"0.703793",
"0.703793",
"0.7036852",
"0.7023799",
"0.7000978",
"0.6981148",
"0.68912953",
"0.6888974"... | 0.0 | -1 |
Generates a banner if a block is given, or returns the currently set banner. It automatically takes care of adding comment marks around the banner. The default banner looks like this: ======================= = Version : v1.0.0 = = Date : 20120620 = ======================= | def banner(options = {}, &block)
options = {
:comment => :js
}.update(options)
if block_given?
@_banner = yield.to_s
elsif !@_banner
banner = []
banner << "Version : #{self.scm.version}"
banner << "Date : #{self.scm.date.strftime("%Y-%m-%d")}"
size = banner.inject(0){|mem,b| b.size > mem ? b.size : mem }
banner.map!{|b| "= #{b.ljust(size)} =" }
div = "=" * banner.first.size
banner.unshift(div)
banner << div
@_banner = banner.join("\n")
end
if options[:comment]
self.comment(@_banner, :style => options[:comment])
else
@_banner
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def banner(options = {}, &_block)\n options = {\n comment: :js\n }.update(options)\n\n if block_given?\n @_banner = yield.to_s\n elsif !@_banner\n @_banner = default_banner.join(\"\\n\")\n end\n\n if options[:comment]\n comment(@_banner, style: options[:com... | [
"0.7764316",
"0.7029551",
"0.69917434",
"0.68789756",
"0.6870191",
"0.6870191",
"0.6573407",
"0.656541",
"0.65457445",
"0.63539004",
"0.6275968",
"0.6257269",
"0.6248917",
"0.62445074",
"0.62316394",
"0.6217306",
"0.62162584",
"0.6207513",
"0.6180822",
"0.60489756",
"0.603077... | 0.7815564 | 0 |
Extract the mockup, this will happen anyway, and will always happen first This method gives you a way to pass options to the extractor. | def extract(options = {})
self.warn(self, "Don't use the extractor anymore, use release.use(:mockup, options) and release.use(:url_relativizer, options) processors")
@extractor_options = options
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def extract( options )\n \n end",
"def extractable_options?; true end",
"def extractable_options?; end",
"def extractor\n @extractor ||= self.respond_to?(:extract) ? self : instantiate(self.class.get_extractor)\n end",
"def extract\n source = self.options.fetch(:source, nil)\n ... | [
"0.7113444",
"0.6102033",
"0.5998116",
"0.58821005",
"0.57242876",
"0.57213783",
"0.5571385",
"0.5556986",
"0.55088884",
"0.54472",
"0.54472",
"0.54383665",
"0.5374096",
"0.5367344",
"0.535354",
"0.53401935",
"0.53369206",
"0.5314586",
"0.5248584",
"0.5248584",
"0.5239394",
... | 0.76932997 | 0 |
Actually perform the release | def run!
# Validate paths
validate_paths!
# Extract mockup
copy_source_path_to_build_path!
validate_stack!
# Run stack
run_stack!
# Run finalizers
run_finalizers!
# Cleanup
cleanup! if self.config[:cleanup_build]
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def release\n end",
"def release\n end",
"def release\n end",
"def release(resource); end",
"def release!\n @ec.release_temp self\n end",
"def release\n locked? && release!\n end",
"def release\n # @invObj.releaseObj(self)\n end",
"def release(number)\n ... | [
"0.8604901",
"0.85713875",
"0.85713875",
"0.81487435",
"0.7855286",
"0.7627473",
"0.7470292",
"0.744611",
"0.7424807",
"0.7247099",
"0.7226407",
"0.72063375",
"0.72024286",
"0.72024286",
"0.72024286",
"0.72024286",
"0.7184828",
"0.71420467",
"0.71230716",
"0.71191806",
"0.709... | 0.0 | -1 |
Write out a log message | def log(part, msg, verbose = false, &block)
if !verbose || verbose && self.project.options[:verbose]
self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + msg.to_s, nil, true
end
if block_given?
begin
self.project.shell.padding = self.project.shell.padding + 1
yield
ensure
self.project.shell.padding = self.project.shell.padding - 1
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def log_write(msg)\n puts msg\n end",
"def write(msg)\n @logger.info msg\n end",
"def log(msg)\n @logger.write(msg) if @logger\n end",
"def write( message )\n\t\t\tApache.request.server.log_debug( message )\n\t\tend",
"def output_to_file message\n @log_file.puts message\n @log... | [
"0.8347941",
"0.8039214",
"0.78621197",
"0.7694358",
"0.76305073",
"0.76109576",
"0.7555628",
"0.74665546",
"0.74613136",
"0.7431343",
"0.7384371",
"0.7380255",
"0.7376845",
"0.7352448",
"0.7335113",
"0.73316646",
"0.7303281",
"0.72944635",
"0.7233944",
"0.7220944",
"0.716435... | 0.0 | -1 |
Write out a warning message | def warn(part, msg)
self.project.shell.say "\033[37m#{part.class.to_s}\033[0m" + " : " + "\033[31m#{msg.to_s}\033[0m", nil, true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def warning(msg) $stderr.puts(\"Warning: #{msg}\") end",
"def warning(msg) $stderr.puts(\"Warning: #{msg}\") end",
"def warning(msg) $stderr.puts(\"Warning: #{msg}\") end",
"def warning(message)\n write_message message, 'warning'\n end",
"def warn( msg )\n @stringio.puts msg\n end",
"... | [
"0.809428",
"0.809428",
"0.809428",
"0.8082665",
"0.7972393",
"0.7898887",
"0.78845495",
"0.7679932",
"0.7566553",
"0.7543718",
"0.7543718",
"0.75200576",
"0.75190127",
"0.75190127",
"0.74892706",
"0.74851817",
"0.7484032",
"0.7484032",
"0.74754834",
"0.7429984",
"0.74194634"... | 0.69162565 | 59 |
============== = The runway = ============== Checks if build path exists (and cleans it up) Checks if target path exists (if not, creates it) | def validate_paths!
if self.build_path.exist?
log self, "Cleaning up previous build \"#{self.build_path}\""
rm_rf(self.build_path)
end
if !self.target_path.exist?
log self, "Creating target path \"#{self.target_path}\""
mkdir self.target_path
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def validate_paths!\n ensure_clean_build_path!\n ensure_existing_target_path!\n end",
"def run!\n begin\n found = Project.find(@dir)\n rescue MissingProject\n ask_questions!\n make_directories!\n create_config!\n copy_sources!\n say... | [
"0.6355052",
"0.61925346",
"0.61658",
"0.61321163",
"0.59300494",
"0.5910512",
"0.5828241",
"0.58250076",
"0.5792434",
"0.5781954",
"0.57324976",
"0.5732147",
"0.57173246",
"0.56891644",
"0.5680433",
"0.567948",
"0.5657562",
"0.5652249",
"0.5642904",
"0.56353575",
"0.5631985"... | 0.6942448 | 0 |
Checks if deprecated extractor options have been set Checks if the mockup will be runned | def validate_stack!
mockup_options = {}
relativizer_options = {}
run_relativizer = true
if @extractor_options
mockup_options = {:env => @extractor_options[:env]}
relativizer_options = {:url_attributes => @extractor_options[:url_attributes]}
run_relativizer = @extractor_options[:url_relativize]
end
unless @stack.find{|(processor, options)| processor.class == HtmlMockup::Release::Processors::Mockup }
@stack.unshift([HtmlMockup::Release::Processors::UrlRelativizer.new, relativizer_options])
@stack.unshift([HtmlMockup::Release::Processors::Mockup.new, mockup_options])
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def completely_deprecated?\n @deprecated == :completely\n end",
"def deprecated?\n false\n end",
"def handle_deprecations\n DEPRECATED_KEYS.each do |old, new|\n next unless @options.key?(old)\n\n lock_config.errors[old] = \"is deprecated, use `#{new}: #{@options[old]}` ... | [
"0.64725137",
"0.639803",
"0.6256996",
"0.6133459",
"0.611401",
"0.60982275",
"0.609574",
"0.594715",
"0.58884084",
"0.5883327",
"0.58587366",
"0.58298916",
"0.58122057",
"0.58122057",
"0.58122057",
"0.58122057",
"0.58122057",
"0.58122057",
"0.58122057",
"0.58122057",
"0.5812... | 0.0 | -1 |
this updates all apt packages (especially important for VirtualBox guest addition packages) | def apt_update(vm)
vm.provision "shell", inline: <<-SHELL
if [ ! -f /root/apt.updated ]; then
apt-get -y update
apt-get -y purge exim4-* libcairo*
apt-get -y autoremove
#apt-get -y upgrade
#apt-get -y dist-upgrade
apt-get -y install htop tree vim aufs-tools screen curl
touch /root/apt.updated
fi
SHELL
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def apt_get_update_install\n @app.packages.present? ? install_additional_packages : update_apt\n end",
"def update_apt\n <<~APT\n # Update apt-get\n RUN DEBIAN_FRONTEND=noninteractive apt-get update\n APT\n end",
"def apt_update(vm)\n vm.provision \"shell\", inline: <<-SHELL\n if [ ! -... | [
"0.80300665",
"0.78911865",
"0.77964854",
"0.77872586",
"0.7715876",
"0.75927037",
"0.7523143",
"0.74980706",
"0.73292875",
"0.7247528",
"0.72381437",
"0.7022791",
"0.69741076",
"0.6876511",
"0.67898434",
"0.6748026",
"0.6708542",
"0.66960686",
"0.667151",
"0.65571916",
"0.65... | 0.80115056 | 1 |
basic/recommended configuration of every machine: | def basic_config(vm)
hosts = NODES.map { |hostname, array| "#{array[0]} #{hostname}" }.join("\n")
bashrc="/home/vagrant/.bashrc"
vm.provision "shell", inline: <<-SHELL
if ! grep -q "git-core" #{bashrc} ; then
echo "customizing ~/bashrc"
echo "\n\n# Customizations from Vagrantfile:" >> #{bashrc}
echo "export PS1='\\[\\033[31;1m\\]\\h\\[\\033[0;32m\\] \\w\\[\\033[00m\\]: '" >> #{bashrc}
echo export PATH="\$PATH:/usr/lib/git-core:/home/vagrant/teleport/build" >> #{bashrc}
echo export GREP_OPTIONS="--color=auto" >> #{bashrc}
echo "alias ll='ls -lh'" >> #{bashrc}
echo "alias tsh='tsh --insecure'" >> #{bashrc}
fi
if ! grep -q "Teleport" /etc/hosts ; then
echo "# Teleport entries added by Vagrant:" >> /etc/hosts
echo -e "#{hosts}" >> /etc/hosts
fi
mkdir -p /var/lib/teleport
chown vagrant:vagrant /var/lib/teleport
SHELL
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def configure\n @environment = facts.fetch(\"chef_environment\"){\"development\"}.downcase\n @fqdn = facts.fetch(\"fqdn\"){\"\"}\n @app_names = facts.fetch(\"trebuchet\"){[]}\n end",
"def setup_defaults()\n {\n 'box' => {\n 'memory' => '2048',\n 'cpus' => '2'\n }\n }\... | [
"0.65542275",
"0.6343865",
"0.6261492",
"0.6190671",
"0.61846995",
"0.61779124",
"0.61644",
"0.61380833",
"0.6134117",
"0.6116369",
"0.6109565",
"0.60672516",
"0.60548383",
"0.60488087",
"0.6016297",
"0.60157365",
"0.5986861",
"0.59864205",
"0.59624565",
"0.59523165",
"0.5948... | 0.57209504 | 42 |
recreates clean ~/.ssh on a VM, populated with your (host) ssh credentials | def configure_ssh(vm)
vm.provision "shell", inline: <<-SHELL
mkdir -p /home/vagrant/.ssh
rm -rf /home/vagrant/.ssh/id_rsa*
chown vagrant:vagrant /home/vagrant/.ssh
SHELL
vm.provision "file", source: '~/.ssh/id_rsa', destination: '~/.ssh/id_rsa'
vm.provision "file", source: '~/.ssh/id_rsa.pub', destination: '~/.ssh/id_rsa.pub'
vm.provision "file", source: '~/.ssh/id_rsa.pub', destination: '~/.ssh/authorized_keys'
vm.provision "file", source: '~/.screenrc', destination: '~/' if File.exists? "~/.screnrc"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def configure_ssh(vm)\n vm.provision \"shell\", inline: <<-SHELL\n mkdir -p /home/vagrant/.ssh\n rm -rf /home/vagrant/.ssh/id_rsa*\n chown vagrant:vagrant /home/vagrant/.ssh\n SHELL\n vm.provision \"file\", source: '~/.ssh/id_rsa', destination: '~/.ssh/id_rsa'\n vm.provision \"file\", source: '~/.ssh/... | [
"0.75587314",
"0.7197087",
"0.6847204",
"0.6667514",
"0.6529258",
"0.64398086",
"0.64337",
"0.6367353",
"0.63625145",
"0.6337364",
"0.6336996",
"0.6335988",
"0.63244736",
"0.62040335",
"0.61573225",
"0.6138676",
"0.6138652",
"0.6117534",
"0.60967374",
"0.60480905",
"0.5992762... | 0.76308215 | 0 |
load the permissions for the current user so that UI can be manipulated | def load_permissions
@current_permissions = current_user.role.permissions.collect{|i| [i.subject_class, i.action]}
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def load_permissions \n @current_permissions = current_user.role.permissions.collect{|i| [i.subject_class, i.action]} \n end",
"def load_permissions\n @current_permissions = current_user.role.permissions.collect{|i| [i.subject_class, i.action]}\n end",
"def load_permissions_from_user\n # u... | [
"0.7986126",
"0.7956271",
"0.72594357",
"0.72403467",
"0.70867306",
"0.6945131",
"0.69420344",
"0.68161803",
"0.67439914",
"0.6737609",
"0.66819453",
"0.66763777",
"0.6664336",
"0.6587977",
"0.6502031",
"0.6396591",
"0.63898",
"0.634672",
"0.63350534",
"0.63145965",
"0.628678... | 0.8057048 | 0 |
gem 'devise' and active_job | def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def devise_modules_hook!; end",
"def user_authentication\n end",
"def auth_browserid(package_dir)\n replace('Gemfile',\n \"gem 'devise'\",\n \"gem 'devise'\\ngem 'devise_browserid_authenticatable'\")\n \n Bundler.with_clean_env do\n system \"bundle install\"\n end\n system \"rails g auth_browser... | [
"0.5648677",
"0.5483095",
"0.54725605",
"0.54268223",
"0.54268223",
"0.52898604",
"0.5030131",
"0.5013897",
"0.4984747",
"0.4964818",
"0.4918824",
"0.49144354",
"0.4870938",
"0.48561317",
"0.48491225",
"0.482679",
"0.48231494",
"0.4804508",
"0.48041457",
"0.47902527",
"0.4787... | 0.0 | -1 |
Internally, Ruby converts your array objects each into a hash (identifier, not object), using hash. By default this is object_id.hash, which is no longer appropriate. The purpose is to recognize which objects have the same hash and which do not, thus they are unique. So, override. | def hash
custom_unique_id.hash
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def hash\n [self.class, id].hash\n end",
"def hash\n\t\t[@id].hash\n\tend",
"def hash\n object_id\n end",
"def dup\n\n # duplicate self\n rta = super\n\n # iterate through array and dup each hash\n rta.each_with_index do |w_hash, index|\n\n # dup the hash at this index\n rta... | [
"0.70497733",
"0.69877523",
"0.6933186",
"0.6661266",
"0.6613222",
"0.6603962",
"0.6597916",
"0.6593305",
"0.6574119",
"0.65711695",
"0.65628237",
"0.65628237",
"0.6532289",
"0.6515633",
"0.65152043",
"0.65152043",
"0.65152043",
"0.65152043",
"0.65152043",
"0.65152043",
"0.65... | 0.6587536 | 8 |
Instance attributes and methods For Rails Admin, see user.rb: | def name
return "New Firmware" if !id
version + " (" + description.to_s + ") " +
" (" + (for_external ? "internal" : "external") + ")"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def admin\n @attributes[:admin]\n end",
"def admin_name\n self.user.name\n end",
"def user\n {user_id: self.object.user.id,\n user_name: self.object.user.name\n }\n end",
"def user\n @user\n end",
"def user\n @user\n end",
"def user\n @user\n ... | [
"0.69626564",
"0.68878126",
"0.6860858",
"0.68414104",
"0.6830569",
"0.6830569",
"0.6830569",
"0.6687014",
"0.6664593",
"0.6610741",
"0.6594102",
"0.65858823",
"0.65610576",
"0.6547457",
"0.653645",
"0.65302646",
"0.6507274",
"0.6477505",
"0.6477505",
"0.647446",
"0.6472262",... | 0.0 | -1 |
Return an array that contains the squares of all elements in an array? | def square_array(some_array)
array_squared = []
some_array.each do |item|
array_squared << item*item
end
return array_squared
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def compute_squares(array)\n arrayFinal = []\n array.each do |element|\n arrayFinal << element * element\n end\n return arrayFinal\nend",
"def square_array(array)\n squared = []\n array.each { |element| squared << element ** 2 }\n squared\nend",
"def square_array(array)\narray.map { |to_s... | [
"0.82418805",
"0.8215701",
"0.8057785",
"0.797745",
"0.7895184",
"0.78538835",
"0.78530765",
"0.77967167",
"0.7790575",
"0.7776725",
"0.77740264",
"0.77727866",
"0.7750432",
"0.77500796",
"0.7744982",
"0.7742994",
"0.77365494",
"0.77351207",
"0.7729818",
"0.7698281",
"0.76717... | 0.7542296 | 32 |
GET /posts GET /posts.json | def index
@without_magazine = Post.without_magazine
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @posts = Post.find(params[:id])\n render json: @posts\n end",
"def index\n @posts = Post.all\n render json: @posts\n end",
"def index\n @posts = Post.all\n\n render json: @posts\n end",
"def index\n @posts = Post.all\n\n render json: @posts\n end",
"def index\n ... | [
"0.7865315",
"0.7494904",
"0.7494433",
"0.7494433",
"0.7488696",
"0.74314564",
"0.728645",
"0.728645",
"0.728645",
"0.72562826",
"0.72522277",
"0.7247287",
"0.7246305",
"0.72221965",
"0.72042215",
"0.72039723",
"0.7169929",
"0.71689725",
"0.71644753",
"0.7121855",
"0.71152896... | 0.0 | -1 |
GET /posts/1 GET /posts/1.json | def show
if params[:short_url]
@post = Post.find_by_short_url(params[:short_url])
else
@post = Post.find(params[:id])
end
raise NotFound unless @post
@articles_side_bar = Post.article_side_bar(@post)
@shop_side_bar = Product.shop_side_bar
respond_to do |format|
format.html # show.html.erb
format.json { render json: @post }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def show\n @posts = Post.find(params[:id])\n render json: @posts\n end",
"def show\n render json: Post.find(params[\"id\"])\n end",
"def show\r\n post = Post.find(params[:id])\r\n render json: post\r\n end",
"def show\n @post = Post.find(params[:id])\n\n render json: @post\n end",
... | [
"0.77110183",
"0.73537844",
"0.73433185",
"0.73379177",
"0.73228735",
"0.7293139",
"0.7275997",
"0.7256934",
"0.7161576",
"0.7158913",
"0.71552676",
"0.71552676",
"0.7119547",
"0.7094749",
"0.7094749",
"0.7094749",
"0.70943594",
"0.7071599",
"0.70607626",
"0.70452625",
"0.703... | 0.0 | -1 |
GET /posts/new GET /posts/new.json | def new
@post = Post.new
respond_to do |format|
format.html { render layout: "editor" }
format.json { render json: @post }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def new\n \n @post = Post.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render :json => @post }\n end\n end",
"def new\n @post = Post.new\n \n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @post }\n end\... | [
"0.8041972",
"0.8015645",
"0.79855055",
"0.7931354",
"0.7921413",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
"0.79208016",
... | 0.0 | -1 |
POST /posts POST /posts.json | def create
@post = Post.new(params[:post])
respond_to do |format|
if @post.save
format.html { redirect_to magazine_post_path(@post.short_url), notice: 'Post was successfully created.' }
format.json { render json: @post, status: :created, location: @post }
else
format.html { render action: "new", layout: "editor" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def create\n render json: Post.create(params[\"post\"])\n end",
"def create\n respond_with Post.create(params[:posts])\n end",
"def create\n @post = Post.create(post_params)\n render json: @post, serializer: PostSerializer\n end",
"def create\n @post = Post.new(post_params)\n @po... | [
"0.74463975",
"0.73221767",
"0.73072433",
"0.7123966",
"0.7015686",
"0.701327",
"0.69841874",
"0.6939327",
"0.69313824",
"0.69053805",
"0.68196476",
"0.6812792",
"0.6793222",
"0.6792862",
"0.6779654",
"0.6779654",
"0.67625546",
"0.67602354",
"0.67515427",
"0.6735786",
"0.6698... | 0.0 | -1 |
PUT /posts/1 PUT /posts/1.json | def update
@post = Post.find(params[:id])
respond_to do |format|
if @post.update_attributes(params[:post])
format.html { redirect_to magazine_post_path(@post.short_url), notice: 'Post was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit", layout: "editor" }
format.json { render json: @post.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n render json: Post.update(params[\"id\"], params[\"post\"])\n end",
"def update\n respond_with Post.update(params[:id], params[:posts])\n end",
"def update\n respond_with post.update(params[:id], params[:post])\n end",
"def update\n title = params[:title]\n body ... | [
"0.7308219",
"0.7123652",
"0.68159384",
"0.66432106",
"0.66181636",
"0.6607148",
"0.6583982",
"0.6564183",
"0.6552021",
"0.6532697",
"0.6511846",
"0.64877653",
"0.6446283",
"0.64321554",
"0.64155626",
"0.638547",
"0.63833165",
"0.63661736",
"0.63641906",
"0.6363359",
"0.63632... | 0.6026328 | 83 |
DELETE /posts/1 DELETE /posts/1.json | def destroy
@post = Post.find(params[:id])
@post.destroy
respond_to do |format|
format.html { redirect_to "/magazine" }
format.json { head :no_content }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def delete\n render json: Post.delete(params[\"id\"])\n end",
"def destroy\n @post.destroy\n respond_to do |format|\n format.json { head :no_content }\n end\n end",
"def destroy\n post = Post.find(params[:id])\n if post.destroy\n render json: {status: \"success\", data: {id: param... | [
"0.8046884",
"0.76902676",
"0.7583626",
"0.75803024",
"0.7568048",
"0.75047046",
"0.75031126",
"0.74750155",
"0.74671036",
"0.74650854",
"0.746482",
"0.74589694",
"0.74589694",
"0.74589694",
"0.74589694",
"0.74579465",
"0.74579465",
"0.74579465",
"0.74579465",
"0.74579465",
"... | 0.0 | -1 |
POST /users POST /users.json | def create
@user = User.find_by_external_id(user_params[:external_id])
if @user.nil?
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.json { render json: {user: @user}, status: 200 }
else
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
else
respond_to do |format|
format.json { render json: {user: @user}, status: 200 }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def post_users(users)\n self.class.post('https://api.yesgraph.com/v0/users', {\n :body => users.to_json,\n :headers => @options,\n })\n end",
"def CreateUser params = {}\n \n APICall(path: 'users.json',method: 'POST',payload: params.to_json)\n \n end",
"def post b... | [
"0.77179813",
"0.75206673",
"0.73831296",
"0.72405374",
"0.719841",
"0.7140812",
"0.71038526",
"0.7058827",
"0.7041636",
"0.70236504",
"0.7003128",
"0.70021695",
"0.70021695",
"0.70021695",
"0.69936967",
"0.6990463",
"0.6980393",
"0.6979075",
"0.69788617",
"0.69788617",
"0.69... | 0.0 | -1 |
Use callbacks to share common setup or constraints between actions. | def set_user
@user = User.find_by_external_id(params[:id])
@user = User.create!(name: params[:name], email: params[:email], external_id: params[:external_id]) unless @user
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.6164095",
"0.6046031",
"0.5945298",
"0.59179014",
"0.58890367",
"0.58341795",
"0.5776118",
"0.5700777",
"0.5700777",
"0.5656277",
"0.56218207",
"0.5423995",
"0.5411516",
"0.5411516",
"0.5411516",
"0.5395004",
"0.53783494",
"0.53593004",
"0.53412604",
"0.534078",
"0.5332865... | 0.0 | -1 |
Never trust parameters from the scary internet, only allow the white list through. | def user_params
params.require(:user).permit(:name, :email, :external_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 |
Fetch a row or rows from the cursor. [direction] A string specifying which row or rows to fetch. See the postgres documentation for the "DECLARE" statement. NEXT PRIOR FIRST LAST ABSOLUTE count RELATIVE count count ALL FORWARD FORWARD count FORWARD ALL BACKWARD BACKWARD count BACKWARD ALL | def fetch(direction = 'NEXT')
@select.fetch_by_cursor(@name, direction, @connection)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fetch(cursor: -1, count: 50, **options)\n cursor, count = cursor.to_i, count.to_i\n window = count + 2 # Fetch extra two elements for concrete next/prev links\n\n if cursor >= 0\n page = @scope.where(@cursor_key => -Float::INFINITY..cursor).limit(window)\n else\n cursor = curs... | [
"0.5511997",
"0.5464936",
"0.5221982",
"0.51928717",
"0.51586896",
"0.5156962",
"0.5111007",
"0.51108",
"0.50792515",
"0.5015464",
"0.50079924",
"0.4984491",
"0.48721975",
"0.48582822",
"0.48554346",
"0.48341647",
"0.48302558",
"0.47793752",
"0.4762576",
"0.4760072",
"0.47315... | 0.73249227 | 0 |
Seek a cursor. Works exactly the same (and takes the same arguments) as fetch, but returns no rows. [direction] See fetch | def move(direction = 'NEXT')
statement = "move #{direction} from #{@name}"
@connection.exec(statement)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fetch_cursor(name='csr')\n raise ArgumentError, \"Cursor #{name} not open\" unless @cursors.has_key?(name)\n fetch_buffer(name) if @cursors[name][:state] == :empty\n return nil if @cursors[name][:state] == :eof\n @cursors[name][:state] = :empty if @cursors[name][:buffer].size <= 1\n row = @curso... | [
"0.6839038",
"0.68363667",
"0.64847374",
"0.6125492",
"0.6078486",
"0.60313755",
"0.60069907",
"0.6002099",
"0.59740347",
"0.5952101",
"0.59491396",
"0.5930051",
"0.5923871",
"0.5923134",
"0.57552224",
"0.57552224",
"0.57552224",
"0.57552224",
"0.57552224",
"0.57552224",
"0.5... | 0.0 | -1 |
Close the cursor. Once closed, it may not be closed or fetched from again. | def close
statement = "close #{@name}"
@connection.exec(statement)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def close\n unless closed?\n begin\n @cursor.close\n rescue Error::OperationFailure, Error::SocketError, Error::SocketTimeoutError, Error::MissingConnection\n # ignore\n end\n @cursor = nil\n end\n end",
"def close_cur... | [
"0.84778374",
"0.7345591",
"0.7089643",
"0.70257",
"0.6966311",
"0.66885644",
"0.66645443",
"0.66612524",
"0.6630109",
"0.65949523",
"0.63304836",
"0.63301367",
"0.6291665",
"0.6271475",
"0.6257681",
"0.6191767",
"0.61739504",
"0.6173155",
"0.6161096",
"0.6143233",
"0.6129709... | 0.62928873 | 12 |
total weight in oz | def total_weight
order_items.collect { |oi| oi.weight }.inject { |sum, x| sum + x } || 0
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def calc_total_weight\n 0\n end",
"def total_weight\r\n\t\t@items.inject(0.0) { |sum, i| sum + i.total_unit_weight * i.quantity }\r\n\tend",
"def total_unit_weight\r\n\t\ttotal = self.unit_weight\r\n\r\n\t\tliovs = self.line_item_option_values\r\n\t\tliovs.each do |cur_liov|\r\n\t\t\ttotal += cur_liov.extr... | [
"0.79434305",
"0.776738",
"0.7549141",
"0.7549141",
"0.74904346",
"0.7430893",
"0.73799187",
"0.7308074",
"0.727979",
"0.7236678",
"0.72099614",
"0.7193675",
"0.7193675",
"0.71743006",
"0.7152409",
"0.71154964",
"0.7067407",
"0.70575905",
"0.7048079",
"0.70345867",
"0.7018201... | 0.75848323 | 2 |
take an ID to use as key | def find(id)
@store.transaction do
#return movie object stored under this key
@store[id]
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def id\n key\n end",
"def key\n raise MissingID if not defined?(@id)\n model.key[id]\n end",
"def key\n id\n end",
"def to_key # :nodoc:\n id\n end",
"def cache_key(id); end",
"def key_id; end",
"def get_key(id)\n @keys[id]\n end",
"def get_key(id)\n if @iden... | [
"0.8109721",
"0.79059756",
"0.7898115",
"0.76118463",
"0.761003",
"0.75992256",
"0.74754834",
"0.7465422",
"0.74245554",
"0.73717666",
"0.7301578",
"0.7245898",
"0.7245898",
"0.7245898",
"0.71900666",
"0.7179912",
"0.71632576",
"0.71606594",
"0.71606594",
"0.71606594",
"0.713... | 0.0 | -1 |
returns all movies in the store | def all
@store.transaction do
@store.roots.map {|id| @store[id] }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def movies\n get('Movies')\n end",
"def index\n @movies = Movie.all\n end",
"def index\n @movies = Movie.all\n end",
"def index\n @movies = Movie.all\n end",
"def index\n @movies = Movie.all\n end",
"def index\n @movies = Movie.all\n end",
"def index\n @movies = Movie.all... | [
"0.7627571",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.75497407",
"0.7483413",
"0.74135906",
"0.7360778",
"0.73511744",
"0.73441386",
"0.73128897",
"0.7305203",
"0.7268398",
"0.72306263",
"0.72174567",
"... | 0.0 | -1 |
saves a movie to the store | def save(movie)
@store.transaction do
#if movie doesn't have an id
unless movie.id
highest_id = @store.roots.max || 0 #find the highest id
movie.id = highest_id + 1 #and increment it
end
@store[movie.id] = movie
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def save(movie)\n @store.transaction do\n # if the movie doesn't have an ID\n unless movie.id \n # find the highest key \n highest_id = @store.roots.max || 0\n # and increment it \n movie.id = highest_id + 1\n end\n @store[movie.id] = movie\n end\n end",
"d... | [
"0.6913982",
"0.6431513",
"0.6394737",
"0.6306452",
"0.62602955",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62509793",
"0.62393373",
"0.623586",
"0.62209177",
"0.6205019",
"0.615468",
"0.6149299",
"0.6126187",
"0.6118... | 0.66130215 | 1 |
everything should be in AA coords! | def extend_borders!(target)
keys = detect_keys target
opposite_keys = opposite_keys target
left, right = [data[keys[:start]], data[keys[:finish]]].sort
op_left, op_right = [data[opposite_keys[:start]], data[opposite_keys[:finish]]].sort
op_len = data[opposite_keys[:len]]
left_shift = op_left
right_shift = op_len-op_right
new_left = left - left_shift
new_left = 1 if new_left < 1
new_right = right + right_shift
new_right = data[keys[:len]] if new_right > data[keys[:len]]
@extended = true
@unextended_data ||= {}
@unextended_data[keys[:start]] = data[keys[:start]]
@unextended_data[keys[:finish]] = data[keys[:finish]]
data[keys[:start]] = data[keys[:start]] < data[keys[:finish]] ? new_left : new_right
data[keys[:finish]] = data[keys[:start]] < data[keys[:finish]] ? new_right : new_left
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def sanity_check_ballot_coords\n \n end",
"def valid_new_aoe_pos(tx, ty, sx, sy, v_range_aoe) # mod MGC\n return false unless $game_map.valid?(tx, ty) \n return true\n end",
"def chk_safe_coords(x, y)\n # If x or y is negative or greater than 4\n if x < 0 || x > 4 || y < 0 || y > 4\n return fal... | [
"0.63943475",
"0.62359285",
"0.58059454",
"0.5781434",
"0.5739325",
"0.56117046",
"0.5534256",
"0.55108815",
"0.5475754",
"0.54735243",
"0.5465022",
"0.54584366",
"0.54516125",
"0.54269564",
"0.5425684",
"0.5421114",
"0.53969896",
"0.53943986",
"0.53925246",
"0.5392404",
"0.5... | 0.0 | -1 |
Used by the threadsafe testing | def method_missing(method_name,*args)
if PedantMysql2.respond_to?(method_name, true)
PedantMysql2.send(method_name,*args)
else
super
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def lock; end",
"def lock; end",
"def lock; end",
"def synchronized?; end",
"def executor; end",
"def executor; end",
"def executor; end",
"def thread()\n #This is a stub, used for indexing\n end",
"def lock!; end",
"def test_readwrite_thread_safe\n @cache[:num] = 0\n @num... | [
"0.68034595",
"0.68034595",
"0.68034595",
"0.6732229",
"0.6650597",
"0.6650597",
"0.6650597",
"0.65836334",
"0.64832175",
"0.6458959",
"0.64279455",
"0.64279455",
"0.6419668",
"0.6419668",
"0.6419668",
"0.6419668",
"0.64191043",
"0.64191043",
"0.64191043",
"0.64079213",
"0.63... | 0.0 | -1 |
Return the argument with all its lowercase characters removed. | def destructive_uppercase(str)
my_str = ""
str.chars{|ch| my_str += ch if ch.upcase == ch}
my_str
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def toLower _args\n \"toLower _args;\" \n end",
"def squash\n upcase.delete('^A-Z0-9')\n end",
"def normalize\n input.upcase\n end",
"def destructive_uppercase(str)\n str.delete(\"abcdefghijklmnopqrstuvwxyz\")\nend",
"def normalized\n @original.downcase\n end",
"def do_magic(str... | [
"0.7506067",
"0.7171146",
"0.6986691",
"0.69201416",
"0.69054854",
"0.6856572",
"0.6830009",
"0.6782394",
"0.6782394",
"0.6773672",
"0.67507994",
"0.6733905",
"0.67071605",
"0.6702155",
"0.6677236",
"0.6655953",
"0.66153115",
"0.6611506",
"0.6610638",
"0.65936375",
"0.6591416... | 0.0 | -1 |
Return the middle character of a string. Return the middle two characters if the word is of even length, e.g. middle_substring("middle") => "dd", middle_substring("mid") => "i" | def middle_substring(str)
length = str.length
if length.odd?
str[length/2]
else
str[length/2-1,2]
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def middle_substring(str)\n mid = str.length / 2\n str.length.odd? ? str[mid] : str[mid-1..mid]\nend",
"def middle_substring(str)\n mid = str.length / 2\n str.length.odd? ? str[mid] : str[mid - 1] + str[mid]\nend",
"def middle_substring(str)\n mid = str.length / 2\n str.length.even? ? str[mid-1..mid] : s... | [
"0.87034416",
"0.8670274",
"0.8669532",
"0.86034125",
"0.85772747",
"0.85714513",
"0.85622585",
"0.8475449",
"0.84118396",
"0.84047246",
"0.8358755",
"0.8351223",
"0.8342785",
"0.8339462",
"0.82862604",
"0.8273304",
"0.8259641",
"0.82200766",
"0.8187455",
"0.81295437",
"0.811... | 0.8838202 | 0 |
Return the factoral of the argument (num). A number's factorial is the product of all whole numbers between 1 and the number itself. Assume the argument will be > 0. | def factorial(num)
product = num
(1...num).each{|n| product *= n}
product
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def factorial(num)\n\treturn nil if num < 0\n\treturn 1 if num.equal?(0)\n\ti = 1\n\ttotal = 1\n\tnum.times do\n\t\ttotal *= i\n\t\ti += 1\n\tend\n\treturn total\nend",
"def factorial(num)\n\tif num <= 1\n\t\treturn 1\n\telse\n\t\tnum * factorial(num - 1)\n\tend\nend",
"def factorial num\n\tfactorial = 1\n\twh... | [
"0.8438145",
"0.83617294",
"0.82316047",
"0.8102202",
"0.8030714",
"0.8010633",
"0.7981912",
"0.79702514",
"0.79697794",
"0.79659307",
"0.7948791",
"0.7947433",
"0.789379",
"0.7872387",
"0.7859212",
"0.78373146",
"0.7796337",
"0.7781423",
"0.77753896",
"0.7772721",
"0.7771955... | 0.764877 | 36 |
MEDIUM Write your own version of the join method. separator = "" ensures that the default seperator is an empty string. | def my_join(arr, separator = "")
if arr.empty?
return ""
else
new_str = ''
arr[0..-2].each{|n| new_str+= (n+separator)}
new_str + arr[-1]
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def join(separator=nil)\n to_a.join(separator)\n end",
"def join(separator = $OFS)\n '' + _join(separator)\n end",
"def join(separator = T.unsafe(nil)); end",
"def my_join(separator = '')\n out_str = ''\n each do |x|\n out_str << x\n out_str << separator\n end\n out_str[0..-1 * ... | [
"0.86138403",
"0.85405743",
"0.85213625",
"0.83767635",
"0.82474196",
"0.8217411",
"0.8038485",
"0.80141306",
"0.7988668",
"0.7850436",
"0.7848108",
"0.78456444",
"0.78402287",
"0.7834805",
"0.7807889",
"0.7798162",
"0.7795482",
"0.76860136",
"0.7685144",
"0.7638092",
"0.7573... | 0.7787051 | 17 |
Write a method that converts its argument to weirdcase, where every odd character is lowercase and every even is uppercase, e.g. weirdcase("weirdcase") => "wEiRdCaSe" | def weirdcase(str)
is_upcase = false
new_str = ''
str.chars.each do |ch|
if is_upcase
new_str += ch.upcase
else
new_str += ch.downcase
end
is_upcase = !is_upcase
end
new_str
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def weirdcase(str)\n new_str = \"\"\n str.chars.each_with_index do |c, i|\n if i%2==0 #reverse because odd characters have even indices\n new_str += c.downcase\n else\n new_str += c.upcase\n end\n end\n return new_str\nend",
"def weirdcase(str)\n result = \"\"\n str.chars.each_with_inde... | [
"0.8193509",
"0.81549597",
"0.81168276",
"0.8098166",
"0.8064706",
"0.8024832",
"0.80095166",
"0.79280037",
"0.7901919",
"0.79010344",
"0.78614455",
"0.7782618",
"0.7765896",
"0.76191705",
"0.7535391",
"0.7523811",
"0.75206393",
"0.74539953",
"0.7414967",
"0.7341723",
"0.7323... | 0.7338746 | 20 |
Reverse all words of five more more letters in a string. Return the resulting string, e.g., reverse_five("Looks like my luck has reversed") => "skooL like my luck has desrever") | def reverse_five(str)
arr = str.split
new_str = []
arr.each do |word|
if word.length >= 5
word.reverse!
end
new_str.push(word)
end
new_str.join(" ")
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reverse_words(string)\n string.split.each { |word| word.reverse! if word.length >= 5 }.join(' ')\nend",
"def reverse_words(string)\n string.split.each { |word| word.reverse! if word.length >= 5 }.join(' ')\nend",
"def reverse_words(string)\n words = string.split\n words.each { |word| word.reverse! if w... | [
"0.8558179",
"0.8558179",
"0.855638",
"0.8515907",
"0.84918094",
"0.8464054",
"0.8432539",
"0.84237075",
"0.84180295",
"0.84021336",
"0.8378752",
"0.83561283",
"0.8354957",
"0.83407587",
"0.83191276",
"0.8316872",
"0.82911116",
"0.82754487",
"0.8258919",
"0.8240712",
"0.82387... | 0.82281363 | 21 |
Return an array of integers from 1 to n (inclusive), except for each multiple of 3 replace the integer with "fizz", for each multiple of 5 replace the integer with "buzz", and for each multiple of both 3 and 5, replace the integer with "fizzbuzz". | def fizzbuzz(max)
arr =[]
(1..max).each do |n|
if n % 3 != 0 && n % 5 != 0
arr.push n
else
val = ''
if n % 3 == 0
val = "fizz"
end
if n % 5 == 0
val += "buzz"
end
arr.push val
end
end
arr
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fizzbuzz(n)\n array = []\n (1..n).each do |num|\n if num % 15 == 0\n array << \"fizzbuzz\"\n elsif num % 3 == 0\n array << \"fizz\"\n elsif num % 5 == 0\n array << \"buzz\"\n else\n array << num\n end\n end\n return array\nend",
"def fizzbuzz(n)\n arr = []\n (1..n).ea... | [
"0.7965208",
"0.78761595",
"0.78654754",
"0.7844762",
"0.77889717",
"0.7785351",
"0.7761416",
"0.7693393",
"0.7665432",
"0.76649815",
"0.7532192",
"0.7477176",
"0.74470556",
"0.74005646",
"0.72847",
"0.72847",
"0.72701806",
"0.72695476",
"0.7258598",
"0.7225696",
"0.72227347"... | 0.7294275 | 14 |
HARD Write a method that returns a new array containing all the elements of the original array in reverse order. | def my_reverse(arr)
idx = arr.length - 1
rev = []
while idx >= 0
rev.push(arr[idx])
idx -= 1
end
rev
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reverse_array(array_new)\n array_new.reverse \n end",
"def my_reverse(arr)\n new_array = arr.reverse\n return new_array\n end",
"def my_reverse\n new_arr = []\n i = self.length-1\n while i >= 0\n new_arr << self[i]\n i -= 1\n end\n new_arr\... | [
"0.8609501",
"0.84842646",
"0.84591293",
"0.84588814",
"0.84588814",
"0.8396383",
"0.83960843",
"0.83671093",
"0.8327724",
"0.8325782",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918",
"0.8278918... | 0.7819486 | 91 |
Write a method that returns a boolean indicating whether the argument is prime. | def prime?(num)
return false if num < 2
(2..num/2).each{ |n| return false if num % n == 0 }
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def is_prime?(num)\nend",
"def prime?(arg)\n Prime.prime?(arg)\nend",
"def prime?(n)\n\tPrime.prime?(n)\nend",
"def prime?(int)\n \nend",
"def is_prime?(num)\n # Write your code here\nend",
"def is_prime?(num)\n\nend",
"def is_prime?(n)\n end",
"def prime?(n)\n primes(n).size == 1\nend",
"de... | [
"0.83982253",
"0.8387713",
"0.83654135",
"0.8345047",
"0.8294106",
"0.82382286",
"0.8210866",
"0.8181966",
"0.81580824",
"0.81545854",
"0.81363606",
"0.8132913",
"0.812148",
"0.812148",
"0.8116212",
"0.81146556",
"0.8065454",
"0.80530596",
"0.80353",
"0.80329394",
"0.80289924... | 0.0 | -1 |
Write a method that returns a sorted array of the factors of its argument. | def factors(num)
facs = [1]
(2..num/2).each{|n| facs.push(n) if num % n == 0 }
facs.push(num)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def factors(num)\n output_arr = []\n\n (1..num).each do |el|\n if num % el == 0\n output_arr << el\n end\n end\n\n output_arr.sort\nend",
"def factors(num)\n array = []\n (1..num).each do |number|\n array << number if num % number == 0\n end\n array.sort!\nend",
"def... | [
"0.7904064",
"0.7902955",
"0.77490956",
"0.77448606",
"0.7737135",
"0.7637974",
"0.75834125",
"0.7557235",
"0.7518705",
"0.75077593",
"0.75072306",
"0.74821216",
"0.7452686",
"0.7440315",
"0.7437962",
"0.74183434",
"0.7413723",
"0.7375539",
"0.73751694",
"0.7374454",
"0.73714... | 0.7119335 | 46 |
Write a method that returns a sorted array of the prime factors of its argument. | def prime_factors(num)
facs = factors(num)
p_facs = []
facs.each{|n| p_facs.push(n) if prime?(n)}
p_facs
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def prime_factors(num)\n all_factors = factors(num)\n output_arr = []\n\n all_factors.each do |el|\n if prime?(el)\n output_arr << el\n end\n end\n\n output_arr.sort\nend",
"def prime_factors(num)\n array = []\n (1..num).each do |number|\n array << number if prime?(nu... | [
"0.8321737",
"0.8214368",
"0.8024582",
"0.7942682",
"0.7887547",
"0.78781176",
"0.7876123",
"0.7858201",
"0.78339076",
"0.7825693",
"0.7825693",
"0.7779158",
"0.7753471",
"0.7732609",
"0.77198684",
"0.7625415",
"0.7618718",
"0.76001966",
"0.7599118",
"0.75832766",
"0.7575698"... | 0.76855034 | 15 |
Write a method that returns the number of prime factors of its argument. | def num_prime_factors(num)
prime_factors(num).length
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def num_prime_factors(num)\n prime_factors(num).count\nend",
"def num_prime_factors(num)\n prime_factors(num).length\n\nend",
"def num_prime_factors(num)\n prime_factors(num).length\nend",
"def num_prime_factors(num)\r\n # your code goes here\r\n prime_factors(num).length\r\n\r\nend",
"def num_prime... | [
"0.87944657",
"0.8692755",
"0.8644713",
"0.86063844",
"0.84600616",
"0.84600616",
"0.8443473",
"0.84298766",
"0.8379911",
"0.82761544",
"0.8150427",
"0.8008973",
"0.79603446",
"0.79120946",
"0.7788769",
"0.7751828",
"0.7732856",
"0.7686826",
"0.768163",
"0.7656219",
"0.763143... | 0.8615301 | 5 |
EXPERT Return the one integer in an array that is even or odd while the rest are of opposite parity, e.g. oddball([1,2,3]) => 2, oddball([2,4,5,6] => 5) | def oddball(arr)
a, b, c = arr
if a %2 == b %2
expected = a %2
arr.drop(2).each{|n| return n if n != a}
elsif a%2 == c %2
return b
else
return a
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def oddball(arr)\n is_even = []\n is_odd = []\n i = 0\n while i < arr.length\n if arr[i] % 2 = 0\n is_even += arr[i]\n else\n is_odd += arr[i]\n end\n i += 1\n end\n if is_even.length == 1\n return is_even[0]\n else\n return is_odd[0]\n end\nend",
"def oddball(arr)\n\tnew_ar... | [
"0.8097777",
"0.80582494",
"0.79378325",
"0.78846085",
"0.78202075",
"0.77989274",
"0.7789699",
"0.77869767",
"0.7783659",
"0.7769034",
"0.77633584",
"0.7735252",
"0.77309644",
"0.77302516",
"0.7723545",
"0.7687903",
"0.76857364",
"0.76700634",
"0.7669797",
"0.76612425",
"0.7... | 0.7865907 | 4 |
Override render_document to pass `turtle` as a local `turtle` is entityescaped Turtle serialization of graph | def render_document(subjects, options = {})
super(subjects, options.merge(:extracted => graph.dump(:rdfa, :haml => RDF::Linter::TABULAR_HAML))) do |subject|
yield(subject) if block_given?
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def render(document)\n renderer = find_renderer(document)\n renderer.render(document) unless renderer.nil?\n end",
"def render_document; end",
"def _render_\n document.to_s\n end",
"def render(obj = Object.new, locals = {})\n output = template.result(obj.instance_eval { binding })\n ... | [
"0.6253246",
"0.6128175",
"0.6103045",
"0.58074194",
"0.56445646",
"0.5542434",
"0.54631513",
"0.5391891",
"0.535961",
"0.5296519",
"0.5257945",
"0.5233452",
"0.51590407",
"0.50982",
"0.5094695",
"0.49739802",
"0.4929019",
"0.49227482",
"0.49211338",
"0.49209684",
"0.4917407"... | 0.53232867 | 9 |
Override render_subject to look for a :rel template if this is a relation. In which case, we'll also pass the typeof the referencing resource | def render_subject(subject, predicates, options = {}, &block)
options = options.merge(:haml => haml_template[:rel]) if options[:rel] && haml_template[:rel]
super(subject, predicates, options) do |predicate|
if predicate.is_a?(Symbol)
# Special snippet processing
# Render associated properties with associated or default formatting
case predicate
when :other
props = predicates.map(&:to_s)
props -= haml_template[:title_props] || []
props -= haml_template[:body_props] || []
props -= haml_template[:description_props] || []
format = lambda {|list| list.map {|e| yield(e)}.join("")}
when :other_nested
props = predicates.map(&:to_s)
props -= haml_template[:nested_props] || []
format = lambda {|list| list.map {|e| yield(e)}.join("")}
else
# Find appropriate entires from template
props = haml_template["#{predicate}_props".to_sym]
add_debug "render_subject(#{subject}, #{predicate}): #{props.inspect}"
format = haml_template["#{predicate}_fmt".to_sym]
end
unless props.nil? || props.empty?
format ||= lambda {|list| list.map {|e| yield(e)}.join("")}
format.call(props, &block)
end
else
yield(predicate)
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def rel_type\n getType().name()\n end",
"def get_resource_templates\n @model.get.mixins.select { |mixin| mixin.related.select { |rel| rel.end_with? 'resource_tpl' }.any? }\n end",
"def part_of_title_by_type(resource_type)\n if self.type == resource_type\n self.title\... | [
"0.5615752",
"0.5476091",
"0.5431551",
"0.54190505",
"0.53665394",
"0.53199923",
"0.53156286",
"0.528927",
"0.5266104",
"0.52639693",
"0.5240948",
"0.5223452",
"0.5221651",
"0.5201447",
"0.51953125",
"0.51744705",
"0.5148638",
"0.5144806",
"0.5121389",
"0.5102442",
"0.5046121... | 0.5366286 | 5 |
Override order_subjects to prefer subjects having an rdf:type Subjects are first sorted in topographical order, by highest (lowest numerical) snippet priority. | def order_subjects
subjects = super
add_debug "order_subjects: #{subjects.inspect}"
# Order subjects by finding those with templates, and then by the template priority order
prioritized_subjects = []
other_subjects = []
subjects.each do |s|
template = find_template(s)
next unless template
priority = template[:priority] || 99
add_debug " priority(#{s}) = #{priority}"
prioritized_subjects[priority] ||= []
prioritized_subjects[priority] << s
end
ordered_subjects = prioritized_subjects.flatten.compact
other_subjects = subjects - ordered_subjects
add_debug "ordered_subjects: #{ordered_subjects.inspect}\n" +
"other_subjects: #{other_subjects.inspect}"
ordered_subjects + other_subjects
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def order_subjects\n subjects = super\n other_subjects = []\n templates = {}\n\n log_debug \"order_subjects: #{subjects.inspect}\"\n\n # Order subjects by finding those with templates, and then by the template priority order and name\n\n # Get template priorities for each subject\n ... | [
"0.804792",
"0.72038674",
"0.55669224",
"0.54452723",
"0.5338515",
"0.5289578",
"0.52037513",
"0.5199704",
"0.5168435",
"0.5110567",
"0.5096804",
"0.5024326",
"0.49352625",
"0.49262598",
"0.4909191",
"0.48932308",
"0.48865318",
"0.4877155",
"0.48666078",
"0.4864642",
"0.48562... | 0.8143512 | 0 |
Find a template appropriate for the subject. Use type information of subject to select among multiple templates In this implementation, find all templates matching on permutations of types of this subjects and choose the one with the lowest :priority Keep track of matched templates | def find_template(subject)
properties = @graph.properties(subject)
types = (properties[RDF.type.to_s] || [])
matched_templates = []
(1..types.length).each do |len|
types.combination(len) do |set|
templ = @options[:haml] && @options[:haml][set]
templ ||= haml_template[set]
if len == 1
templ ||= @options[:haml] && @options[:haml][set.first]
templ ||= haml_template[set.first]
end
add_debug "find_template: look for #{set.inspect}"
add_debug "find_template: look for #{set.first.inspect}" if len == 1
# Look for regular expression match
templ ||= if len == 1
key = haml_template.keys.detect {|k| k.is_a?(Regexp) && set.first.to_s.match(k)}
haml_template[key]
end
next unless templ
matched_templates[len] ||= []
matched_templates[len] << templ
end
end
if matched_templates.empty?
add_debug "find_template: no template found for any #{types.inspect}"
return nil
end
list = matched_templates.last
# Order the list of templates by priority
list = list.sort_by {|templ| templ[:priority] || 99}
# Choose the lowest priority template found
templ = list.first
add_debug "find_template: found #{templ[:identifier] || templ.inspect}"
@options[:matched_templates] << templ[:identifier]
templ
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def find_template(subject)\n properties = @graph.properties(subject)\n types = (properties[RDF.type.to_s] || [])\n \n matched_templates = []\n \n (1..types.length).each do |len|\n types.combination(len) do |set|\n templ = @options[:haml] && @options[:haml][set]\n ... | [
"0.81796455",
"0.58211565",
"0.5803445",
"0.57706887",
"0.5744465",
"0.5616418",
"0.5597275",
"0.55395097",
"0.5475793",
"0.5350764",
"0.5311171",
"0.52903205",
"0.5176038",
"0.5120756",
"0.51200044",
"0.5076966",
"0.5029992",
"0.50119627",
"0.4992376",
"0.4988387",
"0.494091... | 0.8161067 | 1 |
Override get_value to perform lexical matching over selected values, infer datatype and perform datatypespecific formatting | def get_value(literal)
if literal.typed?
literal.humanize
else
# Hack to fix incorrect dattime
case literal.to_s
when RDF::Literal::Duration::GRAMMAR
get_value(RDF::Literal::Duration.new(literal))
when RDF::Literal::Date::GRAMMAR
get_value(RDF::Literal::Date.new(literal))
when RDF::Literal::Time::GRAMMAR
get_value(RDF::Literal::Time.new(literal))
when RDF::Literal::DateTime::GRAMMAR
get_value(RDF::Literal::DateTime.new(literal))
when %r(\A-?\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?(\.\d+)?(([\+\-]\d{2}:\d{2})|UTC|Z)?\Z)
# Hack to fix incorrect DateTimes in examples:
get_value(RDF::Literal::DateTime.new(literal))
else
literal.to_s
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def formatted_value_other(value, type)\n if type == :boolean || (type == :automatic && looks_like_boolean?(value))\n formatted_value_boolean(value)\n elsif type == :date || (type == :automatic && looks_like_date?(value))\n I18n.l(value)\n else # Number or String\n formatted_valu... | [
"0.68830705",
"0.66187906",
"0.6442266",
"0.6315576",
"0.6222422",
"0.6218922",
"0.6162796",
"0.6160508",
"0.60996014",
"0.6093866",
"0.6046954",
"0.6005339",
"0.59773886",
"0.59702265",
"0.59496546",
"0.5945018",
"0.5918942",
"0.59053427",
"0.5902997",
"0.58867675",
"0.58725... | 0.6397479 | 3 |
course is editable if the signed in user is a University Admin and belongs to the same institution as the course | def set_editability
@editable = user_signed_in? && (current_user.member.role.name.eql? "University Admin") &&
current_user.member.institution.id == @course.department.institution.id
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def can_edit?(user)\n course.can_edit? user\n end",
"def can_edit(user)\n\t\tif user\n\t\t\tcan_edit = user.courses.include?(self)\n\t\telse\n\t\t\tfalse\n\t\tend\n\tend",
"def updatable_by?(user)\n user.admin_for?(resource.course)\n end",
"def course_owner\n @course = Course.find(params[:id])\n ... | [
"0.77455914",
"0.75101346",
"0.7456505",
"0.73456204",
"0.71519035",
"0.6946149",
"0.68935764",
"0.68794024",
"0.68114877",
"0.67774683",
"0.6747436",
"0.6737102",
"0.6717443",
"0.67048657",
"0.66837156",
"0.66336876",
"0.6614074",
"0.66133416",
"0.6606802",
"0.6604033",
"0.6... | 0.8348009 | 0 |
next few methods are for updating/editing course | def get_course_params
course_params = params.require(:course)
if !empty_new_end_qual
course_params = course_params.except(:end_qualification_id)
end
if !empty_new_del_mode
course_params = course_params.except(:delivery_mode_id)
end
return course_params.permit!
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def edit\n set_student\n @courses = Course.all\n end",
"def edit #this action allow admin to edit single course value\n end",
"def update\n \n #don't need to add user_id here.. already exists.\n \n @course = Course.find(params[:id])\n\n respond_to do |format|\n if @course.update_att... | [
"0.7805154",
"0.76788527",
"0.7629602",
"0.7628735",
"0.7623742",
"0.762186",
"0.7529985",
"0.7457346",
"0.7445963",
"0.74367666",
"0.74367666",
"0.74346626",
"0.74154264",
"0.741338",
"0.7411294",
"0.7399746",
"0.7356317",
"0.7351276",
"0.7346413",
"0.7326563",
"0.7304887",
... | 0.0 | -1 |
all existing fees have both fields filled | def edit_fee_fields_filled
if !params[:edit_fees].nil?
edit_fees_vals = params[:edit_fees].values
edit_fees_vals.each_slice(3) do |fee, time, remove|
if fee.empty? || time.empty?
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def validatable_basic_fee_types\n @fee_types.select do |fee_type|\n fee_type.calculated == true && !fee_type.defendant_uplift?\n end\n end",
"def verify_fees(test_data)\n fees = test_data[CoreUseOfCollectionsData::FEE_GRP.name] || [CoreUseOfCollectionsData.empty_fee]\n fees.each_with_ind... | [
"0.69060236",
"0.6772932",
"0.6761408",
"0.6740688",
"0.660252",
"0.65942687",
"0.6486096",
"0.6436056",
"0.63311875",
"0.63245404",
"0.6315531",
"0.62102324",
"0.6156142",
"0.6149327",
"0.6124711",
"0.61027366",
"0.6074607",
"0.6059176",
"0.6004836",
"0.5988711",
"0.5981289"... | 0.73601407 | 0 |
edit fee fields have valid integers | def edit_fee_is_integer
if !params[:edit_fees].nil?
edit_fees_vals = params[:edit_fees].values
edit_fees_vals.each_slice(3) do |fee, time, remove|
if !(fee.to_i.to_s.eql? fee)
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_fee_is_integer\n if !params[:add_fee].nil?\n add_fee_vals = params[:add_fee].values\n add_fee_vals.each_slice(3) do |student_type, amount, time_period|\n if !amount.empty? && !(amount.to_i.to_s.eql? amount)\n return false\n end\n end\n end\n return true\n end... | [
"0.66417956",
"0.653504",
"0.61343735",
"0.6095732",
"0.58294827",
"0.58216184",
"0.5797963",
"0.5797407",
"0.570779",
"0.57003444",
"0.5690185",
"0.56842583",
"0.5656483",
"0.5639606",
"0.5638781",
"0.5627222",
"0.56193477",
"0.5585738",
"0.558181",
"0.55663365",
"0.55463916... | 0.7614905 | 0 |
add fee fields are all filled or all empty | def add_fee_filled_or_empty
if !params[:add_fee].nil?
add_fee_keys = params[:add_fee].keys
add_fee_vals = params[:add_fee].values
add_fee_vals.each_slice(3) do |student_type, amount, time_period|
if !((!student_type.empty? && !amount.empty? && !time_period.empty?) ||
(student_type.empty? && amount.empty? && time_period.empty?))
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def edit_fee_fields_filled\n if !params[:edit_fees].nil?\n edit_fees_vals = params[:edit_fees].values\n edit_fees_vals.each_slice(3) do |fee, time, remove|\n if fee.empty? || time.empty?\n return false\n end\n end\n end\n return true\n end",
"def total_fee_is_valid... | [
"0.7955136",
"0.693547",
"0.67354393",
"0.65347356",
"0.64389837",
"0.62996155",
"0.62626946",
"0.62066674",
"0.6140506",
"0.6088533",
"0.60844463",
"0.60794795",
"0.60560393",
"0.6041833",
"0.5974108",
"0.5929109",
"0.5889821",
"0.5887308",
"0.5871929",
"0.5866521",
"0.58610... | 0.76635987 | 1 |
add fee is an integer | def add_fee_is_integer
if !params[:add_fee].nil?
add_fee_vals = params[:add_fee].values
add_fee_vals.each_slice(3) do |student_type, amount, time_period|
if !amount.empty? && !(amount.to_i.to_s.eql? amount)
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_money\n @total += fee\n end",
"def total_fee\n fee + fee2 + fee3 + fee4\n end",
"def total\n (amount + fee) if amount\n end",
"def fee\n (amount * 0.005) if amount\n end",
"def bar_accepts_fee(fee)\n @bar_cash += fee\n end",
"def fee\n params['amount_fee']\n ... | [
"0.7869563",
"0.76108587",
"0.7365345",
"0.71690035",
"0.71125776",
"0.6906227",
"0.68922806",
"0.67977655",
"0.66506",
"0.6647953",
"0.64599144",
"0.63451695",
"0.633986",
"0.633986",
"0.6328",
"0.6302088",
"0.6302088",
"0.62671804",
"0.62576467",
"0.6249384",
"0.6243939",
... | 0.639711 | 11 |
Grade can't be empty | def valid_edit_entry_reqs
if !params[:edit_entry_req].nil?
edit_reqs_vals = params[:edit_entry_req].values
edit_reqs_vals.each_slice(3) do |grade, info, remove|
if grade.empty?
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def grade_is_valid\n errors.add(:grade, 'Invalid grade entered.') unless grade_is_valid?\n end",
"def grade_or_blank\n grade || \"None\"\n end",
"def grade_is_valid?\n if not_nil_and_string(self.grade)\n if GRADES.include? self.grade\n if self.grade == \"k\";self.grade = \"K\";end #force... | [
"0.7560349",
"0.7542708",
"0.7293533",
"0.6466168",
"0.63290566",
"0.63017464",
"0.6279586",
"0.6249708",
"0.62176436",
"0.6185592",
"0.6182905",
"0.6166327",
"0.61450225",
"0.61365336",
"0.6106052",
"0.6102391",
"0.60613227",
"0.6041784",
"0.60280734",
"0.6018244",
"0.600466... | 0.60914916 | 16 |
valid is all fields empty or incoming_qual and grade filled | def valid_add_entry_req
if !params[:add_entry_req].nil?
add_er_vals = params[:add_entry_req].values
add_er_vals.each_slice(3) do |incoming_qual, grade, info|
if (!incoming_qual.empty? && grade.empty?) ||
(incoming_qual.empty? && (!grade.empty? || !info.empty?))
return false
end
end
end
return true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def grade_is_valid\n errors.add(:grade, 'Invalid grade entered.') unless grade_is_valid?\n end",
"def validate_required\n [\n :project_name,\n :status,\n :requester_id,\n :subject_expert_id,\n :sponsor_id,\n :vision,\n :goal,\n :description,\n ... | [
"0.7050975",
"0.7010043",
"0.65794116",
"0.65639305",
"0.656047",
"0.6557604",
"0.64929855",
"0.6391397",
"0.6391397",
"0.6359351",
"0.6329575",
"0.6321248",
"0.62965274",
"0.6296428",
"0.6292145",
"0.62892175",
"0.6275817",
"0.6264646",
"0.6252959",
"0.62178636",
"0.6158149"... | 0.6816034 | 2 |
This is for the "send_reminders" functionality | def user_response
Rails.logger.info(:event => "action_response", :response => params["payload"].class)
begin
payload = ActiveSupport::JSON.decode(params["payload"])
user = payload["user"]
actions = payload["actions"]
id = user["id"]
value = actions[0]["value"]
if value == "done"
# TODO:
# - I think we might need to hide the instance name in the value? Or maybe another field?
# - Once I can identify the instance that's "done", retrieve it from the database and
# mark it as vacant.
# - After successfully updating the instance, send lily a message letting her know what happened.
elsif value == "not_done"
render :status => 200, :body => "No problem!"
return
else
# this... shouldn't be possible
end
rescue StandardError => e
Rails.logger.error(:event => "user_response_crash", :error => e, :backtrace => e.backtrace)
return nil
end
render :status => 200, :body => "Thanks for the update!"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def reminder_sent\n end",
"def reminder\n RequestMailer.reminder\n end",
"def reminder\n UsersMailer.reminder\n end",
"def reminder\n send_reminders self.charges.where(:completed => false)\n end",
"def add_reminder; end",
"def reminder\n DateEventApplicationsMailer.reminder\n end",
"de... | [
"0.82073325",
"0.80129164",
"0.77377504",
"0.7703594",
"0.7659824",
"0.7638564",
"0.754223",
"0.7479497",
"0.74484354",
"0.7372904",
"0.73094285",
"0.728429",
"0.72125155",
"0.7143733",
"0.71231854",
"0.7121898",
"0.7109078",
"0.7100921",
"0.70985067",
"0.7089291",
"0.7075754... | 0.0 | -1 |
to modify board size would initialize board with a diff size | def initialize
@squares = (0..8).to_a
@free_squares = squares.dup
@dimension = Math.sqrt(@squares.length).to_i
@indeces = (squares.dup)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def fill_board(size)\n board = []\n board_rows = []\n size.times {|i| board_rows << i}\n size.times {board << board_rows}\n @board = board\n end",
"def initialize(size)\n @board_size = size\n @board = []\n @board_size.times { @board << Array.new(@board_size, EMPTY_S... | [
"0.76676244",
"0.73507553",
"0.72536045",
"0.72424364",
"0.72154063",
"0.72072756",
"0.7175099",
"0.7023512",
"0.70039284",
"0.70019114",
"0.69003695",
"0.6768323",
"0.67066026",
"0.6691676",
"0.6662086",
"0.6657223",
"0.6603936",
"0.6597341",
"0.65850925",
"0.6553482",
"0.65... | 0.0 | -1 |
Ruby method can take argument without (..) | def my_method2 argument1, argument2
print argument1, " ", argument2, "\n"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def method(a, *b)\r\n\tb\r\nend",
"def method(arg0)\n end",
"def method(arg0)\n end",
"def method(a, b=-2, *c)\r\nend",
"def argue(argument)\n argument\nend",
"def args(*) end",
"def method(a=2, *b)\r\n\tb\r\nend",
"def nothing(param1)\n end",
"def /(arg0)\n end",
"def /(arg0)\n end",
"de... | [
"0.6794627",
"0.6692541",
"0.6692541",
"0.6525113",
"0.6508942",
"0.64719373",
"0.6467577",
"0.6453179",
"0.639138",
"0.639138",
"0.63777286",
"0.6368883",
"0.6365956",
"0.6363147",
"0.6363055",
"0.63630104",
"0.6346795",
"0.63424075",
"0.6321722",
"0.6315374",
"0.6305821",
... | 0.0 | -1 |
Variable number of arguments | def my_method3(*arguments)
print "Arguments class is ", arguments.class, "\n"
print "#{arguments.join(' ')}", "\n"
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def how_many_args (*input)\n input.count\n end",
"def how_many_args(*args)\n\targs.length\nend",
"def how_many_args *args\n args.length\n # accepts any number of arguments without complaint\n # returns the total number of arguments passed to the function\n # Hint: google ruby *args\nend",
"def how_ma... | [
"0.7546812",
"0.750412",
"0.74718434",
"0.7461837",
"0.7456489",
"0.73960036",
"0.73612213",
"0.7339796",
"0.73243415",
"0.7307468",
"0.7290838",
"0.7257489",
"0.70177597",
"0.69750077",
"0.6868659",
"0.6867352",
"0.68528336",
"0.6845597",
"0.68259865",
"0.6760111",
"0.676011... | 0.0 | -1 |
GET /pictures/1 GET /pictures/1.json | def show
@picture = Picture.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @picture }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def index\n @pictures = @album.pictures #JRD111115\n\n respond_to do |format|\n format.html #index.html.erb\n format.json { render json: @pictures}\n end\n end",
"def show\n @picture = @album.pictures.find(params[:id]) #JRD111115\n\n respond_to do |format|\n format.html # show... | [
"0.78861046",
"0.77967006",
"0.7703738",
"0.7652336",
"0.75105095",
"0.75022507",
"0.74907297",
"0.74695826",
"0.744514",
"0.7441424",
"0.7422313",
"0.7395833",
"0.739197",
"0.7329584",
"0.7298408",
"0.7228419",
"0.71639085",
"0.7159588",
"0.71483576",
"0.70885813",
"0.704074... | 0.7424227 | 15 |
GET /pictures/new GET /pictures/new.json | def new
@project = Project.find(params[:project_id])
@picture = @project.pictures.build
respond_to do |format|
format.html # new.html.erb
format.json { render json: @picture }
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def new\n @picture = Picture.new\n \n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @picture }\n end\n end",
"def new\n @picture = Picture.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @picture }\... | [
"0.8038981",
"0.79874873",
"0.79874873",
"0.79874873",
"0.7922598",
"0.78247064",
"0.7807926",
"0.7776248",
"0.7542473",
"0.74994177",
"0.7460262",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0.74600285",
"0... | 0.7421645 | 23 |
PUT /pictures/1 PUT /pictures/1.json | def update
@picture = Picture.find(params[:id])
respond_to do |format|
if @picture.update_attributes(params[:picture])
format.html { redirect_to @picture, notice: 'Picture was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @picture.errors, status: :unprocessable_entity }
end
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def update\n @pictures = Picture.all.order(created_at: :desc)\n @picture.update(picture_params)\n render json: @pictures\n # head :no_content\n end",
"def update\n if @picture.update(picture_params)\n head :no_content\n else\n render json: @picture.errors, status: :unprocessable_enti... | [
"0.7677843",
"0.7093891",
"0.7019593",
"0.6935083",
"0.693408",
"0.68827313",
"0.68587154",
"0.68570614",
"0.67712915",
"0.6759743",
"0.67408067",
"0.6732044",
"0.67319566",
"0.67319566",
"0.67319566",
"0.67319566",
"0.66940475",
"0.6688948",
"0.6681928",
"0.6645544",
"0.6641... | 0.68732107 | 8 |
DELETE /pictures/1 DELETE /pictures/1.json | def destroy
@picture = Picture.find(params[:id])
@picture.destroy
render :json => true
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def destroy\n @picture = Picture.find(params[:id])\n @picture.destroy\n\n respond_to do |format|\n format.html { redirect_to pictures_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @picture = Picture.find(params[:id])\n @picture.destroy\n\n respond_to do |fo... | [
"0.7720266",
"0.7720266",
"0.7720266",
"0.77012306",
"0.76928186",
"0.7626824",
"0.76236266",
"0.7621202",
"0.750104",
"0.74616617",
"0.745819",
"0.7438936",
"0.7438936",
"0.7438936",
"0.7438936",
"0.7438936",
"0.7438936",
"0.7437056",
"0.7424971",
"0.74229836",
"0.7419578",
... | 0.7794452 | 0 |
At the top of your file, add a method that takes an array and an item as parameters, and returns the array with the item added. | def add_to_array(arr, value)
arr.push(value)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def add_item(array, item)\n\tarray << item\nend",
"def add_to_array(array, item)\n array << item\nend",
"def add_item(array, item)\n\tarray.push(item)\nend",
"def add_to_array(array, item)\n\tarray += [item]\n\tp array\nend",
"def add_to_array!(array, item)\n array << item\nend",
"def add_item(elective... | [
"0.7831222",
"0.77694875",
"0.7735271",
"0.75432",
"0.75103503",
"0.7368812",
"0.7130133",
"0.7085374",
"0.69466776",
"0.6819663",
"0.68095666",
"0.6808823",
"0.6781232",
"0.6770126",
"0.6708251",
"0.6668714",
"0.66675544",
"0.66139007",
"0.66086584",
"0.6591497",
"0.65496397... | 0.6370342 | 28 |
Defines column filter for param. | def filter(param, type:, operation:, column: nil, required: false, format_value: nil)
query_param = param.to_s.underscore
column ||= param.to_s.underscore
op = operations.fetch(operation.to_sym) { raise ArgumentError, "unknown operation #{operation}" }
sql = op.call(column, query_param, type)
raw_filter(param, sql:, required:, format_value:, query_param:, array: op.array)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def prepare_orm_filters\n filters = [[]]\n date_format = I18n.t(:\"date.formats.default\", {:locale => I18n.locale })\n self.data_grid.columns.each_with_index do |col, col_index|\n if col.filter and !col.filter_value.blank?\n case col.filter\n when :boolean\n filt... | [
"0.6918216",
"0.66111094",
"0.657951",
"0.65015215",
"0.6492924",
"0.64537555",
"0.63216335",
"0.62943935",
"0.6292374",
"0.62292796",
"0.62292796",
"0.6217071",
"0.6198962",
"0.61800224",
"0.6122546",
"0.6117841",
"0.6110038",
"0.6035985",
"0.60352445",
"0.6014545",
"0.60104... | 0.6594887 | 2 |
Defines raw filter for param via SQL condition. | def raw_filter(param, sql:, query_param: nil, required: false, format_value: nil, array: false)
param = param.to_sym
raise ArgumentError, "filter with param #{param} already defined" if filters.key?(param)
query_param ||= param.to_s.underscore
format_value ||= ->(value, _opts) { value }
filters[param] = Filter.new(param:, sql:, query_param:, required:, format_value:, array:)
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def filter\n params['filter_field'] || '*'\n end",
"def Filter=(arg0)",
"def filter(param, type:, operation:, column: nil, required: false, format_value: nil)\n query_param = param.to_s.underscore\n column ||= param.to_s.underscore\n op = operations.fetch(operation.to_sym) { raise ... | [
"0.68580574",
"0.6649707",
"0.6603387",
"0.6557816",
"0.6487252",
"0.64606726",
"0.63286126",
"0.6320884",
"0.6317552",
"0.6303581",
"0.6302672",
"0.6290166",
"0.62254494",
"0.6222143",
"0.6216791",
"0.62059814",
"0.61531365",
"0.6139491",
"0.61273384",
"0.61079204",
"0.60989... | 0.79207706 | 0 |
Load the contents of a JSON file into Redis Each key in the JSON file becomes a redis key. If the value is a literal then this is added as a redis keyvalue pair. If an array, then a List. If a hash, then a Hash. Nested objects will be flattened. file:: json file path:: optional, path in the json file indicating the subsection to load | def load_json(file, path=nil)
f = File.new( file )
json = JSON.parse( f.read )
if path != nil
json = Siren.query(query, json)
end
counter = 0
#TODO could support proper results, not just hash?
if json != nil
json.each_pair do |key,value|
if value.class() == Array
value.each do |v|
@redis.lpush( key, v )
end
elsif value.class == Hash
value.each_pair do |field, v|
#TODO better handling of nesting?
#E.g. convert hash or array back into JSON?
@redis.hset(key, field, v)
end
else
@redis.set(key, value)
end
counter = counter + 1
end
end
return counter
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def json_load(file_path)\n MultiJson.load(File.read(file_path)).to_smash\n end",
"def load_hash(file_path) \n file=File.read(file_path)\n JSON.parse(file)\n end",
"def load_hash(file_path) \n file=File.read(file_path)\n JSON.parse(file)\n end",
"def load_json(file)\n type = File.... | [
"0.6992283",
"0.64195734",
"0.64195734",
"0.63779396",
"0.6324285",
"0.6300944",
"0.623934",
"0.6237231",
"0.62318707",
"0.6188736",
"0.61245394",
"0.60220444",
"0.6005296",
"0.5924706",
"0.5919942",
"0.5878331",
"0.5819003",
"0.5785386",
"0.5781708",
"0.57408696",
"0.5737095... | 0.75714713 | 0 |
Load the contents of a file into a Redis list key:: name of the list file:: name of file (string) | def load_list(key, file)
f = File.new( file )
counter = process_lines(f) do |redis,line|
redis.lpush( key , line.chomp)
end
return counter
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def loadlist _file, _append\n send_cmd(\"loadlist #{_file} #{_append}\")\n end",
"def load_cache\n @list = YAML::load_file Settings[:cache_file]\n end",
"def add_file(path_to_file, options)\n puts \"INSIDE add_file METHOD\"\n puts \"OPTIONS: #{options.inspect}\"\n name = ... | [
"0.64938444",
"0.63241535",
"0.63234454",
"0.60214484",
"0.59627587",
"0.59255385",
"0.590026",
"0.5876876",
"0.58177805",
"0.5789792",
"0.5767522",
"0.57405245",
"0.57155603",
"0.5713657",
"0.5706526",
"0.56286347",
"0.5605674",
"0.5551865",
"0.554792",
"0.5537724",
"0.55338... | 0.8290899 | 0 |
Process lines io:: IO Object | def process_lines(io)
counter = 0
io.each_line do |line|
yield @redis, line
counter = counter + 1
end
return counter
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def read_lines(io)\n buffer = +''\n while line = io.gets\n buffer << line\n yield line\n end\n buffer\n end",
"def proccess_lines(input)\n CSV.foreach(input, headers: true, header_converters: :symbol) do |row|\n line_parser = LineParser.new(row)\n\n if line_parser.valid?... | [
"0.6559067",
"0.6375462",
"0.62753123",
"0.626858",
"0.61905915",
"0.615974",
"0.6126743",
"0.606643",
"0.6064732",
"0.6054343",
"0.6046821",
"0.6023971",
"0.6022353",
"0.5922476",
"0.5910147",
"0.58940905",
"0.58763564",
"0.586661",
"0.58659804",
"0.58546996",
"0.5853314",
... | 0.6733401 | 0 |
Called on the ratings new page | def return_sub_types
main_type = type_status
if main_type
return self.beer_subtypes.map{|type| {id: type.id, name: type.name}}
else
return types_for_subtype
end
end | {
"objective": {
"self": [],
"paired": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} | [
"def new\n @rating_alt = Rating.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @rating_alt }\n end\n end",
"def new\n @rating = Rating.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @rating }\n ... | [
"0.6557378",
"0.6440427",
"0.6440427",
"0.6440427",
"0.63995826",
"0.6393542",
"0.6364518",
"0.63636035",
"0.63427615",
"0.6242519",
"0.6197882",
"0.618935",
"0.6186078",
"0.6107314",
"0.6106605",
"0.61003184",
"0.6093549",
"0.6075821",
"0.6075821",
"0.6075821",
"0.60682255",... | 0.0 | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.