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 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.send_message | def send_message(chat_id:, text:, disable_web_page_preview: false, reply_to_message_id: nil, reply_markup: nil, parse_mode: nil)
result = call(:sendMessage,
chat_id: chat_id,
text: text,
disable_web_page_preview: disable_web_page_preview,
reply_to_message_id: reply_to_message_id,
... | ruby | def send_message(chat_id:, text:, disable_web_page_preview: false, reply_to_message_id: nil, reply_markup: nil, parse_mode: nil)
result = call(:sendMessage,
chat_id: chat_id,
text: text,
disable_web_page_preview: disable_web_page_preview,
reply_to_message_id: reply_to_message_id,
... | [
"def",
"send_message",
"(",
"chat_id",
":",
",",
"text",
":",
",",
"disable_web_page_preview",
":",
"false",
",",
"reply_to_message_id",
":",
"nil",
",",
"reply_markup",
":",
"nil",
",",
"parse_mode",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":sendMessag... | Send text message.
@param chat_id [Integer] Unique identifier for the message recipient - User or GroupChat id
@param text [String] Text of the message to be sent
@param disable_web_page_preview [Boolean] Disables link previews for links in this message
@param reply_to_message_id [Integer] If the message is a repl... | [
"Send",
"text",
"message",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L65-L75 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.forward_message | def forward_message(chat_id:, from_chat_id:, message_id:)
result = call(:forwardMessage, chat_id: chat_id, from_chat_id: from_chat_id, message_id: message_id)
Message.new(result)
end | ruby | def forward_message(chat_id:, from_chat_id:, message_id:)
result = call(:forwardMessage, chat_id: chat_id, from_chat_id: from_chat_id, message_id: message_id)
Message.new(result)
end | [
"def",
"forward_message",
"(",
"chat_id",
":",
",",
"from_chat_id",
":",
",",
"message_id",
":",
")",
"result",
"=",
"call",
"(",
":forwardMessage",
",",
"chat_id",
":",
"chat_id",
",",
"from_chat_id",
":",
"from_chat_id",
",",
"message_id",
":",
"message_id",... | Use this method to forward messages of any kind.
@param chat_id [Integer] Unique identifier for the message recipient - User or GroupChat id
@param from_chat_id [Integer] Unique identifier for the chat where the original message was sent - User or GroupChat id
@param message_id [Integer] Unique message identifier
... | [
"Use",
"this",
"method",
"to",
"forward",
"messages",
"of",
"any",
"kind",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L84-L87 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.send_photo | def send_photo(chat_id:, photo:, caption: nil, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendPhoto, chat_id: chat_id, photo: photo, caption: caption, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | ruby | def send_photo(chat_id:, photo:, caption: nil, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendPhoto, chat_id: chat_id, photo: photo, caption: caption, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | [
"def",
"send_photo",
"(",
"chat_id",
":",
",",
"photo",
":",
",",
"caption",
":",
"nil",
",",
"reply_to_message_id",
":",
"nil",
",",
"reply_markup",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":sendPhoto",
",",
"chat_id",
":",
"chat_id",
",",
"photo",... | Send a picture.
@param chat_id [Integer] Unique identifier for the message recipient - User or GroupChat id
@param photo [InputFile, String] Photo to send. You can either pass a
file_id as String to resend a photo that is already on the Telegram servers,
or upload a new photo using multipart/form-data.
@param... | [
"Send",
"a",
"picture",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L100-L103 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.send_document | def send_document(chat_id:, document:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendDocument, chat_id: chat_id, document: document, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | ruby | def send_document(chat_id:, document:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendDocument, chat_id: chat_id, document: document, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | [
"def",
"send_document",
"(",
"chat_id",
":",
",",
"document",
":",
",",
"reply_to_message_id",
":",
"nil",
",",
"reply_markup",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":sendDocument",
",",
"chat_id",
":",
"chat_id",
",",
"document",
":",
"document",
... | Send general file.
@param chat_id [Integer]
@param document [Telebot::InputFile, String] document to send (file or file_id)
@param reply_to_message_id [Integer] If the message is a reply, ID of the original message
@param reply_markup [ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply] Additional interface option... | [
"Send",
"general",
"file",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L128-L131 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.send_sticker | def send_sticker(chat_id:, sticker:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendSticker, chat_id: chat_id, sticker: sticker, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | ruby | def send_sticker(chat_id:, sticker:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendSticker, chat_id: chat_id, sticker: sticker, reply_to_message_id: reply_to_message_id, reply_markup: reply_markup)
Message.new(result)
end | [
"def",
"send_sticker",
"(",
"chat_id",
":",
",",
"sticker",
":",
",",
"reply_to_message_id",
":",
"nil",
",",
"reply_markup",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":sendSticker",
",",
"chat_id",
":",
"chat_id",
",",
"sticker",
":",
"sticker",
",",
... | Use this method to send .webp stickers.
@param chat_id [Integer]
@param sticker [Telebot::InputFile, String] sticker to send (file or file_id)
@param reply_to_message_id [Integer] If the message is a reply, ID of the original message
@param reply_markup [ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply] Addition... | [
"Use",
"this",
"method",
"to",
"send",
".",
"webp",
"stickers",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L141-L144 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.send_location | def send_location(chat_id:, latitude:, longitude:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendLocation, chat_id: chat_id,
latitude: latitude,
longitude: longitude,
reply_to_message_id: rep... | ruby | def send_location(chat_id:, latitude:, longitude:, reply_to_message_id: nil, reply_markup: nil)
result = call(:sendLocation, chat_id: chat_id,
latitude: latitude,
longitude: longitude,
reply_to_message_id: rep... | [
"def",
"send_location",
"(",
"chat_id",
":",
",",
"latitude",
":",
",",
"longitude",
":",
",",
"reply_to_message_id",
":",
"nil",
",",
"reply_markup",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":sendLocation",
",",
"chat_id",
":",
"chat_id",
",",
"latit... | Send a point on the map.
@param chat_id [Integer]
@param latitude [Integer]
@param longitude [Integer]
@param reply_to_message_id [Integer]
@param reply_markup [ReplyKeyboardMarkup, ReplyKeyboardHide, ForceReply]
@return [Telebot::Message] | [
"Send",
"a",
"point",
"on",
"the",
"map",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L168-L175 | train |
greyblake/telebot | lib/telebot/client.rb | Telebot.Client.get_user_profile_photos | def get_user_profile_photos(user_id:, offset: nil, limit: nil)
result = call(:getUserProfilePhotos, user_id: user_id, offset: offset, limit: limit)
UserProfilePhotos.new(result)
end | ruby | def get_user_profile_photos(user_id:, offset: nil, limit: nil)
result = call(:getUserProfilePhotos, user_id: user_id, offset: offset, limit: limit)
UserProfilePhotos.new(result)
end | [
"def",
"get_user_profile_photos",
"(",
"user_id",
":",
",",
"offset",
":",
"nil",
",",
"limit",
":",
"nil",
")",
"result",
"=",
"call",
"(",
":getUserProfilePhotos",
",",
"user_id",
":",
"user_id",
",",
"offset",
":",
"offset",
",",
"limit",
":",
"limit",
... | Use this method to get a list of profile pictures for a user.
@param user_id [Integer]
@param offset [Integer]
@param limit [Integer]
@return [Telebot::UserProfilePhotos] | [
"Use",
"this",
"method",
"to",
"get",
"a",
"list",
"of",
"profile",
"pictures",
"for",
"a",
"user",
"."
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L197-L200 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/api_manager.rb | LambdaWrap.API.add_lambda | def add_lambda(*new_lambda)
flattened_lambdas = new_lambda.flatten
flattened_lambdas.each { |lambda| parameter_guard(lambda, LambdaWrap::Lambda, 'LambdaWrap::Lambda') }
lambdas.concat(flattened_lambdas)
end | ruby | def add_lambda(*new_lambda)
flattened_lambdas = new_lambda.flatten
flattened_lambdas.each { |lambda| parameter_guard(lambda, LambdaWrap::Lambda, 'LambdaWrap::Lambda') }
lambdas.concat(flattened_lambdas)
end | [
"def",
"add_lambda",
"(",
"*",
"new_lambda",
")",
"flattened_lambdas",
"=",
"new_lambda",
".",
"flatten",
"flattened_lambdas",
".",
"each",
"{",
"|",
"lambda",
"|",
"parameter_guard",
"(",
"lambda",
",",
"LambdaWrap",
"::",
"Lambda",
",",
"'LambdaWrap::Lambda'",
... | Constructor for the high level API Manager class.
@param [Hash] options The Options to configure the API.
@option options [String] :access_key_id The AWS Access Key Id to communicate with AWS. Will also check the
environment variables for this value.
@option options [String] :secret_access_key The AWS Secret Acc... | [
"Constructor",
"for",
"the",
"high",
"level",
"API",
"Manager",
"class",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/api_manager.rb#L66-L70 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/api_manager.rb | LambdaWrap.API.deploy | def deploy(environment_options)
environment_parameter_guard(environment_options)
if no_op?
puts 'Nothing to deploy.'
return
end
deployment_start_message = 'Deploying '
deployment_start_message += "#{dynamo_tables.length} Dynamo Tables, " unless dynamo_tables.empty?
d... | ruby | def deploy(environment_options)
environment_parameter_guard(environment_options)
if no_op?
puts 'Nothing to deploy.'
return
end
deployment_start_message = 'Deploying '
deployment_start_message += "#{dynamo_tables.length} Dynamo Tables, " unless dynamo_tables.empty?
d... | [
"def",
"deploy",
"(",
"environment_options",
")",
"environment_parameter_guard",
"(",
"environment_options",
")",
"if",
"no_op?",
"puts",
"'Nothing to deploy.'",
"return",
"end",
"deployment_start_message",
"=",
"'Deploying '",
"deployment_start_message",
"+=",
"\"#{dynamo_ta... | Deploys all services to the specified environment.
@param [LambdaWrap::Environment] environment_options the Environment to deploy | [
"Deploys",
"all",
"services",
"to",
"the",
"specified",
"environment",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/api_manager.rb#L97-L147 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/api_manager.rb | LambdaWrap.API.delete | def delete
if dynamo_tables.empty? && lambdas.empty? && api_gateways.empty?
puts 'Nothing to Deleting.'
return
end
deployment_start_message = 'Deleting '
deployment_start_message += "#{dynamo_tables.length} Dynamo Tables, " unless dynamo_tables.empty?
deployment_start_mess... | ruby | def delete
if dynamo_tables.empty? && lambdas.empty? && api_gateways.empty?
puts 'Nothing to Deleting.'
return
end
deployment_start_message = 'Deleting '
deployment_start_message += "#{dynamo_tables.length} Dynamo Tables, " unless dynamo_tables.empty?
deployment_start_mess... | [
"def",
"delete",
"if",
"dynamo_tables",
".",
"empty?",
"&&",
"lambdas",
".",
"empty?",
"&&",
"api_gateways",
".",
"empty?",
"puts",
"'Nothing to Deleting.'",
"return",
"end",
"deployment_start_message",
"=",
"'Deleting '",
"deployment_start_message",
"+=",
"\"#{dynamo_t... | Deletes all services from the cloud. | [
"Deletes",
"all",
"services",
"from",
"the",
"cloud",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/api_manager.rb#L205-L253 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/lambda_manager.rb | LambdaWrap.Lambda.deploy | def deploy(environment_options, client, region = 'AWS_REGION')
super
puts "Deploying Lambda: #{@lambda_name} to Environment: #{environment_options.name}"
unless File.exist?(@path_to_zip_file)
raise ArgumentError, "Deployment Package Zip File does not exist: #{@path_to_zip_file}!"
end
... | ruby | def deploy(environment_options, client, region = 'AWS_REGION')
super
puts "Deploying Lambda: #{@lambda_name} to Environment: #{environment_options.name}"
unless File.exist?(@path_to_zip_file)
raise ArgumentError, "Deployment Package Zip File does not exist: #{@path_to_zip_file}!"
end
... | [
"def",
"deploy",
"(",
"environment_options",
",",
"client",
",",
"region",
"=",
"'AWS_REGION'",
")",
"super",
"puts",
"\"Deploying Lambda: #{@lambda_name} to Environment: #{environment_options.name}\"",
"unless",
"File",
".",
"exist?",
"(",
"@path_to_zip_file",
")",
"raise"... | Initializes a Lambda Manager. Frontloaded configuration.
@param [Hash] options The Configuration for the Lambda
@option options [String] :lambda_name The name you want to assign to the function you are uploading. The function
names appear in the console and are returned in the ListFunctions API. Function names are... | [
"Initializes",
"a",
"Lambda",
"Manager",
".",
"Frontloaded",
"configuration",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/lambda_manager.rb#L104-L128 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/lambda_manager.rb | LambdaWrap.Lambda.delete | def delete(client, region = 'AWS_REGION')
super
puts "Deleting all versions and aliases for Lambda: #{@lambda_name}"
lambda_details = retrieve_lambda_details
if lambda_details.nil?
puts 'No Lambda to delete.'
else
options = { function_name: @lambda_name }
@client.de... | ruby | def delete(client, region = 'AWS_REGION')
super
puts "Deleting all versions and aliases for Lambda: #{@lambda_name}"
lambda_details = retrieve_lambda_details
if lambda_details.nil?
puts 'No Lambda to delete.'
else
options = { function_name: @lambda_name }
@client.de... | [
"def",
"delete",
"(",
"client",
",",
"region",
"=",
"'AWS_REGION'",
")",
"super",
"puts",
"\"Deleting all versions and aliases for Lambda: #{@lambda_name}\"",
"lambda_details",
"=",
"retrieve_lambda_details",
"if",
"lambda_details",
".",
"nil?",
"puts",
"'No Lambda to delete.... | Deletes the Lambda Object with associated versions, code, configuration, and aliases.
@param client [Aws::Lambda::Client] Client to use with SDK. Should be passed in by the API class.
@param region [String] AWS Region string. Should be passed in by the API class. | [
"Deletes",
"the",
"Lambda",
"Object",
"with",
"associated",
"versions",
"code",
"configuration",
"and",
"aliases",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/lambda_manager.rb#L147-L159 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/api_gateway_manager.rb | LambdaWrap.ApiGateway.teardown | def teardown(environment_options, client, region = 'AWS_REGION')
super
api_id = get_id_for_api(@api_name)
if api_id
delete_stage(api_id, environment_options.name)
else
puts "API Gateway Object #{@api_name} not found. No environment to tear down."
end
true
... | ruby | def teardown(environment_options, client, region = 'AWS_REGION')
super
api_id = get_id_for_api(@api_name)
if api_id
delete_stage(api_id, environment_options.name)
else
puts "API Gateway Object #{@api_name} not found. No environment to tear down."
end
true
... | [
"def",
"teardown",
"(",
"environment_options",
",",
"client",
",",
"region",
"=",
"'AWS_REGION'",
")",
"super",
"api_id",
"=",
"get_id_for_api",
"(",
"@api_name",
")",
"if",
"api_id",
"delete_stage",
"(",
"api_id",
",",
"environment_options",
".",
"name",
")",
... | Tearsdown environment for API Gateway. Deletes stage.
@param environment_options [LambdaWrap::Environment] The environment to teardown.
@param client [Aws::APIGateway::Client] Client to use with SDK. Should be passed in by the API class.
@param region [String] AWS Region string. Should be passed in by the API class... | [
"Tearsdown",
"environment",
"for",
"API",
"Gateway",
".",
"Deletes",
"stage",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/api_gateway_manager.rb#L77-L86 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/api_gateway_manager.rb | LambdaWrap.ApiGateway.delete | def delete(client, region = 'AWS_REGION')
super
api_id = get_id_for_api(@api_name)
if api_id
options = {
rest_api_id: api_id
}
@client.delete_rest_api(options)
puts "Deleted API: #{@api_name} ID:#{api_id}"
else
puts "API Gateway Object ... | ruby | def delete(client, region = 'AWS_REGION')
super
api_id = get_id_for_api(@api_name)
if api_id
options = {
rest_api_id: api_id
}
@client.delete_rest_api(options)
puts "Deleted API: #{@api_name} ID:#{api_id}"
else
puts "API Gateway Object ... | [
"def",
"delete",
"(",
"client",
",",
"region",
"=",
"'AWS_REGION'",
")",
"super",
"api_id",
"=",
"get_id_for_api",
"(",
"@api_name",
")",
"if",
"api_id",
"options",
"=",
"{",
"rest_api_id",
":",
"api_id",
"}",
"@client",
".",
"delete_rest_api",
"(",
"options... | Deletes all stages and API Gateway object.
@param client [Aws::APIGateway::Client] Client to use with SDK. Should be passed in by the API class.
@param region [String] AWS Region string. Should be passed in by the API class. | [
"Deletes",
"all",
"stages",
"and",
"API",
"Gateway",
"object",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/api_gateway_manager.rb#L91-L104 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/dynamo_db_manager.rb | LambdaWrap.DynamoTable.deploy | def deploy(environment_options, client, region = 'AWS_REGION')
super
puts "Deploying Table: #{@table_name} to Environment: #{environment_options.name}"
full_table_name = @table_name + (@append_environment_on_deploy ? "-#{environment_options.name}" : '')
table_details = retrieve_table_details(... | ruby | def deploy(environment_options, client, region = 'AWS_REGION')
super
puts "Deploying Table: #{@table_name} to Environment: #{environment_options.name}"
full_table_name = @table_name + (@append_environment_on_deploy ? "-#{environment_options.name}" : '')
table_details = retrieve_table_details(... | [
"def",
"deploy",
"(",
"environment_options",
",",
"client",
",",
"region",
"=",
"'AWS_REGION'",
")",
"super",
"puts",
"\"Deploying Table: #{@table_name} to Environment: #{environment_options.name}\"",
"full_table_name",
"=",
"@table_name",
"+",
"(",
"@append_environment_on_depl... | Sets up the DynamoTable for the Dynamo DB Manager. Preloading the configuration in the constructor.
@param [Hash] options The configuration for the DynamoDB Table.
@option options [String] :table_name The name of the DynamoDB Table. A "Base Name" can be used here where the
environment name can be appended upon dep... | [
"Sets",
"up",
"the",
"DynamoTable",
"for",
"the",
"Dynamo",
"DB",
"Manager",
".",
"Preloading",
"the",
"configuration",
"in",
"the",
"constructor",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/dynamo_db_manager.rb#L158-L176 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/dynamo_db_manager.rb | LambdaWrap.DynamoTable.wait_until_table_is_available | def wait_until_table_is_available(full_table_name, delay = 5, max_attempts = 5)
puts "Waiting for Table #{full_table_name} to be available."
puts "Waiting with a #{delay} second delay between attempts, for a maximum of #{max_attempts} attempts."
max_time = Time.at(delay * max_attempts).utc.strftime('%... | ruby | def wait_until_table_is_available(full_table_name, delay = 5, max_attempts = 5)
puts "Waiting for Table #{full_table_name} to be available."
puts "Waiting with a #{delay} second delay between attempts, for a maximum of #{max_attempts} attempts."
max_time = Time.at(delay * max_attempts).utc.strftime('%... | [
"def",
"wait_until_table_is_available",
"(",
"full_table_name",
",",
"delay",
"=",
"5",
",",
"max_attempts",
"=",
"5",
")",
"puts",
"\"Waiting for Table #{full_table_name} to be available.\"",
"puts",
"\"Waiting with a #{delay} second delay between attempts, for a maximum of #{max_at... | Waits for the table to be available | [
"Waits",
"for",
"the",
"table",
"to",
"be",
"available"
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/dynamo_db_manager.rb#L228-L258 | train |
Cimpress-MCP/LambdaWrap | lib/lambda_wrap/dynamo_db_manager.rb | LambdaWrap.DynamoTable.build_global_index_updates_array | def build_global_index_updates_array(current_global_indexes)
indexes_to_update = []
return indexes_to_update if current_global_indexes.empty?
current_global_indexes.each do |current_index|
@global_secondary_indexes.each do |target_index|
# Find the same named index
next unl... | ruby | def build_global_index_updates_array(current_global_indexes)
indexes_to_update = []
return indexes_to_update if current_global_indexes.empty?
current_global_indexes.each do |current_index|
@global_secondary_indexes.each do |target_index|
# Find the same named index
next unl... | [
"def",
"build_global_index_updates_array",
"(",
"current_global_indexes",
")",
"indexes_to_update",
"=",
"[",
"]",
"return",
"indexes_to_update",
"if",
"current_global_indexes",
".",
"empty?",
"current_global_indexes",
".",
"each",
"do",
"|",
"current_index",
"|",
"@globa... | Looks through the list current of Global Secondary Indexes and builds an array if the Provisioned Throughput
in the intended Indexes are higher than the current Indexes. | [
"Looks",
"through",
"the",
"list",
"current",
"of",
"Global",
"Secondary",
"Indexes",
"and",
"builds",
"an",
"array",
"if",
"the",
"Provisioned",
"Throughput",
"in",
"the",
"intended",
"Indexes",
"are",
"higher",
"than",
"the",
"current",
"Indexes",
"."
] | 9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8 | https://github.com/Cimpress-MCP/LambdaWrap/blob/9c34b4ea49c86aaf9b5c998b12a61ceb065cedd8/lib/lambda_wrap/dynamo_db_manager.rb#L341-L359 | train |
greyblake/telebot | lib/telebot/objects/user_profile_photos.rb | Telebot.UserProfilePhotos.photos= | def photos=(values)
@photos = values.map do |photo|
photo.map do |photo_size_attrs|
PhotoSize.new(photo_size_attrs)
end
end
end | ruby | def photos=(values)
@photos = values.map do |photo|
photo.map do |photo_size_attrs|
PhotoSize.new(photo_size_attrs)
end
end
end | [
"def",
"photos",
"=",
"(",
"values",
")",
"@photos",
"=",
"values",
".",
"map",
"do",
"|",
"photo",
"|",
"photo",
".",
"map",
"do",
"|",
"photo_size_attrs",
"|",
"PhotoSize",
".",
"new",
"(",
"photo_size_attrs",
")",
"end",
"end",
"end"
] | Assign Array of Array of PhotoSize
@param values [Array<Array<PhotoSize>>] | [
"Assign",
"Array",
"of",
"Array",
"of",
"PhotoSize"
] | 16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a | https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/objects/user_profile_photos.rb#L15-L21 | train |
square/border_patrol | lib/border_patrol/polygon.rb | BorderPatrol.Polygon.contains_point? | def contains_point?(point)
return false unless inside_bounding_box?(point)
c = false
i = -1
j = size - 1
while (i += 1) < size
if (self[i].y <= point.y && point.y < self[j].y) ||
(self[j].y <= point.y && point.y < self[i].y)
if point.x < (self[j].x - self[i].x)... | ruby | def contains_point?(point)
return false unless inside_bounding_box?(point)
c = false
i = -1
j = size - 1
while (i += 1) < size
if (self[i].y <= point.y && point.y < self[j].y) ||
(self[j].y <= point.y && point.y < self[i].y)
if point.x < (self[j].x - self[i].x)... | [
"def",
"contains_point?",
"(",
"point",
")",
"return",
"false",
"unless",
"inside_bounding_box?",
"(",
"point",
")",
"c",
"=",
"false",
"i",
"=",
"-",
"1",
"j",
"=",
"size",
"-",
"1",
"while",
"(",
"i",
"+=",
"1",
")",
"<",
"size",
"if",
"(",
"self... | Quick and dirty hash function | [
"Quick",
"and",
"dirty",
"hash",
"function"
] | 72c50ea17c89f7fa89fbaed25ad3db3fa1d8eeb1 | https://github.com/square/border_patrol/blob/72c50ea17c89f7fa89fbaed25ad3db3fa1d8eeb1/lib/border_patrol/polygon.rb#L43-L58 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.list_unspent | def list_unspent(oa_address_list = [])
btc_address_list = oa_address_list.map { |oa_address| oa_address_to_address(oa_address)}
outputs = get_unspent_outputs(btc_address_list)
result = outputs.map{|out| out.to_hash}
result
end | ruby | def list_unspent(oa_address_list = [])
btc_address_list = oa_address_list.map { |oa_address| oa_address_to_address(oa_address)}
outputs = get_unspent_outputs(btc_address_list)
result = outputs.map{|out| out.to_hash}
result
end | [
"def",
"list_unspent",
"(",
"oa_address_list",
"=",
"[",
"]",
")",
"btc_address_list",
"=",
"oa_address_list",
".",
"map",
"{",
"|",
"oa_address",
"|",
"oa_address_to_address",
"(",
"oa_address",
")",
"}",
"outputs",
"=",
"get_unspent_outputs",
"(",
"btc_address_l... | get UTXO for colored coins.
@param [Array] oa_address_list Obtain the balance of this open assets address only, or all addresses if unspecified.
@return [Array] Return array of the unspent information Hash. | [
"get",
"UTXO",
"for",
"colored",
"coins",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L48-L53 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.get_balance | def get_balance(address = nil)
outputs = get_unspent_outputs(address.nil? ? [] : [oa_address_to_address(address)])
colored_outputs = outputs.map{|o|o.output}
sorted_outputs = colored_outputs.sort_by { |o|o.script.to_string}
groups = sorted_outputs.group_by{|o| o.script.to_string}
result = ... | ruby | def get_balance(address = nil)
outputs = get_unspent_outputs(address.nil? ? [] : [oa_address_to_address(address)])
colored_outputs = outputs.map{|o|o.output}
sorted_outputs = colored_outputs.sort_by { |o|o.script.to_string}
groups = sorted_outputs.group_by{|o| o.script.to_string}
result = ... | [
"def",
"get_balance",
"(",
"address",
"=",
"nil",
")",
"outputs",
"=",
"get_unspent_outputs",
"(",
"address",
".",
"nil?",
"?",
"[",
"]",
":",
"[",
"oa_address_to_address",
"(",
"address",
")",
"]",
")",
"colored_outputs",
"=",
"outputs",
".",
"map",
"{",
... | Returns the balance in both bitcoin and colored coin assets for all of the addresses available in your Bitcoin Core wallet.
@param [String] address The open assets address. if unspecified nil. | [
"Returns",
"the",
"balance",
"in",
"both",
"bitcoin",
"and",
"colored",
"coin",
"assets",
"for",
"all",
"of",
"the",
"addresses",
"available",
"in",
"your",
"Bitcoin",
"Core",
"wallet",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L57-L84 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.issue_asset | def issue_asset(from, amount, metadata = nil, to = nil, fees = nil, mode = 'broadcast', output_qty = 1)
to = from if to.nil?
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
issue_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)... | ruby | def issue_asset(from, amount, metadata = nil, to = nil, fees = nil, mode = 'broadcast', output_qty = 1)
to = from if to.nil?
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
issue_param = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)... | [
"def",
"issue_asset",
"(",
"from",
",",
"amount",
",",
"metadata",
"=",
"nil",
",",
"to",
"=",
"nil",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
",",
"output_qty",
"=",
"1",
")",
"to",
"=",
"from",
"if",
"to",
".",
"nil?",
"colored_o... | Creates a transaction for issuing an asset.
@param[String] from The open asset address to issue the asset from.
@param[Integer] amount The amount of asset units to issue.
@param[String] to The open asset address to send the asset to; if unspecified, the assets are sent back to the issuing address.
@param[String] me... | [
"Creates",
"a",
"transaction",
"for",
"issuing",
"an",
"asset",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L99-L106 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.send_asset | def send_asset(from, asset_id, amount, to, fees = nil, mode = 'broadcast', output_qty = 1)
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
asset_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
tx = create_tx_builder.tr... | ruby | def send_asset(from, asset_id, amount, to, fees = nil, mode = 'broadcast', output_qty = 1)
colored_outputs = get_unspent_outputs([oa_address_to_address(from)])
asset_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
tx = create_tx_builder.tr... | [
"def",
"send_asset",
"(",
"from",
",",
"asset_id",
",",
"amount",
",",
"to",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
",",
"output_qty",
"=",
"1",
")",
"colored_outputs",
"=",
"get_unspent_outputs",
"(",
"[",
"oa_address_to_address",
"(",
... | Creates a transaction for sending an asset from an address to another.
@param[String] from The open asset address to send the asset from.
@param[String] asset_id The asset ID identifying the asset to send.
@param[Integer] amount The amount of asset units to send.
@param[String] to The open asset address to send the... | [
"Creates",
"a",
"transaction",
"for",
"sending",
"an",
"asset",
"from",
"an",
"address",
"to",
"another",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L118-L124 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.send_assets | def send_assets(from, send_asset_params, fees = nil, mode = 'broadcast')
transfer_specs = send_asset_params.map{ |param|
colored_outputs = get_unspent_outputs([oa_address_to_address(param.from || from)])
[param.asset_id, OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, pa... | ruby | def send_assets(from, send_asset_params, fees = nil, mode = 'broadcast')
transfer_specs = send_asset_params.map{ |param|
colored_outputs = get_unspent_outputs([oa_address_to_address(param.from || from)])
[param.asset_id, OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, pa... | [
"def",
"send_assets",
"(",
"from",
",",
"send_asset_params",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
")",
"transfer_specs",
"=",
"send_asset_params",
".",
"map",
"{",
"|",
"param",
"|",
"colored_outputs",
"=",
"get_unspent_outputs",
"(",
"[",... | Creates a transaction for sending multiple asset from an address to another.
@param[String] from The open asset address to send the asset from when send_asset_param hasn't from.
to send the bitcoins from, if needed. where to send bitcoin change, if any.
@param[Array[OpenAssets::SendAssetParam]] send_asset_params The... | [
"Creates",
"a",
"transaction",
"for",
"sending",
"multiple",
"asset",
"from",
"an",
"address",
"to",
"another",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L135-L145 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.send_bitcoin | def send_bitcoin(from, amount, to, fees = nil, mode = 'broadcast', output_qty = 1)
validate_address([from, to])
colored_outputs = get_unspent_outputs([from])
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
tx = create_tx_builder.... | ruby | def send_bitcoin(from, amount, to, fees = nil, mode = 'broadcast', output_qty = 1)
validate_address([from, to])
colored_outputs = get_unspent_outputs([from])
btc_transfer_spec = OpenAssets::Transaction::TransferParameters.new(colored_outputs, to, from, amount, output_qty)
tx = create_tx_builder.... | [
"def",
"send_bitcoin",
"(",
"from",
",",
"amount",
",",
"to",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
",",
"output_qty",
"=",
"1",
")",
"validate_address",
"(",
"[",
"from",
",",
"to",
"]",
")",
"colored_outputs",
"=",
"get_unspent_outp... | Creates a transaction for sending bitcoins from an address to another.
@param[String] from The address to send the bitcoins from.
@param[Integer] amount The amount of satoshis to send.
@param[String] to The address to send the bitcoins to.
@param[Integer] fees The fess in satoshis for the transaction.
@param[Strin... | [
"Creates",
"a",
"transaction",
"for",
"sending",
"bitcoins",
"from",
"an",
"address",
"to",
"another",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L158-L164 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.send_bitcoins | def send_bitcoins(from, send_params, fees = nil, mode = 'broadcast')
colored_outputs = get_unspent_outputs([from])
btc_transfer_specs = send_params.map{|param|
OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, from, param.amount)
}
tx = create_tx_builder.transfer... | ruby | def send_bitcoins(from, send_params, fees = nil, mode = 'broadcast')
colored_outputs = get_unspent_outputs([from])
btc_transfer_specs = send_params.map{|param|
OpenAssets::Transaction::TransferParameters.new(colored_outputs, param.to, from, param.amount)
}
tx = create_tx_builder.transfer... | [
"def",
"send_bitcoins",
"(",
"from",
",",
"send_params",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
")",
"colored_outputs",
"=",
"get_unspent_outputs",
"(",
"[",
"from",
"]",
")",
"btc_transfer_specs",
"=",
"send_params",
".",
"map",
"{",
"|",... | Creates a transaction for sending multiple bitcoins from an address to others.
@param[String] from The address to send the bitcoins from.
@param[Array[OpenAssets::SendBitcoinParam]] send_params The send information(amount of satoshis and to).
@param[Integer] fees The fees in satoshis for the transaction.
@param[Str... | [
"Creates",
"a",
"transaction",
"for",
"sending",
"multiple",
"bitcoins",
"from",
"an",
"address",
"to",
"others",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L174-L182 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.burn_asset | def burn_asset(oa_address, asset_id, fees = nil, mode = 'broadcast')
unspents = get_unspent_outputs([oa_address_to_address(oa_address)])
tx = create_tx_builder.burn_asset(unspents, asset_id, fees.nil? ? @config[:default_fees]: fees)
process_transaction(tx, mode)
end | ruby | def burn_asset(oa_address, asset_id, fees = nil, mode = 'broadcast')
unspents = get_unspent_outputs([oa_address_to_address(oa_address)])
tx = create_tx_builder.burn_asset(unspents, asset_id, fees.nil? ? @config[:default_fees]: fees)
process_transaction(tx, mode)
end | [
"def",
"burn_asset",
"(",
"oa_address",
",",
"asset_id",
",",
"fees",
"=",
"nil",
",",
"mode",
"=",
"'broadcast'",
")",
"unspents",
"=",
"get_unspent_outputs",
"(",
"[",
"oa_address_to_address",
"(",
"oa_address",
")",
"]",
")",
"tx",
"=",
"create_tx_builder",... | Creates a transaction for burn asset.
@param[String] oa_address The open asset address to burn asset.
@param[String] asset_id The asset ID identifying the asset to burn.
@param[Integer] fees The fess in satoshis for the transaction.
@param[String] mode 'broadcast' (default) for signing and broadcasting the transact... | [
"Creates",
"a",
"transaction",
"for",
"burn",
"asset",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L192-L196 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.get_unspent_outputs | def get_unspent_outputs(addresses)
validate_address(addresses)
unspent = provider.list_unspent(addresses, @config[:min_confirmation], @config[:max_confirmation])
result = unspent.map{|item|
output_result = get_output(item['txid'], item['vout'])
output_result.account = item['account']
... | ruby | def get_unspent_outputs(addresses)
validate_address(addresses)
unspent = provider.list_unspent(addresses, @config[:min_confirmation], @config[:max_confirmation])
result = unspent.map{|item|
output_result = get_output(item['txid'], item['vout'])
output_result.account = item['account']
... | [
"def",
"get_unspent_outputs",
"(",
"addresses",
")",
"validate_address",
"(",
"addresses",
")",
"unspent",
"=",
"provider",
".",
"list_unspent",
"(",
"addresses",
",",
"@config",
"[",
":min_confirmation",
"]",
",",
"@config",
"[",
":max_confirmation",
"]",
")",
... | Get unspent outputs.
@param [Array] addresses The array of Bitcoin address.
@return [Array[OpenAssets::Transaction::SpendableOutput]] The array of unspent outputs. | [
"Get",
"unspent",
"outputs",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L201-L215 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.get_outputs_from_txid | def get_outputs_from_txid(txid, use_cache = false)
tx = get_tx(txid, use_cache)
outputs = get_color_outputs_from_tx(tx)
outputs.map.with_index{|out, i|out.to_hash.merge({'txid' => tx.hash, 'vout' => i})}
end | ruby | def get_outputs_from_txid(txid, use_cache = false)
tx = get_tx(txid, use_cache)
outputs = get_color_outputs_from_tx(tx)
outputs.map.with_index{|out, i|out.to_hash.merge({'txid' => tx.hash, 'vout' => i})}
end | [
"def",
"get_outputs_from_txid",
"(",
"txid",
",",
"use_cache",
"=",
"false",
")",
"tx",
"=",
"get_tx",
"(",
"txid",
",",
"use_cache",
")",
"outputs",
"=",
"get_color_outputs_from_tx",
"(",
"tx",
")",
"outputs",
".",
"map",
".",
"with_index",
"{",
"|",
"out... | Get tx outputs.
@param[String] txid Transaction ID.
@param[Boolean] use_cache If specified true use cache.(default value is false)
@return[Array] Return array of the transaction output Hash with coloring information. | [
"Get",
"tx",
"outputs",
"."
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L248-L252 | train |
haw-itn/openassets-ruby | lib/openassets/api.rb | OpenAssets.Api.parse_issuance_p2sh_pointer | def parse_issuance_p2sh_pointer(script_sig)
script = Bitcoin::Script.new(script_sig).chunks.last
redeem_script = Bitcoin::Script.new(script)
return nil unless redeem_script.chunks[1] == Bitcoin::Script::OP_DROP
asset_def = to_bytes(redeem_script.chunks[0].to_s.bth)[0..-1].map{|x|x.to_i(16).chr}.... | ruby | def parse_issuance_p2sh_pointer(script_sig)
script = Bitcoin::Script.new(script_sig).chunks.last
redeem_script = Bitcoin::Script.new(script)
return nil unless redeem_script.chunks[1] == Bitcoin::Script::OP_DROP
asset_def = to_bytes(redeem_script.chunks[0].to_s.bth)[0..-1].map{|x|x.to_i(16).chr}.... | [
"def",
"parse_issuance_p2sh_pointer",
"(",
"script_sig",
")",
"script",
"=",
"Bitcoin",
"::",
"Script",
".",
"new",
"(",
"script_sig",
")",
".",
"chunks",
".",
"last",
"redeem_script",
"=",
"Bitcoin",
"::",
"Script",
".",
"new",
"(",
"script",
")",
"return",... | parse issuance p2sh which contains asset definition pointer | [
"parse",
"issuance",
"p2sh",
"which",
"contains",
"asset",
"definition",
"pointer"
] | c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf | https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/api.rb#L409-L415 | train |
poise/halite | lib/halite/spec_helper.rb | Halite.SpecHelper.chef_runner_options | def chef_runner_options
super.tap do |options|
options[:halite_gemspec] = halite_gemspec
# And some legacy data.
options[:default_attributes].update(default_attributes)
options[:normal_attributes].update(normal_attributes)
options[:override_attributes].update(override_attri... | ruby | def chef_runner_options
super.tap do |options|
options[:halite_gemspec] = halite_gemspec
# And some legacy data.
options[:default_attributes].update(default_attributes)
options[:normal_attributes].update(normal_attributes)
options[:override_attributes].update(override_attri... | [
"def",
"chef_runner_options",
"super",
".",
"tap",
"do",
"|",
"options",
"|",
"options",
"[",
":halite_gemspec",
"]",
"=",
"halite_gemspec",
"options",
"[",
":default_attributes",
"]",
".",
"update",
"(",
"default_attributes",
")",
"options",
"[",
":normal_attribu... | Merge in extra options data. | [
"Merge",
"in",
"extra",
"options",
"data",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/spec_helper.rb#L106-L115 | train |
poise/halite | lib/halite/rake_helper.rb | Halite.RakeHelper.install | def install
extend Rake::DSL
# Core Halite tasks
unless options[:no_gem]
desc "Convert #{gemspec.name}-#{gemspec.version} to a cookbook in the pkg directory"
task 'chef:build' do
build_cookbook
end
desc "Push #{gemspec.name}-#{gemspec.version} to Supermarket"... | ruby | def install
extend Rake::DSL
# Core Halite tasks
unless options[:no_gem]
desc "Convert #{gemspec.name}-#{gemspec.version} to a cookbook in the pkg directory"
task 'chef:build' do
build_cookbook
end
desc "Push #{gemspec.name}-#{gemspec.version} to Supermarket"... | [
"def",
"install",
"extend",
"Rake",
"::",
"DSL",
"unless",
"options",
"[",
":no_gem",
"]",
"desc",
"\"Convert #{gemspec.name}-#{gemspec.version} to a cookbook in the pkg directory\"",
"task",
"'chef:build'",
"do",
"build_cookbook",
"end",
"desc",
"\"Push #{gemspec.name}-#{gemsp... | Install all Rake tasks.
@return [void] | [
"Install",
"all",
"Rake",
"tasks",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/rake_helper.rb#L37-L70 | train |
poise/halite | lib/halite/rake_helper.rb | Halite.RakeHelper.remove_files_in_folder | def remove_files_in_folder(base_path)
existing_files = Dir.glob(File.join(base_path, '**', '*'), File::FNM_DOTMATCH).map {|path| File.expand_path(path)}.uniq.reverse # expand_path just to normalize foo/. -> foo
existing_files.delete(base_path) # Don't remove the base
# Fuck FileUtils, it is a confusin... | ruby | def remove_files_in_folder(base_path)
existing_files = Dir.glob(File.join(base_path, '**', '*'), File::FNM_DOTMATCH).map {|path| File.expand_path(path)}.uniq.reverse # expand_path just to normalize foo/. -> foo
existing_files.delete(base_path) # Don't remove the base
# Fuck FileUtils, it is a confusin... | [
"def",
"remove_files_in_folder",
"(",
"base_path",
")",
"existing_files",
"=",
"Dir",
".",
"glob",
"(",
"File",
".",
"join",
"(",
"base_path",
",",
"'**'",
",",
"'*'",
")",
",",
"File",
"::",
"FNM_DOTMATCH",
")",
".",
"map",
"{",
"|",
"path",
"|",
"Fil... | Remove everything in a path, but not the directory itself | [
"Remove",
"everything",
"in",
"a",
"path",
"but",
"not",
"the",
"directory",
"itself"
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/rake_helper.rb#L145-L159 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/udptrackerdriver.rb | QuartzTorrent.UdpTrackerDriver.readWithTimeout | def readWithTimeout(socket, length, timeout)
rc = IO.select([socket], nil, nil, timeout)
if ! rc
raise "Waiting for response from UDP tracker #{@host}:#{@trackerPort} timed out after #{@timeout} seconds"
elsif rc[0].size > 0
socket.recvfrom(length)[0]
else
raise "Error re... | ruby | def readWithTimeout(socket, length, timeout)
rc = IO.select([socket], nil, nil, timeout)
if ! rc
raise "Waiting for response from UDP tracker #{@host}:#{@trackerPort} timed out after #{@timeout} seconds"
elsif rc[0].size > 0
socket.recvfrom(length)[0]
else
raise "Error re... | [
"def",
"readWithTimeout",
"(",
"socket",
",",
"length",
",",
"timeout",
")",
"rc",
"=",
"IO",
".",
"select",
"(",
"[",
"socket",
"]",
",",
"nil",
",",
"nil",
",",
"timeout",
")",
"if",
"!",
"rc",
"raise",
"\"Waiting for response from UDP tracker #{@host}:#{@... | Throws exception if timeout occurs | [
"Throws",
"exception",
"if",
"timeout",
"occurs"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/udptrackerdriver.rb#L82-L91 | train |
poise/halite | lib/halite/helper_base.rb | Halite.HelperBase.find_gem_name | def find_gem_name(base)
spec = Dir[File.join(base, '*.gemspec')].first
File.basename(spec, '.gemspec') if spec
end | ruby | def find_gem_name(base)
spec = Dir[File.join(base, '*.gemspec')].first
File.basename(spec, '.gemspec') if spec
end | [
"def",
"find_gem_name",
"(",
"base",
")",
"spec",
"=",
"Dir",
"[",
"File",
".",
"join",
"(",
"base",
",",
"'*.gemspec'",
")",
"]",
".",
"first",
"File",
".",
"basename",
"(",
"spec",
",",
"'.gemspec'",
")",
"if",
"spec",
"end"
] | Search a directory for a .gemspec file to determine the gem name.
Returns nil if no gemspec is found.
@param base [String] Folder to search.
@return [String, nil] | [
"Search",
"a",
"directory",
"for",
"a",
".",
"gemspec",
"file",
"to",
"determine",
"the",
"gem",
"name",
".",
"Returns",
"nil",
"if",
"no",
"gemspec",
"is",
"found",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/helper_base.rb#L102-L105 | train |
poise/halite | lib/halite/helper_base.rb | Halite.HelperBase.gemspec | def gemspec
@gemspec ||= begin
raise Error.new("Unable to automatically determine gem name from specs in #{base}. Please set the gem name via #{self.class.name}.install_tasks(gem_name: 'name')") unless gem_name
g = Bundler.load_gemspec(File.join(base, gem_name+'.gemspec'))
# This is return... | ruby | def gemspec
@gemspec ||= begin
raise Error.new("Unable to automatically determine gem name from specs in #{base}. Please set the gem name via #{self.class.name}.install_tasks(gem_name: 'name')") unless gem_name
g = Bundler.load_gemspec(File.join(base, gem_name+'.gemspec'))
# This is return... | [
"def",
"gemspec",
"@gemspec",
"||=",
"begin",
"raise",
"Error",
".",
"new",
"(",
"\"Unable to automatically determine gem name from specs in #{base}. Please set the gem name via #{self.class.name}.install_tasks(gem_name: 'name')\"",
")",
"unless",
"gem_name",
"g",
"=",
"Bundler",
"... | Gem specification for the current gem.
@return [Gem::Specification] | [
"Gem",
"specification",
"for",
"the",
"current",
"gem",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/helper_base.rb#L110-L120 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.metainfoCompletedLength | def metainfoCompletedLength
num = @completePieces.countSet
# Last block may be smaller
extra = 0
if @completePieces.set?(@completePieces.length-1)
num -= 1
extra = @lastPieceLength
end
num*BlockSize + extra
end | ruby | def metainfoCompletedLength
num = @completePieces.countSet
# Last block may be smaller
extra = 0
if @completePieces.set?(@completePieces.length-1)
num -= 1
extra = @lastPieceLength
end
num*BlockSize + extra
end | [
"def",
"metainfoCompletedLength",
"num",
"=",
"@completePieces",
".",
"countSet",
"extra",
"=",
"0",
"if",
"@completePieces",
".",
"set?",
"(",
"@completePieces",
".",
"length",
"-",
"1",
")",
"num",
"-=",
"1",
"extra",
"=",
"@lastPieceLength",
"end",
"num",
... | Return the number of bytes of the metainfo that we have downloaded so far. | [
"Return",
"the",
"number",
"of",
"bytes",
"of",
"the",
"metainfo",
"that",
"we",
"have",
"downloaded",
"so",
"far",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L110-L119 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.savePiece | def savePiece(pieceIndex, data)
id = @pieceManager.writeBlock pieceIndex, 0, data
@pieceManagerRequests[id] = PieceManagerRequestMetadata.new(:write, pieceIndex)
id
end | ruby | def savePiece(pieceIndex, data)
id = @pieceManager.writeBlock pieceIndex, 0, data
@pieceManagerRequests[id] = PieceManagerRequestMetadata.new(:write, pieceIndex)
id
end | [
"def",
"savePiece",
"(",
"pieceIndex",
",",
"data",
")",
"id",
"=",
"@pieceManager",
".",
"writeBlock",
"pieceIndex",
",",
"0",
",",
"data",
"@pieceManagerRequests",
"[",
"id",
"]",
"=",
"PieceManagerRequestMetadata",
".",
"new",
"(",
":write",
",",
"pieceInde... | Save the specified piece to disk asynchronously. | [
"Save",
"the",
"specified",
"piece",
"to",
"disk",
"asynchronously",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L141-L145 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.readPiece | def readPiece(pieceIndex)
length = BlockSize
length = @lastPieceLength if pieceIndex == @numPieces - 1
id = @pieceManager.readBlock pieceIndex, 0, length
#result = manager.nextResult
@pieceManagerRequests[id] = PieceManagerRequestMetadata.new(:read, pieceIndex)
id
end | ruby | def readPiece(pieceIndex)
length = BlockSize
length = @lastPieceLength if pieceIndex == @numPieces - 1
id = @pieceManager.readBlock pieceIndex, 0, length
#result = manager.nextResult
@pieceManagerRequests[id] = PieceManagerRequestMetadata.new(:read, pieceIndex)
id
end | [
"def",
"readPiece",
"(",
"pieceIndex",
")",
"length",
"=",
"BlockSize",
"length",
"=",
"@lastPieceLength",
"if",
"pieceIndex",
"==",
"@numPieces",
"-",
"1",
"id",
"=",
"@pieceManager",
".",
"readBlock",
"pieceIndex",
",",
"0",
",",
"length",
"@pieceManagerReques... | Read a piece from disk. This method is asynchronous; it returns a handle that can be later
used to retreive the result. | [
"Read",
"a",
"piece",
"from",
"disk",
".",
"This",
"method",
"is",
"asynchronous",
";",
"it",
"returns",
"a",
"handle",
"that",
"can",
"be",
"later",
"used",
"to",
"retreive",
"the",
"result",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L149-L156 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.checkResults | def checkResults
results = []
while true
result = @pieceManager.nextResult
break if ! result
results.push result
metaData = @pieceManagerRequests.delete(result.requestId)
if ! metaData
@logger.error "Can't find metadata for PieceManager request #... | ruby | def checkResults
results = []
while true
result = @pieceManager.nextResult
break if ! result
results.push result
metaData = @pieceManagerRequests.delete(result.requestId)
if ! metaData
@logger.error "Can't find metadata for PieceManager request #... | [
"def",
"checkResults",
"results",
"=",
"[",
"]",
"while",
"true",
"result",
"=",
"@pieceManager",
".",
"nextResult",
"break",
"if",
"!",
"result",
"results",
".",
"push",
"result",
"metaData",
"=",
"@pieceManagerRequests",
".",
"delete",
"(",
"result",
".",
... | Check the results of savePiece and readPiece. This method returns a list
of the PieceManager results. | [
"Check",
"the",
"results",
"of",
"savePiece",
"and",
"readPiece",
".",
"This",
"method",
"returns",
"a",
"list",
"of",
"the",
"PieceManager",
"results",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L160-L189 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.findRequestablePieces | def findRequestablePieces
piecesRequired = []
removeOldRequests
@numPieces.times do |pieceIndex|
piecesRequired.push pieceIndex if ! @completePieces.set?(pieceIndex) && ! @requestedPieces.set?(pieceIndex)
end
piecesRequired
end | ruby | def findRequestablePieces
piecesRequired = []
removeOldRequests
@numPieces.times do |pieceIndex|
piecesRequired.push pieceIndex if ! @completePieces.set?(pieceIndex) && ! @requestedPieces.set?(pieceIndex)
end
piecesRequired
end | [
"def",
"findRequestablePieces",
"piecesRequired",
"=",
"[",
"]",
"removeOldRequests",
"@numPieces",
".",
"times",
"do",
"|",
"pieceIndex",
"|",
"piecesRequired",
".",
"push",
"pieceIndex",
"if",
"!",
"@completePieces",
".",
"set?",
"(",
"pieceIndex",
")",
"&&",
... | Return a list of torrent pieces that can still be requested. These are pieces that are not completed and are not requested. | [
"Return",
"a",
"list",
"of",
"torrent",
"pieces",
"that",
"can",
"still",
"be",
"requested",
".",
"These",
"are",
"pieces",
"that",
"are",
"not",
"completed",
"and",
"are",
"not",
"requested",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L192-L202 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.findRequestablePeers | def findRequestablePeers(classifiedPeers)
result = []
classifiedPeers.establishedPeers.each do |peer|
result.push peer if ! @badPeers.findByAddr(peer.trackerPeer.ip, peer.trackerPeer.port)
end
result
end | ruby | def findRequestablePeers(classifiedPeers)
result = []
classifiedPeers.establishedPeers.each do |peer|
result.push peer if ! @badPeers.findByAddr(peer.trackerPeer.ip, peer.trackerPeer.port)
end
result
end | [
"def",
"findRequestablePeers",
"(",
"classifiedPeers",
")",
"result",
"=",
"[",
"]",
"classifiedPeers",
".",
"establishedPeers",
".",
"each",
"do",
"|",
"peer",
"|",
"result",
".",
"push",
"peer",
"if",
"!",
"@badPeers",
".",
"findByAddr",
"(",
"peer",
".",
... | Return a list of peers from whom we can request pieces. These are peers for whom we have an established connection, and
are not marked as bad. See markPeerBad. | [
"Return",
"a",
"list",
"of",
"peers",
"from",
"whom",
"we",
"can",
"request",
"pieces",
".",
"These",
"are",
"peers",
"for",
"whom",
"we",
"have",
"an",
"established",
"connection",
"and",
"are",
"not",
"marked",
"as",
"bad",
".",
"See",
"markPeerBad",
"... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L206-L214 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.setPieceRequested | def setPieceRequested(pieceIndex, bool)
if bool
@requestedPieces.set pieceIndex
@pieceRequestTime[pieceIndex] = Time.new
else
@requestedPieces.clear pieceIndex
@pieceRequestTime[pieceIndex] = nil
end
end | ruby | def setPieceRequested(pieceIndex, bool)
if bool
@requestedPieces.set pieceIndex
@pieceRequestTime[pieceIndex] = Time.new
else
@requestedPieces.clear pieceIndex
@pieceRequestTime[pieceIndex] = nil
end
end | [
"def",
"setPieceRequested",
"(",
"pieceIndex",
",",
"bool",
")",
"if",
"bool",
"@requestedPieces",
".",
"set",
"pieceIndex",
"@pieceRequestTime",
"[",
"pieceIndex",
"]",
"=",
"Time",
".",
"new",
"else",
"@requestedPieces",
".",
"clear",
"pieceIndex",
"@pieceReques... | Set whether the piece with the passed pieceIndex is requested or not. | [
"Set",
"whether",
"the",
"piece",
"with",
"the",
"passed",
"pieceIndex",
"is",
"requested",
"or",
"not",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L217-L225 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/metainfopiecestate.rb | QuartzTorrent.MetainfoPieceState.removeOldRequests | def removeOldRequests
now = Time.new
@requestedPieces.length.times do |i|
if @requestedPieces.set? i
if now - @pieceRequestTime[i] > @requestTimeout
@requestedPieces.clear i
@pieceRequestTime[i] = nil
end
end
end
end | ruby | def removeOldRequests
now = Time.new
@requestedPieces.length.times do |i|
if @requestedPieces.set? i
if now - @pieceRequestTime[i] > @requestTimeout
@requestedPieces.clear i
@pieceRequestTime[i] = nil
end
end
end
end | [
"def",
"removeOldRequests",
"now",
"=",
"Time",
".",
"new",
"@requestedPieces",
".",
"length",
".",
"times",
"do",
"|",
"i",
"|",
"if",
"@requestedPieces",
".",
"set?",
"i",
"if",
"now",
"-",
"@pieceRequestTime",
"[",
"i",
"]",
">",
"@requestTimeout",
"@re... | Remove any pending requests after a timeout. | [
"Remove",
"any",
"pending",
"requests",
"after",
"a",
"timeout",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/metainfopiecestate.rb#L263-L273 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Handler.scheduleTimer | def scheduleTimer(duration, metainfo = nil, recurring = true, immed = false)
@reactor.scheduleTimer(duration, metainfo, recurring, immed) if @reactor
end | ruby | def scheduleTimer(duration, metainfo = nil, recurring = true, immed = false)
@reactor.scheduleTimer(duration, metainfo, recurring, immed) if @reactor
end | [
"def",
"scheduleTimer",
"(",
"duration",
",",
"metainfo",
"=",
"nil",
",",
"recurring",
"=",
"true",
",",
"immed",
"=",
"false",
")",
"@reactor",
".",
"scheduleTimer",
"(",
"duration",
",",
"metainfo",
",",
"recurring",
",",
"immed",
")",
"if",
"@reactor",... | Schedule a timer.
@param duration The duration of the timer in seconds
@param metainfo The metainfo to associate with the timer
@param recurring If true when the timer duration expires, the timer will be rescheduled. If false the timer
will not be rescheduled.
@param immed If true then th... | [
"Schedule",
"a",
"timer",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L75-L77 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Handler.connect | def connect(addr, port, metainfo, timeout = nil)
@reactor.connect(addr, port, metainfo, timeout) if @reactor
end | ruby | def connect(addr, port, metainfo, timeout = nil)
@reactor.connect(addr, port, metainfo, timeout) if @reactor
end | [
"def",
"connect",
"(",
"addr",
",",
"port",
",",
"metainfo",
",",
"timeout",
"=",
"nil",
")",
"@reactor",
".",
"connect",
"(",
"addr",
",",
"port",
",",
"metainfo",
",",
"timeout",
")",
"if",
"@reactor",
"end"
] | Create a TCP connection to the specified host and port. Associate the passed metainfo with the IO representing the connection. | [
"Create",
"a",
"TCP",
"connection",
"to",
"the",
"specified",
"host",
"and",
"port",
".",
"Associate",
"the",
"passed",
"metainfo",
"with",
"the",
"IO",
"representing",
"the",
"connection",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L86-L88 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.IoFacade.read | def read(length)
data = ''
while data.length < length
begin
toRead = length-data.length
rateLimited = false
if @ioInfo.readRateLimit
avail = @ioInfo.readRateLimit.avail.to_i
if avail < toRead
toRead = avail
rateLimited... | ruby | def read(length)
data = ''
while data.length < length
begin
toRead = length-data.length
rateLimited = false
if @ioInfo.readRateLimit
avail = @ioInfo.readRateLimit.avail.to_i
if avail < toRead
toRead = avail
rateLimited... | [
"def",
"read",
"(",
"length",
")",
"data",
"=",
"''",
"while",
"data",
".",
"length",
"<",
"length",
"begin",
"toRead",
"=",
"length",
"-",
"data",
".",
"length",
"rateLimited",
"=",
"false",
"if",
"@ioInfo",
".",
"readRateLimit",
"avail",
"=",
"@ioInfo"... | Read `length` bytes. | [
"Read",
"length",
"bytes",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L230-L269 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.connect | def connect(addr, port, metainfo, timeout = nil)
ioInfo = startConnection(port, addr, metainfo)
@ioInfo[ioInfo.io] = ioInfo
if timeout && ioInfo.state == :connecting
ioInfo.connectTimeout = timeout
ioInfo.connectTimer = scheduleTimer(timeout, InternalTimerInfo.new(:connect_timeout, ioI... | ruby | def connect(addr, port, metainfo, timeout = nil)
ioInfo = startConnection(port, addr, metainfo)
@ioInfo[ioInfo.io] = ioInfo
if timeout && ioInfo.state == :connecting
ioInfo.connectTimeout = timeout
ioInfo.connectTimer = scheduleTimer(timeout, InternalTimerInfo.new(:connect_timeout, ioI... | [
"def",
"connect",
"(",
"addr",
",",
"port",
",",
"metainfo",
",",
"timeout",
"=",
"nil",
")",
"ioInfo",
"=",
"startConnection",
"(",
"port",
",",
"addr",
",",
"metainfo",
")",
"@ioInfo",
"[",
"ioInfo",
".",
"io",
"]",
"=",
"ioInfo",
"if",
"timeout",
... | Create a TCP connection to the specified host.
Note that this method may raise exceptions. For example 'Too many open files' might be raised if
the process is using too many file descriptors | [
"Create",
"a",
"TCP",
"connection",
"to",
"the",
"specified",
"host",
".",
"Note",
"that",
"this",
"method",
"may",
"raise",
"exceptions",
".",
"For",
"example",
"Too",
"many",
"open",
"files",
"might",
"be",
"raised",
"if",
"the",
"process",
"is",
"using"... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L422-L429 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.listen | def listen(addr, port, metainfo)
listener = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( port, "0.0.0.0" )
listener.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
listener.bind( sockaddr )
@logger.debug "listening on port #{port}" if @logger
li... | ruby | def listen(addr, port, metainfo)
listener = Socket.new( AF_INET, SOCK_STREAM, 0 )
sockaddr = Socket.pack_sockaddr_in( port, "0.0.0.0" )
listener.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
listener.bind( sockaddr )
@logger.debug "listening on port #{port}" if @logger
li... | [
"def",
"listen",
"(",
"addr",
",",
"port",
",",
"metainfo",
")",
"listener",
"=",
"Socket",
".",
"new",
"(",
"AF_INET",
",",
"SOCK_STREAM",
",",
"0",
")",
"sockaddr",
"=",
"Socket",
".",
"pack_sockaddr_in",
"(",
"port",
",",
"\"0.0.0.0\"",
")",
"listener... | Create a TCP server that listens for connections on the specified
port | [
"Create",
"a",
"TCP",
"server",
"that",
"listens",
"for",
"connections",
"on",
"the",
"specified",
"port"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L433-L445 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.open | def open(path, mode, metainfo, useErrorhandler = true)
file = File.open(path, mode)
info = IOInfo.new(file, metainfo, true)
info.useErrorhandler = useErrorhandler
info.readFiberIoFacade.logger = @logger if @logger
info.state = :connected
@ioInfo[info.io] = info
end | ruby | def open(path, mode, metainfo, useErrorhandler = true)
file = File.open(path, mode)
info = IOInfo.new(file, metainfo, true)
info.useErrorhandler = useErrorhandler
info.readFiberIoFacade.logger = @logger if @logger
info.state = :connected
@ioInfo[info.io] = info
end | [
"def",
"open",
"(",
"path",
",",
"mode",
",",
"metainfo",
",",
"useErrorhandler",
"=",
"true",
")",
"file",
"=",
"File",
".",
"open",
"(",
"path",
",",
"mode",
")",
"info",
"=",
"IOInfo",
".",
"new",
"(",
"file",
",",
"metainfo",
",",
"true",
")",
... | Open the specified file for the specified mode. | [
"Open",
"the",
"specified",
"file",
"for",
"the",
"specified",
"mode",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L448-L456 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.start | def start
while true
begin
break if eventLoopBody == :halt
rescue
@logger.error "Unexpected exception in reactor event loop: #{$!}" if @logger
@logger.error $!.backtrace.join "\n" if @logger
end
end
@logger.info "Reactor shutting down" if @logger
... | ruby | def start
while true
begin
break if eventLoopBody == :halt
rescue
@logger.error "Unexpected exception in reactor event loop: #{$!}" if @logger
@logger.error $!.backtrace.join "\n" if @logger
end
end
@logger.info "Reactor shutting down" if @logger
... | [
"def",
"start",
"while",
"true",
"begin",
"break",
"if",
"eventLoopBody",
"==",
":halt",
"rescue",
"@logger",
".",
"error",
"\"Unexpected exception in reactor event loop: #{$!}\"",
"if",
"@logger",
"@logger",
".",
"error",
"$!",
".",
"backtrace",
".",
"join",
"\"\\n... | Run event loop | [
"Run",
"event",
"loop"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L465-L482 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.findIoByMetainfo | def findIoByMetainfo(metainfo)
@ioInfo.each_value do |info|
if info.metainfo == metainfo
io = info.readFiberIoFacade
# Don't allow read calls from timer handlers. This is to prevent a complex situation.
# See the processTimer call in eventLoopBody for more info
io =... | ruby | def findIoByMetainfo(metainfo)
@ioInfo.each_value do |info|
if info.metainfo == metainfo
io = info.readFiberIoFacade
# Don't allow read calls from timer handlers. This is to prevent a complex situation.
# See the processTimer call in eventLoopBody for more info
io =... | [
"def",
"findIoByMetainfo",
"(",
"metainfo",
")",
"@ioInfo",
".",
"each_value",
"do",
"|",
"info",
"|",
"if",
"info",
".",
"metainfo",
"==",
"metainfo",
"io",
"=",
"info",
".",
"readFiberIoFacade",
"io",
"=",
"WriteOnlyIoFacade",
".",
"new",
"(",
"info",
")... | Meant to be called from the handler. Find an IO by metainfo. The == operator is used to
match the metainfo. | [
"Meant",
"to",
"be",
"called",
"from",
"the",
"handler",
".",
"Find",
"an",
"IO",
"by",
"metainfo",
".",
"The",
"==",
"operator",
"is",
"used",
"to",
"match",
"the",
"metainfo",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L569-L580 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.handleAccept | def handleAccept(ioInfo)
socket, clientAddr = ioInfo.io.accept
info = IOInfo.new(socket, ioInfo.metainfo)
info.readFiberIoFacade.logger = @logger if @logger
info.state = :connected
@ioInfo[info.io] = info
if @logger
port, addr = Socket.unpack_sockaddr_in(clientAddr)
@... | ruby | def handleAccept(ioInfo)
socket, clientAddr = ioInfo.io.accept
info = IOInfo.new(socket, ioInfo.metainfo)
info.readFiberIoFacade.logger = @logger if @logger
info.state = :connected
@ioInfo[info.io] = info
if @logger
port, addr = Socket.unpack_sockaddr_in(clientAddr)
@... | [
"def",
"handleAccept",
"(",
"ioInfo",
")",
"socket",
",",
"clientAddr",
"=",
"ioInfo",
".",
"io",
".",
"accept",
"info",
"=",
"IOInfo",
".",
"new",
"(",
"socket",
",",
"ioInfo",
".",
"metainfo",
")",
"info",
".",
"readFiberIoFacade",
".",
"logger",
"=",
... | Given the ioInfo for a listening socket, call accept and return the new ioInfo for the
client's socket | [
"Given",
"the",
"ioInfo",
"for",
"a",
"listening",
"socket",
"call",
"accept",
"and",
"return",
"the",
"new",
"ioInfo",
"for",
"the",
"client",
"s",
"socket"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L813-L825 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/reactor.rb | QuartzTorrent.Reactor.withReadFiber | def withReadFiber(ioInfo)
if ioInfo.readFiber.nil? || ! ioInfo.readFiber.alive?
ioInfo.readFiber = Fiber.new do |ioInfo|
yield ioInfo.readFiberIoFacade
end
end
# Allow handler to read some data.
# This call will return either if:
# 1. the handler needs mo... | ruby | def withReadFiber(ioInfo)
if ioInfo.readFiber.nil? || ! ioInfo.readFiber.alive?
ioInfo.readFiber = Fiber.new do |ioInfo|
yield ioInfo.readFiberIoFacade
end
end
# Allow handler to read some data.
# This call will return either if:
# 1. the handler needs mo... | [
"def",
"withReadFiber",
"(",
"ioInfo",
")",
"if",
"ioInfo",
".",
"readFiber",
".",
"nil?",
"||",
"!",
"ioInfo",
".",
"readFiber",
".",
"alive?",
"ioInfo",
".",
"readFiber",
"=",
"Fiber",
".",
"new",
"do",
"|",
"ioInfo",
"|",
"yield",
"ioInfo",
".",
"re... | Call the passed block in the context of the read Fiber. Basically the
passed block is run as normal, but if the block performs a read from an io and that
read would block, the block is paused, and withReadFiber returns. The next time withReadFiber
is called the block will be resumed at the point of the read. | [
"Call",
"the",
"passed",
"block",
"in",
"the",
"context",
"of",
"the",
"read",
"Fiber",
".",
"Basically",
"the",
"passed",
"block",
"is",
"run",
"as",
"normal",
"but",
"if",
"the",
"block",
"performs",
"a",
"read",
"from",
"an",
"io",
"and",
"that",
"r... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/reactor.rb#L856-L879 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peermanager.rb | QuartzTorrent.PeerManager.manageConnections | def manageConnections(classifiedPeers)
n = classifiedPeers.handshakingPeers.size + classifiedPeers.establishedPeers.size
if n < @targetActivePeerCount
result = classifiedPeers.disconnectedPeers.shuffle.first(@targetActivePeerCount - n)
@logger.debug "There are #{n} peers connected or in han... | ruby | def manageConnections(classifiedPeers)
n = classifiedPeers.handshakingPeers.size + classifiedPeers.establishedPeers.size
if n < @targetActivePeerCount
result = classifiedPeers.disconnectedPeers.shuffle.first(@targetActivePeerCount - n)
@logger.debug "There are #{n} peers connected or in han... | [
"def",
"manageConnections",
"(",
"classifiedPeers",
")",
"n",
"=",
"classifiedPeers",
".",
"handshakingPeers",
".",
"size",
"+",
"classifiedPeers",
".",
"establishedPeers",
".",
"size",
"if",
"n",
"<",
"@targetActivePeerCount",
"result",
"=",
"classifiedPeers",
".",... | Determine if we need to connect to more peers.
Returns a list of peers to connect to. | [
"Determine",
"if",
"we",
"need",
"to",
"connect",
"to",
"more",
"peers",
".",
"Returns",
"a",
"list",
"of",
"peers",
"to",
"connect",
"to",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peermanager.rb#L46-L56 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peermanager.rb | QuartzTorrent.PeerManager.selectOptimisticPeer | def selectOptimisticPeer(classifiedPeers)
# "at any one time there is a single peer which is unchoked regardless of its upload rate (if interested, it counts as one of the four allowed downloaders). Which peer is optimistically
# unchoked rotates every 30 seconds. Newly connected peers are three times as l... | ruby | def selectOptimisticPeer(classifiedPeers)
# "at any one time there is a single peer which is unchoked regardless of its upload rate (if interested, it counts as one of the four allowed downloaders). Which peer is optimistically
# unchoked rotates every 30 seconds. Newly connected peers are three times as l... | [
"def",
"selectOptimisticPeer",
"(",
"classifiedPeers",
")",
"if",
"!",
"@lastOptimisticPeerChangeTime",
"||",
"(",
"Time",
".",
"new",
"-",
"@lastOptimisticPeerChangeTime",
">",
"@optimisticPeerChangeDuration",
")",
"list",
"=",
"[",
"]",
"classifiedPeers",
".",
"esta... | Choose a peer that we will optimistically unchoke. | [
"Choose",
"a",
"peer",
"that",
"we",
"will",
"optimistically",
"unchoke",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peermanager.rb#L148-L168 | train |
rjurado01/rapidoc | lib/rapidoc/controller_extractor.rb | Rapidoc.ControllerExtractor.extract_blocks | def extract_blocks( lines )
init_doc_lines = lines.each_index.select{ |i| lines[i].include? "=begin" }
end_doc_lines = lines.each_index.select{ |i| lines[i].include? "=end" }
blocks = init_doc_lines.each_index.map do |i|
{ :init => init_doc_lines[i], :end => end_doc_lines[i] }
end
e... | ruby | def extract_blocks( lines )
init_doc_lines = lines.each_index.select{ |i| lines[i].include? "=begin" }
end_doc_lines = lines.each_index.select{ |i| lines[i].include? "=end" }
blocks = init_doc_lines.each_index.map do |i|
{ :init => init_doc_lines[i], :end => end_doc_lines[i] }
end
e... | [
"def",
"extract_blocks",
"(",
"lines",
")",
"init_doc_lines",
"=",
"lines",
".",
"each_index",
".",
"select",
"{",
"|",
"i",
"|",
"lines",
"[",
"i",
"]",
".",
"include?",
"\"=begin\"",
"}",
"end_doc_lines",
"=",
"lines",
".",
"each_index",
".",
"select",
... | Gets init and end lines of each comment block | [
"Gets",
"init",
"and",
"end",
"lines",
"of",
"each",
"comment",
"block"
] | 03b7a8f29a37dd03f4ed5036697b48551d3b4ae6 | https://github.com/rjurado01/rapidoc/blob/03b7a8f29a37dd03f4ed5036697b48551d3b4ae6/lib/rapidoc/controller_extractor.rb#L45-L52 | train |
merqlove/do_snapshot | lib/do_snapshot/command.rb | DoSnapshot.Command.create_snapshot | def create_snapshot(droplet) # rubocop:disable MethodLength,Metrics/AbcSize
fail_if_shutdown(droplet)
logger.info "Start creating snapshot for droplet id: #{droplet.id} name: #{droplet.name}."
today = DateTime.now
name = "#{droplet.name}_#{today.strftime('%Y_%m_%d')}"
# ... | ruby | def create_snapshot(droplet) # rubocop:disable MethodLength,Metrics/AbcSize
fail_if_shutdown(droplet)
logger.info "Start creating snapshot for droplet id: #{droplet.id} name: #{droplet.name}."
today = DateTime.now
name = "#{droplet.name}_#{today.strftime('%Y_%m_%d')}"
# ... | [
"def",
"create_snapshot",
"(",
"droplet",
")",
"fail_if_shutdown",
"(",
"droplet",
")",
"logger",
".",
"info",
"\"Start creating snapshot for droplet id: #{droplet.id} name: #{droplet.name}.\"",
"today",
"=",
"DateTime",
".",
"now",
"name",
"=",
"\"#{droplet.name}_#{today.str... | Trying to create a snapshot. | [
"Trying",
"to",
"create",
"a",
"snapshot",
"."
] | a72212ca489973a64987f0e9eb4abaae57de1abe | https://github.com/merqlove/do_snapshot/blob/a72212ca489973a64987f0e9eb4abaae57de1abe/lib/do_snapshot/command.rb#L61-L91 | train |
merqlove/do_snapshot | lib/do_snapshot/command.rb | DoSnapshot.Command.dispatch_droplets | def dispatch_droplets
droplets.each do |droplet|
id = droplet.id.to_s
next if exclude.include? id
next unless only.empty? || only.include?(id)
prepare_droplet id, droplet.name
end
end | ruby | def dispatch_droplets
droplets.each do |droplet|
id = droplet.id.to_s
next if exclude.include? id
next unless only.empty? || only.include?(id)
prepare_droplet id, droplet.name
end
end | [
"def",
"dispatch_droplets",
"droplets",
".",
"each",
"do",
"|",
"droplet",
"|",
"id",
"=",
"droplet",
".",
"id",
".",
"to_s",
"next",
"if",
"exclude",
".",
"include?",
"id",
"next",
"unless",
"only",
".",
"empty?",
"||",
"only",
".",
"include?",
"(",
"... | Dispatch received droplets, each by each. | [
"Dispatch",
"received",
"droplets",
"each",
"by",
"each",
"."
] | a72212ca489973a64987f0e9eb4abaae57de1abe | https://github.com/merqlove/do_snapshot/blob/a72212ca489973a64987f0e9eb4abaae57de1abe/lib/do_snapshot/command.rb#L149-L157 | train |
merqlove/do_snapshot | lib/do_snapshot/command.rb | DoSnapshot.Command.prepare_droplet | def prepare_droplet(id, name)
logger.debug "Droplet id: #{id} name: #{name}\n"
droplet = api.droplet id
return unless droplet
logger.info "Preparing droplet id: #{droplet.id} name: #{droplet.name} to take snapshot."
return if too_much_snapshots?(droplet)
processed_droplet_ids << dro... | ruby | def prepare_droplet(id, name)
logger.debug "Droplet id: #{id} name: #{name}\n"
droplet = api.droplet id
return unless droplet
logger.info "Preparing droplet id: #{droplet.id} name: #{droplet.name} to take snapshot."
return if too_much_snapshots?(droplet)
processed_droplet_ids << dro... | [
"def",
"prepare_droplet",
"(",
"id",
",",
"name",
")",
"logger",
".",
"debug",
"\"Droplet id: #{id} name: #{name}\\n\"",
"droplet",
"=",
"api",
".",
"droplet",
"id",
"return",
"unless",
"droplet",
"logger",
".",
"info",
"\"Preparing droplet id: #{droplet.id} name: #{dro... | Preparing droplet to take a snapshot.
Droplet instance must be powered off first! | [
"Preparing",
"droplet",
"to",
"take",
"a",
"snapshot",
".",
"Droplet",
"instance",
"must",
"be",
"powered",
"off",
"first!"
] | a72212ca489973a64987f0e9eb4abaae57de1abe | https://github.com/merqlove/do_snapshot/blob/a72212ca489973a64987f0e9eb4abaae57de1abe/lib/do_snapshot/command.rb#L176-L185 | train |
merqlove/do_snapshot | lib/do_snapshot/command.rb | DoSnapshot.Command.cleanup_snapshots | def cleanup_snapshots(droplet, size) # rubocop:disable Metrics/AbcSize
return unless size > keep
warning_size(droplet.id, droplet.name, size)
logger.debug "Cleaning up snapshots for droplet id: #{droplet.id} name: #{droplet.name}."
api.cleanup_snapshots(droplet, size - keep - 1)
rescue =>... | ruby | def cleanup_snapshots(droplet, size) # rubocop:disable Metrics/AbcSize
return unless size > keep
warning_size(droplet.id, droplet.name, size)
logger.debug "Cleaning up snapshots for droplet id: #{droplet.id} name: #{droplet.name}."
api.cleanup_snapshots(droplet, size - keep - 1)
rescue =>... | [
"def",
"cleanup_snapshots",
"(",
"droplet",
",",
"size",
")",
"return",
"unless",
"size",
">",
"keep",
"warning_size",
"(",
"droplet",
".",
"id",
",",
"droplet",
".",
"name",
",",
"size",
")",
"logger",
".",
"debug",
"\"Cleaning up snapshots for droplet id: #{dr... | Cleanup our snapshots. | [
"Cleanup",
"our",
"snapshots",
"."
] | a72212ca489973a64987f0e9eb4abaae57de1abe | https://github.com/merqlove/do_snapshot/blob/a72212ca489973a64987f0e9eb4abaae57de1abe/lib/do_snapshot/command.rb#L200-L210 | train |
philm/twilio | lib/twilio/available_phone_numbers.rb | Twilio.AvailablePhoneNumbers.search | def search(opts={})
iso_country_code = opts[:iso_country_code] || 'US'
resource = opts.delete(:resource)
params = {
:AreaCode => opts[:area_code],
:InPostalCode => opts[:postal_code],
:InRegion => opts[:in_region],
:Contains => opts[:contains],
:NearLatLong => ... | ruby | def search(opts={})
iso_country_code = opts[:iso_country_code] || 'US'
resource = opts.delete(:resource)
params = {
:AreaCode => opts[:area_code],
:InPostalCode => opts[:postal_code],
:InRegion => opts[:in_region],
:Contains => opts[:contains],
:NearLatLong => ... | [
"def",
"search",
"(",
"opts",
"=",
"{",
"}",
")",
"iso_country_code",
"=",
"opts",
"[",
":iso_country_code",
"]",
"||",
"'US'",
"resource",
"=",
"opts",
".",
"delete",
"(",
":resource",
")",
"params",
"=",
"{",
":AreaCode",
"=>",
"opts",
"[",
":area_code... | The Search method handles the searching of both local and toll-free
numbers. | [
"The",
"Search",
"method",
"handles",
"the",
"searching",
"of",
"both",
"local",
"and",
"toll",
"-",
"free",
"numbers",
"."
] | 81c05795924bbfa780ea44efd52d7ca5670bcb55 | https://github.com/philm/twilio/blob/81c05795924bbfa780ea44efd52d7ca5670bcb55/lib/twilio/available_phone_numbers.rb#L12-L31 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.addTrackerClient | def addTrackerClient(infoHash, info, trackerclient)
raise "There is already a tracker registered for torrent #{QuartzTorrent.bytesToHex(infoHash)}" if @torrentData.has_key? infoHash
torrentData = TorrentData.new(infoHash, info, trackerclient)
trackerclient.alarms = torrentData.alarms
@torrentDat... | ruby | def addTrackerClient(infoHash, info, trackerclient)
raise "There is already a tracker registered for torrent #{QuartzTorrent.bytesToHex(infoHash)}" if @torrentData.has_key? infoHash
torrentData = TorrentData.new(infoHash, info, trackerclient)
trackerclient.alarms = torrentData.alarms
@torrentDat... | [
"def",
"addTrackerClient",
"(",
"infoHash",
",",
"info",
",",
"trackerclient",
")",
"raise",
"\"There is already a tracker registered for torrent #{QuartzTorrent.bytesToHex(infoHash)}\"",
"if",
"@torrentData",
".",
"has_key?",
"infoHash",
"torrentData",
"=",
"TorrentData",
".",... | Add a new tracker client. This effectively adds a new torrent to download. Returns the TorrentData object for the
new torrent. | [
"Add",
"a",
"new",
"tracker",
"client",
".",
"This",
"effectively",
"adds",
"a",
"new",
"torrent",
"to",
"download",
".",
"Returns",
"the",
"TorrentData",
"object",
"for",
"the",
"new",
"torrent",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L286-L298 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.removeTorrent | def removeTorrent(infoHash, deleteFiles = false)
# Can't do this right now, since it could be in use by an event handler. Use an immediate, non-recurring timer instead.
@logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Scheduling immediate timer to remove torrent. #{deleteFiles ? "Will" : "Wont"} delete ... | ruby | def removeTorrent(infoHash, deleteFiles = false)
# Can't do this right now, since it could be in use by an event handler. Use an immediate, non-recurring timer instead.
@logger.info "#{QuartzTorrent.bytesToHex(infoHash)}: Scheduling immediate timer to remove torrent. #{deleteFiles ? "Will" : "Wont"} delete ... | [
"def",
"removeTorrent",
"(",
"infoHash",
",",
"deleteFiles",
"=",
"false",
")",
"@logger",
".",
"info",
"\"#{QuartzTorrent.bytesToHex(infoHash)}: Scheduling immediate timer to remove torrent. #{deleteFiles ? \"Will\" : \"Wont\"} delete downloaded files.\"",
"@reactor",
".",
"scheduleTi... | Remove a torrent. | [
"Remove",
"a",
"torrent",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L301-L305 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.setDownloadRateLimit | def setDownloadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set download rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.downRa... | ruby | def setDownloadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set download rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.downRa... | [
"def",
"setDownloadRateLimit",
"(",
"infoHash",
",",
"bytesPerSecond",
")",
"torrentData",
"=",
"@torrentData",
"[",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"Asked to set download rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(info... | Set the download rate limit. Pass nil as the bytesPerSecond to disable the limit. | [
"Set",
"the",
"download",
"rate",
"limit",
".",
"Pass",
"nil",
"as",
"the",
"bytesPerSecond",
"to",
"disable",
"the",
"limit",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L315-L338 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.setUploadRateLimit | def setUploadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set upload rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.upRateLimit... | ruby | def setUploadRateLimit(infoHash, bytesPerSecond)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to set upload rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
if bytesPerSecond
if ! torrentData.upRateLimit... | [
"def",
"setUploadRateLimit",
"(",
"infoHash",
",",
"bytesPerSecond",
")",
"torrentData",
"=",
"@torrentData",
"[",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"Asked to set upload rate limit for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash... | Set the upload rate limit. Pass nil as the bytesPerSecond to disable the limit. | [
"Set",
"the",
"upload",
"rate",
"limit",
".",
"Pass",
"nil",
"as",
"the",
"bytesPerSecond",
"to",
"disable",
"the",
"limit",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L341-L363 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.adjustBytesDownloaded | def adjustBytesDownloaded(infoHash, adjustment)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to adjust uploaded bytes for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
runInReactorThread do
torrentData.bytesDo... | ruby | def adjustBytesDownloaded(infoHash, adjustment)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to adjust uploaded bytes for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
runInReactorThread do
torrentData.bytesDo... | [
"def",
"adjustBytesDownloaded",
"(",
"infoHash",
",",
"adjustment",
")",
"torrentData",
"=",
"@torrentData",
"[",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"Asked to adjust uploaded bytes for a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)... | Adjust the bytesDownloaded property of the specified torrent by the passed amount.
Adjustment should be an integer. It is added to the current bytesDownloaded amount. | [
"Adjust",
"the",
"bytesDownloaded",
"property",
"of",
"the",
"specified",
"torrent",
"by",
"the",
"passed",
"amount",
".",
"Adjustment",
"should",
"be",
"an",
"integer",
".",
"It",
"is",
"added",
"to",
"the",
"current",
"bytesDownloaded",
"amount",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L405-L416 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.updateDelegateTorrentData | def updateDelegateTorrentData(delegate)
return if stopped?
# Use an immediate, non-recurring timer.
semaphore = Semaphore.new
@reactor.scheduleTimer(0, [:update_torrent_data, delegate, semaphore], false, true)
semaphore.wait
result
end | ruby | def updateDelegateTorrentData(delegate)
return if stopped?
# Use an immediate, non-recurring timer.
semaphore = Semaphore.new
@reactor.scheduleTimer(0, [:update_torrent_data, delegate, semaphore], false, true)
semaphore.wait
result
end | [
"def",
"updateDelegateTorrentData",
"(",
"delegate",
")",
"return",
"if",
"stopped?",
"semaphore",
"=",
"Semaphore",
".",
"new",
"@reactor",
".",
"scheduleTimer",
"(",
"0",
",",
"[",
":update_torrent_data",
",",
"delegate",
",",
"semaphore",
"]",
",",
"false",
... | Update the data stored in a TorrentDataDelegate to the latest information. | [
"Update",
"the",
"data",
"stored",
"in",
"a",
"TorrentDataDelegate",
"to",
"the",
"latest",
"information",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L438-L445 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.serverInit | def serverInit(metadata, addr, port)
# A peer connected to us
# Read handshake message
@logger.warn "Peer connection from #{addr}:#{port}"
begin
msg = PeerHandshake.unserializeExceptPeerIdFrom currentIo
rescue
@logger.warn "Peer failed handshake: #{$!}"
close
... | ruby | def serverInit(metadata, addr, port)
# A peer connected to us
# Read handshake message
@logger.warn "Peer connection from #{addr}:#{port}"
begin
msg = PeerHandshake.unserializeExceptPeerIdFrom currentIo
rescue
@logger.warn "Peer failed handshake: #{$!}"
close
... | [
"def",
"serverInit",
"(",
"metadata",
",",
"addr",
",",
"port",
")",
"@logger",
".",
"warn",
"\"Peer connection from #{addr}:#{port}\"",
"begin",
"msg",
"=",
"PeerHandshake",
".",
"unserializeExceptPeerIdFrom",
"currentIo",
"rescue",
"@logger",
".",
"warn",
"\"Peer fa... | REACTOR METHODS
Reactor method called when a peer has connected to us. | [
"REACTOR",
"METHODS",
"Reactor",
"method",
"called",
"when",
"a",
"peer",
"has",
"connected",
"to",
"us",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L451-L551 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.clientInit | def clientInit(peer)
# We connected to a peer
# Send handshake
torrentData = @torrentData[peer.infoHash]
if ! torrentData
@logger.warn "No tracker client found for peer #{peer}. Closing connection."
close
return
end
trackerclient = torrentData.trackerClient
... | ruby | def clientInit(peer)
# We connected to a peer
# Send handshake
torrentData = @torrentData[peer.infoHash]
if ! torrentData
@logger.warn "No tracker client found for peer #{peer}. Closing connection."
close
return
end
trackerclient = torrentData.trackerClient
... | [
"def",
"clientInit",
"(",
"peer",
")",
"torrentData",
"=",
"@torrentData",
"[",
"peer",
".",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"No tracker client found for peer #{peer}. Closing connection.\"",
"close",
"return",
"end",
"trackerclient"... | Reactor method called when we have connected to a peer. | [
"Reactor",
"method",
"called",
"when",
"we",
"have",
"connected",
"to",
"a",
"peer",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L554-L579 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.recvData | def recvData(peer)
msg = nil
@logger.debug "Got data from peer #{peer}"
if peer.state == :handshaking
# Read handshake message
begin
@logger.debug "Reading handshake from #{peer}"
msg = PeerHandshake.unserializeFrom currentIo
rescue
@logger.warn ... | ruby | def recvData(peer)
msg = nil
@logger.debug "Got data from peer #{peer}"
if peer.state == :handshaking
# Read handshake message
begin
@logger.debug "Reading handshake from #{peer}"
msg = PeerHandshake.unserializeFrom currentIo
rescue
@logger.warn ... | [
"def",
"recvData",
"(",
"peer",
")",
"msg",
"=",
"nil",
"@logger",
".",
"debug",
"\"Got data from peer #{peer}\"",
"if",
"peer",
".",
"state",
"==",
":handshaking",
"begin",
"@logger",
".",
"debug",
"\"Reading handshake from #{peer}\"",
"msg",
"=",
"PeerHandshake",
... | Reactor method called when there is data ready to be read from a socket | [
"Reactor",
"method",
"called",
"when",
"there",
"is",
"data",
"ready",
"to",
"be",
"read",
"from",
"a",
"socket"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L582-L666 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.timerExpired | def timerExpired(metadata)
if metadata.is_a?(Array) && metadata[0] == :manage_peers
managePeers(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :request_blocks
requestBlocks(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :check_piece_manager
checkPieceMan... | ruby | def timerExpired(metadata)
if metadata.is_a?(Array) && metadata[0] == :manage_peers
managePeers(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :request_blocks
requestBlocks(metadata[1])
elsif metadata.is_a?(Array) && metadata[0] == :check_piece_manager
checkPieceMan... | [
"def",
"timerExpired",
"(",
"metadata",
")",
"if",
"metadata",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"metadata",
"[",
"0",
"]",
"==",
":manage_peers",
"managePeers",
"(",
"metadata",
"[",
"1",
"]",
")",
"elsif",
"metadata",
".",
"is_a?",
"(",
"Array",
... | Reactor method called when a scheduled timer expires. | [
"Reactor",
"method",
"called",
"when",
"a",
"scheduled",
"timer",
"expires",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L669-L712 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.requestMetadataPieces | def requestMetadataPieces(infoHash)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
return
end
return if torrentData.paused || torrentData.queued
... | ruby | def requestMetadataPieces(infoHash)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.error "Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found."
return
end
return if torrentData.paused || torrentData.queued
... | [
"def",
"requestMetadataPieces",
"(",
"infoHash",
")",
"torrentData",
"=",
"@torrentData",
"[",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"error",
"\"Request metadata pices: torrent data for torrent #{QuartzTorrent.bytesToHex(infoHash)} not found.\"",
"return",
... | For a torrent where we don't have the metainfo, request metainfo pieces from peers. | [
"For",
"a",
"torrent",
"where",
"we",
"don",
"t",
"have",
"the",
"metainfo",
"request",
"metainfo",
"pieces",
"from",
"peers",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1003-L1038 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.withPeersIo | def withPeersIo(peer, what = nil)
io = findIoByMetainfo(peer)
if io
yield io
else
s = ""
s = "when #{what}" if what
@logger.warn "Couldn't find the io for peer #{peer} #{what}"
end
end | ruby | def withPeersIo(peer, what = nil)
io = findIoByMetainfo(peer)
if io
yield io
else
s = ""
s = "when #{what}" if what
@logger.warn "Couldn't find the io for peer #{peer} #{what}"
end
end | [
"def",
"withPeersIo",
"(",
"peer",
",",
"what",
"=",
"nil",
")",
"io",
"=",
"findIoByMetainfo",
"(",
"peer",
")",
"if",
"io",
"yield",
"io",
"else",
"s",
"=",
"\"\"",
"s",
"=",
"\"when #{what}\"",
"if",
"what",
"@logger",
".",
"warn",
"\"Couldn't find th... | Find the io associated with the peer and yield it to the passed block.
If no io is found an error is logged. | [
"Find",
"the",
"io",
"associated",
"with",
"the",
"peer",
"and",
"yield",
"it",
"to",
"the",
"passed",
"block",
".",
"If",
"no",
"io",
"is",
"found",
"an",
"error",
"is",
"logged",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1451-L1460 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.getPeersFromTracker | def getPeersFromTracker(torrentData, infoHash)
addPeer = Proc.new do |trackerPeer|
peer = Peer.new(trackerPeer)
peer.infoHash = infoHash
torrentData.peers.add peer
true
end
classifiedPeers = nil
replaceDisconnectedPeer = Proc.new do |trackerPeer|
classifi... | ruby | def getPeersFromTracker(torrentData, infoHash)
addPeer = Proc.new do |trackerPeer|
peer = Peer.new(trackerPeer)
peer.infoHash = infoHash
torrentData.peers.add peer
true
end
classifiedPeers = nil
replaceDisconnectedPeer = Proc.new do |trackerPeer|
classifi... | [
"def",
"getPeersFromTracker",
"(",
"torrentData",
",",
"infoHash",
")",
"addPeer",
"=",
"Proc",
".",
"new",
"do",
"|",
"trackerPeer",
"|",
"peer",
"=",
"Peer",
".",
"new",
"(",
"trackerPeer",
")",
"peer",
".",
"infoHash",
"=",
"infoHash",
"torrentData",
".... | Update our internal peer list for this torrent from the tracker client | [
"Update",
"our",
"internal",
"peer",
"list",
"for",
"this",
"torrent",
"from",
"the",
"tracker",
"client"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1517-L1556 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.handleRemoveTorrent | def handleRemoveTorrent(infoHash, deleteFiles)
torrentData = @torrentData.delete infoHash
if ! torrentData
@logger.warn "Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
@logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Remov... | ruby | def handleRemoveTorrent(infoHash, deleteFiles)
torrentData = @torrentData.delete infoHash
if ! torrentData
@logger.warn "Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
@logger.info "#{QuartzTorrent.bytesToHex(torrentData.infoHash)}: Remov... | [
"def",
"handleRemoveTorrent",
"(",
"infoHash",
",",
"deleteFiles",
")",
"torrentData",
"=",
"@torrentData",
".",
"delete",
"infoHash",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"Asked to remove a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}\"",
"return... | Remove a torrent that we are downloading. | [
"Remove",
"a",
"torrent",
"that",
"we",
"are",
"downloading",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1559-L1627 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.handlePause | def handlePause(infoHash, value)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to pause a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
return if torrentData.paused == value
torrentData.paused = value
if !value
... | ruby | def handlePause(infoHash, value)
torrentData = @torrentData[infoHash]
if ! torrentData
@logger.warn "Asked to pause a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}"
return
end
return if torrentData.paused == value
torrentData.paused = value
if !value
... | [
"def",
"handlePause",
"(",
"infoHash",
",",
"value",
")",
"torrentData",
"=",
"@torrentData",
"[",
"infoHash",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\"Asked to pause a non-existent torrent #{QuartzTorrent.bytesToHex(infoHash)}\"",
"return",
"end",
"retur... | Pause or unpause a torrent that we are downloading. | [
"Pause",
"or",
"unpause",
"a",
"torrent",
"that",
"we",
"are",
"downloading",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1630-L1650 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.queue | def queue(torrentData, mode = :queue)
return if torrentData.queued
# Queue the torrent
if mode == :unshift
@torrentQueue.unshift torrentData
else
@torrentQueue.push torrentData
end
setFrozen torrentData, true if ! torrentData.paused
end | ruby | def queue(torrentData, mode = :queue)
return if torrentData.queued
# Queue the torrent
if mode == :unshift
@torrentQueue.unshift torrentData
else
@torrentQueue.push torrentData
end
setFrozen torrentData, true if ! torrentData.paused
end | [
"def",
"queue",
"(",
"torrentData",
",",
"mode",
"=",
":queue",
")",
"return",
"if",
"torrentData",
".",
"queued",
"if",
"mode",
"==",
":unshift",
"@torrentQueue",
".",
"unshift",
"torrentData",
"else",
"@torrentQueue",
".",
"push",
"torrentData",
"end",
"setF... | Queue a torrent | [
"Queue",
"a",
"torrent"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1653-L1664 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.dequeue | def dequeue
torrents = @torrentQueue.dequeue(@torrentData.values)
torrents.each do |torrentData|
if torrentData.state == :initializing
initTorrent torrentData
else
setFrozen torrentData, false if ! torrentData.paused
end
end
end | ruby | def dequeue
torrents = @torrentQueue.dequeue(@torrentData.values)
torrents.each do |torrentData|
if torrentData.state == :initializing
initTorrent torrentData
else
setFrozen torrentData, false if ! torrentData.paused
end
end
end | [
"def",
"dequeue",
"torrents",
"=",
"@torrentQueue",
".",
"dequeue",
"(",
"@torrentData",
".",
"values",
")",
"torrents",
".",
"each",
"do",
"|",
"torrentData",
"|",
"if",
"torrentData",
".",
"state",
"==",
":initializing",
"initTorrent",
"torrentData",
"else",
... | Dequeue any torrents that can now run based on available space | [
"Dequeue",
"any",
"torrents",
"that",
"can",
"now",
"run",
"based",
"on",
"available",
"space"
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1667-L1676 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClientHandler.setFrozen | def setFrozen(torrent, value)
torrentData = torrent
if ! torrent.is_a?(TorrentData)
torrentData = @torrentData[torrent]
if ! torrentData
@logger.warn "Asked to freeze a non-existent torrent #{QuartzTorrent.bytesToHex(torrent)}"
return
end
end
if value... | ruby | def setFrozen(torrent, value)
torrentData = torrent
if ! torrent.is_a?(TorrentData)
torrentData = @torrentData[torrent]
if ! torrentData
@logger.warn "Asked to freeze a non-existent torrent #{QuartzTorrent.bytesToHex(torrent)}"
return
end
end
if value... | [
"def",
"setFrozen",
"(",
"torrent",
",",
"value",
")",
"torrentData",
"=",
"torrent",
"if",
"!",
"torrent",
".",
"is_a?",
"(",
"TorrentData",
")",
"torrentData",
"=",
"@torrentData",
"[",
"torrent",
"]",
"if",
"!",
"torrentData",
"@logger",
".",
"warn",
"\... | Freeze or unfreeze a torrent. If value is true, then we disconnect from all peers for this torrent and forget
the peers. If value is false, we start reconnecting to peers.
Parameter torrent can be an infoHash or TorrentData | [
"Freeze",
"or",
"unfreeze",
"a",
"torrent",
".",
"If",
"value",
"is",
"true",
"then",
"we",
"disconnect",
"from",
"all",
"peers",
"for",
"this",
"torrent",
"and",
"forget",
"the",
"peers",
".",
"If",
"value",
"is",
"false",
"we",
"start",
"reconnecting",
... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1681-L1709 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClient.addTorrentByMetainfo | def addTorrentByMetainfo(metainfo)
raise "addTorrentByMetainfo should be called with a Metainfo object, not #{metainfo.class}" if ! metainfo.is_a?(Metainfo)
trackerclient = TrackerClient.createFromMetainfo(metainfo, false)
addTorrent(trackerclient, metainfo.infoHash, metainfo.info)
end | ruby | def addTorrentByMetainfo(metainfo)
raise "addTorrentByMetainfo should be called with a Metainfo object, not #{metainfo.class}" if ! metainfo.is_a?(Metainfo)
trackerclient = TrackerClient.createFromMetainfo(metainfo, false)
addTorrent(trackerclient, metainfo.infoHash, metainfo.info)
end | [
"def",
"addTorrentByMetainfo",
"(",
"metainfo",
")",
"raise",
"\"addTorrentByMetainfo should be called with a Metainfo object, not #{metainfo.class}\"",
"if",
"!",
"metainfo",
".",
"is_a?",
"(",
"Metainfo",
")",
"trackerclient",
"=",
"TrackerClient",
".",
"createFromMetainfo",
... | Add a new torrent to manage described by a Metainfo object. This is generally the
method to call if you have a .torrent file.
Returns the infoHash of the newly added torrent. | [
"Add",
"a",
"new",
"torrent",
"to",
"manage",
"described",
"by",
"a",
"Metainfo",
"object",
".",
"This",
"is",
"generally",
"the",
"method",
"to",
"call",
"if",
"you",
"have",
"a",
".",
"torrent",
"file",
".",
"Returns",
"the",
"infoHash",
"of",
"the",
... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1780-L1784 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClient.addTorrentWithoutMetainfo | def addTorrentWithoutMetainfo(announceUrl, infoHash, magnet = nil)
raise "addTorrentWithoutMetainfo should be called with a Magnet object, not a #{magnet.class}" if magnet && ! magnet.is_a?(MagnetURI)
trackerclient = TrackerClient.create(announceUrl, infoHash, 0, false)
addTorrent(trackerclient, infoH... | ruby | def addTorrentWithoutMetainfo(announceUrl, infoHash, magnet = nil)
raise "addTorrentWithoutMetainfo should be called with a Magnet object, not a #{magnet.class}" if magnet && ! magnet.is_a?(MagnetURI)
trackerclient = TrackerClient.create(announceUrl, infoHash, 0, false)
addTorrent(trackerclient, infoH... | [
"def",
"addTorrentWithoutMetainfo",
"(",
"announceUrl",
",",
"infoHash",
",",
"magnet",
"=",
"nil",
")",
"raise",
"\"addTorrentWithoutMetainfo should be called with a Magnet object, not a #{magnet.class}\"",
"if",
"magnet",
"&&",
"!",
"magnet",
".",
"is_a?",
"(",
"MagnetURI... | Add a new torrent to manage given an announceUrl and an infoHash. The announceUrl may be a list.
Returns the infoHash of the newly added torrent. | [
"Add",
"a",
"new",
"torrent",
"to",
"manage",
"given",
"an",
"announceUrl",
"and",
"an",
"infoHash",
".",
"The",
"announceUrl",
"may",
"be",
"a",
"list",
".",
"Returns",
"the",
"infoHash",
"of",
"the",
"newly",
"added",
"torrent",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1788-L1792 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClient.addTorrentByMagnetURI | def addTorrentByMagnetURI(magnet)
raise "addTorrentByMagnetURI should be called with a MagnetURI object, not a #{magnet.class}" if ! magnet.is_a?(MagnetURI)
trackerUrl = magnet.trackers
raise "addTorrentByMagnetURI can't handle magnet links that don't have a tracker URL." if !trackerUrl
addTor... | ruby | def addTorrentByMagnetURI(magnet)
raise "addTorrentByMagnetURI should be called with a MagnetURI object, not a #{magnet.class}" if ! magnet.is_a?(MagnetURI)
trackerUrl = magnet.trackers
raise "addTorrentByMagnetURI can't handle magnet links that don't have a tracker URL." if !trackerUrl
addTor... | [
"def",
"addTorrentByMagnetURI",
"(",
"magnet",
")",
"raise",
"\"addTorrentByMagnetURI should be called with a MagnetURI object, not a #{magnet.class}\"",
"if",
"!",
"magnet",
".",
"is_a?",
"(",
"MagnetURI",
")",
"trackerUrl",
"=",
"magnet",
".",
"trackers",
"raise",
"\"addT... | Add a new torrent to manage given a MagnetURI object. This is generally the
method to call if you have a magnet link.
Returns the infoHash of the newly added torrent. | [
"Add",
"a",
"new",
"torrent",
"to",
"manage",
"given",
"a",
"MagnetURI",
"object",
".",
"This",
"is",
"generally",
"the",
"method",
"to",
"call",
"if",
"you",
"have",
"a",
"magnet",
"link",
".",
"Returns",
"the",
"infoHash",
"of",
"the",
"newly",
"added"... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1797-L1804 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClient.adjustBytesDownloaded | def adjustBytesDownloaded(infoHash, adjustment)
return if ! adjustment
raise "Bytes downloaded adjustment must be an Integer, not a #{adjustment.class}" if !adjustment.is_a?(Integer)
@handler.adjustBytesDownloaded(infoHash, adjustment)
end | ruby | def adjustBytesDownloaded(infoHash, adjustment)
return if ! adjustment
raise "Bytes downloaded adjustment must be an Integer, not a #{adjustment.class}" if !adjustment.is_a?(Integer)
@handler.adjustBytesDownloaded(infoHash, adjustment)
end | [
"def",
"adjustBytesDownloaded",
"(",
"infoHash",
",",
"adjustment",
")",
"return",
"if",
"!",
"adjustment",
"raise",
"\"Bytes downloaded adjustment must be an Integer, not a #{adjustment.class}\"",
"if",
"!",
"adjustment",
".",
"is_a?",
"(",
"Integer",
")",
"@handler",
".... | Adjust the bytesDownloaded property of the specified torrent by the passed amount.
Adjustment should be an integer. It is added to the current bytesUploaded amount. | [
"Adjust",
"the",
"bytesDownloaded",
"property",
"of",
"the",
"specified",
"torrent",
"by",
"the",
"passed",
"amount",
".",
"Adjustment",
"should",
"be",
"an",
"integer",
".",
"It",
"is",
"added",
"to",
"the",
"current",
"bytesUploaded",
"amount",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1854-L1858 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/peerclient.rb | QuartzTorrent.PeerClient.addTorrent | def addTorrent(trackerclient, infoHash, info, magnet = nil)
trackerclient.port = @port
torrentData = @handler.addTrackerClient(infoHash, info, trackerclient)
torrentData.magnet = magnet
trackerclient.dynamicRequestParamsBuilder = Proc.new do
torrentData = @handler.torrentData[infoHash]... | ruby | def addTorrent(trackerclient, infoHash, info, magnet = nil)
trackerclient.port = @port
torrentData = @handler.addTrackerClient(infoHash, info, trackerclient)
torrentData.magnet = magnet
trackerclient.dynamicRequestParamsBuilder = Proc.new do
torrentData = @handler.torrentData[infoHash]... | [
"def",
"addTorrent",
"(",
"trackerclient",
",",
"infoHash",
",",
"info",
",",
"magnet",
"=",
"nil",
")",
"trackerclient",
".",
"port",
"=",
"@port",
"torrentData",
"=",
"@handler",
".",
"addTrackerClient",
"(",
"infoHash",
",",
"info",
",",
"trackerclient",
... | Helper method for adding a torrent. | [
"Helper",
"method",
"for",
"adding",
"a",
"torrent",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/peerclient.rb#L1867-L1897 | train |
rjurado01/rapidoc | lib/rapidoc/config.rb | Rapidoc.Config.target_dir | def target_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( target_dir_from_config, f )
else
form_file_name( File.join( ::Rails.root.to_s, 'public/docs' ), f )
end
end | ruby | def target_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( target_dir_from_config, f )
else
form_file_name( File.join( ::Rails.root.to_s, 'public/docs' ), f )
end
end | [
"def",
"target_dir",
"(",
"f",
"=",
"nil",
")",
"if",
"File",
".",
"exists?",
"(",
"config_file_path",
")",
"form_file_name",
"(",
"target_dir_from_config",
",",
"f",
")",
"else",
"form_file_name",
"(",
"File",
".",
"join",
"(",
"::",
"Rails",
".",
"root",... | return the directory where rapidoc generates the doc | [
"return",
"the",
"directory",
"where",
"rapidoc",
"generates",
"the",
"doc"
] | 03b7a8f29a37dd03f4ed5036697b48551d3b4ae6 | https://github.com/rjurado01/rapidoc/blob/03b7a8f29a37dd03f4ed5036697b48551d3b4ae6/lib/rapidoc/config.rb#L79-L85 | train |
rjurado01/rapidoc | lib/rapidoc/config.rb | Rapidoc.Config.examples_dir | def examples_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( examples_dir_from_config_file, f )
else
form_file_name( config_dir( '/examples' ), f )
end
end | ruby | def examples_dir( f = nil )
if File.exists?( config_file_path )
form_file_name( examples_dir_from_config_file, f )
else
form_file_name( config_dir( '/examples' ), f )
end
end | [
"def",
"examples_dir",
"(",
"f",
"=",
"nil",
")",
"if",
"File",
".",
"exists?",
"(",
"config_file_path",
")",
"form_file_name",
"(",
"examples_dir_from_config_file",
",",
"f",
")",
"else",
"form_file_name",
"(",
"config_dir",
"(",
"'/examples'",
")",
",",
"f",... | returns the directory where rapidoc searches for examples | [
"returns",
"the",
"directory",
"where",
"rapidoc",
"searches",
"for",
"examples"
] | 03b7a8f29a37dd03f4ed5036697b48551d3b4ae6 | https://github.com/rjurado01/rapidoc/blob/03b7a8f29a37dd03f4ed5036697b48551d3b4ae6/lib/rapidoc/config.rb#L93-L99 | train |
philm/twilio | lib/twilio/verb.rb | Twilio.Verb.say | def say(*args)
options = {:voice => 'man', :language => 'en', :loop => 1}
args.each do |arg|
case arg
when String
options[:text_to_speak] = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'say expects String or Hash argument'
... | ruby | def say(*args)
options = {:voice => 'man', :language => 'en', :loop => 1}
args.each do |arg|
case arg
when String
options[:text_to_speak] = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'say expects String or Hash argument'
... | [
"def",
"say",
"(",
"*",
"args",
")",
"options",
"=",
"{",
":voice",
"=>",
"'man'",
",",
":language",
"=>",
"'en'",
",",
":loop",
"=>",
"1",
"}",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"String",
"options",
"[",
":text_to_... | The Say verb converts text to speech that is read back to the caller.
Say is useful for dynamic text that is difficult to prerecord.
Examples:
Twilio::Verb.say 'The time is 9:35 PM.'
Twilio::Verb.say 'The time is 9:35 PM.', :loop => 3
With numbers, 12345 will be spoken as "twelve thousand three hundred forty... | [
"The",
"Say",
"verb",
"converts",
"text",
"to",
"speech",
"that",
"is",
"read",
"back",
"to",
"the",
"caller",
".",
"Say",
"is",
"useful",
"for",
"dynamic",
"text",
"that",
"is",
"difficult",
"to",
"prerecord",
"."
] | 81c05795924bbfa780ea44efd52d7ca5670bcb55 | https://github.com/philm/twilio/blob/81c05795924bbfa780ea44efd52d7ca5670bcb55/lib/twilio/verb.rb#L62-L84 | train |
philm/twilio | lib/twilio/verb.rb | Twilio.Verb.gather | def gather(*args, &block)
options = args.shift || {}
output {
if block_given?
@xml.Gather(options) { block.call}
else
@xml.Gather(options)
end
}
end | ruby | def gather(*args, &block)
options = args.shift || {}
output {
if block_given?
@xml.Gather(options) { block.call}
else
@xml.Gather(options)
end
}
end | [
"def",
"gather",
"(",
"*",
"args",
",",
"&",
"block",
")",
"options",
"=",
"args",
".",
"shift",
"||",
"{",
"}",
"output",
"{",
"if",
"block_given?",
"@xml",
".",
"Gather",
"(",
"options",
")",
"{",
"block",
".",
"call",
"}",
"else",
"@xml",
".",
... | The Gather verb collects digits entered by a caller into their telephone keypad.
When the caller is done entering data, Twilio submits that data to a provided URL,
as either a HTTP GET or POST request, just like a web browser submits data from an HTML form.
Options (see http://www.twilio.com/docs/api_reference/TwiM... | [
"The",
"Gather",
"verb",
"collects",
"digits",
"entered",
"by",
"a",
"caller",
"into",
"their",
"telephone",
"keypad",
".",
"When",
"the",
"caller",
"is",
"done",
"entering",
"data",
"Twilio",
"submits",
"that",
"data",
"to",
"a",
"provided",
"URL",
"as",
... | 81c05795924bbfa780ea44efd52d7ca5670bcb55 | https://github.com/philm/twilio/blob/81c05795924bbfa780ea44efd52d7ca5670bcb55/lib/twilio/verb.rb#L143-L152 | train |
philm/twilio | lib/twilio/verb.rb | Twilio.Verb.dial | def dial(*args, &block)
number_to_dial = ''
options = {}
args.each do |arg|
case arg
when String
number_to_dial = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'dial expects String or Hash argument'
end
end
... | ruby | def dial(*args, &block)
number_to_dial = ''
options = {}
args.each do |arg|
case arg
when String
number_to_dial = arg
when Hash
options.merge!(arg)
else
raise ArgumentError, 'dial expects String or Hash argument'
end
end
... | [
"def",
"dial",
"(",
"*",
"args",
",",
"&",
"block",
")",
"number_to_dial",
"=",
"''",
"options",
"=",
"{",
"}",
"args",
".",
"each",
"do",
"|",
"arg",
"|",
"case",
"arg",
"when",
"String",
"number_to_dial",
"=",
"arg",
"when",
"Hash",
"options",
".",... | The Dial verb connects the current caller to an another phone. If the called party picks up,
the two parties are connected and can communicate until one hangs up. If the called party does
not pick up, if a busy signal is received, or the number doesn't exist, the dial verb will finish.
If an action verb is provided... | [
"The",
"Dial",
"verb",
"connects",
"the",
"current",
"caller",
"to",
"an",
"another",
"phone",
".",
"If",
"the",
"called",
"party",
"picks",
"up",
"the",
"two",
"parties",
"are",
"connected",
"and",
"can",
"communicate",
"until",
"one",
"hangs",
"up",
".",... | 81c05795924bbfa780ea44efd52d7ca5670bcb55 | https://github.com/philm/twilio/blob/81c05795924bbfa780ea44efd52d7ca5670bcb55/lib/twilio/verb.rb#L198-L219 | train |
rjurado01/rapidoc | lib/rapidoc/resource_doc.rb | Rapidoc.ResourceDoc.generate_info | def generate_info( routes_info )
if routes_info
extractor = get_controller_extractor
@description = extractor.get_resource_info['description'] if extractor
@actions_doc = get_actions_doc( routes_info, extractor )
# template need that description will be an array
@descript... | ruby | def generate_info( routes_info )
if routes_info
extractor = get_controller_extractor
@description = extractor.get_resource_info['description'] if extractor
@actions_doc = get_actions_doc( routes_info, extractor )
# template need that description will be an array
@descript... | [
"def",
"generate_info",
"(",
"routes_info",
")",
"if",
"routes_info",
"extractor",
"=",
"get_controller_extractor",
"@description",
"=",
"extractor",
".",
"get_resource_info",
"[",
"'description'",
"]",
"if",
"extractor",
"@actions_doc",
"=",
"get_actions_doc",
"(",
"... | Create description and actions_doc | [
"Create",
"description",
"and",
"actions_doc"
] | 03b7a8f29a37dd03f4ed5036697b48551d3b4ae6 | https://github.com/rjurado01/rapidoc/blob/03b7a8f29a37dd03f4ed5036697b48551d3b4ae6/lib/rapidoc/resource_doc.rb#L36-L45 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceMapper.findBlock | def findBlock(pieceIndex, offset, length)
leftOffset = @pieceSize*pieceIndex + offset
rightOffset = leftOffset + length-1
findPart(leftOffset, rightOffset)
end | ruby | def findBlock(pieceIndex, offset, length)
leftOffset = @pieceSize*pieceIndex + offset
rightOffset = leftOffset + length-1
findPart(leftOffset, rightOffset)
end | [
"def",
"findBlock",
"(",
"pieceIndex",
",",
"offset",
",",
"length",
")",
"leftOffset",
"=",
"@pieceSize",
"*",
"pieceIndex",
"+",
"offset",
"rightOffset",
"=",
"leftOffset",
"+",
"length",
"-",
"1",
"findPart",
"(",
"leftOffset",
",",
"rightOffset",
")",
"e... | Return a list of FileRegion objects. The FileRegion offsets specify
in order which regions of files the piece covers. | [
"Return",
"a",
"list",
"of",
"FileRegion",
"objects",
".",
"The",
"FileRegion",
"offsets",
"specify",
"in",
"order",
"which",
"regions",
"of",
"files",
"the",
"piece",
"covers",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L75-L80 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceIO.writeBlock | def writeBlock(pieceIndex, offset, block)
regions = @pieceMapper.findBlock(pieceIndex, offset, block.length)
indexInBlock = 0
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a re... | ruby | def writeBlock(pieceIndex, offset, block)
regions = @pieceMapper.findBlock(pieceIndex, offset, block.length)
indexInBlock = 0
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a re... | [
"def",
"writeBlock",
"(",
"pieceIndex",
",",
"offset",
",",
"block",
")",
"regions",
"=",
"@pieceMapper",
".",
"findBlock",
"(",
"pieceIndex",
",",
"offset",
",",
"block",
".",
"length",
")",
"indexInBlock",
"=",
"0",
"regions",
".",
"each",
"do",
"|",
"... | Write a block to an in-progress piece. The block is written to
piece 'peiceIndex', at offset 'offset'. The block data is in block.
Throws exceptions on failure. | [
"Write",
"a",
"block",
"to",
"an",
"in",
"-",
"progress",
"piece",
".",
"The",
"block",
"is",
"written",
"to",
"piece",
"peiceIndex",
"at",
"offset",
"offset",
".",
"The",
"block",
"data",
"is",
"in",
"block",
".",
"Throws",
"exceptions",
"on",
"failure"... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L163-L199 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceIO.readRegions | def readRegions(regions)
piece = ""
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a real IO.
io = @ioManager.get(region.path)
if ! io
# No IO for this file.... | ruby | def readRegions(regions)
piece = ""
regions.each do |region|
# Get the IO for the file with path 'path'. If we are being used in a reactor, this is the IO facade. If we
# are not then this is a real IO.
io = @ioManager.get(region.path)
if ! io
# No IO for this file.... | [
"def",
"readRegions",
"(",
"regions",
")",
"piece",
"=",
"\"\"",
"regions",
".",
"each",
"do",
"|",
"region",
"|",
"io",
"=",
"@ioManager",
".",
"get",
"(",
"region",
".",
"path",
")",
"if",
"!",
"io",
"if",
"!",
"File",
".",
"exists?",
"(",
"regio... | Pass an ordered list of FileRegions to load. | [
"Pass",
"an",
"ordered",
"list",
"of",
"FileRegions",
"to",
"load",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L220-L253 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceManager.readBlock | def readBlock(pieceIndex, offset, length)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_block, pieceIndex, offset, length]
@requestsSemaphore.signal
id
end | ruby | def readBlock(pieceIndex, offset, length)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_block, pieceIndex, offset, length]
@requestsSemaphore.signal
id
end | [
"def",
"readBlock",
"(",
"pieceIndex",
",",
"offset",
",",
"length",
")",
"id",
"=",
"returnAndIncrRequestId",
"return",
"id",
"if",
"@state",
"==",
":after_stop",
"@requests",
".",
"push",
"[",
"id",
",",
":read_block",
",",
"pieceIndex",
",",
"offset",
","... | Read a block from the torrent asynchronously. When the operation
is complete the result is stored in the 'results' list.
This method returns an id that can be used to match the response
to the request.
The readBlock and writeBlock methods are not threadsafe with respect to callers;
they shouldn't be called by mult... | [
"Read",
"a",
"block",
"from",
"the",
"torrent",
"asynchronously",
".",
"When",
"the",
"operation",
"is",
"complete",
"the",
"result",
"is",
"stored",
"in",
"the",
"results",
"list",
".",
"This",
"method",
"returns",
"an",
"id",
"that",
"can",
"be",
"used",... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L319-L325 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceManager.writeBlock | def writeBlock(pieceIndex, offset, block)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :write_block, pieceIndex, offset, block]
@requestsSemaphore.signal
id
end | ruby | def writeBlock(pieceIndex, offset, block)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :write_block, pieceIndex, offset, block]
@requestsSemaphore.signal
id
end | [
"def",
"writeBlock",
"(",
"pieceIndex",
",",
"offset",
",",
"block",
")",
"id",
"=",
"returnAndIncrRequestId",
"return",
"id",
"if",
"@state",
"==",
":after_stop",
"@requests",
".",
"push",
"[",
"id",
",",
":write_block",
",",
"pieceIndex",
",",
"offset",
",... | Write a block to the torrent asynchronously. | [
"Write",
"a",
"block",
"to",
"the",
"torrent",
"asynchronously",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L328-L334 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceManager.readPiece | def readPiece(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_piece, pieceIndex]
@requestsSemaphore.signal
id
end | ruby | def readPiece(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :read_piece, pieceIndex]
@requestsSemaphore.signal
id
end | [
"def",
"readPiece",
"(",
"pieceIndex",
")",
"id",
"=",
"returnAndIncrRequestId",
"return",
"id",
"if",
"@state",
"==",
":after_stop",
"@requests",
".",
"push",
"[",
"id",
",",
":read_piece",
",",
"pieceIndex",
"]",
"@requestsSemaphore",
".",
"signal",
"id",
"e... | Read a block of the torrent asynchronously. | [
"Read",
"a",
"block",
"of",
"the",
"torrent",
"asynchronously",
"."
] | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L337-L343 | train |
jeffwilliams/quartz-torrent | lib/quartz_torrent/filemanager.rb | QuartzTorrent.PieceManager.checkPieceHash | def checkPieceHash(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :hash_piece, pieceIndex]
@requestsSemaphore.signal
id
end | ruby | def checkPieceHash(pieceIndex)
id = returnAndIncrRequestId
return id if @state == :after_stop
@requests.push [id, :hash_piece, pieceIndex]
@requestsSemaphore.signal
id
end | [
"def",
"checkPieceHash",
"(",
"pieceIndex",
")",
"id",
"=",
"returnAndIncrRequestId",
"return",
"id",
"if",
"@state",
"==",
":after_stop",
"@requests",
".",
"push",
"[",
"id",
",",
":hash_piece",
",",
"pieceIndex",
"]",
"@requestsSemaphore",
".",
"signal",
"id",... | Validate that the hash of the downloaded piece matches the hash from the metainfo.
The result is successful? if the hash matches, false otherwise. The data of the result is
set to the piece index. | [
"Validate",
"that",
"the",
"hash",
"of",
"the",
"downloaded",
"piece",
"matches",
"the",
"hash",
"from",
"the",
"metainfo",
".",
"The",
"result",
"is",
"successful?",
"if",
"the",
"hash",
"matches",
"false",
"otherwise",
".",
"The",
"data",
"of",
"the",
"r... | 7aeb40125d886dd60d7481deb5129282fc3e3c06 | https://github.com/jeffwilliams/quartz-torrent/blob/7aeb40125d886dd60d7481deb5129282fc3e3c06/lib/quartz_torrent/filemanager.rb#L360-L366 | train |
poise/halite | lib/halite/gem.rb | Halite.Gem.license_header | def license_header
IO.readlines(spec_file).take_while { |line| line.strip.empty? || line.strip.start_with?('#') }.join('')
end | ruby | def license_header
IO.readlines(spec_file).take_while { |line| line.strip.empty? || line.strip.start_with?('#') }.join('')
end | [
"def",
"license_header",
"IO",
".",
"readlines",
"(",
"spec_file",
")",
".",
"take_while",
"{",
"|",
"line",
"|",
"line",
".",
"strip",
".",
"empty?",
"||",
"line",
".",
"strip",
".",
"start_with?",
"(",
"'#'",
")",
"}",
".",
"join",
"(",
"''",
")",
... | License header extacted from the gemspec. Suitable for inclusion in other
Ruby source files.
@return [String] | [
"License",
"header",
"extacted",
"from",
"the",
"gemspec",
".",
"Suitable",
"for",
"inclusion",
"in",
"other",
"Ruby",
"source",
"files",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/gem.rb#L104-L106 | train |
poise/halite | lib/halite/gem.rb | Halite.Gem.issues_url | def issues_url
if spec.metadata['issues_url']
spec.metadata['issues_url']
elsif spec.homepage =~ /^http(s)?:\/\/(www\.)?github\.com/
spec.homepage.chomp('/') + '/issues'
end
end | ruby | def issues_url
if spec.metadata['issues_url']
spec.metadata['issues_url']
elsif spec.homepage =~ /^http(s)?:\/\/(www\.)?github\.com/
spec.homepage.chomp('/') + '/issues'
end
end | [
"def",
"issues_url",
"if",
"spec",
".",
"metadata",
"[",
"'issues_url'",
"]",
"spec",
".",
"metadata",
"[",
"'issues_url'",
"]",
"elsif",
"spec",
".",
"homepage",
"=~",
"/",
"\\/",
"\\/",
"\\.",
"\\.",
"/",
"spec",
".",
"homepage",
".",
"chomp",
"(",
"... | URL to the issue tracker for this project.
@return [String, nil] | [
"URL",
"to",
"the",
"issue",
"tracker",
"for",
"this",
"project",
"."
] | 9ae174e6b7c5d4674f3301394e14567fa89a8b3e | https://github.com/poise/halite/blob/9ae174e6b7c5d4674f3301394e14567fa89a8b3e/lib/halite/gem.rb#L111-L117 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.