id int32 0 24.9k | repo stringlengths 5 58 | path stringlengths 9 168 | func_name stringlengths 9 130 | original_string stringlengths 66 10.5k | language stringclasses 1
value | code stringlengths 66 10.5k | code_tokens list | docstring stringlengths 8 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 94 266 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1,400 | mikamai/ruby-lol | lib/lol/summoner_request.rb | Lol.SummonerRequest.find_by_name | def find_by_name name
name = CGI.escape name.downcase.gsub(/\s/, '')
DynamicModel.new perform_request api_url "summoners/by-name/#{name}"
end | ruby | def find_by_name name
name = CGI.escape name.downcase.gsub(/\s/, '')
DynamicModel.new perform_request api_url "summoners/by-name/#{name}"
end | [
"def",
"find_by_name",
"name",
"name",
"=",
"CGI",
".",
"escape",
"name",
".",
"downcase",
".",
"gsub",
"(",
"/",
"\\s",
"/",
",",
"''",
")",
"DynamicModel",
".",
"new",
"perform_request",
"api_url",
"\"summoners/by-name/#{name}\"",
"end"
] | Get a summoner by summoner name.
@param [String] name Summoner name
@return [DynamicModel] Summoner representation | [
"Get",
"a",
"summoner",
"by",
"summoner",
"name",
"."
] | 0833669a96e803ab34aa1576be5b3c274396dc9b | https://github.com/mikamai/ruby-lol/blob/0833669a96e803ab34aa1576be5b3c274396dc9b/lib/lol/summoner_request.rb#L21-L24 |
1,401 | pazdera/scriptster | lib/scriptster/configuration.rb | Scriptster.Configuration.apply | def apply
Logger.set_name @name if @name
Logger.set_verbosity @verbosity if @verbosity
Logger.set_file @file if @file
Logger.set_format @log_format if @log_format
if @colours.is_a? Proc
@colours.call
else
ColourThemes.send @colours.to_sym
end
end | ruby | def apply
Logger.set_name @name if @name
Logger.set_verbosity @verbosity if @verbosity
Logger.set_file @file if @file
Logger.set_format @log_format if @log_format
if @colours.is_a? Proc
@colours.call
else
ColourThemes.send @colours.to_sym
end
end | [
"def",
"apply",
"Logger",
".",
"set_name",
"@name",
"if",
"@name",
"Logger",
".",
"set_verbosity",
"@verbosity",
"if",
"@verbosity",
"Logger",
".",
"set_file",
"@file",
"if",
"@file",
"Logger",
".",
"set_format",
"@log_format",
"if",
"@log_format",
"if",
"@colou... | Put the settings from this object in effect.
This function will distribute the configuration to the
appropriate objects and modules. | [
"Put",
"the",
"settings",
"from",
"this",
"object",
"in",
"effect",
"."
] | 8d4fcdaf06e867f1f460e980a9defdf36d0ac29d | https://github.com/pazdera/scriptster/blob/8d4fcdaf06e867f1f460e980a9defdf36d0ac29d/lib/scriptster/configuration.rb#L52-L63 |
1,402 | mikamai/ruby-lol | lib/lol/request.rb | Lol.Request.api_url | def api_url path, params = {}
url = File.join File.join(api_base_url, api_base_path), path
"#{url}?#{api_query_string params}"
end | ruby | def api_url path, params = {}
url = File.join File.join(api_base_url, api_base_path), path
"#{url}?#{api_query_string params}"
end | [
"def",
"api_url",
"path",
",",
"params",
"=",
"{",
"}",
"url",
"=",
"File",
".",
"join",
"File",
".",
"join",
"(",
"api_base_url",
",",
"api_base_path",
")",
",",
"path",
"\"#{url}?#{api_query_string params}\"",
"end"
] | Returns a full url for an API call
@param path [String] API path to call
@return [String] full fledged url | [
"Returns",
"a",
"full",
"url",
"for",
"an",
"API",
"call"
] | 0833669a96e803ab34aa1576be5b3c274396dc9b | https://github.com/mikamai/ruby-lol/blob/0833669a96e803ab34aa1576be5b3c274396dc9b/lib/lol/request.rb#L82-L85 |
1,403 | mikamai/ruby-lol | lib/lol/request.rb | Lol.Request.clean_url | def clean_url(url)
uri = URI.parse(url)
uri.query = CGI.parse(uri.query || '').reject { |k| k == 'api_key' }.to_query
uri.to_s
end | ruby | def clean_url(url)
uri = URI.parse(url)
uri.query = CGI.parse(uri.query || '').reject { |k| k == 'api_key' }.to_query
uri.to_s
end | [
"def",
"clean_url",
"(",
"url",
")",
"uri",
"=",
"URI",
".",
"parse",
"(",
"url",
")",
"uri",
".",
"query",
"=",
"CGI",
".",
"parse",
"(",
"uri",
".",
"query",
"||",
"''",
")",
".",
"reject",
"{",
"|",
"k",
"|",
"k",
"==",
"'api_key'",
"}",
"... | Returns just a path from a full api url
@return [String] | [
"Returns",
"just",
"a",
"path",
"from",
"a",
"full",
"api",
"url"
] | 0833669a96e803ab34aa1576be5b3c274396dc9b | https://github.com/mikamai/ruby-lol/blob/0833669a96e803ab34aa1576be5b3c274396dc9b/lib/lol/request.rb#L105-L109 |
1,404 | mikamai/ruby-lol | lib/lol/request.rb | Lol.Request.perform_request | def perform_request url, verb = :get, body = nil, options = {}
options_id = options.inspect
can_cache = [:post, :put].include?(verb) ? false : cached?
if can_cache && result = store.get("#{clean_url(url)}#{options_id}")
return JSON.parse(result)
end
response = perform_rate_limited_... | ruby | def perform_request url, verb = :get, body = nil, options = {}
options_id = options.inspect
can_cache = [:post, :put].include?(verb) ? false : cached?
if can_cache && result = store.get("#{clean_url(url)}#{options_id}")
return JSON.parse(result)
end
response = perform_rate_limited_... | [
"def",
"perform_request",
"url",
",",
"verb",
"=",
":get",
",",
"body",
"=",
"nil",
",",
"options",
"=",
"{",
"}",
"options_id",
"=",
"options",
".",
"inspect",
"can_cache",
"=",
"[",
":post",
",",
":put",
"]",
".",
"include?",
"(",
"verb",
")",
"?",... | Calls the API via HTTParty and handles errors caching it if a cache is
enabled and rate limiting it if a rate limiter is configured
@param url [String] the url to call
@param verb [Symbol] HTTP verb to use. Defaults to :get
@param body [Hash] Body for POST request
@param options [Hash] Options passed to HTTParty
... | [
"Calls",
"the",
"API",
"via",
"HTTParty",
"and",
"handles",
"errors",
"caching",
"it",
"if",
"a",
"cache",
"is",
"enabled",
"and",
"rate",
"limiting",
"it",
"if",
"a",
"rate",
"limiter",
"is",
"configured"
] | 0833669a96e803ab34aa1576be5b3c274396dc9b | https://github.com/mikamai/ruby-lol/blob/0833669a96e803ab34aa1576be5b3c274396dc9b/lib/lol/request.rb#L118-L127 |
1,405 | pazdera/scriptster | lib/scriptster/shellcmd.rb | Scriptster.ShellCmd.run | def run
Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
stdin.close # leaving stdin open when we don't use it can cause some commands to hang
stdout_buffer=""
stderr_buffer=""
streams = [stdout, stderr]
while streams.length > 0
IO.select(streams).flatten.... | ruby | def run
Open3.popen3(@cmd) do |stdin, stdout, stderr, wait_thr|
stdin.close # leaving stdin open when we don't use it can cause some commands to hang
stdout_buffer=""
stderr_buffer=""
streams = [stdout, stderr]
while streams.length > 0
IO.select(streams).flatten.... | [
"def",
"run",
"Open3",
".",
"popen3",
"(",
"@cmd",
")",
"do",
"|",
"stdin",
",",
"stdout",
",",
"stderr",
",",
"wait_thr",
"|",
"stdin",
".",
"close",
"# leaving stdin open when we don't use it can cause some commands to hang",
"stdout_buffer",
"=",
"\"\"",
"stderr_... | Execute the command and collect all the data from it.
The function will block until the command has finished. | [
"Execute",
"the",
"command",
"and",
"collect",
"all",
"the",
"data",
"from",
"it",
"."
] | 8d4fcdaf06e867f1f460e980a9defdf36d0ac29d | https://github.com/pazdera/scriptster/blob/8d4fcdaf06e867f1f460e980a9defdf36d0ac29d/lib/scriptster/shellcmd.rb#L81-L140 |
1,406 | mikamai/ruby-lol | lib/lol/masteries_request.rb | Lol.MasteriesRequest.by_summoner_id | def by_summoner_id summoner_id
result = perform_request api_url "masteries/by-summoner/#{summoner_id}"
result["pages"].map { |p| DynamicModel.new p }
end | ruby | def by_summoner_id summoner_id
result = perform_request api_url "masteries/by-summoner/#{summoner_id}"
result["pages"].map { |p| DynamicModel.new p }
end | [
"def",
"by_summoner_id",
"summoner_id",
"result",
"=",
"perform_request",
"api_url",
"\"masteries/by-summoner/#{summoner_id}\"",
"result",
"[",
"\"pages\"",
"]",
".",
"map",
"{",
"|",
"p",
"|",
"DynamicModel",
".",
"new",
"p",
"}",
"end"
] | Get mastery pages for a given summoner ID
@param [Integer] summoner_id Summoner ID
@return [Array<DynamicModel>] Mastery pages | [
"Get",
"mastery",
"pages",
"for",
"a",
"given",
"summoner",
"ID"
] | 0833669a96e803ab34aa1576be5b3c274396dc9b | https://github.com/mikamai/ruby-lol/blob/0833669a96e803ab34aa1576be5b3c274396dc9b/lib/lol/masteries_request.rb#L9-L12 |
1,407 | contactually/zuora-ruby | lib/utils/schema_model.rb | SchemaModel.ClassMethods.define_writer! | def define_writer!(k, definition)
define_method("#{k}=") do |value|
# Recursively convert hash and array of hash to schematized objects
value = ensure_schema value, definition[:schema]
# Initial value
instance_variable_set "@#{k}", value
# Dirty tracking
self.chan... | ruby | def define_writer!(k, definition)
define_method("#{k}=") do |value|
# Recursively convert hash and array of hash to schematized objects
value = ensure_schema value, definition[:schema]
# Initial value
instance_variable_set "@#{k}", value
# Dirty tracking
self.chan... | [
"def",
"define_writer!",
"(",
"k",
",",
"definition",
")",
"define_method",
"(",
"\"#{k}=\"",
")",
"do",
"|",
"value",
"|",
"# Recursively convert hash and array of hash to schematized objects",
"value",
"=",
"ensure_schema",
"value",
",",
"definition",
"[",
":schema",
... | Helper for dynamically defining writer method
@param [Symbol] k - name of attribute
@param [Hash] definition - See docstring for schema above | [
"Helper",
"for",
"dynamically",
"defining",
"writer",
"method"
] | 1d64da91babbbe37715591610987ef5d3ac9e3ca | https://github.com/contactually/zuora-ruby/blob/1d64da91babbbe37715591610987ef5d3ac9e3ca/lib/utils/schema_model.rb#L48-L60 |
1,408 | contactually/zuora-ruby | lib/utils/schema_model.rb | SchemaModel.InstanceMethods.check_children | def check_children(child_schema, value)
return unless child_schema && value.present?
if value.is_a? Array
value.map(&:errors).reject(&:empty?)
else
value.errors
end
end | ruby | def check_children(child_schema, value)
return unless child_schema && value.present?
if value.is_a? Array
value.map(&:errors).reject(&:empty?)
else
value.errors
end
end | [
"def",
"check_children",
"(",
"child_schema",
",",
"value",
")",
"return",
"unless",
"child_schema",
"&&",
"value",
".",
"present?",
"if",
"value",
".",
"is_a?",
"Array",
"value",
".",
"map",
"(",
":errors",
")",
".",
"reject",
"(",
":empty?",
")",
"else",... | Given a schema and a value which may be a single record or collection,
collect and return any errors.
@param [SchemaModel] child_schema - A schema object class
@param [Object] value - Array of models or single model
@return [Object] Array of errors hashes, or one hash.
Structure matches 'value' i... | [
"Given",
"a",
"schema",
"and",
"a",
"value",
"which",
"may",
"be",
"a",
"single",
"record",
"or",
"collection",
"collect",
"and",
"return",
"any",
"errors",
"."
] | 1d64da91babbbe37715591610987ef5d3ac9e3ca | https://github.com/contactually/zuora-ruby/blob/1d64da91babbbe37715591610987ef5d3ac9e3ca/lib/utils/schema_model.rb#L110-L118 |
1,409 | contactually/zuora-ruby | lib/utils/schema_model.rb | SchemaModel.InstanceMethods.check_validation | def check_validation(valid, value)
return unless valid && value
passes_validation = begin
valid.call(value)
rescue StandardError
false
end
passes_validation ? nil : 'is invalid'
end | ruby | def check_validation(valid, value)
return unless valid && value
passes_validation = begin
valid.call(value)
rescue StandardError
false
end
passes_validation ? nil : 'is invalid'
end | [
"def",
"check_validation",
"(",
"valid",
",",
"value",
")",
"return",
"unless",
"valid",
"&&",
"value",
"passes_validation",
"=",
"begin",
"valid",
".",
"call",
"(",
"value",
")",
"rescue",
"StandardError",
"false",
"end",
"passes_validation",
"?",
"nil",
":",... | Checks that required field meets validation
@param [Boolean or Callable] valid - callable validation fn or boolean
function will be called with value
@param [Object] value - value to check
@return [Maybe String] error message | [
"Checks",
"that",
"required",
"field",
"meets",
"validation"
] | 1d64da91babbbe37715591610987ef5d3ac9e3ca | https://github.com/contactually/zuora-ruby/blob/1d64da91babbbe37715591610987ef5d3ac9e3ca/lib/utils/schema_model.rb#L135-L144 |
1,410 | contactually/zuora-ruby | lib/utils/schema_model.rb | SchemaModel.InstanceMethods.append! | def append!(errors, attr, key, val)
return unless val.present?
errors ||= {}
errors[attr] ||= {}
errors[attr][key] = val
end | ruby | def append!(errors, attr, key, val)
return unless val.present?
errors ||= {}
errors[attr] ||= {}
errors[attr][key] = val
end | [
"def",
"append!",
"(",
"errors",
",",
"attr",
",",
"key",
",",
"val",
")",
"return",
"unless",
"val",
".",
"present?",
"errors",
"||=",
"{",
"}",
"errors",
"[",
"attr",
"]",
"||=",
"{",
"}",
"errors",
"[",
"attr",
"]",
"[",
"key",
"]",
"=",
"val"... | Mutates errors, adding in error messages scoped to the attribute and key
@param [Maybe Hash] errors -
@param [Symbol] attr - name of attribute under check
@param [Symbol] key - name of validation step
@param [Object] val - data to append | [
"Mutates",
"errors",
"adding",
"in",
"error",
"messages",
"scoped",
"to",
"the",
"attribute",
"and",
"key"
] | 1d64da91babbbe37715591610987ef5d3ac9e3ca | https://github.com/contactually/zuora-ruby/blob/1d64da91babbbe37715591610987ef5d3ac9e3ca/lib/utils/schema_model.rb#L151-L157 |
1,411 | delighted/delighted-ruby | lib/delighted/resource.rb | Delighted.Resource.to_hash | def to_hash
serialized_attributes = attributes.dup
self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
if expanded_class === attributes[attribute_name]
serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
end
end
... | ruby | def to_hash
serialized_attributes = attributes.dup
self.class.expandable_attributes.each_pair.select do |attribute_name, expanded_class|
if expanded_class === attributes[attribute_name]
serialized_attributes[attribute_name] = serialized_attributes[attribute_name].id
end
end
... | [
"def",
"to_hash",
"serialized_attributes",
"=",
"attributes",
".",
"dup",
"self",
".",
"class",
".",
"expandable_attributes",
".",
"each_pair",
".",
"select",
"do",
"|",
"attribute_name",
",",
"expanded_class",
"|",
"if",
"expanded_class",
"===",
"attributes",
"["... | Attributes used for serialization | [
"Attributes",
"used",
"for",
"serialization"
] | 843fe0c1453d651fd609b4a10d05b121fd37fe98 | https://github.com/delighted/delighted-ruby/blob/843fe0c1453d651fd609b4a10d05b121fd37fe98/lib/delighted/resource.rb#L41-L51 |
1,412 | HashNuke/mailgun | lib/mailgun/webhook.rb | Mailgun.Webhook.update | def update(id, url=default_webhook_url)
params = {:url => url}
Mailgun.submit :put, webhook_url(id), params
end | ruby | def update(id, url=default_webhook_url)
params = {:url => url}
Mailgun.submit :put, webhook_url(id), params
end | [
"def",
"update",
"(",
"id",
",",
"url",
"=",
"default_webhook_url",
")",
"params",
"=",
"{",
":url",
"=>",
"url",
"}",
"Mailgun",
".",
"submit",
":put",
",",
"webhook_url",
"(",
"id",
")",
",",
"params",
"end"
] | Updates an existing webhook | [
"Updates",
"an",
"existing",
"webhook"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/webhook.rb#L37-L40 |
1,413 | HashNuke/mailgun | lib/mailgun/list.rb | Mailgun.MailingList.update | def update(address, new_address, options={})
params = {:address => new_address}
Mailgun.submit :put, list_url(address), params.merge(options)
end | ruby | def update(address, new_address, options={})
params = {:address => new_address}
Mailgun.submit :put, list_url(address), params.merge(options)
end | [
"def",
"update",
"(",
"address",
",",
"new_address",
",",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"{",
":address",
"=>",
"new_address",
"}",
"Mailgun",
".",
"submit",
":put",
",",
"list_url",
"(",
"address",
")",
",",
"params",
".",
"merge",
"(",... | Update a mailing list with a given address
with an optional new address, name or description | [
"Update",
"a",
"mailing",
"list",
"with",
"a",
"given",
"address",
"with",
"an",
"optional",
"new",
"address",
"name",
"or",
"description"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/list.rb#L30-L33 |
1,414 | pluginaweek/encrypted_strings | lib/encrypted_strings/asymmetric_cipher.rb | EncryptedStrings.AsymmetricCipher.encrypt | def encrypt(data)
raise NoPublicKeyError, "Public key file: #{public_key_file}" unless public?
encrypted_data = public_rsa.public_encrypt(data)
[encrypted_data].pack('m')
end | ruby | def encrypt(data)
raise NoPublicKeyError, "Public key file: #{public_key_file}" unless public?
encrypted_data = public_rsa.public_encrypt(data)
[encrypted_data].pack('m')
end | [
"def",
"encrypt",
"(",
"data",
")",
"raise",
"NoPublicKeyError",
",",
"\"Public key file: #{public_key_file}\"",
"unless",
"public?",
"encrypted_data",
"=",
"public_rsa",
".",
"public_encrypt",
"(",
"data",
")",
"[",
"encrypted_data",
"]",
".",
"pack",
"(",
"'m'",
... | Creates a new cipher that uses an asymmetric encryption strategy.
Configuration options:
* <tt>:private_key_file</tt> - Encrypted private key file
* <tt>:public_key_file</tt> - Public key file
* <tt>:password</tt> - The password to use in the symmetric cipher
* <tt>:algorithm</tt> - Algorithm to use symmetrically... | [
"Creates",
"a",
"new",
"cipher",
"that",
"uses",
"an",
"asymmetric",
"encryption",
"strategy",
"."
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/asymmetric_cipher.rb#L106-L111 |
1,415 | pluginaweek/encrypted_strings | lib/encrypted_strings/asymmetric_cipher.rb | EncryptedStrings.AsymmetricCipher.decrypt | def decrypt(data)
raise NoPrivateKeyError, "Private key file: #{private_key_file}" unless private?
decrypted_data = data.unpack('m')[0]
private_rsa.private_decrypt(decrypted_data)
end | ruby | def decrypt(data)
raise NoPrivateKeyError, "Private key file: #{private_key_file}" unless private?
decrypted_data = data.unpack('m')[0]
private_rsa.private_decrypt(decrypted_data)
end | [
"def",
"decrypt",
"(",
"data",
")",
"raise",
"NoPrivateKeyError",
",",
"\"Private key file: #{private_key_file}\"",
"unless",
"private?",
"decrypted_data",
"=",
"data",
".",
"unpack",
"(",
"'m'",
")",
"[",
"0",
"]",
"private_rsa",
".",
"private_decrypt",
"(",
"dec... | Decrypts the given data. If no private key file has been specified, then
a NoPrivateKeyError will be raised. | [
"Decrypts",
"the",
"given",
"data",
".",
"If",
"no",
"private",
"key",
"file",
"has",
"been",
"specified",
"then",
"a",
"NoPrivateKeyError",
"will",
"be",
"raised",
"."
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/asymmetric_cipher.rb#L115-L120 |
1,416 | pluginaweek/encrypted_strings | lib/encrypted_strings/asymmetric_cipher.rb | EncryptedStrings.AsymmetricCipher.private_rsa | def private_rsa
if password
options = {:password => password}
options[:algorithm] = algorithm if algorithm
private_key = @private_key.decrypt(:symmetric, options)
OpenSSL::PKey::RSA.new(private_key)
else
@private_rsa ||= OpenSSL::PKey::RSA.new... | ruby | def private_rsa
if password
options = {:password => password}
options[:algorithm] = algorithm if algorithm
private_key = @private_key.decrypt(:symmetric, options)
OpenSSL::PKey::RSA.new(private_key)
else
@private_rsa ||= OpenSSL::PKey::RSA.new... | [
"def",
"private_rsa",
"if",
"password",
"options",
"=",
"{",
":password",
"=>",
"password",
"}",
"options",
"[",
":algorithm",
"]",
"=",
"algorithm",
"if",
"algorithm",
"private_key",
"=",
"@private_key",
".",
"decrypt",
"(",
":symmetric",
",",
"options",
")",... | Retrieves the private RSA from the private key | [
"Retrieves",
"the",
"private",
"RSA",
"from",
"the",
"private",
"key"
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/asymmetric_cipher.rb#L168-L178 |
1,417 | pluginaweek/encrypted_strings | lib/encrypted_strings/sha_cipher.rb | EncryptedStrings.ShaCipher.encrypt | def encrypt(data)
Digest::const_get(algorithm.upcase).hexdigest(build(data, salt))
end | ruby | def encrypt(data)
Digest::const_get(algorithm.upcase).hexdigest(build(data, salt))
end | [
"def",
"encrypt",
"(",
"data",
")",
"Digest",
"::",
"const_get",
"(",
"algorithm",
".",
"upcase",
")",
".",
"hexdigest",
"(",
"build",
"(",
"data",
",",
"salt",
")",
")",
"end"
] | Returns the encrypted value of the data | [
"Returns",
"the",
"encrypted",
"value",
"of",
"the",
"data"
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/sha_cipher.rb#L110-L112 |
1,418 | pluginaweek/encrypted_strings | lib/encrypted_strings/sha_cipher.rb | EncryptedStrings.ShaCipher.build | def build(data, salt)
if builder.is_a?(Proc)
builder.call(data, salt)
else
builder.send(:build, data, salt)
end
end | ruby | def build(data, salt)
if builder.is_a?(Proc)
builder.call(data, salt)
else
builder.send(:build, data, salt)
end
end | [
"def",
"build",
"(",
"data",
",",
"salt",
")",
"if",
"builder",
".",
"is_a?",
"(",
"Proc",
")",
"builder",
".",
"call",
"(",
"data",
",",
"salt",
")",
"else",
"builder",
".",
"send",
"(",
":build",
",",
"data",
",",
"salt",
")",
"end",
"end"
] | Builds the value to hash based on the data being encrypted and the salt
being used to seed the encryption algorithm | [
"Builds",
"the",
"value",
"to",
"hash",
"based",
"on",
"the",
"data",
"being",
"encrypted",
"and",
"the",
"salt",
"being",
"used",
"to",
"seed",
"the",
"encryption",
"algorithm"
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/sha_cipher.rb#L132-L138 |
1,419 | HashNuke/mailgun | lib/mailgun/secure.rb | Mailgun.Secure.check_request_auth | def check_request_auth(timestamp, token, signature, offset=-5)
if offset != 0
offset = Time.now.to_i + offset * 60
return false if timestamp < offset
end
return signature == OpenSSL::HMAC.hexdigest(
OpenSSL::Digest::Digest.new('sha256'),
Mailgun.api_key,
... | ruby | def check_request_auth(timestamp, token, signature, offset=-5)
if offset != 0
offset = Time.now.to_i + offset * 60
return false if timestamp < offset
end
return signature == OpenSSL::HMAC.hexdigest(
OpenSSL::Digest::Digest.new('sha256'),
Mailgun.api_key,
... | [
"def",
"check_request_auth",
"(",
"timestamp",
",",
"token",
",",
"signature",
",",
"offset",
"=",
"-",
"5",
")",
"if",
"offset",
"!=",
"0",
"offset",
"=",
"Time",
".",
"now",
".",
"to_i",
"+",
"offset",
"*",
"60",
"return",
"false",
"if",
"timestamp",... | check request auth | [
"check",
"request",
"auth"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/secure.rb#L18-L28 |
1,420 | bbc/res | lib/res/ir.rb | Res.IR.json | def json
hash = {
:started => @started,
:finished => @finished,
:results => @results,
:type => @type }
# Merge in the world information if it's available
hash[:world] = world if world
hash[:hive_job_id] = hive_job_id if hive_job_id
... | ruby | def json
hash = {
:started => @started,
:finished => @finished,
:results => @results,
:type => @type }
# Merge in the world information if it's available
hash[:world] = world if world
hash[:hive_job_id] = hive_job_id if hive_job_id
... | [
"def",
"json",
"hash",
"=",
"{",
":started",
"=>",
"@started",
",",
":finished",
"=>",
"@finished",
",",
":results",
"=>",
"@results",
",",
":type",
"=>",
"@type",
"}",
"# Merge in the world information if it's available",
"hash",
"[",
":world",
"]",
"=",
"world... | Dump as json | [
"Dump",
"as",
"json"
] | 2a7e86191acf1da957a08ead7a7367c19f20bc21 | https://github.com/bbc/res/blob/2a7e86191acf1da957a08ead7a7367c19f20bc21/lib/res/ir.rb#L47-L59 |
1,421 | pluginaweek/encrypted_strings | lib/encrypted_strings/symmetric_cipher.rb | EncryptedStrings.SymmetricCipher.decrypt | def decrypt(data)
cipher = build_cipher(:decrypt)
cipher.update(data.unpack('m')[0]) + cipher.final
end | ruby | def decrypt(data)
cipher = build_cipher(:decrypt)
cipher.update(data.unpack('m')[0]) + cipher.final
end | [
"def",
"decrypt",
"(",
"data",
")",
"cipher",
"=",
"build_cipher",
"(",
":decrypt",
")",
"cipher",
".",
"update",
"(",
"data",
".",
"unpack",
"(",
"'m'",
")",
"[",
"0",
"]",
")",
"+",
"cipher",
".",
"final",
"end"
] | Creates a new cipher that uses a symmetric encryption strategy.
Configuration options:
* <tt>:algorithm</tt> - The algorithm to use for generating the encrypted string
* <tt>:password</tt> - The secret value to use for generating the
key/initialization vector for the algorithm
Decrypts the current string using ... | [
"Creates",
"a",
"new",
"cipher",
"that",
"uses",
"a",
"symmetric",
"encryption",
"strategy",
"."
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/symmetric_cipher.rb#L83-L86 |
1,422 | pluginaweek/encrypted_strings | lib/encrypted_strings/symmetric_cipher.rb | EncryptedStrings.SymmetricCipher.encrypt | def encrypt(data)
cipher = build_cipher(:encrypt)
[cipher.update(data) + cipher.final].pack('m')
end | ruby | def encrypt(data)
cipher = build_cipher(:encrypt)
[cipher.update(data) + cipher.final].pack('m')
end | [
"def",
"encrypt",
"(",
"data",
")",
"cipher",
"=",
"build_cipher",
"(",
":encrypt",
")",
"[",
"cipher",
".",
"update",
"(",
"data",
")",
"+",
"cipher",
".",
"final",
"]",
".",
"pack",
"(",
"'m'",
")",
"end"
] | Encrypts the current string using the current key and algorithm specified | [
"Encrypts",
"the",
"current",
"string",
"using",
"the",
"current",
"key",
"and",
"algorithm",
"specified"
] | a9bea6b48b910e24e762662d8816709100906756 | https://github.com/pluginaweek/encrypted_strings/blob/a9bea6b48b910e24e762662d8816709100906756/lib/encrypted_strings/symmetric_cipher.rb#L89-L92 |
1,423 | HashNuke/mailgun | lib/mailgun/domain.rb | Mailgun.Domain.create | def create(domain, opts = {})
opts = {name: domain}.merge(opts)
Mailgun.submit :post, domain_url, opts
end | ruby | def create(domain, opts = {})
opts = {name: domain}.merge(opts)
Mailgun.submit :post, domain_url, opts
end | [
"def",
"create",
"(",
"domain",
",",
"opts",
"=",
"{",
"}",
")",
"opts",
"=",
"{",
"name",
":",
"domain",
"}",
".",
"merge",
"(",
"opts",
")",
"Mailgun",
".",
"submit",
":post",
",",
"domain_url",
",",
"opts",
"end"
] | Add domain to account | [
"Add",
"domain",
"to",
"account"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/domain.rb#L21-L24 |
1,424 | junegunn/perlin_noise | lib/perlin/gradient_table.rb | Perlin.GradientTable.index | def index(*coords)
s = coords.last
coords.reverse[1..-1].each do |c|
s = perm(s) + c
end
perm(s)
end | ruby | def index(*coords)
s = coords.last
coords.reverse[1..-1].each do |c|
s = perm(s) + c
end
perm(s)
end | [
"def",
"index",
"(",
"*",
"coords",
")",
"s",
"=",
"coords",
".",
"last",
"coords",
".",
"reverse",
"[",
"1",
"..",
"-",
"1",
"]",
".",
"each",
"do",
"|",
"c",
"|",
"s",
"=",
"perm",
"(",
"s",
")",
"+",
"c",
"end",
"perm",
"(",
"s",
")",
... | A simple hashing | [
"A",
"simple",
"hashing"
] | ac402f5c4a4f54f9b26c8a8166f06ba7f06454d3 | https://github.com/junegunn/perlin_noise/blob/ac402f5c4a4f54f9b26c8a8166f06ba7f06454d3/lib/perlin/gradient_table.rb#L38-L44 |
1,425 | HashNuke/mailgun | lib/mailgun/list/member.rb | Mailgun.MailingList::Member.add | def add(member_address, options={})
params = {:address => member_address}
Mailgun.submit :post, list_member_url, params.merge(options)
end | ruby | def add(member_address, options={})
params = {:address => member_address}
Mailgun.submit :post, list_member_url, params.merge(options)
end | [
"def",
"add",
"(",
"member_address",
",",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"{",
":address",
"=>",
"member_address",
"}",
"Mailgun",
".",
"submit",
":post",
",",
"list_member_url",
",",
"params",
".",
"merge",
"(",
"options",
")",
"end"
] | Adds a mailing list member with a given address
NOTE Use create instead of add? | [
"Adds",
"a",
"mailing",
"list",
"member",
"with",
"a",
"given",
"address",
"NOTE",
"Use",
"create",
"instead",
"of",
"add?"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/list/member.rb#L25-L28 |
1,426 | HashNuke/mailgun | lib/mailgun/list/member.rb | Mailgun.MailingList::Member.update | def update(member_address, options={})
params = {:address => member_address}
Mailgun.submit :put, list_member_url(member_address), params.merge(options)
end | ruby | def update(member_address, options={})
params = {:address => member_address}
Mailgun.submit :put, list_member_url(member_address), params.merge(options)
end | [
"def",
"update",
"(",
"member_address",
",",
"options",
"=",
"{",
"}",
")",
"params",
"=",
"{",
":address",
"=>",
"member_address",
"}",
"Mailgun",
".",
"submit",
":put",
",",
"list_member_url",
"(",
"member_address",
")",
",",
"params",
".",
"merge",
"(",... | Update a mailing list member with a given address | [
"Update",
"a",
"mailing",
"list",
"member",
"with",
"a",
"given",
"address"
] | 5476618ae1208cd0e563b6f84d26e2cfc68417ba | https://github.com/HashNuke/mailgun/blob/5476618ae1208cd0e563b6f84d26e2cfc68417ba/lib/mailgun/list/member.rb#L39-L42 |
1,427 | sdalu/ruby-ble | lib/ble/device.rb | BLE.Device.cancel_pairing | def cancel_pairing
block_given? ? @o_dev[I_DEVICE].CancelPairing(&Proc.new) :
@o_dev[I_DEVICE].CancelPairing()
true
rescue DBus::Error => e
case e.name
when E_DOES_NOT_EXIST then true
when E_FAILED then false
else raise ScriptError
end
end | ruby | def cancel_pairing
block_given? ? @o_dev[I_DEVICE].CancelPairing(&Proc.new) :
@o_dev[I_DEVICE].CancelPairing()
true
rescue DBus::Error => e
case e.name
when E_DOES_NOT_EXIST then true
when E_FAILED then false
else raise ScriptError
end
end | [
"def",
"cancel_pairing",
"block_given?",
"?",
"@o_dev",
"[",
"I_DEVICE",
"]",
".",
"CancelPairing",
"(",
"Proc",
".",
"new",
")",
":",
"@o_dev",
"[",
"I_DEVICE",
"]",
".",
"CancelPairing",
"(",
")",
"true",
"rescue",
"DBus",
"::",
"Error",
"=>",
"e",
"ca... | This method can be used to cancel a pairing
operation initiated by the Pair method.
@return [Boolean] | [
"This",
"method",
"can",
"be",
"used",
"to",
"cancel",
"a",
"pairing",
"operation",
"initiated",
"by",
"the",
"Pair",
"method",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/device.rb#L101-L111 |
1,428 | sdalu/ruby-ble | lib/ble/device.rb | BLE.Device.is_paired? | def is_paired?
@o_dev[I_DEVICE]['Paired']
rescue DBus::Error => e
case e.name
when E_UNKNOWN_OBJECT
raise StalledObject
else raise ScriptError
end
end | ruby | def is_paired?
@o_dev[I_DEVICE]['Paired']
rescue DBus::Error => e
case e.name
when E_UNKNOWN_OBJECT
raise StalledObject
else raise ScriptError
end
end | [
"def",
"is_paired?",
"@o_dev",
"[",
"I_DEVICE",
"]",
"[",
"'Paired'",
"]",
"rescue",
"DBus",
"::",
"Error",
"=>",
"e",
"case",
"e",
".",
"name",
"when",
"E_UNKNOWN_OBJECT",
"raise",
"StalledObject",
"else",
"raise",
"ScriptError",
"end",
"end"
] | Indicates if the remote device is paired | [
"Indicates",
"if",
"the",
"remote",
"device",
"is",
"paired"
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/device.rb#L185-L193 |
1,429 | sdalu/ruby-ble | lib/ble/device.rb | BLE.Device.trusted= | def trusted=(val)
if ! [ true, false ].include?(val)
raise ArgumentError, "value must be a boolean"
end
@o_dev[I_DEVICE]['Trusted'] = val
end | ruby | def trusted=(val)
if ! [ true, false ].include?(val)
raise ArgumentError, "value must be a boolean"
end
@o_dev[I_DEVICE]['Trusted'] = val
end | [
"def",
"trusted",
"=",
"(",
"val",
")",
"if",
"!",
"[",
"true",
",",
"false",
"]",
".",
"include?",
"(",
"val",
")",
"raise",
"ArgumentError",
",",
"\"value must be a boolean\"",
"end",
"@o_dev",
"[",
"I_DEVICE",
"]",
"[",
"'Trusted'",
"]",
"=",
"val",
... | Indicates if the remote is seen as trusted. This
setting can be changed by the application.
@param val [Boolean]
@return [void] | [
"Indicates",
"if",
"the",
"remote",
"is",
"seen",
"as",
"trusted",
".",
"This",
"setting",
"can",
"be",
"changed",
"by",
"the",
"application",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/device.rb#L291-L296 |
1,430 | sdalu/ruby-ble | lib/ble/device.rb | BLE.Device.blocked= | def blocked=(val)
if ! [ true, false ].include?(val)
raise ArgumentError, "value must be a boolean"
end
@o_dev[I_DEVICE]['Blocked'] = val
end | ruby | def blocked=(val)
if ! [ true, false ].include?(val)
raise ArgumentError, "value must be a boolean"
end
@o_dev[I_DEVICE]['Blocked'] = val
end | [
"def",
"blocked",
"=",
"(",
"val",
")",
"if",
"!",
"[",
"true",
",",
"false",
"]",
".",
"include?",
"(",
"val",
")",
"raise",
"ArgumentError",
",",
"\"value must be a boolean\"",
"end",
"@o_dev",
"[",
"I_DEVICE",
"]",
"[",
"'Blocked'",
"]",
"=",
"val",
... | If set to true any incoming connections from the
device will be immediately rejected. Any device
drivers will also be removed and no new ones will
be probed as long as the device is blocked
@param val [Boolean]
@return [void] | [
"If",
"set",
"to",
"true",
"any",
"incoming",
"connections",
"from",
"the",
"device",
"will",
"be",
"immediately",
"rejected",
".",
"Any",
"device",
"drivers",
"will",
"also",
"be",
"removed",
"and",
"no",
"new",
"ones",
"will",
"be",
"probed",
"as",
"long... | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/device.rb#L310-L315 |
1,431 | sdalu/ruby-ble | lib/ble/device.rb | BLE.Device.refresh! | def refresh!
_require_connection!
max_wait ||= 1.5 # Use ||= due to the retry
@services = Hash[@o_dev.subnodes.map {|p_srv|
p_srv = [@o_dev.path, p_srv].join '/'
o_srv = BLUEZ.object(p_srv)
o_srv.introspect
srv = o_srv.GetAll(I_GATT_SERVICE).first
ch... | ruby | def refresh!
_require_connection!
max_wait ||= 1.5 # Use ||= due to the retry
@services = Hash[@o_dev.subnodes.map {|p_srv|
p_srv = [@o_dev.path, p_srv].join '/'
o_srv = BLUEZ.object(p_srv)
o_srv.introspect
srv = o_srv.GetAll(I_GATT_SERVICE).first
ch... | [
"def",
"refresh!",
"_require_connection!",
"max_wait",
"||=",
"1.5",
"# Use ||= due to the retry",
"@services",
"=",
"Hash",
"[",
"@o_dev",
".",
"subnodes",
".",
"map",
"{",
"|",
"p_srv",
"|",
"p_srv",
"=",
"[",
"@o_dev",
".",
"path",
",",
"p_srv",
"]",
".",... | Refresh list of services and characteristics
@raise [NotConnected] if device is not in a connected state
@return [self] | [
"Refresh",
"list",
"of",
"services",
"and",
"characteristics"
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/device.rb#L353-L389 |
1,432 | infinitered/bluepotion | lib/project/pro_motion/fragments/pm_screen_module.rb | PMScreenModule.ClassMethods.action_bar | def action_bar(show_action_bar, opts={})
@action_bar_options = ({show:true, back: true, icon: false}).merge(opts).merge({show: show_action_bar})
end | ruby | def action_bar(show_action_bar, opts={})
@action_bar_options = ({show:true, back: true, icon: false}).merge(opts).merge({show: show_action_bar})
end | [
"def",
"action_bar",
"(",
"show_action_bar",
",",
"opts",
"=",
"{",
"}",
")",
"@action_bar_options",
"=",
"(",
"{",
"show",
":",
"true",
",",
"back",
":",
"true",
",",
"icon",
":",
"false",
"}",
")",
".",
"merge",
"(",
"opts",
")",
".",
"merge",
"(... | Sets up the action bar for this screen.
Example:
action_bar true, back: true, icon: true,
custom_icon: "resourcename", custom_back: "custombackicon" | [
"Sets",
"up",
"the",
"action",
"bar",
"for",
"this",
"screen",
"."
] | 293730b31e3bdeec2887bfa014bcd2d354b3e608 | https://github.com/infinitered/bluepotion/blob/293730b31e3bdeec2887bfa014bcd2d354b3e608/lib/project/pro_motion/fragments/pm_screen_module.rb#L30-L32 |
1,433 | zevarito/mixpanel | lib/mixpanel/tracker.rb | Mixpanel.Tracker.escape_object_for_js | def escape_object_for_js(object, i = 0)
if object.kind_of? Hash
# Recursive case
Hash.new.tap do |h|
object.each do |k, v|
h[escape_object_for_js(k, i + 1)] = escape_object_for_js(v, i + 1)
end
end
elsif object.kind_of? Enumerable
# Recursive... | ruby | def escape_object_for_js(object, i = 0)
if object.kind_of? Hash
# Recursive case
Hash.new.tap do |h|
object.each do |k, v|
h[escape_object_for_js(k, i + 1)] = escape_object_for_js(v, i + 1)
end
end
elsif object.kind_of? Enumerable
# Recursive... | [
"def",
"escape_object_for_js",
"(",
"object",
",",
"i",
"=",
"0",
")",
"if",
"object",
".",
"kind_of?",
"Hash",
"# Recursive case",
"Hash",
".",
"new",
".",
"tap",
"do",
"|",
"h",
"|",
"object",
".",
"each",
"do",
"|",
"k",
",",
"v",
"|",
"h",
"[",... | Recursively escape anything in a primitive, array, or hash, in
preparation for jsonifying it | [
"Recursively",
"escape",
"anything",
"in",
"a",
"primitive",
"array",
"or",
"hash",
"in",
"preparation",
"for",
"jsonifying",
"it"
] | e36b2e1d054c38cc2974e677ecd60f6f424ff33d | https://github.com/zevarito/mixpanel/blob/e36b2e1d054c38cc2974e677ecd60f6f424ff33d/lib/mixpanel/tracker.rb#L97-L130 |
1,434 | nbudin/heroku_external_db | lib/heroku_external_db.rb | HerokuExternalDb.Configuration.db_configuration | def db_configuration(opts)
return {} unless opts
raise "ca_path for #{opts.inspect} cannot be determined from Rails root; please set it explicitly" unless ca_path
config = {}
[
:sslca,
# Needed when using X.509
:sslcert,
:sslkey,
].each do |k|
if ... | ruby | def db_configuration(opts)
return {} unless opts
raise "ca_path for #{opts.inspect} cannot be determined from Rails root; please set it explicitly" unless ca_path
config = {}
[
:sslca,
# Needed when using X.509
:sslcert,
:sslkey,
].each do |k|
if ... | [
"def",
"db_configuration",
"(",
"opts",
")",
"return",
"{",
"}",
"unless",
"opts",
"raise",
"\"ca_path for #{opts.inspect} cannot be determined from Rails root; please set it explicitly\"",
"unless",
"ca_path",
"config",
"=",
"{",
"}",
"[",
":sslca",
",",
"# Needed when usi... | Returns a partial ActiveRecord configuration hash for the given SSL CA certificate.
Checks to make sure the given filename actually exists, and raises an error if it
does not. | [
"Returns",
"a",
"partial",
"ActiveRecord",
"configuration",
"hash",
"for",
"the",
"given",
"SSL",
"CA",
"certificate",
".",
"Checks",
"to",
"make",
"sure",
"the",
"given",
"filename",
"actually",
"exists",
"and",
"raises",
"an",
"error",
"if",
"it",
"does",
... | 1eec5b85e85e03645fa2c478cbaf8aec574ad5a5 | https://github.com/nbudin/heroku_external_db/blob/1eec5b85e85e03645fa2c478cbaf8aec574ad5a5/lib/heroku_external_db.rb#L79-L100 |
1,435 | nbudin/heroku_external_db | lib/heroku_external_db.rb | HerokuExternalDb.Configuration.db_config | def db_config
@db_config ||= begin
raise "ENV['#{env_prefix}_DATABASE_URL'] expected but not found!" unless ENV["#{env_prefix}_DATABASE_URL"]
config = parse_db_uri(ENV["#{env_prefix}_DATABASE_URL"])
if ENV["#{env_prefix}_DATABASE_CA"]
config.merge!(db_configuration({
... | ruby | def db_config
@db_config ||= begin
raise "ENV['#{env_prefix}_DATABASE_URL'] expected but not found!" unless ENV["#{env_prefix}_DATABASE_URL"]
config = parse_db_uri(ENV["#{env_prefix}_DATABASE_URL"])
if ENV["#{env_prefix}_DATABASE_CA"]
config.merge!(db_configuration({
... | [
"def",
"db_config",
"@db_config",
"||=",
"begin",
"raise",
"\"ENV['#{env_prefix}_DATABASE_URL'] expected but not found!\"",
"unless",
"ENV",
"[",
"\"#{env_prefix}_DATABASE_URL\"",
"]",
"config",
"=",
"parse_db_uri",
"(",
"ENV",
"[",
"\"#{env_prefix}_DATABASE_URL\"",
"]",
")",... | Returns an ActiveRecord configuration hash based on the environment variables. | [
"Returns",
"an",
"ActiveRecord",
"configuration",
"hash",
"based",
"on",
"the",
"environment",
"variables",
"."
] | 1eec5b85e85e03645fa2c478cbaf8aec574ad5a5 | https://github.com/nbudin/heroku_external_db/blob/1eec5b85e85e03645fa2c478cbaf8aec574ad5a5/lib/heroku_external_db.rb#L103-L118 |
1,436 | sdalu/ruby-ble | lib/ble/notifications.rb | BLE.Notifications.start_notify! | def start_notify!(service, characteristic)
char= _find_characteristic(service, characteristic)
if char.flag?('notify')
char.notify!
else
raise OperationNotSupportedError.new("No notifications available for characteristic #{characteristic}")
end
end | ruby | def start_notify!(service, characteristic)
char= _find_characteristic(service, characteristic)
if char.flag?('notify')
char.notify!
else
raise OperationNotSupportedError.new("No notifications available for characteristic #{characteristic}")
end
end | [
"def",
"start_notify!",
"(",
"service",
",",
"characteristic",
")",
"char",
"=",
"_find_characteristic",
"(",
"service",
",",
"characteristic",
")",
"if",
"char",
".",
"flag?",
"(",
"'notify'",
")",
"char",
".",
"notify!",
"else",
"raise",
"OperationNotSupported... | Registers current device for notifications of the given _characteristic_.
Synonym for 'subscribe' or 'activate'.
This step is required in order to later receive notifications.
@param service [String, Symbol]
@param characteristic [String, Symbol] | [
"Registers",
"current",
"device",
"for",
"notifications",
"of",
"the",
"given",
"_characteristic_",
".",
"Synonym",
"for",
"subscribe",
"or",
"activate",
".",
"This",
"step",
"is",
"required",
"in",
"order",
"to",
"later",
"receive",
"notifications",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/notifications.rb#L10-L17 |
1,437 | sdalu/ruby-ble | lib/ble/notifications.rb | BLE.Notifications.on_notification | def on_notification(service, characteristic, raw: false, &callback)
_require_connection!
char= _find_characteristic(service, characteristic)
if char.flag?('notify')
char.on_change(raw: raw) { |val|
callback.call(val)
}
elsif char.flag?('encrypt-read') ||
char.... | ruby | def on_notification(service, characteristic, raw: false, &callback)
_require_connection!
char= _find_characteristic(service, characteristic)
if char.flag?('notify')
char.on_change(raw: raw) { |val|
callback.call(val)
}
elsif char.flag?('encrypt-read') ||
char.... | [
"def",
"on_notification",
"(",
"service",
",",
"characteristic",
",",
"raw",
":",
"false",
",",
"&",
"callback",
")",
"_require_connection!",
"char",
"=",
"_find_characteristic",
"(",
"service",
",",
"characteristic",
")",
"if",
"char",
".",
"flag?",
"(",
"'no... | Registers the callback to be invoked when a notification from the given _characteristic_ is received.
NOTE: Requires the device to be subscribed to _characteristic_ notifications.
@param service [String, Symbol]
@param characteristic [String, Symbol]
@param raw [Boolean] When raw is true the value (set/get) is a b... | [
"Registers",
"the",
"callback",
"to",
"be",
"invoked",
"when",
"a",
"notification",
"from",
"the",
"given",
"_characteristic_",
"is",
"received",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/notifications.rb#L28-L41 |
1,438 | bhaberer/steam-api | lib/steam-api/client.rb | Steam.Client.get | def get(resource, params: {}, key: Steam.apikey)
params[:key] = key
response = @conn.get resource, params
JSON.parse(response.body)
rescue JSON::ParserError
# If the steam web api returns an error it's virtually never in json, so
# lets pretend that we're getting some sort of consist... | ruby | def get(resource, params: {}, key: Steam.apikey)
params[:key] = key
response = @conn.get resource, params
JSON.parse(response.body)
rescue JSON::ParserError
# If the steam web api returns an error it's virtually never in json, so
# lets pretend that we're getting some sort of consist... | [
"def",
"get",
"(",
"resource",
",",
"params",
":",
"{",
"}",
",",
"key",
":",
"Steam",
".",
"apikey",
")",
"params",
"[",
":key",
"]",
"=",
"key",
"response",
"=",
"@conn",
".",
"get",
"resource",
",",
"params",
"JSON",
".",
"parse",
"(",
"response... | overriding the get method of Faraday to make things simpler.
@param [String] resource the resource you're targeting
@param [Hash] params Hash of parameters to pass to the resource
@param [String] key Steam API key | [
"overriding",
"the",
"get",
"method",
"of",
"Faraday",
"to",
"make",
"things",
"simpler",
"."
] | e7613b7689497d0d691397d600ec72164b7a3b96 | https://github.com/bhaberer/steam-api/blob/e7613b7689497d0d691397d600ec72164b7a3b96/lib/steam-api/client.rb#L13-L22 |
1,439 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.bootstrap_tab_nav_tag | def bootstrap_tab_nav_tag(title, linkto, active = false)
content_tag('li',
link_to(title, linkto, "data-toggle": 'tab'),
active ? { class: 'active' } : {})
end | ruby | def bootstrap_tab_nav_tag(title, linkto, active = false)
content_tag('li',
link_to(title, linkto, "data-toggle": 'tab'),
active ? { class: 'active' } : {})
end | [
"def",
"bootstrap_tab_nav_tag",
"(",
"title",
",",
"linkto",
",",
"active",
"=",
"false",
")",
"content_tag",
"(",
"'li'",
",",
"link_to",
"(",
"title",
",",
"linkto",
",",
"\"data-toggle\"",
":",
"'tab'",
")",
",",
"active",
"?",
"{",
"class",
":",
"'ac... | Creates a simple bootstrap tab navigation.
==== Signatures
bootstrap_tab_nav_tag(title, linkto, active = false)
==== Examples
<%= bootstrap_tab_nav_tag("Fruits", "#fruits", true) %>
# => <li class="active"><a href="#fruits" data-toggle="tab">Fruits</a></li> | [
"Creates",
"a",
"simple",
"bootstrap",
"tab",
"navigation",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L188-L192 |
1,440 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.bootstrap_list_badge_and_link_to | def bootstrap_list_badge_and_link_to(type, count, name, path)
html = content_tag(:div, bootstrap_badge_tag(type, count), class: 'pull-right') + name
bootstrap_list_link_to(html, path)
end | ruby | def bootstrap_list_badge_and_link_to(type, count, name, path)
html = content_tag(:div, bootstrap_badge_tag(type, count), class: 'pull-right') + name
bootstrap_list_link_to(html, path)
end | [
"def",
"bootstrap_list_badge_and_link_to",
"(",
"type",
",",
"count",
",",
"name",
",",
"path",
")",
"html",
"=",
"content_tag",
"(",
":div",
",",
"bootstrap_badge_tag",
"(",
"type",
",",
"count",
")",
",",
"class",
":",
"'pull-right'",
")",
"+",
"name",
"... | Convenience wrapper for a bootstrap_list_link_to with badge | [
"Convenience",
"wrapper",
"for",
"a",
"bootstrap_list_link_to",
"with",
"badge"
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L195-L198 |
1,441 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.bootstrap_progressbar_tag | def bootstrap_progressbar_tag(*args)
percentage = args[0].to_i
options = args[1] || {}
options.stringify_keys!
options['title'] ||= "#{percentage}%"
classes = ['progress']
classes << options.delete('class')
classes << 'progress-striped'
type = options.delete('type').to_... | ruby | def bootstrap_progressbar_tag(*args)
percentage = args[0].to_i
options = args[1] || {}
options.stringify_keys!
options['title'] ||= "#{percentage}%"
classes = ['progress']
classes << options.delete('class')
classes << 'progress-striped'
type = options.delete('type').to_... | [
"def",
"bootstrap_progressbar_tag",
"(",
"*",
"args",
")",
"percentage",
"=",
"args",
"[",
"0",
"]",
".",
"to_i",
"options",
"=",
"args",
"[",
"1",
"]",
"||",
"{",
"}",
"options",
".",
"stringify_keys!",
"options",
"[",
"'title'",
"]",
"||=",
"\"#{percen... | Creates a Boostrap progress bar.
==== Signatures
bootstrap_progressbar_tag(options)
==== Examples
<%= bootstrap_progressbar_tag(40) %>
# => <div class="progress progress-striped active" title="40%"><div class="progress-bar"
style="width:40%"></div></div>
<%= bootstrap_progressbar_tag(40), type: :d... | [
"Creates",
"a",
"Boostrap",
"progress",
"bar",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L330-L350 |
1,442 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.description_list_name_value_pair | def description_list_name_value_pair(name, value, blank_value_placeholder = nil)
# SECURE: TPG 2013-08-07: The output is sanitised by content_tag
return unless value.present? || blank_value_placeholder.present?
content_tag(:dt, name) +
content_tag(:dd, value || content_tag(:span, blank_value_p... | ruby | def description_list_name_value_pair(name, value, blank_value_placeholder = nil)
# SECURE: TPG 2013-08-07: The output is sanitised by content_tag
return unless value.present? || blank_value_placeholder.present?
content_tag(:dt, name) +
content_tag(:dd, value || content_tag(:span, blank_value_p... | [
"def",
"description_list_name_value_pair",
"(",
"name",
",",
"value",
",",
"blank_value_placeholder",
"=",
"nil",
")",
"# SECURE: TPG 2013-08-07: The output is sanitised by content_tag",
"return",
"unless",
"value",
".",
"present?",
"||",
"blank_value_placeholder",
".",
"pres... | This helper produces a pair of HTML dt, dd tags to display name and value pairs.
If a blank_value_placeholder is not defined then the pair are not shown if the
value is blank. Otherwise the placeholder is shown in the text-muted style.
==== Signature
description_list_name_value_pair(name, value, blank_value_pla... | [
"This",
"helper",
"produces",
"a",
"pair",
"of",
"HTML",
"dt",
"dd",
"tags",
"to",
"display",
"name",
"and",
"value",
"pairs",
".",
"If",
"a",
"blank_value_placeholder",
"is",
"not",
"defined",
"then",
"the",
"pair",
"are",
"not",
"shown",
"if",
"the",
"... | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L400-L405 |
1,443 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.details_link | def details_link(path, options = {})
return unless ndr_can?(:read, path)
link_to_with_icon({ icon: 'share-alt', title: 'Details', path: path }.merge(options))
end | ruby | def details_link(path, options = {})
return unless ndr_can?(:read, path)
link_to_with_icon({ icon: 'share-alt', title: 'Details', path: path }.merge(options))
end | [
"def",
"details_link",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"return",
"unless",
"ndr_can?",
"(",
":read",
",",
"path",
")",
"link_to_with_icon",
"(",
"{",
"icon",
":",
"'share-alt'",
",",
"title",
":",
"'Details'",
",",
"path",
":",
"path",
... | Creates a Boostrap 'Details' link.
==== Signatures
details_link(path, options = {})
==== Examples
<%= details_link('#') %>
# => <a title="Details" class="btn btn-default btn-xs" href="#">
<span class="glyphicon glyphicon-share-alt"></span>
</a> | [
"Creates",
"a",
"Boostrap",
"Details",
"link",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L450-L454 |
1,444 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.edit_link | def edit_link(path, options = {})
return unless ndr_can?(:edit, path)
path = edit_polymorphic_path(path) if path.is_a?(ActiveRecord::Base)
link_to_with_icon({ icon: 'pencil', title: 'Edit', path: path }.merge(options))
end | ruby | def edit_link(path, options = {})
return unless ndr_can?(:edit, path)
path = edit_polymorphic_path(path) if path.is_a?(ActiveRecord::Base)
link_to_with_icon({ icon: 'pencil', title: 'Edit', path: path }.merge(options))
end | [
"def",
"edit_link",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"return",
"unless",
"ndr_can?",
"(",
":edit",
",",
"path",
")",
"path",
"=",
"edit_polymorphic_path",
"(",
"path",
")",
"if",
"path",
".",
"is_a?",
"(",
"ActiveRecord",
"::",
"Base",
... | Creates a Boostrap 'Edit' link.
==== Signatures
edit_link(path, options = {})
==== Examples
<%= edit_link(#) %>
# => <a title="Edit" class="btn btn-default btn-xs" href="#">
<span class="glyphicon glyphicon-pencil"></span>
</a> | [
"Creates",
"a",
"Boostrap",
"Edit",
"link",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L469-L475 |
1,445 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.delete_link | def delete_link(path, options = {})
return unless ndr_can?(:delete, path)
defaults = {
icon: 'trash icon-white', title: 'Delete', path: path,
class: 'btn btn-xs btn-danger', method: :delete,
'data-confirm': I18n.translate(:'ndr_ui.confirm_delete', locale: options[:locale])
}
... | ruby | def delete_link(path, options = {})
return unless ndr_can?(:delete, path)
defaults = {
icon: 'trash icon-white', title: 'Delete', path: path,
class: 'btn btn-xs btn-danger', method: :delete,
'data-confirm': I18n.translate(:'ndr_ui.confirm_delete', locale: options[:locale])
}
... | [
"def",
"delete_link",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"return",
"unless",
"ndr_can?",
"(",
":delete",
",",
"path",
")",
"defaults",
"=",
"{",
"icon",
":",
"'trash icon-white'",
",",
"title",
":",
"'Delete'",
",",
"path",
":",
"path",
"... | Creates a Boostrap 'Delete' link.
==== Signatures
delete_link(path, options = {})
==== Examples
<%= delete_link('#') %>
# => <a title="Delete" class="btn btn-xs btn-danger" rel="nofollow" href="#"
data-method="delete" data-confirm="Are you sure?">
<span class="glyphicon glyphicon-tra... | [
"Creates",
"a",
"Boostrap",
"Delete",
"link",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L490-L500 |
1,446 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/bootstrap_helper.rb | NdrUi.BootstrapHelper.link_to_with_icon | def link_to_with_icon(options = {})
options[:class] ||= 'btn btn-default btn-xs'
icon = bootstrap_icon_tag(options.delete(:icon))
content = options.delete(:text) ? icon + ' ' + options[:title] : icon
link_to content, options.delete(:path), options
end | ruby | def link_to_with_icon(options = {})
options[:class] ||= 'btn btn-default btn-xs'
icon = bootstrap_icon_tag(options.delete(:icon))
content = options.delete(:text) ? icon + ' ' + options[:title] : icon
link_to content, options.delete(:path), options
end | [
"def",
"link_to_with_icon",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"[",
":class",
"]",
"||=",
"'btn btn-default btn-xs'",
"icon",
"=",
"bootstrap_icon_tag",
"(",
"options",
".",
"delete",
"(",
":icon",
")",
")",
"content",
"=",
"options",
".",
"delet... | Creates a Boostrap link with icon.
==== Signatures
link_to_with_icon(options)
==== Examples
<%= link_to_with_icon( { icon: 'trash icon-white', title: 'Delete', path: '#' } ) %>
# => <a title="Delete" class="btn btn-default btn-xs" href="#">
<span class="glyphicon glyphicon-trash icon-white"></s... | [
"Creates",
"a",
"Boostrap",
"link",
"with",
"icon",
"."
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/bootstrap_helper.rb#L540-L545 |
1,447 | benlund/ascii_charts | lib/ascii_charts.rb | AsciiCharts.Chart.round_value | def round_value(val)
remainder = val % self.step_size
unprecised = if (remainder * 2) >= self.step_size
(val - remainder) + self.step_size
else
val - remainder
end
if self.step_size < 1
precision = -Math.log10(... | ruby | def round_value(val)
remainder = val % self.step_size
unprecised = if (remainder * 2) >= self.step_size
(val - remainder) + self.step_size
else
val - remainder
end
if self.step_size < 1
precision = -Math.log10(... | [
"def",
"round_value",
"(",
"val",
")",
"remainder",
"=",
"val",
"%",
"self",
".",
"step_size",
"unprecised",
"=",
"if",
"(",
"remainder",
"*",
"2",
")",
">=",
"self",
".",
"step_size",
"(",
"val",
"-",
"remainder",
")",
"+",
"self",
".",
"step_size",
... | round to nearest step size, making sure we curtail precision to same order of magnitude as the step size to avoid 0.4 + 0.2 = 0.6000000000000001 | [
"round",
"to",
"nearest",
"step",
"size",
"making",
"sure",
"we",
"curtail",
"precision",
"to",
"same",
"order",
"of",
"magnitude",
"as",
"the",
"step",
"size",
"to",
"avoid",
"0",
".",
"4",
"+",
"0",
".",
"2",
"=",
"0",
".",
"6000000000000001"
] | c391b738c633910c22b96e04a36164a1fc4e1f22 | https://github.com/benlund/ascii_charts/blob/c391b738c633910c22b96e04a36164a1fc4e1f22/lib/ascii_charts.rb#L107-L120 |
1,448 | sdalu/ruby-ble | lib/ble/characteristic.rb | BLE.Characteristic._deserialize_value | def _deserialize_value(val, raw: false)
val = val.pack('C*')
val = @desc.post_process(val) if !raw && @desc.read_processors?
val
end | ruby | def _deserialize_value(val, raw: false)
val = val.pack('C*')
val = @desc.post_process(val) if !raw && @desc.read_processors?
val
end | [
"def",
"_deserialize_value",
"(",
"val",
",",
"raw",
":",
"false",
")",
"val",
"=",
"val",
".",
"pack",
"(",
"'C*'",
")",
"val",
"=",
"@desc",
".",
"post_process",
"(",
"val",
")",
"if",
"!",
"raw",
"&&",
"@desc",
".",
"read_processors?",
"val",
"end... | Convert Arrays of bytes returned by DBus to Strings of bytes. | [
"Convert",
"Arrays",
"of",
"bytes",
"returned",
"by",
"DBus",
"to",
"Strings",
"of",
"bytes",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/characteristic.rb#L97-L101 |
1,449 | PublicHealthEngland/ndr_ui | app/helpers/ndr_ui/css_helper.rb | NdrUi.CssHelper.css_class_options_merge | def css_class_options_merge(options, css_classes = [], &block)
options.symbolize_keys!
css_classes += options[:class].split(' ') if options.include?(:class)
yield(css_classes) if block_given?
options[:class] = css_classes.join(' ') unless css_classes.empty?
unless css_classes == css_classe... | ruby | def css_class_options_merge(options, css_classes = [], &block)
options.symbolize_keys!
css_classes += options[:class].split(' ') if options.include?(:class)
yield(css_classes) if block_given?
options[:class] = css_classes.join(' ') unless css_classes.empty?
unless css_classes == css_classe... | [
"def",
"css_class_options_merge",
"(",
"options",
",",
"css_classes",
"=",
"[",
"]",
",",
"&",
"block",
")",
"options",
".",
"symbolize_keys!",
"css_classes",
"+=",
"options",
"[",
":class",
"]",
".",
"split",
"(",
"' '",
")",
"if",
"options",
".",
"includ... | This method merges the specified css_classes into the options hash | [
"This",
"method",
"merges",
"the",
"specified",
"css_classes",
"into",
"the",
"options",
"hash"
] | 1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec | https://github.com/PublicHealthEngland/ndr_ui/blob/1fb8ef2eb8bfed43ff54cf4b9cafe53b3d1843ec/app/helpers/ndr_ui/css_helper.rb#L5-L15 |
1,450 | sdalu/ruby-ble | lib/ble/adapter.rb | BLE.Adapter.filter | def filter(uuids, rssi: nil, pathloss: nil, transport: :le)
unless [:auto, :bredr, :le].include?(transport)
raise ArgumentError,
"transport must be one of :auto, :bredr, :le"
end
filter = { }
unless uuids.nil? || uuids.empty?
filter['UUI... | ruby | def filter(uuids, rssi: nil, pathloss: nil, transport: :le)
unless [:auto, :bredr, :le].include?(transport)
raise ArgumentError,
"transport must be one of :auto, :bredr, :le"
end
filter = { }
unless uuids.nil? || uuids.empty?
filter['UUI... | [
"def",
"filter",
"(",
"uuids",
",",
"rssi",
":",
"nil",
",",
"pathloss",
":",
"nil",
",",
"transport",
":",
":le",
")",
"unless",
"[",
":auto",
",",
":bredr",
",",
":le",
"]",
".",
"include?",
"(",
"transport",
")",
"raise",
"ArgumentError",
",",
"\"... | This method sets the device discovery filter for the caller.
When this method is called with +nil+ or an empty list of UUIDs,
filter is removed.
@todo Need to sync with the adapter-api.txt
@param uuids a list of uuid to filter on
@param rssi RSSI threshold
@param pathloss pathloss threshold
@param tr... | [
"This",
"method",
"sets",
"the",
"device",
"discovery",
"filter",
"for",
"the",
"caller",
".",
"When",
"this",
"method",
"is",
"called",
"with",
"+",
"nil",
"+",
"or",
"an",
"empty",
"list",
"of",
"UUIDs",
"filter",
"is",
"removed",
"."
] | 4c3b32d0ee65f787be235f1a5ee3878e6dcd995a | https://github.com/sdalu/ruby-ble/blob/4c3b32d0ee65f787be235f1a5ee3878e6dcd995a/lib/ble/adapter.rb#L90-L113 |
1,451 | cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.stub_with_file | def stub_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
stub(content)
end | ruby | def stub_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
stub(content)
end | [
"def",
"stub_with_file",
"(",
"filename",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"content",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
"file",
"|",
"file",
".",
"... | Create a stub using the information in the provided filename. | [
"Create",
"a",
"stub",
"using",
"the",
"information",
"in",
"the",
"provided",
"filename",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L119-L124 |
1,452 | cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.stub_with_erb | def stub_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
stub(erb_content)
end | ruby | def stub_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
stub(erb_content)
end | [
"def",
"stub_with_erb",
"(",
"filename",
",",
"hsh",
"=",
"{",
"}",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"template",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
... | Create a stub using the erb template provided. The +Hash+ second
parameter contains the values to be inserted into the +ERB+. | [
"Create",
"a",
"stub",
"using",
"the",
"erb",
"template",
"provided",
".",
"The",
"+",
"Hash",
"+",
"second",
"parameter",
"contains",
"the",
"values",
"to",
"be",
"inserted",
"into",
"the",
"+",
"ERB",
"+",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L130-L136 |
1,453 | cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count | def count(request_criteria)
return if ::ServiceMock.disable_stubs
yield self if block_given?
JSON.parse(http.post('/__admin/requests/count', request_criteria).body)['count']
end | ruby | def count(request_criteria)
return if ::ServiceMock.disable_stubs
yield self if block_given?
JSON.parse(http.post('/__admin/requests/count', request_criteria).body)['count']
end | [
"def",
"count",
"(",
"request_criteria",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"JSON",
".",
"parse",
"(",
"http",
".",
"post",
"(",
"'/__admin/requests/count'",
",",
"request_criteria",
")",
".",
... | Get the count for the request criteria | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria"
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L141-L145 |
1,454 | cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count_with_file | def count_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
count(content)
end | ruby | def count_with_file(filename)
return if ::ServiceMock.disable_stubs
yield self if block_given?
content = File.open(filename, 'rb') { |file| file.read }
count(content)
end | [
"def",
"count_with_file",
"(",
"filename",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"content",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",
"file",
"|",
"file",
".",
... | Get the count for the request criteria in the provided filename. | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria",
"in",
"the",
"provided",
"filename",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L150-L155 |
1,455 | cheezy/service_mock | lib/service_mock/server.rb | ServiceMock.Server.count_with_erb | def count_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
count(erb_content)
end | ruby | def count_with_erb(filename, hsh={})
return if ::ServiceMock.disable_stubs
yield self if block_given?
template = File.open(filename, 'rb') { |file| file.read }
erb_content = ERB.new(template).result(data_binding(hsh))
count(erb_content)
end | [
"def",
"count_with_erb",
"(",
"filename",
",",
"hsh",
"=",
"{",
"}",
")",
"return",
"if",
"::",
"ServiceMock",
".",
"disable_stubs",
"yield",
"self",
"if",
"block_given?",
"template",
"=",
"File",
".",
"open",
"(",
"filename",
",",
"'rb'",
")",
"{",
"|",... | Get the count for the request criteria using the erb template
provided. The +Hash+ second parameter contains the values to be
inserted into the +ERB+. | [
"Get",
"the",
"count",
"for",
"the",
"request",
"criteria",
"using",
"the",
"erb",
"template",
"provided",
".",
"The",
"+",
"Hash",
"+",
"second",
"parameter",
"contains",
"the",
"values",
"to",
"be",
"inserted",
"into",
"the",
"+",
"ERB",
"+",
"."
] | 8ca498008a02b3bd3be2e6327b051caac6112f52 | https://github.com/cheezy/service_mock/blob/8ca498008a02b3bd3be2e6327b051caac6112f52/lib/service_mock/server.rb#L162-L168 |
1,456 | gosu/ashton | lib/ashton/texture.rb | Ashton.Texture.clear | def clear(options = {})
options = {
color: [0.0, 0.0, 0.0, 0.0],
}.merge! options
color = options[:color]
color = color.to_opengl if color.is_a? Gosu::Color
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
Gl.glDisable Gl::GL_BLEND # Need to repla... | ruby | def clear(options = {})
options = {
color: [0.0, 0.0, 0.0, 0.0],
}.merge! options
color = options[:color]
color = color.to_opengl if color.is_a? Gosu::Color
Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, fbo_id unless rendering?
Gl.glDisable Gl::GL_BLEND # Need to repla... | [
"def",
"clear",
"(",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"color",
":",
"[",
"0.0",
",",
"0.0",
",",
"0.0",
",",
"0.0",
"]",
",",
"}",
".",
"merge!",
"options",
"color",
"=",
"options",
"[",
":color",
"]",
"color",
"=",
"color",
... | Clears the buffer, optionally to a specific color.
@option options :color [Gosu::Color, Array<Float>] (transparent) | [
"Clears",
"the",
"buffer",
"optionally",
"to",
"a",
"specific",
"color",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/texture.rb#L93-L111 |
1,457 | mguinada/vlc-client | lib/vlc-client/connection.rb | VLC.Connection.write | def write(data, fire_and_forget = true)
raise NotConnectedError, "no connection to server" unless connected?
@socket.puts(data)
@socket.flush
return true if fire_and_forget
read
rescue Errno::EPIPE
disconnect
raise BrokenConnectionError, "the connection to the server is l... | ruby | def write(data, fire_and_forget = true)
raise NotConnectedError, "no connection to server" unless connected?
@socket.puts(data)
@socket.flush
return true if fire_and_forget
read
rescue Errno::EPIPE
disconnect
raise BrokenConnectionError, "the connection to the server is l... | [
"def",
"write",
"(",
"data",
",",
"fire_and_forget",
"=",
"true",
")",
"raise",
"NotConnectedError",
",",
"\"no connection to server\"",
"unless",
"connected?",
"@socket",
".",
"puts",
"(",
"data",
")",
"@socket",
".",
"flush",
"return",
"true",
"if",
"fire_and_... | Writes data to the TCP server socket
@param data the data to write
@param fire_and_forget if true, no response response is expected from server,
when false, a response from the server will be returned.
@return the server response data if there is one | [
"Writes",
"data",
"to",
"the",
"TCP",
"server",
"socket"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/connection.rb#L52-L63 |
1,458 | mguinada/vlc-client | lib/vlc-client/connection.rb | VLC.Connection.read | def read(timeout=nil)
timeout = read_timeout if timeout.nil?
raw_data = nil
Timeout.timeout(timeout) do
raw_data = @socket.gets.chomp
end
if (data = parse_raw_data(raw_data))
data[1]
else
raise VLC::ProtocolError, "could not interpret the playload: #{raw_dat... | ruby | def read(timeout=nil)
timeout = read_timeout if timeout.nil?
raw_data = nil
Timeout.timeout(timeout) do
raw_data = @socket.gets.chomp
end
if (data = parse_raw_data(raw_data))
data[1]
else
raise VLC::ProtocolError, "could not interpret the playload: #{raw_dat... | [
"def",
"read",
"(",
"timeout",
"=",
"nil",
")",
"timeout",
"=",
"read_timeout",
"if",
"timeout",
".",
"nil?",
"raw_data",
"=",
"nil",
"Timeout",
".",
"timeout",
"(",
"timeout",
")",
"do",
"raw_data",
"=",
"@socket",
".",
"gets",
".",
"chomp",
"end",
"i... | Reads data from the TCP server
@param timeout read timeout value for a read operation.
If omited the configured value or DEFAULT_READ_TIMEOUT will be used.
@return [String] the data | [
"Reads",
"data",
"from",
"the",
"TCP",
"server"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/connection.rb#L73-L88 |
1,459 | gosu/ashton | lib/ashton/gosu_ext/window.rb | Gosu.Window.post_process | def post_process(*shaders)
raise ArgumentError, "Block required" unless block_given?
raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }
# In case no shaders are passed, just run the contents of the block.
unless shaders.size > 0
yield
... | ruby | def post_process(*shaders)
raise ArgumentError, "Block required" unless block_given?
raise TypeError, "Can only process with Shaders" unless shaders.all? {|s| s.is_a? Ashton::Shader }
# In case no shaders are passed, just run the contents of the block.
unless shaders.size > 0
yield
... | [
"def",
"post_process",
"(",
"*",
"shaders",
")",
"raise",
"ArgumentError",
",",
"\"Block required\"",
"unless",
"block_given?",
"raise",
"TypeError",
",",
"\"Can only process with Shaders\"",
"unless",
"shaders",
".",
"all?",
"{",
"|",
"s",
"|",
"s",
".",
"is_a?",... | Full screen post-processing using a fragment shader.
Variables set for you in the fragment shader:
uniform sampler2D in_Texture; // Texture containing the screen image. | [
"Full",
"screen",
"post",
"-",
"processing",
"using",
"a",
"fragment",
"shader",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/gosu_ext/window.rb#L45-L77 |
1,460 | joeyAghion/spidey | lib/spidey/abstract_spider.rb | Spidey.AbstractSpider.each_url | def each_url(&_block)
index = 0
while index < urls.count # urls grows dynamically, don't use &:each
url = urls[index]
next unless url
yield url, handlers[url].first, handlers[url].last
index += 1
end
end | ruby | def each_url(&_block)
index = 0
while index < urls.count # urls grows dynamically, don't use &:each
url = urls[index]
next unless url
yield url, handlers[url].first, handlers[url].last
index += 1
end
end | [
"def",
"each_url",
"(",
"&",
"_block",
")",
"index",
"=",
"0",
"while",
"index",
"<",
"urls",
".",
"count",
"# urls grows dynamically, don't use &:each",
"url",
"=",
"urls",
"[",
"index",
"]",
"next",
"unless",
"url",
"yield",
"url",
",",
"handlers",
"[",
... | Override this for custom storage or prioritization of crawled URLs.
Iterates through URL queue, yielding the URL, handler, and default data. | [
"Override",
"this",
"for",
"custom",
"storage",
"or",
"prioritization",
"of",
"crawled",
"URLs",
".",
"Iterates",
"through",
"URL",
"queue",
"yielding",
"the",
"URL",
"handler",
"and",
"default",
"data",
"."
] | 4fe6daf8bd6b1c1c96a3f3de4ffeb4fe1d3c24ac | https://github.com/joeyAghion/spidey/blob/4fe6daf8bd6b1c1c96a3f3de4ffeb4fe1d3c24ac/lib/spidey/abstract_spider.rb#L56-L64 |
1,461 | gosu/ashton | lib/ashton/gosu_ext/image.rb | Gosu.Image.draw_as_points | def draw_as_points(points, z, options = {})
color = options[:color] || DEFAULT_DRAW_COLOR
scale = options[:scale] || 1.0
shader = options[:shader]
mode = options[:mode] || :default
if shader
shader.enable z
$window.gl z do
shader.image = self
shader.col... | ruby | def draw_as_points(points, z, options = {})
color = options[:color] || DEFAULT_DRAW_COLOR
scale = options[:scale] || 1.0
shader = options[:shader]
mode = options[:mode] || :default
if shader
shader.enable z
$window.gl z do
shader.image = self
shader.col... | [
"def",
"draw_as_points",
"(",
"points",
",",
"z",
",",
"options",
"=",
"{",
"}",
")",
"color",
"=",
"options",
"[",
":color",
"]",
"||",
"DEFAULT_DRAW_COLOR",
"scale",
"=",
"options",
"[",
":scale",
"]",
"||",
"1.0",
"shader",
"=",
"options",
"[",
":sh... | Draw a list of centred sprites by position.
@param points [Array<Array>] Array of [x, y] positions
@param z [Float] Z-order to draw - Ignored if shader is used.
@option options :scale [Float] (1.0) Relative size of the sprites
@option options :shader [Ashton::Shader] Shader to apply to all sprites.
TODO: Need to... | [
"Draw",
"a",
"list",
"of",
"centred",
"sprites",
"by",
"position",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/gosu_ext/image.rb#L64-L85 |
1,462 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_distance | def sample_distance(x, y)
x = [[x, width - 1].min, 0].max
y = [[y, height - 1].min, 0].max
# Could be checking any of red/blue/green.
@field.red((x / @scale).round, (y / @scale).round) - ZERO_DISTANCE
end | ruby | def sample_distance(x, y)
x = [[x, width - 1].min, 0].max
y = [[y, height - 1].min, 0].max
# Could be checking any of red/blue/green.
@field.red((x / @scale).round, (y / @scale).round) - ZERO_DISTANCE
end | [
"def",
"sample_distance",
"(",
"x",
",",
"y",
")",
"x",
"=",
"[",
"[",
"x",
",",
"width",
"-",
"1",
"]",
".",
"min",
",",
"0",
"]",
".",
"max",
"y",
"=",
"[",
"[",
"y",
",",
"height",
"-",
"1",
"]",
".",
"min",
",",
"0",
"]",
".",
"max"... | If positive, distance, in pixels, to the nearest opaque pixel.
If negative, distance in pixels to the nearest transparent pixel. | [
"If",
"positive",
"distance",
"in",
"pixels",
"to",
"the",
"nearest",
"opaque",
"pixel",
".",
"If",
"negative",
"distance",
"in",
"pixels",
"to",
"the",
"nearest",
"transparent",
"pixel",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L47-L52 |
1,463 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_gradient | def sample_gradient(x, y)
d0 = sample_distance x, y - 1
d1 = sample_distance x - 1, y
d2 = sample_distance x + 1, y
d3 = sample_distance x, y + 1
[(d2 - d1) / @scale, (d3 - d0) / @scale]
end | ruby | def sample_gradient(x, y)
d0 = sample_distance x, y - 1
d1 = sample_distance x - 1, y
d2 = sample_distance x + 1, y
d3 = sample_distance x, y + 1
[(d2 - d1) / @scale, (d3 - d0) / @scale]
end | [
"def",
"sample_gradient",
"(",
"x",
",",
"y",
")",
"d0",
"=",
"sample_distance",
"x",
",",
"y",
"-",
"1",
"d1",
"=",
"sample_distance",
"x",
"-",
"1",
",",
"y",
"d2",
"=",
"sample_distance",
"x",
"+",
"1",
",",
"y",
"d3",
"=",
"sample_distance",
"x... | Gets the gradient of the field at a given point.
@return [Float, Float] gradient_x, gradient_y | [
"Gets",
"the",
"gradient",
"of",
"the",
"field",
"at",
"a",
"given",
"point",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L56-L63 |
1,464 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.sample_normal | def sample_normal(x, y)
gradient_x, gradient_y = sample_gradient x, y
length = Gosu::distance 0, 0, gradient_x, gradient_y
if length == 0
[0, 0] # This could be NaN in edge cases.
else
[gradient_x / length, gradient_y / length]
end
end | ruby | def sample_normal(x, y)
gradient_x, gradient_y = sample_gradient x, y
length = Gosu::distance 0, 0, gradient_x, gradient_y
if length == 0
[0, 0] # This could be NaN in edge cases.
else
[gradient_x / length, gradient_y / length]
end
end | [
"def",
"sample_normal",
"(",
"x",
",",
"y",
")",
"gradient_x",
",",
"gradient_y",
"=",
"sample_gradient",
"x",
",",
"y",
"length",
"=",
"Gosu",
"::",
"distance",
"0",
",",
"0",
",",
"gradient_x",
",",
"gradient_y",
"if",
"length",
"==",
"0",
"[",
"0",
... | Get the normal at a given point.
@return [Float, Float] normal_x, normal_y | [
"Get",
"the",
"normal",
"at",
"a",
"given",
"point",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L67-L75 |
1,465 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.line_of_sight_blocked_at | def line_of_sight_blocked_at(x1, y1, x2, y2)
distance_to_travel = Gosu::distance x1, y1, x2, y2
distance_x, distance_y = x2 - x1, y2 - y1
distance_travelled = 0
x, y = x1, y1
loop do
distance = sample_distance x, y
# Blocked?
return [x, y] if distance <= 0
... | ruby | def line_of_sight_blocked_at(x1, y1, x2, y2)
distance_to_travel = Gosu::distance x1, y1, x2, y2
distance_x, distance_y = x2 - x1, y2 - y1
distance_travelled = 0
x, y = x1, y1
loop do
distance = sample_distance x, y
# Blocked?
return [x, y] if distance <= 0
... | [
"def",
"line_of_sight_blocked_at",
"(",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
")",
"distance_to_travel",
"=",
"Gosu",
"::",
"distance",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
"distance_x",
",",
"distance_y",
"=",
"x2",
"-",
"x1",
",",
"y2",
"-",
"y1... | Returns blocking position, else nil if line of sight isn't blocked. | [
"Returns",
"blocking",
"position",
"else",
"nil",
"if",
"line",
"of",
"sight",
"isn",
"t",
"blocked",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L83-L104 |
1,466 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.render_field | def render_field
raise ArgumentError, "Block required" unless block_given?
@mask.render do
@mask.clear
$window.scale 1.0 / @scale do
yield self
end
end
@shader.enable do
@field.render do
@mask.draw 0, 0, 0
end
end
nil
... | ruby | def render_field
raise ArgumentError, "Block required" unless block_given?
@mask.render do
@mask.clear
$window.scale 1.0 / @scale do
yield self
end
end
@shader.enable do
@field.render do
@mask.draw 0, 0, 0
end
end
nil
... | [
"def",
"render_field",
"raise",
"ArgumentError",
",",
"\"Block required\"",
"unless",
"block_given?",
"@mask",
".",
"render",
"do",
"@mask",
".",
"clear",
"$window",
".",
"scale",
"1.0",
"/",
"@scale",
"do",
"yield",
"self",
"end",
"end",
"@shader",
".",
"enab... | Update the SDF should the image have changed.
Draw the mask in the passed block. | [
"Update",
"the",
"SDF",
"should",
"the",
"image",
"have",
"changed",
".",
"Draw",
"the",
"mask",
"in",
"the",
"passed",
"block",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L108-L125 |
1,467 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.draw | def draw(x, y, z, options = {})
options = {
mode: :add,
}.merge! options
$window.scale @scale do
@field.draw x, y, z, options
end
nil
end | ruby | def draw(x, y, z, options = {})
options = {
mode: :add,
}.merge! options
$window.scale @scale do
@field.draw x, y, z, options
end
nil
end | [
"def",
"draw",
"(",
"x",
",",
"y",
",",
"z",
",",
"options",
"=",
"{",
"}",
")",
"options",
"=",
"{",
"mode",
":",
":add",
",",
"}",
".",
"merge!",
"options",
"$window",
".",
"scale",
"@scale",
"do",
"@field",
".",
"draw",
"x",
",",
"y",
",",
... | Draw the field, usually for debugging purposes.
@see Ashton::Texture#draw | [
"Draw",
"the",
"field",
"usually",
"for",
"debugging",
"purposes",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L129-L139 |
1,468 | gosu/ashton | lib/ashton/signed_distance_field.rb | Ashton.SignedDistanceField.to_a | def to_a
width.times.map do |x|
height.times.map do |y|
sample_distance x, y
end
end
end | ruby | def to_a
width.times.map do |x|
height.times.map do |y|
sample_distance x, y
end
end
end | [
"def",
"to_a",
"width",
".",
"times",
".",
"map",
"do",
"|",
"x",
"|",
"height",
".",
"times",
".",
"map",
"do",
"|",
"y",
"|",
"sample_distance",
"x",
",",
"y",
"end",
"end",
"end"
] | Convert into a nested array of sample values.
@return [Array<Array<Integer>>] | [
"Convert",
"into",
"a",
"nested",
"array",
"of",
"sample",
"values",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/signed_distance_field.rb#L143-L149 |
1,469 | mguinada/vlc-client | lib/vlc-client/server.rb | VLC.Server.start | def start(detached = false)
return @pid if running?
detached ? @deamon = true : setup_traps
@pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
end | ruby | def start(detached = false)
return @pid if running?
detached ? @deamon = true : setup_traps
@pid = RUBY_VERSION >= '1.9' ? process_spawn(detached) : process_spawn_ruby_1_8(detached)
end | [
"def",
"start",
"(",
"detached",
"=",
"false",
")",
"return",
"@pid",
"if",
"running?",
"detached",
"?",
"@deamon",
"=",
"true",
":",
"setup_traps",
"@pid",
"=",
"RUBY_VERSION",
">=",
"'1.9'",
"?",
"process_spawn",
"(",
"detached",
")",
":",
"process_spawn_r... | Starts a VLC instance in a subprocess
@param [Boolean] detached if true VLC will be started as a deamon process.
Defaults to false.
@return [Integer] the subprocess PID
@see #daemonize | [
"Starts",
"a",
"VLC",
"instance",
"in",
"a",
"subprocess"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/server.rb#L48-L54 |
1,470 | mguinada/vlc-client | lib/vlc-client/server.rb | VLC.Server.process_spawn_ruby_1_8 | def process_spawn_ruby_1_8(detached)
rd, wr = IO.pipe
if Process.fork #parent
wr.close
pid = rd.read.to_i
rd.close
return pid
else #child
rd.close
detach if detached #daemonization
wr.write(Process.pid)
wr.close
... | ruby | def process_spawn_ruby_1_8(detached)
rd, wr = IO.pipe
if Process.fork #parent
wr.close
pid = rd.read.to_i
rd.close
return pid
else #child
rd.close
detach if detached #daemonization
wr.write(Process.pid)
wr.close
... | [
"def",
"process_spawn_ruby_1_8",
"(",
"detached",
")",
"rd",
",",
"wr",
"=",
"IO",
".",
"pipe",
"if",
"Process",
".",
"fork",
"#parent",
"wr",
".",
"close",
"pid",
"=",
"rd",
".",
"read",
".",
"to_i",
"rd",
".",
"close",
"return",
"pid",
"else",
"#ch... | For ruby 1.8 | [
"For",
"ruby",
"1",
".",
"8"
] | e619bc11ab40deb8ae40878e011d67d05d6db73d | https://github.com/mguinada/vlc-client/blob/e619bc11ab40deb8ae40878e011d67d05d6db73d/lib/vlc-client/server.rb#L118-L140 |
1,471 | shoes/furoshiki | lib/furoshiki/configuration.rb | Furoshiki.Configuration.merge_config | def merge_config(config)
defaults = {
name: 'Ruby App',
version: '0.0.0',
release: 'Rookie',
ignore: 'pkg',
# TODO: Establish these default icons and paths. These would be
# default icons for generic Ruby apps.
icons: {
#osx: 'path/to/default/App.i... | ruby | def merge_config(config)
defaults = {
name: 'Ruby App',
version: '0.0.0',
release: 'Rookie',
ignore: 'pkg',
# TODO: Establish these default icons and paths. These would be
# default icons for generic Ruby apps.
icons: {
#osx: 'path/to/default/App.i... | [
"def",
"merge_config",
"(",
"config",
")",
"defaults",
"=",
"{",
"name",
":",
"'Ruby App'",
",",
"version",
":",
"'0.0.0'",
",",
"release",
":",
"'Rookie'",
",",
"ignore",
":",
"'pkg'",
",",
"# TODO: Establish these default icons and paths. These would be",
"# defau... | Overwrite defaults with supplied config | [
"Overwrite",
"defaults",
"with",
"supplied",
"config"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/configuration.rb#L103-L125 |
1,472 | gosu/ashton | lib/ashton/window_buffer.rb | Ashton.WindowBuffer.capture | def capture
Gl.glBindTexture Gl::GL_TEXTURE_2D, id
Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
self
end | ruby | def capture
Gl.glBindTexture Gl::GL_TEXTURE_2D, id
Gl.glCopyTexImage2D Gl::GL_TEXTURE_2D, 0, Gl::GL_RGBA8, 0, 0, width, height, 0
self
end | [
"def",
"capture",
"Gl",
".",
"glBindTexture",
"Gl",
"::",
"GL_TEXTURE_2D",
",",
"id",
"Gl",
".",
"glCopyTexImage2D",
"Gl",
"::",
"GL_TEXTURE_2D",
",",
"0",
",",
"Gl",
"::",
"GL_RGBA8",
",",
"0",
",",
"0",
",",
"width",
",",
"height",
",",
"0",
"self",
... | Copy the window contents into the buffer. | [
"Copy",
"the",
"window",
"contents",
"into",
"the",
"buffer",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/window_buffer.rb#L10-L14 |
1,473 | gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.[]= | def []=(uniform, value)
uniform = uniform_name_from_symbol(uniform) if uniform.is_a? Symbol
# Ensure that the program is current before setting values.
needs_use = !current?
enable if needs_use
set_uniform uniform_location(uniform), value
disable if needs_use
value
end | ruby | def []=(uniform, value)
uniform = uniform_name_from_symbol(uniform) if uniform.is_a? Symbol
# Ensure that the program is current before setting values.
needs_use = !current?
enable if needs_use
set_uniform uniform_location(uniform), value
disable if needs_use
value
end | [
"def",
"[]=",
"(",
"uniform",
",",
"value",
")",
"uniform",
"=",
"uniform_name_from_symbol",
"(",
"uniform",
")",
"if",
"uniform",
".",
"is_a?",
"Symbol",
"# Ensure that the program is current before setting values.",
"needs_use",
"=",
"!",
"current?",
"enable",
"if",... | Set the value of a uniform.
@param uniform [String, Symbol] If a Symbol, :frog_paste is looked up as "in_FrogPaste", otherwise the Sting is used directly.
@param value [Any] Value to set the uniform to
@raise ShaderUniformError unless requested uniform is defined in vertex or fragment shaders. | [
"Set",
"the",
"value",
"of",
"a",
"uniform",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L159-L169 |
1,474 | gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.set_uniform | def set_uniform(location, value)
raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?
return if location == INVALID_LOCATION # Not for end-users :)
case value
when true, Gl::GL_TRUE
Gl.glUniform1i location, 1
... | ruby | def set_uniform(location, value)
raise ShaderUniformError, "Shader uniform #{location.inspect} could not be set, since shader is not current" unless current?
return if location == INVALID_LOCATION # Not for end-users :)
case value
when true, Gl::GL_TRUE
Gl.glUniform1i location, 1
... | [
"def",
"set_uniform",
"(",
"location",
",",
"value",
")",
"raise",
"ShaderUniformError",
",",
"\"Shader uniform #{location.inspect} could not be set, since shader is not current\"",
"unless",
"current?",
"return",
"if",
"location",
"==",
"INVALID_LOCATION",
"# Not for end-users :... | Set uniform without trying to force use of the program. | [
"Set",
"uniform",
"without",
"trying",
"to",
"force",
"use",
"of",
"the",
"program",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L173-L235 |
1,475 | gosu/ashton | lib/ashton/shader.rb | Ashton.Shader.process_source | def process_source(shader, extension)
source = if shader.is_a? Symbol
file = File.expand_path "#{shader}#{extension}", BUILT_IN_SHADER_PATH
unless File.exist? file
raise ShaderLoadError, "Failed to load built-in shader: #{shader.inspect}"
end
... | ruby | def process_source(shader, extension)
source = if shader.is_a? Symbol
file = File.expand_path "#{shader}#{extension}", BUILT_IN_SHADER_PATH
unless File.exist? file
raise ShaderLoadError, "Failed to load built-in shader: #{shader.inspect}"
end
... | [
"def",
"process_source",
"(",
"shader",
",",
"extension",
")",
"source",
"=",
"if",
"shader",
".",
"is_a?",
"Symbol",
"file",
"=",
"File",
".",
"expand_path",
"\"#{shader}#{extension}\"",
",",
"BUILT_IN_SHADER_PATH",
"unless",
"File",
".",
"exist?",
"file",
"rai... | Symbol => load a built-in
Filename => load file
Source => use directly.
Also recursively replaces #include
TODO: What about line numbers getting messed up by #include? | [
"Symbol",
"=",
">",
"load",
"a",
"built",
"-",
"in",
"Filename",
"=",
">",
"load",
"file",
"Source",
"=",
">",
"use",
"directly",
"."
] | 313673d8b1b3e1082c9d24e4a166396d1f471634 | https://github.com/gosu/ashton/blob/313673d8b1b3e1082c9d24e4a166396d1f471634/lib/ashton/shader.rb#L352-L367 |
1,476 | shoes/furoshiki | lib/furoshiki/util.rb | Furoshiki.Util.deep_set_symbol_key | def deep_set_symbol_key(hash, key, value)
if value.kind_of? Hash
hash[key.to_sym] = value.inject({}) { |inner_hash, (inner_key, inner_value)| deep_set_symbol_key(inner_hash, inner_key, inner_value) }
else
hash[key.to_sym] = value
end
hash
end | ruby | def deep_set_symbol_key(hash, key, value)
if value.kind_of? Hash
hash[key.to_sym] = value.inject({}) { |inner_hash, (inner_key, inner_value)| deep_set_symbol_key(inner_hash, inner_key, inner_value) }
else
hash[key.to_sym] = value
end
hash
end | [
"def",
"deep_set_symbol_key",
"(",
"hash",
",",
"key",
",",
"value",
")",
"if",
"value",
".",
"kind_of?",
"Hash",
"hash",
"[",
"key",
".",
"to_sym",
"]",
"=",
"value",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"inner_hash",
",",
"(",
"inner_key",
... | Ensure symbol keys, even in nested hashes
@param [Hash] config the hash to set (key: value) on
@param [#to_sym] k the key
@param [Object] v the value
@return [Hash] an updated hash | [
"Ensure",
"symbol",
"keys",
"even",
"in",
"nested",
"hashes"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/util.rb#L9-L16 |
1,477 | shoes/furoshiki | lib/furoshiki/util.rb | Furoshiki.Util.merge_with_symbolized_keys | def merge_with_symbolized_keys(defaults, hash)
hash.inject(defaults) { |symbolized, (k, v)| deep_set_symbol_key(symbolized, k, v) }
end | ruby | def merge_with_symbolized_keys(defaults, hash)
hash.inject(defaults) { |symbolized, (k, v)| deep_set_symbol_key(symbolized, k, v) }
end | [
"def",
"merge_with_symbolized_keys",
"(",
"defaults",
",",
"hash",
")",
"hash",
".",
"inject",
"(",
"defaults",
")",
"{",
"|",
"symbolized",
",",
"(",
"k",
",",
"v",
")",
"|",
"deep_set_symbol_key",
"(",
"symbolized",
",",
"k",
",",
"v",
")",
"}",
"end... | Assumes that defaults already has symbolized keys | [
"Assumes",
"that",
"defaults",
"already",
"has",
"symbolized",
"keys"
] | ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb | https://github.com/shoes/furoshiki/blob/ead3a1d38bcac23cc13f1bf3e31cc40fdd75b2eb/lib/furoshiki/util.rb#L23-L25 |
1,478 | abates/ruby_expect | lib/ruby_expect/expect.rb | RubyExpect.Expect.expect | def expect *patterns, &block
@logger.debug("Expecting: #{patterns.inspect}") if @logger.debug?
patterns = pattern_escape(*patterns)
@end_time = 0
if (@timeout != 0)
@end_time = Time.now + @timeout
end
@before = ''
matched_index = nil
while (@end_time == 0 || Time... | ruby | def expect *patterns, &block
@logger.debug("Expecting: #{patterns.inspect}") if @logger.debug?
patterns = pattern_escape(*patterns)
@end_time = 0
if (@timeout != 0)
@end_time = Time.now + @timeout
end
@before = ''
matched_index = nil
while (@end_time == 0 || Time... | [
"def",
"expect",
"*",
"patterns",
",",
"&",
"block",
"@logger",
".",
"debug",
"(",
"\"Expecting: #{patterns.inspect}\"",
")",
"if",
"@logger",
".",
"debug?",
"patterns",
"=",
"pattern_escape",
"(",
"patterns",
")",
"@end_time",
"=",
"0",
"if",
"(",
"@timeout",... | Wait until either the timeout occurs or one of the given patterns is seen
in the input. Upon a match, the property before is assigned all input in
the accumulator before the match, the matched string itself is assigned to
the match property and an optional block is called
The method will return the index of the m... | [
"Wait",
"until",
"either",
"the",
"timeout",
"occurs",
"or",
"one",
"of",
"the",
"given",
"patterns",
"is",
"seen",
"in",
"the",
"input",
".",
"Upon",
"a",
"match",
"the",
"property",
"before",
"is",
"assigned",
"all",
"input",
"in",
"the",
"accumulator",
... | 3c0cf66b90f79173b799f2df4195cf60815ea242 | https://github.com/abates/ruby_expect/blob/3c0cf66b90f79173b799f2df4195cf60815ea242/lib/ruby_expect/expect.rb#L260-L294 |
1,479 | abates/ruby_expect | lib/ruby_expect/expect.rb | RubyExpect.Expect.pattern_escape | def pattern_escape *patterns
escaped_patterns = []
patterns.each do |pattern|
if (pattern.is_a?(String))
pattern = Regexp.new(Regexp.escape(pattern))
elsif (! pattern.is_a?(Regexp))
raise "Don't know how to match on a #{pattern.class}"
end
... | ruby | def pattern_escape *patterns
escaped_patterns = []
patterns.each do |pattern|
if (pattern.is_a?(String))
pattern = Regexp.new(Regexp.escape(pattern))
elsif (! pattern.is_a?(Regexp))
raise "Don't know how to match on a #{pattern.class}"
end
... | [
"def",
"pattern_escape",
"*",
"patterns",
"escaped_patterns",
"=",
"[",
"]",
"patterns",
".",
"each",
"do",
"|",
"pattern",
"|",
"if",
"(",
"pattern",
".",
"is_a?",
"(",
"String",
")",
")",
"pattern",
"=",
"Regexp",
".",
"new",
"(",
"Regexp",
".",
"esc... | This method will convert any strings in the argument list to regular
expressions that search for the literal string
+patterns+::
List of patterns to escape | [
"This",
"method",
"will",
"convert",
"any",
"strings",
"in",
"the",
"argument",
"list",
"to",
"regular",
"expressions",
"that",
"search",
"for",
"the",
"literal",
"string"
] | 3c0cf66b90f79173b799f2df4195cf60815ea242 | https://github.com/abates/ruby_expect/blob/3c0cf66b90f79173b799f2df4195cf60815ea242/lib/ruby_expect/expect.rb#L409-L420 |
1,480 | mech/filemaker-ruby | lib/filemaker/server.rb | Filemaker.Server.serialize_args | def serialize_args(args)
return {} if args.nil?
args.each do |key, value|
case value
when DateTime, Time
args[key] = value.strftime('%m/%d/%Y %H:%M:%S')
when Date
args[key] = value.strftime('%m/%d/%Y')
else
# Especially for range operator (...),... | ruby | def serialize_args(args)
return {} if args.nil?
args.each do |key, value|
case value
when DateTime, Time
args[key] = value.strftime('%m/%d/%Y %H:%M:%S')
when Date
args[key] = value.strftime('%m/%d/%Y')
else
# Especially for range operator (...),... | [
"def",
"serialize_args",
"(",
"args",
")",
"return",
"{",
"}",
"if",
"args",
".",
"nil?",
"args",
".",
"each",
"do",
"|",
"key",
",",
"value",
"|",
"case",
"value",
"when",
"DateTime",
",",
"Time",
"args",
"[",
"key",
"]",
"=",
"value",
".",
"strft... | {"-db"=>"mydb", "-lay"=>"mylay", "email"=>"a@b.com", "updated_at": Date}
Take Ruby type and serialize into a form FileMaker can understand | [
"{",
"-",
"db",
"=",
">",
"mydb",
"-",
"lay",
"=",
">",
"mylay",
"email",
"=",
">",
"a"
] | 75bb9eaf467546b2404bcb79267f2434090f2c88 | https://github.com/mech/filemaker-ruby/blob/75bb9eaf467546b2404bcb79267f2434090f2c88/lib/filemaker/server.rb#L101-L117 |
1,481 | oggy/cast | lib/cast/parse.rb | C.NodeList.match? | def match?(arr, parser=nil)
arr = arr.to_a
return false if arr.length != self.length
each_with_index do |node, i|
node.match?(arr[i], parser) or return false
end
return true
end | ruby | def match?(arr, parser=nil)
arr = arr.to_a
return false if arr.length != self.length
each_with_index do |node, i|
node.match?(arr[i], parser) or return false
end
return true
end | [
"def",
"match?",
"(",
"arr",
",",
"parser",
"=",
"nil",
")",
"arr",
"=",
"arr",
".",
"to_a",
"return",
"false",
"if",
"arr",
".",
"length",
"!=",
"self",
".",
"length",
"each_with_index",
"do",
"|",
"node",
",",
"i",
"|",
"node",
".",
"match?",
"("... | As defined in Node. | [
"As",
"defined",
"in",
"Node",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/parse.rb#L40-L47 |
1,482 | oggy/cast | lib/cast/node.rb | C.Node.assert_invariants | def assert_invariants(testcase)
fields.each do |field|
if val = send(field.reader)
assert_same(self, node.parent, "field.reader is #{field.reader}")
if field.child?
assert_same(field, val.instance_variable_get(:@parent_field), "field.reader is #{field.reader}")
en... | ruby | def assert_invariants(testcase)
fields.each do |field|
if val = send(field.reader)
assert_same(self, node.parent, "field.reader is #{field.reader}")
if field.child?
assert_same(field, val.instance_variable_get(:@parent_field), "field.reader is #{field.reader}")
en... | [
"def",
"assert_invariants",
"(",
"testcase",
")",
"fields",
".",
"each",
"do",
"|",
"field",
"|",
"if",
"val",
"=",
"send",
"(",
"field",
".",
"reader",
")",
"assert_same",
"(",
"self",
",",
"node",
".",
"parent",
",",
"\"field.reader is #{field.reader}\"",
... | Called by the test suite to ensure all invariants are true. | [
"Called",
"by",
"the",
"test",
"suite",
"to",
"ensure",
"all",
"invariants",
"are",
"true",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L15-L24 |
1,483 | oggy/cast | lib/cast/node.rb | C.Node.each | def each(&blk)
fields.each do |field|
if field.child?
val = self.send(field.reader)
yield val unless val.nil?
end
end
return self
end | ruby | def each(&blk)
fields.each do |field|
if field.child?
val = self.send(field.reader)
yield val unless val.nil?
end
end
return self
end | [
"def",
"each",
"(",
"&",
"blk",
")",
"fields",
".",
"each",
"do",
"|",
"field",
"|",
"if",
"field",
".",
"child?",
"val",
"=",
"self",
".",
"send",
"(",
"field",
".",
"reader",
")",
"yield",
"val",
"unless",
"val",
".",
"nil?",
"end",
"end",
"ret... | Yield each child in field order. | [
"Yield",
"each",
"child",
"in",
"field",
"order",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L107-L115 |
1,484 | oggy/cast | lib/cast/node.rb | C.Node.swap_with | def swap_with node
return self if node.equal? self
if self.attached?
if node.attached?
# both attached -- use placeholder
placeholder = Default.new
my_parent = @parent
my_parent.replace_node(self, placeholder)
node.parent.replace_node(node, self)
... | ruby | def swap_with node
return self if node.equal? self
if self.attached?
if node.attached?
# both attached -- use placeholder
placeholder = Default.new
my_parent = @parent
my_parent.replace_node(self, placeholder)
node.parent.replace_node(node, self)
... | [
"def",
"swap_with",
"node",
"return",
"self",
"if",
"node",
".",
"equal?",
"self",
"if",
"self",
".",
"attached?",
"if",
"node",
".",
"attached?",
"# both attached -- use placeholder",
"placeholder",
"=",
"Default",
".",
"new",
"my_parent",
"=",
"@parent",
"my_p... | Swap this node with `node' in their trees. If either node is
detached, the other will become detached as a result of calling
this method. | [
"Swap",
"this",
"node",
"with",
"node",
"in",
"their",
"trees",
".",
"If",
"either",
"node",
"is",
"detached",
"the",
"other",
"will",
"become",
"detached",
"as",
"a",
"result",
"of",
"calling",
"this",
"method",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L318-L341 |
1,485 | oggy/cast | lib/cast/node.rb | C.Node.node_before | def node_before(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
fields = self.fields
i = node.instance_variable_get(:@parent_field).index - 1
i.downto(0) do |i|
f = fields[i]
if f.child? && (val = self.send(f.reader))
return val
... | ruby | def node_before(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
fields = self.fields
i = node.instance_variable_get(:@parent_field).index - 1
i.downto(0) do |i|
f = fields[i]
if f.child? && (val = self.send(f.reader))
return val
... | [
"def",
"node_before",
"(",
"node",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"fields",
"=",
"self",
".",
"fields",
"i",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
"... | Return the Node that comes before the given Node in tree
preorder. | [
"Return",
"the",
"Node",
"that",
"comes",
"before",
"the",
"given",
"Node",
"in",
"tree",
"preorder",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L634-L646 |
1,486 | oggy/cast | lib/cast/node.rb | C.Node.remove_node | def remove_node(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
node.instance_variable_set(:@parent, nil)
node.instance_variable_set(:@parent_field, nil)
self.instance_variable_set(field.var, nil)
... | ruby | def remove_node(node)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
node.instance_variable_set(:@parent, nil)
node.instance_variable_set(:@parent_field, nil)
self.instance_variable_set(field.var, nil)
... | [
"def",
"remove_node",
"(",
"node",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"field",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
")",
"node",
".",
"instance_variable_se... | Remove the given Node. | [
"Remove",
"the",
"given",
"Node",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L651-L659 |
1,487 | oggy/cast | lib/cast/node.rb | C.Node.replace_node | def replace_node(node, newnode=nil)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
self.send(field.writer, newnode)
return self
end | ruby | def replace_node(node, newnode=nil)
node.parent.equal? self or
raise ArgumentError, "node is not a child"
field = node.instance_variable_get(:@parent_field)
self.send(field.writer, newnode)
return self
end | [
"def",
"replace_node",
"(",
"node",
",",
"newnode",
"=",
"nil",
")",
"node",
".",
"parent",
".",
"equal?",
"self",
"or",
"raise",
"ArgumentError",
",",
"\"node is not a child\"",
"field",
"=",
"node",
".",
"instance_variable_get",
"(",
":@parent_field",
")",
"... | Replace `node' with `newnode'. | [
"Replace",
"node",
"with",
"newnode",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node.rb#L664-L670 |
1,488 | oggy/cast | lib/cast/node_list.rb | C.NodeChain.link_ | def link_(a, nodes, b)
if nodes.empty?
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b)
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a)
end
else
# connect `a' and `b'
first = n... | ruby | def link_(a, nodes, b)
if nodes.empty?
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b)
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a)
end
else
# connect `a' and `b'
first = n... | [
"def",
"link_",
"(",
"a",
",",
"nodes",
",",
"b",
")",
"if",
"nodes",
".",
"empty?",
"if",
"a",
".",
"nil?",
"@first",
"=",
"b",
"else",
"a",
".",
"instance_variable_set",
"(",
":@next",
",",
"b",
")",
"end",
"if",
"b",
".",
"nil?",
"@last",
"=",... | Link up `nodes' between `a' and `b'. | [
"Link",
"up",
"nodes",
"between",
"a",
"and",
"b",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L763-L807 |
1,489 | oggy/cast | lib/cast/node_list.rb | C.NodeChain.link2_ | def link2_(a, b)
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b) unless a.nil?
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a) unless b.nil?
end
end | ruby | def link2_(a, b)
if a.nil?
@first = b
else
a.instance_variable_set(:@next, b) unless a.nil?
end
if b.nil?
@last = a
else
b.instance_variable_set(:@prev, a) unless b.nil?
end
end | [
"def",
"link2_",
"(",
"a",
",",
"b",
")",
"if",
"a",
".",
"nil?",
"@first",
"=",
"b",
"else",
"a",
".",
"instance_variable_set",
"(",
":@next",
",",
"b",
")",
"unless",
"a",
".",
"nil?",
"end",
"if",
"b",
".",
"nil?",
"@last",
"=",
"a",
"else",
... | Special case for 2 | [
"Special",
"case",
"for",
"2"
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L811-L822 |
1,490 | oggy/cast | lib/cast/node_list.rb | C.NodeChain.get_ | def get_(i)
# return a Node
if i < (@length >> 1)
# go from the beginning
node = @first
i.times{node = node.next}
else
# go from the end
node = @last
(@length - 1 - i).times{node = node.prev}
end
return node
end | ruby | def get_(i)
# return a Node
if i < (@length >> 1)
# go from the beginning
node = @first
i.times{node = node.next}
else
# go from the end
node = @last
(@length - 1 - i).times{node = node.prev}
end
return node
end | [
"def",
"get_",
"(",
"i",
")",
"# return a Node",
"if",
"i",
"<",
"(",
"@length",
">>",
"1",
")",
"# go from the beginning",
"node",
"=",
"@first",
"i",
".",
"times",
"{",
"node",
"=",
"node",
".",
"next",
"}",
"else",
"# go from the end",
"node",
"=",
... | Return the `i'th Node. Assume `i' is in 0...length. | [
"Return",
"the",
"i",
"th",
"Node",
".",
"Assume",
"i",
"is",
"in",
"0",
"...",
"length",
"."
] | 5986def9ec60ef720255cea9bd42f0c896d7e697 | https://github.com/oggy/cast/blob/5986def9ec60ef720255cea9bd42f0c896d7e697/lib/cast/node_list.rb#L827-L839 |
1,491 | spraints/resqued | lib/resqued/listener.rb | Resqued.Listener.exec | def exec
socket_fd = @socket.to_i
ENV['RESQUED_SOCKET'] = socket_fd.to_s
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
ENV['RESQUED_STATE'] = (@old_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
ENV['RESQUED_... | ruby | def exec
socket_fd = @socket.to_i
ENV['RESQUED_SOCKET'] = socket_fd.to_s
ENV['RESQUED_CONFIG_PATH'] = @config_paths.join(':')
ENV['RESQUED_STATE'] = (@old_workers.map { |r| "#{r[:pid]}|#{r[:queue]}" }.join('||'))
ENV['RESQUED_LISTENER_ID'] = @listener_id.to_s
ENV['RESQUED_... | [
"def",
"exec",
"socket_fd",
"=",
"@socket",
".",
"to_i",
"ENV",
"[",
"'RESQUED_SOCKET'",
"]",
"=",
"socket_fd",
".",
"to_s",
"ENV",
"[",
"'RESQUED_CONFIG_PATH'",
"]",
"=",
"@config_paths",
".",
"join",
"(",
"':'",
")",
"ENV",
"[",
"'RESQUED_STATE'",
"]",
"... | Configure a new listener object.
Runs in the master process.
Public: As an alternative to #run, exec a new ruby instance for this listener.
Runs in the master process. | [
"Configure",
"a",
"new",
"listener",
"object",
"."
] | 5d95bdfe009ce99ae745af552b6446b1465a3eb8 | https://github.com/spraints/resqued/blob/5d95bdfe009ce99ae745af552b6446b1465a3eb8/lib/resqued/listener.rb#L31-L45 |
1,492 | chemistrykit/chemistrykit | lib/chemistrykit/chemist.rb | ChemistryKit.Chemist.method_missing | def method_missing(name, *arguments)
value = arguments[0]
name = name.to_s
if name[-1, 1] == '='
key = name[/(.+)\s?=/, 1]
@data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym
else
@data[name.to_sym]
end
end | ruby | def method_missing(name, *arguments)
value = arguments[0]
name = name.to_s
if name[-1, 1] == '='
key = name[/(.+)\s?=/, 1]
@data[key.to_sym] = value unless instance_variables.include? "@#{key}".to_sym
else
@data[name.to_sym]
end
end | [
"def",
"method_missing",
"(",
"name",
",",
"*",
"arguments",
")",
"value",
"=",
"arguments",
"[",
"0",
"]",
"name",
"=",
"name",
".",
"to_s",
"if",
"name",
"[",
"-",
"1",
",",
"1",
"]",
"==",
"'='",
"key",
"=",
"name",
"[",
"/",
"\\s",
"/",
","... | allow this object to be set with arbitrary key value data | [
"allow",
"this",
"object",
"to",
"be",
"set",
"with",
"arbitrary",
"key",
"value",
"data"
] | 99f0fe213c69595eb1f3efee514fd88c415ca34b | https://github.com/chemistrykit/chemistrykit/blob/99f0fe213c69595eb1f3efee514fd88c415ca34b/lib/chemistrykit/chemist.rb#L28-L37 |
1,493 | jsl/placemaker | lib/placemaker/client.rb | Placemaker.Client.fetch! | def fetch!
fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
# Change ruby-form fields to url type, e.g., document_content => documentContent
cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
Curl::PostField.content(cgi_param, @options[f])
e... | ruby | def fetch!
fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
# Change ruby-form fields to url type, e.g., document_content => documentContent
cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
Curl::PostField.content(cgi_param, @options[f])
e... | [
"def",
"fetch!",
"fields",
"=",
"POST_FIELDS",
".",
"reject",
"{",
"|",
"f",
"|",
"@options",
"[",
"f",
"]",
".",
"nil?",
"}",
".",
"map",
"do",
"|",
"f",
"|",
"# Change ruby-form fields to url type, e.g., document_content => documentContent",
"cgi_param",
"=",
... | Fetches the place information for input parameters from the Yahoo Placemaker service | [
"Fetches",
"the",
"place",
"information",
"for",
"input",
"parameters",
"from",
"the",
"Yahoo",
"Placemaker",
"service"
] | 5391ace291d94ffc77c0fa23322b1cdd46a753db | https://github.com/jsl/placemaker/blob/5391ace291d94ffc77c0fa23322b1cdd46a753db/lib/placemaker/client.rb#L21-L30 |
1,494 | code-and-effect/effective_email_templates | lib/effective_email_templates/liquid_resolver.rb | EffectiveEmailTemplates.LiquidResolver.decorate | def decorate(templates, path_info, details, locals)
templates.each do |t|
t.locals = locals
end
end | ruby | def decorate(templates, path_info, details, locals)
templates.each do |t|
t.locals = locals
end
end | [
"def",
"decorate",
"(",
"templates",
",",
"path_info",
",",
"details",
",",
"locals",
")",
"templates",
".",
"each",
"do",
"|",
"t",
"|",
"t",
".",
"locals",
"=",
"locals",
"end",
"end"
] | Ensures all the resolver information is set in the template. | [
"Ensures",
"all",
"the",
"resolver",
"information",
"is",
"set",
"in",
"the",
"template",
"."
] | 1f76a16b1ce3d0db126c90056507302f66ff6d9e | https://github.com/code-and-effect/effective_email_templates/blob/1f76a16b1ce3d0db126c90056507302f66ff6d9e/lib/effective_email_templates/liquid_resolver.rb#L25-L29 |
1,495 | pmviva/mention_system | lib/mention_system/mention_processor.rb | MentionSystem.MentionProcessor.extract_handles_from_mentioner | def extract_handles_from_mentioner(mentioner)
content = extract_mentioner_content(mentioner)
handles = content.scan(handle_regexp).map { |handle| handle.gsub("#{mention_prefix}","") }
end | ruby | def extract_handles_from_mentioner(mentioner)
content = extract_mentioner_content(mentioner)
handles = content.scan(handle_regexp).map { |handle| handle.gsub("#{mention_prefix}","") }
end | [
"def",
"extract_handles_from_mentioner",
"(",
"mentioner",
")",
"content",
"=",
"extract_mentioner_content",
"(",
"mentioner",
")",
"handles",
"=",
"content",
".",
"scan",
"(",
"handle_regexp",
")",
".",
"map",
"{",
"|",
"handle",
"|",
"handle",
".",
"gsub",
"... | Extract handles from mentioner
@param [Mentioner] mentioner - the {Mentioner} to extract handles from
@return [Array] | [
"Extract",
"handles",
"from",
"mentioner"
] | f5418c576b2e299539b10f8d4c9a49009a9662b7 | https://github.com/pmviva/mention_system/blob/f5418c576b2e299539b10f8d4c9a49009a9662b7/lib/mention_system/mention_processor.rb#L44-L47 |
1,496 | pmviva/mention_system | lib/mention_system/mention_processor.rb | MentionSystem.MentionProcessor.process_after_callbacks | def process_after_callbacks(mentioner, mentionee)
result = true
@callbacks[:after].each do |callback|
unless callback.call(mentioner, mentionee)
result = false
break
end
end
result
end | ruby | def process_after_callbacks(mentioner, mentionee)
result = true
@callbacks[:after].each do |callback|
unless callback.call(mentioner, mentionee)
result = false
break
end
end
result
end | [
"def",
"process_after_callbacks",
"(",
"mentioner",
",",
"mentionee",
")",
"result",
"=",
"true",
"@callbacks",
"[",
":after",
"]",
".",
"each",
"do",
"|",
"callback",
"|",
"unless",
"callback",
".",
"call",
"(",
"mentioner",
",",
"mentionee",
")",
"result",... | Process after callbacks
@param [Mentioner] mentioner - the mentioner of the callback
@param [Mentionee] mentionee - the mentionee of the callback | [
"Process",
"after",
"callbacks"
] | f5418c576b2e299539b10f8d4c9a49009a9662b7 | https://github.com/pmviva/mention_system/blob/f5418c576b2e299539b10f8d4c9a49009a9662b7/lib/mention_system/mention_processor.rb#L112-L121 |
1,497 | bjjb/ebayr | lib/ebayr/request.rb | Ebayr.Request.headers | def headers
{
'X-EBAY-API-COMPATIBILITY-LEVEL' => @compatability_level.to_s,
'X-EBAY-API-DEV-NAME' => dev_id.to_s,
'X-EBAY-API-APP-NAME' => app_id.to_s,
'X-EBAY-API-CERT-NAME' => cert_id.to_s,
'X-EBAY-API-CALL-NAME' => @command.to_s,
'X-EBAY-API-SITEID' => @site_id.... | ruby | def headers
{
'X-EBAY-API-COMPATIBILITY-LEVEL' => @compatability_level.to_s,
'X-EBAY-API-DEV-NAME' => dev_id.to_s,
'X-EBAY-API-APP-NAME' => app_id.to_s,
'X-EBAY-API-CERT-NAME' => cert_id.to_s,
'X-EBAY-API-CALL-NAME' => @command.to_s,
'X-EBAY-API-SITEID' => @site_id.... | [
"def",
"headers",
"{",
"'X-EBAY-API-COMPATIBILITY-LEVEL'",
"=>",
"@compatability_level",
".",
"to_s",
",",
"'X-EBAY-API-DEV-NAME'",
"=>",
"dev_id",
".",
"to_s",
",",
"'X-EBAY-API-APP-NAME'",
"=>",
"app_id",
".",
"to_s",
",",
"'X-EBAY-API-CERT-NAME'",
"=>",
"cert_id",
... | Gets the headers that will be sent with this request. | [
"Gets",
"the",
"headers",
"that",
"will",
"be",
"sent",
"with",
"this",
"request",
"."
] | 7dcfc95608399a0b2ad5e1ee625556200d5733e7 | https://github.com/bjjb/ebayr/blob/7dcfc95608399a0b2ad5e1ee625556200d5733e7/lib/ebayr/request.rb#L33-L43 |
1,498 | bjjb/ebayr | lib/ebayr/request.rb | Ebayr.Request.http | def http(&block)
http = Net::HTTP.new(@uri.host, @uri.port)
if @uri.port == 443
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http.start(&block) if block_given?
http
end | ruby | def http(&block)
http = Net::HTTP.new(@uri.host, @uri.port)
if @uri.port == 443
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
return http.start(&block) if block_given?
http
end | [
"def",
"http",
"(",
"&",
"block",
")",
"http",
"=",
"Net",
"::",
"HTTP",
".",
"new",
"(",
"@uri",
".",
"host",
",",
"@uri",
".",
"port",
")",
"if",
"@uri",
".",
"port",
"==",
"443",
"http",
".",
"use_ssl",
"=",
"true",
"http",
".",
"verify_mode",... | Gets a HTTP connection for this request. If you pass in a block, it will
be run on that HTTP connection. | [
"Gets",
"a",
"HTTP",
"connection",
"for",
"this",
"request",
".",
"If",
"you",
"pass",
"in",
"a",
"block",
"it",
"will",
"be",
"run",
"on",
"that",
"HTTP",
"connection",
"."
] | 7dcfc95608399a0b2ad5e1ee625556200d5733e7 | https://github.com/bjjb/ebayr/blob/7dcfc95608399a0b2ad5e1ee625556200d5733e7/lib/ebayr/request.rb#L144-L152 |
1,499 | rightscale/right_api_client | lib/right_api_client/client.rb | RightApi.Client.retry_request | def retry_request(is_read_only = false)
attempts = 0
begin
yield
rescue OpenSSL::SSL::SSLError => e
raise e unless @enable_retry
# These errors pertain to the SSL handshake. Since no data has been
# exchanged its always safe to retry
raise e if attempts >= @max... | ruby | def retry_request(is_read_only = false)
attempts = 0
begin
yield
rescue OpenSSL::SSL::SSLError => e
raise e unless @enable_retry
# These errors pertain to the SSL handshake. Since no data has been
# exchanged its always safe to retry
raise e if attempts >= @max... | [
"def",
"retry_request",
"(",
"is_read_only",
"=",
"false",
")",
"attempts",
"=",
"0",
"begin",
"yield",
"rescue",
"OpenSSL",
"::",
"SSL",
"::",
"SSLError",
"=>",
"e",
"raise",
"e",
"unless",
"@enable_retry",
"# These errors pertain to the SSL handshake. Since no data... | Users shouldn't need to call the following methods directly | [
"Users",
"shouldn",
"t",
"need",
"to",
"call",
"the",
"following",
"methods",
"directly"
] | 29534dcebbc96fc0727e2d57bac73e349a910f08 | https://github.com/rightscale/right_api_client/blob/29534dcebbc96fc0727e2d57bac73e349a910f08/lib/right_api_client/client.rb#L234-L269 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.