_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q9200
Fishbans.BlockEngine.get_block
train
def get_block(id, metadata = nil, size = 42) url = "http://blocks.fishbans.com/#{id}" url += "-#{metadata}" unless metadata.nil? url += "/#{size}" if size != 42 response = get(url, false) ChunkyPNG::Image.from_blob(response.body) end
ruby
{ "resource": "" }
q9201
Fishbans.BlockEngine.get_monster
train
def get_monster(id, three = false, size = 42) id = id.to_s url = 'http://blocks.fishbans.com' url += "/#{id}" if id =~ /^m/ url += "/m#{id}" if id !~ /^m/ url += '-3d' if three url += "/#{size}" if size != 42 response = get(url, false) ChunkyPNG::Image.from_blob(response....
ruby
{ "resource": "" }
q9202
Osiris.ZipFileGenerator.write
train
def write(inputDir, outputFile) entries = Dir.entries(inputDir); entries.delete("."); entries.delete("..") io = Zip::File.open(outputFile, Zip::File::CREATE); writeEntries(entries, "", io, inputDir) io.close(); end
ruby
{ "resource": "" }
q9203
FileBlobs.ActiveRecordFixtureSetExtensions.file_blob_id
train
def file_blob_id(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) blob_contents = File.binread file_path # This needs to be kept in sync with blob_model.rb. Base64.urlsafe_encode64(Digest::SHA256.digest(blob_contents)).inspect end
ruby
{ "resource": "" }
q9204
FileBlobs.ActiveRecordFixtureSetExtensions.file_blob_data
train
def file_blob_data(path, options = {}) # The line with base64 data must be indented further than the current line. indent = ' ' * ((options[:indent] || 2) + 2) file_path = Rails.root.join('test/fixtures'.freeze).join(path) blob_contents = File.binread file_path base64_data = Base64.encode64 blob_co...
ruby
{ "resource": "" }
q9205
FileBlobs.ActiveRecordFixtureSetExtensions.file_blob_size
train
def file_blob_size(path) file_path = Rails.root.join('test/fixtures'.freeze).join(path) File.stat(file_path).size end
ruby
{ "resource": "" }
q9206
StorageRoom.File.set_with_filename
train
def set_with_filename(path) return if path.blank? self.filename = ::File.basename(path) self.content_type = ::MIME::Types.type_for(path).first.content_type self.data = ::Base64.encode64(::File.read(path)) end
ruby
{ "resource": "" }
q9207
StorageRoom.File.download_to_directory
train
def download_to_directory(path) Dir.mkdir(path) unless ::File.directory?(path) download_file(self[:@url], ::File.join(path, local_filename)) true end
ruby
{ "resource": "" }
q9208
ICU.Player.to_sp_text
train
def to_sp_text(rounds, columns, formats) values = columns.inject([]) do |vals,col| val = send(col).to_s val.sub!(/\.0/, '') if col == :points vals << val end (1..rounds).each do |r| result = find_result(r) values << (result ? result.to_sp_text : " : ") end...
ruby
{ "resource": "" }
q9209
NumericArray.InstanceMethods.variance
train
def variance(sample = false) a = numerify avg = a.average sum = a.inject(0) { |sum, value| sum + (value - avg) ** 2} (1 / (a.length.to_f - (sample ? 1 : 0)) * sum) end
ruby
{ "resource": "" }
q9210
GemFootprintAnalyzer.CLI.run
train
def run(args = ARGV) opts.parse!(args) if !analyze_gemfile? && args.empty? puts opts.parser exit 1 end print_requires(options, args) end
ruby
{ "resource": "" }
q9211
StreamBot.Tracker.start
train
def start keywords = self.params["keywords"] @thread = Thread.new do @client.filter_by_keywords(keywords) do |status| if retweet?(status) before_retweet.trigger(status) @retweet.retweet(status["id"]) after_retweet.trigger(status) end e...
ruby
{ "resource": "" }
q9212
StreamBot.Tracker.load_filters
train
def load_filters filters_config = self.params["filters_config" ] if !filters_config.nil? && File.exists?(filters_config) begin YAML::load_file(filters_config) rescue on_error.trigger($!, $@) end end end
ruby
{ "resource": "" }
q9213
StreamBot.Tracker.retweet?
train
def retweet?(status) filters = load_filters retweet = true if !filters.nil? filters.each_pair do |path, value| array = [] array << value array.flatten.each do |filter_value| path_value = StreamBot::ArrayPath.get_path(status, path) if path_v...
ruby
{ "resource": "" }
q9214
HTML.AutoTag.tag
train
def tag( params ) # TODO: make these method args if possible tag = params['tag'] attr = params['attr'] cdata = params['cdata'] unless attr.kind_of?( HTML::AutoAttr ) attr = HTML::AutoAttr.new( attr, @sorted ) end #...
ruby
{ "resource": "" }
q9215
Chartify.ChartBase.darken_color
train
def darken_color(hex_color, amount=0.4) hex_color = hex_color.gsub('#', '') rgb = hex_color.scan(/../).map { |color| color.hex } rgb[0] = (rgb[0].to_i * amount).round rgb[1] = (rgb[1].to_i * amount).round rgb[2] = (rgb[2].to_i * amount).round "#%02x%02x%02x" % rgb end
ruby
{ "resource": "" }
q9216
Chartify.ChartBase.lighten_color
train
def lighten_color(hex_color, amount=0.6) hex_color = hex_color.gsub('#', '') rgb = hex_color.scan(/../).map { |color| color.hex } rgb[0] = [(rgb[0].to_i + 255 * amount).round, 255].min rgb[1] = [(rgb[1].to_i + 255 * amount).round, 255].min rgb[2] = [(rgb[2].to_i + 255 * amount).round, 255]...
ruby
{ "resource": "" }
q9217
Trax.Model.reverse_assign_attributes
train
def reverse_assign_attributes(attributes_hash) attributes_to_assign = attributes_hash.keys.reject{|_attribute_name| attribute_present?(_attribute_name) } assign_attributes(attributes_hash.slice(attributes_to_assign)) end
ruby
{ "resource": "" }
q9218
MediaWiki.Query.pages
train
def pages result_map = map_query_to_results query_result["query"]["pages"].each do |key, value| page_title = value["title"] original_query = find_result_map_match_for_title(result_map, page_title) @page_hash[original_query] = MediaWiki::Page.new(value) end @page_hash end
ruby
{ "resource": "" }
q9219
MediaWiki.Query.map_query_to_results
train
def map_query_to_results #Initalize map result_map = initialize_map # Apply the normalization to the result map normalized = get_query_map("normalized") if normalized result_map = get_normalizations_for(result_map, normalized) end # Apply the redirects to the result map redirects = get_qu...
ruby
{ "resource": "" }
q9220
WhereWasI.Track.add_point
train
def add_point(lat:, lon:, elevation:, time:) time = Time.parse(time) if ! time.is_a?(Time) current = [lat, lon, elevation] if @start_time.nil? || time < @start_time @start_time = time @start_location = current end if @end_time.nil? || time > @end_time @end_...
ruby
{ "resource": "" }
q9221
WhereWasI.Track.in_time_range?
train
def in_time_range?(time) time = Time.parse(time) if ! time.is_a?(Time) time_range.cover?(time) end
ruby
{ "resource": "" }
q9222
WhereWasI.Track.at
train
def at(time) if time.is_a?(String) time = Time.parse(time) end if time.is_a?(Integer) time = Time.at(time) end raise ArgumentError, "time must be a Time,String, or Fixnum" if ! time.is_a?(Time) return nil if ! in_time_range?(time) @interp ||= Interpolate::Poin...
ruby
{ "resource": "" }
q9223
LooseLeaf.TaskHelpers.sh_in_dir
train
def sh_in_dir(dir, shell_commands) shell_commands = [shell_commands] if shell_commands.is_a?(String) shell_commands.each { |shell_command| sh %(cd #{dir} && #{shell_command.strip}) } end
ruby
{ "resource": "" }
q9224
ODBA.Cache.create_deferred_indices
train
def create_deferred_indices(drop_existing = false) @deferred_indices.each { |definition| name = definition.index_name if(drop_existing && self.indices.include?(name)) drop_index(name) end unless(self.indices.include?(name)) index = create_index(definition) ...
ruby
{ "resource": "" }
q9225
ODBA.Cache.create_index
train
def create_index(index_definition, origin_module=Object) transaction { klass = if(index_definition.fulltext) FulltextIndex elsif(index_definition.resolve_search_term.is_a?(Hash)) ConditionIndex else Index end index = klass.new(index_definition, origin_module...
ruby
{ "resource": "" }
q9226
ODBA.Cache.delete
train
def delete(odba_object) odba_id = odba_object.odba_id name = odba_object.odba_name odba_object.odba_notify_observers(:delete, odba_id, odba_object.object_id) rows = ODBA.storage.retrieve_connected_objects(odba_id) rows.each { |row| id = row.first # Self-Referencing objects don't have to be ...
ruby
{ "resource": "" }
q9227
ODBA.Cache.drop_index
train
def drop_index(index_name) transaction { ODBA.storage.drop_index(index_name) self.delete(self.indices[index_name]) } end
ruby
{ "resource": "" }
q9228
ODBA.Cache.next_id
train
def next_id if @file_lock dbname = ODBA.storage.instance_variable_get('@dbi').dbi_args.first.split(/:/).last id = new_id(dbname, ODBA.storage) else id = ODBA.storage.next_id end @peers.each do |peer| peer.reserve_next_id id rescue DRb::DRbError end id ...
ruby
{ "resource": "" }
q9229
ODBA.Cache.retrieve_from_index
train
def retrieve_from_index(index_name, search_term, meta=nil) index = indices.fetch(index_name) ids = index.fetch_ids(search_term, meta) if meta.respond_to?(:error_limit) && (limit = meta.error_limit) \ && (size = ids.size) > limit.to_i error = OdbaResultLimitError.new error.limit = lim...
ruby
{ "resource": "" }
q9230
ODBA.Cache.store
train
def store(object) odba_id = object.odba_id name = object.odba_name object.odba_notify_observers(:store, odba_id, object.object_id) if(ids = Thread.current[:txids]) ids.unshift([odba_id,name]) end ## get target_ids before anything else target_ids = object.odba_target_ids changes = st...
ruby
{ "resource": "" }
q9231
I18nAdminUtils.ApplicationHelper.translation_missing_icon
train
def translation_missing_icon(translation) missing_translations = translation.missing_translations color_id = (missing_translations.size.to_f/translation.translations.size.to_f*5).ceil-1 if missing_translations.size == 0 content_tag 'span', '', :class => 'glyphicon glyphicon-ok greentext', ...
ruby
{ "resource": "" }
q9232
Blueprint.Namespace.add_namespace
train
def add_namespace(html, namespace) html.gsub!(/(class=")([a-zA-Z0-9\-_ ]*)(")/) do |m| classes = m.to_s.split('"')[1].split(' ') classes.map! { |c| c = namespace + c } 'class="' + classes.join(' ') + '"' end html end
ruby
{ "resource": "" }
q9233
StixSchemaSpy.SimpleType.enumeration_values
train
def enumeration_values enumeration = @xml.xpath('./xs:restriction/xs:enumeration', {'xs' => 'http://www.w3.org/2001/XMLSchema'}) if enumeration.length > 0 return enumeration.map {|elem| [elem.attributes['value'].value, elem.xpath('./xs:annotation/xs:documentation', {'xs' => 'http://www.w3.org/2001/X...
ruby
{ "resource": "" }
q9234
LatoBlog.Interface::Categories.blog__create_default_category
train
def blog__create_default_category category_parent = LatoBlog::CategoryParent.find_by(meta_default: true) return if category_parent category_parent = LatoBlog::CategoryParent.new(meta_default: true) throw 'Impossible to create default category parent' unless category_parent.save languages...
ruby
{ "resource": "" }
q9235
LatoBlog.Interface::Categories.blog__clean_category_parents
train
def blog__clean_category_parents category_parents = LatoBlog::CategoryParent.all category_parents.map { |cp| cp.destroy if cp.categories.empty? } end
ruby
{ "resource": "" }
q9236
LatoBlog.Interface::Categories.blog__get_categories
train
def blog__get_categories( order: nil, language: nil, search: nil, page: nil, per_page: nil ) categories = LatoBlog::Category.all # apply filters order = order && order == 'ASC' ? 'ASC' : 'DESC' categories = _categories_filter_by_order(categories, order) c...
ruby
{ "resource": "" }
q9237
SugarfreeConfig.Config.fetch_config
train
def fetch_config Rails.logger.debug "Loading #{@file}::#{@env}" if Object.const_defined?('Rails') && Rails.logger.present? YAML::load_file(@file)[@env.to_s] end
ruby
{ "resource": "" }
q9238
SugarfreeConfig.Config.default_options
train
def default_options if Object.const_defined?('Rails') { :file => Rails.root.join('config', 'config.yml'), :reload => Rails.env.development?, :env => Rails.env } else { :file => File.expand_path("config.yml"), ...
ruby
{ "resource": "" }
q9239
SugarfreeConfig.ConfigIterator.next
train
def next if (value = @scoped_config[@path_elements.last]).nil? raise ConfigKeyException.new(@path_elements) elsif value.is_a?(Hash) @scoped_config = value self else value end end
ruby
{ "resource": "" }
q9240
ClassProxy.ClassMethods.proxy_methods
train
def proxy_methods(*methods) @_methods ||= {} methods.each do |method| if method.is_a? Symbol # If given a symbol, store as a method to overwrite and use the default loader proxy_method method elsif method.is_a? Hash # If its a hash it will include methods to ov...
ruby
{ "resource": "" }
q9241
ClassProxy.ClassMethods.fetch
train
def fetch(args, options={}) @primary_fetch.is_a?(Proc) ? @primary_fetch[args] : (raise NotFound) rescue NotFound return nil if options[:skip_fallback] run_fallback(args) end
ruby
{ "resource": "" }
q9242
Weechat.Plugin.unload
train
def unload(force = false) if name == "ruby" and !force Weechat.puts "Won't unload the ruby plugin unless you force it." false else Weechat.exec("/plugin unload #{name}") true end end
ruby
{ "resource": "" }
q9243
Weechat.Plugin.scripts
train
def scripts scripts = [] Infolist.parse("#{name}_script").each do |script| scripts << Script.new(script[:pointer], self) end scripts end
ruby
{ "resource": "" }
q9244
HttpPing.HttpPing::WMI.ping
train
def ping(host = @host, options = {}) super(host) lhost = Socket.gethostname cs = "winmgmts:{impersonationLevel=impersonate}!//#{lhost}/root/cimv2" wmi = WIN32OLE.connect(cs) query = "select * from win32_pingstatus where address = '#{host}'" unless options.empty? options.e...
ruby
{ "resource": "" }
q9245
CaRuby.SQLExecutor.query
train
def query(sql, *args, &block) fetched = nil execute do |dbh| result = dbh.execute(sql, *args) if block_given? then result.each(&block) else fetched = result.fetch(:all) end result.finish end fetched end
ruby
{ "resource": "" }
q9246
CaRuby.SQLExecutor.transact
train
def transact(sql=nil, *args) # Work-around for rcbi nil substitution. if sql then sql, *args = replace_nil_binds(sql, args) transact { |dbh| dbh.execute(sql, *args) } elsif block_given? then execute { |dbh| dbh.transaction { yield dbh } } else raise ArgumentError....
ruby
{ "resource": "" }
q9247
CaRuby.SQLExecutor.replace_nil_binds
train
def replace_nil_binds(sql, args) nils = [] args.each_with_index { |value, i| nils << i if value.nil? } unless nils.empty? then logger.debug { "SQL executor working around RDBI bug by eliminating the nil arguments #{nils.to_series} for the SQL:\n#{sql}..." } # Quoted ? is too much of a ...
ruby
{ "resource": "" }
q9248
BuoyData.NoaaStation.current_reading
train
def current_reading(doc) reading = {} xpath = "//table/caption[@class='titleDataHeader'][" xpath += "contains(text(),'Conditions')" xpath += " and " xpath += "not(contains(text(),'Solar Radiation'))" xpath += "]" # Get the reading timestamp source_updated_at = reading_t...
ruby
{ "resource": "" }
q9249
VcenterLib.VmConverter.facts
train
def facts logger.debug "get complete data of all VMs in all datacenters: begin" result = Hash[vm_mos_to_h(@vcenter.vms).map do |h| [h['name'], Hash[h.map { |k, v| [k.tr('.', '_'), v] }]] end] logger.debug "get complete data of all VMs in all datacenters: end" result end
ruby
{ "resource": "" }
q9250
Duxml.ElementGuts.traverse
train
def traverse(node=nil, &block) return self.to_enum unless block_given? node_stack = [node || self] until node_stack.empty? current = node_stack.shift if current yield current node_stack = node_stack.insert(0, *current.nodes) if current.respond_to?(:nodes) en...
ruby
{ "resource": "" }
q9251
Cloudpassage.Base.method_missing
train
def method_missing(sym, *args, &block) if (data && data[sym]) data[sym] else super(sym, *args, &block) end end
ruby
{ "resource": "" }
q9252
Derelict.Instance.validate!
train
def validate! logger.debug "Starting validation for #{description}" raise NotFound.new path unless File.exists? path raise NonDirectory.new path unless File.directory? path raise MissingBinary.new vagrant unless File.exists? vagrant raise MissingBinary.new vagrant unless File.executable? v...
ruby
{ "resource": "" }
q9253
Derelict.Instance.version
train
def version logger.info "Determining Vagrant version for #{description}" output = execute!("--version").stdout Derelict::Parser::Version.new(output).version end
ruby
{ "resource": "" }
q9254
Derelict.Instance.execute
train
def execute(subcommand, *arguments, &block) options = arguments.last.is_a?(Hash) ? arguments.pop : Hash.new command = command(subcommand, *arguments) command = "sudo -- #{command}" if options.delete(:sudo) logger.debug "Executing #{command} using #{description}" Executer.execute command, o...
ruby
{ "resource": "" }
q9255
Derelict.Instance.command
train
def command(subcommand, *arguments) args = [vagrant, subcommand.to_s, arguments].flatten args.map {|a| Shellwords.escape a }.join(' ').tap do |command| logger.debug "Generated command '#{command}' from " + "subcommand '#{subcommand.to_s}' with arguments " + arguments.in...
ruby
{ "resource": "" }
q9256
Deas.ShowExceptions.call!
train
def call!(env) status, headers, body = @app.call(env) if error = env['deas.error'] error_body = Body.new(error) headers['Content-Length'] = error_body.size.to_s headers['Content-Type'] = error_body.mime_type.to_s body = [error_body.content] end [status, headers...
ruby
{ "resource": "" }
q9257
HelpDeskAPI.Client.sign_in
train
def sign_in # Contact sign in page to set cookies. begin sign_in_res = RestClient.get(Endpoints::SIGN_IN) rescue RestClient::ExceptionWithResponse => error fail HelpDeskAPI::Exceptions.SignInError, "Error contacting #{Endpoints::SIGN_IN}: #{error}" end # Parse authenticity...
ruby
{ "resource": "" }
q9258
XS.Message.copy_in_bytes
train
def copy_in_bytes bytes, len data_buffer = LibC.malloc len # writes the exact number of bytes, no null byte to terminate string data_buffer.write_string bytes, len # use libC to call free on the data buffer; earlier versions used an # FFI::Function here that called back into Ruby, but Rub...
ruby
{ "resource": "" }
q9259
Confuse.Config.check
train
def check @definition.namespaces.each do |(namespace, ns)| ns.items.each do |key, _| lookup(namespace, key) end end end
ruby
{ "resource": "" }
q9260
Rsxml.Util.check_opts
train
def check_opts(constraints, opts) opts ||= {} opts.each{|k,v| raise "opt not permitted: #{k.inspect}" if !constraints.has_key?(k)} Hash[constraints.map do |k,constraint| if opts.has_key?(k) v = opts[k] if constraint.is_a?(Array) raise "unknow...
ruby
{ "resource": "" }
q9261
Align.PairwiseAlgorithm.max4
train
def max4(a,b,c,d) x = a >= b ? a : b y = c >= d ? c : d (x >= y) ? x : y end
ruby
{ "resource": "" }
q9262
MultiForecast.Client.get_complex
train
def get_complex(path) client(path).get_complex(service_name(path), section_name(path), graph_name(path)).tap do |graph| graph['base_uri'] = client(path).base_uri graph['path'] = path end end
ruby
{ "resource": "" }
q9263
MultiForecast.Client.delete_complex
train
def delete_complex(path) client(path).delete_complex(service_name(path), section_name(path), graph_name(path)) end
ruby
{ "resource": "" }
q9264
FentonShell.Certificate.certificate_create
train
def certificate_create(global_options, options) result = Excon.post( "#{global_options[:fenton_server_url]}/certificates.json", body: certificate_json(options), headers: { 'Content-Type' => 'application/json' } ) write_client_certificate( public_key_cert_location(optio...
ruby
{ "resource": "" }
q9265
HasMedia.ClassMethods.set_relations
train
def set_relations(context, relation) @contexts ||= {} @contexts[relation] ||= [] @media_relation_set ||= [] if @contexts[relation].include?(context) raise Exception.new("You should NOT use same context identifier for several has_one or has_many relation to media") end @contex...
ruby
{ "resource": "" }
q9266
Some.API.method_missing
train
def method_missing meth, *args, &block meth_s = meth.to_s if @method && meth_s =~ API_REGEX if meth_s.end_with?('!') # `foo! bar' is syntactic sugar for `foo.! bar' self[meth_s[0...-1]].!(args[0] || {}) else # chain the method name onto URL path self...
ruby
{ "resource": "" }
q9267
Xcellus.Instance.save
train
def save(path) unless path.kind_of? String raise ArgumentError, 'save expects a string path' end Xcellus::_save(@handle, path) end
ruby
{ "resource": "" }
q9268
Samsao.Helpers.changelog_modified?
train
def changelog_modified?(*changelogs) changelogs = config.changelogs if changelogs.nil? || changelogs.empty? changelogs.any? { |changelog| git.modified_files.include?(changelog) } end
ruby
{ "resource": "" }
q9269
Samsao.Helpers.has_app_changes?
train
def has_app_changes?(*sources) sources = config.sources if sources.nil? || sources.empty? sources.any? do |source| pattern = Samsao::Regexp.from_matcher(source, when_string_pattern_prefix_with: '^') modified_file?(pattern) end end
ruby
{ "resource": "" }
q9270
Samsao.Helpers.truncate
train
def truncate(input, max = 30) return input if input.nil? || input.length <= max input[0..max - 1].gsub(/\s\w+\s*$/, '...') end
ruby
{ "resource": "" }
q9271
MultiGit.Ref.resolve
train
def resolve @leaf ||= begin ref = self loop do break ref unless ref.target.kind_of? MultiGit::Ref ref = ref.target end end end
ruby
{ "resource": "" }
q9272
MultiGit.Ref.commit
train
def commit(options = {}, &block) resolve.update(options.fetch(:lock, :optimistic)) do |current| Commit::Builder.new(current, &block) end return reload end
ruby
{ "resource": "" }
q9273
Authpwn.ControllerInstanceMethods.set_session_current_user
train
def set_session_current_user(user) self.current_user = user # Try to reuse existing sessions. if session[:authpwn_suid] token = Tokens::SessionUid.with_code(session[:authpwn_suid]).first if token if token.user == user token.touch return user else tok...
ruby
{ "resource": "" }
q9274
Authpwn.ControllerInstanceMethods.authenticate_using_session
train
def authenticate_using_session return if current_user session_uid = session[:authpwn_suid] user = session_uid && Tokens::SessionUid.authenticate(session_uid) self.current_user = user if user && !user.instance_of?(Symbol) end
ruby
{ "resource": "" }
q9275
Tkar.Canvas.del
train
def del tkar_id tkaroid = @objects[tkar_id] if tkaroid if @follow_id == tkar_id follow nil end delete tkaroid.tag @objects.delete tkar_id @changed.delete tkar_id get_objects_by_layer(tkaroid.layer).delete tkaroid end end
ruby
{ "resource": "" }
q9276
Aptly.Repo.add
train
def add path, kwargs={} remove_files = kwargs.arg :remove_files, false cmd = 'aptly repo add' cmd += ' -remove-files' if remove_files cmd += " #{@name.quote} #{path}" Aptly::runcmd cmd end
ruby
{ "resource": "" }
q9277
Aptly.Repo.import
train
def import from_mirror, kwargs={} deps = kwargs.arg :deps, false packages = kwargs.arg :packages, [] if packages.length == 0 raise AptlyError.new '1 or more packages are required' end cmd = 'aptly repo import' cmd += ' -with-deps' if deps cmd += " #{from_mirror.quote}...
ruby
{ "resource": "" }
q9278
Aptly.Repo.copy
train
def copy from_repo, to_repo, kwargs={} deps = kwargs.arg :deps, false packages = kwargs.arg :packages, [] if packages.length == 0 raise AptlyError.new '1 or more packages are required' end cmd = 'aptly repo copy' cmd += ' -with-deps' if deps cmd += " #{from_repo.quote...
ruby
{ "resource": "" }
q9279
GoogleApi.Session.login
train
def login(code = nil) @client = Google::APIClient.new @client.authorization.client_id = c('client_id') @client.authorization.client_secret = c('client_secret') @client.authorization.scope = @scope @client.authorization.redirect_uri = c('redirect_uri') @api = @client.dis...
ruby
{ "resource": "" }
q9280
GoogleApi.Session.login_by_line
train
def login_by_line(server = 'http://localhost/oauth2callback', port = 0) begin require "launchy" # open browser rescue raise GoogleApi::RequireError, "You don't have launchy gem. Firt install it: gem install launchy." end require "socket" # make tcp server require "...
ruby
{ "resource": "" }
q9281
Vtasks.Docker.add_namespace
train
def add_namespace(image, path) namespace path.to_sym do |_args| require 'rspec/core/rake_task' ::RSpec::Core::RakeTask.new(:spec) do |task| task.pattern = "#{path}/spec/*_spec.rb" end docker_image = Vtasks::Docker::Image.new(image, path, args) lint_image(path) ...
ruby
{ "resource": "" }
q9282
Vtasks.Docker.dockerfiles
train
def dockerfiles @dockerfiles = Dir.glob('*').select do |dir| File.directory?(dir) && File.exist?("#{dir}/Dockerfile") end end
ruby
{ "resource": "" }
q9283
Vtasks.Docker.list_images
train
def list_images desc 'List all Docker images' task :list do info dockerfiles.map { |image| File.basename(image) } end end
ruby
{ "resource": "" }
q9284
ReturnHook.FormTagHelper.html_options_for_form
train
def html_options_for_form(url_for_options, options) options.stringify_keys.tap do |html_options| html_options["enctype"] = "multipart/form-data" if html_options.delete("multipart") # The following URL is unescaped, this is just a hash of options, and it is the # responsibility of the calle...
ruby
{ "resource": "" }
q9285
Beanstalkify.Environment.deploy!
train
def deploy!(app, settings=[]) @beanstalk.update_environment({ version_label: app.version, environment_name: self.name, option_settings: settings }) end
ruby
{ "resource": "" }
q9286
Beanstalkify.Environment.create!
train
def create!(archive, stack, cnames, settings=[]) params = { application_name: archive.app_name, version_label: archive.version, environment_name: self.name, solution_stack_name: stack, option_settings: settings } cnames.each do |c| if dns_available(c) ...
ruby
{ "resource": "" }
q9287
DR.Encoding.fix_utf8
train
def fix_utf8(s=nil) s=self if s.nil? #if we are included if String.method_defined?(:scrub) #Ruby 2.1 #cf http://ruby-doc.org/core-2.1.0/String.html#method-i-scrub return s.scrub {|bytes| '<'+bytes.unpack('H*')[0]+'>' } else return DR::Encoding.to_utf8(s) end e...
ruby
{ "resource": "" }
q9288
DR.Encoding.to_utf8!
train
def to_utf8!(s=nil,from:nil) s=self if s.nil? #if we are included from=s.encoding if from.nil? return s.encode!('UTF-8',from, :invalid => :replace, :undef => :replace, :fallback => Proc.new { |bytes| '<'+bytes.unpack('H*')[0]+'>' } ) end
ruby
{ "resource": "" }
q9289
Muack.Spy.__mock_dispatch_spy
train
def __mock_dispatch_spy @stub.__mock_disps.values.flatten.each do |disp| next unless __mock_defis.key?(disp.msg) # ignore undefined spies defis = __mock_defis[disp.msg] if idx = __mock_find_checked_difi(defis, disp.args, :index) __mock_disps_push(defis.delete_at(idx)) # found, d...
ruby
{ "resource": "" }
q9290
Samsao.Actions.check_non_single_commit_feature
train
def check_non_single_commit_feature(level = :fail) commit_count = git.commits.size message = "Your feature branch should have a single commit but found #{commit_count}, squash them together!" report(level, message) if feature_branch? && commit_count > 1 end
ruby
{ "resource": "" }
q9291
Samsao.Actions.check_feature_jira_issue_number
train
def check_feature_jira_issue_number(level = :fail) return if samsao.trivial_change? || !samsao.feature_branch? return report(:fail, 'Your Danger config is missing a `jira_project_key` value.') unless jira_project_key? message = 'The PR title must starts with JIRA issue number between square brackets'...
ruby
{ "resource": "" }
q9292
Samsao.Actions.check_fix_jira_issue_number
train
def check_fix_jira_issue_number(level = :warn) return if samsao.trivial_change? || !samsao.fix_branch? return report(:fail, 'Your Danger config is missing a `jira_project_key` value.') unless jira_project_key? git.commits.each do |commit| check_commit_contains_jira_issue_number(commit, level)...
ruby
{ "resource": "" }
q9293
Samsao.Actions.check_acceptance_criteria
train
def check_acceptance_criteria(level = :warn) return unless samsao.feature_branch? message = 'The PR description should have the acceptance criteria in the body.' report(level, message) if (/acceptance criteria/i =~ github.pr_body).nil? end
ruby
{ "resource": "" }
q9294
Samsao.Actions.check_label_pr
train
def check_label_pr(level = :fail) message = 'The PR should have at least one label added to it.' report(level, message) if github.pr_labels.nil? || github.pr_labels.empty? end
ruby
{ "resource": "" }
q9295
Samsao.Actions.report
train
def report(level, content) case level when :warn warn content when :fail fail content when :message message content else raise "Report level '#{level}' is invalid." end end
ruby
{ "resource": "" }
q9296
Samsao.Actions.check_commit_contains_jira_issue_number
train
def check_commit_contains_jira_issue_number(commit, type) commit_id = "#{shorten_sha(commit.sha)} ('#{truncate(commit.message)}')" jira_project_key = config.jira_project_key message = "The commit message #{commit_id} should contain JIRA issue number" \ " between square brackets (i.e. [#{jira_pro...
ruby
{ "resource": "" }
q9297
ZTK.Background.wait
train
def wait config.ui.logger.debug { "wait" } pid, status = (Process.wait2(@pid) rescue nil) if !pid.nil? && !status.nil? data = (Marshal.load(Base64.decode64(@parent_reader.read.to_s)) rescue nil) config.ui.logger.debug { "read(#{data.inspect})" } !data.nil? and @result = data ...
ruby
{ "resource": "" }
q9298
SycLink.Formatter.extract_columns
train
def extract_columns(rows, header) columns = [] header.each do |h| columns << rows.map do |r| r.send(h) end end columns end
ruby
{ "resource": "" }
q9299
SycLink.Formatter.max_column_widths
train
def max_column_widths(columns, header, opts = {}) row_column_widths = columns.map do |c| c.reduce(0) { |m, v| [m, v.nil? ? 0 : v.length].max } end header_column_widths = header.map { |h| h.length } row_column_widths = header_column_widths if row_column_widths.empty? widths = ro...
ruby
{ "resource": "" }