_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
30
4.3k
language
stringclasses
1 value
meta_information
dict
q21500
Spark.RDD.subtract
train
def subtract(other, num_partitions=nil) mapping_function = 'lambda{|x| [x,nil]}' self.map(mapping_function)
ruby
{ "resource": "" }
q21501
Spark.RDD.sort_by
train
def sort_by(key_function=nil, ascending=true, num_partitions=nil) key_function ||= 'lambda{|x| x}' num_partitions ||= default_reduce_partitions command_klass = Spark::Command::SortByKey # Allow spill data to disk due to memory limit # spilling = config['spark.shuffle.spill'] || false ...
ruby
{ "resource": "" }
q21502
Spark.RDD._reduce
train
def _reduce(klass, seq_op, comb_op, zero_value=nil) if seq_op.nil? # Partitions are already reduced rdd = self else rdd = new_rdd_from_command(klass, seq_op, zero_value) end # Send all results to one worker and combine results rdd = rdd.coalesce(1)....
ruby
{ "resource": "" }
q21503
Spark.RDD._combine_by_key
train
def _combine_by_key(combine, merge, num_partitions) num_partitions ||= default_reduce_partitions # Combine key combined = new_rdd_from_command(combine.shift, *combine) # Merge items
ruby
{ "resource": "" }
q21504
Spark.Logger.disable
train
def disable jlogger.setLevel(level_off) JLogger.getLogger('org').setLevel(level_off)
ruby
{ "resource": "" }
q21505
Spark.Context.accumulator
train
def accumulator(value, accum_param=:+, zero_value=0)
ruby
{ "resource": "" }
q21506
Spark.Context.parallelize
train
def parallelize(data, num_slices=nil, serializer=nil) num_slices ||= default_parallelism serializer ||= default_serializer serializer.check_each(data) # Through file file = Tempfile.new('to_parallelize', temp_dir) serializer.dump_to_io(data, file) file.close # not unlink ...
ruby
{ "resource": "" }
q21507
Spark.Context.run_job
train
def run_job(rdd, f, partitions=nil, allow_local=false) run_job_with_command(rdd,
ruby
{ "resource": "" }
q21508
Spark.Context.run_job_with_command
train
def run_job_with_command(rdd, partitions, allow_local, command, *args) if !partitions.nil? && !partitions.is_a?(Array) raise Spark::ContextError, 'Partitions must be nil or Array' end partitions_size = rdd.partitions_size # Execute all parts if partitions.nil? partitions ...
ruby
{ "resource": "" }
q21509
Spark.StatCounter.merge
train
def merge(other) if other.is_a?(Spark::StatCounter) merge_stat_counter(other) elsif other.respond_to?(:each) merge_array(other)
ruby
{ "resource": "" }
q21510
Caze.ClassMethods.raise_use_case_error
train
def raise_use_case_error(use_case, error) name = error.class.name.split('::').last klass = define_use_case_error(use_case, name) wrapped
ruby
{ "resource": "" }
q21511
SchemaEvolutionManager.Db.bootstrap!
train
def bootstrap! scripts = Scripts.new(self, Scripts::BOOTSTRAP_SCRIPTS) dir = File.join(Library.base_dir, "scripts") scripts.each_pending(dir) do |filename, path|
ruby
{ "resource": "" }
q21512
SchemaEvolutionManager.Db.psql_command
train
def psql_command(sql_command) Preconditions.assert_class(sql_command, String) command
ruby
{ "resource": "" }
q21513
SchemaEvolutionManager.MigrationFile.parse_attribute_values
train
def parse_attribute_values values = [] each_property do |name, value| values << AttributeValue.new(name, value)
ruby
{ "resource": "" }
q21514
SchemaEvolutionManager.Scripts.each_pending
train
def each_pending(dir) files = {} Scripts.all(dir).each do |path| name = File.basename(path) files[name] = path end scripts_previously_run(files.keys).each do |filename| files.delete(filename) end files.keys.sort.each do |filename| ## We have to reche...
ruby
{ "resource": "" }
q21515
SchemaEvolutionManager.Scripts.has_run?
train
def has_run?(filename) if @db.schema_schema_evolution_manager_exists? query = "select count(*) from %s.%s where filename = '%s'" % [Db.schema_name, @table_name,
ruby
{ "resource": "" }
q21516
SchemaEvolutionManager.Scripts.record_as_run!
train
def record_as_run!(filename) Preconditions.check_state(filename.match(/^\d\d\d\d\d\d+\-\d\d\d\d\d\d\.sql$/), "Invalid filename[#{filename}]. Must be like: 20120503-173242.sql") command = "insert into %s.%s (filename) select '%s' where
ruby
{ "resource": "" }
q21517
SchemaEvolutionManager.Scripts.scripts_previously_run
train
def scripts_previously_run(scripts) if scripts.empty? || !@db.schema_schema_evolution_manager_exists? [] else sql = "select filename from %s.%s where filename in (%s)"
ruby
{ "resource": "" }
q21518
SchemaEvolutionManager.InstallTemplate.generate
train
def generate template = Template.new template.add('timestamp', Time.now.to_s) template.add('lib_dir', @lib_dir)
ruby
{ "resource": "" }
q21519
Wp2txt.Runner.fill_buffer
train
def fill_buffer while true do begin new_lines = @file_pointer.read(10485760) rescue => e return nil end return nil unless new_lines # temp_buf is filled with text split by "\n" temp_buf = [] ss = StringScanner.new(new_lines) ...
ruby
{ "resource": "" }
q21520
LanguageFilter.Filter.replace
train
def replace(word) case @replacement when :vowels then word.gsub(/[aeiou]/i, '*') when :stars then '*' * word.size when :nonconsonants then word.gsub(/[^bcdfghjklmnpqrstvwxyz]/i, '*') when :default, :garbled then '$@!#%'
ruby
{ "resource": "" }
q21521
Jekyll.StaticFile.to_page
train
def to_page page = Jekyll::Page.new(@site, @base, @dir, @name) page.data["permalink"] =
ruby
{ "resource": "" }
q21522
AppleSystemStatus.Crawler.perform
train
def perform(country: nil, title: nil) @session.visit(apple_url(country)) response = { title: @session.find(".section-date .date-copy").text.strip, services: [], } MAX_RETRY_COUNT.times do services = fetch_services if services.empty? # wait until th...
ruby
{ "resource": "" }
q21523
FioAPI.List.fetch_and_deserialize_response
train
def fetch_and_deserialize_response(path) self.request = FioAPI::Request.get(path,
ruby
{ "resource": "" }
q21524
Archangel.FlashHelper.flash_class_for
train
def flash_class_for(flash_type) flash_type = flash_type.to_s.downcase.parameterize { success: "success", error: "danger", alert:
ruby
{ "resource": "" }
q21525
Momentum::OpsWorks.Deployer.execute_recipe!
train
def execute_recipe!(stack_name, layer, recipe, app_name = Momentum.config[:app_base_name]) raise "No recipe provided" unless recipe stack = Momentum::OpsWorks.get_stack(@ow, stack_name) app = Momentum::OpsWorks.get_app(@ow, stack, app_name) layer_names = layer ? [layer] : Momentum.config[:app_la...
ruby
{ "resource": "" }
q21526
Fix.On.it
train
def it(*, &spec) i = It.new(described, challenges, helpers) result = i.verify(&spec)
ruby
{ "resource": "" }
q21527
Fix.On.on
train
def on(method_name, *args, &block) o = On.new(described, results, (challenges + [Defi.send(method_name, *args)]),
ruby
{ "resource": "" }
q21528
Fix.On.context
train
def context(*, &block) o = On.new(described, [], challenges,
ruby
{ "resource": "" }
q21529
Emittance.Watcher.watch
train
def watch(identifier, callback_method = nil, **params, &callback) if callback _dispatcher(params).register identifier, params, &callback else
ruby
{ "resource": "" }
q21530
Archangel.RenderService.call
train
def call liquid = ::Liquid::Template.parse(template)
ruby
{ "resource": "" }
q21531
Archangel.ApplicationHelper.frontend_resource_path
train
def frontend_resource_path(resource) permalink_path = proc do |permalink| archangel.frontend_page_path(permalink).gsub("%2F", "/") end return permalink_path.call(resource) unless
ruby
{ "resource": "" }
q21532
Seoshop.Client.get
train
def get(url, params = {}) params = params.inject({}){|memo,(k,v)| memo[k.to_s] =
ruby
{ "resource": "" }
q21533
Seoshop.Client.post
train
def post(url, params) params = convert_hash_keys(params) preform(url, :post, params: params) do
ruby
{ "resource": "" }
q21534
Seoshop.Client.put
train
def put(url, params) params = convert_hash_keys(params) preform(url, :put, params: params) do
ruby
{ "resource": "" }
q21535
Archangel.LiquidView.render
train
def render(template, local_assigns = {}) default_controller.headers["Content-Type"] ||= "text/html; charset=utf-8" assigns = default_assigns(local_assigns) options =
ruby
{ "resource": "" }
q21536
BibTeX.Lexer.push
train
def push(value) case value[0] when :CONTENT, :STRING_LITERAL value[1].gsub!(/\n\s*/, ' ') if strip_line_breaks? if !@stack.empty? && value[0] == @stack[-1][0] @stack[-1][1] << value[1] else @stack.push(value) end
ruby
{ "resource": "" }
q21537
BibTeX.Lexer.analyse
train
def analyse(string = nil) raise(ArgumentError, 'Lexer: failed to start analysis: no source given!') unless string || @scanner self.data = string || @scanner.string
ruby
{ "resource": "" }
q21538
BibTeX.Lexer.enter_object
train
def enter_object @brace_level = 0 push [:AT,'@'] case when @scanner.scan(Lexer.patterns[:string]) @mode = @active_object = :string push [:STRING, @scanner.matched] when @scanner.scan(Lexer.patterns[:preamble]) @mode = @active_object = :preamble push [:PREAM...
ruby
{ "resource": "" }
q21539
BibTeX.Entry.initialize_copy
train
def initialize_copy(other) @fields = {} self.type = other.type self.key
ruby
{ "resource": "" }
q21540
BibTeX.Entry.key=
train
def key=(key) key = key.to_s if registered? bibliography.entries.delete(@key) key = register(key) end @key = key rescue => e
ruby
{ "resource": "" }
q21541
BibTeX.Entry.provide
train
def provide(name) return nil unless name.respond_to?(:to_sym)
ruby
{ "resource": "" }
q21542
BibTeX.Entry.field_names
train
def field_names(filter = [], include_inherited = true) names = fields.keys if include_inherited && has_parent? names.concat(inherited_fields) end
ruby
{ "resource": "" }
q21543
BibTeX.Entry.inherited_fields
train
def inherited_fields return [] unless has_parent? names = parent.fields.keys - fields.keys names.concat(parent.aliases.reject
ruby
{ "resource": "" }
q21544
BibTeX.Entry.rename!
train
def rename!(*arguments) Hash[*arguments.flatten].each_pair do |from,to| if fields.has_key?(from) && !fields.has_key?(to)
ruby
{ "resource": "" }
q21545
BibTeX.Entry.valid?
train
def valid? REQUIRED_FIELDS[type].all? do |f|
ruby
{ "resource": "" }
q21546
BibTeX.Entry.digest
train
def digest(filter = []) names = field_names(filter) digest = type.to_s names.zip(values_at(*names)).each do |key, value| digest << "|#{key}:#{value}"
ruby
{ "resource": "" }
q21547
BibTeX.Entry.added_to_bibliography
train
def added_to_bibliography(bibliography) super @key = register(key) [:parse_names, :parse_months].each do |parser| send(parser) if bibliography.options[parser] end if bibliography.options.has_key?(:filter)
ruby
{ "resource": "" }
q21548
BibTeX.Entry.register
train
def register(key) return nil if bibliography.nil? k = key.dup k.succ! while bibliography.has_key?(k)
ruby
{ "resource": "" }
q21549
BibTeX.Entry.parse_names
train
def parse_names strings = bibliography ? bibliography.strings.values : [] NAME_FIELDS.each do |key| if name = fields[key]
ruby
{ "resource": "" }
q21550
BibTeX.Entry.convert!
train
def convert!(*filters) filters = filters.flatten.map { |f| Filters.resolve!(f) } fields.each_pair do |k, v|
ruby
{ "resource": "" }
q21551
BibTeX.Entry.default_key
train
def default_key k = names[0] k = k.respond_to?(:family) ? k.family : k.to_s k = BibTeX.transliterate(k).gsub(/["']/, '') k = k[/[A-Za-z-]+/] || 'unknown'
ruby
{ "resource": "" }
q21552
BibTeX.Bibliography.initialize_copy
train
def initialize_copy(other) @options = other.options.dup @errors = other.errors.dup @data, @strings = [], {} @entries = Hash.new { |h,k| h.fetch(k.to_s, nil) }
ruby
{ "resource": "" }
q21553
BibTeX.Bibliography.add
train
def add(*arguments) Element.parse(arguments.flatten, @options).each do |element|
ruby
{ "resource": "" }
q21554
BibTeX.Bibliography.save_to
train
def save_to(path, options = {}) options[:quotes] ||= %w({ }) File.open(path, 'w:UTF-8') do |f|
ruby
{ "resource": "" }
q21555
BibTeX.Bibliography.delete
train
def delete(*arguments, &block) objects = q(*arguments, &block).map { |o| o.removed_from_bibliography(self) } @data =
ruby
{ "resource": "" }
q21556
BibTeX.Bibliography.extend_initials!
train
def extend_initials! groups = Hash.new do |h,k| h[k] = { :prototype => nil, :names => [] } end # group names together names.each do |name| group = groups[name.sort_order(:initials => true).downcase] group[:names] << name if group[:prototype].nil? || group[:proto...
ruby
{ "resource": "" }
q21557
BibTeX.Element.matches?
train
def matches?(query) return true if query.nil? || query.respond_to?(:empty?) && query.empty? case query when Symbol query.to_s == id.to_s when Element query == self when Regexp to_s.match(query) when /^\/(.+)\/$/ to_s.match(Regexp.new($1)) when /...
ruby
{ "resource": "" }
q21558
BibTeX.Name.set
train
def set(attributes = {}) attributes.each_pair do |key, value|
ruby
{ "resource": "" }
q21559
BibTeX.Name.extend_initials
train
def extend_initials(with_first, for_last) rename_if :first => with_first do |name| if name.last == for_last mine = name.initials.split(/\.[^[:alpha:]]*/) other = initials(with_first).split(/\.[^[:alpha:]]*/)
ruby
{ "resource": "" }
q21560
BibTeX.Name.rename_if
train
def rename_if(attributes, conditions = {}) if block_given? set(attributes) if yield self else set(attributes) if conditions.all? do |key, value|
ruby
{ "resource": "" }
q21561
Assert.Context.assert
train
def assert(assertion, desc = nil) if assertion pass else what = if block_given? yield
ruby
{ "resource": "" }
q21562
Assert.Context.pass
train
def pass(pass_msg = nil) if @__assert_pending__ == 0 capture_result(Assert::Result::Pass, pass_msg) else capture_result(Assert::Result::Fail, "Pending pass
ruby
{ "resource": "" }
q21563
Assert.Context.fail
train
def fail(message = nil) if @__assert_pending__ == 0 if halt_on_fail? raise Result::TestFailure, message || "" else capture_result(Assert::Result::Fail, message || "") end else if halt_on_fail?
ruby
{ "resource": "" }
q21564
ResqueUnit.Scheduler.enqueue_in
train
def enqueue_in(number_of_seconds_from_now, klass, *args)
ruby
{ "resource": "" }
q21565
ResqueUnit.Helpers.decode
train
def decode(object) return unless object if defined? Yajl begin Yajl::Parser.parse(object, :check_utf8 => false) rescue Yajl::ParseError end else
ruby
{ "resource": "" }
q21566
ResqueUnit.Helpers.constantize
train
def constantize(camel_cased_word) camel_cased_word = camel_cased_word.to_s if camel_cased_word.include?('-') camel_cased_word = classify(camel_cased_word) end names = camel_cased_word.split('::') names.shift if names.empty? || names.first.empty? constant = Object
ruby
{ "resource": "" }
q21567
Unitwise.Term.atom=
train
def atom=(value) value.is_a?(Atom)
ruby
{ "resource": "" }
q21568
Unitwise.Term.prefix=
train
def prefix=(value) value.is_a?(Prefix)
ruby
{ "resource": "" }
q21569
Unitwise.Term.root_terms
train
def root_terms if terminal? [self] else atom.scale.root_terms.map do
ruby
{ "resource": "" }
q21570
Unitwise.Term.operate
train
def operate(operator, other) exp = operator == '/' ? -1 : 1 if other.respond_to?(:terms) Unit.new(other.terms.map { |t| t ** exp } << self) elsif other.respond_to?(:atom)
ruby
{ "resource": "" }
q21571
Unitwise.Base.to_s
train
def to_s(mode = :primary_code) res = send(mode)
ruby
{ "resource": "" }
q21572
Unitwise.Atom.scale=
train
def scale=(attrs) @scale = if attrs[:function_code] Functional.new(attrs[:value], attrs[:unit_code], attrs[:function_code]) else
ruby
{ "resource": "" }
q21573
Unitwise.Atom.validate!
train
def validate! missing_properties = %i{primary_code names scale}.select do |prop| val = liner_get(prop) val.nil? || (val.respond_to?(:empty) && val.empty?) end if !missing_properties.empty? missing_list = missing_properties.join(',') raise Unitwise::DefinitionError, ...
ruby
{ "resource": "" }
q21574
Unitwise.Compatible.composition
train
def composition root_terms.reduce(SignedMultiset.new) do |s, t|
ruby
{ "resource": "" }
q21575
Unitwise.Compatible.composition_string
train
def composition_string composition.sort.map do
ruby
{ "resource": "" }
q21576
Unitwise.Unit.terms
train
def terms unless frozen? unless @terms decomposer = Expression.decompose(@expression) @mode = decomposer.mode
ruby
{ "resource": "" }
q21577
Unitwise.Unit.expression
train
def expression(mode=nil) if @expression && (mode.nil? || mode == self.mode) @expression else
ruby
{ "resource": "" }
q21578
Unitwise.Unit.scalar
train
def scalar(magnitude = 1) terms.reduce(1) do |prod, term|
ruby
{ "resource": "" }
q21579
Unitwise.Unit.**
train
def **(other) if other.is_a?(Numeric) self.class.new(terms.map { |t| t ** other }) else
ruby
{ "resource": "" }
q21580
Unitwise.Unit.operate
train
def operate(operator, other) exp = operator == '/' ? -1 : 1 if other.respond_to?(:terms) self.class.new(terms + other.terms.map { |t|
ruby
{ "resource": "" }
q21581
Unitwise.Measurement.convert_to
train
def convert_to(other_unit) other_unit = Unit.new(other_unit) if compatible_with?(other_unit) new(converted_value(other_unit), other_unit) else
ruby
{ "resource": "" }
q21582
Unitwise.Measurement.**
train
def **(other) if other.is_a?(Numeric) new(value ** other, unit ** other) else fail
ruby
{ "resource": "" }
q21583
Unitwise.Measurement.round
train
def round(digits = nil) rounded_value = digits ? value.round(digits)
ruby
{ "resource": "" }
q21584
Unitwise.Measurement.method_missing
train
def method_missing(meth, *args, &block) if args.empty? && !block_given? && (match = /\Ato_(\w+)\Z/.match(meth.to_s)) begin convert_to(match[1]) rescue ExpressionError
ruby
{ "resource": "" }
q21585
Unitwise.Measurement.converted_value
train
def converted_value(other_unit) if other_unit.special? other_unit.magnitude scalar else
ruby
{ "resource": "" }
q21586
Unitwise.Measurement.combine
train
def combine(operator, other) if other.respond_to?(:composition) && compatible_with?(other)
ruby
{ "resource": "" }
q21587
Unitwise.Measurement.operate
train
def operate(operator, other) if other.is_a?(Numeric) new(value.send(operator, other), unit) elsif other.respond_to?(:composition) if compatible_with?(other) converted = other.convert_to(unit) new(value.send(operator, converted.value), unit.send(operator,
ruby
{ "resource": "" }
q21588
Unitwise.Scale.scalar
train
def scalar(magnitude = value) if special? unit.scalar(magnitude)
ruby
{ "resource": "" }
q21589
Unitwise.Scale.magnitude
train
def magnitude(scalar = scalar()) if special?
ruby
{ "resource": "" }
q21590
Unitwise.Scale.to_s
train
def to_s(mode = nil) unit_string = unit.to_s(mode) if unit_string && unit_string != '1'
ruby
{ "resource": "" }
q21591
QML.Engine.evaluate
train
def evaluate(str, file = '<in QML::Engine#evaluate>', lineno = 1) evaluate_impl(str, file, lineno).tap do |result|
ruby
{ "resource": "" }
q21592
QML.Component.load_path
train
def load_path(path) path = path.to_s check_error_string do @path = Pathname.new(path)
ruby
{ "resource": "" }
q21593
QML.Signal.emit
train
def emit(*args) if args.size != @arity fail ::ArgumentError ,"wrong number of arguments for signal (#{args.size} for #{@arity})" end
ruby
{ "resource": "" }
q21594
QML.ListModel.moving
train
def moving(range, destination) return if range.count == 0 @access.begin_move(range.min, range.max, destination)
ruby
{ "resource": "" }
q21595
QML.ListModel.inserting
train
def inserting(range, &block) return if range.count == 0
ruby
{ "resource": "" }
q21596
QML.ListModel.removing
train
def removing(range, &block) return if range.count == 0 @access.begin_remove(range.min,
ruby
{ "resource": "" }
q21597
QML.ArrayModel.insert
train
def insert(index, *items) inserting(index ... index + items.size) do
ruby
{ "resource": "" }
q21598
QML.JSObject.method_missing
train
def method_missing(method, *args, &block) if method[-1] == '=' # setter key = method.slice(0...-1).to_sym unless has_key?(key) super end
ruby
{ "resource": "" }
q21599
ZPNG.Adam7Decoder.convert_coords
train
def convert_coords x,y # optimizing this into one switch/case statement gives # about 1-2% speed increase (ruby 1.9.3p286) if y%2 == 1 # 7th pass: last height/2 full scanlines [x, y/2 + @pass_starts[7]] elsif x%2 == 1 && y%2 == 0 # 6th pass [x/2, y/2 + @pass_star...
ruby
{ "resource": "" }