id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
list
docstring
stringlengths
8
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
94
266
2,100
flamontagne/rrschedule
lib/rrschedule.rb
RRSchedule.Schedule.face_to_face
def face_to_face(team_a,team_b) res=[] self.gamedays.each do |gd| res << gd.games.select {|g| (g.team_a == team_a && g.team_b == team_b) || (g.team_a == team_b && g.team_b == team_a)} end res.flatten end
ruby
def face_to_face(team_a,team_b) res=[] self.gamedays.each do |gd| res << gd.games.select {|g| (g.team_a == team_a && g.team_b == team_b) || (g.team_a == team_b && g.team_b == team_a)} end res.flatten end
[ "def", "face_to_face", "(", "team_a", ",", "team_b", ")", "res", "=", "[", "]", "self", ".", "gamedays", ".", "each", "do", "|", "gd", "|", "res", "<<", "gd", ".", "games", ".", "select", "{", "|", "g", "|", "(", "g", ".", "team_a", "==", "team...
return matchups between two teams
[ "return", "matchups", "between", "two", "teams" ]
7b334205e38901786a7569a6e96e49c24f9b425e
https://github.com/flamontagne/rrschedule/blob/7b334205e38901786a7569a6e96e49c24f9b425e/lib/rrschedule.rb#L316-L322
2,101
flamontagne/rrschedule
lib/rrschedule.rb
RRSchedule.Rule.gt=
def gt=(gt) @gt = Array(gt).empty? ? ["7:00 PM"] : Array(gt) @gt.collect! do |gt| begin DateTime.parse(gt) rescue raise "game times must be valid time representations in the string form (e.g. 3:00 PM, 11:00 AM, 18:20, etc)" end end end
ruby
def gt=(gt) @gt = Array(gt).empty? ? ["7:00 PM"] : Array(gt) @gt.collect! do |gt| begin DateTime.parse(gt) rescue raise "game times must be valid time representations in the string form (e.g. 3:00 PM, 11:00 AM, 18:20, etc)" end end end
[ "def", "gt", "=", "(", "gt", ")", "@gt", "=", "Array", "(", "gt", ")", ".", "empty?", "?", "[", "\"7:00 PM\"", "]", ":", "Array", "(", "gt", ")", "@gt", ".", "collect!", "do", "|", "gt", "|", "begin", "DateTime", ".", "parse", "(", "gt", ")", ...
Array of game times where games are played. Must be valid DateTime objects in the string form
[ "Array", "of", "game", "times", "where", "games", "are", "played", ".", "Must", "be", "valid", "DateTime", "objects", "in", "the", "string", "form" ]
7b334205e38901786a7569a6e96e49c24f9b425e
https://github.com/flamontagne/rrschedule/blob/7b334205e38901786a7569a6e96e49c24f9b425e/lib/rrschedule.rb#L369-L378
2,102
dilcom/gnuplotrb
lib/gnuplotrb/staff/terminal.rb
GnuplotRB.Terminal.options_hash_to_string
def options_hash_to_string(options) result = '' options.sort_by { |key, _| OPTION_ORDER.find_index(key) || -1 }.each do |key, value| if value result += "set #{OptionHandling.option_to_string(key, value)}\n" else result += "unset #{key}\n" end end resul...
ruby
def options_hash_to_string(options) result = '' options.sort_by { |key, _| OPTION_ORDER.find_index(key) || -1 }.each do |key, value| if value result += "set #{OptionHandling.option_to_string(key, value)}\n" else result += "unset #{key}\n" end end resul...
[ "def", "options_hash_to_string", "(", "options", ")", "result", "=", "''", "options", ".", "sort_by", "{", "|", "key", ",", "_", "|", "OPTION_ORDER", ".", "find_index", "(", "key", ")", "||", "-", "1", "}", ".", "each", "do", "|", "key", ",", "value"...
Convert given options to gnuplot format. For "{ opt1: val1, .. , optN: valN }" it returns set opt1 val1 .. set optN valN @param ptions [Hash] options to convert @return [String] options in Gnuplot format
[ "Convert", "given", "options", "to", "gnuplot", "format", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/staff/terminal.rb#L91-L101
2,103
cfis/proj4rb
lib/proj4.rb
Proj4.Projection.forwardDeg!
def forwardDeg!(point) point.x *= Proj4::DEG_TO_RAD point.y *= Proj4::DEG_TO_RAD forward!(point) end
ruby
def forwardDeg!(point) point.x *= Proj4::DEG_TO_RAD point.y *= Proj4::DEG_TO_RAD forward!(point) end
[ "def", "forwardDeg!", "(", "point", ")", "point", ".", "x", "*=", "Proj4", "::", "DEG_TO_RAD", "point", ".", "y", "*=", "Proj4", "::", "DEG_TO_RAD", "forward!", "(", "point", ")", "end" ]
Convenience function for calculating a forward projection with degrees instead of radians. This version works in-place, i.e. the point objects content is overwritten. call-seq: forwardDeg!(point) -> point
[ "Convenience", "function", "for", "calculating", "a", "forward", "projection", "with", "degrees", "instead", "of", "radians", ".", "This", "version", "works", "in", "-", "place", "i", ".", "e", ".", "the", "point", "objects", "content", "is", "overwritten", ...
97a14b5d6884506795953f7c69b8ede73bb84e0f
https://github.com/cfis/proj4rb/blob/97a14b5d6884506795953f7c69b8ede73bb84e0f/lib/proj4.rb#L196-L200
2,104
cfis/proj4rb
lib/proj4.rb
Proj4.Projection.inverseDeg!
def inverseDeg!(point) inverse!(point) point.x *= Proj4::RAD_TO_DEG point.y *= Proj4::RAD_TO_DEG point end
ruby
def inverseDeg!(point) inverse!(point) point.x *= Proj4::RAD_TO_DEG point.y *= Proj4::RAD_TO_DEG point end
[ "def", "inverseDeg!", "(", "point", ")", "inverse!", "(", "point", ")", "point", ".", "x", "*=", "Proj4", "::", "RAD_TO_DEG", "point", ".", "y", "*=", "Proj4", "::", "RAD_TO_DEG", "point", "end" ]
Convenience function for calculating an inverse projection with the result in degrees instead of radians. This version works in-place, i.e. the point objects content is overwritten. call-seq: inverseDeg!(point) -> point
[ "Convenience", "function", "for", "calculating", "an", "inverse", "projection", "with", "the", "result", "in", "degrees", "instead", "of", "radians", ".", "This", "version", "works", "in", "-", "place", "i", ".", "e", ".", "the", "point", "objects", "content...
97a14b5d6884506795953f7c69b8ede73bb84e0f
https://github.com/cfis/proj4rb/blob/97a14b5d6884506795953f7c69b8ede73bb84e0f/lib/proj4.rb#L250-L255
2,105
cfis/proj4rb
lib/proj4.rb
Proj4.Projection.transform_all!
def transform_all!(otherProjection, collection) collection.each do |point| transform!(otherProjection, point) end collection end
ruby
def transform_all!(otherProjection, collection) collection.each do |point| transform!(otherProjection, point) end collection end
[ "def", "transform_all!", "(", "otherProjection", ",", "collection", ")", "collection", ".", "each", "do", "|", "point", "|", "transform!", "(", "otherProjection", ",", "point", ")", "end", "collection", "end" ]
Transforms all points in a collection 'in place' from one projection to another. The +collection+ object must implement the +each+ method for this to work. call-seq: transform_all!(destinationProjection, collection) -> collection
[ "Transforms", "all", "points", "in", "a", "collection", "in", "place", "from", "one", "projection", "to", "another", ".", "The", "+", "collection", "+", "object", "must", "implement", "the", "+", "each", "+", "method", "for", "this", "to", "work", "." ]
97a14b5d6884506795953f7c69b8ede73bb84e0f
https://github.com/cfis/proj4rb/blob/97a14b5d6884506795953f7c69b8ede73bb84e0f/lib/proj4.rb#L298-L303
2,106
wework/faraday-sunset
lib/faraday/sunset.rb
Faraday.Sunset.call
def call(env) @app.call(env).on_complete do |response_env| datetime = sunset_header(response_env.response_headers) report_deprecated_usage(env, datetime) unless datetime.nil? end end
ruby
def call(env) @app.call(env).on_complete do |response_env| datetime = sunset_header(response_env.response_headers) report_deprecated_usage(env, datetime) unless datetime.nil? end end
[ "def", "call", "(", "env", ")", "@app", ".", "call", "(", "env", ")", ".", "on_complete", "do", "|", "response_env", "|", "datetime", "=", "sunset_header", "(", "response_env", ".", "response_headers", ")", "report_deprecated_usage", "(", "env", ",", "dateti...
Initialize the middleware @param [Type] app describe app @param [Hash] options = {} @return void @param [Faraday::Env] no idea what this does @return [Faraday::Response] response from the middleware
[ "Initialize", "the", "middleware" ]
aac1e1ac5828ae7d2bed173e5d03fd2c63b5ce6a
https://github.com/wework/faraday-sunset/blob/aac1e1ac5828ae7d2bed173e5d03fd2c63b5ce6a/lib/faraday/sunset.rb#L21-L26
2,107
dilcom/gnuplotrb
lib/gnuplotrb/staff/dataset.rb
GnuplotRB.Dataset.update
def update(data = nil, **options) if data && @type == :datablock new_datablock = @data.update(data) if new_datablock == @data update_options(options) else self.class.new(new_datablock, options) end else update_options(options) end end
ruby
def update(data = nil, **options) if data && @type == :datablock new_datablock = @data.update(data) if new_datablock == @data update_options(options) else self.class.new(new_datablock, options) end else update_options(options) end end
[ "def", "update", "(", "data", "=", "nil", ",", "**", "options", ")", "if", "data", "&&", "@type", "==", ":datablock", "new_datablock", "=", "@data", ".", "update", "(", "data", ")", "if", "new_datablock", "==", "@data", "update_options", "(", "options", ...
Create new dataset with updated data and merged options. Given data is appended to existing. Data is updated only if Dataset stores it in Datablock. Method does nothing if no options given and data isn't stored in in-memory Datablock. @param data [#to_gnuplot_points] data to append to existing @param options [H...
[ "Create", "new", "dataset", "with", "updated", "data", "and", "merged", "options", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/staff/dataset.rb#L119-L130
2,108
dilcom/gnuplotrb
lib/gnuplotrb/staff/dataset.rb
GnuplotRB.Dataset.options_to_string
def options_to_string options.sort_by { |key, _| OPTION_ORDER.find_index(key.to_s) || 999 } .map { |key, value| OptionHandling.option_to_string(key, value) } .join(' ') end
ruby
def options_to_string options.sort_by { |key, _| OPTION_ORDER.find_index(key.to_s) || 999 } .map { |key, value| OptionHandling.option_to_string(key, value) } .join(' ') end
[ "def", "options_to_string", "options", ".", "sort_by", "{", "|", "key", ",", "_", "|", "OPTION_ORDER", ".", "find_index", "(", "key", ".", "to_s", ")", "||", "999", "}", ".", "map", "{", "|", "key", ",", "value", "|", "OptionHandling", ".", "option_to_...
Create string from own options @return [String] options converted to Gnuplot format
[ "Create", "string", "from", "own", "options" ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/staff/dataset.rb#L221-L225
2,109
dilcom/gnuplotrb
lib/gnuplotrb/staff/dataset.rb
GnuplotRB.Dataset.init_string
def init_string(data, options) @type, @data = File.exist?(data) ? [:datafile, "'#{data}'"] : [:math_function, data.clone] @options = Hamster.hash(options) end
ruby
def init_string(data, options) @type, @data = File.exist?(data) ? [:datafile, "'#{data}'"] : [:math_function, data.clone] @options = Hamster.hash(options) end
[ "def", "init_string", "(", "data", ",", "options", ")", "@type", ",", "@data", "=", "File", ".", "exist?", "(", "data", ")", "?", "[", ":datafile", ",", "\"'#{data}'\"", "]", ":", "[", ":math_function", ",", "data", ".", "clone", "]", "@options", "=", ...
Initialize Dataset from given String
[ "Initialize", "Dataset", "from", "given", "String" ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/staff/dataset.rb#L235-L238
2,110
dilcom/gnuplotrb
lib/gnuplotrb/staff/dataset.rb
GnuplotRB.Dataset.get_daru_columns
def get_daru_columns(data, cnt) new_opt = (2..cnt).to_a.join(':') if data.index[0].is_a?(DateTime) || data.index[0].is_a?(Numeric) "1:#{new_opt}" else "#{new_opt}:xtic(1)" end end
ruby
def get_daru_columns(data, cnt) new_opt = (2..cnt).to_a.join(':') if data.index[0].is_a?(DateTime) || data.index[0].is_a?(Numeric) "1:#{new_opt}" else "#{new_opt}:xtic(1)" end end
[ "def", "get_daru_columns", "(", "data", ",", "cnt", ")", "new_opt", "=", "(", "2", "..", "cnt", ")", ".", "to_a", ".", "join", "(", "':'", ")", "if", "data", ".", "index", "[", "0", "]", ".", "is_a?", "(", "DateTime", ")", "||", "data", ".", "i...
Create new value for 'using' option based on column count
[ "Create", "new", "value", "for", "using", "option", "based", "on", "column", "count" ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/staff/dataset.rb#L250-L257
2,111
dilcom/gnuplotrb
lib/gnuplotrb/plot.rb
GnuplotRB.Plot.provide_with_datetime_format
def provide_with_datetime_format(data, using) return unless defined?(Daru) return unless data.is_a?(Daru::DataFrame) || data.is_a?(Daru::Vector) return unless data.index.first.is_a?(DateTime) return if using[0..1] != '1:' @options = Hamster::Hash.new( xdata: 'time', timefmt...
ruby
def provide_with_datetime_format(data, using) return unless defined?(Daru) return unless data.is_a?(Daru::DataFrame) || data.is_a?(Daru::Vector) return unless data.index.first.is_a?(DateTime) return if using[0..1] != '1:' @options = Hamster::Hash.new( xdata: 'time', timefmt...
[ "def", "provide_with_datetime_format", "(", "data", ",", "using", ")", "return", "unless", "defined?", "(", "Daru", ")", "return", "unless", "data", ".", "is_a?", "(", "Daru", "::", "DataFrame", ")", "||", "data", ".", "is_a?", "(", "Daru", "::", "Vector",...
Checks several conditions and set options needed to handle DateTime indexes properly.
[ "Checks", "several", "conditions", "and", "set", "options", "needed", "to", "handle", "DateTime", "indexes", "properly", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/plot.rb#L250-L260
2,112
dilcom/gnuplotrb
lib/gnuplotrb/plot.rb
GnuplotRB.Plot.dataset_from_any
def dataset_from_any(source) ds = case source # when initialized with dataframe (it passes here several vectors) when (defined?(Daru) ? Daru::Vector : nil) Dataset.new(source) when Dataset source.clone else Dataset.new(*source) ...
ruby
def dataset_from_any(source) ds = case source # when initialized with dataframe (it passes here several vectors) when (defined?(Daru) ? Daru::Vector : nil) Dataset.new(source) when Dataset source.clone else Dataset.new(*source) ...
[ "def", "dataset_from_any", "(", "source", ")", "ds", "=", "case", "source", "# when initialized with dataframe (it passes here several vectors)", "when", "(", "defined?", "(", "Daru", ")", "?", "Daru", "::", "Vector", ":", "nil", ")", "Dataset", ".", "new", "(", ...
Check if given args is a dataset and returns it. Creates new dataset from given args otherwise.
[ "Check", "if", "given", "args", "is", "a", "dataset", "and", "returns", "it", ".", "Creates", "new", "dataset", "from", "given", "args", "otherwise", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/plot.rb#L265-L278
2,113
alor/em-http-server
lib/em-http-server/response.rb
EventMachine.HttpResponse.send_headers
def send_headers raise "sent headers already" if @sent_headers @sent_headers = true fixup_headers ary = [] ary << "HTTP/1.1 #{@status || 200} #{@status_string || '...'}\r\n" ary += generate_header_lines(@headers) ary << "\r\n" send_data ary.join end
ruby
def send_headers raise "sent headers already" if @sent_headers @sent_headers = true fixup_headers ary = [] ary << "HTTP/1.1 #{@status || 200} #{@status_string || '...'}\r\n" ary += generate_header_lines(@headers) ary << "\r\n" send_data ary.join end
[ "def", "send_headers", "raise", "\"sent headers already\"", "if", "@sent_headers", "@sent_headers", "=", "true", "fixup_headers", "ary", "=", "[", "]", "ary", "<<", "\"HTTP/1.1 #{@status || 200} #{@status_string || '...'}\\r\\n\"", "ary", "+=", "generate_header_lines", "(", ...
Send the headers out in alpha-sorted order. This will degrade performance to some degree, and is intended only to simplify the construction of unit tests.
[ "Send", "the", "headers", "out", "in", "alpha", "-", "sorted", "order", ".", "This", "will", "degrade", "performance", "to", "some", "degree", "and", "is", "intended", "only", "to", "simplify", "the", "construction", "of", "unit", "tests", "." ]
4c5050b376e5765572e074db7a92f65f882b24a2
https://github.com/alor/em-http-server/blob/4c5050b376e5765572e074db7a92f65f882b24a2/lib/em-http-server/response.rb#L108-L120
2,114
iron-io/rest
lib/rest/wrappers/base_wrapper.rb
Rest.BaseResponseWrapper.headers
def headers new_h = {} headers_orig.each_pair do |k, v| if v.is_a?(Array) && v.size == 1 v = v[0] end new_h[k.downcase] = v end new_h end
ruby
def headers new_h = {} headers_orig.each_pair do |k, v| if v.is_a?(Array) && v.size == 1 v = v[0] end new_h[k.downcase] = v end new_h end
[ "def", "headers", "new_h", "=", "{", "}", "headers_orig", ".", "each_pair", "do", "|", "k", ",", "v", "|", "if", "v", ".", "is_a?", "(", "Array", ")", "&&", "v", ".", "size", "==", "1", "v", "=", "v", "[", "0", "]", "end", "new_h", "[", "k", ...
Provide a headers_orig method in your wrapper to allow this to work
[ "Provide", "a", "headers_orig", "method", "in", "your", "wrapper", "to", "allow", "this", "to", "work" ]
7775483f775a4b0560a1687fee48149b52fa5c51
https://github.com/iron-io/rest/blob/7775483f775a4b0560a1687fee48149b52fa5c51/lib/rest/wrappers/base_wrapper.rb#L42-L51
2,115
dilcom/gnuplotrb
lib/gnuplotrb/animation.rb
GnuplotRB.Animation.plot
def plot(path = nil, **options) options[:output] ||= path plot_options = mix_options(options) do |plot_opts, anim_opts| plot_opts.merge(term: ['gif', anim_opts]) end.to_h need_output = plot_options[:output].nil? plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_o...
ruby
def plot(path = nil, **options) options[:output] ||= path plot_options = mix_options(options) do |plot_opts, anim_opts| plot_opts.merge(term: ['gif', anim_opts]) end.to_h need_output = plot_options[:output].nil? plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_o...
[ "def", "plot", "(", "path", "=", "nil", ",", "**", "options", ")", "options", "[", ":output", "]", "||=", "path", "plot_options", "=", "mix_options", "(", "options", ")", "do", "|", "plot_opts", ",", "anim_opts", "|", "plot_opts", ".", "merge", "(", "t...
This method creates a gif animation where frames are plots already contained by Animation object. Options passed in #plot have priority over those which were set before. Inner options of Plots have the highest priority (except :term and :output which are ignored). @param path [String] path to new gif file that ...
[ "This", "method", "creates", "a", "gif", "animation", "where", "frames", "are", "plots", "already", "contained", "by", "Animation", "object", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/animation.rb#L55-L73
2,116
dilcom/gnuplotrb
lib/gnuplotrb/animation.rb
GnuplotRB.Animation.specific_keys
def specific_keys %w( animate size background transparent enhanced rounded butt linewidth dashlength tiny small medium large giant font fontscale crop ) end
ruby
def specific_keys %w( animate size background transparent enhanced rounded butt linewidth dashlength tiny small medium large giant font fontscale crop ) end
[ "def", "specific_keys", "%w(", "animate", "size", "background", "transparent", "enhanced", "rounded", "butt", "linewidth", "dashlength", "tiny", "small", "medium", "large", "giant", "font", "fontscale", "crop", ")", "end" ]
This plot have some specific options which should be handled different way than others. Here are keys of this options.
[ "This", "plot", "have", "some", "specific", "options", "which", "should", "be", "handled", "different", "way", "than", "others", ".", "Here", "are", "keys", "of", "this", "options", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/animation.rb#L107-L127
2,117
dilcom/gnuplotrb
lib/gnuplotrb/fit.rb
GnuplotRB.Fit.fit
def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options) dataset = data.is_a?(Dataset) ? Dataset.new(data.data) : Dataset.new(data) opts_str = OptionHandling.ruby_class_to_gnuplot(options) output = gnuplot_fit(function, dataset, opts_str, initials, term...
ruby
def fit(data, function: 'a2*x*x+a1*x+a0', initials: { a2: 1, a1: 1, a0: 1 }, term_options: {}, **options) dataset = data.is_a?(Dataset) ? Dataset.new(data.data) : Dataset.new(data) opts_str = OptionHandling.ruby_class_to_gnuplot(options) output = gnuplot_fit(function, dataset, opts_str, initials, term...
[ "def", "fit", "(", "data", ",", "function", ":", "'a2*x*x+a1*x+a0'", ",", "initials", ":", "{", "a2", ":", "1", ",", "a1", ":", "1", ",", "a0", ":", "1", "}", ",", "term_options", ":", "{", "}", ",", "**", "options", ")", "dataset", "=", "data", ...
Fit given data with function. Fit waits for output from gnuplot Settings.max_fit_delay and throw exception if gets nothing. One can change this value in order to wait longer (if huge datasets is fitted). @param data [#to_gnuplot_points] method accepts the same sources as Dataset.new and Dataset object @param :...
[ "Fit", "given", "data", "with", "function", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/fit.rb#L36-L47
2,118
dilcom/gnuplotrb
lib/gnuplotrb/fit.rb
GnuplotRB.Fit.wait_for_output
def wait_for_output(term, variables) # now we should catch 'error' from terminal: it will contain approximation data # but we can get a real error instead of output, so lets wait for limited time start = Time.now output = '' until output_ready?(output, variables) begin te...
ruby
def wait_for_output(term, variables) # now we should catch 'error' from terminal: it will contain approximation data # but we can get a real error instead of output, so lets wait for limited time start = Time.now output = '' until output_ready?(output, variables) begin te...
[ "def", "wait_for_output", "(", "term", ",", "variables", ")", "# now we should catch 'error' from terminal: it will contain approximation data", "# but we can get a real error instead of output, so lets wait for limited time", "start", "=", "Time", ".", "now", "output", "=", "''", ...
It takes some time to produce output so here we need to wait for it. Max time to wait is stored in Settings.max_fit_delay, so one can change it in order to wait longer.
[ "It", "takes", "some", "time", "to", "produce", "output", "so", "here", "we", "need", "to", "wait", "for", "it", "." ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/fit.rb#L140-L156
2,119
dilcom/gnuplotrb
lib/gnuplotrb/fit.rb
GnuplotRB.Fit.gnuplot_fit
def gnuplot_fit(function, data, options, initials, term_options) variables = initials.keys term = Terminal.new term.set(term_options) initials.each { |var_name, value| term.stream_puts "#{var_name} = #{value}" } command = "fit #{function} #{data.to_s(term, without_options: true)} " \ ...
ruby
def gnuplot_fit(function, data, options, initials, term_options) variables = initials.keys term = Terminal.new term.set(term_options) initials.each { |var_name, value| term.stream_puts "#{var_name} = #{value}" } command = "fit #{function} #{data.to_s(term, without_options: true)} " \ ...
[ "def", "gnuplot_fit", "(", "function", ",", "data", ",", "options", ",", "initials", ",", "term_options", ")", "variables", "=", "initials", ".", "keys", "term", "=", "Terminal", ".", "new", "term", ".", "set", "(", "term_options", ")", "initials", ".", ...
Make fit command and send it to gnuplot
[ "Make", "fit", "command", "and", "send", "it", "to", "gnuplot" ]
0a3146386ae28fcbe2c09cb6e266fe40ebb659f4
https://github.com/dilcom/gnuplotrb/blob/0a3146386ae28fcbe2c09cb6e266fe40ebb659f4/lib/gnuplotrb/fit.rb#L184-L202
2,120
namick/scatter_swap
lib/scatter_swap/hasher.rb
ScatterSwap.Hasher.swapper_map
def swapper_map(index) array = (0..9).to_a 10.times.collect.with_index do |i| array.rotate!(index + i ^ spin).pop end end
ruby
def swapper_map(index) array = (0..9).to_a 10.times.collect.with_index do |i| array.rotate!(index + i ^ spin).pop end end
[ "def", "swapper_map", "(", "index", ")", "array", "=", "(", "0", "..", "9", ")", ".", "to_a", "10", ".", "times", ".", "collect", ".", "with_index", "do", "|", "i", "|", "array", ".", "rotate!", "(", "index", "+", "i", "^", "spin", ")", ".", "p...
We want a unique map for each place in the original number
[ "We", "want", "a", "unique", "map", "for", "each", "place", "in", "the", "original", "number" ]
0ae5a936482752e4f2220f0e54d7647b5953d80e
https://github.com/namick/scatter_swap/blob/0ae5a936482752e4f2220f0e54d7647b5953d80e/lib/scatter_swap/hasher.rb#L31-L36
2,121
namick/scatter_swap
lib/scatter_swap/hasher.rb
ScatterSwap.Hasher.unscatter
def unscatter scattered_array = @working_array sum_of_digits = scattered_array.inject(:+).to_i @working_array = [] @working_array.tap do |unscatter| 10.times do unscatter.push scattered_array.pop unscatter.rotate! (sum_of_digits ^ spin) * -1 end end ...
ruby
def unscatter scattered_array = @working_array sum_of_digits = scattered_array.inject(:+).to_i @working_array = [] @working_array.tap do |unscatter| 10.times do unscatter.push scattered_array.pop unscatter.rotate! (sum_of_digits ^ spin) * -1 end end ...
[ "def", "unscatter", "scattered_array", "=", "@working_array", "sum_of_digits", "=", "scattered_array", ".", "inject", "(", ":+", ")", ".", "to_i", "@working_array", "=", "[", "]", "@working_array", ".", "tap", "do", "|", "unscatter", "|", "10", ".", "times", ...
Reverse the scatter
[ "Reverse", "the", "scatter" ]
0ae5a936482752e4f2220f0e54d7647b5953d80e
https://github.com/namick/scatter_swap/blob/0ae5a936482752e4f2220f0e54d7647b5953d80e/lib/scatter_swap/hasher.rb#L64-L74
2,122
futurechimp/awrence
lib/awrence/methods.rb
Awrence.Methods.to_camelback_keys
def to_camelback_keys(value = self) case value when Array value.map { |v| to_camelback_keys(v) } when Hash Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }] else value end end
ruby
def to_camelback_keys(value = self) case value when Array value.map { |v| to_camelback_keys(v) } when Hash Hash[value.map { |k, v| [camelize_key(k, false), to_camelback_keys(v)] }] else value end end
[ "def", "to_camelback_keys", "(", "value", "=", "self", ")", "case", "value", "when", "Array", "value", ".", "map", "{", "|", "v", "|", "to_camelback_keys", "(", "v", ")", "}", "when", "Hash", "Hash", "[", "value", ".", "map", "{", "|", "k", ",", "v...
Recursively converts Rubyish snake_case hash keys to camelBack JSON-style hash keys suitable for use with a JSON API.
[ "Recursively", "converts", "Rubyish", "snake_case", "hash", "keys", "to", "camelBack", "JSON", "-", "style", "hash", "keys", "suitable", "for", "use", "with", "a", "JSON", "API", "." ]
f040f70b82828a6d803f3552b267eb9aec194c57
https://github.com/futurechimp/awrence/blob/f040f70b82828a6d803f3552b267eb9aec194c57/lib/awrence/methods.rb#L8-L17
2,123
futurechimp/awrence
lib/awrence/methods.rb
Awrence.Methods.to_camel_keys
def to_camel_keys(value = self) case value when Array value.map { |v| to_camel_keys(v) } when Hash Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }] else value end end
ruby
def to_camel_keys(value = self) case value when Array value.map { |v| to_camel_keys(v) } when Hash Hash[value.map { |k, v| [camelize_key(k), to_camel_keys(v)] }] else value end end
[ "def", "to_camel_keys", "(", "value", "=", "self", ")", "case", "value", "when", "Array", "value", ".", "map", "{", "|", "v", "|", "to_camel_keys", "(", "v", ")", "}", "when", "Hash", "Hash", "[", "value", ".", "map", "{", "|", "k", ",", "v", "|"...
Recursively converts Rubyish snake_case hash keys to CamelCase JSON-style hash keys suitable for use with a JSON API.
[ "Recursively", "converts", "Rubyish", "snake_case", "hash", "keys", "to", "CamelCase", "JSON", "-", "style", "hash", "keys", "suitable", "for", "use", "with", "a", "JSON", "API", "." ]
f040f70b82828a6d803f3552b267eb9aec194c57
https://github.com/futurechimp/awrence/blob/f040f70b82828a6d803f3552b267eb9aec194c57/lib/awrence/methods.rb#L22-L31
2,124
mdh/ssm
lib/simple_state_machine/state_machine.rb
SimpleStateMachine.StateMachine.next_state
def next_state(event_name) transition = transitions.select{|t| t.is_transition_for?(event_name, @subject.send(state_method))}.first transition ? transition.to : nil end
ruby
def next_state(event_name) transition = transitions.select{|t| t.is_transition_for?(event_name, @subject.send(state_method))}.first transition ? transition.to : nil end
[ "def", "next_state", "(", "event_name", ")", "transition", "=", "transitions", ".", "select", "{", "|", "t", "|", "t", ".", "is_transition_for?", "(", "event_name", ",", "@subject", ".", "send", "(", "state_method", ")", ")", "}", ".", "first", "transition...
Returns the next state for the subject for event_name
[ "Returns", "the", "next", "state", "for", "the", "subject", "for", "event_name" ]
81f82c44cf75f444ee720f83fb3a5d3e570247f9
https://github.com/mdh/ssm/blob/81f82c44cf75f444ee720f83fb3a5d3e570247f9/lib/simple_state_machine/state_machine.rb#L15-L18
2,125
mdh/ssm
lib/simple_state_machine/state_machine.rb
SimpleStateMachine.StateMachine.error_state
def error_state(event_name, error) transition = transitions.select{|t| t.is_error_transition_for?(event_name, error) }.first transition ? transition.to : nil end
ruby
def error_state(event_name, error) transition = transitions.select{|t| t.is_error_transition_for?(event_name, error) }.first transition ? transition.to : nil end
[ "def", "error_state", "(", "event_name", ",", "error", ")", "transition", "=", "transitions", ".", "select", "{", "|", "t", "|", "t", ".", "is_error_transition_for?", "(", "event_name", ",", "error", ")", "}", ".", "first", "transition", "?", "transition", ...
Returns the error state for the subject for event_name and error
[ "Returns", "the", "error", "state", "for", "the", "subject", "for", "event_name", "and", "error" ]
81f82c44cf75f444ee720f83fb3a5d3e570247f9
https://github.com/mdh/ssm/blob/81f82c44cf75f444ee720f83fb3a5d3e570247f9/lib/simple_state_machine/state_machine.rb#L21-L24
2,126
mdh/ssm
lib/simple_state_machine/state_machine.rb
SimpleStateMachine.StateMachine.transition
def transition(event_name) clear_raised_error if to = next_state(event_name) begin result = yield rescue => e error_state = error_state(event_name, e) || state_machine_definition.default_error_state if error_state @raised_error = e ...
ruby
def transition(event_name) clear_raised_error if to = next_state(event_name) begin result = yield rescue => e error_state = error_state(event_name, e) || state_machine_definition.default_error_state if error_state @raised_error = e ...
[ "def", "transition", "(", "event_name", ")", "clear_raised_error", "if", "to", "=", "next_state", "(", "event_name", ")", "begin", "result", "=", "yield", "rescue", "=>", "e", "error_state", "=", "error_state", "(", "event_name", ",", "e", ")", "||", "state_...
Transitions to the next state if next_state exists. When an error occurs, it uses the error to determine next state. If no next state can be determined it transitions to the default error state if defined, otherwise the error is re-raised. Calls illegal_event_callback event_name if no next_state is found
[ "Transitions", "to", "the", "next", "state", "if", "next_state", "exists", ".", "When", "an", "error", "occurs", "it", "uses", "the", "error", "to", "determine", "next", "state", ".", "If", "no", "next", "state", "can", "be", "determined", "it", "transitio...
81f82c44cf75f444ee720f83fb3a5d3e570247f9
https://github.com/mdh/ssm/blob/81f82c44cf75f444ee720f83fb3a5d3e570247f9/lib/simple_state_machine/state_machine.rb#L31-L62
2,127
alfa-jpn/inum
lib/inum/active_record_mixin.rb
Inum.ActiveRecordMixin.bind_inum
def bind_inum(column, enum_class, options = {}) options = { prefix: column }.merge(options) options[:prefix] = options[:prefix] ? "#{options[:prefix]}_" : '' self.class_eval do define_method(column) do enum_class.parse(read_attribute(column)) end define_method("#{co...
ruby
def bind_inum(column, enum_class, options = {}) options = { prefix: column }.merge(options) options[:prefix] = options[:prefix] ? "#{options[:prefix]}_" : '' self.class_eval do define_method(column) do enum_class.parse(read_attribute(column)) end define_method("#{co...
[ "def", "bind_inum", "(", "column", ",", "enum_class", ",", "options", "=", "{", "}", ")", "options", "=", "{", "prefix", ":", "column", "}", ".", "merge", "(", "options", ")", "options", "[", ":prefix", "]", "=", "options", "[", ":prefix", "]", "?", ...
Define compare method in class. @param column [Symbol] Binding column name. @param enum_class [Inum::Base] Binding Enum. @param options [Hash] option @option options [Symbol] :prefix Prefix. (default: column)
[ "Define", "compare", "method", "in", "class", "." ]
41a504aaebaf5523a9d895b1173bdbd6f02ac86d
https://github.com/alfa-jpn/inum/blob/41a504aaebaf5523a9d895b1173bdbd6f02ac86d/lib/inum/active_record_mixin.rb#L16-L41
2,128
veelenga/i3ipc-ruby
lib/i3ipc/protocol.rb
I3Ipc.Protocol.receive
def receive(type = nil) check_connected # length of "i3-ipc" + 4 bytes length + 4 bytes type data = @socket.read 14 magic, len, recv_type = unpack_header(data) raise WrongMagicString.new(magic) unless MAGIC_STRING.eql? magic type && (raise WrongType.new(type, recv_type) unless type ...
ruby
def receive(type = nil) check_connected # length of "i3-ipc" + 4 bytes length + 4 bytes type data = @socket.read 14 magic, len, recv_type = unpack_header(data) raise WrongMagicString.new(magic) unless MAGIC_STRING.eql? magic type && (raise WrongType.new(type, recv_type) unless type ...
[ "def", "receive", "(", "type", "=", "nil", ")", "check_connected", "# length of \"i3-ipc\" + 4 bytes length + 4 bytes type", "data", "=", "@socket", ".", "read", "14", "magic", ",", "len", ",", "recv_type", "=", "unpack_header", "(", "data", ")", "raise", "WrongMa...
Receives message from i3-ipc server socket. @param [Integer] type expected type of the message. @return [String] unpacked response from i3 server. @raise [NotConnected] if protocol is not connected. @raise [WrongMagicString] if got message with wrong magic string. @raise [WrongType] if got message with not expe...
[ "Receives", "message", "from", "i3", "-", "ipc", "server", "socket", "." ]
0c3a2a76d3c264c634a0d94cc31b8be2639d9ec6
https://github.com/veelenga/i3ipc-ruby/blob/0c3a2a76d3c264c634a0d94cc31b8be2639d9ec6/lib/i3ipc/protocol.rb#L84-L94
2,129
mdh/ssm
lib/simple_state_machine/transition.rb
SimpleStateMachine.Transition.is_error_transition_for?
def is_error_transition_for?(event_name, error) is_same_event?(event_name) && from.is_a?(Class) && error.is_a?(from) end
ruby
def is_error_transition_for?(event_name, error) is_same_event?(event_name) && from.is_a?(Class) && error.is_a?(from) end
[ "def", "is_error_transition_for?", "(", "event_name", ",", "error", ")", "is_same_event?", "(", "event_name", ")", "&&", "from", ".", "is_a?", "(", "Class", ")", "&&", "error", ".", "is_a?", "(", "from", ")", "end" ]
returns true if it's a error transition for event_name and error
[ "returns", "true", "if", "it", "s", "a", "error", "transition", "for", "event_name", "and", "error" ]
81f82c44cf75f444ee720f83fb3a5d3e570247f9
https://github.com/mdh/ssm/blob/81f82c44cf75f444ee720f83fb3a5d3e570247f9/lib/simple_state_machine/transition.rb#L17-L19
2,130
fantasticfears/ffi-icu
lib/ffi-icu/normalizer.rb
ICU.Normalizer.normalize
def normalize(input) input_length = input.jlength in_ptr = UCharPointer.from_string(input) needed_length = capacity = 0 out_ptr = UCharPointer.new(needed_length) retried = false begin Lib.check_error do |error| needed_length = Lib.unorm2_normalize(@in...
ruby
def normalize(input) input_length = input.jlength in_ptr = UCharPointer.from_string(input) needed_length = capacity = 0 out_ptr = UCharPointer.new(needed_length) retried = false begin Lib.check_error do |error| needed_length = Lib.unorm2_normalize(@in...
[ "def", "normalize", "(", "input", ")", "input_length", "=", "input", ".", "jlength", "in_ptr", "=", "UCharPointer", ".", "from_string", "(", "input", ")", "needed_length", "=", "capacity", "=", "0", "out_ptr", "=", "UCharPointer", ".", "new", "(", "needed_le...
support for newer ICU normalization API
[ "support", "for", "newer", "ICU", "normalization", "API" ]
9694d97b5a700b613c8d3c9ce9e0d0e9dcbf4a30
https://github.com/fantasticfears/ffi-icu/blob/9694d97b5a700b613c8d3c9ce9e0d0e9dcbf4a30/lib/ffi-icu/normalizer.rb#L11-L33
2,131
mdespuits/validates_formatting_of
lib/validates_formatting_of/model_additions.rb
ValidatesFormattingOf.ModelAdditions.validates_formatting_of
def validates_formatting_of(attribute, options = {}) validation = Method.find(attribute, options) options.reverse_merge!(:with => validation.regex, :message => validation.message) self.validates_format_of(attribute, options) end
ruby
def validates_formatting_of(attribute, options = {}) validation = Method.find(attribute, options) options.reverse_merge!(:with => validation.regex, :message => validation.message) self.validates_format_of(attribute, options) end
[ "def", "validates_formatting_of", "(", "attribute", ",", "options", "=", "{", "}", ")", "validation", "=", "Method", ".", "find", "(", "attribute", ",", "options", ")", "options", ".", "reverse_merge!", "(", ":with", "=>", "validation", ".", "regex", ",", ...
Using validates_formatting_of is as simple as using Rails' built-in validation methods in models. class User < ActiveRecord::Base validates_formatting_of :email, :using => :email end If your column name is idencital to any of the built-in methods, you may leave off the `:using` option and validates_formatting...
[ "Using", "validates_formatting_of", "is", "as", "simple", "as", "using", "Rails", "built", "-", "in", "validation", "methods", "in", "models", "." ]
664b7c8b1ae8c9016549944fc833737c74f1d752
https://github.com/mdespuits/validates_formatting_of/blob/664b7c8b1ae8c9016549944fc833737c74f1d752/lib/validates_formatting_of/model_additions.rb#L27-L31
2,132
phstc/sidekiq-statsd
lib/sidekiq/statsd/server_middleware.rb
Sidekiq::Statsd.ServerMiddleware.call
def call worker, msg, queue @statsd.batch do |b| begin # colon causes invalid metric names worker_name = worker.class.name.gsub('::', '.') b.time prefix(worker_name, 'processing_time') do yield end b.increment prefix(worker_name, 'success') ...
ruby
def call worker, msg, queue @statsd.batch do |b| begin # colon causes invalid metric names worker_name = worker.class.name.gsub('::', '.') b.time prefix(worker_name, 'processing_time') do yield end b.increment prefix(worker_name, 'success') ...
[ "def", "call", "worker", ",", "msg", ",", "queue", "@statsd", ".", "batch", "do", "|", "b", "|", "begin", "# colon causes invalid metric names", "worker_name", "=", "worker", ".", "class", ".", "name", ".", "gsub", "(", "'::'", ",", "'.'", ")", "b", ".",...
Initializes the middleware with options. @param [Hash] options The options to initialize the StatsD client. @option options [Statsd] :statsd Existing statsd client. @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure). @option options [String]...
[ "Initializes", "the", "middleware", "with", "options", "." ]
8ae212173b8860ece70e903a6a8ebd266f1f818e
https://github.com/phstc/sidekiq-statsd/blob/8ae212173b8860ece70e903a6a8ebd266f1f818e/lib/sidekiq/statsd/server_middleware.rb#L37-L74
2,133
rpossan/autoit
lib/autoit/control.rb
AutoIt.Control.control_command_select_string
def control_command_select_string(title, text, control, string) command 'ControlCommand', [title, text, control, 'SelectString', string] end
ruby
def control_command_select_string(title, text, control, string) command 'ControlCommand', [title, text, control, 'SelectString', string] end
[ "def", "control_command_select_string", "(", "title", ",", "text", ",", "control", ",", "string", ")", "command", "'ControlCommand'", ",", "[", "title", ",", "text", ",", "control", ",", "'SelectString'", ",", "string", "]", "end" ]
Sets selection according to string in a ListBox or ComboBox @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: string: The string.
[ "Sets", "selection", "according", "to", "string", "in", "a", "ListBox", "or", "ComboBox" ]
f24d1891dac4431830eaf9a7c6afeeada3f653f8
https://github.com/rpossan/autoit/blob/f24d1891dac4431830eaf9a7c6afeeada3f653f8/lib/autoit/control.rb#L110-L112
2,134
rpossan/autoit
lib/autoit/control.rb
AutoIt.Control.control_set_text
def control_set_text(title, text, control, value) command_validate'ControlSetText', [title, text, control, value] end
ruby
def control_set_text(title, text, control, value) command_validate'ControlSetText', [title, text, control, value] end
[ "def", "control_set_text", "(", "title", ",", "text", ",", "control", ",", "value", ")", "command_validate", "'ControlSetText'", ",", "[", "title", ",", "text", ",", "control", ",", "value", "]", "end" ]
Sets text of a control. Sends a string of characters to a control. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: string: The string. @return True if success, false otherwise
[ "Sets", "text", "of", "a", "control", ".", "Sends", "a", "string", "of", "characters", "to", "a", "control", "." ]
f24d1891dac4431830eaf9a7c6afeeada3f653f8
https://github.com/rpossan/autoit/blob/f24d1891dac4431830eaf9a7c6afeeada3f653f8/lib/autoit/control.rb#L137-L139
2,135
rpossan/autoit
lib/autoit/control.rb
AutoIt.Control.control_click
def control_click(title, text, control, button, clicks, x, y) command_validate('ControlClick', [title, text, control, button, clicks, x, y]) end
ruby
def control_click(title, text, control, button, clicks, x, y) command_validate('ControlClick', [title, text, control, button, clicks, x, y]) end
[ "def", "control_click", "(", "title", ",", "text", ",", "control", ",", "button", ",", "clicks", ",", "x", ",", "y", ")", "command_validate", "(", "'ControlClick'", ",", "[", "title", ",", "text", ",", "control", ",", "button", ",", "clicks", ",", "x",...
Sends a mouse click command to a given control. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: controlID: The control to interact with. @param: button: The button to click, "left", "right" or "middle". @param: clicks: The number of times to click the mouse...
[ "Sends", "a", "mouse", "click", "command", "to", "a", "given", "control", "." ]
f24d1891dac4431830eaf9a7c6afeeada3f653f8
https://github.com/rpossan/autoit/blob/f24d1891dac4431830eaf9a7c6afeeada3f653f8/lib/autoit/control.rb#L150-L152
2,136
rpossan/autoit
lib/autoit/control.rb
AutoIt.Control.control_command_set_current_selection
def control_command_set_current_selection(title, text, control, occurrance) command('ControlCommand', [title, text, control, 'SetCurrentSelection', occurrance]) end
ruby
def control_command_set_current_selection(title, text, control, occurrance) command('ControlCommand', [title, text, control, 'SetCurrentSelection', occurrance]) end
[ "def", "control_command_set_current_selection", "(", "title", ",", "text", ",", "control", ",", "occurrance", ")", "command", "(", "'ControlCommand'", ",", "[", "title", ",", "text", ",", "control", ",", "'SetCurrentSelection'", ",", "occurrance", "]", ")", "end...
Sets selection to occurrence ref in a ListBox or ComboBox. @param: title: The title of the window to access. @param: text: The text of the window to access. @param: control: The control to interact with. @param: occurrance: the value.
[ "Sets", "selection", "to", "occurrence", "ref", "in", "a", "ListBox", "or", "ComboBox", "." ]
f24d1891dac4431830eaf9a7c6afeeada3f653f8
https://github.com/rpossan/autoit/blob/f24d1891dac4431830eaf9a7c6afeeada3f653f8/lib/autoit/control.rb#L159-L161
2,137
stereobooster/html_press
lib/html_press/html.rb
HtmlPress.Html.process_ie_conditional_comments
def process_ie_conditional_comments (out) out.gsub /(<!--\[[^\]]+\]>([\s\S]*?)<!\[[^\]]+\]-->)\s*/ do m = $1 comment = $2 comment_compressed = Html.new.press(comment) m.gsub!(comment, comment_compressed) reserve m end end
ruby
def process_ie_conditional_comments (out) out.gsub /(<!--\[[^\]]+\]>([\s\S]*?)<!\[[^\]]+\]-->)\s*/ do m = $1 comment = $2 comment_compressed = Html.new.press(comment) m.gsub!(comment, comment_compressed) reserve m end end
[ "def", "process_ie_conditional_comments", "(", "out", ")", "out", ".", "gsub", "/", "\\[", "\\]", "\\]", "\\s", "\\S", "\\[", "\\]", "\\]", "\\s", "/", "do", "m", "=", "$1", "comment", "=", "$2", "comment_compressed", "=", "Html", ".", "new", ".", "pre...
IE conditional comments
[ "IE", "conditional", "comments" ]
4bc4599751708b6054d0d2afc76aa720973dd94f
https://github.com/stereobooster/html_press/blob/4bc4599751708b6054d0d2afc76aa720973dd94f/lib/html_press/html.rb#L57-L65
2,138
stereobooster/html_press
lib/html_press/html.rb
HtmlPress.Html.process_pres
def process_pres (out) out.gsub /(<pre\b[^>]*?>([\s\S]*?)<\/pre>)\s*/i do pre = $2 m = $1 pre_compressed = pre.lines.map{ |l| l.gsub(/\s+$/, '') }.join("\n") pre_compressed = HtmlPress.entities_compressor pre_compressed m.gsub!(pre, pre_compressed) reserve m e...
ruby
def process_pres (out) out.gsub /(<pre\b[^>]*?>([\s\S]*?)<\/pre>)\s*/i do pre = $2 m = $1 pre_compressed = pre.lines.map{ |l| l.gsub(/\s+$/, '') }.join("\n") pre_compressed = HtmlPress.entities_compressor pre_compressed m.gsub!(pre, pre_compressed) reserve m e...
[ "def", "process_pres", "(", "out", ")", "out", ".", "gsub", "/", "\\b", "\\s", "\\S", "\\/", "\\s", "/i", "do", "pre", "=", "$2", "m", "=", "$1", "pre_compressed", "=", "pre", ".", "lines", ".", "map", "{", "|", "l", "|", "l", ".", "gsub", "(",...
replace PREs with placeholders
[ "replace", "PREs", "with", "placeholders" ]
4bc4599751708b6054d0d2afc76aa720973dd94f
https://github.com/stereobooster/html_press/blob/4bc4599751708b6054d0d2afc76aa720973dd94f/lib/html_press/html.rb#L107-L116
2,139
stereobooster/html_press
lib/html_press/html.rb
HtmlPress.Html.process_block_elements
def process_block_elements (out) re = '\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' + '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' + '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' + '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h|r|foot|it...
ruby
def process_block_elements (out) re = '\\s+(<\\/?(?:area|base(?:font)?|blockquote|body' + '|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form' + '|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta' + '|ol|opt(?:group|ion)|p|param|t(?:able|body|head|d|h|r|foot|it...
[ "def", "process_block_elements", "(", "out", ")", "re", "=", "'\\\\s+(<\\\\/?(?:area|base(?:font)?|blockquote|body'", "+", "'|caption|center|cite|col(?:group)?|dd|dir|div|dl|dt|fieldset|form'", "+", "'|frame(?:set)?|h[1-6]|head|hr|html|legend|li|link|map|menu|meta'", "+", "'|ol|opt(?:group...
remove whitespaces outside of block elements
[ "remove", "whitespaces", "outside", "of", "block", "elements" ]
4bc4599751708b6054d0d2afc76aa720973dd94f
https://github.com/stereobooster/html_press/blob/4bc4599751708b6054d0d2afc76aa720973dd94f/lib/html_press/html.rb#L124-L140
2,140
haw-itn/openassets-ruby
lib/openassets/util.rb
OpenAssets.Util.address_to_oa_address
def address_to_oa_address(btc_address) begin btc_hex = decode_base58(btc_address) btc_hex = '0' +btc_hex if btc_hex.size==47 address = btc_hex[0..-9] # bitcoin address without checksum named_addr = OA_NAMESPACE.to_s(16) + address oa_checksum = checksum(named_addr) e...
ruby
def address_to_oa_address(btc_address) begin btc_hex = decode_base58(btc_address) btc_hex = '0' +btc_hex if btc_hex.size==47 address = btc_hex[0..-9] # bitcoin address without checksum named_addr = OA_NAMESPACE.to_s(16) + address oa_checksum = checksum(named_addr) e...
[ "def", "address_to_oa_address", "(", "btc_address", ")", "begin", "btc_hex", "=", "decode_base58", "(", "btc_address", ")", "btc_hex", "=", "'0'", "+", "btc_hex", "if", "btc_hex", ".", "size", "==", "47", "address", "=", "btc_hex", "[", "0", "..", "-", "9"...
convert bitcoin address to open assets address @param [String] btc_address The Bitcoin address. @return [String] The Open Assets Address.
[ "convert", "bitcoin", "address", "to", "open", "assets", "address" ]
c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf
https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/util.rb#L17-L28
2,141
haw-itn/openassets-ruby
lib/openassets/util.rb
OpenAssets.Util.oa_address_to_address
def oa_address_to_address(oa_address) decode_address = decode_base58(oa_address) btc_addr = decode_address[2..-9] btc_checksum = checksum(btc_addr) encode_base58(btc_addr + btc_checksum) end
ruby
def oa_address_to_address(oa_address) decode_address = decode_base58(oa_address) btc_addr = decode_address[2..-9] btc_checksum = checksum(btc_addr) encode_base58(btc_addr + btc_checksum) end
[ "def", "oa_address_to_address", "(", "oa_address", ")", "decode_address", "=", "decode_base58", "(", "oa_address", ")", "btc_addr", "=", "decode_address", "[", "2", "..", "-", "9", "]", "btc_checksum", "=", "checksum", "(", "btc_addr", ")", "encode_base58", "(",...
convert open assets address to bitcoin address @param [String] oa_address The Open Assets Address. @return [String] The Bitcoin address.
[ "convert", "open", "assets", "address", "to", "bitcoin", "address" ]
c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf
https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/util.rb#L33-L38
2,142
haw-itn/openassets-ruby
lib/openassets/util.rb
OpenAssets.Util.valid_asset_id?
def valid_asset_id?(asset_id) return false if asset_id.nil? || asset_id.length != 34 decoded = decode_base58(asset_id) return false if decoded[0,2].to_i(16) != oa_version_byte p2pkh_script_hash = decoded[2..-9] address = hash160_to_address(p2pkh_script_hash) valid_address?(address) ...
ruby
def valid_asset_id?(asset_id) return false if asset_id.nil? || asset_id.length != 34 decoded = decode_base58(asset_id) return false if decoded[0,2].to_i(16) != oa_version_byte p2pkh_script_hash = decoded[2..-9] address = hash160_to_address(p2pkh_script_hash) valid_address?(address) ...
[ "def", "valid_asset_id?", "(", "asset_id", ")", "return", "false", "if", "asset_id", ".", "nil?", "||", "asset_id", ".", "length", "!=", "34", "decoded", "=", "decode_base58", "(", "asset_id", ")", "return", "false", "if", "decoded", "[", "0", ",", "2", ...
validate asset ID
[ "validate", "asset", "ID" ]
c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf
https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/util.rb#L113-L120
2,143
haw-itn/openassets-ruby
lib/openassets/util.rb
OpenAssets.Util.read_var_integer
def read_var_integer(data, offset = 0) raise ArgumentError, "data is nil." unless data packed = [data].pack('H*') return [nil, 0] if packed.bytesize < 1+offset bytes = packed.bytes[offset..(offset + 9)] # 9 is variable integer max storage length. first_byte = bytes[0] if first_byte <...
ruby
def read_var_integer(data, offset = 0) raise ArgumentError, "data is nil." unless data packed = [data].pack('H*') return [nil, 0] if packed.bytesize < 1+offset bytes = packed.bytes[offset..(offset + 9)] # 9 is variable integer max storage length. first_byte = bytes[0] if first_byte <...
[ "def", "read_var_integer", "(", "data", ",", "offset", "=", "0", ")", "raise", "ArgumentError", ",", "\"data is nil.\"", "unless", "data", "packed", "=", "[", "data", "]", ".", "pack", "(", "'H*'", ")", "return", "[", "nil", ",", "0", "]", "if", "packe...
read variable integer @param [String] data reading data @param [Integer] offset the position when reading from data. @return [[Integer, Integer]] decoded integer value and the reading byte length. https://en.bitcoin.it/wiki/Protocol_documentation#Variable_length_integer
[ "read", "variable", "integer" ]
c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf
https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/util.rb#L127-L142
2,144
haw-itn/openassets-ruby
lib/openassets/util.rb
OpenAssets.Util.read_leb128
def read_leb128(data, offset = 0) bytes = [data].pack('H*').bytes result = 0 shift = 0 while true return [nil, offset] if bytes.length < 1 + offset byte = bytes[offset..(offset + 1)][0] result |= (byte & 0x7f) << shift break if byte & 0x80 == 0 shift += 7 ...
ruby
def read_leb128(data, offset = 0) bytes = [data].pack('H*').bytes result = 0 shift = 0 while true return [nil, offset] if bytes.length < 1 + offset byte = bytes[offset..(offset + 1)][0] result |= (byte & 0x7f) << shift break if byte & 0x80 == 0 shift += 7 ...
[ "def", "read_leb128", "(", "data", ",", "offset", "=", "0", ")", "bytes", "=", "[", "data", "]", ".", "pack", "(", "'H*'", ")", ".", "bytes", "result", "=", "0", "shift", "=", "0", "while", "true", "return", "[", "nil", ",", "offset", "]", "if", ...
read leb128 value @param [String] data reading data @param [Integer] offset start position when reading from data. @return [[Integer, Integer]] decoded integer value and the reading byte length.
[ "read", "leb128", "value" ]
c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf
https://github.com/haw-itn/openassets-ruby/blob/c2171ccb7e3bf2b8c712e9ef82a3bfaef3d1f4bf/lib/openassets/util.rb#L148-L161
2,145
mikerodrigues/arp_scan
lib/arp_scan/scan_report.rb
ARPScan.ScanReport.to_array
def to_array self.instance_variables.map do |var| if var == :@hosts self.instance_variable_get(var).map {|host| host.to_array} else self.instance_variable_get(var) end end end
ruby
def to_array self.instance_variables.map do |var| if var == :@hosts self.instance_variable_get(var).map {|host| host.to_array} else self.instance_variable_get(var) end end end
[ "def", "to_array", "self", ".", "instance_variables", ".", "map", "do", "|", "var", "|", "if", "var", "==", ":@hosts", "self", ".", "instance_variable_get", "(", "var", ")", ".", "map", "{", "|", "host", "|", "host", ".", "to_array", "}", "else", "self...
Create a new scan report, passing in every attribute. The best way to do this is with the ScanResultProcessor module. Returns an array representation of the ScanReport. Metadata about the scan, and an array of Host arrays comprise the array.
[ "Create", "a", "new", "scan", "report", "passing", "in", "every", "attribute", ".", "The", "best", "way", "to", "do", "this", "is", "with", "the", "ScanResultProcessor", "module", "." ]
c0fb8821ce9a08e43e74ed7d219b029c7b6c32c9
https://github.com/mikerodrigues/arp_scan/blob/c0fb8821ce9a08e43e74ed7d219b029c7b6c32c9/lib/arp_scan/scan_report.rb#L60-L68
2,146
greyblake/telebot
lib/telebot/client.rb
Telebot.Client.get_updates
def get_updates(offset: nil, limit: nil, timeout: nil) result = call(:getUpdates, offset: offset, limit: limit, timeout: timeout) result.map { |update_hash| Update.new(update_hash) } end
ruby
def get_updates(offset: nil, limit: nil, timeout: nil) result = call(:getUpdates, offset: offset, limit: limit, timeout: timeout) result.map { |update_hash| Update.new(update_hash) } end
[ "def", "get_updates", "(", "offset", ":", "nil", ",", "limit", ":", "nil", ",", "timeout", ":", "nil", ")", "result", "=", "call", "(", ":getUpdates", ",", "offset", ":", "offset", ",", "limit", ":", "limit", ",", "timeout", ":", "timeout", ")", "res...
Use this method to receive incoming updates using long polling. An Array of Update objects is returned. Note: 1. This method will not work if an outgoing webhook is set up. 2. In order to avoid getting duplicate updates, recalculate offset after each server response. @param offset [Integer] Identifier of the ...
[ "Use", "this", "method", "to", "receive", "incoming", "updates", "using", "long", "polling", ".", "An", "Array", "of", "Update", "objects", "is", "returned", "." ]
16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a
https://github.com/greyblake/telebot/blob/16c3f73ce47c2dc2480c23b3ef2cc8ee1f9cae4a/lib/telebot/client.rb#L50-L53
2,147
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
2,148
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
2,149
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
2,150
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
2,151
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
2,152
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
2,153
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
2,154
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
2,155
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
2,156
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
2,157
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
2,158
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
2,159
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
2,160
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
2,161
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
2,162
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
2,163
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
2,164
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
2,165
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
2,166
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
2,167
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
2,168
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
2,169
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
2,170
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
2,171
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
2,172
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
2,173
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
2,174
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
2,175
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
2,176
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
2,177
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", "# And some legacy data.", "options", "[", ":default_attributes", "]", ".", "update", "(", "default_attributes", ")", "option...
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
2,178
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", "# 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", "\"Pus...
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
2,179
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
2,180
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
2,181
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
2,182
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
2,183
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", "# Last block may be smaller", "extra", "=", "0", "if", "@completePieces", ".", "set?", "(", "@completePieces", ".", "length", "-", "1", ")", "num", "-=", "1", "extra", "=", "@last...
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
2,184
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
2,185
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", "#result = manager.n...
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
2,186
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
2,187
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
2,188
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
2,189
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
2,190
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
2,191
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
2,192
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
2,193
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
2,194
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
2,195
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
2,196
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
2,197
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
2,198
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", "# Don't allow read calls from timer handlers. This is to prevent a compl...
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
2,199
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