_id
stringlengths 2
6
| title
stringlengths 9
130
| partition
stringclasses 3
values | text
stringlengths 30
4.3k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q2000
|
RTP.Record.delete_children
|
train
|
def delete_children(attribute)
self.send(attribute).each { |c| c.parent = nil }
|
ruby
|
{
"resource": ""
}
|
q2001
|
RTP.Record.set_attributes
|
train
|
def set_attributes(values)
import_indices([values.length - 1, @max_elements - 1].min).each_with_index do |indices, i|
param = nil
if indices
param = values.values_at(*indices)
param = param[0]
|
ruby
|
{
"resource": ""
}
|
q2002
|
RTP.Record.discard_unsupported_attributes
|
train
|
def discard_unsupported_attributes(values, options={})
case self
when SiteSetup
options[:version].to_f >= 2.6 ? values : values[0..-4]
when Field
options[:version].to_f >= 2.64
|
ruby
|
{
"resource": ""
}
|
q2003
|
Cfer.Config.include_config
|
train
|
def include_config(*files)
include_base = File.dirname(@config_file) if @config_file
files.each do |file|
path = File.join(include_base,
|
ruby
|
{
"resource": ""
}
|
q2004
|
RTP.Plan.write
|
train
|
def write(file, options={})
f = open_file(file)
|
ruby
|
{
"resource": ""
}
|
q2005
|
Cfer::Cfn.Client.tail
|
train
|
def tail(options = {})
q = []
event_id_highwater = nil
counter = 0
number = options[:number] || 0
for_each_event name do |fetched_event|
q.unshift fetched_event if counter < number
counter = counter + 1
end
while q.size > 0
event = q.shift
yield event
event_id_highwater = event.event_id
end
sleep_time = 1
running = true
if options[:follow]
while running
sleep_time = [sleep_time * (options[:backoff] || 1), options[:backoff_max_wait] || 15].min
begin
stack_status = describe_stacks(stack_name: name).stacks.first.stack_status
running = running && (/.+_(COMPLETE|FAILED)$/.match(stack_status) == nil)
yielding = true
for_each_event name do |fetched_event|
if event_id_highwater == fetched_event.event_id
yielding = false
end
if yielding
q.unshift fetched_event
|
ruby
|
{
"resource": ""
}
|
q2006
|
Cfer.Block.build_from_block
|
train
|
def build_from_block(*args, &block)
pre_block
Docile.dsl_eval(self, *args,
|
ruby
|
{
"resource": ""
}
|
q2007
|
RTP.Plan.add_angle
|
train
|
def add_angle(item, angle_tag, direction_tag, angle, direction, current_angle)
if !self.send(current_angle) || angle != self.send(current_angle)
self.send("#{current_angle}=", angle)
|
ruby
|
{
"resource": ""
}
|
q2008
|
RTP.Plan.add_couch_position
|
train
|
def add_couch_position(item, tag, value, current)
if !self.send(current) || value != self.send(current)
self.send("#{current}=", value)
|
ruby
|
{
"resource": ""
}
|
q2009
|
RTP.Plan.add_doserate
|
train
|
def add_doserate(value, item)
if !@current_doserate || value != @current_doserate
@current_doserate = value
|
ruby
|
{
"resource": ""
}
|
q2010
|
RTP.Plan.create_control_point
|
train
|
def create_control_point(cp, sequence, options={})
cp_item = DICOM::Item.new(:parent => sequence)
# Some CP attributes will always be written (CP index, BLD positions & Cumulative meterset weight).
# The other attributes are only written if they are different from the previous control point.
# Control Point Index:
DICOM::Element.new('300A,0112', "#{cp.index}", :parent => cp_item)
# Beam Limiting Device Position Sequence:
create_beam_limiting_device_positions(cp_item, cp, options)
# Source to Surface Distance:
add_ssd(cp.ssd, cp_item)
# Cumulative Meterset Weight:
DICOM::Element.new('300A,0134', cp.monitor_units.to_f, :parent => cp_item)
# Referenced Dose Reference Sequence:
create_referenced_dose_reference(cp_item) if options[:dose_ref]
# Attributes that are only added if they carry an updated value:
# Nominal Beam Energy:
add_energy(cp.energy, cp_item)
# Dose Rate Set:
add_doserate(cp.doserate, cp_item)
# Gantry Angle & Rotation Direction:
add_angle(cp_item, '300A,011E', '300A,011F', cp.gantry_angle, cp.gantry_dir, :current_gantry)
# Beam Limiting
|
ruby
|
{
"resource": ""
}
|
q2011
|
RTP.Plan.create_beam_limiting_devices
|
train
|
def create_beam_limiting_devices(beam_item, field)
bl_seq = DICOM::Sequence.new('300A,00B6', :parent => beam_item)
# The ASYMX item ('backup jaws') doesn't exist on all models:
if ['SYM', 'ASY'].include?(field.field_x_mode.upcase)
bl_item_x = DICOM::Item.new(:parent => bl_seq)
DICOM::Element.new('300A,00B8', "ASYMX", :parent => bl_item_x)
DICOM::Element.new('300A,00BC', "1", :parent => bl_item_x)
end
# The ASYMY item is always created:
bl_item_y = DICOM::Item.new(:parent => bl_seq)
# RT Beam Limiting Device Type:
DICOM::Element.new('300A,00B8', "ASYMY", :parent => bl_item_y)
# Number of Leaf/Jaw Pairs:
DICOM::Element.new('300A,00BC', "1", :parent => bl_item_y)
# MLCX item is only created if leaves are defined:
# (NB: The RTP file doesn't specify leaf position boundaries, so we
# have to set these based
|
ruby
|
{
"resource": ""
}
|
q2012
|
RTP.Plan.create_asym_item
|
train
|
def create_asym_item(cp, dcm_parent, axis, options={})
val1 = cp.send("dcm_collimator_#{axis.to_s}1", options[:scale])
val2 = cp.send("dcm_collimator_#{axis.to_s}2", options[:scale])
item = DICOM::Item.new(:parent => dcm_parent)
# RT
|
ruby
|
{
"resource": ""
}
|
q2013
|
RTP.Plan.create_dose_reference
|
train
|
def create_dose_reference(dcm, description)
dr_seq = DICOM::Sequence.new('300A,0010', :parent => dcm)
dr_item = DICOM::Item.new(:parent => dr_seq)
# Dose Reference Number:
DICOM::Element.new('300A,0012', '1', :parent => dr_item)
# Dose Reference Structure Type:
DICOM::Element.new('300A,0014', 'SITE', :parent => dr_item)
# Dose Reference Description:
|
ruby
|
{
"resource": ""
}
|
q2014
|
RTP.Plan.create_referenced_dose_reference
|
train
|
def create_referenced_dose_reference(cp_item)
# Referenced Dose Reference Sequence:
rd_seq = DICOM::Sequence.new('300C,0050', :parent => cp_item)
rd_item = DICOM::Item.new(:parent => rd_seq)
# Cumulative Dose Reference Coeffecient:
|
ruby
|
{
"resource": ""
}
|
q2015
|
YamlRecord.Base.save
|
train
|
def save
run_callbacks(:before_save)
run_callbacks(:before_create) unless self.is_created
existing_items = self.class.all
if self.new_record?
existing_items << self
else # update existing record
updated_item = existing_items.find { |item| item.id == self.id }
return false unless updated_item
updated_item.attributes = self.attributes
end
|
ruby
|
{
"resource": ""
}
|
q2016
|
YamlRecord.Base.destroy
|
train
|
def destroy
run_callbacks(:before_destroy)
new_data = self.class.all.reject { |item| item.persisted_attributes == self.persisted_attributes }.map { |item| item.persisted_attributes }
self.class.write_contents(new_data)
|
ruby
|
{
"resource": ""
}
|
q2017
|
Cfer::Core.Resource.tag
|
train
|
def tag(k, v, **options)
self[:Properties][:Tags] ||= []
self[:Properties][:Tags].delete_if { |kv| kv["Key"] == k }
|
ruby
|
{
"resource": ""
}
|
q2018
|
Cfer::Core.Stack.parameter
|
train
|
def parameter(name, options = {})
param = {}
options.each do |key, v|
next if v === nil
k = key.to_s.camelize.to_sym
param[k] =
case k
when :AllowedPattern
if v.class == Regexp
v.source
end
when :Default
|
ruby
|
{
"resource": ""
}
|
q2019
|
Cfer::Core.Stack.resource
|
train
|
def resource(name, type, options = {}, &block)
Preconditions.check_argument(/[[:alnum:]]+/ =~ name, "Resource name must be alphanumeric")
clazz = Cfer::Core::Resource.resource_class(type)
rc
|
ruby
|
{
"resource": ""
}
|
q2020
|
Cfer::Core.Stack.include_template
|
train
|
def include_template(*files)
include_base = options[:include_base] || File.dirname(caller.first.split(/:\d/,2).first)
files.each do |file|
path
|
ruby
|
{
"resource": ""
}
|
q2021
|
Cfer::Core.Stack.lookup_outputs
|
train
|
def lookup_outputs(stack)
client = @options[:client] || raise(Cfer::Util::CferError, "Can not fetch stack
|
ruby
|
{
"resource": ""
}
|
q2022
|
RackFakeS3.SortedObjectList.list
|
train
|
def list(options)
marker = options[:marker]
prefix = options[:prefix]
max_keys = options[:max_keys] || 1000
delimiter = options[:delimiter]
ms = S3MatchSet.new
marker_found = true
pseudo = nil
if marker
marker_found = false
if !@object_map[marker]
pseudo = S3Object.new
pseudo.name = marker
@sorted_set << pseudo
end
end
count = 0
@sorted_set.each do |s3_object|
if marker_found && (!prefix or s3_object.name.index(prefix) == 0)
|
ruby
|
{
"resource": ""
}
|
q2023
|
Gusteau.Config.build_node
|
train
|
def build_node(node_name, env_hash, node_hash)
node_config = {
'server' => node_hash.slice('host', 'port', 'user', 'password', 'platform', 'vagrant'),
'attributes' => (node_hash['attributes'] || {}).deep_merge(env_hash['attributes'] || {}),
'run_list' => node_hash['run_list'] || env_hash['run_list'],
'before' => env_hash['before']
|
ruby
|
{
"resource": ""
}
|
q2024
|
RackFakeS3.Servlet.normalize_request
|
train
|
def normalize_request(rack_req)
host = rack_req.host
s_req = Request.new
s_req.path = path_for_rack_request(rack_req)
s_req.is_path_style = true
s_req.rack_request = rack_req
if !@root_hostnames.include?(host)
s_req.bucket = host.split(".")[0]
s_req.is_path_style = false
end
|
ruby
|
{
"resource": ""
}
|
q2025
|
Metior.Report.generate
|
train
|
def generate(target_dir, with_assets = true)
target_dir = File.expand_path target_dir
copy_assets target_dir if with_assets
render.each do |view_name, output|
file_name = File.join target_dir, view_name.to_s.downcase + '.html'
begin
output_file =
|
ruby
|
{
"resource": ""
}
|
q2026
|
Metior.Report.copy_assets
|
train
|
def copy_assets(target_dir)
FileUtils.mkdir_p target_dir
self.class.assets.map do |asset|
asset_path = self.class.find asset
asset_dir = File.join target_dir, File.dirname(asset)
|
ruby
|
{
"resource": ""
}
|
q2027
|
Metior.Repository.actor
|
train
|
def actor(actor)
id = self.class::Actor.id_for(actor)
|
ruby
|
{
"resource": ""
}
|
q2028
|
Metior.Repository.commits
|
train
|
def commits(range = current_branch)
range = parse_range range
commits = cached_commits range
if commits.empty?
base_commit, raw_commits = load_commits(range)
commits = build_commits raw_commits
unless base_commit.nil?
base_commit = self.class::Commit.new(self, base_commit)
base_commit.add_child commits.last.id
@commits[base_commit.id] = base_commit
end
else
if range.first == ''
unless commits.last.parents.empty?
raw_commits = load_commits(''..commits.last.id).last
commits += build_commits raw_commits[0..-2]
end
else
|
ruby
|
{
"resource": ""
}
|
q2029
|
Metior.Repository.file_stats
|
train
|
def file_stats(range = current_branch)
support! :file_stats
stats = {}
commits(range).each_value do |commit|
commit.added_files.each do |file|
stats[file] = { :modifications => 0 } unless stats.key? file
stats[file][:added_date] = commit.authored_date
stats[file][:modifications] += 1
|
ruby
|
{
"resource": ""
}
|
q2030
|
Metior.Repository.build_commits
|
train
|
def build_commits(raw_commits)
child_commit_id = nil
raw_commits.map do |commit|
commit = self.class::Commit.new(self, commit)
commit.add_child child_commit_id unless child_commit_id.nil?
|
ruby
|
{
"resource": ""
}
|
q2031
|
Metior.Repository.cached_commits
|
train
|
def cached_commits(range)
commits = []
direction = nil
if @commits.key? range.last
current_commits = [@commits[range.last]]
direction = :parents
elsif @commits.key? range.first
current_commits = [@commits[range.first]]
direction = :children
end
unless direction.nil?
while !current_commits.empty? do
new_commits = []
current_commits.each do |commit|
new_commits += commit.send direction
commits << commit if commit.id != range.first
if direction == :parents && new_commits.include?(range.first)
new_commits = []
|
ruby
|
{
"resource": ""
}
|
q2032
|
Metior.Repository.parse_range
|
train
|
def parse_range(range)
unless range.is_a? Range
range = range.to_s.split '..'
range = ((range.size == 1) ? '' : range.first)..range.last
end
|
ruby
|
{
"resource": ""
}
|
q2033
|
Metior::Adapter.ClassMethods.register_for
|
train
|
def register_for(vcs)
vcs = Metior.find_vcs vcs
vcs.register_adapter id, self
|
ruby
|
{
"resource": ""
}
|
q2034
|
BentoSearch.OpenurlCreator.ensure_no_tags
|
train
|
def ensure_no_tags(str)
return str unless str.html_safe?
str = str.to_str # get it
|
ruby
|
{
"resource": ""
}
|
q2035
|
Route53.DNSRecord.update
|
train
|
def update(name,type,ttl,values,comment=nil, zone_apex = nil)
prev = self.clone
@name = name unless name.nil?
@type = type unless type.nil?
@ttl = ttl unless ttl.nil?
@values = values unless values.nil?
|
ruby
|
{
"resource": ""
}
|
q2036
|
Route53.DNSRecord.update_dirty
|
train
|
def update_dirty(name,type,ttl,values,zone_apex = nil)
prev = self.clone
@name = name unless name.nil?
@type = type unless type.nil?
@ttl = ttl unless ttl.nil?
@values = values unless
|
ruby
|
{
"resource": ""
}
|
q2037
|
Metior.ActorCollection.most_significant
|
train
|
def most_significant(count = 3)
support! :line_stats
authors = ActorCollection.new
sort_by {
|
ruby
|
{
"resource": ""
}
|
q2038
|
Metior.ActorCollection.top
|
train
|
def top(count = 3)
authors = ActorCollection.new
sort_by { |author| -author.authored_commits.size }.each
|
ruby
|
{
"resource": ""
}
|
q2039
|
Metior.ActorCollection.load_commits
|
train
|
def load_commits(commit_type, actor_id = nil)
commits = CommitCollection.new
if actor_id.nil?
|
ruby
|
{
"resource": ""
}
|
q2040
|
Metior::Adapter::Octokit.Repository.load_commits
|
train
|
def load_commits(range)
base_commit = nil
commits = []
last_commit = nil
loop do
new_commits = ::Octokit.commits(@path, nil, :last_sha => last_commit, :per_page => 100, :top => range.last)
break if new_commits.empty?
base_commit_index = new_commits.find_index do |commit|
|
ruby
|
{
"resource": ""
}
|
q2041
|
Autosign.Validator.validate
|
train
|
def validate(challenge_password, certname, raw_csr)
@log.debug "running validate"
fail unless challenge_password.is_a?(String)
fail unless certname.is_a?(String)
case perform_validation(challenge_password, certname, raw_csr)
when true
@log.debug "validated successfully"
@log.info "Validated '#{certname}' using '#{name}' validator"
return true
when false
|
ruby
|
{
"resource": ""
}
|
q2042
|
Autosign.Validator.settings
|
train
|
def settings
@log.debug "merging settings"
setting_sources = [get_override_settings, load_config, default_settings]
merged_settings = setting_sources.inject({}) { |merged, hash| merged.deep_merge(hash) }
@log.debug "using merged settings: " + merged_settings.to_s
@log.debug "validating merged settings"
if validate_settings(merged_settings)
@log.debug "successfully validated merged settings"
|
ruby
|
{
"resource": ""
}
|
q2043
|
Autosign.Validator.load_config
|
train
|
def load_config
@log.debug "loading validator-specific configuration"
config = Autosign::Config.new
if config.settings.to_hash[self.name].nil?
@log.warn "Unable to load validator-specific configuration"
@log.warn "Cannot load configuration section named '#{self.name}'"
return {}
else
|
ruby
|
{
"resource": ""
}
|
q2044
|
BentoSearch.SearchEngine.fill_in_search_metadata_for
|
train
|
def fill_in_search_metadata_for(results, normalized_arguments = {})
results.search_args = normalized_arguments
results.start = normalized_arguments[:start] || 0
results.per_page = normalized_arguments[:per_page]
results.engine_id = configuration.id
results.display_configuration = configuration.for_display
# We copy some configuraton info over to each Item, as a convenience
# to display logic that may have decide what to
|
ruby
|
{
"resource": ""
}
|
q2045
|
AllscriptsUnityClient.JSONUnityRequest.to_hash
|
train
|
def to_hash
action = @parameters[:action]
userid = @parameters[:userid]
appname = @parameters[:appname] || @appname
patientid = @parameters[:patientid]
token = @parameters[:token] || @security_token
parameter1 = process_date(@parameters[:parameter1]) || ''
parameter2 = process_date(@parameters[:parameter2]) || ''
parameter3 = process_date(@parameters[:parameter3]) || ''
parameter4 = process_date(@parameters[:parameter4]) || ''
parameter5 = process_date(@parameters[:parameter5]) || ''
parameter6 = process_date(@parameters[:parameter6]) || ''
data = Utilities::encode_data(@parameters[:data]) || ''
{
'Action' => action,
'AppUserID' => userid,
|
ruby
|
{
"resource": ""
}
|
q2046
|
AllscriptsUnityClient.Client.get_encounter_list
|
train
|
def get_encounter_list(
userid,
patientid,
encounter_type = nil,
when_param = nil,
nostradamus = 0,
show_past_flag = true,
billing_provider_user_name = nil,
show_all = false)
magic_parameters = {
action: 'GetEncounterList',
userid: userid,
patientid: patientid,
parameter1: encounter_type,
parameter2: when_param,
parameter3: nostradamus,
parameter4: unity_boolean_parameter(show_past_flag),
parameter5: billing_provider_user_name,
# According to the developer guide this parameter is no longer
# used.
|
ruby
|
{
"resource": ""
}
|
q2047
|
AllscriptsUnityClient.Client.get_task_list
|
train
|
def get_task_list(userid = nil, since = nil, delegated = nil, task_types = nil, task_statuses = nil)
magic_parameters = {
action: 'GetTaskList',
userid: userid,
parameter1: since,
parameter2: task_types,
parameter3: task_statuses,
|
ruby
|
{
"resource": ""
}
|
q2048
|
Route53.Zone.perform_actions
|
train
|
def perform_actions(change_list,comment=nil)
xml_str = gen_change_xml(change_list,comment)
|
ruby
|
{
"resource": ""
}
|
q2049
|
Route53.CLI.process_options
|
train
|
def process_options
@options.verbose = false if @options.quiet
@options.file = (user_home+"/.route53") if @options.file.nil?
#setup file
if @options.setup
setup
end
load_config
@config['access_key'] = @options.access unless @options.access.nil?
@config['secret_key'] = @options.secret unless @options.secret.nil?
|
ruby
|
{
"resource": ""
}
|
q2050
|
Route53.CLI.process_arguments
|
train
|
def process_arguments
if @options.new_zone
new_zone
elsif @options.delete_zone
delete_zone
elsif @options.create_record
|
ruby
|
{
"resource": ""
}
|
q2051
|
Mongoid.CachedJson.as_json_partial
|
train
|
def as_json_partial(options = {})
options ||= {}
if options[:properties] && !all_json_properties.member?(options[:properties])
fail ArgumentError.new("Unknown properties option: #{options[:properties]}")
end
# partial, unmaterialized JSON
keys, partial_json = self.class.materialize_json({
properties:
|
ruby
|
{
"resource": ""
}
|
q2052
|
Mongoid.CachedJson.as_json_cached
|
train
|
def as_json_cached(options = {})
keys, json = as_json_partial(options)
|
ruby
|
{
"resource": ""
}
|
q2053
|
Mongoid.CachedJson.expire_cached_json
|
train
|
def expire_cached_json
all_json_properties.each do |properties|
[true, false].each do |is_top_level_json|
all_json_versions.each do |version|
Mongoid::CachedJson.config.cache.delete(self.class.cached_json_key({
properties: properties,
is_top_level_json: is_top_level_json,
|
ruby
|
{
"resource": ""
}
|
q2054
|
Autosign.Journal.setup
|
train
|
def setup
@log.debug "using journalfile: " + self.settings['journalfile']
journalfile = self.settings['journalfile']
store
|
ruby
|
{
"resource": ""
}
|
q2055
|
Autosign.Journal.validate_uuid
|
train
|
def validate_uuid(uuid)
unless uuid.is_a?(String)
@log.error "UUID is not a string"
return false
end
unless !!/^\S{8}-\S{4}-4\S{3}-[89abAB]\S{3}-\S{12}$/.match(uuid.to_s)
|
ruby
|
{
"resource": ""
}
|
q2056
|
Metior.CommitCollection.<<
|
train
|
def <<(commit)
return self if key? commit.id
if @additions.nil? && empty? && commit.line_stats?
@additions = commit.additions
@deletions = commit.deletions
|
ruby
|
{
"resource": ""
}
|
q2057
|
Metior.CommitCollection.activity
|
train
|
def activity
activity = {}
return activity if empty?
commit_count = values.size
active_days = {}
each do |commit|
date = commit.committed_date.utc
day = Time.utc(date.year, date.month, date.day).send :to_date
if active_days.key? day
active_days[day] += 1
else
active_days[day] = 1
end
end
most_active_day = active_days.sort_by { |day, count| count }.last.first
activity[:first_commit_date] = last.committed_date
|
ruby
|
{
"resource": ""
}
|
q2058
|
Metior.CommitCollection.authors
|
train
|
def authors(commit_id = nil)
authors = ActorCollection.new
if commit_id.nil?
each { |commit| authors << commit.author }
elsif key? commit_id
|
ruby
|
{
"resource": ""
}
|
q2059
|
Metior.CommitCollection.before
|
train
|
def before(date)
date = Time.parse date if date.is_a? String
commits = CommitCollection.new
each do |commit|
commits
|
ruby
|
{
"resource": ""
}
|
q2060
|
Metior.CommitCollection.by
|
train
|
def by(*author_ids)
author_ids = author_ids.flatten.map do |author_id|
author_id.is_a?(Actor) ? author_id.id : author_id
|
ruby
|
{
"resource": ""
}
|
q2061
|
Metior.CommitCollection.changing
|
train
|
def changing(*files)
support! :file_stats
commits = CommitCollection.new
each do |commit|
commit_files = commit.added_files + commit.deleted_files + commit.modified_files
|
ruby
|
{
"resource": ""
}
|
q2062
|
Metior.CommitCollection.committers
|
train
|
def committers(commit_id = nil)
committers = ActorCollection.new
if commit_id.nil?
each { |commit| committers << commit.committer }
elsif key? commit_id
|
ruby
|
{
"resource": ""
}
|
q2063
|
Metior.CommitCollection.line_history
|
train
|
def line_history
support! :line_stats
history = { :additions => [], :deletions => [] }
values.reverse.each do
|
ruby
|
{
"resource": ""
}
|
q2064
|
Metior.CommitCollection.most_significant
|
train
|
def most_significant(count = 10)
support! :line_stats
commits = CommitCollection.new
sort_by {
|
ruby
|
{
"resource": ""
}
|
q2065
|
Metior.CommitCollection.with_impact
|
train
|
def with_impact(line_count)
support! :line_stats
commits = CommitCollection.new
each do |commit|
commits
|
ruby
|
{
"resource": ""
}
|
q2066
|
Metior.CommitCollection.load_line_stats
|
train
|
def load_line_stats
@additions = 0
@deletions = 0
return if empty?
line_stats = nil
if @range.nil?
ids = values.reject { |c| c.line_stats? }.map { |c| c.id }
line_stats = first.repo.load_line_stats ids unless ids.empty?
else
line_stats = first.repo.load_line_stats @range
end
unless line_stats.nil?
|
ruby
|
{
"resource": ""
}
|
q2067
|
Metior::Report.View.render
|
train
|
def render(*args)
begin
features = self.class.send :class_variable_get, :@@required_features
super
|
ruby
|
{
"resource": ""
}
|
q2068
|
BentoSearch.SearchController.search
|
train
|
def search
engine = BentoSearch.get_engine(params[:engine_id])
# put it in an iVar mainly for testing purposes.
@engine = engine
unless engine.configuration.allow_routable_results == true
raise AccessDenied.new("engine needs to be registered with :allow_routable_results => true")
end
@results = engine.search safe_search_args(engine, params)
|
ruby
|
{
"resource": ""
}
|
q2069
|
Metior::Adapter::Grit.Repository.current_branch
|
train
|
def current_branch
branch = @grit_repo.head
return branch.name unless branch.nil?
commit
|
ruby
|
{
"resource": ""
}
|
q2070
|
Metior::Adapter::Grit.Repository.load_line_stats
|
train
|
def load_line_stats(ids)
if ids.is_a? Range
if ids.first == ''
range = ids.last
else
range = '%s..%s' % [ids.first, ids.last]
end
options = { :numstat => true, :timeout => false }
output = @grit_repo.git.native :log, options, range
commit_stats = ::Grit::CommitStats.list_from_string @grit_repo, output
|
ruby
|
{
"resource": ""
}
|
q2071
|
Metior::Adapter::Grit.Repository.load_branches
|
train
|
def load_branches
Hash[@grit_repo.branches.map { |b|
|
ruby
|
{
"resource": ""
}
|
q2072
|
Metior::Adapter::Grit.Repository.load_commits
|
train
|
def load_commits(range)
if range.first == ''
base_commit = nil
range = range.last
else
base_commit = @grit_repo.commit(range.first)
range = '%s..%s' % [range.first, range.last]
end
options = { :pretty => 'raw', :timeout => false }
output =
|
ruby
|
{
"resource": ""
}
|
q2073
|
Metior::Adapter::Grit.Repository.load_name_and_description
|
train
|
def load_name_and_description
description = @grit_repo.description
if description.start_with? 'Unnamed repository'
@name = ''
@description = ''
else
description
|
ruby
|
{
"resource": ""
}
|
q2074
|
Metior::Adapter::Grit.Repository.load_tags
|
train
|
def load_tags
Hash[@grit_repo.tags.map { |b|
|
ruby
|
{
"resource": ""
}
|
q2075
|
Nestive.LayoutHelper.area
|
train
|
def area(name, content=nil, &block)
content = capture(&block) if block_given?
append
|
ruby
|
{
"resource": ""
}
|
q2076
|
Nestive.LayoutHelper.render_area
|
train
|
def render_area(name)
[].tap do |output|
@_area_for.fetch(name, []).reverse_each do |method_name, content|
|
ruby
|
{
"resource": ""
}
|
q2077
|
BentoSearch.GoogleBooksEngine.hash_to_item
|
train
|
def hash_to_item(item_response)
v_info = item_response["volumeInfo"] || {}
item = ResultItem.new
item.unique_id = item_response["id"]
item.title = format_title(v_info)
item.publisher = v_info["publisher"]
# previewLink gives you your search results highlighted, preferable
# if it exists.
item.link = v_info["previewLink"] || v_info["canonicalVolumeLink"]
item.abstract = sanitize v_info["description"]
item.year = get_year v_info["publishedDate"]
# sometimes we have yyyy-mm, but we need a date to make a ruby Date,
# we'll just say the 1st.
item.publication_date = case v_info["publishedDate"]
when /(\d\d\d\d)-(\d\d)/ then Date.parse "#{$1}-#{$2}-01"
when /(\d\d\d\d)-(\d\d)-(\d\d)/ then Date.parse v_info["published_date"]
else nil
end
item.format = if v_info["printType"] == "MAGAZINE"
|
ruby
|
{
"resource": ""
}
|
q2078
|
BentoSearch.GoogleBooksEngine.args_to_search_url
|
train
|
def args_to_search_url(arguments)
query = if arguments[:query].kind_of? Hash
#multi-field
arguments[:query].collect {|field, query_value| fielded_query(query_value, field)}.join(" ")
elsif arguments[:search_field]
fielded_query(arguments[:query], arguments[:search_field])
else
arguments[:query]
end
query_url = base_url + "volumes?q=#{CGI.escape query}"
if configuration.api_key
query_url += "&key=#{configuration.api_key}"
end
if arguments[:per_page]
query_url += "&maxResults=#{arguments[:per_page]}"
end
if arguments[:start]
|
ruby
|
{
"resource": ""
}
|
q2079
|
BentoSearch.StandardDecorator.render_authors_list
|
train
|
def render_authors_list
parts = []
first_three = self.authors.slice(0,3)
first_three.each_with_index do |author, index|
parts << _h.content_tag("span", :class => "author") do
|
ruby
|
{
"resource": ""
}
|
q2080
|
BentoSearch.StandardDecorator.render_citation_details
|
train
|
def render_citation_details
# \u00A0 is unicode non-breaking space to keep labels and values from
# getting separated.
result_elements = []
result_elements.push("#{I18n.t('bento_search.volume')}\u00A0#{volume}") if volume.present?
result_elements.push("#{I18n.t('bento_search.issue')}\u00A0#{issue}") if issue.present?
|
ruby
|
{
"resource": ""
}
|
q2081
|
BentoSearch.StandardDecorator.render_summary
|
train
|
def render_summary
summary = nil
max_chars = (self.display_configuration.try {|h| h["summary_max_chars"]}) || 280
if self.snippets.length > 0 && !(self.display_configuration.try {|h| h["prefer_abstract_as_summary"]} && self.abstract)
summary = self.snippets.first
self.snippets.slice(1, self.snippets.length).each do |snippet|
summary
|
ruby
|
{
"resource": ""
}
|
q2082
|
Autosign.Config.configfile
|
train
|
def configfile
@log.debug "Finding config file"
@config_file_paths.each { |file|
@log.debug "Checking if file '#{file}' exists"
if File.file?(file)
@log.debug "Reading config file from: " + file
config_file = File.read(file)
parsed_config_file = YAML.load(config_file)
#parsed_config_file = IniParse.parse(config_file).to_hash
|
ruby
|
{
"resource": ""
}
|
q2083
|
Autosign.Config.validate_config_file
|
train
|
def validate_config_file(configfile = location)
@log.debug "validating config file"
unless File.file?(configfile)
@log.error "configuration file not found at: #{configfile}"
raise Autosign::Exceptions::NotFound
end
# check if file is world-readable
if File.world_readable?(configfile) or File.world_writable?(configfile)
|
ruby
|
{
"resource": ""
}
|
q2084
|
BentoSearch.RISCreator.format_author_name
|
train
|
def format_author_name(author)
if author.last.present? && author.first.present?
str = "#{author.last}, #{author.first}"
if author.middle.present?
middle = author.middle
middle += "." if middle.length == 1
str += " #{middle}"
|
ruby
|
{
"resource": ""
}
|
q2085
|
SendWithUs.Api.send_email
|
train
|
def send_email(email_id, to, options = {})
if email_id.nil?
raise SendWithUs::ApiNilEmailId, 'email_id cannot be nil'
end
payload = {
email_id: email_id,
recipient: to
}
if options[:data] && options[:data].any?
payload[:email_data] = options[:data]
end
if options[:from] && options[:from].any?
payload[:sender] = options[:from]
end
if options[:cc] && options[:cc].any?
payload[:cc] = options[:cc]
end
if options[:bcc] && options[:bcc].any?
payload[:bcc] = options[:bcc]
end
if options[:esp_account]
payload[:esp_account] = options[:esp_account]
end
if options[:version_name]
payload[:version_name] = options[:version_name]
end
|
ruby
|
{
"resource": ""
}
|
q2086
|
ActiveAdmin.Duplicatable.enable_resource_duplication_via_form
|
train
|
def enable_resource_duplication_via_form
action_item(*compatible_action_item_parameters) do
if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :new, _source_id: resource.id)
end
end
controller do
|
ruby
|
{
"resource": ""
}
|
q2087
|
ActiveAdmin.Duplicatable.enable_resource_duplication_via_save
|
train
|
def enable_resource_duplication_via_save
action_item(*compatible_action_item_parameters) do
if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :duplicate)
end
end
member_action :duplicate do
resource = resource_class.find(params[:id])
authorize! ActiveAdmin::Auth::CREATE, resource
duplicate = resource.amoeba_dup
if duplicate.save
|
ruby
|
{
"resource": ""
}
|
q2088
|
ActiveAdmin.Duplicatable.enable_resource_duplication_via_custom_method
|
train
|
def enable_resource_duplication_via_custom_method(method)
action_item(*compatible_action_item_parameters) do
if controller.action_methods.include?('new') && authorized?(ActiveAdmin::Auth::CREATE, active_admin_config.resource_class)
link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :duplicate)
end
end
member_action :duplicate do
resource = resource_class.find(params[:id])
authorize! ActiveAdmin::Auth::CREATE, resource
begin
duplicate = resource.send
|
ruby
|
{
"resource": ""
}
|
q2089
|
GnuplotRB.ErrorHandling.check_errors
|
train
|
def check_errors(raw: false)
return if @err_array.empty?
command = ''
rest = ''
@semaphore.synchronize do
command = @err_array.first
rest = @err_array[1..-1].join('; ')
@err_array.clear
end
message = if raw
|
ruby
|
{
"resource": ""
}
|
q2090
|
GnuplotRB.ErrorHandling.handle_stderr
|
train
|
def handle_stderr(stream)
@err_array = []
# synchronize access to @err_array
@semaphore = Mutex.new
Thread.new do
until (line = stream.gets).nil?
line.strip!
|
ruby
|
{
"resource": ""
}
|
q2091
|
GnuplotRB.OptionHandling.option
|
train
|
def option(key, *value)
if value.empty?
value = options[key]
value = value[0] if value && value.size == 1
|
ruby
|
{
"resource": ""
}
|
q2092
|
Blurrily.Client.put
|
train
|
def put(needle, ref, weight = 0)
check_valid_needle(needle)
check_valid_ref(ref)
raise(ArgumentError, "WEIGHT value
|
ruby
|
{
"resource": ""
}
|
q2093
|
SfnParameters.Utils.lock_content
|
train
|
def lock_content(content)
content = content.to_smash
content.merge!(:sfn_lock_enabled => true)
|
ruby
|
{
"resource": ""
}
|
q2094
|
SfnParameters.Utils.unlock_content
|
train
|
def unlock_content(content)
content = content.to_smash
if content[:sfn_parameters_lock]
safe = SfnParameters::Safe.build(
config.fetch(:sfn_parameters, :safe, Smash.new)
|
ruby
|
{
"resource": ""
}
|
q2095
|
Clockwork.API.balance
|
train
|
def balance
xml = Clockwork::XML::Balance.build( self )
response = Clockwork::HTTP.post( Clockwork::API::BALANCE_URL, xml, @use_ssl )
|
ruby
|
{
"resource": ""
}
|
q2096
|
GnuplotRB.Multiplot.mix_options
|
train
|
def mix_options(options)
all_options = @options.merge(options)
specific_options, plot_options
|
ruby
|
{
"resource": ""
}
|
q2097
|
RRSchedule.Schedule.generate
|
train
|
def generate(params={})
raise "You need to specify at least 1 team" if @teams.nil? || @teams.empty?
raise "You need to specify at least 1 rule" if @rules.nil? || @rules.empty?
arrange_flights
init_stats
@gamedays = []; @rounds = []
@flights.each_with_index do |teams,flight_id|
current_cycle = current_round = 0
teams = teams.sort_by{rand} if @shuffle
#loop to generate the whole round-robin(s) for the current flight
begin
t = teams.clone
games = []
#process one round
while !t.empty? do
team_a = t.shift
team_b = t.reverse!.shift
t.reverse!
x = (current_cycle % 2) == 0 ? [team_a,team_b] : [team_b,team_a]
matchup = {:team_a => x[0], :team_b => x[1]}
games << matchup
end
#done processing round
current_round += 1
#Team rotation (the first team is fixed)
teams = teams.insert(1,teams.delete_at(teams.size-1))
#add the round in memory
@rounds ||= []
@rounds[flight_id] ||= []
@rounds[flight_id] <<
|
ruby
|
{
"resource": ""
}
|
q2098
|
RRSchedule.Schedule.to_s
|
train
|
def to_s
res = ""
res << "#{self.gamedays.size.to_s} gamedays\n"
self.gamedays.each do |gd|
res << gd.date.strftime("%Y-%m-%d") + "\n"
res << "==========\n"
|
ruby
|
{
"resource": ""
}
|
q2099
|
RRSchedule.Schedule.next_game_date
|
train
|
def next_game_date(dt,wday)
dt += 1 until wday == dt.wday &&
|
ruby
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.