_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q200
Filegen.ErbGenerator.compile
train
def compile(source, destination) erb = ERB.new(source.read, nil, '-') begin destination.puts erb.result(data.instance_binding) rescue SyntaxError => e raise Exceptions::ErbTemplateHasSyntaxErrors, e.message end end
ruby
{ "resource": "" }
q201
ActsAsSolr.InstanceMethods.solr_save
train
def solr_save return true if indexing_disabled? if evaluate_condition(:if, self) debug "solr_save: #{self.class.name} : #{record_id(self)}" solr_add to_solr_doc solr_commit if configuration[:auto_commit] true else solr_destroy end end
ruby
{ "resource": "" }
q202
ActsAsSolr.InstanceMethods.to_solr_doc
train
def to_solr_doc debug "to_solr_doc: creating doc for class: #{self.class.name}, id: #{record_id(self)}" doc = Solr::Document.new doc.boost = validate_boost(configuration[:boost]) if configuration[:boost] doc << {:id => solr_id, solr_configuration[:type_field] => self.class.n...
ruby
{ "resource": "" }
q203
Typograf.Client.send_request
train
def send_request(text) params = { 'text' => text.encode("cp1251"), } params['xml'] = @xml if @xml request = Net::HTTP::Post.new(@url.path) request.set_form_data(params) begin response = Net::HTTP.new(@url.host, @url.port).start do |http| http.request(reques...
ruby
{ "resource": "" }
q204
ActsAsSolr.ActsMethods.acts_as_solr
train
def acts_as_solr(options={}, solr_options={}, &deferred_solr_configuration) $solr_indexed_models << self extend ClassMethods include InstanceMethods include CommonMethods include ParserMethods define_solr_configuration_methods acts_as_taggable_on :tags if options[:taggable]...
ruby
{ "resource": "" }
q205
JsonApiClient.Mapper.build_linked_resources_map
train
def build_linked_resources_map(data) data["linked"].each_with_object({}) do |(type, resources), obj| obj[type] ||= {} resources.each do |linked_resource| obj[type][linked_resource["id"]] = linked_resource end end end
ruby
{ "resource": "" }
q206
JsonApiClient.Mapper.build_link_type_map
train
def build_link_type_map(data) data["links"].each_with_object({}) do |(key, value), obj| association = key.split(".").last obj[association] = value["type"].pluralize end end
ruby
{ "resource": "" }
q207
Dk.TreeRunner.build_and_run_task
train
def build_and_run_task(task_class, params = nil) task_run = TaskRun.new(task_class, params) @task_run_stack.last.runs << task_run @task_run_stack.push(task_run) task = super(task_class, params) @task_run_stack.pop task end
ruby
{ "resource": "" }
q208
TinyCI.Runner.run!
train
def run! begin ensure_path target_path setup_log log_info "Commit: #{@commit}" log_info "Cleaning..." clean log_info "Exporting..." ensure_path export_path export begin load_config rescue ...
ruby
{ "resource": "" }
q209
TinyCI.Runner.instantiate_builder
train
def instantiate_builder klass = TinyCI::Builders.const_get(@config[:builder][:class]) klass.new(@config[:builder][:config].merge(target: export_path), logger: @logger) end
ruby
{ "resource": "" }
q210
TinyCI.Runner.instantiate_hooker
train
def instantiate_hooker return nil unless @config[:hooker].is_a? Hash klass = TinyCI::Hookers.const_get(@config[:hooker][:class]) klass.new(@config[:hooker][:config].merge(target: export_path), logger: @logger) end
ruby
{ "resource": "" }
q211
Grooveshark.Playlist.load_songs
train
def load_songs @songs = [] playlist = @client.request('getPlaylistByID', playlistID: @id) @songs = playlist['songs'].map! do |s| Song.new(s) end if playlist.key?('songs') @songs end
ruby
{ "resource": "" }
q212
AudioMonster.Monster.create_wav_wrapped_mpeg
train
def create_wav_wrapped_mpeg(mpeg_path, result_path, options={}) options.to_options! start_at = get_datetime_for_option(options[:start_at]) end_at = get_datetime_for_option(options[:end_at]) wav_wrapped_mpeg = NuWav::WaveFile.from_mpeg(mpeg_path) cart = wav_wrapped_mpeg.chunks[:cart] ...
ruby
{ "resource": "" }
q213
AudioMonster.Monster.run_command
train
def run_command(command, options={}) timeout = options[:timeout] || 7200 # default to adding a nice 13 if nothing specified nice = if options.key?(:nice) (options[:nice] == 'n') ? '' : "nice -n #{options[:nice]} " else 'nice -n 19 ' end echo_return = (options.key?(:...
ruby
{ "resource": "" }
q214
Emerson.Responder.key_for_primary
train
def key_for_primary @_key_for_primary ||= if options[:as] options[:as] else controller_name = controller.controller_name (resource.respond_to?(:each) ? controller_name : controller_name.singularize).intern end end
ruby
{ "resource": "" }
q215
Quora.Client.get
train
def get(field, filter = true) if field.nil? or !field.instance_of?(String) raise ArgumentError, "Field value must be a string" end resp = http.get("#{BASEPATH}?fields=#{field}", headers) data = resp.body[RESP_PREFIX.length..-1] data = JSON.parse(data) if filter && data.has_ke...
ruby
{ "resource": "" }
q216
Quora.Client.method_missing
train
def method_missing(method_id, *arguments, &block) if method_id.to_s =~ /^get_[\w]+/ self.class.send :define_method, method_id do field = method_id.to_s[4..-1] get(field) end self.send(method_id) else super end end
ruby
{ "resource": "" }
q217
UnionStationHooks.RequestReporter.log_controller_action_block
train
def log_controller_action_block(options = {}) if null? do_nothing_on_null(:log_controller_action_block) yield else build_full_controller_action_string(options) has_error = true begin_time = UnionStationHooks.now begin result = yield has_err...
ruby
{ "resource": "" }
q218
UnionStationHooks.RequestReporter.log_controller_action
train
def log_controller_action(options) return do_nothing_on_null(:log_controller_action) if null? Utils.require_key(options, :begin_time) Utils.require_key(options, :end_time) if options[:controller_name] build_full_controller_action_string(options) @transaction.message("Controller ...
ruby
{ "resource": "" }
q219
Zadt.Graph.remove_vertex
train
def remove_vertex(vertex) # The vertex must exist raise "not a vertex" unless vertex.is_a?(Vertex) if !vertex raise "Vertex does not exist" # The vertex must not be connected to anything elsif !vertex.connections.empty? raise "Vertex has edges. Break them first." # I...
ruby
{ "resource": "" }
q220
Zadt.Graph.make_connection
train
def make_connection(v1, v2) raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex) raise "already connected" if is_connected?(v1, v2) # Make new edge edge = Edge.new(v1, v2) # Connect the two using the vertex method "connect" v1.connect(v2, edge) v2.connect(v1, edge) ...
ruby
{ "resource": "" }
q221
Zadt.Graph.find_connection
train
def find_connection(v1, v2) raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex) raise "Vertices not connected" if !is_connected?(v1, v2) connection = v1.edges.select {|edge| edge.connection.include?(v2)} raise "Error finding connection" if connection.length > 1 connection.firs...
ruby
{ "resource": "" }
q222
Zadt.Graph.is_connected?
train
def is_connected?(v1, v2) raise "not a vertex" unless v1.is_a?(Vertex) && v2.is_a?(Vertex) v1.connections.include?(v2) end
ruby
{ "resource": "" }
q223
ActsAsSolr.ClassMethods.find_by_solr
train
def find_by_solr(query, options={}) data = parse_query(query, options) return parse_results(data, options) end
ruby
{ "resource": "" }
q224
ActsAsSolr.ClassMethods.rebuild_solr_index
train
def rebuild_solr_index(batch_size=300, options = {}, &finder) finder ||= lambda do |ar, sql_options| ar.all sql_options.merge!({:order => self.primary_key, :include => configuration[:solr_includes].keys}) end start_time = Time.now options[:offset] ||= 0 options[:threads] ||= 2 ...
ruby
{ "resource": "" }
q225
S3MetaSync.Syncer.delete_old_temp_folders
train
def delete_old_temp_folders path = File.join(Dir.tmpdir, STAGING_AREA_PREFIX + '*') day = 24 * 60 * 60 dirs = Dir.glob(path) dirs.select! { |dir| Time.now.utc - File.ctime(dir).utc > day } # only stale ones removed = dirs.each { |dir| FileUtils.rm_rf(dir) } log "Removed #{removed} ...
ruby
{ "resource": "" }
q226
Linkage.FieldSet.fetch_key
train
def fetch_key(key) string_key = key.to_s keys.detect { |k| k.to_s.casecmp(string_key) == 0 } end
ruby
{ "resource": "" }
q227
SimpleRecord.Translations.ruby_to_sdb
train
def ruby_to_sdb(name, value) return nil if value.nil? name = name.to_s # puts "Converting #{name} to sdb value=#{value}" # puts "atts_local=" + defined_attributes_local.inspect att_meta = get_att_meta(name) if value.is_a? Array ret = value.collect { |x| ruby_t...
ruby
{ "resource": "" }
q228
SimpleRecord.Translations.sdb_to_ruby
train
def sdb_to_ruby(name, value) # puts 'sdb_to_ruby arg=' + name.inspect + ' - ' + name.class.name + ' - value=' + value.to_s return nil if value.nil? att_meta = get_att_meta(name) if att_meta.options if att_meta.options[:encrypted] value = Translations.decrypt(value, att_me...
ruby
{ "resource": "" }
q229
FamilySearch.URLTemplate.head
train
def head(template_values) raise FamilySearch::Error::MethodNotAllowed unless allow.include?('head') template_values = validate_values(template_values) t = Addressable::Template.new(@template) url = t.expand(template_values).to_s @client.head url end
ruby
{ "resource": "" }
q230
PsUtilities.PreBuiltGet.get_one_student
train
def get_one_student(params) # api_path = "/ws/v1/district/student/{dcid}?expansions=school_enrollment,contact&q=student_username==xxxxxx237" ps_dcid = params[:dcid] || params[:dc_id] || params[:id] api_path = "/ws/v1/student/#{ps_dcid.to_i}" options = { query: { "ex...
ruby
{ "resource": "" }
q231
PsUtilities.PreBuiltGet.build_query
train
def build_query(params) query = [] query << "school_enrollment.enroll_status_code==#{params[:status_code]}" if params.has_key?(:status_code) query << "school_enrollment.enroll_status==#{params[:enroll_status]}" if params.has_key?(:enroll_status) query << "student_username==#{params[:username...
ruby
{ "resource": "" }
q232
TinyCI.Compactor.directories_to_compact
train
def directories_to_compact builds = Dir.entries builds_dir builds.select! {|e| File.directory? builds_dir(e) } builds.reject! {|e| %w{. ..}.include? e } builds.sort! builds = builds[0..-(@num_builds_to_leave+1)] builds.reject! {|e| @builds_to_leave.include?(e) || @builds_to_le...
ruby
{ "resource": "" }
q233
TinyCI.Compactor.compress_directory
train
def compress_directory(dir) File.open archive_path(dir), 'wb' do |oarchive_path| Zlib::GzipWriter.wrap oarchive_path do |gz| Gem::Package::TarWriter.new gz do |tar| Find.find "#{builds_dir}/"+dir do |f| relative_path = f.sub "#{builds_dir}/", "" mode = Fil...
ruby
{ "resource": "" }
q234
TinyCI.Subprocesses.execute
train
def execute(*command, label: nil) output, status = Open3.capture2(*command.flatten) log_debug caller[0] log_debug "CMD: #{command.join(' ')}" log_debug "OUT: #{output}" unless status.success? log_error output raise SubprocessError.new(label, command.join(' '),...
ruby
{ "resource": "" }
q235
TinyCI.Subprocesses.execute_pipe
train
def execute_pipe(*commands, label: nil) stdout, waiters = Open3.pipeline_r(*commands) output = stdout.read waiters.each_with_index do |waiter, i| status = waiter.value unless status.success? log_error output raise SubprocessError.new(label, commands[i].join('...
ruby
{ "resource": "" }
q236
TinyCI.Subprocesses.execute_stream
train
def execute_stream(*command, label: nil, pwd: nil) opts = {} opts[:chdir] = pwd unless pwd.nil? Open3.popen2e(command.join(' '), opts) do |stdin, stdout_and_stderr, wait_thr| stdin.close until stdout_and_stderr.closed? || stdout_and_stderr.eof? line = stdout_a...
ruby
{ "resource": "" }
q237
Borderlands.PropertyManager.property
train
def property(contractid, groupid, propertyid) begin property_hash = @client.get_json_body( "/papi/v0/properties/#{propertyid}", { 'contractId' => contractid, 'groupId' => groupid, }, ) rescue puts "# unable to retrieve property for (group=#{groupid},contract=#{con...
ruby
{ "resource": "" }
q238
Borderlands.PropertyManager.properties
train
def properties properties = [] contract_group_pairs.each do |cg| begin properties_hash = @client.get_json_body( "/papi/v0/properties/", { 'contractId' => cg[:contract], 'groupId' => cg[:group], } ) if properties_hash && properties_hash['propertie...
ruby
{ "resource": "" }
q239
Borderlands.PropertyManager.hostnames
train
def hostnames(property, skip_update_dns_status = false, version = nil) raise 'property must be a Borderlands::Property object' unless property.is_a? Property version ||= property.productionversion begin hostnames_hash = @client.get_json_body( "/papi/v0/properties/#{property.id}/versi...
ruby
{ "resource": "" }
q240
Borderlands.PropertyManager.ruletree
train
def ruletree(property,version = nil) raise 'property must be a Borderlands::Property object' unless property.is_a? Property version ||= property.productionversion tree = nil begin rt = @client.get_json_body( "/papi/v0/properties/#{property.id}/versions/#{version}/rules/", ...
ruby
{ "resource": "" }
q241
UnionStationHooks.SpecHelper.find_passenger_config
train
def find_passenger_config passenger_config = ENV['PASSENGER_CONFIG'] if passenger_config.nil? || passenger_config.empty? passenger_config = find_passenger_config_vendor || find_passenger_config_in_path end if passenger_config.nil? || passenger_config.empty? abort 'ERROR...
ruby
{ "resource": "" }
q242
UnionStationHooks.SpecHelper.undo_bundler
train
def undo_bundler clean_env = nil Bundler.with_clean_env do clean_env = ENV.to_hash end ENV.replace(clean_env) end
ruby
{ "resource": "" }
q243
UnionStationHooks.SpecHelper.write_file
train
def write_file(path, content) dir = File.dirname(path) if !File.exist?(dir) FileUtils.mkdir_p(dir) end File.open(path, 'wb') do |f| f.write(content) end end
ruby
{ "resource": "" }
q244
UnionStationHooks.SpecHelper.debug_shell
train
def debug_shell puts '------ Opening debug shell -----' @orig_dir = Dir.pwd begin if respond_to?(:prepare_debug_shell) prepare_debug_shell end system('bash') ensure Dir.chdir(@orig_dir) end puts '------ Exiting debug shell -----' end
ruby
{ "resource": "" }
q245
UnionStationHooks.SpecHelper.eventually
train
def eventually(deadline_duration = 3, check_interval = 0.05) deadline = Time.now + deadline_duration while Time.now < deadline if yield return else sleep(check_interval) end end raise 'Time limit exceeded' end
ruby
{ "resource": "" }
q246
UnionStationHooks.SpecHelper.should_never_happen
train
def should_never_happen(deadline_duration = 0.5, check_interval = 0.05) deadline = Time.now + deadline_duration while Time.now < deadline if yield raise "That which shouldn't happen happened anyway" else sleep(check_interval) end end end
ruby
{ "resource": "" }
q247
Runnable.ClassMethods.define_command
train
def define_command( name, opts = {}, &block ) blocking = opts[:blocking] || false log_path = opts[:log_path] || false commands[name] = { :blocking => blocking } define_method( name ) do |*args| if block run name, block.call(*args), log_path else run name, ni...
ruby
{ "resource": "" }
q248
Runnable.ClassMethods.method_missing
train
def method_missing( name, *opts ) raise NoMethodError.new( name.to_s ) unless name.to_s =~ /([a-z]*)_([a-z]*)/ # command_processors if $2 == "processors" commands[$1.to_sym][:outputs] = opts.first[:outputs] commands[$1.to_sym][:exceptions] = opts.first[:exceptions] end end
ruby
{ "resource": "" }
q249
Grooveshark.User.library_remove
train
def library_remove(song) fail ArgumentError, 'Song object required' unless song.is_a?(Song) req = { userID: @id, songID: song.id, albumID: song.album_id, artistID: song.artist_id } @client.request('userRemoveSongFromLibrary', req) end
ruby
{ "resource": "" }
q250
Grooveshark.User.get_playlist
train
def get_playlist(id) result = playlists.select { |p| p.id == id } result.nil? ? nil : result.first end
ruby
{ "resource": "" }
q251
Grooveshark.User.create_playlist
train
def create_playlist(name, description = '', songs = []) @client.request('createPlaylist', 'playlistName' => name, 'playlistAbout' => description, 'songIDs' => songs.map do |s| s.is_a?(Song) ? s.id : s.to_s ...
ruby
{ "resource": "" }
q252
Grooveshark.User.add_favorite
train
def add_favorite(song) song_id = song.is_a?(Song) ? song.id : song @client.request('favorite', what: 'Song', ID: song_id) end
ruby
{ "resource": "" }
q253
CrmFormatter.Phone.check_phone_status
train
def check_phone_status(hsh) phone = hsh[:phone] phone_f = hsh[:phone_f] status = 'invalid' status = phone != phone_f ? 'formatted' : 'unchanged' if phone && phone_f hsh[:phone_status] = status if status.present? hsh end
ruby
{ "resource": "" }
q254
Eluka.Model.add
train
def add (data, label) raise "No meaningful label associated with data" unless ([:positive, :negative].include? label) #Create a data point in the vector space from the datum given data_point = Eluka::DataPoint.new(data, @analyzer) #Add the data point to the feature space #Exp...
ruby
{ "resource": "" }
q255
Rex::SSLScan.Result.add_cipher
train
def add_cipher(version, cipher, key_length, status) unless @supported_versions.include? version raise ArgumentError, "Must be a supported SSL Version" end unless OpenSSL::SSL::SSLContext.new(version).ciphers.flatten.include?(cipher) || @deprecated_weak_ciphers.include?(cipher) raise ArgumentErro...
ruby
{ "resource": "" }
q256
BlueprintClient.AssetTypeTemplatesApi.add
train
def add(namespace, asset_type, template_body, opts = {}) data, _status_code, _headers = add_with_http_info(namespace, asset_type, template_body, opts) return data end
ruby
{ "resource": "" }
q257
BlueprintClient.AssetTypeTemplatesApi.delete
train
def delete(namespace, asset_type, opts = {}) data, _status_code, _headers = delete_with_http_info(namespace, asset_type, opts) return data end
ruby
{ "resource": "" }
q258
BlueprintClient.AssetTypeTemplatesApi.put
train
def put(namespace, asset_type, template_body, opts = {}) data, _status_code, _headers = put_with_http_info(namespace, asset_type, template_body, opts) return data end
ruby
{ "resource": "" }
q259
Log.ProgressBar.thr_msg
train
def thr_msg if @history.nil? @history ||= [[@ticks, Time.now] ] else @history << [@ticks, Time.now] max_history ||= case when @ticks > 20 count = @ticks - @last_count count = 1 if count == 0 ...
ruby
{ "resource": "" }
q260
Rex::SSLScan.Scanner.valid?
train
def valid? begin @host = Rex::Socket.getaddress(@host, true) rescue return false end @port.kind_of?(Integer) && @port >= 0 && @port <= 65535 && @timeout.kind_of?(Integer) end
ruby
{ "resource": "" }
q261
Rex::SSLScan.Scanner.scan
train
def scan scan_result = Rex::SSLScan::Result.new scan_result.openssl_sslv2 = sslv2 # If we can't get any SSL connection, then don't bother testing # individual ciphers. if test_ssl == :rejected and test_tls == :rejected return scan_result end threads = [] ciphers = Queue.new @s...
ruby
{ "resource": "" }
q262
Rex::SSLScan.Scanner.get_cert
train
def get_cert(ssl_version, cipher) validate_params(ssl_version,cipher) begin scan_client = Rex::Socket::Tcp.create( 'PeerHost' => @host, 'PeerPort' => @port, 'SSL' => true, 'SSLVersion' => ssl_version, 'SSLCipher' => cipher, 'Timeout' => @timeo...
ruby
{ "resource": "" }
q263
Rex::SSLScan.Scanner.validate_params
train
def validate_params(ssl_version, cipher) raise StandardError, "The scanner configuration is invalid" unless valid? unless @supported_versions.include? ssl_version raise StandardError, "SSL Version must be one of: #{@supported_versions.to_s}" end if ssl_version == :SSLv2 and sslv2 == false ra...
ruby
{ "resource": "" }
q264
UnionStationHooks.RequestReporter.log_user_activity_begin
train
def log_user_activity_begin(name) return do_nothing_on_null(:log_user_activity_begin) if null? id = next_user_activity_name @transaction.log_activity_begin(id, UnionStationHooks.now, name) id end
ruby
{ "resource": "" }
q265
UnionStationHooks.RequestReporter.log_user_activity_end
train
def log_user_activity_end(id, has_error = false) return do_nothing_on_null(:log_user_activity_end) if null? @transaction.log_activity_end(id, UnionStationHooks.now, has_error) end
ruby
{ "resource": "" }
q266
UnionStationHooks.RequestReporter.log_user_activity
train
def log_user_activity(name, begin_time, end_time, has_error = false) return do_nothing_on_null(:log_user_activity) if null? @transaction.log_activity(next_user_activity_name, begin_time, end_time, name, has_error) end
ruby
{ "resource": "" }
q267
UnionStationHooks.RequestReporter.log_exception
train
def log_exception(exception) transaction = @context.new_transaction( @app_group_name, :exceptions, @key) begin return do_nothing_on_null(:log_exception) if transaction.null? base64_message = exception.message base64_message = exception.to_s if base64_message....
ruby
{ "resource": "" }
q268
UnionStationHooks.RequestReporter.log_database_query
train
def log_database_query(options) return do_nothing_on_null(:log_database_query) if null? Utils.require_key(options, :begin_time) Utils.require_key(options, :end_time) Utils.require_non_empty_key(options, :query) name = options[:name] || 'SQL' begin_time = options[:begin_time] e...
ruby
{ "resource": "" }
q269
Linkage.Matcher.mean
train
def mean w = @comparators.collect { |comparator| comparator.weight || 1 } @score_set.open_for_reading @score_set.each_pair do |id_1, id_2, scores| sum = 0 scores.each do |key, value| sum += value * w[key-1] end mean = sum / @comparators.length.to_f if ...
ruby
{ "resource": "" }
q270
Finitio.SubType.dress
train
def dress(value, handler = DressHelper.new) # Check that the supertype is able to dress the value. # Rewrite and set cause to any encountered TypeError. uped = handler.try(self, value) do super_type.dress(value, handler) end # Check each constraint in turn constraints.each d...
ruby
{ "resource": "" }
q271
Quora.Auth.login
train
def login(user, password) endpoint = URI.parse(QUORA_URI) http = Net::HTTP.new(endpoint.host, endpoint.port) resp = http.get('/login/') cookie = resp["set-cookie"] # TODO: improve this rubbish # get formkey value start = resp.body.index("Q.formkey") formkey = resp.body[...
ruby
{ "resource": "" }
q272
ColumnPack.BinPacker.empty_space
train
def empty_space pack_all if @needs_packing max = @sizes.each.max space = 0 @sizes.each { |size| space += max - size } space end
ruby
{ "resource": "" }
q273
ColumnPack.BinPacker.tall_to_middle
train
def tall_to_middle if (@total_bins > 1) && ((@total_bins % 2) != 0) _, max_col = @sizes.each_with_index.max mid_col = @total_bins / 2 temp = @bins[mid_col].clone @bins[mid_col] = @bins[max_col] @bins[max_col] = temp end end
ruby
{ "resource": "" }
q274
PsUtilities.Connection.api
train
def api(verb, api_path, options={}) count = 0 retries = 3 ps_url = base_uri + api_path options = options.merge(headers) begin HTTParty.send(verb, ps_url, options) rescue Net::ReadTimeout, Net::OpenTimeout if count < retries count += 1 retry ...
ruby
{ "resource": "" }
q275
PsUtilities.Connection.authenticate
train
def authenticate ps_url = base_uri + auth_path response = HTTParty.post( ps_url, { headers: auth_headers, body: 'grant_type=client_credentials'} ) if response.code.to_s.eql? "200" @auth_info = response.parsed_response ...
ruby
{ "resource": "" }
q276
Levelup.Api.apps
train
def apps(app_id = nil) if app_id Endpoints::SpecificApp.new(app_id) else Endpoints::Apps.new(app_access_token) end end
ruby
{ "resource": "" }
q277
Levelup.Api.orders
train
def orders(order_uuid = nil) if order_uuid Endpoints::SpecificOrder.new(order_uuid) else Endpoints::Orders.new end end
ruby
{ "resource": "" }
q278
Kril.Consumer.consume_all
train
def consume_all(topic) config = @config.clone config[:group_id] = SecureRandom.uuid consumer = build_consumer(topic, true, config) consumer.each_message do |message| yield decode(message), consumer end ensure consumer.stop end
ruby
{ "resource": "" }
q279
SudoAttributes.ClassMethods.sudo_create!
train
def sudo_create!(attributes = nil, &block) if attributes.is_a?(Array) attributes.collect { |attr| sudo_create!(attr, &block) } else object = sudo_new(attributes) yield(object) if block_given? object.save! object end end
ruby
{ "resource": "" }
q280
Linkage.Field.ruby_type
train
def ruby_type unless @ruby_type hsh = case @schema[:db_type].downcase when /\A(medium|small)?int(?:eger)?(?:\((\d+)\))?( unsigned)?\z/o if !$1 && $2 && $2.to_i >= 10 && $3 # Unsigned integer type with 10 digits can potentially contain values which ...
ruby
{ "resource": "" }
q281
Crawler.Observer.update
train
def update(response, url) @log.puts "Scanning: #{url}" if response.kind_of?(Net::HTTPClientError) or response.kind_of?(Net::HTTPServerError) @log.puts "#{response.code} encountered for #{url}" end end
ruby
{ "resource": "" }
q282
Skyper.Skype.answer
train
def answer(call) cmd = "ALTER CALL #{call.call_id} ANSWER" r = Skype.send_command cmd raise RuntimeError("Failed to answer call. Skype returned '#{r}'") unless r == cmd end
ruby
{ "resource": "" }
q283
SimpleRecord.Attributes.get_attribute
train
def get_attribute(name) # puts "get_attribute #{name}" # Check if this arg is already converted name_s = name.to_s name = name.to_sym att_meta = get_att_meta(name) # puts "att_meta for #{name}: " + att_meta.inspect if att_meta && att_meta.type == :clob ret = @lobs[n...
ruby
{ "resource": "" }
q284
OodSupport.ACL.ordered_check
train
def ordered_check(**kwargs) entries.each do |entry| if entry.match(**kwargs) # Check if its an allow or deny acl entry (may not be both) return true if entry.is_allow? return false if entry.is_deny? end end return default # default allow o...
ruby
{ "resource": "" }
q285
UV.ScheduledEvent.inspect
train
def inspect insp = String.new("#<#{self.class}:#{"0x00%x" % (self.__id__ << 1)} ") insp << "trigger_count=#{@trigger_count} " insp << "config=#{info} " if self.respond_to?(:info, true) insp << "next_scheduled=#{to_time(@next_scheduled)} " insp << "last_schedul...
ruby
{ "resource": "" }
q286
UV.OneShot.update
train
def update(time) @last_scheduled = @reactor.now parsed_time = Scheduler.parse_in(time, :quiet) if parsed_time.nil? # Parse at will throw an error if time is invalid parsed_time = Scheduler.parse_at(time) - @scheduler.time_diff else ...
ruby
{ "resource": "" }
q287
UV.Repeat.update
train
def update(every, timezone: nil) time = Scheduler.parse_in(every, :quiet) || Scheduler.parse_cron(every, :quiet, timezone: timezone) raise ArgumentError.new("couldn't parse \"#{o}\"") if time.nil? @every = time reschedule end
ruby
{ "resource": "" }
q288
UV.Scheduler.every
train
def every(time) ms = Scheduler.parse_in(time) event = Repeat.new(self, ms) event.progress &Proc.new if block_given? schedule(event) event end
ruby
{ "resource": "" }
q289
UV.Scheduler.in
train
def in(time) ms = @reactor.now + Scheduler.parse_in(time) event = OneShot.new(self, ms) event.progress &Proc.new if block_given? schedule(event) event end
ruby
{ "resource": "" }
q290
UV.Scheduler.at
train
def at(time) ms = Scheduler.parse_at(time) - @time_diff event = OneShot.new(self, ms) event.progress &Proc.new if block_given? schedule(event) event end
ruby
{ "resource": "" }
q291
UV.Scheduler.cron
train
def cron(schedule, timezone: nil) ms = Scheduler.parse_cron(schedule, timezone: timezone) event = Repeat.new(self, ms) event.progress &Proc.new if block_given? schedule(event) event end
ruby
{ "resource": "" }
q292
UV.Scheduler.reschedule
train
def reschedule(event) # Check promise is not resolved return if event.resolved? @critical.synchronize { # Remove the event from the scheduled list and ensure it is in the schedules set if @schedules.include?(event) remove(event) ...
ruby
{ "resource": "" }
q293
UV.Scheduler.unschedule
train
def unschedule(event) @critical.synchronize { # Only call delete and update the timer when required if @schedules.include?(event) @schedules.delete(event) remove(event) check_timer end } ...
ruby
{ "resource": "" }
q294
UV.Scheduler.remove
train
def remove(obj) position = nil @scheduled.each_index do |i| # object level comparison if obj.equal? @scheduled[i] position = i break end end @scheduled.slice!(position) unless positi...
ruby
{ "resource": "" }
q295
UV.Scheduler.check_timer
train
def check_timer @reactor.update_time existing = @next schedule = @scheduled.first @next = schedule.nil? ? nil : schedule.next_scheduled if existing != @next # lazy load the timer if @timer.nil? new_timer ...
ruby
{ "resource": "" }
q296
UV.Scheduler.on_timer
train
def on_timer @critical.synchronize { schedule = @scheduled.shift @schedules.delete(schedule) schedule.trigger # execute schedules that are within 3ms of this event # Basic timer coalescing.. now = @reactor.now +...
ruby
{ "resource": "" }
q297
Stately.Core.stately
train
def stately(*opts, &block) options = opts.last.is_a?(Hash) ? opts.last : {} options[:attr] ||= :state @stately_machine = Stately::Machine.new(options[:attr], options[:start]) @stately_machine.instance_eval(&block) if block_given? include Stately::InstanceMethods end
ruby
{ "resource": "" }
q298
Dk.Runner.build_local_cmd
train
def build_local_cmd(task, cmd_str, input, given_opts) Local::Cmd.new(cmd_str, given_opts) end
ruby
{ "resource": "" }
q299
Dk.Runner.build_remote_cmd
train
def build_remote_cmd(task, cmd_str, input, given_opts, ssh_opts) Remote::Cmd.new(cmd_str, ssh_opts) end
ruby
{ "resource": "" }