_id stringlengths 2 6 | title stringlengths 9 130 | partition stringclasses 3
values | text stringlengths 66 10.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q12800 | Magick.Image.texture_floodfill | train | def texture_floodfill(x, y, texture)
target = pixel_color(x, y)
texture_flood_fill(target, texture, x, y, FloodfillMethod)
end | ruby | {
"resource": ""
} |
q12801 | Magick.Image.texture_fill_to_border | train | def texture_fill_to_border(x, y, texture)
texture_flood_fill(border_color, texture, x, y, FillToBorderMethod)
end | ruby | {
"resource": ""
} |
q12802 | Magick.Image.view | train | def view(x, y, width, height)
view = View.new(self, x, y, width, height)
return view unless block_given?
begin
yield(view)
ensure
view.sync
end
nil
end | ruby | {
"resource": ""
} |
q12803 | Magick.ImageList.set_current | train | def set_current(current)
if length.zero?
self.scene = nil
return
# Don't bother looking for current image
elsif scene.nil? || scene >= length
self.scene = length - 1
return
elsif !current.nil?
# Find last instance of "current" in the list.
# If "cu... | ruby | {
"resource": ""
} |
q12804 | Magick.ImageList.scene= | train | def scene=(n)
if n.nil?
Kernel.raise IndexError, 'scene number out of bounds' unless @images.length.zero?
@scene = nil
return @scene
elsif @images.length.zero?
Kernel.raise IndexError, 'scene number out of bounds'
end
n = Integer(n)
Kernel.raise IndexError,... | ruby | {
"resource": ""
} |
q12805 | Magick.ImageList.copy | train | def copy
ditto = self.class.new
@images.each { |f| ditto << f.copy }
ditto.scene = @scene
ditto.taint if tainted?
ditto
end | ruby | {
"resource": ""
} |
q12806 | Magick.ImageList.delay= | train | def delay=(d)
raise ArgumentError, 'delay must be greater than or equal to 0' if Integer(d) < 0
@images.each { |f| f.delay = Integer(d) }
end | ruby | {
"resource": ""
} |
q12807 | Magick.ImageList.insert | train | def insert(index, *args)
args.each { |image| is_an_image image }
current = get_current
@images.insert(index, *args)
set_current current
self
end | ruby | {
"resource": ""
} |
q12808 | Magick.ImageList.inspect | train | def inspect
img = []
@images.each { |image| img << image.inspect }
img = '[' + img.join(",\n") + "]\nscene=#{@scene}"
end | ruby | {
"resource": ""
} |
q12809 | Magick.ImageList.iterations= | train | def iterations=(n)
n = Integer(n)
Kernel.raise ArgumentError, 'iterations must be between 0 and 65535' if n < 0 || n > 65_535
@images.each { |f| f.iterations = n }
self
end | ruby | {
"resource": ""
} |
q12810 | Magick.ImageList.new_image | train | def new_image(cols, rows, *fill, &info_blk)
self << Magick::Image.new(cols, rows, *fill, &info_blk)
end | ruby | {
"resource": ""
} |
q12811 | Magick.ImageList.read | train | def read(*files, &block)
Kernel.raise ArgumentError, 'no files given' if files.length.zero?
files.each do |f|
Magick::Image.read(f, &block).each { |n| @images << n }
end
@scene = length - 1
self
end | ruby | {
"resource": ""
} |
q12812 | Magick.ImageList.reject | train | def reject(&block)
current = get_current
ilist = self.class.new
a = @images.reject(&block)
a.each { |image| ilist << image }
ilist.set_current current
ilist
end | ruby | {
"resource": ""
} |
q12813 | Magick.Image.alpha_hist | train | def alpha_hist(freqs, scale, fg, bg)
histogram = Image.new(HISTOGRAM_COLS, HISTOGRAM_ROWS) do
self.background_color = bg
self.border_color = fg
end
gc = Draw.new
gc.affine(1, 0, 0, -scale, 0, HISTOGRAM_ROWS)
gc.fill('white')
HISTOGRAM_COLS.times do |x|
gc.po... | ruby | {
"resource": ""
} |
q12814 | Magick.Image.color_hist | train | def color_hist(fg, bg)
img = number_colors > 256 ? quantize(256) : self
begin
hist = img.color_histogram
rescue NotImplementedError
warn 'The color_histogram method is not supported by this version '\
'of ImageMagick/GraphicsMagick'
else
pixels = his... | ruby | {
"resource": ""
} |
q12815 | Magick.Image.pixel_intensity | train | def pixel_intensity(pixel)
(306 * (pixel.red & MAX_QUANTUM) + 601 * (pixel.green & MAX_QUANTUM) + 117 * (pixel.blue & MAX_QUANTUM)) / 1024
end | ruby | {
"resource": ""
} |
q12816 | Magick.Image.histogram | train | def histogram(fg = 'white', bg = 'black')
red = Array.new(HISTOGRAM_COLS, 0)
green = Array.new(HISTOGRAM_COLS, 0)
blue = Array.new(HISTOGRAM_COLS, 0)
alpha = Array.new(HISTOGRAM_COLS, 0)
int = Array.new(HISTOGRAM_COLS, 0)
rows.times do |row|
pixels = get_pixels(0, row, ... | ruby | {
"resource": ""
} |
q12817 | Dalli.Client.get_cas | train | def get_cas(key)
(value, cas) = perform(:cas, key)
value = (!value || value == 'Not found') ? nil : value
if block_given?
yield value, cas
else
[value, cas]
end
end | ruby | {
"resource": ""
} |
q12818 | Dalli.Client.set_cas | train | def set_cas(key, value, cas, ttl=nil, options=nil)
ttl ||= @options[:expires_in].to_i
perform(:set, key, value, ttl, cas, options)
end | ruby | {
"resource": ""
} |
q12819 | Dalli.Client.fetch | train | def fetch(key, ttl=nil, options=nil)
options = options.nil? ? CACHE_NILS : options.merge(CACHE_NILS) if @options[:cache_nils]
val = get(key, options)
not_found = @options[:cache_nils] ?
val == Dalli::Server::NOT_FOUND :
val.nil?
if not_found && block_given?
val = yield
... | ruby | {
"resource": ""
} |
q12820 | Dalli.Client.cas | train | def cas(key, ttl=nil, options=nil, &block)
cas_core(key, false, ttl, options, &block)
end | ruby | {
"resource": ""
} |
q12821 | Dalli.Client.incr | train | def incr(key, amt=1, ttl=nil, default=nil)
raise ArgumentError, "Positive values only: #{amt}" if amt < 0
perform(:incr, key, amt.to_i, ttl_or_default(ttl), default)
end | ruby | {
"resource": ""
} |
q12822 | Dalli.Client.touch | train | def touch(key, ttl=nil)
resp = perform(:touch, key, ttl_or_default(ttl))
resp.nil? ? nil : true
end | ruby | {
"resource": ""
} |
q12823 | Dalli.Client.version | train | def version
values = {}
ring.servers.each do |server|
values["#{server.name}"] = server.alive? ? server.request(:version) : nil
end
values
end | ruby | {
"resource": ""
} |
q12824 | Dalli.Client.get_multi_yielder | train | def get_multi_yielder(keys)
perform do
return {} if keys.empty?
ring.lock do
begin
groups = groups_for_keys(keys)
if unfound_keys = groups.delete(nil)
Dalli.logger.debug { "unable to get keys for #{unfound_keys.length} keys because no matching server... | ruby | {
"resource": ""
} |
q12825 | Kubeclient.ClientMixin.delete_entity | train | def delete_entity(resource_name, name, namespace = nil, delete_options: {})
delete_options_hash = delete_options.to_hash
ns_prefix = build_namespace_prefix(namespace)
payload = delete_options_hash.to_json unless delete_options_hash.empty?
response = handle_exception do
rs = rest_client[n... | ruby | {
"resource": ""
} |
q12826 | Kubeclient.ClientMixin.format_datetime | train | def format_datetime(value)
case value
when DateTime, Time
value.strftime('%FT%T.%9N%:z')
when String
value
else
raise ArgumentError, "unsupported type '#{value.class}' of time value '#{value}'"
end
end | ruby | {
"resource": ""
} |
q12827 | Addressable.Template.extract | train | def extract(uri, processor=nil)
match_data = self.match(uri, processor)
return (match_data ? match_data.mapping : nil)
end | ruby | {
"resource": ""
} |
q12828 | Addressable.Template.match | train | def match(uri, processor=nil)
uri = Addressable::URI.parse(uri)
mapping = {}
# First, we need to process the pattern, and extract the values.
expansions, expansion_regexp =
parse_template_pattern(pattern, processor)
return nil unless uri.to_str.match(expansion_regexp)
unpar... | ruby | {
"resource": ""
} |
q12829 | Addressable.Template.partial_expand | train | def partial_expand(mapping, processor=nil, normalize_values=true)
result = self.pattern.dup
mapping = normalize_keys(mapping)
result.gsub!( EXPRESSION ) do |capture|
transform_partial_capture(mapping, capture, processor, normalize_values)
end
return Addressable::Template.new(result... | ruby | {
"resource": ""
} |
q12830 | Addressable.Template.expand | train | def expand(mapping, processor=nil, normalize_values=true)
result = self.pattern.dup
mapping = normalize_keys(mapping)
result.gsub!( EXPRESSION ) do |capture|
transform_capture(mapping, capture, processor, normalize_values)
end
return Addressable::URI.parse(result)
end | ruby | {
"resource": ""
} |
q12831 | Addressable.Template.generate | train | def generate(params={}, recall={}, options={})
merged = recall.merge(params)
if options[:processor]
processor = options[:processor]
elsif options[:parameterize]
# TODO: This is sending me into fits trying to shoe-horn this into
# the existing API. I think I've got this backward... | ruby | {
"resource": ""
} |
q12832 | Addressable.Template.transform_partial_capture | train | def transform_partial_capture(mapping, capture, processor = nil,
normalize_values = true)
_, operator, varlist = *capture.match(EXPRESSION)
vars = varlist.split(",")
if operator == "?"
# partial expansion of form style query variables sometimes requires a
... | ruby | {
"resource": ""
} |
q12833 | Addressable.Template.normalize_keys | train | def normalize_keys(mapping)
return mapping.inject({}) do |accu, pair|
name, value = pair
if Symbol === name
name = name.to_s
elsif name.respond_to?(:to_str)
name = name.to_str
else
raise TypeError,
"Can't convert #{name.class} into String."... | ruby | {
"resource": ""
} |
q12834 | Addressable.URI.freeze | train | def freeze
self.normalized_scheme
self.normalized_user
self.normalized_password
self.normalized_userinfo
self.normalized_host
self.normalized_port
self.normalized_authority
self.normalized_site
self.normalized_path
self.normalized_query
self.normalized_f... | ruby | {
"resource": ""
} |
q12835 | Addressable.URI.normalized_scheme | train | def normalized_scheme
return nil unless self.scheme
@normalized_scheme ||= begin
if self.scheme =~ /^\s*ssh\+svn\s*$/i
"svn+ssh".dup
else
Addressable::URI.normalize_component(
self.scheme.strip.downcase,
Addressable::URI::CharacterClasses::SCHEME
... | ruby | {
"resource": ""
} |
q12836 | Addressable.URI.scheme= | train | def scheme=(new_scheme)
if new_scheme && !new_scheme.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_scheme.class} into String."
elsif new_scheme
new_scheme = new_scheme.to_str
end
if new_scheme && new_scheme !~ /\A[a-z][a-z0-9\.\+\-]*\z/i
raise InvalidURIError... | ruby | {
"resource": ""
} |
q12837 | Addressable.URI.user= | train | def user=(new_user)
if new_user && !new_user.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_user.class} into String."
end
@user = new_user ? new_user.to_str : nil
# You can't have a nil user with a non-nil password
if password != nil
@user = EMPTY_STR if @user.... | ruby | {
"resource": ""
} |
q12838 | Addressable.URI.normalized_password | train | def normalized_password
return nil unless self.password
return @normalized_password if defined?(@normalized_password)
@normalized_password ||= begin
if self.normalized_scheme =~ /https?/ && self.password.strip.empty? &&
(!self.user || self.user.strip.empty?)
nil
e... | ruby | {
"resource": ""
} |
q12839 | Addressable.URI.password= | train | def password=(new_password)
if new_password && !new_password.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_password.class} into String."
end
@password = new_password ? new_password.to_str : nil
# You can't have a nil user with a non-nil password
@password ||= nil
... | ruby | {
"resource": ""
} |
q12840 | Addressable.URI.userinfo | train | def userinfo
current_user = self.user
current_password = self.password
(current_user || current_password) && @userinfo ||= begin
if current_user && current_password
"#{current_user}:#{current_password}"
elsif current_user && !current_password
"#{current_user}"
... | ruby | {
"resource": ""
} |
q12841 | Addressable.URI.normalized_userinfo | train | def normalized_userinfo
return nil unless self.userinfo
return @normalized_userinfo if defined?(@normalized_userinfo)
@normalized_userinfo ||= begin
current_user = self.normalized_user
current_password = self.normalized_password
if !current_user && !current_password
n... | ruby | {
"resource": ""
} |
q12842 | Addressable.URI.userinfo= | train | def userinfo=(new_userinfo)
if new_userinfo && !new_userinfo.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_userinfo.class} into String."
end
new_user, new_password = if new_userinfo
[
new_userinfo.to_str.strip[/^(.*):/, 1],
new_userinfo.to_str.strip[/:(... | ruby | {
"resource": ""
} |
q12843 | Addressable.URI.normalized_host | train | def normalized_host
return nil unless self.host
@normalized_host ||= begin
if !self.host.strip.empty?
result = ::Addressable::IDNA.to_ascii(
URI.unencode_component(self.host.strip.downcase)
)
if result =~ /[^\.]\.$/
# Single trailing dots are unn... | ruby | {
"resource": ""
} |
q12844 | Addressable.URI.host= | train | def host=(new_host)
if new_host && !new_host.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_host.class} into String."
end
@host = new_host ? new_host.to_str : nil
# Reset dependent values
remove_instance_variable(:@authority) if defined?(@authority)
remove_instan... | ruby | {
"resource": ""
} |
q12845 | Addressable.URI.authority | train | def authority
self.host && @authority ||= begin
authority = String.new
if self.userinfo != nil
authority << "#{self.userinfo}@"
end
authority << self.host
if self.port != nil
authority << ":#{self.port}"
end
authority
end
end | ruby | {
"resource": ""
} |
q12846 | Addressable.URI.normalized_authority | train | def normalized_authority
return nil unless self.authority
@normalized_authority ||= begin
authority = String.new
if self.normalized_userinfo != nil
authority << "#{self.normalized_userinfo}@"
end
authority << self.normalized_host
if self.normalized_port != n... | ruby | {
"resource": ""
} |
q12847 | Addressable.URI.authority= | train | def authority=(new_authority)
if new_authority
if !new_authority.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_authority.class} into String."
end
new_authority = new_authority.to_str
new_userinfo = new_authority[/^([^\[\]]*)@/, 1]
if new_userinfo
... | ruby | {
"resource": ""
} |
q12848 | Addressable.URI.origin= | train | def origin=(new_origin)
if new_origin
if !new_origin.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_origin.class} into String."
end
new_origin = new_origin.to_str
new_scheme = new_origin[/^([^:\/?#]+):\/\//, 1]
unless new_scheme
raise Invalid... | ruby | {
"resource": ""
} |
q12849 | Addressable.URI.port= | train | def port=(new_port)
if new_port != nil && new_port.respond_to?(:to_str)
new_port = Addressable::URI.unencode_component(new_port.to_str)
end
if new_port.respond_to?(:valid_encoding?) && !new_port.valid_encoding?
raise InvalidURIError, "Invalid encoding in port"
end
if new_... | ruby | {
"resource": ""
} |
q12850 | Addressable.URI.site | train | def site
(self.scheme || self.authority) && @site ||= begin
site_string = "".dup
site_string << "#{self.scheme}:" if self.scheme != nil
site_string << "//#{self.authority}" if self.authority != nil
site_string
end
end | ruby | {
"resource": ""
} |
q12851 | Addressable.URI.normalized_site | train | def normalized_site
return nil unless self.site
@normalized_site ||= begin
site_string = "".dup
if self.normalized_scheme != nil
site_string << "#{self.normalized_scheme}:"
end
if self.normalized_authority != nil
site_string << "//#{self.normalized_authori... | ruby | {
"resource": ""
} |
q12852 | Addressable.URI.site= | train | def site=(new_site)
if new_site
if !new_site.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_site.class} into String."
end
new_site = new_site.to_str
# These two regular expressions derived from the primary parsing
# expression
self.scheme = new... | ruby | {
"resource": ""
} |
q12853 | Addressable.URI.normalized_path | train | def normalized_path
@normalized_path ||= begin
path = self.path.to_s
if self.scheme == nil && path =~ NORMPATH
# Relative paths with colons in the first segment are ambiguous.
path = path.sub(":", "%2F")
end
# String#split(delimeter, -1) uses the more strict spl... | ruby | {
"resource": ""
} |
q12854 | Addressable.URI.path= | train | def path=(new_path)
if new_path && !new_path.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_path.class} into String."
end
@path = (new_path || EMPTY_STR).to_str
if !@path.empty? && @path[0..0] != SLASH && host != nil
@path = "/#{@path}"
end
# Reset depend... | ruby | {
"resource": ""
} |
q12855 | Addressable.URI.normalized_query | train | def normalized_query(*flags)
return nil unless self.query
return @normalized_query if defined?(@normalized_query)
@normalized_query ||= begin
modified_query_class = Addressable::URI::CharacterClasses::QUERY.dup
# Make sure possible key-value pair delimiters are escaped.
modifie... | ruby | {
"resource": ""
} |
q12856 | Addressable.URI.query= | train | def query=(new_query)
if new_query && !new_query.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_query.class} into String."
end
@query = new_query ? new_query.to_str : nil
# Reset dependent values
remove_instance_variable(:@normalized_query) if defined?(@normalized_quer... | ruby | {
"resource": ""
} |
q12857 | Addressable.URI.query_values | train | def query_values(return_type=Hash)
empty_accumulator = Array == return_type ? [] : {}
if return_type != Hash && return_type != Array
raise ArgumentError, "Invalid return type. Must be Hash or Array."
end
return nil if self.query == nil
split_query = self.query.split("&").map do |pa... | ruby | {
"resource": ""
} |
q12858 | Addressable.URI.query_values= | train | def query_values=(new_query_values)
if new_query_values == nil
self.query = nil
return nil
end
if !new_query_values.is_a?(Array)
if !new_query_values.respond_to?(:to_hash)
raise TypeError,
"Can't convert #{new_query_values.class} into Hash."
end
... | ruby | {
"resource": ""
} |
q12859 | Addressable.URI.request_uri= | train | def request_uri=(new_request_uri)
if !new_request_uri.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_request_uri.class} into String."
end
if self.absolute? && self.scheme !~ /^https?$/i
raise InvalidURIError,
"Cannot set an HTTP request URI for a non-HTTP URI."
... | ruby | {
"resource": ""
} |
q12860 | Addressable.URI.normalized_fragment | train | def normalized_fragment
return nil unless self.fragment
return @normalized_fragment if defined?(@normalized_fragment)
@normalized_fragment ||= begin
component = Addressable::URI.normalize_component(
self.fragment,
Addressable::URI::CharacterClasses::FRAGMENT
)
... | ruby | {
"resource": ""
} |
q12861 | Addressable.URI.fragment= | train | def fragment=(new_fragment)
if new_fragment && !new_fragment.respond_to?(:to_str)
raise TypeError, "Can't convert #{new_fragment.class} into String."
end
@fragment = new_fragment ? new_fragment.to_str : nil
# Reset dependent values
remove_instance_variable(:@normalized_fragment) i... | ruby | {
"resource": ""
} |
q12862 | Addressable.URI.join | train | def join(uri)
if !uri.respond_to?(:to_str)
raise TypeError, "Can't convert #{uri.class} into String."
end
if !uri.kind_of?(URI)
# Otherwise, convert to a String, then parse.
uri = URI.parse(uri.to_str)
end
if uri.to_s.empty?
return self.dup
end
... | ruby | {
"resource": ""
} |
q12863 | Addressable.URI.normalize | train | def normalize
# This is a special exception for the frequently misused feed
# URI scheme.
if normalized_scheme == "feed"
if self.to_s =~ /^feed:\/*http:\/*/
return URI.parse(
self.to_s[/^feed:\/*(http:\/*.*)/, 1]
).normalize
end
end
return s... | ruby | {
"resource": ""
} |
q12864 | Addressable.URI.defer_validation | train | def defer_validation(&block)
raise LocalJumpError, "No block given." unless block
@validation_deferred = true
block.call()
@validation_deferred = false
validate
return nil
end | ruby | {
"resource": ""
} |
q12865 | Addressable.URI.validate | train | def validate
return if !!@validation_deferred
if self.scheme != nil && self.ip_based? &&
(self.host == nil || self.host.empty?) &&
(self.path == nil || self.path.empty?)
raise InvalidURIError,
"Absolute URI missing hierarchical segment: '#{self.to_s}'"
end
i... | ruby | {
"resource": ""
} |
q12866 | Addressable.URI.replace_self | train | def replace_self(uri)
# Reset dependent values
instance_variables.each do |var|
if instance_variable_defined?(var) && var != :@validation_deferred
remove_instance_variable(var)
end
end
@scheme = uri.scheme
@user = uri.user
@password = uri.password
@ho... | ruby | {
"resource": ""
} |
q12867 | Dynamoid.Fields.write_attribute | train | def write_attribute(name, value)
name = name.to_sym
if association = @associations[name]
association.reset
end
@attributes_before_type_cast[name] = value
value_casted = TypeCasting.cast_field(value, self.class.attributes[name])
attributes[name] = value_casted
end | ruby | {
"resource": ""
} |
q12868 | Dynamoid.Fields.set_created_at | train | def set_created_at
self.created_at ||= DateTime.now.in_time_zone(Time.zone) if Dynamoid::Config.timestamps
end | ruby | {
"resource": ""
} |
q12869 | Dynamoid.Fields.set_updated_at | train | def set_updated_at
if Dynamoid::Config.timestamps && !updated_at_changed?
self.updated_at = DateTime.now.in_time_zone(Time.zone)
end
end | ruby | {
"resource": ""
} |
q12870 | Dynamoid.Document.reload | train | def reload
options = { consistent_read: true }
if self.class.range_key
options[:range_key] = range_value
end
self.attributes = self.class.find(hash_key, options).attributes
@associations.values.each(&:reset)
self
end | ruby | {
"resource": ""
} |
q12871 | Dynamoid.Document.evaluate_default_value | train | def evaluate_default_value(val)
if val.respond_to?(:call)
val.call
elsif val.duplicable?
val.dup
else
val
end
end | ruby | {
"resource": ""
} |
q12872 | Dynamoid.Persistence.touch | train | def touch(name = nil)
now = DateTime.now
self.updated_at = now
attributes[name] = now if name
save
end | ruby | {
"resource": ""
} |
q12873 | Dynamoid.Persistence.save | train | def save(_options = {})
self.class.create_table
if new_record?
conditions = { unless_exists: [self.class.hash_key] }
conditions[:unless_exists] << range_key if range_key
run_callbacks(:create) { persist(conditions) }
else
persist
end
end | ruby | {
"resource": ""
} |
q12874 | Dynamoid.Persistence.update_attributes | train | def update_attributes(attributes)
attributes.each { |attribute, value| write_attribute(attribute, value) }
save
end | ruby | {
"resource": ""
} |
q12875 | Dynamoid.Persistence.delete | train | def delete
options = range_key ? { range_key: Dumping.dump_field(read_attribute(range_key), self.class.attributes[range_key]) } : {}
# Add an optimistic locking check if the lock_version column exists
if self.class.attributes[:lock_version]
conditions = { if: {} }
conditions[:if][:loc... | ruby | {
"resource": ""
} |
q12876 | Dynamoid.Persistence.persist | train | def persist(conditions = nil)
run_callbacks(:save) do
self.hash_key = SecureRandom.uuid if hash_key.blank?
# Add an exists check to prevent overwriting existing records with new ones
if new_record?
conditions ||= {}
(conditions[:unless_exists] ||= []) << self.class.has... | ruby | {
"resource": ""
} |
q12877 | Dynamoid.Adapter.adapter | train | def adapter
unless @adapter_.value
adapter = self.class.adapter_plugin_class.new
adapter.connect! if adapter.respond_to?(:connect!)
@adapter_.compare_and_set(nil, adapter)
clear_cache!
end
@adapter_.value
end | ruby | {
"resource": ""
} |
q12878 | Dynamoid.Adapter.benchmark | train | def benchmark(method, *args)
start = Time.now
result = yield
Dynamoid.logger.debug "(#{((Time.now - start) * 1000.0).round(2)} ms) #{method.to_s.split('_').collect(&:upcase).join(' ')}#{" - #{args.inspect}" unless args.nil? || args.empty?}"
result
end | ruby | {
"resource": ""
} |
q12879 | Dynamoid.Adapter.read | train | def read(table, ids, options = {}, &blk)
if ids.respond_to?(:each)
batch_get_item({ table => ids }, options, &blk)
else
get_item(table, ids, options)
end
end | ruby | {
"resource": ""
} |
q12880 | Dynamoid.Adapter.delete | train | def delete(table, ids, options = {})
range_key = options[:range_key] # array of range keys that matches the ids passed in
if ids.respond_to?(:each)
ids = if range_key.respond_to?(:each)
# turn ids into array of arrays each element being hash_key, range_key
ids.each_wi... | ruby | {
"resource": ""
} |
q12881 | Dynamoid.Adapter.scan | train | def scan(table, query = {}, opts = {})
benchmark('Scan', table, query) { adapter.scan(table, query, opts) }
end | ruby | {
"resource": ""
} |
q12882 | Dynamoid.Adapter.method_missing | train | def method_missing(method, *args, &block)
return benchmark(method, *args) { adapter.send(method, *args, &block) } if adapter.respond_to?(method)
super
end | ruby | {
"resource": ""
} |
q12883 | Dynamoid.Config.logger= | train | def logger=(logger)
case logger
when false, nil then @logger = NullLogger.new
when true then @logger = default_logger
else
@logger = logger if logger.respond_to?(:info)
end
end | ruby | {
"resource": ""
} |
q12884 | CombinePDF.Renderer.object_to_pdf | train | def object_to_pdf(object)
if object.nil?
return 'null'
elsif object.is_a?(String)
return format_string_to_pdf object
elsif object.is_a?(Symbol)
return format_name_to_pdf object
elsif object.is_a?(Array)
return format_array_to_pdf object
elsif object.is_a?(In... | ruby | {
"resource": ""
} |
q12885 | CombinePDF.PDF.new_page | train | def new_page(mediabox = [0, 0, 612.0, 792.0], _location = -1)
p = PDFWriter.new(mediabox)
insert(-1, p)
p
end | ruby | {
"resource": ""
} |
q12886 | CombinePDF.PDF.to_pdf | train | def to_pdf(options = {})
# reset version if not specified
@version = 1.5 if @version.to_f == 0.0
# set info for merged file
@info[:ModDate] = @info[:CreationDate] = Time.now.strftime "D:%Y%m%d%H%M%S%:::z'00"
@info[:Subject] = options[:subject] if options[:subject]
@info[:Producer] = ... | ruby | {
"resource": ""
} |
q12887 | CombinePDF.PDF.pages | train | def pages(catalogs = nil)
page_list = []
catalogs ||= get_existing_catalogs
if catalogs.is_a?(Array)
catalogs.each { |c| page_list.concat pages(c) unless c.nil? }
elsif catalogs.is_a?(Hash)
if catalogs[:is_reference_only]
if catalogs[:referenced_object]
pag... | ruby | {
"resource": ""
} |
q12888 | CombinePDF.PDF.fonts | train | def fonts(limit_to_type0 = false)
fonts_array = []
pages.each do |pg|
if pg[:Resources][:Font]
pg[:Resources][:Font].values.each do |f|
f = f[:referenced_object] if f[:referenced_object]
if (limit_to_type0 || f[:Subtype] == :Type0) && f[:Type] == :Font && !fonts_arr... | ruby | {
"resource": ""
} |
q12889 | CombinePDF.PDF.remove | train | def remove(page_index)
catalog = rebuild_catalog
pages_array = catalog[:Pages][:referenced_object][:Kids]
removed_page = pages_array.delete_at page_index
catalog[:Pages][:referenced_object][:Count] = pages_array.length
removed_page
end | ruby | {
"resource": ""
} |
q12890 | CombinePDF.Fonts.register_font_from_pdf_object | train | def register_font_from_pdf_object(font_name, font_object)
# FIXME:
# - add stream deflation for the CMap file.
# - add :Encoding CMaps (such as :WinAnsiEncoding etc`)
# - the ToUnicode CMap parsing assumes 8 Bytes <0F0F> while 16 Bytes and multiple unicode chars are also possible.
# first... | ruby | {
"resource": ""
} |
q12891 | CombinePDF.Page_Methods.init_contents | train | def init_contents
self[:Contents] = self[:Contents][:referenced_object][:indirect_without_dictionary] if self[:Contents].is_a?(Hash) && self[:Contents][:referenced_object] && self[:Contents][:referenced_object].is_a?(Hash) && self[:Contents][:referenced_object][:indirect_without_dictionary]
self[:Contents] ... | ruby | {
"resource": ""
} |
q12892 | CombinePDF.Page_Methods.insert_content | train | def insert_content(object, location = -1)
object = { is_reference_only: true, referenced_object: { indirect_reference_id: 0, raw_stream_content: object } } if object.is_a?(String)
raise TypeError, 'expected a String or Hash object.' unless object.is_a?(Hash)
prep_content_array
self[:Contents].in... | ruby | {
"resource": ""
} |
q12893 | CombinePDF.Page_Methods.graphic_state | train | def graphic_state(graphic_state_dictionary = {})
# if the graphic state exists, return it's name
resources[:ExtGState] ||= {}
gs_res = resources[:ExtGState][:referenced_object] || resources[:ExtGState]
gs_res.each do |k, v|
return k if v.is_a?(Hash) && v == graphic_state_dictionary
... | ruby | {
"resource": ""
} |
q12894 | Textbringer.Buffer.save_excursion | train | def save_excursion
old_point = new_mark
old_mark = @mark&.dup
old_column = @goal_column
begin
yield
ensure
point_to_mark(old_point)
old_point.delete
if old_mark
@mark.location = old_mark.location
old_mark.delete
end
@goal_... | ruby | {
"resource": ""
} |
q12895 | Textbringer.Buffer.push_mark | train | def push_mark(pos = @point)
@mark = new_mark
@mark.location = pos
@mark_ring.push(@mark)
if self != Buffer.minibuffer
global_mark_ring = Buffer.global_mark_ring
if global_mark_ring.empty? || global_mark_ring.current.buffer != self
push_global_mark(pos)
end
... | ruby | {
"resource": ""
} |
q12896 | Textbringer.ProgrammingMode.indent_line | train | def indent_line
result = false
level = calculate_indentation
return result if level.nil?
@buffer.save_excursion do
@buffer.beginning_of_line
@buffer.composite_edit do
if @buffer.looking_at?(/[ \t]+/)
s = @buffer.match_string(0)
break if /\t/ !~ s... | ruby | {
"resource": ""
} |
q12897 | Wechat.Cipher.pack | train | def pack(content, app_id)
random = SecureRandom.hex(8)
text = content.force_encoding('ASCII-8BIT')
msg_len = [text.length].pack('N')
encode_padding("#{random}#{msg_len}#{text}#{app_id}")
end | ruby | {
"resource": ""
} |
q12898 | IceCube.Validations::FixedValue.validate_interval_lock | train | def validate_interval_lock(time, start_time)
t0 = starting_unit(start_time)
t1 = time.send(type)
t0 >= t1 ? t0 - t1 : INTERVALS[type] - t1 + t0
end | ruby | {
"resource": ""
} |
q12899 | IceCube.Validations::FixedValue.validate_hour_lock | train | def validate_hour_lock(time, start_time)
h0 = starting_unit(start_time)
h1 = time.hour
if h0 >= h1
h0 - h1
else
if dst_offset = TimeUtil.dst_change(time)
h0 - h1 + dst_offset
else
24 - h1 + h0
end
end
end | ruby | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.