input stringlengths 109 5.2k | output stringlengths 7 509 |
|---|---|
Summarize the following code: def pivot_each_column(values=[])
pivot.each do |column, parameters|
value = values[parameters[:col].to_i]
value = value.strip.gsub(/^"|"$/, "") unless value.nil?
match = false
begin
match = eval(parameters[:operation].gsub('[value]', value))
... | Yields the column value and whether the filter matches the column |
Summarize the following code: def create_filter(values)
values.scan(/(?<=,|^)(BEGIN.*?END|\/.*?\/|.*?)(?=,|$)/i).flatten.each do |value|
send(value)
end unless values.nil?
end | Creates a filter based on the provided rows and columns select criteria |
Summarize the following code: def equal(value, args, block)
filter << value.to_i unless filter.index(value.to_i)
end | Adds a single value to the filter |
Summarize the following code: def equal_type(type, value, args, block)
filter_size_before = filter.size
equal(value, args, block)
types << type if filter_size_before < filter.size
end | Adds a single value and an associated type to the filter |
Summarize the following code: def range(start_value, end_value, args, block)
filter << (start_value.to_i..end_value.to_i).to_a
end | Adds a range to the filter |
Summarize the following code: def range_type(type, start_value, end_value, args, block)
filter_size_before = filter.size
range(start_value, end_value, args, block)
(filter.size - filter_size_before).times { types << type }
end | Adds a range and the associated types to the filter |
Summarize the following code: def col_regex(col, r, args, block)
operation = "'[value]' =~ Regexp.new('#{r}')"
pivot[r] = { col: col, operation: operation }
end | Adds a comparisson filter |
Summarize the following code: def date(col, comparator, date, args, block)
comparator = '==' if comparator == '='
operation = "Date.strptime(\"[value]\", \"#{date_format}\") #{comparator} " +
"Date.strptime(\"#{date}\", \"#{date_format}\")"
pivot["#{comparator}#{date}"] = { c... | Adds a date filter |
Summarize the following code: def date_range(col, start_date, end_date, args, block)
operation = " Date.strptime(\"#{start_date}\", \"#{date_format}\") " +
"<= Date.strptime(\"[value]\", \"#{date_format}\") && " +
" Date.strptime(\"[value]\", \"#{dat... | Adds a date range filter |
Summarize the following code: def number(col, comparator, number, args, block)
comparator = '==' if comparator == '='
operation = "[value] #{comparator} #{number}"
pivot["#{comparator}#{number}"] = { col: col, operation: operation }
end | Adds a number filter |
Summarize the following code: def number_range(col, start_number, end_number, arg, block)
operation = " #{start_number} <= [value] && [value] <= #{end_number}"
pivot["#{start_number}-#{end_number}"] = { col: col, operation: operation }
end | Adds a number range filter |
Summarize the following code: def create_annotation(hook, annotation)
# validate the arguments
if hook.nil? then raise ArgumentError.new("Annotated caTissue object is missing") end
if annotation.nil? then raise ArgumentError.new("Annotation caTissue object is missing") end
# the annotated object... | Creates a new annotation object in the caTissue database . |
Summarize the following code: def join_as_series(options = {})
if defined?(I18n)
default_delimiter = I18n.translate(:'series_joiner.default_delimiter', :locale => options[:locale])
default_final_delimiter = I18n.translate(:'series_joiner.default_final_delimiter', :locale => options[:lo... | Joins items in an array together in a grammatically correct manner . |
Summarize the following code: def awesome_string(string)
lexers = ::Rouge::Guessers::Source.new(string).filter(R_LEXERS)
if !lexers.empty?
format_syntax_string(string, lexers.first)
elsif string =~ /(?:\r?\n)(?!\z)/
format_multiline_string(string)
else
format_plain_string... | Format a String for awesome_print display . |
Summarize the following code: def meta=val
val = JSON.parse(val) if val.is_a?(String)
write_store_attribute(:data, :meta, val)
end | ensure meta always will be saved as json instead of json string |
Summarize the following code: def execute
File.new(infile).each_with_index do |line, index|
row = row_filter.process(line, row: index)
next if row.nil? or row.chomp.empty?
collection.each do |category, elements|
values = elements[:filter].process(row)
values.chomp.spli... | Creates a new Collector Execute the collector |
Summarize the following code: def init_collection(column_filter)
column_filter.split('+').each do |f|
category, filter = f.split(':')
collection[category] = { entries: [], filter: ColumnFilter.new(filter) }
end
end | Initializes the collection |
Summarize the following code: def log
out.sync = true
@log ||= Logger.new(out)
@log.formatter = proc do |severity, datetime, progname, msg|
if verbose
string = "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%2N')}]: "
else
string = "[#{datetime.strftime('%H:%... | Initialize with default stdout output and verbose false Gets the logging object |
Summarize the following code: def require_aether *deps
@mini_aether_require_spec ||= MiniAether::Spec.new
@mini_aether_require_resolver ||= MiniAether::Resolver.new
spec = @mini_aether_require_spec
resolver = @mini_aether_require_resolver
if deps.last.kind_of?(Hash)
hash = deps.p... | Experimental require_aether method for use in irb or just for convenience . Not threadsafe . |
Summarize the following code: def create_lookup_table
File.open(source).each_with_index do |line|
next if line.chomp.empty?
values = unstring(line).chomp.split(';')
next if values.empty?
@joiners.each do |joiner|
key = values[joiner.join[0]]
joi... | Creates a lookup table from the source file values . The join column of the source file is the key |
Summarize the following code: def col_positions(pos, cols)
if pos.nil? || pos.empty?
pos = []
cols.each { |c| pos << Array.new(c.size) { |c| c } }
pos
else
pos.split(';').collect { |p| p.split(',').collect { |p| p.to_i } }
end
end | Initializes the column positions where the source file columns have to be inserted . If no column positions are provided the inserted columns are put at the beginning of the row |
Summarize the following code: def create_joiners(j, c, p)
js = j.split(';').collect { |j| j.split('=').collect { |j| j.to_i } }
cs = c.split(';').collect { |c| c.split(',').collect { |c| c.to_i } }
ps = col_positions(p, cs)
@joiners = []
(0...js.size).each do |i|
@joi... | Initializes joiners based on joins positions and columns |
Summarize the following code: def add_defaults_local
super
self.title ||= short_title
self.short_title ||= title
self.start_date ||= Java::JavaUtil::Date.new
end | Sets the defaults if necessary . The start date is set to now . The title is set to the short title . |
Summarize the following code: def [](*range)
r, c = range
r ||= 0..(nrows-1)
c ||= 0..(ncols-1)
row_selection = rows.values_at(*r)
col_selection = []
if rows_are_arrays?(row_selection)
row_selection.each do |row|
values = row.values_at(*c)
col_selection... | Returns a subset of the spread sheet and returns a new spread sheet with the result and the corresponding row and column labels |
Summarize the following code: def column_collect(&block)
result = []
0.upto(ncols-1) { |i| result << block.call(self[nil,i]) }
result
end | Collects the operation on each column and returns the result in an array |
Summarize the following code: def rename(opts = {})
if opts[:rows]
opts[:rows] = opts[:rows][0,nrows]
opts[:rows] += row_labels[opts[:rows].size, nrows]
end
if opts[:cols]
opts[:cols] = opts[:cols][0,ncols]
opts[:cols] += col_labels[opts[:cols].size, ncols]
end
... | Renames the row and column labels |
Summarize the following code: def to_s
col_label_sizes = col_labels.collect { |c| c.to_s.size + 2 }
row_label_size = row_labels.collect { |r| r.to_s.size + 2 }.max
row_col_sizes = rows.transpose.collect { |r| r.collect { |c| c.to_s.size } }
i = -1
col_sizes = col_label_sizes.collect do ... | Prints the spread sheet in a matrix with column labels and row labels . If no labels are available the column number and row number is printed |
Summarize the following code: def rows_from_params(opts)
col_count = opts[:cols]
row_count = opts[:rows]
size = row_count * col_count if row_count && col_count
rows = []
if values = opts[:values]
if size
values += [NotAvailable] * (size - values... | Creates rows from provided array or file . If array doesn t provide equal column sizes the array is extended with NotAvailable values |
Summarize the following code: def equalize_rows(rows)
column_sizes = rows.collect { |r| r.size }
return rows if column_sizes.uniq.size == 1
max_size = column_sizes.max
small_rows = []
column_sizes.each_with_index { |c,i| small_rows << i if c < max_size }
small_rows.eac... | If rows are of different column size the rows are equalized in column size by filling missing columns with NA |
Summarize the following code: def same_column_size?(rows)
offset = opts[:c] ? 1 : 0
return true if rows.size == 1 + offset
(0 + offset).upto(rows.size - 2) do |i|
return false unless rows[i].size == rows[i+1].size
end
true
end | Checks whether all rows have the same column size . Returns true if all columns have the same column size |
Summarize the following code: def coerce(value)
return SpreadSheet.new([value]) if value.is_a?(Numeric)
return SpreadSheet.new(value) if value.is_a?(Array)
end | Coerces a number or an array to a spread sheet |
Summarize the following code: def process(operator, s)
s = coerce(s) || s
raise "operand needs to be a SpreadSheet, "+
"Numeric or Array" unless s.is_a?(SpreadSheet)
result = []
rlabel = []
clabel = []
s1_row_count, s1_col_count = dim
s2_row_count, s... | Conducts the calculation of this spread sheet with the provided value based on the operator . It s is a number or an array it is coerced into a spread sheet |
Summarize the following code: def process_count
File.new(infile).each_with_index do |line, index|
result = col_filter.process(row_filter.process(line.chomp, row: index))
unless result.nil? or result.empty?
key = unstring(line).split(';').values_at(*key_columns)
key_value = key_... | Processes the counting on the in file |
Summarize the following code: def write_result
sum_line = [sum_row_title] + [''] * (key_titles.size - 1)
headline = heading_sort ? heading.sort : original_pivot_sequence_heading
headline << add_sum_col unless sum_col_title.nil?
headline.each do |h|
sum_line << sums[h]
end
row... | Writes the count results |
Summarize the following code: def init_sum_scheme(sum_scheme)
return if sum_scheme.nil?
re = /(\w+):(\d+)|(\w+)/
sum_scheme.scan(re).each do |part|
if part.compact.size == 2
@sum_row_title = part[0]
@sum_row = part[1].to_i
else
@su... | Initializes the sum row title an positions as well as the sum column title |
Summarize the following code: def init_key_columns(key_scheme)
@key_titles = []
@key_columns = []
keys = key_scheme.scan(/(\d+):(\w+)/)
keys.each do |key|
@key_titles << key[1]
@key_columns << key[0].to_i
end
end | Initialize the key columns and headers |
Summarize the following code: def original_pivot_sequence_heading
(heading.sort - col_filter.pivot.keys << col_filter.pivot.keys).flatten
end | Arrange heading in the original sequence regarding conditional column filters |
Summarize the following code: def process(object, options={})
object = unstring(object)
return object unless has_filter?
filtered = !filter.flatten.uniq.index(options[:row]).nil?
pattern.each do |p|
filtered = (filtered or !(object =~ Regexp.new(p)).nil?)
end
filtered = (filt... | Processes the filter on the given row |
Summarize the following code: def messages
data = api('pm.history', :receiverid => id)
data['history'].map {|attrs| Message.new(client, attrs)}
end | Gets the private conversation history with this user . |
Summarize the following code: def stalk
become_fan unless client.user.fan_of.include?(self)
client.rooms.with_friends.detect do |room|
room.listener(id)
end
end | Gets the location of the user . |
Summarize the following code: def boot(reason = '')
api('room.boot_user', :roomid => room.id, :section => room.section, :target_userid => id, :reason => reason)
true
end | Boots the user for the specified reason . |
Summarize the following code: def report(reason = '')
api('room.report_user', :roomid => room.id, :section => room.section, :reported => id, :reason => reason)
true
end | Reports abuse by a user . |
Summarize the following code: def default_derived_characteristics
chrs = specimen_characteristics || return
pas = chrs.class.nondomain_attributes.reject { |pa| pa == :identifier }
chrs.copy(pas)
end | Returns characteristics to use for a derived specimen . The new characteristics is copied from this parent specimen s characteristics without the identifier . |
Summarize the following code: def region=(args)
case args
when Hash
self.setRegion(CoordinateRegion.new(args[:region]).api, animated: args[:animated])
else
self.setRegion(CoordinateRegion.new(args).api, animated: false)
end
end | Set the maps region |
Summarize the following code: def collection_site
return unless medical_identifiers.size == 1
site = medical_identifiers.first.site
return if site.nil?
site.site_type == Site::SiteType::COLLECTION ? site : nil
end | Returns the collection site for which this participant has a MRN . If there is not exactly one such site then this method returns nil . This method is a convenience for the common situation where a participant is enrolled at one site . |
Summarize the following code: def match_characteristics(other)
chr = characteristics
ochr = other.characteristics
chr and ochr and chr.tissue_side == ochr.tissue_side and chr.tissue_site == ochr.tissue_site
end | Returns whether this SpecimenRequirement characteristics matches the other SpecimenRequirement characteristics on the tissue site and tissue side . |
Summarize the following code: def default_user
scg = specimen_collection_group || (specimen.specimen_collection_group if specimen) || return
cp = scg.collection_protocol || return
cp.coordinators.first || (cp.sites.first.coordinator if cp.sites.size === 1)
end | Returns the first SCG CP coordinator if any . |
Summarize the following code: def export!
puts "Exporting translations:\n"
if config[:split]
translations.keys.each do |locale|
if translations[:en].nil?
puts 'Missing english translation'
exit
end
puts "\nLocale: #{locale}"
fallback_en... | Export translations to JavaScript considering settings from configuration file |
Summarize the following code: def save(translations, file)
file = ::Rails.root.join(file)
FileUtils.mkdir_p File.dirname(file)
variable_to_assign = config.fetch(:variable, 'Ember.I18n.translations')
File.open(file, 'w+') do |f|
f << variable_to_assign
f << ' = '
f << JS... | Convert translations to JSON string and save file . |
Summarize the following code: def translations
::I18n.load_path = default_locales_path
::I18n.backend.instance_eval do
init_translations unless initialized?
translations
end
end | Initialize and return translations |
Summarize the following code: def load_properties
# the properties file
file = default_properties_file
# the access properties
props = file && File.exists?(file) ? load_properties_file(file) : {}
# Load the Java application jar path.
path = props[:classpath] || props[:path] || infer_... | Loads the caTissue classpath and connection properties . |
Summarize the following code: def parse
download_files
parsing_clients = false
parsing_prefile = false
parsing_general = false
parsing_servers = false
parsing_voice_servers = false
File.open(DATA_FILE_PATH, 'r:ascii-8bit').each { |line|
if line.start_with? ";"
... | Parse the vatsim data file and store output as necessary |
Summarize the following code: def download_files
if !File.exists?(STATUS_FILE_PATH) or File.mtime(STATUS_FILE_PATH) < Time.now - STATUS_DOWNLOAD_INTERVAL
download_to_file STATUS_URL, STATUS_FILE_PATH
end
if !File.exists?(DATA_FILE_PATH) or File.mtime(DATA_FILE_PATH) < Time.now - DATA_DOWNLOAD_... | Initialize the system by downloading status and vatsim data files |
Summarize the following code: def download_to_file url, file
url = URI.parse(URI.encode(url.strip))
File.new(file, File::CREAT)
Net::HTTP.start(url.host) { |http|
resp = http.get(url.path)
open(file, "wb") { |file|
file.write(resp.body)
}
}
end | Download a url to a file path |
Summarize the following code: def random_data_url
url0s = Array.new
file = File.open(STATUS_FILE_PATH)
file.each {|line|
if line.start_with? "url0"
url0s << line.split("=").last
end
}
return url0s[rand(url0s.length)]
end | Return random vatsim data url from status file |
Summarize the following code: def cachier!(var = nil)
if var && instance_variable_get("@#{var}")
# => Clear the Single Variable
remove_instance_variable("@#{var}")
else
# => Clear the Whole Damned Cache
instance_variables.each { |x| remove_instance_variable(x) }
end
... | = > Clear Cache |
Summarize the following code: def write_json(file, object)
return unless file && object
begin
File.open(file, 'w') { |f| f.write(JSON.pretty_generate(object)) }
end
end | = > Define JSON Writer |
Summarize the following code: def filestring(file, size = 8192)
return unless file
return file unless file.is_a?(String) && File.file?(file) && File.size(file) <= size
File.read(file)
end | = > Check if a string is an existing file and return it s content |
Summarize the following code: def common_array(ary) # rubocop: disable AbcSize
return ary unless ary.is_a? Array
count = ary.count
return ary if count.zero?
return ary.flatten.uniq if count == 1
common = ary[0] & ary[1]
return common if count == 2
(count - 2).times { |x| common... | = > Return Common Elements of an Array |
Summarize the following code: def run
bind_queues and return if test_env?
start_shutdown_thread
start_error_counter_thread
client.on_exception do |e|
count_error(e)
end
client.connect
start_event_thread
puts 'EventListener started. Hit Ctrl-C to exit'
Threa... | Initialize a new EventListener daemon instance |
Summarize the following code: def register_observer_class(observer_class)
@observer_mutex.synchronize do
return if @observed_models.include?(observer_class)
@observed_models << observer_class
log "EventListener: registering observer class #{observer_class}"
observer_queue.bind(mode... | Register the observer class watcher |
Summarize the following code: def register_observer(observer)
@observer_mutex.synchronize do
log "EventListener: registering observer #{observer.class} #{observer.id}"
@observers[observer_key_for(observer.class, observer.id)] = observer.observe_events(client)
end
end | Register an observer instance and start listening for events on its associated queue . Also ensure that we are listening for observer class update events |
Summarize the following code: def unregister_observer(observer_class, observer_id)
@observer_mutex.synchronize do
log "EventListener: un-registering observer #{observer_class} #{observer_id}"
if (consumer = @observers.delete(observer_key_for(observer_class, observer_id)))
consumer.cancel... | Unregister an observer instance and cancel consumption of messages . Any pre - fetched messages will be returned to the queue . |
Summarize the following code: def observer_queue
@observer_queue ||= client.create_queue([name, 'listener', Socket.gethostname, Process.pid].join('.'),
models_exchange,
queue_options: {exclusive: true},
... | Create or return the observer queue which listens for ModelWatcher events |
Summarize the following code: def as_json(options = {})
session_id = parameters.delete(:session_id) || Thread.current[:keas_session_id]
data = {type: type,
action: action,
user_id: user_id,
occurred_at: occurred_at,
eventful_ty... | Return hash of data to be serialized to JSON |
Summarize the following code: def do_create(action)
options = do_creation_options
options.title ||= @params.first
@helper.send("#{action}_usage") unless options.title
fn = @commands.send(action, options)
puts "#{@src_dir}/#{fn}"
end | action is a string either post or draft |
Summarize the following code: def do_move(action)
options = do_move_options(action)
path = @params.first
@helper.send("#{action}_usage") unless path
fn = @commands.send(action, path, options)
puts "#{@src_dir}/#{fn}"
end | action is a string either publish or unpublish |
Summarize the following code: def do_move_options(type)
options = OpenStruct.new
opt_parser = OptionParser.new do |opts|
if type == 'publish'
opts.on('-d', '--keep-draft', "Keep draft post") do |d|
options.keep_draft = d
end
else
opts.on('-p', '--kee... | pass a string either publish or unpublish |
Summarize the following code: def resolve_links(text)
html = Nokogiri::HTML.fragment(text)
html.css("a[href]").each do |link|
href = URI(link["href"])
next unless href.relative? && markup_for_file(nil, href.path) == :markdown
link.replace "{file:#{href} #{link.inner_html}}"
end... | Resolves relative links to Markdown files . |
Summarize the following code: def nr_api
# => Build the Faraday Connection
@conn ||= Faraday::Connection.new('https://api.newrelic.com', conn_opts) do |client|
client.use Faraday::Response::RaiseError
client.use FaradayMiddleware::EncodeJson
client.use FaradayMiddleware::ParseJson, c... | = > Build the HTTP Connection |
Summarize the following code: def alert_add_entity(entity_id, condition_id, entity_type = 'Server')
nr_api.put do |req|
req.url url('alerts_entity_conditions', entity_id)
req.params['entity_type'] = entity_type
req.params['condition_id'] = condition_id
end
end | = > Add an Entitity to an Existing Alert Policy |
Summarize the following code: def alert_delete_entity(entity_id, condition_id, entity_type = 'Server')
nr_api.delete do |req|
req.url url('alerts_entity_conditions', entity_id)
req.params['entity_type'] = entity_type
req.params['condition_id'] = condition_id
end
end | = > Delete an Entitity from an Existing Alert Policy |
Summarize the following code: def get_server_id(server_id)
return nil unless server_id =~ /^[0-9]+$/
ret = nr_api.get(url('servers', server_id)).body
ret['server']
rescue Faraday::ResourceNotFound, NoMethodError
nil
end | = > Get a Server based on ID |
Summarize the following code: def get_server_name(server, exact = true)
ret = nr_api.get(url('servers'), 'filter[name]' => server).body
return ret['servers'] unless exact
ret['servers'].find { |x| x['name'].casecmp(server).zero? }
rescue NoMethodError
nil
end | = > Get a Server based on Name |
Summarize the following code: def get_servers_labeled(labels)
label_query = Array(labels).reject { |x| !x.include?(':') }.join(';')
return [] unless label_query
nr_api.get(url('servers'), 'filter[labels]' => label_query).body
end | = > List the Servers with a Label |
Summarize the following code: def observe_events(client)
return unless enable_listener?
queue = create_queue(client)
client.subscribe(queue) do |message|
event = Event.parse(message)
handle_event(event)
end
end | Create or attach to a queue on the specified exchange . When an event message that matches the observer s routing keys is received parse the event and call handle_event on same . |
Summarize the following code: def bind(queue_name, exchange_name, *routing_keys, &block)
queue = create_queue(queue_name, exchange_name,
queue_options: {durable: true},
routing_keys: routing_keys)
subscribe(queue, &block) if block_given?
end | Initialize a new BunnyClient instance . Note that a connection is not established until any other method is called |
Summarize the following code: def create_queue(queue_name, exchange_name, options = {})
queue_options = options[:queue_options] || {durable: true}
routing_keys = options[:routing_keys] || []
log "Isimud::BunnyClient: create_queue #{queue_name}: queue_options=#{queue_options.inspect}"
queue = fi... | Find or create a named queue and bind it to the specified exchange |
Summarize the following code: def subscribe(queue, options = {}, &block)
queue.subscribe(options.merge(manual_ack: true)) do |delivery_info, properties, payload|
current_channel = delivery_info.channel
begin
log "Isimud: queue #{queue.name} received #{properties[:message_id]} routing_key... | Subscribe to messages on the Bunny queue . The provided block will be called each time a message is received . The message will be acknowledged and deleted from the queue unless an exception is raised from the block . In the case that an uncaught exception is raised the message is rejected and any declared exception ha... |
Summarize the following code: def channel
if (channel = Thread.current[CHANNEL_KEY]).try(:open?)
channel
else
new_channel = connection.channel
new_channel.confirm_select
new_channel.prefetch(Isimud.prefetch_count) if Isimud.prefetch_count
Thread.current[CHANNEL_KEY] =... | Open a new thread - specific AMQP connection channel or return the current channel for this thread if it exists and is currently open . New channels are created with publisher confirms enabled . Messages will be prefetched according to Isimud . prefetch_count when declared . |
Summarize the following code: def publish(exchange, routing_key, payload, options = {})
log "Isimud::BunnyClient#publish: exchange=#{exchange} routing_key=#{routing_key}", :debug
channel.topic(exchange, durable: true).publish(payload, options.merge(routing_key: routing_key, persistent: true))
end | Publish a message to the specified exchange which is declared as a durable topic exchange . Note that message is always persisted . |
Summarize the following code: def post(opts)
opts = @helper.ensure_open_struct(opts)
date = @helper.get_date_stamp
# still want to escape any garbage in the slug
slug = if opts.slug.nil? || opts.slug.empty?
opts.title
else
opts.slug
end
... | Generate a timestamped post |
Summarize the following code: def draft(opts)
opts = @helper.ensure_open_struct(opts)
# the drafts folder might not exist yet...create it just in case
FileUtils.mkdir_p(DRAFTS_FOLDER)
slug = if opts.slug.nil? || opts.slug.empty?
opts.title
else
opts.s... | Generate a non - timestamped draft |
Summarize the following code: def publish(draftpath, opts={})
opts = @helper.ensure_open_struct(opts)
tail = File.basename(draftpath)
begin
infile = File.open(draftpath, "r")
rescue Errno::ENOENT
@helper.bad_path(draftpath)
end
date = @helper.get_date_stamp
ti... | Todo make this take a path instead? |
Summarize the following code: def terminal_size
rows, cols = 25, 80
buf = [0, 0, 0, 0].pack("SSSS")
if $stdout.ioctl(TIOCGWINSZ, buf) >= 0 then
rows, cols, row_pixels, col_pixels = buf.unpack("SSSS")
end
return [rows, cols]
end | 0000002 thanks google for all of this |
Summarize the following code: def prepare_modes
buf = [0, 0, 0, 0, 0, 0, ''].pack("IIIICCA*")
$stdout.ioctl(TCGETS, buf)
@old_modes = buf.unpack("IIIICCA*")
new_modes = @old_modes.clone
new_modes[3] &= ~ECHO # echo off
new_modes[3] &= ~ICANON # one char @ a time
$stdout.ioctl(TCSETS, new_mod... | had to convert these from C ... fun |
Summarize the following code: def extract_subjects(subject)
return extract_subjects(subject.to_permission_instance) if subject.respond_to? :to_permission_instance
return subject[:any] if subject.is_a? Hash and subject.key? :any
[subject]
end | Override functionality from CanCan to allow objects to masquerade as other objects |
Summarize the following code: def daemon # rubocop: disable AbcSize, MethodLength
# => Windows Workaround (https://github.com/bdwyertech/newrelic-management/issues/1)
ENV['TZ'] = 'UTC' if OS.windows? && !ENV['TZ']
scheduler = Rufus::Scheduler.new
Notifier.msg('Daemonizing Process')
# => ... | = > Daemonization for Periodic Management |
Summarize the following code: def run
daemon if Config.daemonize
# => Manage Alerts
Manager.manage_alerts
# => Manage
Manager.remove_nonreporting_servers(Config.cleanup_age) if Config.cleanup
end | = > Run the Application |
Summarize the following code: def ensure_jekyll_dir
@orig_dir = Dir.pwd
start_path = Pathname.new(@orig_dir)
ok = File.exists?('./_posts')
new_path = nil
# if it doesn't exist, check for a custom source dir in _config.yml
if !ok
check_custom_src_dir!
ok = File.exist... | Check for a _posts directory in current directory . If there s not one check for a _config . yml and look for a custom src directory . If we don t find one puke an error message and die . If we do return the name of the directory |
Summarize the following code: def get_layout(layout_path)
if layout_path.nil?
contents = "---\n"
contents << "title:\n"
contents << "layout: post\n"
contents << "date:\n"
contents << "---\n"
ext = nil
else
begin
contents = File.open(layout_... | Get a layout as a string . If layout_path is non - nil will open that file and read it otherwise will return a default one and a file extension to use |
Summarize the following code: def gen_usage
puts 'Usage:'
puts ' poole [ACTION] [ARG]'
puts ''
puts 'Actions:'
puts ' draft Create a new draft in _drafts with title SLUG'
puts ' post Create a new timestamped post in _posts with title SLUG'
puts ' publish Publi... | Print a usage message and exit |
Summarize the following code: def msg(message, subtitle = message, title = 'NewRelic Management')
# => Stdout Messages
terminal_notification(message, subtitle)
return if Config.silent
# => Pretty GUI Messages
osx_notification(message, subtitle, title) if OS.x?
end | = > Primary Notification Message Controller |
Summarize the following code: def osx_notification(message, subtitle, title)
TerminalNotifier.notify(message, title: title, subtitle: subtitle)
end | = > OS X Cocoa Messages |
Summarize the following code: def analyze(string, options = {})
x = []
@fst._analyze(string) do |a|
if options[:symbol_sequence]
x << a.map { |s| s.match(/^<(.*)>$/) ? $1.to_sym : s }
else
x << a.join
end
end
x
end | Analyses a string + string + . Returns an array of analysed strings if the string is accepted or an empty array if not . |
Summarize the following code: def generate(string)
x = []
@fst._generate(string) { |a| x << a.join }
x
end | Generates a string + string + . Returns an array of generated strings if the string is accepted or an empty array if not . |
Summarize the following code: def configure(argv = ARGV)
# => Parse CLI Configuration
cli = Options.new
cli.parse_options(argv)
# => Parse JSON Config File (If Specified and Exists)
json_config = Util.parse_json(cli.config[:config_file] || Config.config_file)
# => Merge Configurati... | = > Configure the CLI |
Summarize the following code: def missing_specs_from_file(path)
Spectro::Spec::Parser.parse(path).select do |spec|
index_spec = Spectro::Database.index[path] && Spectro::Database.index[path][spec.signature.name]
index_spec.nil? || index_spec['spec_md5'] != spec.md5
end
end | Parse the specs on the given file path and return those that have not been fulfilled or need to be updated . |
Summarize the following code: def remove_nonreporting_servers(keeptime = nil)
list_nonreporting_servers.each do |server|
next if keeptime && Time.parse(server[:last_reported_at]) >= Time.now - ChronicDuration.parse(keeptime)
Notifier.msg(server[:name], 'Removing Stale, Non-Reporting Server')
... | = > Remove Non - Reporting Servers |
Summarize the following code: def find_excluded(excluded)
result = []
Array(excluded).each do |exclude|
if exclude.include?(':')
find_labeled(exclude).each { |x| result << x }
next
end
res = Client.get_server(exclude)
result << res['id'] if res
end
... | = > Find Servers which should be excluded from Management |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.