query stringlengths 7 9.5k | document stringlengths 10 1.07M | negatives listlengths 19 19 | metadata dict |
|---|---|---|---|
Returns the closest date within the configured dates to the date supplied in the argument. This is useful when you want to automatically change the default timetable page based on today's date. | def closest_date_for(symbol, date)
my_date = date.beginning_of_day
dates = dates_for(symbol)
if dates.include?(my_date)
return my_date
else
my_date < dates.min ?
dates.min :
dates.max
end
end | [
"def nearest_date\n d = @dates.find { |d| \"#{d.date}\" == \"#{@transaction_date}\" }\n return d if d\n\n raise \"#{DATE_ERROR_MESSAGE} #{@transaction_date}\" unless @options[:permissive]\n\n dates.sort_by{ |d| d.date }.reverse.first\n end",
"def closest_available_date(d... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
resource_card helper this helper render a very elegant presentation card for a resource. | def resource_card(&block)
concat(show_section_label, block.binding)
concat('<div class="resource-card">', block.binding)
yield
concat('</div>', block.binding)
concat('<div style="clear:both;"></div>', block.binding)
end | [
"def display(resource, given_options={})\n controller.render given_options.merge!(options).merge!(format => resource)\n end",
"def display(resource, given_options = {})\n controller.render given_options.merge!(options).merge!(format => resource)\n end",
"def card(resource_id, gateway_code, data ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
field_block helper Use this helper to set a two column fieldset layout for an admin form. usage: in a _form.html.erb note: this two input boxes will be rendered in a single row | def field_block(cols = 2, &block)
css_class = "float_left"
css_class << "_#{cols}" unless cols == 2
concat('<div class="'+ css_class +'">', block.binding)
yield
concat('</div>', block.binding)
concat('<div style="clear:both;"></div>', block.binding)
end | [
"def field_block(cols = 2, &block)\n css_class = \"float_left\"\n css_class << \"_#{cols}\" unless cols == 2\n concat('<div class=\"'+ css_class +'\">', block.binding)\n yield\n concat('</div>', block.binding)\n concat('<div style=\"clear:both;\"></div>... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Add a spinner, hidden by default, with the specified id. | def spinner(spinner_id = :spinner, hidden = true)
options = {:id => spinner_id}
options.merge!(:style => 'display:none') if hidden
image_tag('admin_ui/indicator.gif', options)
end | [
"def spinner(spinner_id = :spinner, hidden = true)\n options = {:id => spinner_id}\n options.merge!(:style => 'display:none') if hidden\n image_tag('admin_ui/indicator.gif', options)\n end",
"def loading_with_spinner(spinner_id, options)\n options.merge(\n :loading => \"$('#{spinner... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Provide options for ajax helpers with default loading and complete options. ==== Example observe_field(:some_field_id, loading_with_spinner(:spinner_id, :url => update_path, :with => 'value') the loading_with_spinner helper will add loading and complete actions to the observe_field options to show and hide the spinner ... | def loading_with_spinner(spinner_id, options)
options.merge(
:loading => "$('#{spinner_id}').show(); #{options[:loading]}",
:complete => "$('#{spinner_id}').hide(); #{options[:complete]}"
)
end | [
"def loading_with_spinner(spinner_id, options)\n options.merge(\n :loading => \"$('#{spinner_id}').show(); #{options[:loading]}\",\n :complete => \"$('#{spinner_id}').hide(); #{options[:complete]}\"\n )\n end",
"def ajax_busy_options(element_id)\n {:loading => \"load_busy($('#{eleme... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Method goes through board array and checks each position in the array, and adds to the amount of turns played if the checked position isn't blank. | def turn_count
turns_played = 0
@board.each do |index|
if index != " "
turns_played += 1
end
end
return turns_played
end | [
"def turn_count\n counter = 0\n @board.each_with_index {|space, index| counter += 1 if self.position_taken?(index)}\n counter\n end",
"def turn_count\n @board.count{|position| position != \" \"}\n end",
"def turn_count\n turns = 0\n @board.each do |spot|\n if spot==\"X\" || spot==... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Method that checks if the game is over by checking the return values of the won? and draw? method to see whether they're true or false. | def over?
won = won?()
draw = draw?()
# Due to the won? method never explicitly returning a true value,
# the program must instead check if it isn't false.
if draw == true || won != false
return true
else
return false
end
end | [
"def game_over?\r\n won? || draw?\r\n end",
"def game_over?\n draw? || won?\n end",
"def game_is_over?\n (won? || draw? || full?) ? true : false\n end",
"def game_over?\n @win.update_board(@board.game_board) # update the @win object's board for evaluation\n @win.x_won? || @win.o_won? ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Creates new `Author` from Ravelry API PatternAuthor attributes. All class variables are readonly. | def initialize(pattern_author)
@id = pattern_author[:id]
@name = pattern_author[:name]
@permalink = pattern_author[:permalink]
@patterns_count = pattern_author[:patterns_count]
@favorites_count = pattern_author[:favorites_count]
end | [
"def to_author_attributes\n ScienceWire::AuthorAttributes.new(\n Agent::AuthorName.new(last_name, first_name, middle_name),\n email,\n # there is no seed list for AuthorIdentity because it is not needed for dumb search\n # but there is a seed list that can come from Author#approved_sciencewir... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
return [String] branch_of_service code and rank_code joined with ':' | def id
branch_of_service_code + ':' + rank_code
end | [
"def id\n branch_of_service_cd + ':' + military_rank_detail[:rank_code]\n end",
"def bic_with_branch_code\n if self.bic.length == 8\n return \"#{self.bic}XXX\"\n else\n return self.bic\n end\n end",
"def rank_to_s\n\t\t\tRankingName[rank]\n\t\tend",
"def human_friendly_... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Perform mesh refinement by adding new vertex points to the tiles, curvature for which exceeds provied max_curvature value. To reach desired smoothness you need repeatedly call this function until amount of tiles that were split (returned by this function ) is zero. Alternatively you can call '' | def refine(max_curvature)
@nvariance_limit = max_curvature
refined = 0
tiles_to_split=[]
@tiles.each { |i, t|
nvr = t.value.nvariance()
if nvr[1] > max_curvature
# Something needs to be split, either this tile or its counterpart which gives
# us highest nva... | [
"def update_mesh\r\n Console.log( 'BezierSurface.update_mesh' )\r\n d = TT::Instance.definition( @instance )\r\n transformation = d.model.edit_transform\r\n subdivisions = final_subdivs()\r\n # Init a PolygonMesh with an rough geometry estimate for best performance.\r\n points = count_... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
of refine(...) Same as 'refine(max_curvature)', but will contain recursively until maximum tile curvature falls bellow max_curvature | def refine_recursively(max_curvature)
refined = self.refine(max_curvature)
while refined > 0
if not @iter_callback.nil?
@iter_callback.call(self, refined)
end
refined = self.refine(max_curvature)
end
if not @iter_callback.nil?
# last callback ca... | [
"def refine(max_curvature)\n @nvariance_limit = max_curvature\n refined = 0\n tiles_to_split=[]\n @tiles.each { |i, t| \n nvr = t.value.nvariance()\n if nvr[1] > max_curvature \n # Something needs to be split, either this tile or its counterpart which gives \n # u... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Find all nearby tiles connected to this one through the common edges ( up to three tiles ) and for each tile calculate cross product between normal vectors of this tile and nearby ones. Find the one that give maximum of these three cross products by absolute value and return array where first element is adjacent tile t... | def nvariance(debug=false)
nv0 = self.normal_vector
all_near_by_tiles = []
all_near_by_tiles << ( @grd.vtxs[vtx[0]-1].tiles & @grd.vtxs[vtx[1]-1].tiles )
all_near_by_tiles << ( @grd.vtxs[vtx[0]-1].tiles & @grd.vtxs[vtx[2]-1].tiles )
all_near_by_tiles << ( @grd.vtxs[vtx[1]-1].tiles & @grd.v... | [
"def refine(max_curvature)\n @nvariance_limit = max_curvature\n refined = 0\n tiles_to_split=[]\n @tiles.each { |i, t| \n nvr = t.value.nvariance()\n if nvr[1] > max_curvature \n # Something needs to be split, either this tile or its counterpart which gives \n # u... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Two tiles are equal when their vertixes are geometrically equal. | def ==(tile)
self.vtx == tile.vtx
end | [
"def is_tile_flipped_v?(x, y)\n false\n end",
"def ==( other_square )\n column == other_square.column and row == other_square.row\n end",
"def is_tile_flipped_h?(x, y)\n false\n end",
"def test_for_equality_of_two_dead_grids\n grid1 = Grid.new\n grid2 = Grid.new\n assert_e... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
If curvature returned by nvariance() is greater then some prescribed value then this method can be called to split this tile by adding new vertex and optionally evaluate value at that new vertex | def split(evaluate=false)
@inspect = false # no more ispection for this tile
l=[0,1,2].map { |m|
((m+1)..2).to_a.map { |n|
(@grd.vtxs[@vtx[m]-1].x-@grd.vtxs[@vtx[n]-1].x)**2+(@grd.vtxs[@vtx[m]-1].y-@grd.vtxs[@vtx[n]-1].y)**2
}
}.flatten.each_with_index.max[1]
# intr... | [
"def refine(max_curvature)\n @nvariance_limit = max_curvature\n refined = 0\n tiles_to_split=[]\n @tiles.each { |i, t| \n nvr = t.value.nvariance()\n if nvr[1] > max_curvature \n # Something needs to be split, either this tile or its counterpart which gives \n # u... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Check if the user is authorized. Override this method in your controllers if you want to restrict access to only a few actions or if you want to check if the user has the correct rights. Example: only allow nonbobs def authorize?(user) user.login != "bob" end | def authorized?(user)
true
end | [
"def authorized?(user)\n return true\n end",
"def authorize?(user)\n true\n end",
"def authorize?(user)\n user.admin? or user.invited?\n end",
"def valid_user? #:doc:\n if require_admin_for_request?\n authorize! true\n elsif require_anon_for_request?\n if logged_in?\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Filter method to enforce a login requirement. To require logins for all actions, use this in your controllers: before_filter :login_required To require logins for specific actions, use this in your controllers: before_filter :login_required, :only => [ :edit, :update ] To skip this in a subclassed controller: skip_befo... | def login_required
# Skip this filter if the requested action is not protected
return true unless protect?(action_name)
# Check if user is logged in and authorized
return true if logged_in? and authorized?(current_user)
# Store current location so that we can redirect back after login
store_lo... | [
"def login_required\n login_by_token unless logged_in?\n login_by_basic_auth unless logged_in?\n access_denied unless logged_in? && authorized?\n end",
"def login_required\n call(Rs(:login)) unless logged_in?\n end",
"def check_if_login_required\r\n require_login if Setting.log... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Instance Methods returns true if this instance has a maintenance schedule, false otherwise | def has_maintenance_schedules?
maintenance_schedules.count > 0
end | [
"def in_scheduled_maintenance?\n @redis.exists(\"#{@key}:scheduled_maintenance\")\n end",
"def in_unscheduled_maintenance?\n @redis.exists(\"#{@key}:unscheduled_maintenance\")\n end",
"def has_schedule?\n self.schedule != nil\n end",
"def schedules?\n self.schedules.any?\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
value of assignments amounts must total the amount of the bill | def validate_assignments
assignments.sum(:amount_in_cents) == self[:amount_in_cents]
end | [
"def invoice_value_calculation\n val = 0\n self.batches.each do |b|\n next if b._destroy == true\n val += (b.qty * b.rate) if b.qty and b.rate\n end\n\n if val != self.invoice_value\n errors.add(:invoice_value, \"entered - #{self.invoice_value} and total - #{val} do not tally\")\n end\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Wrap resource into Reform::Form if needed | def apply_form(resource)
if apply_form?
form = form_class.new(resource)
form.prepopulate! if prepopulate_form?
form
else
resource
end
end | [
"def apply_form(resource)\n apply_form? ? form_class.new(resource) : resource\n end",
"def to_resource(mapper)\n Resource::Form::Field.new(\n resource_attributes.each_with_object({}) do |attr, attrs|\n attrs[attr] = mapper.expand_value(public_send(attr))\n end.m... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Public: Provides a configuration option that sets the key_path Examples AWS::CF::Signer.configure do |config| config.key_path = "/path/to/your/keyfile.pem" end Returns nothing. | def key_path=(path)
raise ArgumentError.new("The signing key could not be found at #{path}") unless File.exists?(path)
@key_path = path
self.key=(File.readlines(path).join(""))
end | [
"def key_path=(path)\n unless File.exist?(path)\n fail ArgumentError,\n \"The signing key could not be found at #{path}\"\n end\n @key_path = path\n self.key = File.readlines(path).join('')\n end",
"def keypair_path\n options.keypair_pat... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Public: Provides an accessor to the key_path Returns a String value indicating the current setting | def key_path
@key_path
end | [
"def key_path\n return @key_path\n end",
"def key_path=(value)\n @key_path = value\n end",
"def key \n path\n end",
"def key_path; end",
"def fetch_key_path(key)\n ['keys', key].join('/')\n end",
"def key_name\n @config.key_nam... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Public: Provides a configuration option that sets the default_expires in seconds Examples AWS::CF::Signer.configure do |config| config.default_expires = 3600 end Returns nothing. | def default_expires=(value)
@default_expires = value
end | [
"def default_expires\n @default_expires ||= 3600\n end",
"def set_expires_at\n self[:expires_at] = case self.expiry_option \n when :in then Time.now.utc + (self.expiry_days || DEFAULT_EXPIRY_DAYS).days\n when :on then self[:expires_at]\n else self[:expires_at]\n end\n end",
... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Public: Provides an accessor to the default_expires value Returns an Integer value indicating the current setting (seconds) | def default_expires
@default_expires ||= 3600
end | [
"def default_expires=(value)\n @default_expires = value\n end",
"def default_expire=(value)\n raise ArgumentError, \"#{name}.default_expire value must be greater than 0\" unless (value = value.to_f) > 0\n @@default_expire = value\n end",
"def getExpiration; @expires; end... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /reservations/new GET /reservations/new.json | def new
@reservation = Reservation.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @reservation }
end
end | [
"def new\n @reserv = Reserv.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @reserv }\n end\n end",
"def new\n @reservations_table = ReservationsTable.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render jso... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Syncs up the milestone with lighthouse updates | def sync_with_lighthouse
results = Lighthouse.get_milestone(self.remote_id, self.project.remote_id, self.project.token.account, self.project.token.token)
return false unless milestone = results["milestone"]
self.update(:name => milestone["title"], :due_on => milestone["due_on"], :tickets_count => mile... | [
"def sync_with_lighthouse\n results = Lighthouse.get_milestone(self.remote_id, self.project.remote_id, self.project.token.account, self.project.token.token)\n return false unless milestone = results[\"milestone\"]\n self.update_attributes(:name => milestone[\"title\"], :due_on => milestone[\"due_on\"... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Coding 1 Here num1 and num2 will be added by using my_result method | def add(num1, num2)
my_result = (num1 + num2)
end | [
"def plus\n \tget_nums do |n1, n2| \n \t\t@result = n1 + n2\n \t\t@calculator << @result \n \tend\n end",
"def print_two_numbers_result(number_1, operation, number_2, result)\n\tputs \"Here is your result:\"\n\tputs number_1.to_s + operation.to_s + number_2.to_s + \" = \" + result.to_s\nend",
"def add_toge... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /korans POST /korans.json | def create
@koran = Koran.new(koran_params)
respond_to do |format|
if @koran.save
format.html { redirect_to @koran, notice: 'Koran was successfully created.' }
format.json { render :show, status: :created, location: @koran }
else
format.html { render :new }
format.js... | [
"def create\n @koans = Koan.all\n @koan = Koan.new(koan_params)\n\n respond_to do |format|\n if @koan.save\n format.html { redirect_to @koan, notice: 'Koan was successfully created.' }\n format.json { render :show, status: :created, location: @koan }\n else\n format.html { re... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /korans/1 PATCH/PUT /korans/1.json | def update
respond_to do |format|
if @koran.update(koran_params)
format.html { redirect_to @koran, notice: 'Koran was successfully updated.' }
format.json { render :show, status: :ok, location: @koran }
else
format.html { render :edit }
format.json { render json: @koran.e... | [
"def update\n @koans = Koan.all\n respond_to do |format|\n if @koan.update(koan_params)\n format.html { redirect_to @koan, notice: 'Koan was successfully updated.' }\n format.json { render :show, status: :ok, location: @koan }\n else\n format.html { render :edit }\n forma... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns array of permitted events | def permitted_events
events = self.states_events_config.map { |se| se[:event] }
events.delete_if { |e| !event_permitted(e) }
end | [
"def available_events\n\t\treturn current_room.events || []\n\tend",
"def event_list\n @_events\n end",
"def events\n @events ||= Array(context[:events]).reverse.map { |event| Concierge::SafeAccessHash.new(event) }\n end",
"def events\n return @events\n end",
"d... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Triggers an event, moving record to associated state, if permitted Returns false if event not permitted | def trigger(event, metadata={})
if (event_permitted(event) || User.is_admin?(metadata[:user_id])) &&
required_metadata_present?(event, metadata)
to_state = self.event_to_state(event)
callback_metadata = metadata.clone
transition_to(to_state, metadata)
if respond_to?(:even... | [
"def save_event?(event)\n event.save\n end",
"def transition_allowed?(event)\n allowed = case event\n when :charge\n [ :pending, :failed, :unpaid ].include?(self.state.to_sym)\n when :generate_pdf\n true\n else\n s... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Triggers an event, moving record to associated state, if permitted Raises exception if event is not permitted | def trigger!(event, metadata={})
if !trigger(event, metadata)
raise StateTransitionException::TransitionNotPermitted
end
end | [
"def execute_workflow_event(resource, event)\n redirect_state = resource.workflow_state\n resource.send(\"#{event}!\")\n redirect_to url_for([:admin, resource.class, workflow_state: redirect_state]), notice: I18n.t('shared.saved')\n rescue Workflow::NoTransitionAllowed\n redirect_to url_for([... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Return all prior state transitions for the record | def state_transitions
StateTransition.where(record_id: id, record_type: self.class.to_s).order(id: :desc)
end | [
"def transitions(curr_state = nil, **)\n curr_state = state_value(curr_state)\n next_states = state_table.dig(curr_state, :next)\n Array.wrap(next_states).compact_blank\n end",
"def transitions\n @transitions ||= []\n end",
"def history\n transition_data = lambda do |state_transition|\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the last (most recent) state transition for the record | def last_transition
StateTransition.where(record_id: id, record_type: self.class.to_s).order(id: :desc).limit(1).first
end | [
"def last_transition_to(to_state)\n StateTransition.where(record_id: id, record_type: self.class.to_s, to_state: to_state.to_s).order(id: :desc).limit(1).first\n end",
"def last_state\n self[-2]\n end",
"def last_state_change\n if self.alive? and @thread.key?(:last_state_change)\n return... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the last (most recent) state transition that moved the record to the given state | def last_transition_to(to_state)
StateTransition.where(record_id: id, record_type: self.class.to_s, to_state: to_state.to_s).order(id: :desc).limit(1).first
end | [
"def last_transition\n StateTransition.where(record_id: id, record_type: self.class.to_s).order(id: :desc).limit(1).first\n end",
"def last_state\n self[-2]\n end",
"def last_transition_before(*to_state)\n not_in_fragment = \"'#{to_state.map { |x| x.to_s }.join(\"','\")}'\"\n StateTransiti... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the last state transition prior to the record moving to the given state | def last_transition_before(*to_state)
not_in_fragment = "'#{to_state.map { |x| x.to_s }.join("','")}'"
StateTransition.where(record_id: id, record_type: self.class.to_s).where("to_state NOT IN (#{ not_in_fragment })").order(id: :desc).limit(1).first
end | [
"def last_state\n self[-2]\n end",
"def last_transition_to(to_state)\n StateTransition.where(record_id: id, record_type: self.class.to_s, to_state: to_state.to_s).order(id: :desc).limit(1).first\n end",
"def get_predecessor(state)\n return @trace_map[state]\n end",
"def last_transition\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the record's current state | def current_state
current = StateTransition.where(record_id: id, record_type: self.class.to_s, current: true).order(id: :desc).limit(1).first
if current
current.to_state.to_sym
else
self.initial_state.to_sym
end
end | [
"def state\n return @state\n end",
"def current_state\r\n self.send(self.class.state_column).to_sym\r\n end",
"def get_workflow_state(rec = nil)\n (rec || record)&.get_state(workflow_column)&.to_s\n end",
"def read_state()\n #This is a stub, used fo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns true if the current state is at or after the given state in the workflow | def state_reached?(state)
states = states_events.map { |se| se[0] }
if states.index(current_state) && states.index(state)
states.index(current_state) >= states.index(state)
end
end | [
"def in_or_after_state?(test_state)\n return false if test_state.nil? || self.state.nil?\n test_state = test_state.to_sym\n my_state = self.state.to_sym\n\n # Get all the states that are in and after the state we want to check (test_state),\n # and then see if the vehicle's current state is in that l... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Transition record to given state, creating a new StateTransition record | def transition_to(to_state, metadata={})
if last_transition
last_transition.update_attributes(current: false)
end
from_state = last_transition ? last_transition.to_state : nil
# remove request if included in metadata
if metadata && metadata[:request]
metadata.delete(:reques... | [
"def to_transition\n Transition.new(to_struct)\n end",
"def local_transition!(state:)\n Mua::State::Transition.new(state: state, parent: false)\n end",
"def transition_state_machine!(new_state, emit_params = {})\n state_machine.transition_to!(new_state, emit_object(new_state, emit_params))\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
filtering selected locations accordind to attributes values eg. "/locations?city=london&name=Eye" | def filter_locations
allowed_keys=["name", "city", "user_id", "area_tl", "area_br"]
filtering_keys=allowed_keys & params.keys
filtering_keys.each {|key| filter_by_key(key)}
end | [
"def filter\n @drives = Drive.all\n @user = current_user\n if(params[:city]==\"StLouis\")\n @city = \"St. Louis\"\n else\n @city = params[:city]\n end\n end",
"def search_by_location\n location_list\n puts \"SELECT A LOCATION TO SEE ALL PRODUCTS IN THAT LOCATION(USE ID)\"\n sea... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
restrict returned locations according to "limit=5" and "offset=100" no default pagination implemented | def limit_locations
@locations=@locations.offset(params[:offset]) if params[:offset].present?
@locations=@locations.limit(params[:limit]) if params[:limit].present?
end | [
"def locations(limit = 5)\n Location.where(locatable_type: self.class.to_s, locatable_id: self.id, geocoded: false).order(\"id DESC\").limit(limit)\n end",
"def limit_and_offset\r\n if query_params[:offset].present?\r\n @offset = query_params[:offset].to_i\r\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Check HTTP request status and raise an exception if needed | def validate_http_status
return true if @http.code.to_i == 200
DomainTools::Exceptions::raise_by_code(@http.code)
end | [
"def is_http_error response\n\treturn (response.code.to_i) / 100 != 2\nend",
"def http_error?\n !(200..299).include?(http_code)\n end",
"def bad_request?\n status == 400\n end",
"def on_http_error(status, content)\n raise \"HTTP error #{status}\"\n end",
"def http_error?\n !... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Create tracklist files for every arguments | def run
@files.each do |file|
generate_tracklist(file)
end
end | [
"def make_file_list()\n\n\t\tres = `camput permanode -title=\"filetypes\"`\n\t\tsha = res.split(\"\\n\")[0]\n\n\t\tset_attributes(sha, 'audio', 'mp3')\n\t\tset_attributes(sha, 'audio', 'wav')\n\t\tset_attributes(sha, 'document', 'doc')\n\t\tset_attributes(sha, 'document', 'pdf')\n\t\tset_attributes(sha, 'document',... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
get cache version from CDN | def get_cache_version
data = get_from_cdn('version', {t: Time.now.to_i}, {public: true, uncompressed: true})
unless data
Tml.logger.debug('No releases have been published yet')
return '0'
end
data['version']
end | [
"def version_for_cache\n \"download_url:#{source[:url]}|#{digest_type}:#{checksum}\"\n end",
"def version_for_cache\n if fetcher\n fetcher.version_for_cache || version\n else\n version\n end\n end",
"def fetch\n self.version = begin\n ver = cache.fetch(CACHE_V... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
trace api call for logging | def trace_api_call(path, params, opts = {})
if Tml.config.logger[:secure]
[:access_token].each do |param|
params = params.merge(param => "##filtered##") if params[param]
end
end
path = "#{path[0] == '/' ? '' : '/'}#{path}"
if opts[:method] == :post
Tml.logger.debug("post: #{o... | [
"def log_http_call(payload); end",
"def log_request; end",
"def __trace(method, path, params, body, url, response, json, took, duration)\n trace_url = \"http://localhost:9200/#{path}?pretty\" +\n ( params.empty? ? '' : \"&#{::Faraday::Utils::ParamsHash[params].to_query}\" )\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This method instructs the technician to image the given gel. | def image_gel gel, image_name
show do
title "Image gel #{gel}"
check "Clean the transilluminator with ethanol."
check "Put the gel #{gel} on the transilluminator."
check "Turn off the room lights before turning on the transilluminator."
check "Put the camera hood on, turn o... | [
"def pour_label_gels\n show do\n title \"Pour and label the gel(s)\"\n note \"Using a gel pouring autoclave glove, pour agarose from one flask into the casting tray. \n Pour slowly and in a corner for best results. Pop any bubbles with a 10 µL pipet tip. Repeat for each gel\"\n operatio... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This method tells the technician to verify fragment lengths for the given gel. | def check_frag_length gel, grouped_ops
show {
title "Verify Fragment Lengths for gel #{gel}"
table grouped_ops.start_table
.custom_column(heading: "Gel ID") { |op| op.input(FRAGMENT).item.id }
.custom_column(heading: "Row") { |op| op.input(FRAGMENT).row + 1 }
.custom_... | [
"def test_from_addr_length_valid\n\t\tblock = Block::new 0, \"0\", \"SYSTEM>Henry(100)\", \"1518892051.737141000\", \"1c12\"\n\t\ttransaction = Transaction::new \"SYSTEM\", \"Henry\", 100\n\t\tassert_equal 1, Verifier.check_from_addr_length(block, transaction)\n\tend",
"def test_to_addr_length_invalid\n\t\tblock ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This method instructs the technician to cut out fragments associated to the given operations. | def cut_fragments grouped_ops
show {
title "Cut Out Fragments"
check "Take out #{grouped_ops.length} 1.5 mL tubes and label accordingly: #{grouped_ops.map { |op| "#{op.output("Fragment").item}" }.to_sentence}"
check "Now, cut out the bands and place them into the 1.5 mL tubes according t... | [
"def discard_stripwells\r\n show do \r\n title \"Discard Stripwells\"\r\n note \"Discard all the empty stripwells\"\r\n operations.each do |op|\r\n #if op.input(\"Fragment\").item != nil\r\n op.input(\"Fragment\").item.mark_as_deleted\r\n #else\r\n # show do\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
This method instructs the technician to clean up and dispose of gels. | def clean_up gel, gels
show {
title "Clean Up"
check "Turn off the transilluminator."
check "Dispose of the gel #{gel} and any gel parts by placing it in the waste container. Spray the surface of the transilluminator with ethanol and wipe until dry using a paper towel."
check "Clea... | [
"def cleanup\n\t\t@spawners.cleanup\n\tend",
"def dispose\n @voronoi = nil\n @point = nil\n @index = nil\n @cells = nil\n @color = nil\n end",
"def dispose\n return if @ptr.nil?\n do_finalization\n C.dispose_pass_manager(@ptr)\n @ptr = nil\n end",
... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
=begin Updates the table cards if cards delt after a set result in no set being available. They are replaced. Written by: Sina =end | def updateTable(tableCards, deck)
while deck.deckSize!=0 && (tableCards.size<12 || findSets(tableCards).size==0)
tableCards.push(deck.dealCard!)
tableCards.push(deck.dealCard!)
tableCards.push(deck.dealCard!)
end
end | [
"def putOnTable\n # take the 12 cards on top of the deck and deal on \"table\"\n @cardsOnTable = @cards[0..11]\n 12.times{@cards.shift}\n end",
"def tablecards_alltaken\r\n @log.debug \"Player #{@lasttaken_player.name} take the rest on table: #{@lasttaken_cards.join(\",\")}\"\r\n @pl... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
find the category name corresponding to the given file path e.g. if input is /home/me/devel/amee/transport/car/generic, output is tranport/car/generic | def find_category(file)
file.match(Regexp.new(Regexp.escape(csv_root))) or
raise AMEEM::Exceptions::Location.new("#{file} is not in CSV tree")
file.sub(Regexp.new(Regexp.escape(csv_root)),"");
end | [
"def get_category_name(path)\n catname = \"\"\n\n curdir = path\n while !curdir.eql?(\"_posts\")\n catpath = curdir + \"/_category.yml\"\n n = File.basename(curdir)\n if File.exists?(catpath)\n category_info = YAML.load_file(catpath)\n n = catego... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Connects to the server on +host+ and +port+ with given connection timeout. | def connect(host, port, timeout)
conn = EventMachine.connect(host, port, ConnectionClient) do |c|
c.pending_connect_timeout = [Float(timeout), 0.1].max
end
setup_connect_callbacks(conn, Fiber.current)
end | [
"def connect_to(host, port, timeout=nil)\n addr = Socket.getaddrinfo(host, nil)\n sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)\n \n if timeout\n secs = Integer(timeout)\n usecs = Integer((timeout - secs) * 1_000_000)\n optval = [secs, usecs].pack(\"l_2\")\n sock.setsockopt ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Class initializer Can be initialized with WebdavApi's directory method or with Nextcloud::Webdav::Directory.new(...credentials...) | def initialize(args)
if args.class == Nextcloud::WebdavApi
@api = args
else
super
@api = self
end
@path = "/files/#{@api.username}"
end | [
"def directory\n Webdav::Directory.new(self)\n end",
"def webdav\n WebdavApi.new(url: @url, username: @username, password: @password)\n end",
"def webdav(args)\n WebdavApi.new(args)\n end",
"def initialize(args)\n if args.class == Nextcloud::WebdavApi\n @api = args\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Action links configured for the controller. | def action_links(action: nil, **opt)
opt[:action] = action || :index
config_lookup('action_links', **opt) || {}
end | [
"def add_default_action_items\n # New Link on all actions except :new and :show\n add_action_item :except => [:new, :show], :if => proc{ can?(:new, controller.resource_class) } do\n if controller.action_methods.include?('new')\n link_to(I18n.t('active_admin.new_model', :model => active_adm... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns GeoJSON representation of the polygon | def to_geojson
coordinates = @points.map { |point| [point.longitude, point.lattitude] }
{ 'type' => 'Polygon', 'coordinates' => [coordinates] }.to_json
end | [
"def polygon\n return { \"type\": \"Polygon\", \"coordinates\": [FakeGeo.latlon(rand(3..6))]}\n end",
"def to_geojson\n { 'type' => 'Feature',\n 'geometry' => { 'type' => 'Point',\n 'coordinates' => [@longitude, @lattitude] },\n 'properties' => { 'radius' => @... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
true if photoset named 'name' exists, false otherwise. | def photoset_exist? name
@flickr.photosets.getList.each do |x|
return true if x.title == name
end
return false
end | [
"def has_file(name)\n return !@files[name].nil?\n end",
"def has_photo?\n File.exists? photo_filename\n end",
"def has_photo?\n \tFile.exists? photo_filename\n end",
"def file_name_spec_set?\n not @file_name_spec.nil?\n end",
"def has_package_set?(name)\n each_package_se... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
f => path to file to upload photoset => photoset name | def upload f, photoset
return if !is_supported?(f)
id = @flickr.photos.upload.upload_file(f, f, "", Array.new,
false, false, false)
if photoset_exist? photoset
set_id = get_photoset_id(photoset)
@flickr.photosets.addPhoto set_id, id
else
@f... | [
"def upload_file( user, work, filename, title, visibility )\n\n print \"uploading #{filename}... \"\n\n fileset = ::FileSet.new\n fileset.title << title unless title.nil?\n file_actor = ::CurationConcerns::Actors::FileSetActor.new( fileset, user )\n file_actor.create_metadata( work )\n file_actor.... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /group_docs GET /group_docs.json | def index
@group_docs = GroupDoc.all
end | [
"def documents(params={})\n server.get(\"#{name}/_all_docs\", params)\n end",
"def index\n @documents = @group.main_folder\n \n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @documents }\n end\n end",
"def solr_docs_for_group(group_field, gro... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /group_docs POST /group_docs.json | def create
@group_doc = GroupDoc.new(group_doc_params)
respond_to do |format|
if @group_doc.save
format.html { redirect_to @group_doc, notice: 'Group doc was successfully created.' }
format.json { render :show, status: :created, location: @group_doc }
else
format.html { rend... | [
"def index\n @group_docs = GroupDoc.all\n end",
"def add_doc_to_group\n return if authorize_user_for_level(2) == false\n @document = DocumentRepository.find @doc\n return if @document == nil\n return if @document.author_credentials2['id'].to_i != @user.id\n group = \"#{@user.screen_name}_#{@to_... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /group_docs/1 PATCH/PUT /group_docs/1.json | def update
respond_to do |format|
if @group_doc.update(group_doc_params)
format.html { redirect_to @group_doc, notice: 'Group doc was successfully updated.' }
format.json { render :show, status: :ok, location: @group_doc }
else
format.html { render :edit }
format.json { r... | [
"def patch_group(group_id, request)\n start.uri('/api/group')\n .url_segment(group_id)\n .body_handler(FusionAuth::JSONBodyHandler.new(request))\n .patch()\n .go()\n end",
"def update\n respond_with Document.find(params[:id]).update_attributes(params[:doc... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /group_docs/1 DELETE /group_docs/1.json | def destroy
@group_doc.destroy
respond_to do |format|
format.html { redirect_to group_docs_url, notice: 'Group doc was successfully destroyed.' }
format.json { head :no_content }
end
end | [
"def destroy\n @document_group.destroy\n respond_to do |format|\n format.html { redirect_to dokumentit_path, notice: destroyed_message(@@object_type) }\n format.json { head :no_content }\n end\n end",
"def destroy\n @group = @dataset.groups.find(params[:id])\n @group.destroy\n\n respo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /m_answers GET /m_answers.json | def index
@m_answers = MAnswer.all
end | [
"def index\n\n @answers = Answer.current\n\n respond_to do |format|\n format.html # index.html.erb\n format.json { render json: @answers }\n end\n end",
"def index\n @answer_respondents = AnswerRespondent.all\n end",
"def get_answers_for\n user = current_user\n render_401 and retur... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /m_answers POST /m_answers.json | def create
@m_answer = @m_question.m_answers.build(m_answer_params)
respond_to do |format|
if @m_answer.save
format.html { redirect_to m_question_path(@m_question) }
format.json { render action: 'show', status: :created, location: @m_answer }
else
format.html { render action:... | [
"def create\n @test_answer = TestAnswer.new(test_answer_params)\n\n respond_to do |format|\n if @test_answer.save\n params[:questions].each do |question|\n answer = Answer.new\n answer.test_answer_id = @test_answer.id\n answer.question_id = question.first\n answ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /user_feedbacks GET /user_feedbacks.json | def index
@user_feedbacks = UserFeedback.all
end | [
"def index\n @userfeedbacks = Userfeedback.all\n end",
"def index\n authorize! :read_feedbacks, @outlet\n @feedbacks = @outlet.get_feedbacks(params)\n render json: @feedbacks\n end",
"def show\n @user_feedback = UserFeedback.find(params[:id])\n\n respond_to do |format|\n format.html # s... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /user_feedbacks POST /user_feedbacks.json | def create
@user_feedback = UserFeedback.new(user_feedback_params)
respond_to do |format|
if @user_feedback.save
format.html { redirect_to @user_feedback, notice: 'User feedback was successfully created.' }
format.json { render :show, status: :created, location: @user_feedback }
els... | [
"def create\n @user_feedback = UserFeedback.new(params[:user_feedback])\n\n respond_to do |format|\n if @user_feedback.save\n format.html { redirect_to @user_feedback, notice: 'User feedback was successfully created.' }\n format.json { render json: @user_feedback, status: :created, location... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /user_feedbacks/1 PATCH/PUT /user_feedbacks/1.json | def update
respond_to do |format|
if @user_feedback.update(user_feedback_params)
format.html { redirect_to @user_feedback, notice: 'User feedback was successfully updated.' }
format.json { render :show, status: :ok, location: @user_feedback }
else
format.html { render :edit }
... | [
"def update\n @user_feedback = UserFeedback.find(params[:id])\n\n respond_to do |format|\n if @user_feedback.update_attributes(params[:user_feedback])\n format.html { redirect_to @user_feedback, notice: 'User feedback was successfully updated.' }\n format.json { head :no_content }\n el... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /user_feedbacks/1 DELETE /user_feedbacks/1.json | def destroy
@user_feedback.destroy
respond_to do |format|
format.html { redirect_to user_feedbacks_url, notice: 'User feedback was successfully destroyed.' }
format.json { head :no_content }
end
end | [
"def destroy\n @user_feedback = UserFeedback.find(params[:id])\n @user_feedback.destroy\n\n respond_to do |format|\n format.html { redirect_to user_feedbacks_url }\n format.json { head :no_content }\n end\n end",
"def destroy\n @user_feedback.destroy\n respond_to do |format|\n fo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /admin_mbooks/new GET /admin_mbooks/new.xml | def new
@mbook = Admin::Mbook.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @mbook }
end
end | [
"def new\n @admin_book = Book.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @admin_book }\n end\n end",
"def new\n @bookshelf = Bookshelf.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @boo... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /admin_mbooks POST /admin_mbooks.xml | def create
@mbook = Admin::Mbook.new(params[:mbook])
respond_to do |format|
if @mbook.save
flash[:notice] = 'Admin::Mbook was successfully created.'
format.html { redirect_to(@mbook) }
format.xml { render :xml => @mbook, :status => :created, :location => @mbook }
else
... | [
"def new\n @mbook = Admin::Mbook.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.xml { render :xml => @mbook }\n end\n end",
"def create\n puts_message \"Create Mbook process has start!\"\n \n @mbook = Mbook.new()\n # @mbook.category_id = params[:category_id]\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Inserts a string at a cursor | def insert(cursor, string)
string.split(Pattern).each_with_index do |str, i|
if i.even?
cursor.insert_text str
else
enable_ansi_code(cursor, str)
end
end
end | [
"def insert(chars)\n self[@cursor] = chars\n end",
"def insert_text_at_cursor(text) \n\t\tinsert_text(@cursor_row, @cursor_col, text)\n\t\n\t\tif text.include?(\"\\n\")\n\t\t\t#todo what about multiple \\n's\n\t\t\t@cursor_row += 1\n\t\t\t@cursor_col = 0\n\t\t\t#resize_contents(500, line_num_to_coord(... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Initialize all Locations' paths (ABC size is pretty big, but can't get around it) | def init_paths(locations)
locations['Enumerable Canyon'].add_paths_to(locations['Duck Type Beach'],
locations['Monkey Patch City'])
locations['Duck Type Beach'].add_paths_to(locations['Enumerable Canyon'],
locations['M... | [
"def initialize_paths\n paths = Struct.new(:root).new\n paths.root = File.dirname(__FILE__)\n paths\n end",
"def initial_paths; end",
"def path_maps() = @path_maps ||= []",
"def initialize_fringe\n [{\n city: @initial,\n path: [@initial],\n depth: 1,\n cost: ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Prints found rubies with correct grammar | def ruby_format_print(rubies)
real_ruby_noun = (rubies[0] > 1 ? 'rubies' : 'ruby')
fake_ruby_noun = (rubies[1] > 1 ? 'fake rubies' : 'fake ruby')
pri = ''
if rubies[0] > 0 && rubies[1] > 0
pri += "\tFound #{rubies[0]} #{real_ruby_noun} and #{rubies[1]} #{fake_ruby_noun} in #{@current_location.name... | [
"def puts_grammar(cnf)\n\t\tcnf.each {|state, production| puts \"#{state} => #{production}\"}\n\t\tprint \"\\n\"\n\tend",
"def test_display_one\r\n assert_output(\"After 2 days, Rubyist #1 found:\\n\\t1 ruby.\\n\\t1 fake ruby.\\n\") { @g.display_rubies(1, 1, 1, 2) }\r\n end",
"def print\n # -> uncommen... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Construct a thumbnail URI from a CONTENTdm object URI. This method assumes that it receives a URI as returned from CONTENTdm's OAIPMH provider. Adapted from | def cdm_thumbnail(uri, responsive: true)
return uri.gsub('cdm/ref', 'digital/api/singleitem') + '/thumbnail' if uri.include?('cdm/ref') && responsive
return uri.gsub('cdm/ref', 'utils/getthumbnail') if uri.include?('cdm/ref')
# if `digital` is in the URI it's already served in the responsive UI
... | [
"def thumbnail_url_for( media, height = 150, width = 185)\n url = nil\n if media.thumbnail_url.blank? == false\n # There is a custom url\n url = media.thumbnail_url\n elsif media.provider\n # Here, the url follows the pattern from the provider\n url = parse_variables_to_url(media.provid... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Undefine a previously defined throttle | def undefine_throttle(method_name)
rocket_job_throttles.delete_if { |throttle| throttle.method_name == method_name }
end | [
"def unthrottle\n mutex.synchronize do\n old_interval = throttled_interval\n throttles.pop.tap do |throttle|\n if throttle\n @future -= (old_interval - throttled_interval)\n end\n end\n end\n end",
"def undefine_batch_throttle(method... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Returns the matching filter, or nil if no throttles were triggered. | def rocket_job_evaluate_throttles
rocket_job_throttles.each do |throttle|
# Throttle exceeded?
next unless send(throttle.method_name)
logger.debug { "Throttle: #{throttle.method_name} has been exceeded. #{self.class.name}:#{id}" }
filter = throttle.filter
... | [
"def rate_filters(&blk)\n if block_given?\n self.rate_filters.select(&blk)\n else\n Thresholds.new(@thresholds.select{|t| t.class.to_s == \"Threshold::RateFilter\"})\n end\n end",
"def get_filter\n if params[:jobfilter] && filters.any? { |f| f.filter_id == params[:jobfilter] }\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PUT /actividades/1 PUT /actividades/1.xml | def update
@actividad = Actividad.find(params[:id])
respond_to do |format|
if @actividad.update_attributes(params[:actividad])
flash[:notice] = 'Actividad was successfully updated.'
format.html { redirect_to(@actividad) }
format.xml { head :ok }
else
format.html { r... | [
"def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post 'update', opts\n end",
"def update opts = {}\n opts[:headers] ||= {}\n opts[:headers]['Content-Type'] ||= 'text/xml'\n post opts.fetch(:path, update_path), opts\n end",
"def update\n @esta... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /liquidacions/1 GET /liquidacions/1.json | def show
@liquidacion = Liquidacion.find(params[:id])
#Obtengo todos los conceptos de la liquidacion
@concepto_liquidacion = ConceptoLiquidacion.select("*")
.joins('LEFT JOIN liquidacions ON liquidacions.id = concepto_liquidacions.liquidacion_id')
.joins('RIGHT JOIN conceptos ON conceptos.id = conc... | [
"def index\n @liquidacions = Liquidacion.all\n end",
"def index\n @liquidaciones = Liquidacion.all\n end",
"def show\n @liquidacion_comision = LiquidacionComision.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @liquidacion_comision... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /liquidacions/new GET /liquidacions/new.json | def new
@liquidacion = Liquidacion.new
#Levanto de conceptos, todos los conceptos que son requeridos para liquidacion de auxiliares
@conceptos = Concepto.where(:anhomes => 201407).order(:codigo_concepto)
respond_to do |format|
format.html # new.html.erb
format.json { render json: @... | [
"def create\n @liquidation = Liquidation.new(liquidation_params)\n\n respond_to do |format|\n if @liquidation.save\n format.html { redirect_to @liquidation, notice: 'Liquidation was successfully created.' }\n format.json { render :show, status: :created, location: @liquidation }\n else... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /liquidacions POST /liquidacions.json | def create
@liquidacion = Liquidacion.new(params[:liquidacion])
respond_to do |format|
if @liquidacion.save
calcular_conceptos(@liquidacion)
format.html { redirect_to @liquidacion, notice: 'Se ha creado una nueva liquidacion' }
format.json { render json: @liquidacion, st... | [
"def create\n @liquidation = Liquidation.new(liquidation_params)\n\n respond_to do |format|\n if @liquidation.save\n format.html { redirect_to @liquidation, notice: 'Liquidation was successfully created.' }\n format.json { render :show, status: :created, location: @liquidation }\n else... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PUT /liquidacions/1 PUT /liquidacions/1.json | def update
@liquidacion = Liquidacion.find(params[:id])
@liquidacion.update_attributes(params[:liquidacion])
#Elimino todos los conceptos incluidos en la liquidacion
@conceptos_liquidacion = ConceptoLiquidacion.where(:liquidacion_id => @liquidacion.id)
@conceptos_liquidacion.each do |co... | [
"def update\n respond_to do |format|\n if @liquidation.update(liquidation_params)\n format.html { redirect_to @liquidation, notice: 'Liquidation was successfully updated.' }\n format.json { render :show, status: :ok, location: @liquidation }\n else\n format.html { render :edit }\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /liquidacions/1 DELETE /liquidacions/1.json | def destroy
@liquidacion = Liquidacion.find(params[:id])
#Elimino todos los conceptos incluidos en la liquidacion
@conceptos_liquidacion = ConceptoLiquidacion.where(:liquidacion_id => @liquidacion.id)
@conceptos_liquidacion.each do |concepto|
concepto.destroy
end
@liquidacion.destroy
... | [
"def destroy\n @liquidation.destroy\n respond_to do |format|\n format.html { redirect_to liquidations_url, notice: 'Liquidation was successfully destroyed.' }\n format.json { head :no_content }\n end\n end",
"def destroy\n @liquidacion = Liquidacion.find(params[:id])\n @liquidacion.destr... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Calculo el total de la sumatoria de los elementos contenidos en el hash | def calcular_total hash
p hash.inject(0) { |sum, tuple| sum += tuple[1] }
end | [
"def total_sum\n total = 0\n self.purchases.each do |purchase|\n sum = 0\n purchase.items.each do |item|\n sum += item.amount\n end\n total += sum\n end\n total\n end",
"def total_students(hash)\n sum = 0\n hash.each { |co... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Some keys are system_names and they can have a '/' in them that causes creation of folders that are not sections in the CMS. Track the list of these folders so we can avoid false negatives on diff and upload | def build_implicit_folders_list(cms_list)
folder_list = {}
STDERR.puts "\n"
cms_list.each do |key, entry|
if key.include?(File::SEPARATOR)
Pathname.new(key).dirname.descend { |directory|
directory_name = directory.to_s
if directory_name =~ /[A-Z... | [
"def prepare_folders\n @folders = @folders.inject({}) do |acc, data|\n key, opts = data\n opts[:map_uid] = prepare_permission(:uid, opts)\n opts[:map_gid] = prepare_permission(:gid, opts)\n opts[:nfs_version] ||= 3\n\n # The poor man's UUID. An MD5 has... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /image_libraries GET /image_libraries.json | def index
@image_libraries = ImageLibrary.all
end | [
"def image_list\n @images = Picture.where(album_id: params[:album_id])\n respond_to do |format|\n format.json { render json: @images.to_json(methods: [:path])}\n end\n end",
"def index\n @libraries = Library.all\n\n respond_to do |format|\n format.html # index.html.erb\n format.json... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
POST /image_libraries POST /image_libraries.json | def create
@image_library = ImageLibrary.new(image_library_params)
respond_to do |format|
if @image_library.save
format.html { redirect_to @image_library, notice: 'Image library was successfully created.' }
format.json { render action: 'show', status: :created, location: @image_library }
... | [
"def create\n @image_library = ImageLibrary.new(image_library_params)\n\n respond_to do |format|\n if @image_library.save\n format.html { redirect_to @image_library, notice: 'Image library was successfully created.' }\n format.json { render :show, status: :created, location: @image_library ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PATCH/PUT /image_libraries/1 PATCH/PUT /image_libraries/1.json | def update
respond_to do |format|
if @image_library.update(image_library_params)
format.html { redirect_to @image_library, notice: 'Image library was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render ... | [
"def update\n respond_to do |format|\n if @image_library.update(image_library_params)\n format.html { redirect_to @image_library, notice: 'Image library was successfully updated.' }\n format.json { render :show, status: :ok, location: @image_library }\n else\n format.html { render ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
DELETE /image_libraries/1 DELETE /image_libraries/1.json | def destroy
@image_library.destroy
respond_to do |format|
format.html { redirect_to image_libraries_url }
format.json { head :no_content }
end
end | [
"def destroy\n @image_library.destroy\n respond_to do |format|\n format.html { redirect_to image_libraries_url, notice: 'Image library was successfully destroyed.' }\n format.json { head :no_content }\n end\n end",
"def delete_floor_plan(args = {}) \n delete(\"/files.json/floorplan/images\", a... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Create a Hash representing the Solr doc to be written to Solr, based on MODS and public_xml | def doc_hash
@doc_hash ||= begin
doc_hash = GDor::Indexer::SolrDocHash.new id: resource.bare_druid, modsxml: smods_rec.to_xml
hash_from_mods = doc_hash_from_mods # defined in gdor_mods_fields
doc_hash.merge!(hash_from_mods) if hash_from_mods
doc_hash
end
end | [
"def to_solr(solr_doc = Hash.new())\n super(solr_doc) # Run the default solrization behavior\n\n # Extract a creation year field\n if self.origin_info.copyright.any? && !self.origin_info.copyright.first.blank?\n creation_date = self.origin_info.copyright.first\n solr_doc[\"creation_year... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
the public_xml for the druid as a Nokogiri::XML::Document object | def public_xml
resource.public_xml
end | [
"def public_xml(druid)\n Harvestdor.public_xml(druid, config.purl)\n end",
"def get_xml_document\n Nokogiri::XML(self.body)\n end",
"def document\n @doc ||= Nokogiri::XML(@xml)\n end",
"def doc\n @doc ||= Nokogiri::XML(@xml)\n end",
"def xml_document\n xml = XML::Document.new\... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Collection resource methods here gets involved from index when the user has requested to associate pictures with specific trees uses a hidden field called selected_tree to hold the tree id. | def selected_trees
Rails.logger.info(">>>Selected Tree #{params.inspect}")
if Pictureandmeta.add_assigned_pics(params['selected_tree'], params['add_to'])
flash[:notice] = "Successfully added sslected pictures."
else
flash[:notice] = "Pictures not added due to error."
end
redirect_to :con... | [
"def selected_trees\n Rails.logger.info(\">>>Selected Tree #{params.inspect}\")\n if Picture.add_assigned_pics(params['selected_tree'], params['add_to'])\n flash[:notice] = \"Successfully added selected pictures.\"\n else\n flash[:notice] = \"Pictures not added due to error.\"\n end\n redir... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
A PUT Resource that is called, currently, to remove a tree reference from a Picture. IN: id of picture, id of tree | def assignedtrees
@pictureandmeta = Pictureandmeta.find(params)
@pictureandmeta.delete_assigned_pics(params[:tree])
redirect_to :controller => 'trees', :action => 'show', :id => params[:tree]
end | [
"def picture_remove\n picture = Picture.find(params[:picture_id])\n @collection.pictures.delete(picture)\n end",
"def remove_picture(picture)\n end",
"def destroy\n @picture = Picture.find(params[:id])\n @picture.destroy\n render :json => true\n end",
"def remove_avatar\n getProfile\n ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
sanitize the select options for insert select | def sanitize_select_options(options)#:nodoc:
o = options.dup
select = o.delete :select
o[:override_select] = select ? select_column_sql(select) : ' * '
o
end | [
"def gather_insert_options(options)#:nodoc:\n into_options = valid_insert_select_options.inject(:command => 'INSERT') do |map, o|\n v = options.delete(o)\n map[o] = v if v\n map\n end\n end",
"def clean_select_items\n @cleaned_select_items = \"\"\n\n if selectitems... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
move all the insert options to a seperate map | def gather_insert_options(options)#:nodoc:
into_options = valid_insert_select_options.inject(:command => 'INSERT') do |map, o|
v = options.delete(o)
map[o] = v if v
map
end
end | [
"def extract_add_options(options)\n {\n \"id\" => options.delete(\"id\"),\n \"default\" => options.delete(\"default\") || false,\n \"next_style_id\" => options.delete(\"next_style\") || nil,\n \"base_style_id\" => options.delete(\"base_style\") || nil,\n \"assign_handle\" => ... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /unapproved_projects GET /unapproved_projects.xml | def index
@unapproved_projects = Project.unapproved
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @unapproved_projects }
end
end | [
"def show\n respond_to do |format|\n format.html # show.html.erb\n format.xml { render :xml => @unapproved_project }\n end\n end",
"def index\n @projects = @user.projects.drafts\n\n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @projects }\n... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
GET /unapproved_projects/1 GET /unapproved_projects/1.xml | def show
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @unapproved_project }
end
end | [
"def index\n @unapproved_projects = Project.unapproved\n \n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @unapproved_projects }\n end\n end",
"def index\n @resource_requests = @project.resource_requests\n\n respond_to do |format|\n format.h... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
PUT /unapproved_projects/1 PUT /unapproved_projects/1.xml | def update
respond_to do |format|
if @unapproved_project.approve
flash[:notice] = 'Project has been approved.'
format.html { redirect_to(unapproved_projects_path) }
format.xml { head :ok }
else
format.html { render :action => "show" }
format.xml { render :xml =>... | [
"def index\n @unapproved_projects = Project.unapproved\n \n respond_to do |format|\n format.html # index.html.erb\n format.xml { render :xml => @unapproved_projects }\n end\n end",
"def approve_project id\n get_request \"projects/#{id}/approve\"\n end",
"def update\n @pastproj... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
:callseq: starts_as(initial_state) > state_machine Put the +state_machine+ into the +initial_state+. | def starts_as(initial_state)
@current_state = initial_state
self
end | [
"def start_state_machine\n @current_state = self\n puts \"start state machine with #{@current_state.inspect}\"\n while !@current_state.done? && !@current_state.failed?\n begin\n @current_state = @current_state.enter()\n rescue Exception => e\n @current_state = FailedState.new(@conte... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Determine an appropriate default content_type for this part given the preferred handler_name, if possible. Considers any predefined set of values on the content_type attributge of the headers. | def derive_content_type(handler_name)
possible_values = if content_type.match 'text/plain'
_, content_type_attribute = headers_attribute&.attributes&.find { |k, _v| k.to_s =~ /^content[-_]{1}type$/i }
if content_type_attribute&.options&.key?(:values)
... | [
"def derive_content_type(handler_name)\n possible_values = if self.content_type.match 'text/plain'\n _, content_type_attribute = self.headers_attribute && self.headers_attribute.attributes.find { |k,v| k.to_s =~ /^content[-_]{1}type$/i }\n if content_type_attribute && content_type_attribute.optio... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Using the Ruby language, have the function PermutationStep(num) take the num parameter being passed and return the next number greater than num using the same digits. For example: if num is 123 return 132, if it's 12453 return 12534. If a number has no greater permutations, return 1 (ie. 999). Solution : | def PermutationStep(num)
possibilities = []
possibilities = num.to_s.chars.map(&:to_i).permutation.to_a
possibilities.reject! {|comb| comb.join.to_i <= num}
possibilities.map! {|comb| comb.join.to_i}
possibilities.empty? ? -1 : possibilities.min
end | [
"def permutation_step(num)\n digits = num.to_s.chars\n permutations = digits.permutation(digits.size).map(&:join).map(&:to_i).uniq.sort\n permutations.each do |permutation|\n return permutation if permutation > num\n end\n -1\nend",
"def PermutationStep(num)\n combos = num.to_s.split(\"\").map{|i|i.to_i}... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
waiting alert. Raise error if alert didn't appear | def wait_alert_accept_if_exist
sleep 1.5 #should wait animation
wait_true(timeout: 30, message: 'waiting alert dialog via wait_alert_accept_until_display_alert') {
execute_script('$.mainApp().alert().buttons().length > 0')
}
alert_accept_if_exist
end | [
"def tap_alert_if_exist(text)\n sleep 1.5 # wait for animation\n if wait_true(timeout: 30, message: \"failed to wait #{text} on alert with timeout\") {\n execute_script('$.mainApp().alert().buttons().length > 0') }\n execute_script(\"$.mainApp().alert().buttons()['#{text}'].tap();\")\n end\n end... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
ignore raise error when waiting alert ... | def ignore_wait_alert_accept_if_exist
begin
wait_alert_accept_if_exist
rescue
# nothing
end
end | [
"def wait_alert_accept_if_exist\n sleep 1.5 #should wait animation\n wait_true(timeout: 30, message: 'waiting alert dialog via wait_alert_accept_until_display_alert') {\n execute_script('$.mainApp().alert().buttons().length > 0')\n }\n alert_accept_if_exist\n end",
"def wait_for_alert(seconds)\r... | {
"objective": {
"paired": [],
"self": [],
"triplet": [
[
"query",
"document",
"negatives"
]
]
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.