_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q27500
Ropenstack.Image::Version2.upload_image_from_file
test
def upload_image_from_file(name, disk_format, container_format, minDisk, minRam, is_public, file) data = { "name" => name, "disk_format" => disk_format, "container_format" => container_format, "minDisk" => minDisk, "minRam" => minRam, "public" => is_public } imagesBefore = images()
ruby
{ "resource": "" }
q27501
Ropenstack.Image::Version2.put_octect
test
def put_octect(uri, data, manage_errors) headers = build_headers(@token) headers["Content-Type"] = 'application/octet-stream' req =
ruby
{ "resource": "" }
q27502
Qwiki.App.relative_path
test
def relative_path(path) path = File.expand_path(path) root = full_path("") if path.size >= root.size && path[0...root.size] == root
ruby
{ "resource": "" }
q27503
Qwiki.App.index
test
def index(path) @entries = [] Dir.entries(path).each do |entry| relative_path = relative_path(File.join(path, entry)) if entry != "." && relative_path
ruby
{ "resource": "" }
q27504
Tabledata.Table.accessors_from_headers!
test
def accessors_from_headers! raise "Can't define accessors from headers in a table without headers" unless @has_headers
ruby
{ "resource": "" }
q27505
Tabledata.Table.<<
test
def <<(row) index = @data.size begin row = row.to_ary rescue NoMethodError raise ArgumentError, "Row must be provided as Array or respond to `to_ary`, but got #{row.class}
ruby
{ "resource": "" }
q27506
Hemingway.FootnoteNode.html
test
def html(id, time) inline_footnote_label = Build.tag("span", Build.tag("sup", id.to_s), :class => "inline-footnote-number")
ruby
{ "resource": "" }
q27507
Hemingway.FootnoteNode.footnote_html
test
def footnote_html(id, time) footnote_label = Build.tag("span", Build.tag("sup", id.to_s), :class => "footnote-number") footnote_content = sequence.elements.map { |s| s.html }.join
ruby
{ "resource": "" }
q27508
Ropenstack.Database::Version1.instance_action
test
def instance_action(id, action, param) case action when "RESTART" post_request(address("/instances/" + id + "/action"), {:restart => {}}, @token) when "RESIZE" if param.is_a? String post_request(address("/instances/" + id + "/action"), {:resize => {:flavorRef => param }}, @token) elsif param.is_a? Int post_request(address("/instances/" + id + "/action"), {:resize
ruby
{ "resource": "" }
q27509
Revenc.Errors.add
test
def add(error_on, message = "Unknown error") # humanize error_on if error_on.is_a?(Symbol) error_on_str = error_on.to_s else error_on_str = underscore(error_on.class.name) end error_on_str = error_on_str.gsub(/\//, '_') error_on_str = error_on_str.gsub(/_/, ' ')
ruby
{ "resource": "" }
q27510
GameOfLife.Board.coords_of_neighbors
test
def coords_of_neighbors(x, y) coords_of_neighbors = [] (x - 1).upto(x + 1).each do |neighbors_x| (y - 1).upto(y + 1).each do |neighbors_y|
ruby
{ "resource": "" }
q27511
RSqoot.Merchant.merchant
test
def merchant(id, options = {}) options = update_by_expire_time options if merchant_not_latest?(id) @rsqoot_merchant = get("merchants/#{id}", options, SqootMerchant) @rsqoot_merchant = @rsqoot_merchant.merchant if @rsqoot_merchant
ruby
{ "resource": "" }
q27512
EventMachine::WebSocketCodec.Encoder.encode
test
def encode data, opcode=TEXT_FRAME frame = [] frame << (opcode | 0x80) packr = "CC" if opcode == TEXT_FRAME data.force_encoding("UTF-8") if !data.valid_encoding? raise "Invalid UTF!" end end # append frame length and mask bit 0x80 len = data ? data.bytesize : 0 if len <= 125 frame << (len | 0x80) elsif
ruby
{ "resource": "" }
q27513
Challah::Rolls.Permission.challah_permission
test
def challah_permission unless included_modules.include?(InstanceMethods) include InstanceMethods extend ClassMethods end class_eval do validates_presence_of :name, :key validates_uniqueness_of :name, :key validates_format_of :key, :with => /^([a-z0-9_])*$/, :message => :invalid_key has_many :permission_roles, :dependent => :destroy has_many :roles, :through => :permission_roles, :order => 'roles.name'
ruby
{ "resource": "" }
q27514
Connectors.ApiConnector.post
test
def post hash={}, payload raise 'Payload cannot be blank' if payload.nil? || payload.empty?
ruby
{ "resource": "" }
q27515
Ropenstack.Networking.create_network
test
def create_network(name, tenant, admin_state_up = true) data = { 'network' => { 'name' => name, 'tenant_id' => tenant,
ruby
{ "resource": "" }
q27516
Ropenstack.Networking.create_port
test
def create_port(network, subnet = nil, device = nil, device_owner = nil) data = { 'port' => { 'network_id' => network, } } unless device_owner.nil? data['port']['device_owner'] = device_owner end unless device.nil? data['port']['device_id'] = device end
ruby
{ "resource": "" }
q27517
Ropenstack.Networking.move_port_to_subnets
test
def move_port_to_subnets(port_id, subnet_ids) id_list = Array.new() subnet_ids.each do
ruby
{ "resource": "" }
q27518
Rack.Action.json
test
def json(data={}, options={}) response[CONTENT_TYPE] = APPLICATION_JSON response.status = options[:status] if options.has_key?(:status)
ruby
{ "resource": "" }
q27519
Rack.Action.redirect_to
test
def redirect_to(url, options={}) full_url = absolute_url(url, options) response[LOCATION] =
ruby
{ "resource": "" }
q27520
Ropenstack.Compute.servers
test
def servers(id) endpoint = "/servers" unless id.nil? endpoint = endpoint + "/" + id end
ruby
{ "resource": "" }
q27521
Ropenstack.Compute.create_server
test
def create_server(name, image, flavor, networks = nil, keypair = nil, security_group = nil, metadata = nil) data = { "server" => { "name" => name, "imageRef" => image, "flavorRef" => flavor,
ruby
{ "resource": "" }
q27522
Ropenstack.Compute.action
test
def action(id, act, *args) data = case act when "reboot" then {'reboot' =>{"type" => args[0]}} when "vnc" then {'os-getVNCConsole' => { "type" => "novnc" }} when "stop" then {'os-stop' => 'null'} when "start" then {'os-start' => 'null'} when "pause" then {'pause' => 'null'} when "unpause" then {'unpause' => 'null'} when "suspend" then
ruby
{ "resource": "" }
q27523
Ropenstack.Compute.delete_image
test
def delete_image(id) uri = URI.parse("http://" + @location.host
ruby
{ "resource": "" }
q27524
RSqoot.Request.get
test
def get(path, opts = {}, wrapper = ::Hashie::Mash) uri, headers = url_generator(path, opts) begin json = JSON.parse uri.open(headers).read result = wrapper.new json
ruby
{ "resource": "" }
q27525
Optimacms.Template.set_basepath
test
def set_basepath if self.parent.nil? self.basepath = self.basename self.basedirpath ||= '' else self.basepath
ruby
{ "resource": "" }
q27526
RSqoot.Commission.commissions
test
def commissions(options = {}) options = update_by_expire_time options if commissions_not_latest?(options) @rsqoot_commissions = get('commissions', options, SqootCommission) @rsqoot_commissions = @rsqoot_commissions.commissions if @rsqoot_commissions
ruby
{ "resource": "" }
q27527
FootballRuby.Client.leagues
test
def leagues(opts={}) season = opts.fetch(:season) { Time.now.year }
ruby
{ "resource": "" }
q27528
Ov.Ext.match
test
def match(*args, &block) z = Module.new do include Ov extend self def try(*args, &block) let :anon_method, *args, &block end def otherwise(&block) let :otherwise, &block
ruby
{ "resource": "" }
q27529
Tabledata.Row.fetch
test
def fetch(column, *default_value, &default_block) raise ArgumentError, "Must only provide at max one default value or one default block" if default_value.size > (block_given? ? 0 : 1) index = case column when Symbol then @table.index_for_accessor(column) when String then @table.index_for_header(column) when Integer then column else
ruby
{ "resource": "" }
q27530
Tabledata.Row.at
test
def at(column) case column when Symbol then at_accessor(column) when String then at_header(column) when Integer then at_index(column) when Range then @data[column]
ruby
{ "resource": "" }
q27531
Tabledata.Row.values_at
test
def values_at(*columns) result = [] columns.each do |column| data = at(column) if column.is_a?(Range)
ruby
{ "resource": "" }
q27532
Tabledata.Row.method_missing
test
def method_missing(name, *args, &block) return super unless @table.accessors? name =~ /^(\w+)(=)?$/ name_mod, assign = $1, $2 index = @table.index_for_accessor(name_mod) arg_count = assign ? 1 : 0 return super unless index
ruby
{ "resource": "" }
q27533
TaskMapper::Provider.Unfuddle.authorize
test
def authorize(auth = {}) @authentication ||= TaskMapper::Authenticator.new(auth) auth = @authentication if (auth.account.nil? and auth.subdomain.nil?) or auth.username.nil? or auth.password.nil?
ruby
{ "resource": "" }
q27534
Ropenstack::Networking::Version2::Extensions.L3.routers
test
def routers(id = nil) endpoint = "routers" unless id.nil? endpoint = endpoint + "/" + id
ruby
{ "resource": "" }
q27535
Ropenstack::Networking::Version2::Extensions.L3.create_router
test
def create_router(name, admin_state_up = true) data = { 'router' =>{ 'name' => name, 'admin_state_up' => admin_state_up,
ruby
{ "resource": "" }
q27536
Ropenstack::Networking::Version2::Extensions.L3.delete_router_interface
test
def delete_router_interface(router, id, type) data = case type when 'port' then { 'port_id' => id } when 'subnet' then { 'subnet_id' => id } else raise "Invalid Interface Type" end
ruby
{ "resource": "" }
q27537
Ov.OA.where
test
def where(method) @complete, @result = nil, nil z = find_or_next(method) { |method| self.find{|m| m.eql?(method) } }.find_or_next(method) { |method|
ruby
{ "resource": "" }
q27538
Semistatic.Configuration.load
test
def load config_files.each do |file| config = YAML::load(File.open(file))
ruby
{ "resource": "" }
q27539
RSqoot.Provider.providers
test
def providers(options = {}) options = update_by_expire_time options query = options.delete(:query) if providers_not_latest?(options) @rsqoot_providers = get('providers', options, SqootProvider) @rsqoot_providers = @rsqoot_providers.providers.map(&:provider) if @rsqoot_providers
ruby
{ "resource": "" }
q27540
RSqoot.Category.categories
test
def categories(options = {}) options = update_by_expire_time options query = options.delete(:query) if categories_not_latest?(options) @rsqoot_categories = get('categories', options, SqootCategory) @rsqoot_categories = @rsqoot_categories.categories.map(&:category) if @rsqoot_categories
ruby
{ "resource": "" }
q27541
Challah::Rolls.Role.challah_role
test
def challah_role unless included_modules.include?(InstanceMethods) include InstanceMethods extend ClassMethods end class_eval do # Validations ################################################################ validates :name, :presence => true, :uniqueness => true # Relationships ################################################################ has_many :permission_roles, :dependent => :destroy has_many :permissions, :through => :permission_roles, :order => 'permissions.name'
ruby
{ "resource": "" }
q27542
Tang.Subscription.check_for_upgrade
test
def check_for_upgrade if plan_id_changed? old_plan = Plan.find(plan_id_was) if plan_id_was.present?
ruby
{ "resource": "" }
q27543
ZeevexProxy.Base.method_missing
test
def method_missing(name, *args, &block) obj = __getobj__
ruby
{ "resource": "" }
q27544
RSqoot.Deal.deals
test
def deals(options = {}) options = update_by_expire_time options if deals_not_latest?(options) uniq = !!options.delete(:uniq) @rsqoot_deals = get('deals', options, SqootDeal) || [] @rsqoot_deals = @rsqoot_deals.deals.map(&:deal) unless @rsqoot_deals.empty?
ruby
{ "resource": "" }
q27545
RSqoot.Deal.deal
test
def deal(id, options = {}) options = update_by_expire_time options if deal_not_latest?(id) @rsqoot_deal = get("deals/#{id}", options, SqootDeal) @rsqoot_deal = @rsqoot_deal.deal if @rsqoot_deal
ruby
{ "resource": "" }
q27546
RSqoot.Deal.total_sqoot_deals
test
def total_sqoot_deals(options = {}) @total_deals ||= [] @cached_pages ||= [] page = options[:page] || 1 check_query_change options unless page_cached? page
ruby
{ "resource": "" }
q27547
RSqoot.Deal.uniq_deals
test
def uniq_deals(deals = []) titles = deals.map(&:title).uniq titles.map do |title| deals.map do |deal|
ruby
{ "resource": "" }
q27548
Watir.Browser.load_cookies
test
def load_cookies(file) now = ::Time.now io = case file when String open(file) else file end io.each_line do |line| line.chomp! line.gsub!(/#.+/, '') fields = line.split("\t") next if fields.length != 7 name, value, domain, for_domain, path, secure, version = fields[5], fields[6], fields[0], (fields[1] == "TRUE"), fields[2], (fields[3] == "TRUE"), 0
ruby
{ "resource": "" }
q27549
Watir.Browser.dump_cookies
test
def dump_cookies(file) io = case file when String open(file, "w") else file end cookies.to_a.each do |cookie| io.puts([ cookie[:domain], "FALSE", # for_domain cookie[:path], cookie[:secure] ?
ruby
{ "resource": "" }
q27550
Watir.Element.set2
test
def set2(selector, value=nil) elem = element(xpath: selector).to_subtype case elem when Watir::Radio elem.set
ruby
{ "resource": "" }
q27551
RSqoot.Helper.update_by_expire_time
test
def update_by_expire_time(options = {}) @expired_in = options[:expired_in] if options[:expired_in].present? time =
ruby
{ "resource": "" }
q27552
RubyMeetup.Client.get
test
def get(options={}) uri = new_uri params = merge_params(options) uri.query = URI.encode_www_form(params) Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| request = Net::HTTP::Get.new(uri)
ruby
{ "resource": "" }
q27553
Ropenstack.Image::Version1.images
test
def images(id, tenant_id) if id.nil? return get_request(address(tenant_id, "images/detail"), @token) else return
ruby
{ "resource": "" }
q27554
Ropenstack.Image::Version1.image_create
test
def image_create(name, disk_format, container_format, create_image, tenant_id) data = { :name => name, :disk_format => disk_format,
ruby
{ "resource": "" }
q27555
Ropenstack.Image::Version1.replace_memberships
test
def replace_memberships(id, memberships, tenant_id) data = { :memberships =>
ruby
{ "resource": "" }
q27556
Ropenstack.Image::Version1.add_member
test
def add_member(id, member_id, can_share, tenant_id) if can_share.nil? data = { :member => {:can_share => false} } else data = {
ruby
{ "resource": "" }
q27557
Scripto.FileCommands.mkdir
test
def mkdir(dir, owner: nil, mode: nil) FileUtils.mkdir_p(dir, verbose: verbose?) chown(dir,
ruby
{ "resource": "" }
q27558
Scripto.FileCommands.cp
test
def cp(src, dst, mkdir: false, owner: nil, mode: nil) mkdir_if_necessary(File.dirname(dst)) if mkdir FileUtils.cp_r(src, dst, preserve: true, verbose: verbose?)
ruby
{ "resource": "" }
q27559
Scripto.FileCommands.mv
test
def mv(src, dst, mkdir: false) mkdir_if_necessary(File.dirname(dst))
ruby
{ "resource": "" }
q27560
Scripto.FileCommands.ln
test
def ln(src, dst) FileUtils.ln_sf(src, dst, verbose: verbose?) rescue Errno::EEXIST => e # It's a race - this can occur because ln_sf removes the old # dst, then creates the
ruby
{ "resource": "" }
q27561
Scripto.FileCommands.chmod
test
def chmod(file, mode) return if File.stat(file).mode
ruby
{ "resource": "" }
q27562
Scripto.FileCommands.rm_and_mkdir
test
def rm_and_mkdir(dir) raise "don't do this" if dir == "" FileUtils.rm_rf(dir,
ruby
{ "resource": "" }
q27563
Scripto.FileCommands.copy_metadata
test
def copy_metadata(src, dst) stat = File.stat(src) File.chmod(stat.mode, dst)
ruby
{ "resource": "" }
q27564
Scripto.FileCommands.atomic_write
test
def atomic_write(path) tmp = Tempfile.new(File.basename(path)) yield(tmp) tmp.close chmod(tmp.path, 0o644)
ruby
{ "resource": "" }
q27565
Capybarbecue.Server.handle_requests
test
def handle_requests until @requestmq.empty? request = @requestmq.deq(true) begin request.response = @app.call(request.env) rescue Exception => e request.exception = e ensure
ruby
{ "resource": "" }
q27566
Vagrantomatic.Instance.configfile_hash
test
def configfile_hash config = {} begin json = File.read(configfile) config = JSON.parse(json) rescue Errno::ENOENT # depending on whether the instance has been saved or not, we may not # yet have a configfile - allow to proceed @logger.debug "#{configfile} does not exist" @force_save = true
ruby
{ "resource": "" }
q27567
SimpleFormat.AutoLink.email_addresses
test
def email_addresses(text) text.gsub(@regex[:mail]) do text = $& if auto_linked?($`, $') text
ruby
{ "resource": "" }
q27568
Risky::Inflector.Inflections.plural
test
def plural(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String)
ruby
{ "resource": "" }
q27569
Risky::Inflector.Inflections.singular
test
def singular(rule, replacement) @uncountables.delete(rule) if rule.is_a?(String)
ruby
{ "resource": "" }
q27570
Risky::Inflector.Inflections.irregular
test
def irregular(singular, plural) @uncountables.delete(singular) @uncountables.delete(plural) if singular[0,1].upcase == plural[0,1].upcase plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1]) singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
ruby
{ "resource": "" }
q27571
Revenc.ActionFolder.execute
test
def execute raise errors.to_sentences unless valid? # default failing command result = false # protect command from recursion mutex = Mutagem::Mutex.new('revenc.lck') lock_successful = mutex.execute
ruby
{ "resource": "" }
q27572
HanselCore.Hansel.output
test
def output opts = options if opts.format FileUtils.mkdir_p opts.output_dir
ruby
{ "resource": "" }
q27573
HanselCore.Hansel.run
test
def run while @jobs.length > 0 do # do a warm up run first with the highest connection rate @current_job = @jobs.pop @current_rate = @current_job.high_rate.to_i
ruby
{ "resource": "" }
q27574
Ropenstack.Identity::Version2.authenticate
test
def authenticate(username, password, tenant = nil) data = { "auth" => { "passwordCredentials" => { "username" => username, "password" => password } } }
ruby
{ "resource": "" }
q27575
Ropenstack.Identity::Version2.add_to_services
test
def add_to_services(name, type, description) data = { 'OS-KSADM:service' => { 'name' => name, 'type' => type, 'description'
ruby
{ "resource": "" }
q27576
Ropenstack.Identity::Version2.add_endpoint
test
def add_endpoint(region, service_id, publicurl, adminurl, internalurl) data = { 'endpoint' => { 'region' => region, 'service_id' => service_id, 'publicurl' => publicurl,
ruby
{ "resource": "" }
q27577
Ropenstack.Identity::Version2.get_endpoints
test
def get_endpoints(token = nil) if token.nil? return get_request(address("/endpoints"), token()) else
ruby
{ "resource": "" }
q27578
MethodDisabling.ClassMethods.disable_method
test
def disable_method(method_name, message = nil) disabled_methods[method_name]
ruby
{ "resource": "" }
q27579
MethodDisabling.DisabledMethod.to_proc
test
def to_proc disabled_method = self # This proc will be evaluated with "self" set to the original object. Proc.new do |*args, &block|
ruby
{ "resource": "" }
q27580
MethodDisabling.DisabledMethod.execute
test
def execute(object, *args, &block) if disabled? raise NoMethodError,
ruby
{ "resource": "" }
q27581
MethodDisabling.DisabledMethod.alias_method!
test
def alias_method! klass.send(:define_method, replacement_name, &self) klass.send(:alias_method,
ruby
{ "resource": "" }
q27582
Ed25519Keccak.Ed25519Base.secret_to_public
test
def secret_to_public(secret, form=:byte) publickey = p_secret_to_public( change_argument_format(secret, form) )
ruby
{ "resource": "" }
q27583
Ed25519Keccak.Ed25519Base.point_equal
test
def point_equal(pa, pb) # x1 / z1 == x2 / z2 <==> x1 * z2 == x2 * z1 return false if (pa[0] * pb[2] - pb[0] * pa[2]) % @@p != 0
ruby
{ "resource": "" }
q27584
Ed25519Keccak.Ed25519Base.recover_x
test
def recover_x(y, sign) return nil if y >= @@p # x2 means x^2 x2 = (y*y-1) * modp_inv(@@d*y*y+1) # when x2==0 and sign!=0, these combination of arguments is illegal if x2.equal? 0 then unless sign.equal? 0 then return nil else return 0 end end # Compute square root of x2 x = pow_mod(x2 ,
ruby
{ "resource": "" }
q27585
Ed25519Keccak.Ed25519Base.point_decompress
test
def point_decompress(s) # check argument raise ArgumentError , "Invalid input length for decompression" unless s.length.equal? 32 y = int_form_bytes(s) sign = y >> 255 y &= (1 << 255) - 1
ruby
{ "resource": "" }
q27586
Ed25519Keccak.Ed25519Base.p_secret_to_public
test
def p_secret_to_public(secret) expanded = secret_expand(secret)
ruby
{ "resource": "" }
q27587
Semistatic.Page.part
test
def part(name) parts.select {|p| p.name.downcase ==
ruby
{ "resource": "" }