_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23000 | Dradis::Plugins::ContentService.Issues.issue_cache | train | def issue_cache
@issue_cache ||= begin
issues_map = all_issues.map do |issue|
cache_key = [
issue.fields['plugin'],
issue.fields['plugin_id']
].join('-')
[cache_key, issue]
end
Hash[issues_map]
end
end | ruby | {
"resource": ""
} |
q23001 | Bunto.Renderer.render_liquid | train | def render_liquid(content, payload, info, path = nil)
template = site.liquid_renderer.file(path).parse(content)
template.warnings.each do |e|
Bunto.logger.warn "Liquid Warning:",
LiquidRenderer.format_error(e, path || document.relative_path)
end
template.render!(payload, info)
... | ruby | {
"resource": ""
} |
q23002 | Bunto.Renderer.place_in_layouts | train | def place_in_layouts(content, payload, info)
output = content.dup
layout = layouts[document.data["layout"]]
Bunto.logger.warn(
"Build Warning:",
"Layout '#{document.data["layout"]}' requested in "\
"#{document.relative_path} does not exist."
) if invalid_layout? layout
... | ruby | {
"resource": ""
} |
q23003 | Bunto.Site.reset | train | def reset
if config["time"]
self.time = Utils.parse_date(config["time"].to_s, "Invalid time in _config.yml.")
else
self.time = Time.now
end
self.layouts = {}
self.pages = []
self.static_files = []
self.data = {}
@collections = nil
@regenerator.clear_... | ruby | {
"resource": ""
} |
q23004 | Bunto.Site.setup | train | def setup
ensure_not_in_dest
plugin_manager.conscientious_require
self.converters = instantiate_subclasses(Bunto::Converter)
self.generators = instantiate_subclasses(Bunto::Generator)
end | ruby | {
"resource": ""
} |
q23005 | Bunto.Site.ensure_not_in_dest | train | def ensure_not_in_dest
dest_pathname = Pathname.new(dest)
Pathname.new(source).ascend do |path|
if path == dest_pathname
raise(
Errors::FatalException,
"Destination directory cannot be or contain the Source directory."
)
end
end
end | ruby | {
"resource": ""
} |
q23006 | Bunto.Site.generate | train | def generate
generators.each do |generator|
start = Time.now
generator.generate(self)
Bunto.logger.debug "Generating:",
"#{generator.class} finished in #{Time.now - start} seconds."
end
end | ruby | {
"resource": ""
} |
q23007 | Bunto.Site.render | train | def render
relative_permalinks_are_deprecated
payload = site_payload
Bunto::Hooks.trigger :site, :pre_render, self, payload
render_docs(payload)
render_pages(payload)
Bunto::Hooks.trigger :site, :post_render, self, payload
end | ruby | {
"resource": ""
} |
q23008 | Bunto.Page.dir | train | def dir
if url.end_with?(FORWARD_SLASH)
url
else
url_dir = File.dirname(url)
url_dir.end_with?(FORWARD_SLASH) ? url_dir : "#{url_dir}/"
end
end | ruby | {
"resource": ""
} |
q23009 | Bunto.Convertible.read_yaml | train | def read_yaml(base, name, opts = {})
filename = File.join(base, name)
begin
self.content = File.read(@path || site.in_source_dir(base, name),
Utils.merged_file_read_opts(site, opts))
if content =~ Document::YAML_FRONT_MATTER_REGEXP
self.content = $... | ruby | {
"resource": ""
} |
q23010 | Bunto.Filters.sassify | train | def sassify(input)
site = @context.registers[:site]
converter = site.find_converter_instance(Bunto::Converters::Sass)
converter.convert(input)
end | ruby | {
"resource": ""
} |
q23011 | Bunto.Filters.scssify | train | def scssify(input)
site = @context.registers[:site]
converter = site.find_converter_instance(Bunto::Converters::Scss)
converter.convert(input)
end | ruby | {
"resource": ""
} |
q23012 | ValidateWebsite.Crawl.extract_imgs_from_page | train | def extract_imgs_from_page(page)
return Set[] if page.is_redirect?
page.doc.search('//img[@src]').reduce(Set[]) do |result, elem|
u = elem.attributes['src'].content
result << page.to_absolute(URI.parse(URI.encode(u)))
end
end | ruby | {
"resource": ""
} |
q23013 | Geos.GeometryCollection.each | train | def each
if block_given?
num_geometries.times do |n|
yield get_geometry_n(n)
end
self
else
num_geometries.times.collect { |n|
get_geometry_n(n)
}.to_enum
end
end | ruby | {
"resource": ""
} |
q23014 | Bunto.Collection.read | train | def read
filtered_entries.each do |file_path|
full_path = collection_dir(file_path)
next if File.directory?(full_path)
if Utils.has_yaml_header? full_path
read_document(full_path)
else
read_static_file(file_path, full_path)
end
end
docs.sort!... | ruby | {
"resource": ""
} |
q23015 | IndexAsCalendar.DSL.index_as_calendar | train | def index_as_calendar( options={}, &block )
default_options = {
:ajax => true, # Use AJAX to fetch events. Set to false to send data during render.
:model => nil, # Model to be used to fetch events. Defaults to ActiveAdmin resource model.
:includes => [], # Eager loading of related mod... | ruby | {
"resource": ""
} |
q23016 | Geos.Geometry.union | train | def union(geom = nil)
if geom
check_geometry(geom)
cast_geometry_ptr(FFIGeos.GEOSUnion_r(Geos.current_handle_pointer, ptr, geom.ptr), srid_copy: pick_srid_from_geoms(srid, geom.srid))
else
if respond_to?(:unary_union)
unary_union
else
union_cascaded
... | ruby | {
"resource": ""
} |
q23017 | Geos.Geometry.relate_pattern | train | def relate_pattern(geom, pattern)
check_geometry(geom)
bool_result(FFIGeos.GEOSRelatePattern_r(Geos.current_handle_pointer, ptr, geom.ptr, pattern))
end | ruby | {
"resource": ""
} |
q23018 | Roboto.ContentProvider.contents | train | def contents(custom_binding = nil)
return @contents unless @contents.nil?
@contents = File.read(path)
if path.extname == '.erb'
@contents = ERB.new(@contents, nil, '>').result(custom_binding ? custom_binding : binding)
end
@contents
end | ruby | {
"resource": ""
} |
q23019 | Bunto.Regenerator.regenerate? | train | def regenerate?(document)
case document
when Page
regenerate_page?(document)
when Document
regenerate_document?(document)
else
source_path = document.respond_to?(:path) ? document.path : nil
dest_path = if document.respond_to?(:destination)
d... | ruby | {
"resource": ""
} |
q23020 | Bunto.Regenerator.read_metadata | train | def read_metadata
@metadata =
if !disabled? && File.file?(metadata_file)
content = File.binread(metadata_file)
begin
Marshal.load(content)
rescue TypeError
SafeYAML.load(content)
rescue ArgumentError => e
Bunto.logger.warn("Faile... | ruby | {
"resource": ""
} |
q23021 | Bunto.FrontmatterDefaults.applies? | train | def applies?(scope, path, type)
applies_path?(scope, path) && applies_type?(scope, type)
end | ruby | {
"resource": ""
} |
q23022 | Phcscriptcdn.Script::VersionsController.show | train | def show
@script_versions = Script::Version.friendly.find(params[:id])
@versions = Phcscriptcdn::ScriptversionVersions.where(item_id: params[:id], item_type: 'Phcscriptcdn::Script::Version')
end | ruby | {
"resource": ""
} |
q23023 | Phcscriptcdn.Script::VersionsController.new | train | def new
@script_version = Script::Version.new
@script_version.user_id = current_user.id
@script_version.org_id = current_user.org_id
end | ruby | {
"resource": ""
} |
q23024 | Phcscriptcdn.Script::VersionsController.create | train | def create
@script_version = Script::Version.new(script_version_params)
@script_version.user_id = current_user.id
@script_version.org_id = current_user.org_id
if @script_version.save
redirect_to script_versions_url, notice: 'Version was successfully created.'
else
rende... | ruby | {
"resource": ""
} |
q23025 | Nightwing.Metric.for | train | def for(queue:, worker: nil)
worker_name = worker.to_s.underscore.tr("/", "_") if worker
[namespace, queue, worker_name].compact.join(".")
end | ruby | {
"resource": ""
} |
q23026 | Phcscriptcdn.Script::UrlsController.show | train | def show
script_listing = Script::Listing.find(params[:listing_id])
@script_url = script_listing.urls.friendly.find(params[:id])
end | ruby | {
"resource": ""
} |
q23027 | Phcscriptcdn.Script::UrlsController.new | train | def new
script_listing = Script::Listing.find(params[:listing_id])
@script_url = script_listing.urls.build
@script_url.user_id = current_user.id
@script_url.org_id = current_user.org_id
end | ruby | {
"resource": ""
} |
q23028 | Phcscriptcdn.Script::UrlsController.edit | train | def edit
script_listing = Script::Listing.find(params[:listing_id])
@script_url = script_listing.urls.find(params[:id])
end | ruby | {
"resource": ""
} |
q23029 | Phcscriptcdn.Script::UrlsController.create | train | def create
@script_listing = Script::Listing.find(params[:listing_id])
@script_url = @script_listing.urls.create(script_url_params)
@script_url.user_id = current_user.id
@script_url.org_id = current_user.org_id
if @script_url.save
redirect_to script_listing_urls_path, notice: 'Auth... | ruby | {
"resource": ""
} |
q23030 | Phcscriptcdn.Script::UrlsController.destroy | train | def destroy
@script_listing = Script::Listing.find(params[:listing_id])
@script_url = @script_listing.urls.find(params[:id])
@script_url.destroy
redirect_to script_listing_urls_path, notice: 'Author was successfully destroyed.'
end | ruby | {
"resource": ""
} |
q23031 | Phcscriptcdn.Script::ListingsController.show | train | def show
@script_listings = Script::Listing.friendly.find(params[:id])
@versions = Phcscriptcdn::ListingVersions.where(item_id: params[:id], item_type: 'Phcscriptcdn::Script::Listing')
end | ruby | {
"resource": ""
} |
q23032 | Phcscriptcdn.Script::ListingsController.create | train | def create
@script_listing = Script::Listing.new(script_listing_params)
@script_listing.user_id = current_user.id
@script_listing.org_id = current_user.org_id
if @script_listing.save
redirect_to script_listings_path, notice: 'Listing was successfully created.'
else
rend... | ruby | {
"resource": ""
} |
q23033 | RubyManta.MantaClient.put_object | train | def put_object(obj_path, data, opts = {})
url = obj_url(obj_path)
opts[:data] = data
headers = gen_headers(opts)
cors_headers = gen_cors_headers(opts)
headers = headers.concat(cors_headers)
durability_level = opts[:durability_level]
if durability_level
raise Argument... | ruby | {
"resource": ""
} |
q23034 | RubyManta.MantaClient.get_object | train | def get_object(obj_path, opts = {})
url = obj_url(obj_path)
headers = gen_headers(opts)
attempt(opts[:attempts]) do
method = opts[:head] ? :head : :get
result = @client.send(method, url, nil, headers)
raise unless result.is_a? HTTP::Message
if result.status == 200... | ruby | {
"resource": ""
} |
q23035 | RubyManta.MantaClient.delete_object | train | def delete_object(obj_path, opts = {})
url = obj_url(obj_path)
headers = gen_headers(opts)
attempt(opts[:attempts]) do
result = @client.delete(url, nil, headers)
raise unless result.is_a? HTTP::Message
return true, result.headers if result.status == 204
raise_erro... | ruby | {
"resource": ""
} |
q23036 | RubyManta.MantaClient.put_directory | train | def put_directory(dir_path, opts = {})
url = obj_url(dir_path)
headers = gen_headers(opts)
headers.push([ 'Content-Type', 'application/json; type=directory' ])
cors_headers = gen_cors_headers(opts)
headers = headers.concat(cors_headers)
attempt(opts[:attempts]) do
result = ... | ruby | {
"resource": ""
} |
q23037 | RubyManta.MantaClient.list_directory | train | def list_directory(dir_path, opts = {})
url = obj_url(dir_path)
headers = gen_headers(opts)
query_parameters = {}
limit = opts[:limit] || MAX_LIMIT
raise ArgumentError unless 0 < limit && limit <= MAX_LIMIT
query_parameters[:limit] = limit
marker = opts[:marker]
if ... | ruby | {
"resource": ""
} |
q23038 | RubyManta.MantaClient.find | train | def find(dir_path, opts = {})
regex = opts.key?(:regex) ? opts[:regex] : nil
# We should always be doing GET because switching between methods is used
# within this function.
opts.delete(:head)
begin
exists = list_directory(dir_path, head: true).first
rescue
exists ... | ruby | {
"resource": ""
} |
q23039 | RubyManta.MantaClient.delete_directory | train | def delete_directory(dir_path, opts = {})
url = obj_url(dir_path)
headers = gen_headers(opts)
attempt(opts[:attempts]) do
result = @client.delete(url, nil, headers)
raise unless result.is_a? HTTP::Message
return true, result.headers if result.status == 204
raise_e... | ruby | {
"resource": ""
} |
q23040 | RubyManta.MantaClient.put_snaplink | train | def put_snaplink(orig_path, link_path, opts = {})
headers = gen_headers(opts)
headers.push([ 'Content-Type', 'application/json; type=link' ],
[ 'Location', obj_url(orig_path) ])
attempt(opts[:attempts]) do
result = @client.put(obj_url(link_path), nil, headers... | ruby | {
"resource": ""
} |
q23041 | RubyManta.MantaClient.create_job | train | def create_job(job, opts = {})
raise ArgumentError unless job[:phases] || job['phases']
headers = gen_headers(opts)
headers.push([ 'Content-Type', 'application/json; type=job' ])
data = job.to_json
attempt(opts[:attempts]) do
result = @client.post(job_url(), data, headers)
... | ruby | {
"resource": ""
} |
q23042 | RubyManta.MantaClient.get_job | train | def get_job(job_path, opts = {})
url = job_url(job_path, '/live/status')
headers = gen_headers(opts)
attempt(opts[:attempts]) do
method = opts[:head] ? :head : :get
result = @client.send(method, url, nil, headers)
raise unless result.is_a? HTTP::Message
if result.... | ruby | {
"resource": ""
} |
q23043 | RubyManta.MantaClient.get_job_errors | train | def get_job_errors(job_path, opts = {})
url = job_url(job_path, '/live/err')
headers = gen_headers(opts)
attempt(opts[:attempts]) do
method = opts[:head] ? :head : :get
result = @client.send(method, url, nil, headers)
raise unless result.is_a? HTTP::Message
if res... | ruby | {
"resource": ""
} |
q23044 | RubyManta.MantaClient.cancel_job | train | def cancel_job(job_path, opts = {})
url = job_url(job_path, 'live/cancel')
body = '{}'
opts[:data] = body
headers = gen_headers(opts)
headers << [ 'Accept', 'application/json' ]
headers << [ 'Content-Type', 'application/json']
headers << [ 'Content-Length', body.bytesiz... | ruby | {
"resource": ""
} |
q23045 | RubyManta.MantaClient.add_job_keys | train | def add_job_keys(job_path, obj_paths, opts = {})
url = job_url(job_path, '/live/in')
headers = gen_headers(opts)
headers.push([ 'Content-Type', 'text/plain' ])
data = obj_paths.join("\n")
attempt(opts[:attempts]) do
result = @client.post(url, data, headers)
raise unless r... | ruby | {
"resource": ""
} |
q23046 | RubyManta.MantaClient.end_job_input | train | def end_job_input(job_path, opts = {})
url = job_url(job_path, '/live/in/end')
headers = gen_headers(opts)
attempt(opts[:attempts]) do
result = @client.post(url, nil, headers)
raise unless result.is_a? HTTP::Message
return true, result.headers if result.status == 202
... | ruby | {
"resource": ""
} |
q23047 | RubyManta.MantaClient.list_jobs | train | def list_jobs(state, opts = {})
raise ArgumentError unless [:all, :running, :done].include? state
state = nil if state == :all
headers = gen_headers(opts)
attempt(opts[:attempts]) do
# method = opts[:head] ? :head : :get
method = :get # until added to Manta service
resul... | ruby | {
"resource": ""
} |
q23048 | RubyManta.MantaClient.gen_signed_url | train | def gen_signed_url(expires, method, path, args=[])
methods = method.is_a?(Array) ? method : [method]
raise ArgumentError unless (methods - [:get, :put, :post, :delete, :options]).empty?
raise ArgumentError unless path =~ OBJ_PATH_REGEX
key_id = '/%s/keys/%s' % [user_path, @fingerprint]
a... | ruby | {
"resource": ""
} |
q23049 | RubyManta.MantaClient.get_job_state_streams | train | def get_job_state_streams(type, path, opts)
raise ArgumentError unless [:in, :out, :fail].include? type
url = job_url(path, '/live/' + type.to_s)
headers = gen_headers(opts)
attempt(opts[:attempts]) do
#method = opts[:head] ? :head : :get
method = :get # until added to Mant... | ruby | {
"resource": ""
} |
q23050 | RubyManta.MantaClient.job_url | train | def job_url(*args)
path = if args.size == 0
@job_base
else
raise ArgumentError unless args.first =~ JOB_PATH_REGEX
args.join('/')
end
URI.encode(@host + path)
end | ruby | {
"resource": ""
} |
q23051 | RubyManta.MantaClient.gen_headers | train | def gen_headers(opts)
now = Time.now.httpdate
sig = gen_signature('date: ' + now)
headers = [[ 'Date', now ],
[ 'Authorization', sig ],
[ 'User-Agent', HTTP_AGENT ],
[ 'Accept-Version', '~1.0' ]]
# headers fo... | ruby | {
"resource": ""
} |
q23052 | RubyManta.MantaClient.gen_cors_headers | train | def gen_cors_headers(opts)
headers = []
allow_credentials = opts[:access_control_allow_credentials]
if allow_credentials
allow_credentials = allow_credentials.to_s
raise ArgumentError unless allow_credentials == 'true' ||
allow_credentials == 'false'... | ruby | {
"resource": ""
} |
q23053 | RubyManta.MantaClient.gen_signature | train | def gen_signature(data)
raise ArgumentError unless data
sig = @priv_key.sign(@digest, data)
base64sig = Base64.strict_encode64(sig)
return HTTP_SIGNATURE % [user_path, @fingerprint, @digest_name, base64sig]
end | ruby | {
"resource": ""
} |
q23054 | Phcscriptcdn.Script::AuthorsController.show | train | def show
@script_authors = Script::Author.friendly.find(params[:id])
@versions = Phcscriptcdn::AuthorVersions.where(item_id: params[:id], item_type: 'Phcscriptcdn::Script::Author')
end | ruby | {
"resource": ""
} |
q23055 | Phcscriptcdn.Script::AuthorsController.new | train | def new
@script_author = Script::Author.new
@script_author.user_id = current_user.id
@script_author.org_id = current_user.org_id
end | ruby | {
"resource": ""
} |
q23056 | Phcscriptcdn.Script::AuthorsController.create | train | def create
@script_author = Script::Author.new(script_author_params)
@script_author.user_id = current_user.id
@script_author.org_id = current_user.org_id
if @script_author.save
redirect_to script_authors_url, notice: 'Author was successfully created.'
else
render :new
... | ruby | {
"resource": ""
} |
q23057 | Phcscriptcdn.Script::ExtensionsController.show | train | def show
@script_extensions = Script::Extension.friendly.find(params[:id])
@versions = Phcscriptcdn::ExtensionVersions.where(item_id: params[:id], item_type: 'Phcscriptcdn::Script::Extension')
end | ruby | {
"resource": ""
} |
q23058 | Phcscriptcdn.Script::ExtensionsController.new | train | def new
@script_extension = Script::Extension.new
@script_extension.user_id = current_user.id
@script_extension.org_id = current_user.org_id
end | ruby | {
"resource": ""
} |
q23059 | Phcscriptcdn.Script::ExtensionsController.create | train | def create
@script_extension = Script::Extension.new(script_extension_params)
@script_extension.user_id = current_user.id
@script_extension.org_id = current_user.org_id
if @script_extension.save
redirect_to script_extensions_url, notice: 'Extension was successfully created.'
else... | ruby | {
"resource": ""
} |
q23060 | Phcscriptcdn.Script::LicencesController.show | train | def show
@script_licences = Script::Licence.friendly.find(params[:id])
@versions = Phcscriptcdn::LicenceVersions.where(item_id: params[:id], item_type: 'Phcscriptcdn::Script::Licence')
end | ruby | {
"resource": ""
} |
q23061 | Phcscriptcdn.Script::LicencesController.new | train | def new
@script_licence = Script::Licence.new
@script_licence.user_id = current_user.id
@script_licence.org_id = current_user.org_id
end | ruby | {
"resource": ""
} |
q23062 | Phcscriptcdn.Script::LicencesController.create | train | def create
@script_licence = Script::Licence.new(script_licence_params)
@script_licence.user_id = current_user.id
@script_licence.org_id = current_user.org_id
if @script_licence.save
redirect_to script_licences_url, notice: 'Licence was successfully created.'
else
render ... | ruby | {
"resource": ""
} |
q23063 | HydraAttribute.HydraValue.save | train | def save
raise EntityModelIsNotPersistedError unless entity.persisted?
if persisted?
return false unless changed?
update
else
create
end
@previously_changed = changes
@changed_attributes.clear
true
end | ruby | {
"resource": ""
} |
q23064 | HydraAttribute.HydraValue.arel_insert | train | def arel_insert
table = self.class.arel_tables[entity.class.table_name][hydra_attribute.backend_type]
fields = {}
fields[table[:entity_id]] = entity.id
fields[table[:hydra_attribute_id]] = hydra_attribute.id
fields[table[:value]] = value
fields[tabl... | ruby | {
"resource": ""
} |
q23065 | HydraAttribute.HydraValue.arel_update | train | def arel_update
table = self.class.arel_tables[entity.class.table_name][hydra_attribute.backend_type]
arel = table.from(table)
arel.where(table[:id].eq(id)).compile_update(table[:value] => value, table[:updated_at] => Time.now)
end | ruby | {
"resource": ""
} |
q23066 | ActsAsIndexed.SearchIndex.add_records | train | def add_records(records)
atoms = ActiveSupport::OrderedHash.new
records_count = 0
records.each do |record|
next unless allow_indexing?(record)
records_count += 1
condensed_record = condense_record(record)
atoms = add_occurences(condensed_record, record.id, atoms)
... | ruby | {
"resource": ""
} |
q23067 | ActsAsIndexed.SearchIndex.remove_record | train | def remove_record(record)
condensed_record = condense_record(record)
atoms = add_occurences(condensed_record,record.id)
@storage.remove(atoms)
end | ruby | {
"resource": ""
} |
q23068 | ActsAsIndexed.SearchIndex.search | train | def search(query)
return [] if query.nil?
@atoms = @storage.fetch(cleanup_atoms(query), query[/\^/])
queries = parse_query(query.dup)
positive = run_queries(queries[:positive])
positive_quoted = run_quoted_queries(queries[:positive_quoted])
negative = run_queries(queries[:negative])... | ruby | {
"resource": ""
} |
q23069 | ActsAsIndexed.SearchIndex.record_unchanged? | train | def record_unchanged?(record_new, record_old)
# NOTE: Using the dirty state would be great here, but it doesn't keep track of
# in-place changes.
allow_indexing?(record_old) == allow_indexing?(record_new) &&
!@fields.map { |field| record_old.send(field) == record_new.send(field) }.include?(fa... | ruby | {
"resource": ""
} |
q23070 | Vmstat.ProcFS.memory | train | def memory
@pagesize ||= Vmstat.pagesize
has_available = false
total = free = active = inactive = pageins = pageouts = available = 0
procfs_file("meminfo") do |file|
content = file.read(2048) # the requested information is in the first bytes
content.scan(/(\w+):\s+(\d+) kB/) do... | ruby | {
"resource": ""
} |
q23071 | Vmstat.ProcFS.network_interfaces | train | def network_interfaces
netifcs = []
procfs_file("net", "dev") do |file|
file.read.scan(NET_DATA) do |columns|
type = case columns[0]
when /^eth/ then NetworkInterface::ETHERNET_TYPE
when /^lo/ then NetworkInterface::LOOPBACK_TYPE
end
netifcs <<... | ruby | {
"resource": ""
} |
q23072 | Vmstat.ProcFS.task | train | def task
@pagesize ||= Vmstat.pagesize
procfs_file("self", "stat") do |file|
data = file.read.split(/ /)
Task.new(data[22].to_i / @pagesize, data[23].to_i,
data[13].to_i * 1000, data[14].to_i * 1000)
end
end | ruby | {
"resource": ""
} |
q23073 | Vmstat.ProcFS.boot_time | train | def boot_time
raw = procfs_file("uptime") { |file| file.read }
Time.now - raw.split(/\s/).first.to_f
end | ruby | {
"resource": ""
} |
q23074 | Vmstat.ProcFS.procfs_file | train | def procfs_file(*names, &block)
path = File.join(procfs_path, *names)
File.open(path, "r", &block)
end | ruby | {
"resource": ""
} |
q23075 | ActsAsIndexed.SearchAtom.+ | train | def +(other)
SearchAtom.new(@records.clone.merge!(other.records) { |key, _old, _new|
_old + _new
})
end | ruby | {
"resource": ""
} |
q23076 | ActsAsIndexed.SearchAtom.- | train | def -(other)
records = @records.clone.reject { |name, records| other.records.include?(name) }
SearchAtom.new(records)
end | ruby | {
"resource": ""
} |
q23077 | ActsAsIndexed.SearchAtom.preceded_by | train | def preceded_by(former)
matches = SearchAtom.new
latter = ActiveSupport::OrderedHash.new
former.record_ids.each do |rid|
latter[rid] = @records[rid] if @records[rid]
end
# Iterate over each record in latter.
latter.each do |record_id,pos|
# Iterate over each position... | ruby | {
"resource": ""
} |
q23078 | ActsAsIndexed.SearchAtom.weightings | train | def weightings(records_size)
out = ActiveSupport::OrderedHash.new
## phurni 2012-09-21 when records_size is exactly the @records.size (all records are matches), the Math.log would
## return 0 which means the frequency (pos.size) will have no effect. Cheat to make it like the matching
## record ... | ruby | {
"resource": ""
} |
q23079 | Alexa.Response.elicit_slot! | train | def elicit_slot!(slot_to_elicit, skip_render: false)
directives << {
type: "Dialog.ElicitSlot",
slotToElicit: slot_to_elicit
}
if skip_render
@slots_to_not_render_elicitation << slot_to_elicit
end
end | ruby | {
"resource": ""
} |
q23080 | ActsAsIndexed.Storage.fetch | train | def fetch(atom_names, start=false)
atoms = ActiveSupport::OrderedHash.new
atom_names.uniq.collect{|a| encoded_prefix(a) }.uniq.each do |prefix|
pattern = @path.join(prefix.to_s).to_s
pattern += '*' if start
pattern += INDEX_FILE_EXTENSION
Pathname.glob(pattern).each do |ato... | ruby | {
"resource": ""
} |
q23081 | ActsAsIndexed.Storage.operate | train | def operate(operation, atoms)
# ActiveSupport always available?
atoms_sorted = ActiveSupport::OrderedHash.new
# Sort the atoms into the appropriate shards for writing to individual
# files.
atoms.each do |atom_name, records|
(atoms_sorted[encoded_prefix(atom_name)] ||= ActiveSuppo... | ruby | {
"resource": ""
} |
q23082 | ActsAsIndexed.Storage.lock_file | train | def lock_file(file_path, &block) # :nodoc:
@@file_lock.synchronize do
# Windows does not support file locking.
if !windows? && file_path.exist?
file_path.open('r+') do |f|
begin
f.flock File::LOCK_EX
yield
ensure
f.flock ... | ruby | {
"resource": ""
} |
q23083 | Alexa.Device.location | train | def location
@_location ||= begin
if Alexa.configuration.location_permission_type == :full_address
get_address
elsif Alexa.configuration.location_permission_type == :country_and_postal_code
get_address(only: :country_and_postal_code)
end
end
end | ruby | {
"resource": ""
} |
q23084 | SimplifyRb.DouglasPeuckerSimplifier.get_sq_seg_dist | train | def get_sq_seg_dist(point, point_1, point_2)
x = point_1.x
y = point_1.y
dx = point_2.x - x
dy = point_2.y - y
if dx != 0 || dy != 0
t = ((point.x - x) * dx + (point.y - y) * dy) / (dx * dx + dy * dy)
if t > 1
x = point_2.x
y = point_2.y
els... | ruby | {
"resource": ""
} |
q23085 | ActsAsIndexed.ClassMethods.acts_as_indexed | train | def acts_as_indexed(options = {})
class_eval do
extend ActsAsIndexed::SingletonMethods
end
include ActsAsIndexed::InstanceMethods
after_create :add_to_index
before_update :update_index
after_destroy :remove_from_index
# scope for Rails 3.x, named_scope for Rails 2.x.... | ruby | {
"resource": ""
} |
q23086 | ActsAsIndexed.ClassMethods.index_add | train | def index_add(record)
return if self.aai_config.disable_auto_indexing
build_index
index = new_index
index.add_record(record)
@query_cache = {}
end | ruby | {
"resource": ""
} |
q23087 | ActsAsIndexed.ClassMethods.index_update | train | def index_update(record)
return if self.aai_config.disable_auto_indexing
build_index
index = new_index
index.update_record(record,find(record.id))
@query_cache = {}
end | ruby | {
"resource": ""
} |
q23088 | ActsAsIndexed.ClassMethods.search_index | train | def search_index(query, find_options={}, options={})
# Clear the query cache off if the key is set.
@query_cache = {} if options[:no_query_cache]
# Run the query if not already in cache.
if !@query_cache || !@query_cache[query]
build_index
(@query_cache ||= {})[query] = new_i... | ruby | {
"resource": ""
} |
q23089 | ActsAsIndexed.ClassMethods.build_index | train | def build_index
return if aai_config.index_file.directory?
index = new_index
find_in_batches({ :batch_size => 500 }) do |records|
index.add_records(records)
end
end | ruby | {
"resource": ""
} |
q23090 | ActsAsIndexed.ClassMethods.sort | train | def sort(ranked_records)
ranked_records.sort { |a, b|
a_score = a.last
a_id = a.first.is_a?(Fixnum) ? a.first : a.first.id
b_score = b.last
b_id = b.first.is_a?(Fixnum) ? b.first : b.first.id
if a_score == b_score
a_id <=> b_id
else
b_score <=>... | ruby | {
"resource": ""
} |
q23091 | MongodbLogger.Base.mongo_fix_session_keys | train | def mongo_fix_session_keys(session = {})
new_session = Hash.new
session.to_hash.each do |i, j|
new_session[i.gsub(/\./i, "|")] = j.inspect
end unless session.empty?
new_session
end | ruby | {
"resource": ""
} |
q23092 | Panoramic.Resolver.find_templates | train | def find_templates(name, prefix, partial, details, key=nil, locals=[])
return [] if @@resolver_options[:only] && !@@resolver_options[:only].include?(prefix)
path = build_path(name, prefix)
conditions = {
:path => path,
:locale => [normalize_array(details[:locale]).first, nil],
... | ruby | {
"resource": ""
} |
q23093 | Panoramic.Resolver.virtual_path | train | def virtual_path(path, partial)
return path unless partial
if index = path.rindex("/")
path.insert(index + 1, "_")
else
"_#{path}"
end
end | ruby | {
"resource": ""
} |
q23094 | Slack.Poster.send_message | train | def send_message(message)
body = message.is_a?(String) ? options.merge(text: message) : options.merge(message.as_json)
conn = Faraday.new(url: @base_uri)
response = conn.post('', payload: body.to_json)
response
end | ruby | {
"resource": ""
} |
q23095 | MongodbLogger.Logger.record_serializer | train | def record_serializer(rec, nice = true)
[:messages, :params].each do |key|
if msgs = rec[key]
msgs.each do |i, j|
msgs[i] = (true == nice ? nice_serialize_object(j) : j.inspect)
end
end
end
end | ruby | {
"resource": ""
} |
q23096 | MongodbLogger.ReplicaSetHelper.rescue_connection_failure | train | def rescue_connection_failure(max_retries = 40)
success = false
retries = 0
while !success
begin
yield
success = true
rescue mongo_error_type => e
raise e if (retries += 1) >= max_retries
sleep 0.25
end
end
end | ruby | {
"resource": ""
} |
q23097 | POI.Cell.error_value | train | def error_value
if poi_cell.cell_type == CELL_TYPE_ERROR
error_value_from(poi_cell.error_cell_value)
elsif poi_cell.cell_type == CELL_TYPE_FORMULA &&
poi_cell.cached_formula_result_type == CELL_TYPE_ERROR
cell_value = formula_evaluator.evaluate(poi_cell)
cel... | ruby | {
"resource": ""
} |
q23098 | POI.Cell.to_s | train | def to_s(evaluate_formulas=true)
return '' if poi_cell.nil?
if poi_cell.cell_type == CELL_TYPE_FORMULA && evaluate_formulas == false
formula_value
else
value.to_s
end
end | ruby | {
"resource": ""
} |
q23099 | Dare.Window.add_mouse_event_listener | train | def add_mouse_event_listener
Element.find("##{@canvas.id}").on :mousemove do |event|
coords = get_cursor_position(event)
@mouse_x = coords.x[:x]
@mouse_y = coords.x[:y]
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.