_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q25600
HIDAPI.Device.get_feature_report
validation
def get_feature_report(report_number, buffer_size = nil) buffer_size ||= input_ep_max_packet_size mutex.synchronize do handle.control_transfer( bmRequestType: LIBUSB::REQUEST_TYPE_CLASS | LIBUSB::RECIPIENT_INTERFACE | LIBUSB::ENDPOINT_IN, bRequest: 0x01, # HID Get_Report ...
ruby
{ "resource": "" }
q25601
HIDAPI.Device.read_string
validation
def read_string(index, on_failure = '') begin # does not require an interface, so open from the usb_dev instead of using our open method. data = mutex.synchronize do if open? handle.string_descriptor_ascii(index) else usb_device.open { |handle| handle.st...
ruby
{ "resource": "" }
q25602
SimpleAudit.Audit.delta
validation
def delta(other_audit) return self.change_log if other_audit.nil? {}.tap do |d| # first for keys present only in this audit (self.change_log.keys - other_audit.change_log.keys).each do |k| d[k] = [nil, self.change_log[k]] end # .. then for ke...
ruby
{ "resource": "" }
q25603
SimpleAudit.Helper.render_audits
validation
def render_audits(audited_model) return '' unless audited_model.respond_to?(:audits) audits = (audited_model.audits || []).dup.sort{|a,b| b.created_at <=> a.created_at} res = '' audits.each_with_index do |audit, index| older_audit = audits[index + 1] res += content_tag(:div, :cla...
ruby
{ "resource": "" }
q25604
Guard.Haml._output_paths
validation
def _output_paths(file) input_file_dir = File.dirname(file) file_name = _output_filename(file) file_name = "#{file_name}.html" if _append_html_ext_to_output_path?(file_name) input_file_dir = input_file_dir.gsub(Regexp.new("#{options[:input]}(\/){0,1}"), '') if options[:input] if options[:...
ruby
{ "resource": "" }
q25605
Guard.Haml._output_filename
validation
def _output_filename(file) sub_strings = File.basename(file).split('.') base_name, extensions = sub_strings.first, sub_strings[1..-1] if extensions.last == 'haml' extensions.pop if extensions.empty? [base_name, options[:default_ext]].join('.') else ...
ruby
{ "resource": "" }
q25606
VCloudClient.Connection.get_vapp_by_name
validation
def get_vapp_by_name(organization, vdcName, vAppName) result = nil get_vdc_by_name(organization, vdcName)[:vapps].each do |vapp| if vapp[0].downcase == vAppName.downcase result = get_vapp(vapp[1]) end end result end
ruby
{ "resource": "" }
q25607
VCloudClient.Connection.poweroff_vapp
validation
def poweroff_vapp(vAppId) builder = Nokogiri::XML::Builder.new do |xml| xml.UndeployVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5") { xml.UndeployPowerAction 'powerOff' } end params = { 'method' => :post, 'command' => "/vApp/vapp-#{vAppId}/actio...
ruby
{ "resource": "" }
q25608
VCloudClient.Connection.create_vapp_from_template
validation
def create_vapp_from_template(vdc, vapp_name, vapp_description, vapp_templateid, poweron=false) builder = Nokogiri::XML::Builder.new do |xml| xml.InstantiateVAppTemplateParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance", ...
ruby
{ "resource": "" }
q25609
VCloudClient.Connection.compose_vapp_from_vm
validation
def compose_vapp_from_vm(vdc, vapp_name, vapp_description, vm_list={}, network_config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.ComposeVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", "name" => vapp_name)...
ruby
{ "resource": "" }
q25610
VCloudClient.Connection.add_vm_to_vapp
validation
def add_vm_to_vapp(vapp, vm, network_config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.RecomposeVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1", "name" => vapp[:name]) { xml.SourcedItem...
ruby
{ "resource": "" }
q25611
VCloudClient.Connection.clone_vapp
validation
def clone_vapp(vdc_id, source_vapp_id, name, deploy="true", poweron="false", linked="false", delete_source="false") params = { "method" => :post, "command" => "/vdc/#{vdc_id}/action/cloneVApp" } builder = Nokogiri::XML::Builder.new do |xml| xml.CloneVAppParams( ...
ruby
{ "resource": "" }
q25612
VCloudClient.Connection.set_vapp_network_config
validation
def set_vapp_network_config(vappid, network, config={}) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vappid}/networkConfigSection" } netconfig_response, headers = send_request(params) picked_network = netconfig_response.css("NetworkConfig").select do |net| ne...
ruby
{ "resource": "" }
q25613
VCloudClient.Connection.set_vapp_port_forwarding_rules
validation
def set_vapp_port_forwarding_rules(vappid, network_name, config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.NetworkConfigSection( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1") { xml['ovf'].Info "Network configuratio...
ruby
{ "resource": "" }
q25614
VCloudClient.Connection.get_vapp_port_forwarding_rules
validation
def get_vapp_port_forwarding_rules(vAppId) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } response, headers = send_request(params) # FIXME: this will return nil if the vApp uses multiple vApp Networks # with Edge devices in natRout...
ruby
{ "resource": "" }
q25615
VCloudClient.Connection.merge_network_config
validation
def merge_network_config(vapp_networks, new_network, config) net_configuration = new_network.css('Configuration').first fence_mode = new_network.css('FenceMode').first fence_mode.content = config[:fence_mode] || 'isolated' network_features = Nokogiri::XML::Node.new "Features", net_conf...
ruby
{ "resource": "" }
q25616
VCloudClient.Connection.add_network_to_vapp
validation
def add_network_to_vapp(vAppId, network_section) params = { 'method' => :put, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } response, headers = send_request(params, network_section, "application/vnd.vmware.vcloud.networkConfigSection+xml") task_id = hea...
ruby
{ "resource": "" }
q25617
VCloudClient.Connection.create_fake_network_node
validation
def create_fake_network_node(vapp_networks, network_name) parent_section = vapp_networks.css('NetworkConfigSection').first new_network = Nokogiri::XML::Node.new "NetworkConfig", parent_section new_network['networkName'] = network_name placeholder = Nokogiri::XML::Node.new "PLACEHOLDER", ...
ruby
{ "resource": "" }
q25618
VCloudClient.Connection.create_internal_network_node
validation
def create_internal_network_node(network_config) builder = Nokogiri::XML::Builder.new do |xml| xml.Configuration { xml.IpScopes { xml.IpScope { xml.IsInherited(network_config[:is_inherited] || "false") xml.Gateway network_config[:gateway] ...
ruby
{ "resource": "" }
q25619
VCloudClient.Connection.generate_network_section
validation
def generate_network_section(vAppId, network, config, type) params = { 'method' => :get, 'command' => "/vApp/vapp-#{vAppId}/networkConfigSection" } vapp_networks, headers = send_request(params) create_fake_network_node(vapp_networks, network[:name]) if type....
ruby
{ "resource": "" }
q25620
VCloudClient.Connection.login
validation
def login params = { 'method' => :post, 'command' => '/sessions' } response, headers = send_request(params) if !headers.has_key?(:x_vcloud_authorization) raise "Unable to authenticate: missing x_vcloud_authorization header" end extensibility_link = response...
ruby
{ "resource": "" }
q25621
VCloudClient.Connection.get_task
validation
def get_task(taskid) params = { 'method' => :get, 'command' => "/task/#{taskid}" } response, headers = send_request(params) task = response.css('Task').first status = task['status'] start_time = task['startTime'] end_time = task['endTime'] { :status => ...
ruby
{ "resource": "" }
q25622
VCloudClient.Connection.wait_task_completion
validation
def wait_task_completion(taskid) errormsg = nil task = {} loop do task = get_task(taskid) break if task[:status] != 'running' sleep 1 end if task[:status] == 'error' errormsg = task[:response].css("Error").first errormsg = "Error code #{errormsg['m...
ruby
{ "resource": "" }
q25623
VCloudClient.Connection.send_request
validation
def send_request(params, payload=nil, content_type=nil) req_params = setup_request(params, payload, content_type) handled_request(req_params) do request = RestClient::Request.new(req_params) response = request.execute if ![200, 201, 202, 204].include?(response.code) ...
ruby
{ "resource": "" }
q25624
VCloudClient.Connection.upload_file
validation
def upload_file(uploadURL, uploadFile, progressUrl, config={}) raise ::IOError, "#{uploadFile} not found." unless File.exists?(uploadFile) # Set chunksize to 10M if not specified otherwise chunkSize = (config[:chunksize] || 10485760) # Set progress bar to default format if not specifie...
ruby
{ "resource": "" }
q25625
VCloudClient.Connection.get_catalog
validation
def get_catalog(catalogId) params = { 'method' => :get, 'command' => "/catalog/#{catalogId}" } response, headers = send_request(params) description = response.css("Description").first description = description.text unless description.nil? items = {} response.c...
ruby
{ "resource": "" }
q25626
VCloudClient.Connection.get_vm_disk_info
validation
def get_vm_disk_info(vmid) response, headers = __get_disk_info(vmid) disks = [] response.css("Item").each do |entry| # Pick only entries with node "HostResource" resource = entry.css("rasd|HostResource").first next unless resource name = entry.css("rasd|ElementName")....
ruby
{ "resource": "" }
q25627
VCloudClient.Connection.set_vm_disk_info
validation
def set_vm_disk_info(vmid, disk_info={}) get_response, headers = __get_disk_info(vmid) if disk_info[:add] data = add_disk(get_response, disk_info) else data = edit_disk(get_response, disk_info) end params = { 'method' => :put, 'command' => "/vApp/vm-#{vmid...
ruby
{ "resource": "" }
q25628
VCloudClient.Connection.set_vm_cpus
validation
def set_vm_cpus(vmid, cpu_number) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmid}/virtualHardwareSection/cpu" } get_response, headers = send_request(params) # Change attributes from the previous invocation get_response.css("rasd|ElementName").first.content = "...
ruby
{ "resource": "" }
q25629
VCloudClient.Connection.set_vm_ram
validation
def set_vm_ram(vmid, memory_size) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmid}/virtualHardwareSection/memory" } get_response, headers = send_request(params) # Change attributes from the previous invocation get_response.css("rasd|ElementName").first.content ...
ruby
{ "resource": "" }
q25630
VCloudClient.Connection.edit_vm_network
validation
def edit_vm_network(vmId, network, config={}) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmId}/networkConnectionSection" } netconfig_response, headers = send_request(params) if config[:primary_index] node = netconfig_response.css('PrimaryNetworkConnectionInde...
ruby
{ "resource": "" }
q25631
VCloudClient.Connection.add_vm_network
validation
def add_vm_network(vmId, network, config={}) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmId}/networkConnectionSection" } netconfig_response, headers = send_request(params) parent_section = netconfig_response.css('NetworkConnectionSection').first # For some re...
ruby
{ "resource": "" }
q25632
VCloudClient.Connection.delete_vm_network
validation
def delete_vm_network(vmId, network) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmId}/networkConnectionSection" } netconfig_response, headers = send_request(params) picked_network = netconfig_response.css("NetworkConnection").select do |net| net.attribute('ne...
ruby
{ "resource": "" }
q25633
VCloudClient.Connection.set_vm_guest_customization
validation
def set_vm_guest_customization(vmid, computer_name, config={}) builder = Nokogiri::XML::Builder.new do |xml| xml.GuestCustomizationSection( "xmlns" => "http://www.vmware.com/vcloud/v1.5", "xmlns:ovf" => "http://schemas.dmtf.org/ovf/envelope/1") { xml['ovf'].Info "VM Guest Customiza...
ruby
{ "resource": "" }
q25634
VCloudClient.Connection.get_vm
validation
def get_vm(vmId) params = { 'method' => :get, 'command' => "/vApp/vm-#{vmId}" } response, headers = send_request(params) vm_name = response.css('Vm').attribute("name") vm_name = vm_name.text unless vm_name.nil? status = convert_vapp_status(response.css('Vm').attrib...
ruby
{ "resource": "" }
q25635
VCloudClient.Connection.get_vm_by_name
validation
def get_vm_by_name(organization, vdcName, vAppName, vmName) result = nil get_vapp_by_name(organization, vdcName, vAppName)[:vms_hash].each do |key, values| if key.downcase == vmName.downcase result = get_vm(values[:id]) end end result end
ruby
{ "resource": "" }
q25636
VCloudClient.Connection.poweroff_vm
validation
def poweroff_vm(vmId) builder = Nokogiri::XML::Builder.new do |xml| xml.UndeployVAppParams( "xmlns" => "http://www.vmware.com/vcloud/v1.5") { xml.UndeployPowerAction 'powerOff' } end params = { 'method' => :post, 'command' => "/vApp/vm-#{vmId}/action/undepl...
ruby
{ "resource": "" }
q25637
VCloudClient.Connection.acquire_ticket_vm
validation
def acquire_ticket_vm(vmId) params = { 'method' => :post, 'command' => "/vApp/vm-#{vmId}/screen/action/acquireTicket" } response, headers = send_request(params) screen_ticket = response.css("ScreenTicket").text result = {} if screen_ticket =~ /mks:\/\/([^\/]*)\/(...
ruby
{ "resource": "" }
q25638
VCloudClient.Connection.get_network
validation
def get_network(networkId) response = get_base_network(networkId) name = response.css('OrgVdcNetwork').attribute('name').text description = response.css("Description").first description = description.text unless description.nil? gateway = response.css('Gateway') gateway = gateway....
ruby
{ "resource": "" }
q25639
VCloudClient.Connection.get_organizations
validation
def get_organizations params = { 'method' => :get, 'command' => '/org' } response, headers = send_request(params) orgs = response.css('OrgList Org') results = {} orgs.each do |org| results[org['name']] = org['href'].gsub(/.*\/org\//, "") end resu...
ruby
{ "resource": "" }
q25640
VCloudClient.Connection.get_tasks_list
validation
def get_tasks_list(id) params = { 'method' => :get, 'command' => "/tasksList/#{id}" } response, headers = send_request(params) tasks = [] response.css('Task').each do |task| id = task['href'].gsub(/.*\/task\//, "") operation = task['operationName'] ...
ruby
{ "resource": "" }
q25641
VCloudClient.Connection.get_vdc_id_by_name
validation
def get_vdc_id_by_name(organization, vdcName) result = nil organization[:vdcs].each do |vdc| if vdc[0].downcase == vdcName.downcase result = vdc[1] end end result end
ruby
{ "resource": "" }
q25642
VCloudClient.Connection.get_vdc_by_name
validation
def get_vdc_by_name(organization, vdcName) result = nil organization[:vdcs].each do |vdc| if vdc[0].downcase == vdcName.downcase result = get_vdc(vdc[1]) end end result end
ruby
{ "resource": "" }
q25643
DataProvider.Container.add!
validation
def add!(container) ### add container's providers ### # internally providers are added in reverse order (last one first) # so at runtime you it's easy and fast to grab the latest provider # so when adding now, we have to reverse the providers to get them in the original order container.pro...
ruby
{ "resource": "" }
q25644
DataProvider.Container.get_provider
validation
def get_provider(id, opts = {}) # get all matching providers matching_provider_args = providers.find_all{|args| args.first == id} # sort providers on priority, form high to low matching_provider_args.sort! do |args_a, args_b| # we want to sort from high priority to low, but providers wit...
ruby
{ "resource": "" }
q25645
Rack::Tidy.Cleaner.call!
validation
def call!(env) @env = env.dup status, @headers, response = @app.call(@env) if should_clean? @headers.delete('Content-Length') response = Rack::Response.new( tidy_markup(response.respond_to?(:body) ? response.body : response), status, @headers ...
ruby
{ "resource": "" }
q25646
Scribble.Registry.for
validation
def for *classes, &proc classes.each { |receiver_class| ForClassContext.new(self, receiver_class).instance_eval &proc } end
ruby
{ "resource": "" }
q25647
Scribble.Registry.evaluate
validation
def evaluate name, receiver, args, call = nil, context = nil matcher = Support::Matcher.new self, name, receiver, args matcher.match.new(receiver, call, context).send name, *args end
ruby
{ "resource": "" }
q25648
Bundleup.Console.progress
validation
def progress(message, &block) spinner = %w[/ - \\ |].cycle print "\e[90m#{message}... \e[0m" result = observing_thread(block, 0.5, 0.1) do print "\r\e[90m#{message}... #{spinner.next} \e[0m" end puts "\r\e[90m#{message}... OK\e[0m" result rescue StandardError puts "...
ruby
{ "resource": "" }
q25649
Bundleup.Console.tableize
validation
def tableize(rows, &block) rows = rows.map(&block) if block widths = max_length_of_each_column(rows) rows.map do |row| row.zip(widths).map { |value, width| value.ljust(width) }.join(" ") end end
ruby
{ "resource": "" }
q25650
Bundleup.Console.observing_thread
validation
def observing_thread(callable, initial_wait, periodic_wait) thread = Thread.new(&callable) wait_for_exit(thread, initial_wait) loop do break if wait_for_exit(thread, periodic_wait) yield end thread.value end
ruby
{ "resource": "" }
q25651
Rescuetime.Collection.all
validation
def all requester = Rescuetime::Requester host = HOST parse_response requester.get(host, params) end
ruby
{ "resource": "" }
q25652
Rescuetime.Collection.format
validation
def format(format) # Guard: fail if the passed format isn't on the whitelist format = format.to_s formatters.all.include?(format) || raise(Errors::InvalidFormatError) @format = format self end
ruby
{ "resource": "" }
q25653
Rescuetime.Collection.parse_response
validation
def parse_response(body) report = CSV.new(body, headers: true, header_converters: :symbol, converters: :all) format = @format.to_s.downcase report_formatter = formatters.find(format) report_formatter.format report ...
ruby
{ "resource": "" }
q25654
Rescuetime.ReportFormatters.find
validation
def find(name) formatter = formatters.find do |f| standardize(f.name) == standardize(name) end formatter || raise(Rescuetime::Errors::InvalidFormatError) end
ruby
{ "resource": "" }
q25655
Rescuetime.QueryBuildable.order_by
validation
def order_by(order, interval: nil) # set order and intervals as symbols order = order.to_s interval = interval ? interval.to_s : nil # guards against invalid order or interval unless valid_order? order raise Errors::InvalidQueryError, "#{order} is not a valid order" end ...
ruby
{ "resource": "" }
q25656
Rescuetime.QueryBuildable.where
validation
def where(name: nil, document: nil) # Stand-in for required keyword arguments name || raise(ArgumentError, 'missing keyword: name') add_to_query restrict_thing: name, restrict_thingy: document end
ruby
{ "resource": "" }
q25657
Rescuetime.QueryBuildable.add_to_query
validation
def add_to_query(**terms) if is_a? Rescuetime::Collection self << terms self else Rescuetime::Collection.new(BASE_PARAMS, state, terms) end end
ruby
{ "resource": "" }
q25658
Rescuetime.Client.valid_credentials?
validation
def valid_credentials? return false unless api_key? !activities.all.nil? rescue Rescuetime::Errors::InvalidCredentialsError false end
ruby
{ "resource": "" }
q25659
Rescuetime.Formatters.load_formatter_files
validation
def load_formatter_files(local_path: LOCAL_FORMATTER_PATH) # require all formatters, local and configured paths = Rescuetime.configuration.formatter_paths << local_path paths.each do |path| Dir[File.expand_path(path, __FILE__)].each { |file| require file } end end
ruby
{ "resource": "" }
q25660
NibblerMethods.InstanceMethods.parse
validation
def parse self.class.rules.each do |target, (selector, delegate, plural)| if plural send(target).concat @doc.search(selector).map { |i| parse_result(i, delegate) } else send("#{target}=", parse_result(@doc.at(selector), delegate)) end end self end
ruby
{ "resource": "" }
q25661
NibblerMethods.InstanceMethods.to_hash
validation
def to_hash converter = lambda { |obj| obj.respond_to?(:to_hash) ? obj.to_hash : obj } self.class.rules.keys.inject({}) do |hash, name| value = send(name) hash[name.to_sym] = Array === value ? value.map(&converter) : converter[value] hash end end
ruby
{ "resource": "" }
q25662
NibblerMethods.InstanceMethods.parse_result
validation
def parse_result(node, delegate) if delegate method = delegate.is_a?(Proc) ? delegate : delegate.method(delegate.respond_to?(:call) ? :call : :parse) method.arity == 1 ? method[node] : method[node, self] else node end unless node.nil? end
ruby
{ "resource": "" }
q25663
Tweetburner.Scraper.get_document
validation
def get_document(url) URI === url ? Nokogiri::HTML::Document.parse(open(url), url.to_s, 'UTF-8') : url rescue OpenURI::HTTPError $stderr.puts "ERROR opening #{url}" Nokogiri('') end
ruby
{ "resource": "" }
q25664
MMS2R.MMS2R::Media.subject
validation
def subject unless @subject subject = mail.subject.strip rescue "" ignores = config['ignore']['text/plain'] if ignores && ignores.detect{|s| s == subject} @subject = "" else @subject = transform_text('text/plain', subject).last end end @sub...
ruby
{ "resource": "" }
q25665
MMS2R.MMS2R::Media.ignore_media?
validation
def ignore_media?(type, part) ignores = config['ignore'][type] || [] ignore = ignores.detect{ |test| filename?(part) == test} ignore ||= ignores.detect{ |test| filename?(part) =~ test if test.is_a?(Regexp) } ignore ||= ignores.detect{ |test| part.body.decoded.strip =~ test if test.is_a?(Regexp...
ruby
{ "resource": "" }
q25666
MMS2R.MMS2R::Media.process_media
validation
def process_media(part) # Mail body auto-magically decodes quoted # printable for text/html type. file = temp_file(part) if part.part_type? =~ /^text\// || part.part_type? == 'application/smil' type, content = transform_text_part(part) else if part.part_type? == 'a...
ruby
{ "resource": "" }
q25667
MMS2R.MMS2R::Media.process_part
validation
def process_part(part) return if ignore_media?(part.part_type?, part) type, file = process_media(part) add_file(type, file) unless type.nil? || file.nil? end
ruby
{ "resource": "" }
q25668
MMS2R.MMS2R::Media.transform_text
validation
def transform_text(type, text) return type, text if !config['transform'] || !(transforms = config['transform'][type]) if RUBY_VERSION < "1.9" require 'iconv' ic = Iconv.new('UTF-8', 'ISO-8859-1') text = ic.iconv(text) text << ic.iconv(nil) ic.close end t...
ruby
{ "resource": "" }
q25669
MMS2R.MMS2R::Media.transform_text_part
validation
def transform_text_part(part) type = part.part_type? text = part.body.decoded.strip transform_text(type, text) end
ruby
{ "resource": "" }
q25670
MMS2R.MMS2R::Media.temp_file
validation
def temp_file(part) file_name = filename?(part) File.expand_path(File.join(msg_tmp_dir(),File.basename(file_name))) end
ruby
{ "resource": "" }
q25671
MMS2R.MMS2R::Media.add_file
validation
def add_file(type, file) media[type] = [] unless media[type] media[type] << file end
ruby
{ "resource": "" }
q25672
MMS2R.MMS2R::Media.msg_tmp_dir
validation
def msg_tmp_dir @dir_count += 1 dir = File.expand_path(File.join(@media_dir, "#{@dir_count}")) FileUtils.mkdir_p(dir) dir end
ruby
{ "resource": "" }
q25673
MMS2R.MMS2R::Media.filename?
validation
def filename?(part) name = part.filename if (name.nil? || name.empty?) if part.content_id && (matched = /^<(.+)>$/.match(part.content_id)) name = matched[1] else name = "#{Time.now.to_f}.#{self.default_ext(part.part_type?)}" end end # FIXME FWIW, janky...
ruby
{ "resource": "" }
q25674
MMS2R.MMS2R::Media.type_from_filename
validation
def type_from_filename(filename) ext = filename.split('.').last ent = MMS2R::EXT.detect{|k,v| v == ext} ent.nil? ? nil : ent.first end
ruby
{ "resource": "" }
q25675
ArJdbc.AS400.prefetch_primary_key?
validation
def prefetch_primary_key?(table_name = nil) return true if table_name.nil? table_name = table_name.to_s primary_keys(table_name.to_s).size == 0 end
ruby
{ "resource": "" }
q25676
ArJdbc.AS400.execute_and_auto_confirm
validation
def execute_and_auto_confirm(sql, name = nil) begin execute_system_command('CHGJOB INQMSGRPY(*SYSRPYL)') execute_system_command("ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I')") rescue Exception => e raise unauthorized_error_message("CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(987...
ruby
{ "resource": "" }
q25677
TravisCustomDeploy.Deployment.get_transfer
validation
def get_transfer(type) type = type[0].upcase + type[1..-1] try_require(type) Transfer.const_get(type).new(@options, @files) end
ruby
{ "resource": "" }
q25678
Smurf.Javascript.peek
validation
def peek(aheadCount=1) history = [] aheadCount.times { history << @input.getc } history.reverse.each { |chr| @input.ungetc(chr) } return history.last.chr end
ruby
{ "resource": "" }
q25679
Motion.Capture.captureOutput
validation
def captureOutput(output, didFinishProcessingPhoto: photo, error: error) if error error_callback.call(error) else @capture_callback.call(photo.fileDataRepresentation) end end
ruby
{ "resource": "" }
q25680
Motion.Capture.captureOutput
validation
def captureOutput(output, didFinishProcessingPhotoSampleBuffer: photo_sample_buffer, previewPhotoSampleBuffer: preview_photo_sample_buffer, resolvedSettings: resolved_settings, bracketSettings: bracket_settings, error: error) if error error_callback.call(error) else jpeg_data = AVCapturePhotoOutput....
ruby
{ "resource": "" }
q25681
Motion.Capture.save_to_assets_library
validation
def save_to_assets_library(jpeg_data, &block) assets_library.writeImageDataToSavedPhotosAlbum(jpeg_data, metadata: nil, completionBlock: -> (asset_url, error) { error ? error_callback.call(error) : block.call(asset_url) }) end
ruby
{ "resource": "" }
q25682
Motion.Capture.save_to_photo_library
validation
def save_to_photo_library(jpeg_data, &block) photo_library.performChanges(-> { image = UIImage.imageWithData(jpeg_data) PHAssetChangeRequest.creationRequestForAssetFromImage(image) }, completionHandler: -> (success, error) { if error error_callback.call(error) else block....
ruby
{ "resource": "" }
q25683
Motion.Capture.update_video_orientation!
validation
def update_video_orientation! photo_output.connectionWithMediaType(AVMediaTypeVideo).tap do |connection| device_orientation = UIDevice.currentDevice.orientation video_orientation = orientation_mapping.fetch(device_orientation, AVCaptureVideoOrientationPortrait) connection.setVideoOrientation(vid...
ruby
{ "resource": "" }
q25684
OnedClusterer.Ckmeans.select_levels
validation
def select_levels(data, backtrack, kmin, kmax) return kmin if kmin == kmax method = :normal # "uniform" or "normal" kopt = kmin base = 1 # The position of first element in x: 1 or 0. n = data.size - base max_bic = 0.0 for k in kmin..kmax cluster_sizes ...
ruby
{ "resource": "" }
q25685
SourceRoute.ParamsConfigParser.full_feature
validation
def full_feature(value=true) return unless value @config.formulize @config.event = (@config.event + [:call, :return]).uniq @config.import_return_to_call = true @config.show_additional_attrs = [:path, :lineno] # JSON serialize trigger many problems when handle complicated object(in ra...
ruby
{ "resource": "" }
q25686
Pancake.Middleware.stack
validation
def stack(name = nil, opts = {}) if self::StackMiddleware._mwares[name] && mw = self::StackMiddleware._mwares[name] unless mw.stack == self mw = self::StackMiddleware._mwares[name] = self::StackMiddleware._mwares[name].dup end mw else self::StackMiddleware.new(name,...
ruby
{ "resource": "" }
q25687
Pancake.Middleware.use
validation
def use(middleware, *_args, &block) stack(middleware).use(middleware, *_args, &block) end
ruby
{ "resource": "" }
q25688
Metadata::Ingest::Translators.FormToAttributes.attribute_lookup
validation
def attribute_lookup(assoc) group_data = @map[assoc.group.to_sym] return nil unless group_data attribute = group_data[assoc.type.to_sym] return attribute end
ruby
{ "resource": "" }
q25689
Metadata::Ingest::Translators.FormToAttributes.translate_association
validation
def translate_association(assoc) attribute = attribute_lookup(assoc) return unless attribute # Make sure we properly handle destroyed values by forcing them to an # empty association. We keep their state up to this point because the # caller may be using the prior value for something. ...
ruby
{ "resource": "" }
q25690
Metadata::Ingest::Translators.FormToAttributes.add_association_to_attribute_map
validation
def add_association_to_attribute_map(attribute, assoc) current = @attributes[attribute] # If there's already a value, we can safely ignore the empty association return if current && assoc.blank? case current when nil then @attributes[attribute] = [assoc] when Array then @at...
ruby
{ "resource": "" }
q25691
Metadata::Ingest::Translators.FormToAttributes.store_associations_on_object
validation
def store_associations_on_object(object, attribute, associations) values = associations.collect do |assoc| assoc.internal.blank? ? assoc.value : assoc.internal end # Clean up values values.compact! case values.length when 0 then values = nil when 1 then values = va...
ruby
{ "resource": "" }
q25692
Metadata::Ingest::Translators.AttributesToForm.setup_form
validation
def setup_form(group, type, attr_definition) attr_trans = single_attribute_translator.new( source: @source, form: @form, group: group, type: type, attribute_definition: attr_definition ) attr_trans.add_associations_to_form end
ruby
{ "resource": "" }
q25693
Pancake.Router.mount
validation
def mount(mounted_app, path, options = {}) mounted_app = MountedApplication.new(mounted_app, path, options) self.class.mounted_applications << mounted_app mounted_app end
ruby
{ "resource": "" }
q25694
SourceRoute.GenerateResult.assign_tp_self_caches
validation
def assign_tp_self_caches(tp_ins) unless tp_self_caches.find { |tp_cache| tp_cache.object_id.equal? tp_ins.self.object_id } tp_self_caches.push tp_ins.self end end
ruby
{ "resource": "" }
q25695
Pancake.Logger.set_log
validation
def set_log(stream = Pancake.configuration.log_stream, log_level = Pancake.configuration.log_level, delimiter = Pancake.configuration.log_delimiter, auto_flush = Pancake.configuration.log_auto_flush) @buffer = [] @delimiter = delimiter @auto_flush ...
ruby
{ "resource": "" }
q25696
Pancake.Paths.dirs_for
validation
def dirs_for(name, opts = {}) if _load_paths[name].blank? [] else result = [] invert = !!opts[:invert] load_paths = invert ? _load_paths[name].reverse : _load_paths[name] roots.each do |root| load_paths.each do |paths, glob| paths = paths.reverse...
ruby
{ "resource": "" }
q25697
Pancake.Paths.paths_for
validation
def paths_for(name, opts = {}) result = [] dirs_and_glob_for(name, opts).each do |path, glob| next if glob.nil? paths = Dir[File.join(path, glob)] paths = paths.reverse if opts[:invert] paths.each do |full_path| result << [path, full_path.gsub(path, "")] end...
ruby
{ "resource": "" }
q25698
Pancake.Paths.unique_paths_for
validation
def unique_paths_for(name, opts = {}) tally = {} output = [] paths_for(name, opts).reverse.each do |ary| tally[ary[1]] ||= ary[0] output << ary if tally[ary[1]] == ary[0] end output.reverse end
ruby
{ "resource": "" }
q25699
Metadata::Ingest::Translators.SingleAttributeTranslator.build_association
validation
def build_association(value) association = @form.create_association( group: @group.to_s, type: @type.to_s, value: value ) # Since the associations are fake, we just set persistence to the parent # object's value association.persisted = @source.persisted? return association ...
ruby
{ "resource": "" }