_id
stringlengths 2
6
| title
stringlengths 9
130
| partition
stringclasses 3
values | text
stringlengths 30
4.3k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q26600
|
TensorStream.Ops.pack
|
test
|
def pack(values, axis: 0, name: "pack")
|
ruby
|
{
"resource": ""
}
|
q26601
|
TensorStream.Ops.unpack
|
test
|
def unpack(value, num: nil, axis: 0, name: "unpack")
|
ruby
|
{
"resource": ""
}
|
q26602
|
TensorStream.Ops.case
|
test
|
def case(args = {})
args = args.dup
default = args.delete(:default)
exclusive = args.delete(:exclusive)
strict = args.delete(:strict)
name = args.delete(:name)
predicates = []
functions = []
args.each do |k, v|
raise "Invalid argment or option #{k}" unless
|
ruby
|
{
"resource": ""
}
|
q26603
|
TensorStream.OpHelper.i_op
|
test
|
def i_op(code, *args)
options = if args.last.is_a?(Hash)
args.pop
else
{}
end
|
ruby
|
{
"resource": ""
}
|
q26604
|
TensorStream.ArrayOpsHelper.broadcast_dimensions
|
test
|
def broadcast_dimensions(input, dims = [])
return input if dims.empty?
d = dims.shift
if input.is_a?(Array) && (get_rank(input) - 1) == dims.size
row_to_dup = input.collect { |item|
broadcast_dimensions(item, dims.dup)
}
row_to_dup + Array.new(d) {
|
ruby
|
{
"resource": ""
}
|
q26605
|
TensorStream.ArrayOpsHelper.vector_op
|
test
|
def vector_op(vector, vector2, switch = false, safe = true, &block)
if get_rank(vector) < get_rank(vector2) # upgrade rank of A
duplicated = Array.new(vector2.size) {
vector
}
return vector_op(duplicated, vector2, switch, &block)
end
return yield(vector, vector2) unless vector.is_a?(Array)
vector.each_with_index.collect { |input, index|
next vector_op(input, vector2, switch, &block) if input.is_a?(Array) && get_rank(vector) > get_rank(vector2)
if safe && vector2.is_a?(Array)
next nil if vector2.size != 1 && index >= vector2.size
end
z = if vector2.is_a?(Array)
|
ruby
|
{
"resource": ""
}
|
q26606
|
TensorStream.ArrayOpsHelper.transpose_with_perm
|
test
|
def transpose_with_perm(arr, new_arr, shape, new_shape, perm)
arr_size = shape.reduce(:*)
divisors = shape.dup.drop(1).reverse.inject([1]) { |a, s|
a << s * a.last
}.reverse
multipliers = new_shape.dup.drop(1).reverse.inject([1]) { |a, s|
a << s * a.last
}.reverse
arr_size.times do |p|
ptr = p
index = []
divisors.each_with_object(index) do |div, a|
a << (ptr / div.to_f).floor
ptr = ptr %
|
ruby
|
{
"resource": ""
}
|
q26607
|
TensorStream.OpStub.add
|
test
|
def add(input_a, input_b, name: nil)
input_a, input_b = apply_data_type_coercion(input_a,
|
ruby
|
{
"resource": ""
}
|
q26608
|
TensorStream.OpStub.argmax
|
test
|
def argmax(input_a, axis = nil, name: nil, dimension: nil, output_type: :int32)
check_allowed_types(input_a, TensorStream::Ops::NUMERIC_TYPES)
check_allowed_types(axis, TensorStream::Ops::INTEGER_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26609
|
TensorStream.OpStub.ceil
|
test
|
def ceil(input_a, name: nil)
check_allowed_types(input_a, TensorStream::Ops::FLOATING_POINT_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26610
|
TensorStream.OpStub.cos
|
test
|
def cos(input_a, name: nil)
check_allowed_types(input_a,
|
ruby
|
{
"resource": ""
}
|
q26611
|
TensorStream.OpStub.floor
|
test
|
def floor(input_a, name: nil)
check_allowed_types(input_a, TensorStream::Ops::FLOATING_POINT_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26612
|
TensorStream.OpStub.mod
|
test
|
def mod(input_a, input_b, name: nil)
input_a, input_b = apply_data_type_coercion(input_a,
|
ruby
|
{
"resource": ""
}
|
q26613
|
TensorStream.OpStub.pow
|
test
|
def pow(input_a, input_b, name: nil)
input_a, input_b = apply_data_type_coercion(input_a,
|
ruby
|
{
"resource": ""
}
|
q26614
|
TensorStream.OpStub.prod
|
test
|
def prod(input_a, axis = nil, name: nil, keepdims: false)
check_allowed_types(axis, TensorStream::Ops::INTEGER_TYPES)
input_a = TensorStream.convert_to_tensor(input_a)
return input_a if input_a.shape.scalar?
|
ruby
|
{
"resource": ""
}
|
q26615
|
TensorStream.OpStub.random_uniform
|
test
|
def random_uniform(shape, name: nil, dtype: :float32, minval: 0, maxval: 1, seed: nil)
_op(:random_uniform, shape,
|
ruby
|
{
"resource": ""
}
|
q26616
|
TensorStream.OpStub.range
|
test
|
def range(start = 0, limit = 0, delta = 1, name: "range", dtype: nil, output_type: :int32)
_op(:range, start,
|
ruby
|
{
"resource": ""
}
|
q26617
|
TensorStream.OpStub.rank
|
test
|
def rank(input, name: nil)
input = convert_to_tensor(input)
|
ruby
|
{
"resource": ""
}
|
q26618
|
TensorStream.OpStub.round
|
test
|
def round(input_a, name: nil)
check_allowed_types(input_a, TensorStream::Ops::FLOATING_POINT_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26619
|
TensorStream.OpStub.rsqrt
|
test
|
def rsqrt(input_a, name: nil)
check_allowed_types(input_a, TensorStream::Ops::FLOATING_POINT_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26620
|
TensorStream.OpStub.shape
|
test
|
def shape(input, name: nil, out_type: :int32)
return constant(shape_eval(input, out_type), dtype: out_type, name: "Shape/#{name}") if input.is_a?(Array) && !input[0].is_a?(Tensor)
return
|
ruby
|
{
"resource": ""
}
|
q26621
|
TensorStream.OpStub.sigmoid
|
test
|
def sigmoid(input_a, name: nil)
check_allowed_types(input_a,
|
ruby
|
{
"resource": ""
}
|
q26622
|
TensorStream.OpStub.sin
|
test
|
def sin(input_a, name: nil)
check_allowed_types(input_a,
|
ruby
|
{
"resource": ""
}
|
q26623
|
TensorStream.OpStub.sub
|
test
|
def sub(input_a, input_b, name: nil)
input_a, input_b = apply_data_type_coercion(input_a,
|
ruby
|
{
"resource": ""
}
|
q26624
|
TensorStream.OpStub.sum
|
test
|
def sum(input_a, axis_p = nil, axis: nil, name: nil, keepdims: false)
check_allowed_types(axis_p, TensorStream::Ops::INTEGER_TYPES)
input_a = TensorStream.convert_to_tensor(input_a)
return input_a if input_a.shape.scalar?
axis_p
|
ruby
|
{
"resource": ""
}
|
q26625
|
TensorStream.OpStub.tan
|
test
|
def tan(input_a, name: nil)
check_allowed_types(input_a,
|
ruby
|
{
"resource": ""
}
|
q26626
|
TensorStream.OpStub.tanh
|
test
|
def tanh(input_a, name: nil)
check_allowed_types(input_a, TensorStream::Ops::FLOATING_POINT_TYPES)
|
ruby
|
{
"resource": ""
}
|
q26627
|
TensorStream.OpStub.top_k
|
test
|
def top_k(input, k = 1, sorted: true, name: nil)
result = _op(:top_k, input, k,
|
ruby
|
{
"resource": ""
}
|
q26628
|
TensorStream.OpStub.zeros
|
test
|
def zeros(shape, dtype: :float32, name: nil)
|
ruby
|
{
"resource": ""
}
|
q26629
|
TensorStream.Freezer.convert
|
test
|
def convert(session, checkpoint_folder, output_file)
model_file = File.join(checkpoint_folder, "model.yaml")
TensorStream.graph.as_default do |current_graph|
YamlLoader.new.load_from_string(File.read(model_file))
saver = TensorStream::Train::Saver.new
saver.restore(session, checkpoint_folder)
# collect all assign ops and remove them from the graph
remove_nodes = Set.new(current_graph.nodes.values.select { |op| op.is_a?(TensorStream::Operation) && op.operation == :assign }.map { |op| op.consumers.to_a }.flatten.uniq)
output_buffer = TensorStream::Yaml.new.get_string(current_graph) { |graph, node_key|
node = graph.get_tensor_by_name(node_key)
case node.operation
when :variable_v2
value = node.container
options = {
value: value,
data_type: node.data_type,
shape: shape_eval(value),
}
const_op
|
ruby
|
{
"resource": ""
}
|
q26630
|
TensorStream.Graph.device
|
test
|
def device(device_name)
Thread.current["ts_graph_#{object_id}"] ||= {}
Thread.current["ts_graph_#{object_id}"][:default_device] ||= []
Thread.current["ts_graph_#{object_id}"][:default_device] << device_name
begin
|
ruby
|
{
"resource": ""
}
|
q26631
|
TensorStream.YamlLoader.load_from_string
|
test
|
def load_from_string(buffer)
serialized_ops = YAML.safe_load(buffer, [Symbol], [], true)
serialized_ops.each do |op_def|
inputs = op_def[:inputs].map { |i| @graph.get_tensor_by_name(i) }
options = {}
new_var = nil
if op_def.dig(:attrs, :container)
new_var = Variable.new(op_def.dig(:attrs, :data_type))
var_shape = op_def.dig(:attrs, :container, :shape)
var_options = op_def.dig(:attrs, :container, :options)
var_options[:name] = op_def[:name]
new_var.prepare(var_shape.size, var_shape, TensorStream.get_variable_scope, var_options)
options[:container] = new_var
@graph.add_variable(new_var, var_options)
end
new_op = Operation.new(@graph, inputs: inputs, options: op_def[:attrs].merge(options))
|
ruby
|
{
"resource": ""
}
|
q26632
|
TensorStream.Utils.variable
|
test
|
def variable(value, name: nil, initializer: nil, graph: nil, dtype: nil, trainable: true)
op = Graph.get_default_graph.add_op(:assign, nil, value)
common_options = {
initializer: initializer || op,
name: name,
graph: graph,
dtype: dtype,
trainable: trainable,
}
tensor = if value.is_a?(String)
i_var(dtype || :string, 0, [], get_variable_scope, common_options)
elsif value.is_a?(Integer)
i_var(dtype || :int32, 0,
|
ruby
|
{
"resource": ""
}
|
q26633
|
TensorStream.Utils.variable_scope
|
test
|
def variable_scope(scope = nil, default_name = nil, reuse: nil, initializer: nil)
Thread.current[:tensor_stream_variable_scope] ||= [VariableScope.new]
# uniquenifier
if scope.nil? && default_name
same_names = get_variable_scope.used_names.select { |s| s.start_with?(default_name) }
new_name = default_name
index = 1
while same_names.include?(new_name)
new_name = "#{default_name}_#{index}"
index += 1
end
scope = new_name
end
variable_scope = VariableScope.new(name: scope, reuse: reuse, initializer: initializer)
get_variable_scope.register_name(scope || "")
Thread.current[:tensor_stream_variable_scope]
|
ruby
|
{
"resource": ""
}
|
q26634
|
TensorStream.Utils.session
|
test
|
def session(evaluator = nil, thread_pool_class: Concurrent::ImmediateExecutor, log_device_placement: false, profile_enabled: false)
session = TensorStream::Session.new(evaluator, thread_pool_class: thread_pool_class,
|
ruby
|
{
"resource": ""
}
|
q26635
|
TensorStream.Utils.placeholder
|
test
|
def placeholder(dtype, shape: nil, name: nil)
|
ruby
|
{
"resource": ""
}
|
q26636
|
TensorStream.Utils.check_if_dense
|
test
|
def check_if_dense(value, expected_shape = nil)
return unless value.is_a?(Array)
return if value.empty?
expected_shape ||= shape_eval(value)
s = expected_shape.shift
raise TensorStream::ValueError, "Argument must be a dense tensor: #{value}, expected size #{s}
|
ruby
|
{
"resource": ""
}
|
q26637
|
TensorStream.Utils.apply_data_type_coercion
|
test
|
def apply_data_type_coercion(*args)
coerced_type = check_data_types(*args)
args.map { |a|
|
ruby
|
{
"resource": ""
}
|
q26638
|
IBMWatson.SpeechToTextV1.add_audio
|
test
|
def add_audio(customization_id:, audio_name:, audio_resource:, contained_content_type: nil, allow_overwrite: nil, content_type: nil)
raise ArgumentError.new("customization_id must be provided") if customization_id.nil?
raise ArgumentError.new("audio_name must be provided") if audio_name.nil?
raise ArgumentError.new("audio_resource must be provided") if audio_resource.nil?
headers = {
"Contained-Content-Type" => contained_content_type,
"Content-Type" => content_type
}
sdk_headers = Common.new.get_sdk_headers("speech_to_text", "V1", "add_audio")
headers.merge!(sdk_headers)
params = {
"allow_overwrite" => allow_overwrite
}
|
ruby
|
{
"resource": ""
}
|
q26639
|
IBMWatson.DiscoveryV1.create_event
|
test
|
def create_event(type:, data:)
raise ArgumentError.new("type must be provided") if type.nil?
raise ArgumentError.new("data must be provided") if data.nil?
headers = {
}
sdk_headers = Common.new.get_sdk_headers("discovery", "V1", "create_event")
headers.merge!(sdk_headers)
params = {
"version" => @version
}
data = {
"type" => type,
"data" => data
|
ruby
|
{
"resource": ""
}
|
q26640
|
RbNaCl.Util.zero_pad
|
test
|
def zero_pad(n, message)
len = message.bytesize
if len == n
message
elsif len > n
raise LengthError, "String too long for zero-padding
|
ruby
|
{
"resource": ""
}
|
q26641
|
RbNaCl.Util.check_length
|
test
|
def check_length(string, length, description)
if string.nil?
# code below is runs only in test cases
# nil can't be converted to str with #to_str method
raise LengthError,
"#{description} was nil (Expected #{length.to_int})",
caller
|
ruby
|
{
"resource": ""
}
|
q26642
|
RbNaCl.Util.check_string
|
test
|
def check_string(string, length, description)
check_string_validation(string)
|
ruby
|
{
"resource": ""
}
|
q26643
|
RbNaCl.Util.check_hmac_key
|
test
|
def check_hmac_key(string, _description)
check_string_validation(string)
string = string.to_str
if string.bytesize.zero?
raise LengthError,
|
ruby
|
{
"resource": ""
}
|
q26644
|
RbNaCl.Util.check_string_validation
|
test
|
def check_string_validation(string)
raise TypeError, "can't convert #{string.class} into String with #to_str" unless string.respond_to? :to_str
string = string.to_str
|
ruby
|
{
"resource": ""
}
|
q26645
|
RbNaCl.Auth.auth
|
test
|
def auth(message)
authenticator = Util.zeros(tag_bytes)
message
|
ruby
|
{
"resource": ""
}
|
q26646
|
RbNaCl.Auth.verify
|
test
|
def verify(authenticator, message)
auth = authenticator.to_s
Util.check_length(auth, tag_bytes, "Provided authenticator")
verify_message(auth,
|
ruby
|
{
"resource": ""
}
|
q26647
|
RbNaCl.SimpleBox.box
|
test
|
def box(message)
nonce = generate_nonce
cipher_text =
|
ruby
|
{
"resource": ""
}
|
q26648
|
RbNaCl.SimpleBox.open
|
test
|
def open(enciphered_message)
nonce, ciphertext =
|
ruby
|
{
"resource": ""
}
|
q26649
|
SemanticLogger.Appenders.reopen
|
test
|
def reopen
each do |appender|
begin
next unless appender.respond_to?(:reopen)
logger.trace "Reopening appender: #{appender.name}"
appender.reopen
rescue Exception => exc
logger.error "Failed to
|
ruby
|
{
"resource": ""
}
|
q26650
|
SemanticLogger.Subscriber.logger
|
test
|
def logger
@logger ||= begin
logger = SemanticLogger::Processor.logger.clone
logger.name
|
ruby
|
{
"resource": ""
}
|
q26651
|
SemanticLogger.Base.measure
|
test
|
def measure(level, message, params = {}, &block)
index = Levels.index(level)
if level_index <= index
|
ruby
|
{
"resource": ""
}
|
q26652
|
SemanticLogger.Base.backtrace
|
test
|
def backtrace(thread: Thread.current,
level: :warn,
message: 'Backtrace:',
payload: nil,
metric: nil,
metric_amount: nil)
log = Log.new(name, level)
return false unless meets_log_level?(log)
backtrace =
if thread == Thread.current
Utils.extract_backtrace
else
log.thread_name = thread.name
log.tags = (thread[:semantic_logger_tags] || []).clone
log.named_tags = (thread[:semantic_logger_named_tags] || {}).clone
thread.backtrace
end
# TODO: Keep backtrace instead of transforming into a text message at this point
# Maybe log_backtrace: true
|
ruby
|
{
"resource": ""
}
|
q26653
|
SemanticLogger.Base.tagged
|
test
|
def tagged(*tags, &block)
# Allow named tags to be passed into the logger
if tags.size == 1
tag = tags[0]
return yield if tag.nil? || tag == ''
return tag.is_a?(Hash) ? SemanticLogger.named_tagged(tag, &block) : SemanticLogger.fast_tag(tag.to_s, &block)
end
|
ruby
|
{
"resource": ""
}
|
q26654
|
SemanticLogger.Base.push_tags
|
test
|
def push_tags(*tags)
# Need to flatten and reject empties to support calls from Rails 4
new_tags
|
ruby
|
{
"resource": ""
}
|
q26655
|
SemanticLogger.Base.filtered?
|
test
|
def filtered?(log)
return false if @filter.nil?
@filter.is_a?(Regexp) ?
|
ruby
|
{
"resource": ""
}
|
q26656
|
SemanticLogger.Base.log_internal
|
test
|
def log_internal(level, index, message = nil, payload = nil, exception = nil, &block)
log = Log.new(name, level, index)
should_log =
if payload.nil? && exception.nil? && message.is_a?(Hash)
# Check if someone just logged a hash payload instead of meaning to call semantic logger
|
ruby
|
{
"resource": ""
}
|
q26657
|
SemanticLogger.Base.measure_internal
|
test
|
def measure_internal(level, index, message, params)
exception = nil
result = nil
# Single parameter is a hash
if params.empty? && message.is_a?(Hash)
params = message
message = nil
end
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
if block_given?
result =
if (silence_level = params[:silence])
# In case someone accidentally sets `silence: true` instead of `silence: :error`
silence_level = :error if silence_level == true
silence(silence_level) { yield(params) }
else
yield(params)
end
end
rescue Exception => exc
exception = exc
ensure
# Must use ensure block otherwise a `return` in the yield above will skip the log entry
log = Log.new(name, level, index)
exception ||= params[:exception]
message = params[:message] if params[:message]
duration =
if block_given?
1_000.0 * (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start)
else
params[:duration] || raise('Mandatory block missing when :duration option is not supplied')
end
# Extract options after block completes so
|
ruby
|
{
"resource": ""
}
|
q26658
|
SemanticLogger.Base.measure_method
|
test
|
def measure_method(index:,
level:,
message:,
min_duration:,
metric:,
log_exception:,
on_exception_level:)
# Ignores filter, silence, payload
exception = nil
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
begin
yield
rescue Exception => exc
exception = exc
ensure
log = Log.new(name, level, index)
# May return false due to elastic logging
should_log = log.assign(
message: message,
min_duration: min_duration,
exception: exception,
metric: metric,
duration:
|
ruby
|
{
"resource": ""
}
|
q26659
|
SemanticLogger.Logger.log
|
test
|
def log(log, message = nil, progname = nil, &block)
# Compatibility with ::Logger
return
|
ruby
|
{
"resource": ""
}
|
q26660
|
SemanticLogger.Log.assign
|
test
|
def assign(message: nil,
payload: nil,
min_duration: 0.0,
exception: nil,
metric: nil,
metric_amount: nil,
duration: nil,
backtrace: nil,
log_exception: :full,
on_exception_level: nil,
dimensions: nil)
# Elastic logging: Log when :duration exceeds :min_duration
# Except if there is an exception when it will always be logged
if duration
self.duration = duration
return false if (duration < min_duration) && exception.nil?
end
self.message = message
if payload && payload.is_a?(Hash)
self.payload = payload
elsif payload
self.message = message.nil? ? payload.to_s : "#{message} -- #{payload}"
self.payload = nil
end
if exception
case log_exception
when :full
self.exception = exception
when :partial
self.message = "#{message} -- Exception: #{exception.class}: #{exception.message}"
when nil, :none
# Log the message without the exception that was raised
nil
|
ruby
|
{
"resource": ""
}
|
q26661
|
SemanticLogger.Log.assign_positional
|
test
|
def assign_positional(message = nil, payload = nil, exception = nil)
# Exception being logged?
# Under JRuby a java exception is not a Ruby Exception
# Java::JavaLang::ClassCastException.new.is_a?(Exception) => false
if exception.nil? && payload.nil? && message.respond_to?(:backtrace) && message.respond_to?(:message)
exception = message
message = nil
elsif exception.nil? && payload && payload.respond_to?(:backtrace) && payload.respond_to?(:message)
exception = payload
payload = nil
elsif payload && !payload.is_a?(Hash)
message = message.nil? ? payload : "#{message} -- #{payload}"
payload = nil
end
# Add result of block as message or payload if not nil
if block_given? && (result = yield)
|
ruby
|
{
"resource": ""
}
|
q26662
|
SemanticLogger.Log.each_exception
|
test
|
def each_exception
# With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81
depth = 0
exceptions = []
ex = exception
while !ex.nil? && !exceptions.include?(ex) && exceptions.length < MAX_EXCEPTIONS_TO_UNWRAP
exceptions << ex
yield(ex, depth)
depth += 1
ex =
if ex.respond_to?(:cause) && ex.cause
|
ruby
|
{
"resource": ""
}
|
q26663
|
SemanticLogger.Log.extract_file_and_line
|
test
|
def extract_file_and_line(stack, short_name = false)
match = CALLER_REGEXP.match(stack.first)
|
ruby
|
{
"resource": ""
}
|
q26664
|
DidYouMean.VerboseFormatter.message_for
|
test
|
def message_for(corrections)
return "" if corrections.empty?
output =
|
ruby
|
{
"resource": ""
}
|
q26665
|
Flor.Ganger.gather_vars
|
test
|
def gather_vars(executor, tconf, message)
# try to return before a potentially costly call to executor.vars(nid)
return nil if (tconf.keys & %w[ include_vars exclude_vars ]).empty?
# default behaviour, don't pass variables to taskers
iv = expand_filter(tconf['include_vars'])
return nil if iv == false
ev = expand_filter(tconf['exclude_vars'])
|
ruby
|
{
"resource": ""
}
|
q26666
|
Flor.UnitExecutor.do_run
|
test
|
def do_run
@unit.logger.log_run_start(self)
counter_next('runs')
t0 = Time.now
(@unit.conf['exe_max_messages'] || 77).times do |i|
break if @shutdown
m = @messages.shift
break unless m
m = (@messages << m).shift \
if m['point'] == 'terminated' && @messages.any?
#
# handle 'terminated' messages last
ms = process(m)
@consumed << m
ims, oms = ms.partition { |mm| mm['exid'] == @exid }
# qui est "in", qui est "out"?
counter_add('omsgs', oms.size)
# keep track of "out" messages, messages to other executions
@messages.concat(ims)
@unit.storage.put_messages(oms)
end
@alive = false
@execution.merge!(
closing_messages: @consumed.select { |m|
CLOSING_POINTS.include?(m['point']) })
@unit.storage.put_execution(@execution)
@unit.storage.consume(@consumed)
@unit.storage.put_messages(@messages)
du = Time.now - t0
t0 = Flor.tstamp(t0)
@unit.logger.log_run_end(self, t0, du)
@unit.hooker.notify(self, make_end_message(t0, du, @execution['size']))
@consumed.clear
rescue Exception => exc
# TODO eventually, have a dump dir
fn =
[
'flor',
@unit.conf['env'], @unit.identifier, @exid,
|
ruby
|
{
"resource": ""
}
|
q26667
|
Flor.BasicTasker.route
|
test
|
def route(name)
if name.is_a?(String)
[ Flor.dup_and_merge(
@message,
'tasker' => name, 'original_tasker' => @message['tasker'],
'routed' => true) ]
else
|
ruby
|
{
"resource": ""
}
|
q26668
|
Flor.Waiter.row_waiter?
|
test
|
def row_waiter?
@serie.find { |_, points|
points.find { |po|
pos = po.split(':')
|
ruby
|
{
"resource": ""
}
|
q26669
|
Flor.FlorModel.node
|
test
|
def node(reload=false)
nid = @values[:nid]; return nil unless nid
exe = execution(reload); return nil unless exe
|
ruby
|
{
"resource": ""
}
|
q26670
|
Flor.Executor.vars
|
test
|
def vars(nid, vs={})
n = node(nid); return vs unless n
(n['vars'] || {})
.each { |k, v| vs[k] = Flor.dup(v) unless vs.has_key?(k) }
pnid = n['parent']
if @unit.loader && pnid
|
ruby
|
{
"resource": ""
}
|
q26671
|
Flor.Executor.lookup_on_error_parent
|
test
|
def lookup_on_error_parent(message)
nd = Flor::Node.new(self, nil, message).on_error_parent
|
ruby
|
{
"resource": ""
}
|
q26672
|
Flor.Trap.decrement
|
test
|
def decrement
c = data['count']
return false unless c
c = c - 1
data['count'] = c
self[:status] = s = (c > 0) ? 'active' : 'consumed'
self.update(
|
ruby
|
{
"resource": ""
}
|
q26673
|
QC.Worker.work
|
test
|
def work
queue, job = lock_job
if queue && job
QC.log_yield(:at => "work", :job => job[:id]) do
|
ruby
|
{
"resource": ""
}
|
q26674
|
QC.Worker.lock_job
|
test
|
def lock_job
log(:at => "lock_job")
job = nil
while @running
@queues.each do |queue|
if job = queue.lock
return [queue, job]
end
|
ruby
|
{
"resource": ""
}
|
q26675
|
QC.Worker.call
|
test
|
def call(job)
args = job[:args]
receiver_str, _, message = job[:method].rpartition('.')
|
ruby
|
{
"resource": ""
}
|
q26676
|
LazyHighCharts.HighChart.method_missing
|
test
|
def method_missing(meth, opts = {})
if meth.to_s == 'to_ary'
super
end
if meth.to_s.end_with? '!'
|
ruby
|
{
"resource": ""
}
|
q26677
|
RackCAS.URL.remove_params
|
test
|
def remove_params(params)
self.tap do |u|
u.query_values = (u.query_values || {}).tap do |qv|
params.each do |key, value|
qv.delete key
end
|
ruby
|
{
"resource": ""
}
|
q26678
|
RackCAS.ServiceValidationResponse.parse_user_info
|
test
|
def parse_user_info(node)
return nil if node.nil?
{}.tap do |hash|
node.children.each do |e|
unless e.kind_of?(Nokogiri::XML::Text) || e.name == 'proxies'
# There are no child elements
if e.element_children.count == 0
if hash.has_key?(e.name)
hash[e.name] = [hash[e.name]] if hash[e.name].is_a? String
|
ruby
|
{
"resource": ""
}
|
q26679
|
ForemanRemoteExecutionCore.ScriptRunner.run_async
|
test
|
def run_async(command)
raise 'Async command already in progress' if @started
@started = false
@user_method.reset
session.open_channel do |channel|
channel.request_pty
channel.on_data do |ch, data|
publish_data(data, 'stdout') unless @user_method.filter_password?(data)
@user_method.on_data(data, ch)
end
channel.on_extended_data { |ch, type, data| publish_data(data, 'stderr') }
# standard exit of the command
channel.on_request('exit-status') { |ch, data| publish_exit_status(data.read_long) }
# on signal: sending the signal value (such as 'TERM')
channel.on_request('exit-signal') do |ch, data|
publish_exit_status(data.read_string)
|
ruby
|
{
"resource": ""
}
|
q26680
|
ForemanRemoteExecutionCore.FakeScriptRunner.exit_code
|
test
|
def exit_code
fail_chance = ENV.fetch('REX_SIMULATE_FAIL_CHANCE', 0).to_i
fail_exitcode = ENV.fetch('REX_SIMULATE_EXIT', 0).to_i
if fail_exitcode
|
ruby
|
{
"resource": ""
}
|
q26681
|
Transproc.Store.import_method
|
test
|
def import_method(source, name, new_name = name)
from = name.to_sym
to = new_name.to_sym
fn =
|
ruby
|
{
"resource": ""
}
|
q26682
|
Transproc.Store.import_methods
|
test
|
def import_methods(source, names)
names.inject(self)
|
ruby
|
{
"resource": ""
}
|
q26683
|
Transproc.Store.import_all
|
test
|
def import_all(source)
names = source.public_methods - Registry.instance_methods - Module.methods
names -=
|
ruby
|
{
"resource": ""
}
|
q26684
|
Transproc.Registry.[]
|
test
|
def [](fn, *args)
fetched = fetch(fn)
return Function.new(fetched, args: args, name: fn)
|
ruby
|
{
"resource": ""
}
|
q26685
|
Transproc.Registry.fetch
|
test
|
def fetch(fn)
return fn unless fn.instance_of? Symbol
respond_to?(fn) ? method(fn) : store.fetch(fn)
rescue
|
ruby
|
{
"resource": ""
}
|
q26686
|
Transproc.Function.to_ast
|
test
|
def to_ast
args_ast = args.map { |arg| arg.respond_to?(:to_ast)
|
ruby
|
{
"resource": ""
}
|
q26687
|
Transproc.Function.to_proc
|
test
|
def to_proc
if args.size > 0
proc { |*value| fn.call(*value, *args) }
|
ruby
|
{
"resource": ""
}
|
q26688
|
UserAgentParser.Parser.from_pattern_match
|
test
|
def from_pattern_match(keys, pattern, match)
keys.each_with_index.map do |key, idx|
# Check if there is any replacement specified
if pattern[key]
interpolate(pattern[key], match)
else
|
ruby
|
{
"resource": ""
}
|
q26689
|
UserAgentParser.Parser.interpolate
|
test
|
def interpolate(replacement, match)
group_idx = replacement.index('$')
return replacement if group_idx.nil?
|
ruby
|
{
"resource": ""
}
|
q26690
|
Consular.DSL.before
|
test
|
def before(*commands, &block)
context = (@_context[:before] ||= [])
block_given?
|
ruby
|
{
"resource": ""
}
|
q26691
|
Consular.DSL.window
|
test
|
def window(*args, &block)
key = "window#{@_windows.keys.size}"
options = args.extract_options!
options[:name] = args.first unless args.empty?
context
|
ruby
|
{
"resource": ""
}
|
q26692
|
Consular.DSL.tab
|
test
|
def tab(*args, &block)
tabs = @_context[:tabs]
key = "tab#{tabs.keys.size}"
return (tabs[key] = { :commands => args }) unless block_given?
context = (tabs[key] = {:commands => []})
options = args.extract_options!
options[:name] = args.first unless args.empty?
|
ruby
|
{
"resource": ""
}
|
q26693
|
Consular.DSL.run
|
test
|
def run(*commands)
context = case
when @_context.is_a?(Hash) && @_context[:tabs]
@_context[:tabs]['default'][:commands]
|
ruby
|
{
"resource": ""
}
|
q26694
|
Aerospike.Command.set_write
|
test
|
def set_write(policy, operation, key, bins)
begin_cmd
field_count = estimate_key_size(key, policy)
bins.each do |bin|
estimate_operation_size_for_bin(bin)
|
ruby
|
{
"resource": ""
}
|
q26695
|
Aerospike.Command.set_delete
|
test
|
def set_delete(policy, key)
begin_cmd
field_count = estimate_key_size(key)
size_buffer
write_header_with_policy(policy, 0,
|
ruby
|
{
"resource": ""
}
|
q26696
|
Aerospike.Command.set_touch
|
test
|
def set_touch(policy, key)
begin_cmd
field_count = estimate_key_size(key)
estimate_operation_size
size_buffer
|
ruby
|
{
"resource": ""
}
|
q26697
|
Aerospike.Command.set_exists
|
test
|
def set_exists(policy, key)
begin_cmd
field_count = estimate_key_size(key)
size_buffer
|
ruby
|
{
"resource": ""
}
|
q26698
|
Aerospike.Command.set_read_header
|
test
|
def set_read_header(policy, key)
begin_cmd
field_count = estimate_key_size(key)
estimate_operation_size_for_bin_name('')
size_buffer
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
# The workaround is to request a non-existent bin.
# TODO: Fix this on server.
#command.set_read(INFO1_READ
|
ruby
|
{
"resource": ""
}
|
q26699
|
Aerospike.Command.set_operate
|
test
|
def set_operate(policy, key, operations)
begin_cmd
field_count = estimate_key_size(key, policy)
read_attr = 0
write_attr = 0
read_header = false
operations.each do |operation|
case operation.op_type
when Aerospike::Operation::READ
read_attr |= INFO1_READ
# Read all bins if no bin is specified.
read_attr |= INFO1_GET_ALL unless operation.bin_name
when Aerospike::Operation::READ_HEADER
# The server does not currently return record header data with _INFO1_NOBINDATA attribute set.
# The workaround is to request a non-existent bin.
# TODO: Fix this on server.
# read_attr |= _INFO1_READ | _INFO1_NOBINDATA
read_attr |= INFO1_READ
read_header = true
else
write_attr = INFO2_WRITE
end
estimate_operation_size_for_operation(operation)
end
size_buffer
|
ruby
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.