_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q8500
FileBlobs.ActionControllerDataStreamingExtensions.send_file_blob
train
def send_file_blob(proxy, options = {}) if request.get_header(HTTP_IF_NONE_MATCH) == proxy.blob_id head :not_modified else response.headers[ETAG] = proxy.blob_id send_options = { type: proxy.mime_type, filename:
ruby
{ "resource": "" }
q8501
Diversion.Configurable.validate_configuration!
train
def validate_configuration! unless @host.is_a?(String) && @host.length > 0 raise(Error::ConfigurationError, "Invalid host specified: Host must contain the host to redirect to.") end if @host.end_with?('/') raise(Error::ConfigurationError, "Invalid host specified: #{@host} should not en...
ruby
{ "resource": "" }
q8502
Brocade.InstanceMethods.barcode
train
def barcode(opts = {}) data = format_for_subset_c_if_applicable send(barcodable) if (subset = opts[:subset]) case subset
ruby
{ "resource": "" }
q8503
Brocade.InstanceMethods.create_barcode
train
def create_barcode(opts = {}) path = barcode_path FileUtils.mkdir_p File.dirname(path) File.open(path, 'wb') do |f|
ruby
{ "resource": "" }
q8504
Checkdin.Leaderboard.classification_leaderboard
train
def classification_leaderboard(campaign_id) response = connection.get do |req| req.url
ruby
{ "resource": "" }
q8505
DummyText.Base.character
train
def character(count, template) out_of_order("c", count, template)
ruby
{ "resource": "" }
q8506
DummyText.Base.word
train
def word(count, template) out_of_order("w", count, template)
ruby
{ "resource": "" }
q8507
DummyText.Base.paragraph
train
def paragraph(count, template) out_of_order("p", count, template) i = 0 result = "" data = Paragraph.new.render(template) while i
ruby
{ "resource": "" }
q8508
CaRuby.Database.open
train
def open(user=nil, password=nil) raise ArgumentError.new("Database open requires an execution block") unless block_given? raise DatabaseError.new("The caRuby application database is already
ruby
{ "resource": "" }
q8509
CaRuby.Database.close
train
def close return if @session.nil? begin @session.terminate_session rescue Exception => e logger.error("Session termination unsuccessful - #{e.message}") end #
ruby
{ "resource": "" }
q8510
CaRuby.Database.perform
train
def perform(op, obj, opts=nil, &block) op_s = op.to_s.capitalize_first pa = Options.get(:attribute, opts) attr_s = " #{pa}" if pa ag_s = " autogenerated" if Options.get(:autogenerated, opts) ctxt_s = " in context #{print_operations}" unless @operations.empty? logger.info(">> #{op_s}#...
ruby
{ "resource": "" }
q8511
CaRuby.Database.start_session
train
def start_session(user=nil, password=nil) user ||= @user password ||= @password if user.nil? then raise DatabaseError.new('The caRuby application is missing the login user') end if password.nil? then raise DatabaseError.new('The caRuby
ruby
{ "resource": "" }
q8512
CaRuby.Database.print_operations
train
def print_operations ops = @operations.reverse.map do |op| attr_s = " #{op.attribute}" if op.attribute
ruby
{ "resource": "" }
q8513
CaRuby.Database.connect
train
def connect(user, password) logger.debug { "Connecting to application server with login id #{user}..." } begin @session.start_session(user, password) rescue Exception => e
ruby
{ "resource": "" }
q8514
MarkovWords.FileStore.retrieve_data
train
def retrieve_data(key = '') key = key.to_s unless key.is_a? String data_array =
ruby
{ "resource": "" }
q8515
GitOrgFileScanner.Scanner.setup_client
train
def setup_client(token) client = Octokit::Client.new(access_token:
ruby
{ "resource": "" }
q8516
Derelict.Parser::PluginList.plugins
train
def plugins raise NeedsReinstall, output if needs_reinstall?
ruby
{ "resource": "" }
q8517
Derelict.Parser::PluginList.parse_line
train
def parse_line(match) raise InvalidFormat.new "Couldn't parse plugin" if match.nil?
ruby
{ "resource": "" }
q8518
XiamiSauce.Track.sospa
train
def sospa(location) string = location[1..-1] col = location[0].to_i row = (string.length.to_f / col).floor remainder = string.length % col address = [[nil]*col]*(row+1) sizes = [row+1] * remainder + [row] * (col - remainder) pos = 0 sizes.each_with_index...
ruby
{ "resource": "" }
q8519
SimpleSolrClient.Client._post_json
train
def _post_json(path, object_to_post) resp = @rawclient.post(url(path),
ruby
{ "resource": "" }
q8520
SimpleSolrClient.Client.get
train
def get(path, args = {}, response_type = nil) response_type = SimpleSolrClient::Response::GenericResponse
ruby
{ "resource": "" }
q8521
SimpleSolrClient.Client.post_json
train
def post_json(path, object_to_post, response_type = nil) response_type = SimpleSolrClient::Response::GenericResponse if response_type.nil?
ruby
{ "resource": "" }
q8522
SimpleSolrClient.Client.core
train
def core(corename) raise "Core #{corename} not found" unless
ruby
{ "resource": "" }
q8523
SimpleSolrClient.Client.new_core
train
def new_core(corename) dir = temp_core_dir_setup(corename) args = { :wt => 'json', :action => 'CREATE', :name => corename,
ruby
{ "resource": "" }
q8524
SimpleSolrClient.Client.temp_core_dir_setup
train
def temp_core_dir_setup(corename) dest = Dir.mktmpdir("simple_solr_#{corename}_#{SecureRandom.uuid}")
ruby
{ "resource": "" }
q8525
Jimson.ClientHelper.send_single_request
train
def send_single_request(method, args) post_data = { 'jsonrpc' => JSON_RPC_VERSION, 'method' => method, 'params' => args, 'id' => self.class.make_id }.to_json resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ru...
ruby
{ "resource": "" }
q8526
Jimson.ClientHelper.send_batch_request
train
def send_batch_request(batch) post_data = batch.to_json resp = RestClient.post(@url, post_data, content_type: 'application/json', user_agent: "syncano-ruby-#{Syncano::VERSION}") if
ruby
{ "resource": "" }
q8527
Jimson.ClientHelper.send_batch
train
def send_batch batch = @batch.map(&:first) # get the requests response = send_batch_request(batch) begin responses = JSON.parse(response) rescue raise
ruby
{ "resource": "" }
q8528
Smsified.Helpers.camelcase_keys
train
def camelcase_keys(options) options = options.clone if options[:destination_address] options[:destinationAddress] = options[:destination_address] options.delete(:destination_address) end if options[:notify_url] options[:notifyURL] = options[:notify_url] ...
ruby
{ "resource": "" }
q8529
Smsified.Helpers.build_query_string
train
def build_query_string(options) options = camelcase_keys(options) query = '' options.each do |k,v| if k == :address if RUBY_VERSION.to_f >= 1.9 if v.instance_of?(String) v.each_line { |address| query += "#{ '&' if query != '' }address=#{CGI.escape ad...
ruby
{ "resource": "" }
q8530
Redlander.Serializing.to
train
def to(options = {}) format = options[:format].to_s mime_type = options[:mime_type] && options[:mime_type].to_s type_uri = options[:type_uri] && options[:type_uri].to_s base_uri = options[:base_uri] && options[:base_uri].to_s rdf_serializer = Redland.librdf_new_serializer(Redlander.rdf_wo...
ruby
{ "resource": "" }
q8531
Djinn.Base.start
train
def start config={}, &block @config.update(config).update(load_config) #@config = (config.empty?) ? load_config : config log "Starting #{name} in the background.." logfile = get_logfile(config) daemonize(logfile, get_pidfile(config)) do yield(self) if block_given? trap('TER...
ruby
{ "resource": "" }
q8532
Djinn.Base.run
train
def run config={}, &block @config.update(config).update(load_config) # @config = (config.empty?) ? load_config : config log "Starting #{name} in the foreground.." trap('TERM') { handle_exit
ruby
{ "resource": "" }
q8533
BitMagic.BitField.read_bits
train
def read_bits(*args) {}.tap do |m| args.each { |bit|
ruby
{ "resource": "" }
q8534
BitMagic.BitField.read_field
train
def read_field(*args) m = 0 args.flatten.each_with_index do |bit, i| if bit.is_a?(Integer)
ruby
{ "resource": "" }
q8535
Zcloudjp.Utils.parse_params
train
def parse_params(params, key_word) body = params.has_key?(:path) ? load_file(params[:path], key_word) : params
ruby
{ "resource": "" }
q8536
Zcloudjp.Utils.load_file
train
def load_file(path, key_word) begin data = MultiJson.load(IO.read(File.expand_path(path)), symbolize_keys: true) rescue RuntimeError, Errno::ENOENT => e raise e.message rescue MultiJson::LoadError => e raise e.message
ruby
{ "resource": "" }
q8537
Pinion.Server.bundle_url
train
def bundle_url(name) bundle = Bundle[name] raise "No such bundle: #{name}" unless bundle return bundle.paths.map { |p| asset_url(p) } unless Pinion.environment == "production"
ruby
{ "resource": "" }
q8538
EasyTag.Taggable.set_tags
train
def set_tags(tag_list, options = {}) options.reverse_merge! :context => nil, :tagger => nil, :downcase => true, :delimiter => ',' if block_given? tags = yield(klass) else tags = EasyTag::Tag.compa...
ruby
{ "resource": "" }
q8539
Rlocu2.Venue.external=
train
def external=(externals_list) @external = [] externals_list.each { |external_id| @external << Rlocu2::ExternalID.new(id: external_id['id'],
ruby
{ "resource": "" }
q8540
FileCharLicker.Licker.forward_lines
train
def forward_lines(size = 10) file = @file result = "" while
ruby
{ "resource": "" }
q8541
Parole.Comment.ensure_valid_role_for_commentable
train
def ensure_valid_role_for_commentable allowed_roles = commentable.class.commentable_options[:roles] if allowed_roles.any? errors.add(:role,
ruby
{ "resource": "" }
q8542
Activr.Dispatcher.route
train
def route(activity) raise "Activity must be stored before routing: #{activity.inspect}" if !activity.stored? result = 0 activity.run_callbacks(:route) do # iterate on all timelines Activr.registry.timelines.values.each do |timeline_class| # check if timeline refuses that ac...
ruby
{ "resource": "" }
q8543
Activr.Dispatcher.recipients_for_timeline
train
def recipients_for_timeline(timeline_class, activity) result = { } routes = timeline_class.routes_for_activity(activity.class) routes.each do |route| route.resolve(activity).each do |recipient| recipient_id = timeline_class.recipient_id(recipient) # keep only one route pe...
ruby
{ "resource": "" }
q8544
SimpleFormDojo.DojoPropsMethods.get_and_merge_dojo_props!
train
def get_and_merge_dojo_props! add_dojo_options_to_dojo_props if object.id.present? add_dojo_compliant_id else input_html_options["id"] = nil #let dojo generate internal id end
ruby
{ "resource": "" }
q8545
NSISam.Client.store
train
def store(data) request_data = {:value => data} request_data[:expire] = @expire if @expire request
ruby
{ "resource": "" }
q8546
NSISam.Client.store_file
train
def store_file(file_content, filename, type=:file)
ruby
{ "resource": "" }
q8547
NSISam.Client.delete
train
def delete(key) request_data = {:key => key}.to_json request
ruby
{ "resource": "" }
q8548
NSISam.Client.get
train
def get(key, expected_checksum=nil) request_data = {:key => key}.to_json request = prepare_request :GET, request_data
ruby
{ "resource": "" }
q8549
NSISam.Client.get_file
train
def get_file(key, type=:file, expected_checksum = nil) response = get(key, expected_checksum) response = Response.new( 'key' => response.key, 'checksum' => response.checksum,
ruby
{ "resource": "" }
q8550
NSISam.Client.update
train
def update(key, value) request_data = {:key => key, :value => value} request_data[:expire] = @expire if @expire
ruby
{ "resource": "" }
q8551
NSISam.Client.update_file
train
def update_file(key, type=:file, new_content, filename) encoded
ruby
{ "resource": "" }
q8552
RubyEdit.CLI.configure
train
def configure(*) if options[:help] invoke :help, ['configure'] else require_relative 'commands/configure'
ruby
{ "resource": "" }
q8553
Dassets.Server.call!
train
def call!(env) if (request = Request.new(env)).for_asset_file?
ruby
{ "resource": "" }
q8554
Brandish.PathSet.find_all
train
def find_all(short, options = {}) return to_enum(:find_all, short, options) unless block_given? short = ::Pathname.new(short) options = DEFAULT_FIND_OPTIONS.merge(options) @paths.reverse.each do |path|
ruby
{ "resource": "" }
q8555
Tay.Builder.get_compiled_file_content
train
def get_compiled_file_content(path) begin Tilt.new(path.to_s).render({}, { :spec => spec
ruby
{ "resource": "" }
q8556
Tay.Builder.simple_compile_directory
train
def simple_compile_directory(directory) if directory.is_a?(String) # If we just have a single dirname, assume it's under src from_directory = (directory[/\//] ? '' : 'src/') + directory directory = { :from => from_directory, :as => directory } end ...
ruby
{ "resource": "" }
q8557
Tay.Builder.compile_files
train
def compile_files(files) files.each do |base_path| # We do this second glob in case the path provided in the tayfile # references a compiled version Dir[@base_dir.join('src', base_path + '*')].each do |path| path = Pathname.new(path).relative_path_from(@base_dir.join('src')) ...
ruby
{ "resource": "" }
q8558
Tay.Builder.write_manifest
train
def write_manifest generator = ManifestGenerator.new(spec) File.open(@output_dir.join('manifest.json'), 'w') do |f|
ruby
{ "resource": "" }
q8559
Tay.Builder.create_sprockets_environment
train
def create_sprockets_environment @sprockets = Sprockets::Environment.new @sprockets.append_path(@base_dir.join('src/javascripts').to_s) @sprockets.append_path(@base_dir.join('src/templates').to_s)
ruby
{ "resource": "" }
q8560
Jabber.Simple.deliver
train
def deliver(jid, message, type=:chat) contacts(jid) do |friend| unless subscribed_to? friend add(friend.jid) return deliver_deferred(friend.jid, message, type) end if message.kind_of?(Jabber::Message) msg = message
ruby
{ "resource": "" }
q8561
Jabber.Simple.status
train
def status(presence, message) @presence = presence @status_message = message stat_msg
ruby
{ "resource": "" }
q8562
Jabber.Simple.send!
train
def send!(msg) attempts = 0 begin attempts += 1 client.send(msg) rescue Errno::EPIPE, IOError => e sleep 1 disconnect reconnect retry unless attempts > 3 raise e
ruby
{ "resource": "" }
q8563
Jabber.Simple.deliver_deferred
train
def deliver_deferred(jid, message, type) msg = {:to => jid, :message => message, :type => type}
ruby
{ "resource": "" }
q8564
Jabber.Simple.start_deferred_delivery_thread
train
def start_deferred_delivery_thread #:nodoc: Thread.new { loop { messages = [queue(:pending_messages).pop].flatten messages.each do |message|
ruby
{ "resource": "" }
q8565
FentonShell.Key.create
train
def create(options) status, body = key_create(options) if status save_message('Key': ['created!']) true
ruby
{ "resource": "" }
q8566
FentonShell.Key.key_create
train
def key_create(options) ssh_key = key_generation(options) ssh_private_key_file = options[:private_key] ssh_public_key_file = "#{ssh_private_key_file}.pub" # TODO: - add to .fenton/config file File.write(ssh_private_key_file, ssh_key.private_key) File.chmod(0o600,
ruby
{ "resource": "" }
q8567
FentonShell.Key.key_generation
train
def key_generation(options) SSHKey.generate( type: options[:type], bits: options[:bits], comment:
ruby
{ "resource": "" }
q8568
Raca.Containers.metadata
train
def metadata log "retrieving containers metadata from #{storage_path}" response = storage_client.head(storage_path) { :containers => response["X-Account-Container-Count"].to_i,
ruby
{ "resource": "" }
q8569
XS.Context.setctxopt
train
def setctxopt name, value length = 4 pointer = LibC.malloc length pointer.write_int value rc = LibXS.xs_setctxopt @context, name, pointer, length
ruby
{ "resource": "" }
q8570
XS.Context.socket
train
def socket type sock = nil begin sock = Socket.new @context,
ruby
{ "resource": "" }
q8571
Attention.Instance.publish
train
def publish publisher.publish('instance', added: info) do |redis| redis.setex "instance_#{ @id }",
ruby
{ "resource": "" }
q8572
Coulda.WebSteps.given_a
train
def given_a(factory_name, args = {}) Given "a #{factory_name} #{humanize args}" do args.each do |key, value| if value.is_a? Symbol instance_var_named_value = instance_variable_get("@#{value}") args[key] = instance_var_named_value if
ruby
{ "resource": "" }
q8573
Octo.Enterprise.setup_notification_categories
train
def setup_notification_categories templates = Octo.get_config(:push_templates) if templates templates.each do |t| args = { enterprise_id: self._id,
ruby
{ "resource": "" }
q8574
Octo.Enterprise.setup_intelligent_segments
train
def setup_intelligent_segments segments = Octo.get_config(:intelligent_segments) if segments segments.each do |seg| args = { enterprise_id: self._id, name: seg[:name], type: seg[:type].constantize, dimensions: seg[:dimensions].collect(&:const...
ruby
{ "resource": "" }
q8575
FastExt.SessionsController.forgot_password
train
def forgot_password klass = params[:type] || 'FastExt::MPerson' @user = klass.constantize.where(username:params[:username]) random_password = Array.new(10).map { (65 + rand(58)).chr }.join
ruby
{ "resource": "" }
q8576
Sem4rSpecHelper.Hash.except
train
def except(*keys) self.reject { |k,v|
ruby
{ "resource": "" }
q8577
Sem4rSpecHelper.Hash.only
train
def only(*keys) self.reject { |k,v|
ruby
{ "resource": "" }
q8578
Brandish.Configure.build
train
def build(which = :all) return to_enum(:build, which) unless
ruby
{ "resource": "" }
q8579
Brandish.Configure.roots
train
def roots @_roots ||= ::Hash.new do |h, k| h[k] = nil
ruby
{ "resource": "" }
q8580
Brandish.Configure.parse_from
train
def parse_from(path, short = path.relative_path_from(root)) contents = path.read digest = Digest::SHA2.digest(contents) cache.fetch(digest) do scanner
ruby
{ "resource": "" }
q8581
RDO.Statement.execute
train
def execute(*bind_values) t = Time.now @executor.execute(*bind_values).tap do |rs| rs.info[:execution_time] ||= Time.now - t if logger.debug? logger.debug( "(%.6f) %s %s" % [ rs.execution_time,
ruby
{ "resource": "" }
q8582
ActiveRecord.AttributeMethods.attributes
train
def attributes attrs = {} attribute_names.each { |name| attrs[name] =
ruby
{ "resource": "" }
q8583
Declare.Assertions.EQL?
train
def EQL?(sample) @it.eql?(sample) && sample.eql?(@it) && (@it.hash == sample.hash) &&
ruby
{ "resource": "" }
q8584
Declare.Assertions.CATCH
train
def CATCH(exception_klass, &block) block.call rescue ::Exception if $!.instance_of? exception_klass pass else failure("Faced a exception, that instance of #{exception_klass}.", "Faced a exception, that instance of #{$!.class}.", 2) end
ruby
{ "resource": "" }
q8585
ActiveHarmony.QueueItem.process_push
train
def process_push factory = "::#{object_type}".constantize local_object = factory.find(object_local_id)
ruby
{ "resource": "" }
q8586
ActiveHarmony.QueueItem.process_pull
train
def process_pull factory = "::#{object_type}".constantize syncer = factory.synchronizer
ruby
{ "resource": "" }
q8587
StronglyTyped.Attributes.attribute
train
def attribute(name, type=Object) name = name.to_sym #normalize raise NameError, "attribute `#{name}` already created" if members.include?(name) raise TypeError, "second argument, type, must be a Class but got `#{type.inspect}` insted" unless type.is_a?(Class)
ruby
{ "resource": "" }
q8588
StronglyTyped.Attributes.new_attribute
train
def new_attribute(name, type) attributes[name] = type define_attr_reader(name)
ruby
{ "resource": "" }
q8589
StronglyTyped.Attributes.define_attr_writer
train
def define_attr_writer(name, type) define_method("#{name}=") do |value| unless value.kind_of?(type) value = coerce(value, to: type) unless value.kind_of?(type)
ruby
{ "resource": "" }
q8590
Derelict.VirtualMachine.validate!
train
def validate! logger.debug "Starting validation for #{description}" raise NotFound.new name, connection unless exists?
ruby
{ "resource": "" }
q8591
Derelict.VirtualMachine.execute!
train
def execute!(command, options) # Build up the arguments to pass to connection.execute! arguments = [command, name, *arguments_for(command)] arguments << "--color" if options[:color] if options[:provider] arguments << "--provider" arguments << options[:provider] ...
ruby
{ "resource": "" }
q8592
Duvet.Cov.total_coverage
train
def total_coverage return 0.0 if lines.size.zero?
ruby
{ "resource": "" }
q8593
Duvet.Cov.code_coverage
train
def code_coverage return 0.0 if code_lines.size.zero?
ruby
{ "resource": "" }
q8594
StackableFlash.StackLayer.[]=
train
def []=(key, value) if StackableFlash.stacking super(key, StackableFlash::FlashStack.new.replace( value.kind_of?(Array) ? value : # Preserves nil values in the result... I suppose that's OK, users can compact if needed :)
ruby
{ "resource": "" }
q8595
ActiveSupport.BufferedLogger.add
train
def add(severity, message = nil, progname = nil, &block) return if @level > severity message = (message || (block && block.call) || progname).to_s
ruby
{ "resource": "" }
q8596
Bitsa.GmailContactsLoader.load_chunk
train
def load_chunk(client, idx, cache, orig_last_modified) # last_modified = nil url = generate_loader_url(idx, orig_last_modified) feed = client.get(url).to_xml feed.elements.each('entry') do |entry|
ruby
{ "resource": "" }
q8597
Bitsa.GmailContactsLoader.process_entry
train
def process_entry(cache, entry) gmail_id = entry.elements['id'].text if entry.elements['gd:deleted'] cache.delete(gmail_id)
ruby
{ "resource": "" }
q8598
Bitsa.GmailContactsLoader.generate_loader_url
train
def generate_loader_url(idx, cache_last_modified) # FIXME: Escape variables url = "https://www.google.com/m8/feeds/contacts/#{@user}/thin" url += '?orderby=lastmodified' url += '&showdeleted=true' url += "&max-results=#{@fetch_size}"
ruby
{ "resource": "" }
q8599
MultiGit.Walkable.walk
train
def walk( mode = :pre, &block ) raise ArgumentError, "Unknown walk mode #{mode.inspect}. Use either :pre, :post or :leaves" unless MODES.include? mode return to_enum(:walk, mode) unless block
ruby
{ "resource": "" }