_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q22000
YNAB.ScheduledTransactionsApi.get_scheduled_transaction_by_id
train
def get_scheduled_transaction_by_id(budget_id, scheduled_transaction_id, opts = {}) data,
ruby
{ "resource": "" }
q22001
YNAB.ScheduledTransactionsApi.get_scheduled_transactions
train
def get_scheduled_transactions(budget_id, opts = {}) data, _status_code, _headers =
ruby
{ "resource": "" }
q22002
Chess.Gnuchess.gnuchess_move
train
def gnuchess_move pipe = IO.popen('gnuchess -x', 'r+') begin pipe.puts('depth 1') pipe.puts('manual') self.coord_moves.each do |m| pipe.puts(m) end pipe.puts('go') while line = pipe.gets raise IllegalMoveError if line.include?('Invalid move...
ruby
{ "resource": "" }
q22003
YNAB.PayeesApi.get_payee_by_id
train
def get_payee_by_id(budget_id, payee_id, opts = {}) data, _status_code, _headers =
ruby
{ "resource": "" }
q22004
YNAB.PayeesApi.get_payees
train
def get_payees(budget_id, opts = {}) data, _status_code, _headers =
ruby
{ "resource": "" }
q22005
Jdoc.Resource.links
train
def links @links ||= @schema.links.map do |link|
ruby
{ "resource": "" }
q22006
Daybreak.DB.hash_default
train
def hash_default(_, key) if @default != nil value = @default.respond_to?(:call) ? @default.call(key) : @default
ruby
{ "resource": "" }
q22007
Daybreak.Journal.clear
train
def clear flush with_tmpfile do |path, file| file.write(@format.header) file.close # Clear replaces the database file like a compactification does
ruby
{ "resource": "" }
q22008
Daybreak.Journal.compact
train
def compact load with_tmpfile do |path, file| # Compactified database has the same size -> return return self if @pos == file.write(dump(yield, @format.header)) with_flock(File::LOCK_EX) do # Database was replaced (cleared or compactified) in the meantime if @pos ...
ruby
{ "resource": "" }
q22009
Daybreak.Journal.open
train
def open @fd.close if @fd @fd = File.open(@file, 'ab+') @fd.advise(:sequential) if @fd.respond_to? :advise stat = @fd.stat
ruby
{ "resource": "" }
q22010
Daybreak.Journal.read
train
def read with_flock(File::LOCK_SH) do # File was opened unless @pos @fd.pos = 0 @format.read_header(@fd) @size = 0 @emit.call(nil) else
ruby
{ "resource": "" }
q22011
Daybreak.Journal.dump
train
def dump(records, dump = '') # each is faster than inject records.each do |record|
ruby
{ "resource": "" }
q22012
Daybreak.Journal.write
train
def write(dump) with_flock(File::LOCK_EX) do @fd.write(dump) # Flush to make sure the file is really updated @fd.flush
ruby
{ "resource": "" }
q22013
Daybreak.Journal.with_flock
train
def with_flock(mode) return yield if @locked begin loop do # HACK: JRuby returns false if the process is already hold by the same process # see https://github.com/jruby/jruby/issues/496 Thread.pass until @fd.flock(mode)
ruby
{ "resource": "" }
q22014
Daybreak.Journal.with_tmpfile
train
def with_tmpfile path = [@file, $$.to_s(36), Thread.current.object_id.to_s(36)].join file = File.open(path, 'wb') yield(path, file) ensure
ruby
{ "resource": "" }
q22015
Daybreak.Format.read_header
train
def read_header(input) raise 'Not a Daybreak database' if input.read(MAGIC.bytesize) != MAGIC
ruby
{ "resource": "" }
q22016
Daybreak.Format.dump
train
def dump(record) data = if record.size == 1 [record[0].bytesize, DELETE].pack('NN') << record[0] else
ruby
{ "resource": "" }
q22017
Daybreak.Format.parse
train
def parse(buf) n, count = 0, 0 while n < buf.size key_size, value_size = buf[n, 8].unpack('NN') data_size = key_size + 8 data_size += value_size if value_size != DELETE data = buf[n, data_size] n += data_size raise 'CRC mismatch: your data might be corrupted!'...
ruby
{ "resource": "" }
q22018
Ronin.URL.query_string
train
def query_string params = {} self.query_params.each do |param|
ruby
{ "resource": "" }
q22019
Ronin.URL.query_string=
train
def query_string=(query) self.query_params.clear ::URI::QueryParams.parse(query).each do |name,value| self.query_params.new(
ruby
{ "resource": "" }
q22020
Ronin.URL.to_uri
train
def to_uri # map the URL scheme to a URI class url_class = SCHEMES.fetch(self.scheme.name,::URI::Generic) host = if self.host_name self.host_name.address end port = if self.port self.port.number end query = unless self.query_params....
ruby
{ "resource": "" }
q22021
Ronin.HostName.lookup!
train
def lookup!(nameserver=nil) resolver = Resolv.resolver(nameserver) ips = begin resolver.getaddresses(self.address) rescue []
ruby
{ "resource": "" }
q22022
Ronin.Campaign.target!
train
def target!(addr) unless (address = Address.first(:address => addr)) raise("unknown address
ruby
{ "resource": "" }
q22023
Ronin.IPAddress.lookup!
train
def lookup!(nameserver=nil) resolver = Resolv.resolver(nameserver) hosts = begin resolver.getnames(self.address.to_s) rescue []
ruby
{ "resource": "" }
q22024
Ronin.Repository.find_script
train
def find_script(sub_path) paths = @script_dirs.map { |dir| File.join(dir,sub_path) }
ruby
{ "resource": "" }
q22025
Ronin.Repository.update!
train
def update! local_repo = Pullr::LocalRepository.new( :path => self.path, :scm => self.scm ) # only update if we have a repository local_repo.update(self.uri) # re-initialize the metadata initialize_metadata # save the repository if
ruby
{ "resource": "" }
q22026
Ronin.Repository.uninstall!
train
def uninstall! deactivate! FileUtils.rm_rf(self.path) if self.installed? # destroy any cached files first clean_scripts! # remove
ruby
{ "resource": "" }
q22027
Ronin.Password.digest
train
def digest(algorithm,options={}) digest_class = begin Digest.const_get(algorithm.to_s.upcase) rescue LoadError raise(ArgumentError,"Unknown Digest algorithm #{algorithm}") end hash = digest_class.new
ruby
{ "resource": "" }
q22028
Ronin.MACAddress.to_i
train
def to_i self.address.split(':').inject(0) do |bits,char|
ruby
{ "resource": "" }
q22029
Plugg.Dispatcher.start
train
def start(paths, params = {}) @registry = [] paths.each do |path| if path[-1] == '/' path.chop! end Dir["#{path}/*.rb"].each do |f| require File.expand_path(f) begin instance = Object.const_get(File.basename(f, '.rb')).new # ...
ruby
{ "resource": "" }
q22030
Plugg.Dispatcher.on
train
def on(method, *args, &block) if [:initialize, :before, :setup, :after].include? method raise "#{method} should not be called directly" end buffer = [] # Container for the response buffer threads = [] # Container for the execution threads @registry.each do |s| if s.resp...
ruby
{ "resource": "" }
q22031
ActionMessenger.Base.message_to_slack
train
def message_to_slack(channel:, options: {}) @caller_method_name = caller[0][/`([^']*)'/, 1] options = apply_defaults(options) message = nil ActiveSupport::Notifications.instrument('message_to_slack.action_messenger', channel:
ruby
{ "resource": "" }
q22032
ActionMessenger.Base.upload_file_to_slack
train
def upload_file_to_slack(channels: ,file: ,options: {}) upload_file = nil ActiveSupport::Notifications.instrument('upload_file_to_slack.action_messenger', channels: channels) do upload_file = slack_client.upload_file(channels, file, options)
ruby
{ "resource": "" }
q22033
WORLDCATAPI.SruSearchResponse.extract_multiple
train
def extract_multiple(record, field, tag) a = Array.new record.fields(field).each do |field|
ruby
{ "resource": "" }
q22034
Conduit::Driver::Braintree.Base.perform
train
def perform body = perform_action parser = parser_class.new(body) Conduit::ApiResponse.new(raw_response: @raw_response, body: body, parser: parser) rescue Braintree::NotFoundError => error report_braintree_exceptions(error) rescue ArgumentError => error
ruby
{ "resource": "" }
q22035
Settingson::Base.ClassMethods.defaults
train
def defaults @__defaults = Settingson::Store::Default.new( klass: self ) if block_given?
ruby
{ "resource": "" }
q22036
PoliceState.TransitionHelpers.attribute_transitioning?
train
def attribute_transitioning?(attr, options={}) options = _transform_options_for_attribute(attr,
ruby
{ "resource": "" }
q22037
ActionMessenger.MessageDelivery.deliver_now!
train
def deliver_now! messenger.handle_exceptions do ActiveSupport::Notifications.instrument('deliver_now!.action_messenger', method_name: method_name, args: args) do if args.present?
ruby
{ "resource": "" }
q22038
ActionMessenger.MessageDelivery.deliver_later!
train
def deliver_later! ActionMessenger::MessageDeliveryJob.perform_later(self.class.name,
ruby
{ "resource": "" }
q22039
GraphqlGrpc.Proxy.map_functions
train
def map_functions(stub_services) return @function_map unless @function_map.empty? stub_services.keys.each do |service_name| stub = @services[service_name] = stub_services[service_name] stub.class.to_s.gsub('::Stub', '::Service').constantize.rpc_descs.values.each do |d| next if d.n...
ruby
{ "resource": "" }
q22040
GraphqlGrpc.Function.arg
train
def arg(params) rpc_desc.input.decode_json(params.reject { |k, _v| k
ruby
{ "resource": "" }
q22041
Conduit::Driver::Braintree.UpdateCreditCard.whitelist_options
train
def whitelist_options @options[:options] ||= {}.tap do |h| h[:verify_card] = @options.fetch(:verify_card, true) @options.delete(:verify_card) if @options.key?(:verification_merchant_account_id)
ruby
{ "resource": "" }
q22042
WPDB.Termable.add_term
train
def add_term(term, taxonomy, description, count) if term.respond_to?(:term_id) term_id = term.term_id else term_id = term.to_i end term_taxonomy = WPDB::TermTaxonomy.where(term_id: term_id, taxonomy: taxonomy).first unless term_taxonomy term_taxonomy = WPDB::TermTa...
ruby
{ "resource": "" }
q22043
NounProjectApi.Retriever.find
train
def find(id) raise ArgumentError.new("Missing id/slug") unless id result = access_token.get("#{API_BASE}#{self.class::API_PATH}#{id}")
ruby
{ "resource": "" }
q22044
TrustedSandbox.UidPool.lock
train
def lock retries.times do atomically(timeout) do uid = available_uid if uid lock_uid uid return uid.to_i end end
ruby
{ "resource": "" }
q22045
TrustedSandbox.Response.parse!
train
def parse! unless File.exists? output_file_path @status = 'error' @error = ContainerError.new('User code did not finish properly') @error_to_raise = @error return end begin data = File.binread output_file_path @raw_response = Marshal.load(data) re...
ruby
{ "resource": "" }
q22046
Pro.Commands.find_repo
train
def find_repo(name) return @index.base_dirs.first unless name
ruby
{ "resource": "" }
q22047
Pro.Commands.status
train
def status() max_name = @index.map {|repo| repo.name.length}.max + 1 @index.each do |r| next unless Dir.exists?(r.path) status = repo_status(r.path)
ruby
{ "resource": "" }
q22048
Pro.Commands.repo_status
train
def repo_status(path) messages = [] messages << EMPTY_MESSAGE if repo_empty?(path) messages << UNCOMMITTED_MESSAGE if
ruby
{ "resource": "" }
q22049
Pro.Commands.install_cd
train
def install_cd puts CD_INFO print "Continue with installation (yN)? " return unless gets.chomp.downcase == "y" # get name print "Name of pro cd command (default 'pd'): " name = gets.strip name = 'pd' if name.empty? # sub into function func = SHELL_FUNCTION.sub("{{na...
ruby
{ "resource": "" }
q22050
Pro.Indexer.read_cache
train
def read_cache return nil unless File.readable_real?(CACHE_PATH) index = YAML::load_file(CACHE_PATH) return nil unless
ruby
{ "resource": "" }
q22051
Pro.Indexer.run_index_process
train
def run_index_process readme, writeme = IO.pipe p1 = fork { # Stop cd function from blocking on fork STDOUT.reopen(writeme)
ruby
{ "resource": "" }
q22052
Pro.Indexer.cache_index
train
def cache_index(index) # TODO: atomic rename. Right now we just hope. File.open(CACHE_PATH, 'w'
ruby
{ "resource": "" }
q22053
Pro.Indexer.index_repos_slow
train
def index_repos_slow(base) STDERR.puts "WARNING: pro is indexing slowly, please install the 'find' command." repos = [] Find.find(base) do |path| target = path # additionally, index repos symlinked directly from a base root
ruby
{ "resource": "" }
q22054
Pro.Indexer.find_base_dirs
train
def find_base_dirs() bases = [] # check environment first base = ENV['PRO_BASE'] bases << base if base # next check proBase file path = ENV['HOME'] + "/.proBase" if File.exists?(path) # read lines of the pro base file bases += IO.read(path).split("\n").map {|p| ...
ruby
{ "resource": "" }
q22055
Pupistry.GPG.artifact_sign
train
def artifact_sign @signature = 'unsigned' # Clean up the existing signature file signature_cleanup Dir.chdir("#{$config['general']['app_cache']}/artifacts/") do # Generate the signature file and pick up the signature data unless system "gpg --use-agent --detach-sign artifact.#{...
ruby
{ "resource": "" }
q22056
Pupistry.GPG.signature_extract
train
def signature_extract manifest = YAML.load(File.open($config['general']['app_cache'] + "/artifacts/manifest.#{@checksum}.yaml"), safe: true, raise_on_unknown_tag: true) if manifest['gpgsig'] # We have the base64 version @signature = manifest['gpgsig'] # Decode the base64 and write ...
ruby
{ "resource": "" }
q22057
Pupistry.GPG.signature_save
train
def signature_save manifest = YAML.load(File.open($config['general']['app_cache'] + "/artifacts/manifest.#{@checksum}.yaml"), safe: true, raise_on_unknown_tag: true) manifest['gpgsig'] = @signature
ruby
{ "resource": "" }
q22058
Pupistry.GPG.pubkey_upload
train
def pubkey_upload unless File.exist?("#{$config['general']['app_cache']}/artifacts/#{$config['general']['gpg_signing_key']}.publickey") # GPG key does not exist locally, we therefore assume it's not in the S3 # bucket either, so we should export out and upload. Technically this may # resu...
ruby
{ "resource": "" }
q22059
Pupistry.GPG.pubkey_install
train
def pubkey_install $logger.warn "Installing GPG key #{$config['general']['gpg_signing_key']}..." s3 = Pupistry::StorageAWS.new 'agent' unless s3.download "#{$config['general']['gpg_signing_key']}.publickey", "#{$config['general']['app_cache']}/artifacts/#{$config['general']['gpg_signing_key']}.publi...
ruby
{ "resource": "" }
q22060
Danger.DangerAutoLabel.wip=
train
def wip=(pr) label_names = [] labels.each do |label| label_names << label.name end puts("exist labels:" + label_names.join(", ")) unless wip? begin add_label("WIP") rescue Octokit::UnprocessableEntity => e
ruby
{ "resource": "" }
q22061
Danger.DangerAutoLabel.set
train
def set(pr, name, color) message = "" if label?(name) message = "Set #{name} label. (Color: #{color})" else message = "Add #{name} new label. (Color: #{color})"
ruby
{ "resource": "" }
q22062
Danger.DangerAutoLabel.delete
train
def delete(name) begin github.api.delete_label!(repo, name) rescue Octokit::Error => e
ruby
{ "resource": "" }
q22063
Danger.DangerAutoLabel.remove
train
def remove(name) begin github.api.remove_label(repo, number, name)
ruby
{ "resource": "" }
q22064
Coverage.Helpers.diff
train
def diff(cov1, cov2) ncov = {} old_format = true cov1.each do |path1, runs1| if cov2[path1] runs2 = cov2[path1] if runs1.is_a?(Array) && runs2.is_a?(Array) && old_format # diff two old-format (ruby 2.4 or before) coverage results ncov[path1] = diff...
ruby
{ "resource": "" }
q22065
Coverage.Helpers.sanitize
train
def sanitize(cov) ncov = {} cov.each do |path, runs| if runs.is_a?(Array) ncov[path] = runs next end ncov[path] = {} ncov[path][:lines] = runs[:lines] if runs[:lines] ncov[path][:branches] = runs[:branches] if runs[:branches] if runs[:met...
ruby
{ "resource": "" }
q22066
Coverage.Helpers.save
train
def save(path, cov) File.binwrite(path,
ruby
{ "resource": "" }
q22067
Coverage.Helpers.to_lcov_info
train
def to_lcov_info(cov, out: "", test_name: nil) out << "TN:#{ test_name }\n" cov.each do |path, runs| out << "SF:#{ path }\n" # function coverage if runs.is_a?(Hash) && runs[:methods] total = covered = 0 runs[:methods].each do |(klass, name, lineno), run| ...
ruby
{ "resource": "" }
q22068
Hatenablog.AfterHook.after_hook
train
def after_hook(hook, *methods) methods.each do |method| origin_method = "#{method}_origin".to_sym if instance_methods.include? origin_method raise NameError, "#{origin_method} isn't a unique name" end alias_method origin_method, method
ruby
{ "resource": "" }
q22069
Hatenablog.Client.next_feed
train
def next_feed(feed = nil) return Feed.load_xml(get_collection(collection_uri).body) if feed.nil? return
ruby
{ "resource": "" }
q22070
Hatenablog.Client.get_entry
train
def get_entry(entry_id) response = get(member_uri(entry_id))
ruby
{ "resource": "" }
q22071
Hatenablog.Client.post_entry
train
def post_entry(title = '', content = '', categories = [], draft = 'no') entry_xml = entry_xml(title, content, categories, draft)
ruby
{ "resource": "" }
q22072
Hatenablog.Client.update_entry
train
def update_entry(entry_id, title = '', content = '', categories = [], draft = 'no', updated = '') entry_xml = entry_xml(title, content, categories, draft, updated)
ruby
{ "resource": "" }
q22073
Hatenablog.Client.entry_xml
train
def entry_xml(title = '', content = '', categories = [], draft = 'no', updated = '', author_name = @user_id) builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |xml| xml.entry('xmlns' => 'http://www.w3.org/2005/Atom', 'xmlns:app' => 'http://www.w3.org/2007/app') do ...
ruby
{ "resource": "" }
q22074
AsyncCache.Store.check_arguments
train
def check_arguments arguments arguments.each_with_index do |argument, index| next if argument.is_a? Numeric next if argument.is_a? String next if argument.is_a? Symbol next if argument.is_a? Hash next if argument.is_a? NilClass next if argument.is_a? T...
ruby
{ "resource": "" }
q22075
RackStep.Router.find_route_for
train
def find_route_for(path, verb) # Ignoring the first char if path starts with '/'. This way the path of # 'http//localhost/' will be the same of 'http://localhost' (both will # be empty strings). path = path[1..-1] if path[0] == '/' route_id = verb + path route = routes[route_id]
ruby
{ "resource": "" }
q22076
Bureaucrat.Quickfields.hide
train
def hide(name) base_fields[name] = base_fields[name].dup
ruby
{ "resource": "" }
q22077
Bureaucrat.Quickfields.text
train
def text(name, options = {}) field name,
ruby
{ "resource": "" }
q22078
Bureaucrat.Quickfields.password
train
def password(name, options = {}) field name,
ruby
{ "resource": "" }
q22079
Bureaucrat.Quickfields.regex
train
def regex(name, regexp, options = {})
ruby
{ "resource": "" }
q22080
Bureaucrat.Quickfields.choice
train
def choice(name, choices = [], options = {})
ruby
{ "resource": "" }
q22081
Bureaucrat.Quickfields.typed_choice
train
def typed_choice(name, choices = [], options = {}) field name,
ruby
{ "resource": "" }
q22082
Bureaucrat.Quickfields.multiple_choice
train
def multiple_choice(name, choices = [], options = {}) field name,
ruby
{ "resource": "" }
q22083
Bureaucrat.Quickfields.radio_choice
train
def radio_choice(name, choices = [], options = {}) field name, ChoiceField.new(choices,
ruby
{ "resource": "" }
q22084
Bureaucrat.Quickfields.checkbox_multiple_choice
train
def checkbox_multiple_choice(name, choices = [], options = {}) field name, MultipleChoiceField.new(choices,
ruby
{ "resource": "" }
q22085
APICake.Base.save
train
def save(filename, path, params={}) payload = get! path, nil, params
ruby
{ "resource": "" }
q22086
APICake.Base.csv_node
train
def csv_node(data) arrays = data.keys.select { |key| data[key].is_a? Array }
ruby
{ "resource": "" }
q22087
APICake.Base.http_get
train
def http_get(path, extra=nil, params={}) payload
ruby
{ "resource": "" }
q22088
APICake.Base.normalize
train
def normalize(path, extra=nil, params={}) if extra.is_a?(Hash) and params.empty? params = extra extra = nil end path = "#{path}/#{extra}" if extra
ruby
{ "resource": "" }
q22089
PLSQL.Connection.describe_synonym
train
def describe_synonym(schema_name, synonym_name) #:nodoc: select_first( "SELECT table_owner, table_name FROM all_synonyms WHERE owner = :owner AND synonym_name
ruby
{ "resource": "" }
q22090
Moped.Connection.read
train
def read with_connection do |socket| reply = Protocol::Reply.allocate data = read_data(socket, 36) response = data.unpack(REPLY_DECODE_STR) reply.length, reply.request_id, reply.response_to, reply.op_code, reply.flags, reply.cursor_...
ruby
{ "resource": "" }
q22091
Moped.Connection.write
train
def write(operations) buf = "" operations.each do |operation| operation.request_id = (@request_id += 1) operation.serialize(buf)
ruby
{ "resource": "" }
q22092
Moped.Connection.read_data
train
def read_data(socket, length) data = socket.read(length) unless data raise Errors::ConnectionFailure.new( "Attempted to read
ruby
{ "resource": "" }
q22093
Moped.Node.command
train
def command(database, cmd, options = {})
ruby
{ "resource": "" }
q22094
Moped.Node.connection
train
def connection connection_acquired = false begin pool.with do |conn| connection_acquired = true yield(conn) end rescue Timeout::Error, ConnectionPool::PoolShuttingDownError => e
ruby
{ "resource": "" }
q22095
Moped.Node.ensure_connected
train
def ensure_connected(&block) unless (conn = stack(:connection)).empty? return yield(conn.first) end begin connection do |conn| connect(conn) unless conn.alive? conn.apply_credentials(@credentials)
ruby
{ "resource": "" }
q22096
Moped.Node.get_more
train
def get_more(database, collection, cursor_id, limit)
ruby
{ "resource": "" }
q22097
Moped.Node.insert
train
def insert(database, collection, documents, concern, options = {})
ruby
{ "resource": "" }
q22098
Moped.Node.process
train
def process(operation, &callback) if executing?(:pipeline)
ruby
{ "resource": "" }
q22099
Moped.Node.query
train
def query(database, collection, selector, options = {})
ruby
{ "resource": "" }