_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q26700
Aerospike.Command.write_header
test
def write_header(policy, read_attr, write_attr, field_count, operation_count) read_attr |= INFO1_CONSISTENCY_ALL if policy.consistency_level == Aerospike::ConsistencyLevel::CONSISTENCY_ALL # Write all header data except total size which must be written last. @data_buffer.write_byte(MSG_REMAINING_HEAD...
ruby
{ "resource": "" }
q26701
Aerospike.Command.write_header_with_policy
test
def write_header_with_policy(policy, read_attr, write_attr, field_count, operation_count) # Set flags. generation = Integer(0) info_attr = Integer(0) case policy.record_exists_action when Aerospike::RecordExistsAction::UPDATE when Aerospike::RecordExistsAction::UPDATE_ONLY i...
ruby
{ "resource": "" }
q26702
Aerospike.ExecuteTask.all_nodes_done?
test
def all_nodes_done? if @scan command = 'scan-list' else command = 'query-list' end nodes = @cluster.nodes done = false nodes.each do |node| conn = node.get_connection(0) responseMap, _ = Info.request(conn, command) node.put_connection(conn) ...
ruby
{ "resource": "" }
q26703
Aerospike.Node.get_connection
test
def get_connection(timeout) loop do conn = @connections.poll if conn.connected? conn.timeout = timeout.to_f return conn end end end
ruby
{ "resource": "" }
q26704
Aerospike.MultiCommand.parse_record
test
def parse_record(key, op_count, generation, expiration) bins = op_count > 0 ? {} : nil i = 0 while i < op_count raise Aerospike::Exceptions::QueryTerminated.new unless valid? read_bytes(8) op_size = @data_buffer.read_int32(0).ord particle_type = @data_buffer.read(5).o...
ruby
{ "resource": "" }
q26705
Aerospike.Cluster.random_node
test
def random_node # Must copy array reference for copy on write semantics to work. node_array = nodes length = node_array.length i = 0 while i < length # Must handle concurrency with other non-tending threads, so node_index is consistent. index = (@node_index.update{ |v| v+1 ...
ruby
{ "resource": "" }
q26706
Aerospike.Cluster.get_node_by_name
test
def get_node_by_name(node_name) node = find_node_by_name(node_name) raise Aerospike::Exceptions::InvalidNode unless node node end
ruby
{ "resource": "" }
q26707
Aerospike.Client.prepend
test
def prepend(key, bins, options = nil) policy = create_policy(options, WritePolicy, default_write_policy) command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::PREPEND) execute_command(command) end
ruby
{ "resource": "" }
q26708
Aerospike.Client.get_header
test
def get_header(key, options = nil) policy = create_policy(options, Policy, default_read_policy) command = ReadHeaderCommand.new(@cluster, policy, key) execute_command(command) command.record end
ruby
{ "resource": "" }
q26709
Aerospike.Client.batch_exists
test
def batch_exists(keys, options = nil) policy = create_policy(options, BatchPolicy, default_batch_policy) results = Array.new(keys.length) if policy.use_batch_direct key_map = BatchItem.generate_map(keys) execute_batch_direct_commands(keys) do |node, batch| BatchDirectExistsC...
ruby
{ "resource": "" }
q26710
Aerospike.Client.register_udf
test
def register_udf(udf_body, server_path, language, options = nil) policy = create_policy(options, Policy, default_info_policy) content = Base64.strict_encode64(udf_body).force_encoding('binary') str_cmd = "udf-put:filename=#{server_path};content=#{content};" str_cmd << "content-len=#{content.len...
ruby
{ "resource": "" }
q26711
Aerospike.Client.remove_udf
test
def remove_udf(udf_name, options = nil) policy = create_policy(options, Policy, default_info_policy) str_cmd = "udf-remove:filename=#{udf_name};" # Send command to one node. That node will distribute it to other nodes. # Send UDF to one node. That node will distribute the UDF to other nodes. ...
ruby
{ "resource": "" }
q26712
Aerospike.Client.list_udf
test
def list_udf(options = nil) policy = create_policy(options, Policy, default_info_policy) str_cmd = 'udf-list' # Send command to one node. That node will distribute it to other nodes. response_map = @cluster.request_info(policy, str_cmd) _, response = response_map.first vals = resp...
ruby
{ "resource": "" }
q26713
Aerospike.Client.execute_udf_on_query
test
def execute_udf_on_query(statement, package_name, function_name, function_args=[], options = nil) policy = create_policy(options, QueryPolicy, default_query_policy) nodes = @cluster.nodes if nodes.empty? raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "...
ruby
{ "resource": "" }
q26714
Aerospike.Client.create_index
test
def create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = nil) if options.nil? && collection_type.is_a?(Hash) options, collection_type = collection_type, nil end policy = create_policy(options, Policy, default_info_policy) str_cmd = "sindex...
ruby
{ "resource": "" }
q26715
Aerospike.Client.drop_index
test
def drop_index(namespace, set_name, index_name, options = nil) policy = create_policy(options, Policy, default_info_policy) str_cmd = "sindex-delete:ns=#{namespace}" str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty? str_cmd << ";indexname=#{index_name}" # Send index command...
ruby
{ "resource": "" }
q26716
Aerospike.Client.scan_node
test
def scan_node(node, namespace, set_name, bin_names = nil, options = nil) policy = create_policy(options, ScanPolicy, default_scan_policy) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # Retry policy must be one-shot for...
ruby
{ "resource": "" }
q26717
Aerospike.Client.drop_user
test
def drop_user(user, options = nil) policy = create_policy(options, AdminPolicy, default_admin_policy) command = AdminCommand.new command.drop_user(@cluster, policy, user) end
ruby
{ "resource": "" }
q26718
Aerospike.Client.change_password
test
def change_password(user, password, options = nil) raise Aerospike::Exceptions::Aerospike.new(INVALID_USER) unless @cluster.user && @cluster.user != "" policy = create_policy(options, AdminPolicy, default_admin_policy) hash = AdminCommand.hash_password(password) command = AdminCommand.new ...
ruby
{ "resource": "" }
q26719
Aerospike.Client.grant_roles
test
def grant_roles(user, roles, options = nil) policy = create_policy(options, AdminPolicy, default_admin_policy) command = AdminCommand.new command.grant_roles(@cluster, policy, user, roles) end
ruby
{ "resource": "" }
q26720
Aerospike.Client.query_users
test
def query_users(options = nil) policy = create_policy(options, AdminPolicy, default_admin_policy) command = AdminCommand.new command.query_users(@cluster, policy) end
ruby
{ "resource": "" }
q26721
Aerospike.Recordset.next_record
test
def next_record raise @thread_exception.get unless @thread_exception.get.nil? r = @records.deq set_exception if r.nil? r end
ruby
{ "resource": "" }
q26722
Aerospike.Recordset.each
test
def each(&block) r = true while r r = next_record # nil means EOF unless r.nil? block.call(r) else # reached the EOF break end end end
ruby
{ "resource": "" }
q26723
IntercomRails.ScriptTagHelper.intercom_script_tag
test
def intercom_script_tag(user_details = nil, options={}) controller.instance_variable_set(IntercomRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE, true) if defined?(controller) options[:user_details] = user_details if user_details.present? options[:find_current_user_details] = !options[:user_details]...
ruby
{ "resource": "" }
q26724
MiniGL.Movement.move_free
test
def move_free(aim, speed) if aim.is_a? Vector x_d = aim.x - @x; y_d = aim.y - @y distance = Math.sqrt(x_d**2 + y_d**2) if distance == 0 @speed.x = @speed.y = 0 return end @speed.x = 1.0 * x_d * speed / distance @speed.y = 1.0 * y_d * speed / di...
ruby
{ "resource": "" }
q26725
MiniGL.Map.get_absolute_size
test
def get_absolute_size return Vector.new(@tile_size.x * @size.x, @tile_size.y * @size.y) unless @isometric avg = (@size.x + @size.y) * 0.5 Vector.new (avg * @tile_size.x).to_i, (avg * @tile_size.y).to_i end
ruby
{ "resource": "" }
q26726
MiniGL.Map.get_screen_pos
test
def get_screen_pos(map_x, map_y) return Vector.new(map_x * @tile_size.x - @cam.x, map_y * @tile_size.y - @cam.y) unless @isometric Vector.new ((map_x - map_y - 1) * @tile_size.x * 0.5) - @cam.x + @x_offset, ((map_x + map_y) * @tile_size.y * 0.5) - @cam.y end
ruby
{ "resource": "" }
q26727
MiniGL.Map.get_map_pos
test
def get_map_pos(scr_x, scr_y) return Vector.new((scr_x + @cam.x) / @tile_size.x, (scr_y + @cam.y) / @tile_size.y) unless @isometric # Gets the position transformed to isometric coordinates v = get_isometric_position scr_x, scr_y # divides by the square size to find the position in the matrix ...
ruby
{ "resource": "" }
q26728
MiniGL.Map.is_in_map
test
def is_in_map(v) v.x >= 0 && v.y >= 0 && v.x < @size.x && v.y < @size.y end
ruby
{ "resource": "" }
q26729
MiniGL.Sprite.animate_once
test
def animate_once(indices, interval) if @animate_once_control == 2 return if indices == @animate_once_indices && interval == @animate_once_interval @animate_once_control = 0 end unless @animate_once_control == 1 @anim_counter = 0 @img_index = indices[0] @index_i...
ruby
{ "resource": "" }
q26730
MiniGL.Sprite.draw
test
def draw(map = nil, scale_x = 1, scale_y = 1, alpha = 0xff, color = 0xffffff, angle = nil, flip = nil, z_index = 0, round = false) if map.is_a? Hash scale_x = map.fetch(:scale_x, 1) scale_y = map.fetch(:scale_y, 1) alpha = map.fetch(:alpha, 0xff) color = map.fetch(:color, 0xffffff)...
ruby
{ "resource": "" }
q26731
MiniGL.Button.update
test
def update return unless @enabled and @visible mouse_over = Mouse.over? @x, @y, @w, @h mouse_press = Mouse.button_pressed? :left mouse_rel = Mouse.button_released? :left if @state == :up if mouse_over @img_index = 1 @state = :over else @img_i...
ruby
{ "resource": "" }
q26732
MiniGL.Button.draw
test
def draw(alpha = 0xff, z_index = 0, color = 0xffffff) return unless @visible color = (alpha << 24) | color text_color = if @enabled if @state == :down @down_text_color else @state == :over ? @over_text_color : @text_color end else ...
ruby
{ "resource": "" }
q26733
MiniGL.TextField.text=
test
def text=(value, trigger_changed = true) @text = value[0...@max_length] @nodes.clear; @nodes << @text_x x = @nodes[0] @text.chars.each { |char| x += @font.text_width(char) * @scale_x @nodes << x } @cur_node = @nodes.size - 1 @anchor1 = nil @anchor2 = nil ...
ruby
{ "resource": "" }
q26734
MiniGL.TextField.set_position
test
def set_position(x, y) d_x = x - @x d_y = y - @y @x = x; @y = y @text_x += d_x @text_y += d_y @nodes.map! do |n| n + d_x end end
ruby
{ "resource": "" }
q26735
MiniGL.TextField.draw
test
def draw(alpha = 0xff, z_index = 0, color = 0xffffff, disabled_color = 0x808080) return unless @visible color = (alpha << 24) | ((@enabled or @disabled_img) ? color : disabled_color) text_color = (alpha << 24) | (@enabled ? @text_color : @disabled_text_color) img = ((@enabled or @disabled_img.n...
ruby
{ "resource": "" }
q26736
MiniGL.ProgressBar.draw
test
def draw(alpha = 0xff, z_index = 0, color = 0xffffff) return unless @visible if @bg c = (alpha << 24) | color @bg.draw @x, @y, z_index, @scale_x, @scale_y, c else c = (alpha << 24) | @bg_color G.window.draw_quad @x, @y, c, @x + @w, @y, c, ...
ruby
{ "resource": "" }
q26737
MiniGL.DropDownList.update
test
def update return unless @enabled and @visible if @open and Mouse.button_pressed? :left and not Mouse.over?(@x, @y, @w, @max_h) toggle return end @buttons.each { |b| b.update } end
ruby
{ "resource": "" }
q26738
MiniGL.DropDownList.value=
test
def value=(val) if @options.include? val old = @value @value = @buttons[0].text = val @on_changed.call(old, val) if @on_changed end end
ruby
{ "resource": "" }
q26739
MiniGL.DropDownList.draw
test
def draw(alpha = 0xff, z_index = 0, color = 0xffffff, over_color = 0xcccccc) return unless @visible unless @img bottom = @y + (@open ? @max_h : @h) + @scale_y b_color = (alpha << 24) G.window.draw_quad @x - @scale_x, @y - @scale_y, b_color, @x + @w + @scale...
ruby
{ "resource": "" }
q26740
MiniGL.Label.draw
test
def draw(alpha = 255, z_index = 0, color = 0xffffff) c = @enabled ? @text_color : @disabled_text_color r1 = c >> 16 g1 = (c & 0xff00) >> 8 b1 = (c & 0xff) r2 = color >> 16 g2 = (color & 0xff00) >> 8 b2 = (color & 0xff) r1 *= r2; r1 /= 255 g1 *= g2; g1 /= 255 b...
ruby
{ "resource": "" }
q26741
MiniGL.TextHelper.write_line
test
def write_line(text, x = nil, y = nil, mode = :left, color = 0, alpha = 0xff, effect = nil, effect_color = 0, effect_size = 1, effect_alpha = 0xff, z_index = 0) if text.is_a? Hash x = text[:x] y = text[:y] mode = text.fetch(:mode, :left) color ...
ruby
{ "resource": "" }
q26742
MiniGL.TextHelper.write_breaking
test
def write_breaking(text, x, y, width, mode = :left, color = 0, alpha = 0xff, z_index = 0) color = (alpha << 24) | color text.split("\n").each do |p| if mode == :justified y = write_paragraph_justified p, x, y, width, color, z_index else rel = case mode ...
ruby
{ "resource": "" }
q26743
Fit4Ruby.FitMessageIdMapper.add_global
test
def add_global(message) unless (slot = @entries.index { |e| e.nil? }) # No more free slots. We have to find the least recently used one. slot = 0 0.upto(15) do |i| if i != slot && @entries[slot].last_use > @entries[i].last_use slot = i end end ...
ruby
{ "resource": "" }
q26744
Fit4Ruby.FitMessageIdMapper.get_local
test
def get_local(message) 0.upto(15) do |i| if (entry = @entries[i]) && entry.global_message == message entry.last_use = Time.now return i end end nil end
ruby
{ "resource": "" }
q26745
Fit4Ruby.Monitoring_B.check
test
def check last_timestamp = ts_16_offset = nil last_ts_16 = nil # The timestamp_16 is a 2 byte time stamp value that is used instead of # the 4 byte timestamp field for monitoring records that have # current_activity_type_intensity values with an activity type of 6. The # value seems...
ruby
{ "resource": "" }
q26746
Fit4Ruby.FieldDescription.create_global_definition
test
def create_global_definition(fit_entity) messages = fit_entity.developer_fit_messages unless (gfm = GlobalFitMessages[@native_mesg_num]) Log.error "Developer field description references unknown global " + "message number #{@native_mesg_num}" return end if @developer_d...
ruby
{ "resource": "" }
q26747
Fit4Ruby.DeviceInfo.check
test
def check(index) unless @device_index Log.fatal 'device info record must have a device_index' end if @device_index == 0 unless @manufacturer Log.fatal 'device info record 0 must have a manufacturer field set' end if @manufacturer == 'garmin' unless @...
ruby
{ "resource": "" }
q26748
Fit4Ruby.ILogger.open
test
def open(io) begin @@logger = Logger.new(io) rescue => e @@logger = Logger.new($stderr) Log.fatal "Cannot open log file: #{e.message}" end end
ruby
{ "resource": "" }
q26749
Fit4Ruby.FitFileEntity.set_type
test
def set_type(type) if @top_level_record Log.fatal "FIT file type has already been set to " + "#{@top_level_record.class}" end case type when 4, 'activity' @top_level_record = Activity.new @type = 'activity' when 32, 'monitoring_b' @top_leve...
ruby
{ "resource": "" }
q26750
Fit4Ruby.Activity.check
test
def check unless @timestamp && @timestamp >= Time.parse('1990-01-01T00:00:00+00:00') Log.fatal "Activity has no valid timestamp" end unless @total_timer_time Log.fatal "Activity has no valid total_timer_time" end unless @device_infos.length > 0 Log.fatal "Activity m...
ruby
{ "resource": "" }
q26751
Fit4Ruby.Activity.total_gps_distance
test
def total_gps_distance timer_stops = [] # Generate a list of all timestamps where the timer was stopped. @events.each do |e| if e.event == 'timer' && e.event_type == 'stop_all' timer_stops << e.timestamp end end # The first record of a FIT file can already have a...
ruby
{ "resource": "" }
q26752
Fit4Ruby.Activity.vo2max
test
def vo2max # First check the event log for a vo2max reporting event. @events.each do |e| return e.vo2max if e.event == 'vo2max' end # Then check the user_data entries for a metmax entry. METmax * 3.5 # is same value as VO2max. @user_data.each do |u| return u.metmax * ...
ruby
{ "resource": "" }
q26753
Fit4Ruby.Activity.write
test
def write(io, id_mapper) @file_id.write(io, id_mapper) @file_creator.write(io, id_mapper) (@field_descriptions + @developer_data_ids + @device_infos + @sensor_settings + @data_sources + @user_profiles + @physiological_metrics + @events + @sessions + @laps + @records + @hea...
ruby
{ "resource": "" }
q26754
Fit4Ruby.Activity.new_fit_data_record
test
def new_fit_data_record(record_type, field_values = {}) case record_type when 'file_id' @file_id = (record = FileId.new(field_values)) when 'field_description' @field_descriptions << (record = FieldDescription.new(field_values)) when 'developer_data_id' @developer_data_id...
ruby
{ "resource": "" }
q26755
Fit4Ruby.Session.check
test
def check(activity) unless @first_lap_index Log.fatal 'first_lap_index is not set' end unless @num_laps Log.fatal 'num_laps is not set' end @first_lap_index.upto(@first_lap_index - @num_laps) do |i| if (lap = activity.lap[i]) @laps << lap else ...
ruby
{ "resource": "" }
q26756
Fit4Ruby.GlobalFitMessage.field
test
def field(number, type, name, opts = {}) field = Field.new(type, name, opts) register_field_by_name(field, name) register_field_by_number(field, number) end
ruby
{ "resource": "" }
q26757
Fit4Ruby.GlobalFitMessage.alt_field
test
def alt_field(number, ref_field, &block) unless @fields_by_name.include?(ref_field) raise "Unknown ref_field: #{ref_field}" end field = AltField.new(self, ref_field, &block) register_field_by_number(field, number) end
ruby
{ "resource": "" }
q26758
MailForm.Delivery.spam?
test
def spam? self.class.mail_captcha.each do |field| next if send(field).blank? if defined?(Rails) && Rails.env.development? raise ScriptError, "The captcha field #{field} was supposed to be blank" else return true end end false end
ruby
{ "resource": "" }
q26759
MailForm.Delivery.deliver!
test
def deliver! mailer = MailForm::Notifier.contact(self) if mailer.respond_to?(:deliver_now) mailer.deliver_now else mailer.deliver end end
ruby
{ "resource": "" }
q26760
MailForm.Delivery.mail_form_attributes
test
def mail_form_attributes self.class.mail_attributes.each_with_object({}) do |attr, hash| hash[attr.to_s] = send(attr) end end
ruby
{ "resource": "" }
q26761
SolrWrapper.Instance.start
test
def start extract_and_configure if config.managed? exec('start', p: port, c: config.cloud) # Wait for solr to start unless status sleep config.poll_interval end after_start end end
ruby
{ "resource": "" }
q26762
SolrWrapper.Instance.restart
test
def restart if config.managed? && started? exec('restart', p: port, c: config.cloud) end end
ruby
{ "resource": "" }
q26763
SolrWrapper.Instance.create
test
def create(options = {}) options[:name] ||= SecureRandom.hex create_options = { p: port } create_options[:c] = options[:name] if options[:name] create_options[:n] = options[:config_name] if options[:config_name] create_options[:d] = options[:dir] if options[:dir] Retriable.retriabl...
ruby
{ "resource": "" }
q26764
SolrWrapper.Instance.upconfig
test
def upconfig(options = {}) options[:name] ||= SecureRandom.hex options[:zkhost] ||= zkhost upconfig_options = { upconfig: true, n: options[:name] } upconfig_options[:d] = options[:dir] if options[:dir] upconfig_options[:z] = options[:zkhost] if options[:zkhost] exec 'zk', upconfig_...
ruby
{ "resource": "" }
q26765
SolrWrapper.Instance.downconfig
test
def downconfig(options = {}) options[:name] ||= SecureRandom.hex options[:zkhost] ||= zkhost downconfig_options = { downconfig: true, n: options[:name] } downconfig_options[:d] = options[:dir] if options[:dir] downconfig_options[:z] = options[:zkhost] if options[:zkhost] exec 'zk',...
ruby
{ "resource": "" }
q26766
SolrWrapper.Instance.with_collection
test
def with_collection(options = {}) options = config.collection_options.merge(options) return yield if options.empty? name = create(options) begin yield name ensure delete name unless options[:persist] end end
ruby
{ "resource": "" }
q26767
SolrWrapper.Instance.clean!
test
def clean! stop remove_instance_dir! FileUtils.remove_entry(config.download_dir, true) if File.exist?(config.download_dir) FileUtils.remove_entry(config.tmp_save_dir, true) if File.exist? config.tmp_save_dir checksum_validator.clean! FileUtils.remove_entry(config.version_file) if Fil...
ruby
{ "resource": "" }
q26768
Qt.MetaInfo.get_signals
test
def get_signals all_signals = [] current = @klass while current != Qt::Base meta = Meta[current.name] if !meta.nil? all_signals.concat meta.signals end current = current.superclass end return all_signals end
ruby
{ "resource": "" }
q26769
MotionSupport.Duration.+
test
def +(other) if Duration === other Duration.new(value + other.value, @parts + other.parts) else Duration.new(value + other, @parts + [[:seconds, other]]) end end
ruby
{ "resource": "" }
q26770
DateAndTime.Calculations.days_to_week_start
test
def days_to_week_start(start_day = Date.beginning_of_week) start_day_number = DAYS_INTO_WEEK[start_day] current_day_number = wday != 0 ? wday - 1 : 6 (current_day_number - start_day_number) % 7 end
ruby
{ "resource": "" }
q26771
TTY.ProgressBar.reset
test
def reset @width = 0 if no_width @render_period = frequency == 0 ? 0 : 1.0 / frequency @current = 0 @last_render_time = Time.now @last_render_width = 0 @done = false @stopped = false @start_at = Time.now @st...
ruby
{ "resource": "" }
q26772
TTY.ProgressBar.advance
test
def advance(progress = 1, tokens = {}) return if done? synchronize do emit(:progress, progress) if progress.respond_to?(:to_hash) tokens, progress = progress, 1 end @start_at = Time.now if @current.zero? && !@started @current += progress @tokens ...
ruby
{ "resource": "" }
q26773
TTY.ProgressBar.iterate
test
def iterate(collection, progress = 1, &block) update(total: collection.count * progress) unless total progress_enum = Enumerator.new do |iter| collection.each do |elem| advance(progress) iter.yield(elem) end end block_given? ? progress_enum.each(&block) : prog...
ruby
{ "resource": "" }
q26774
TTY.ProgressBar.update
test
def update(options = {}) synchronize do options.each do |name, val| if @configuration.respond_to?("#{name}=") @configuration.public_send("#{name}=", val) end end end end
ruby
{ "resource": "" }
q26775
TTY.ProgressBar.render
test
def render return if done? if hide_cursor && @last_render_width == 0 && !(@current >= total) write(TTY::Cursor.hide) end if @multibar characters_in = @multibar.line_inset(self) update(inset: self.class.display_columns(characters_in)) end formatted = @formatt...
ruby
{ "resource": "" }
q26776
TTY.ProgressBar.move_to_row
test
def move_to_row if @multibar CURSOR_LOCK.synchronize do if @first_render @row = @multibar.next_row yield if block_given? output.print "\n" @first_render = false else lines_up = (@multibar.rows + 1) - @row output.pr...
ruby
{ "resource": "" }
q26777
TTY.ProgressBar.write
test
def write(data, clear_first = false) return unless tty? # write only to terminal move_to_row do output.print(TTY::Cursor.column(1)) if clear_first characters_in = @multibar.line_inset(self) if @multibar output.print("#{characters_in}#{data}") output.flush end end
ruby
{ "resource": "" }
q26778
TTY.ProgressBar.finish
test
def finish return if done? @current = total unless no_width render clear ? clear_line : write("\n", false) ensure @meter.clear @done = true # reenable cursor if it is turned off if hide_cursor && @last_render_width != 0 write(TTY::Cursor.show, false) en...
ruby
{ "resource": "" }
q26779
TTY.ProgressBar.stop
test
def stop # reenable cursor if it is turned off if hide_cursor && @last_render_width != 0 write(TTY::Cursor.show, false) end return if done? render clear ? clear_line : write("\n", false) ensure @meter.clear @stopped = true emit(:stopped) end
ruby
{ "resource": "" }
q26780
TTY.ProgressBar.log
test
def log(message) sanitized_message = message.gsub(/\r|\n/, ' ') if done? write(sanitized_message + "\n", false) return end sanitized_message = padout(sanitized_message) write(sanitized_message + "\n", true) render end
ruby
{ "resource": "" }
q26781
TTY.ProgressBar.padout
test
def padout(message) message_length = self.class.display_columns(message) if @last_render_width > message_length remaining_width = @last_render_width - message_length message += ' ' * remaining_width end message end
ruby
{ "resource": "" }
q26782
Delayed.Job.lock_exclusively!
test
def lock_exclusively!(max_run_time, worker = worker_name) now = self.class.db_time_now affected_rows = if locked_by != worker # We don't own this job so we will update the locked_by name and the locked_at self.class.update_all(["locked_at = ?, locked_by = ?", now, worker], ["id = ? and (lock...
ruby
{ "resource": "" }
q26783
Elephrame.Trace.setup_tracery
test
def setup_tracery dir_path raise "Provided path not a directory" unless Dir.exist?(dir_path) @grammar = {} Dir.open(dir_path) do |dir| dir.each do |file| # skip our current and parent dir next if file =~ /^\.\.?$/ # read the rule file into the files hash ...
ruby
{ "resource": "" }
q26784
Elephrame.Trace.expand_and_post
test
def expand_and_post(text, *options) opts = Hash[*options] rules = opts.fetch(:rules, 'default') actually_post(@grammar[rules].flatten(text), **opts.reject {|k| k == :rules }) end
ruby
{ "resource": "" }
q26785
Elephrame.AllInteractions.run_interact
test
def run_interact @streamer.user do |update| if update.kind_of? Mastodon::Notification case update.type when 'mention' # this makes it so .content calls strip instead update.status.class.module_eval { alias_method :content, :strip } if...
ruby
{ "resource": "" }
q26786
Elephrame.Reply.reply
test
def reply(text, *options) options = Hash[*options] post("@#{@mention_data[:account].acct} #{text}", **@mention_data.merge(options).reject { |k| k == :mentions or k == :account }) end
ruby
{ "resource": "" }
q26787
Elephrame.Reply.run_reply
test
def run_reply @streamer.user do |update| next unless update.kind_of? Mastodon::Notification and update.type == 'mention' # this makes it so .content calls strip instead update.status.class.module_eval { alias_method :content, :strip } if @strip_html store_mention_data update.sta...
ruby
{ "resource": "" }
q26788
Elephrame.Reply.store_mention_data
test
def store_mention_data(mention) @mention_data = { reply_id: mention.id, visibility: mention.visibility, spoiler: mention.spoiler_text, hide_media: mention.sensitive?, mentions: mention.mentions, account: mention.account } end
ruby
{ "resource": "" }
q26789
Elephrame.Streaming.setup_streaming
test
def setup_streaming stream_uri = @client.instance() .attributes['urls']['streaming_api'].gsub(/^wss?/, 'https') @streamer = Mastodon::Streaming::Client.new(base_url: stream_uri, bearer_token: ENV['TOKEN']) end
ruby
{ "resource": "" }
q26790
PoiseService.Utils.parse_service_name
test
def parse_service_name(path) parts = Pathname.new(path).each_filename.to_a.reverse! # Find the last segment not in common segments, fall back to the last segment. parts.find {|seg| !COMMON_SEGMENTS[seg] } || parts.first end
ruby
{ "resource": "" }
q26791
Net.TCPClient.connect
test
def connect start_time = Time.now retries = 0 close # Number of times to try begin connect_to_server(servers, policy) logger.info(message: "Connected to #{address}", duration: (Time.now - start_time) * 1000) if respond_to?(:logger) rescue ConnectionFailure, Connec...
ruby
{ "resource": "" }
q26792
Net.TCPClient.write
test
def write(data, timeout = write_timeout) data = data.to_s if respond_to?(:logger) payload = {timeout: timeout} # With trace level also log the sent data payload[:data] = data if logger.trace? logger.benchmark_debug('#write', payload: payload) do payload[:byte...
ruby
{ "resource": "" }
q26793
Net.TCPClient.read
test
def read(length, buffer = nil, timeout = read_timeout) if respond_to?(:logger) payload = {bytes: length, timeout: timeout} logger.benchmark_debug('#read', payload: payload) do data = socket_read(length, buffer, timeout) # With trace level also log the received data ...
ruby
{ "resource": "" }
q26794
Net.TCPClient.close
test
def close socket.close if socket && !socket.closed? @socket = nil @address = nil true rescue IOError => exception logger.warn "IOError when attempting to close socket: #{exception.class}: #{exception.message}" if respond_to?(:logger) false end
ruby
{ "resource": "" }
q26795
Net.TCPClient.alive?
test
def alive? return false if socket.nil? || closed? if IO.select([socket], nil, nil, 0) !socket.eof? rescue false else true end rescue IOError false end
ruby
{ "resource": "" }
q26796
Net.TCPClient.socket_connect
test
def socket_connect(socket, address, timeout) socket_address = Socket.pack_sockaddr_in(address.port, address.ip_address) # Timeout of -1 means wait forever for a connection return socket.connect(socket_address) if timeout == -1 deadline = Time.now.utc + timeout begin non_blocking(...
ruby
{ "resource": "" }
q26797
Net.TCPClient.socket_write
test
def socket_write(data, timeout) if timeout < 0 socket.write(data) else deadline = Time.now.utc + timeout length = data.bytesize total_count = 0 non_blocking(socket, deadline) do loop do begin count = socket.write_nonblock(data) ...
ruby
{ "resource": "" }
q26798
Net.TCPClient.ssl_connect
test
def ssl_connect(socket, address, timeout) ssl_context = OpenSSL::SSL::SSLContext.new ssl_context.set_params(ssl.is_a?(Hash) ? ssl : {}) ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context) ssl_socket.hostname = address.host_name ssl_socket.sync_close = true be...
ruby
{ "resource": "" }
q26799
Sonos.System.party_mode
test
def party_mode new_master = nil return nil unless speakers.length > 1 new_master = find_party_master if new_master.nil? party_over speakers.each do |slave| next if slave.uid == new_master.uid slave.join new_master end rescan @topology end
ruby
{ "resource": "" }