idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
14,900
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 , nil , log_path end join if blocking e...
Create a user definde command
14,901
def method_missing ( name , * opts ) raise NoMethodError . new ( name . to_s ) unless name . to_s =~ / / if $2 == "processors" commands [ $1 . to_sym ] [ :outputs ] = opts . first [ :outputs ] commands [ $1 . to_sym ] [ :exceptions ] = opts . first [ :exceptions ] end end
Method missing processing for the command processors
14,902
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
Remove song from user library
14,903
def get_playlist ( id ) result = playlists . select { | p | p . id == id } result . nil? ? nil : result . first end
Get playlist by ID
14,904
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 end ) end
Create new user playlist
14,905
def add_favorite ( song ) song_id = song . is_a? ( Song ) ? song . id : song @client . request ( 'favorite' , what : 'Song' , ID : song_id ) end
Add song to favorites
14,906
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
COMPARE ORIGINAL AND FORMATTED PHONE
14,907
def add ( data , label ) raise "No meaningful label associated with data" unless ( [ :positive , :negative ] . include? label ) data_point = Eluka :: DataPoint . new ( data , @analyzer ) @fv_train . add ( data_point . vector , @labels [ label ] ) end
Initialize the classifier with sane defaults if customised data is not provided Adds a data point to the training data
14,908
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 Argu...
Adds the details of a cipher test to the Result object .
14,909
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
Configure a template for a given asset type
14,910
def delete ( namespace , asset_type , opts = { } ) data , _status_code , _headers = delete_with_http_info ( namespace , asset_type , opts ) return data end
Delete a template for a given asset type
14,911
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
update a template for a given asset type
14,912
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 if @max times = @max / count num = times / 20 num = 2 if num < 2 else num = 10 end count * num else 20 end max_histo...
def thr count = (
14,913
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
Initializes the scanner object
14,914
def scan scan_result = Rex :: SSLScan :: Result . new scan_result . openssl_sslv2 = sslv2 if test_ssl == :rejected and test_tls == :rejected return scan_result end threads = [ ] ciphers = Queue . new @supported_versions . each do | ssl_version | sslctx = OpenSSL :: SSL :: SSLContext . new ( ssl_version ) sslctx . ciphe...
Initiate the Scan against the target . Will test each cipher one at a time .
14,915
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' => @timeout ) cert = scan_client . peer_cert if cert . kind_of? O...
Retrieve the X509 Cert from the target service
14,916
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 raise StandardError , ...
Validates that the SSL Version and Cipher are valid both seperately and together as part of an SSL Context .
14,917
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
Logs the begin of a user - defined activity for display in the activity timeline .
14,918
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
Logs the end of a user - defined activity for display in the activity timeline .
14,919
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
Logs a user - defined activity for display in the activity timeline .
14,920
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 . empty? base64_message = Utils . base64 ( ...
Logs an exception that occurred during a request .
14,921
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 ] end_time = opt...
Logs a database query that was performed during the request .
14,922
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 mean >= @threshold changed notify_observ...
Combine scores for each pair of records via mean then compare the combined score to the threshold . Notify observers if there s a match .
14,923
def dress ( value , handler = DressHelper . new ) uped = handler . try ( self , value ) do super_type . dress ( value , handler ) end constraints . each do | constraint | next if constraint === uped msg = handler . default_error_message ( self , value ) if constraint . named? && constraints . size > 1 msg << " (not #{c...
Check that value can be uped through the supertype then verify all constraints . Raise an error if anything goes wrong .
14,924
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" ] start = resp . body . index ( "Q.formkey" ) formkey = resp . body [ start .. start + 200 ] . split ( "\"" ) [ 1 ] start = resp ...
login with Quora user and password
14,925
def empty_space pack_all if @needs_packing max = @sizes . each . max space = 0 @sizes . each { | size | space += max - size } space end
Total empty space left over by uneven packing .
14,926
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
moves the tallest bin to the middle
14,927
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 else { error : "no response (timeout) from URL: #{url}...
Direct API access
14,928
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 @auth_info [ 'token_expires' ] = Time . now + response . parsed_response [ 'expires_in...
gets API auth token and puts in header HASH for future requests with PS server
14,929
def apps ( app_id = nil ) if app_id Endpoints :: SpecificApp . new ( app_id ) else Endpoints :: Apps . new ( app_access_token ) end end
Generates an interface for the + apps + endpoint .
14,930
def orders ( order_uuid = nil ) if order_uuid Endpoints :: SpecificOrder . new ( order_uuid ) else Endpoints :: Orders . new end end
Generates the interface for the + orders + endpoint . Supply an order UUID if you would like to access endpoints for a specific order otherwise supply no parameters .
14,931
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
Consume all records from a topic . Each record will be yielded to block along with consumer instance . Will listen to topic after all records have been consumed .
14,932
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
Creates an object just like sudo_create but calls save! instead of save so an exception is raised if the record is invalid
14,933
def ruby_type unless @ruby_type hsh = case @schema [ :db_type ] . downcase when / \A \( \d \) \z /o if ! $1 && $2 && $2 . to_i >= 10 && $3 { :type => Bignum } else { :type => Integer } end when / \A \( \d \) \z /o { :type => schema [ :type ] == :boolean ? TrueClass : Integer } when / \A \( \d \) \z /o { :type => Bignum...
Returns a new instance of Field .
14,934
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
Creates a new Observer object Called by the Observable module through Webcrawler .
14,935
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
Answers a call given a skype Call ID . Returns an Array of Call objects .
14,936
def get_attribute ( name ) name_s = name . to_s name = name . to_sym att_meta = get_att_meta ( name ) if att_meta && att_meta . type == :clob ret = @lobs [ name ] if ret if ret . is_a? RemoteNil return nil else return ret end end unless new_record? if self . class . get_sr_config [ :single_clob ] begin single_clob = s3...
Since SimpleDB supports multiple attributes per value the values are an array . This method will return the value unwrapped if it s the only otherwise it will return the array .
14,937
def ordered_check ( ** kwargs ) entries . each do | entry | if entry . match ( ** kwargs ) return true if entry . is_allow? return false if entry . is_deny? end end return default end
Check each entry in order from array
14,938
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_scheduled=#{to_time(@last_scheduled)} created=#{to_time(...
Provide relevant inspect information
14,939
def update ( time ) @last_scheduled = @reactor . now parsed_time = Scheduler . parse_in ( time , :quiet ) if parsed_time . nil? parsed_time = Scheduler . parse_at ( time ) - @scheduler . time_diff else parsed_time += @last_scheduled end @next_scheduled = parsed_time @scheduler . reschedule ( self ) end
Updates the scheduled time
14,940
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
Update the time period of the repeating event
14,941
def every ( time ) ms = Scheduler . parse_in ( time ) event = Repeat . new ( self , ms ) event . progress & Proc . new if block_given? schedule ( event ) event end
Create a repeating event that occurs each time period
14,942
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
Create a one off event that occurs after the time period
14,943
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
Create a one off event that occurs at a particular date and time
14,944
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
Create a repeating event that uses a CRON line to determine the trigger time
14,945
def reschedule ( event ) return if event . resolved? @critical . synchronize { if @schedules . include? ( event ) remove ( event ) else @schedules << event end Bisect . insort ( @scheduled , event ) check_timer } end
Schedules an event for execution
14,946
def unschedule ( event ) @critical . synchronize { if @schedules . include? ( event ) @schedules . delete ( event ) remove ( event ) check_timer end } end
Removes an event from the schedule
14,947
def remove ( obj ) position = nil @scheduled . each_index do | i | if obj . equal? @scheduled [ i ] position = i break end end @scheduled . slice! ( position ) unless position . nil? end
Remove an element from the array
14,948
def check_timer @reactor . update_time existing = @next schedule = @scheduled . first @next = schedule . nil? ? nil : schedule . next_scheduled if existing != @next if @timer . nil? new_timer else @timer . stop end if not @next . nil? in_time = @next - @reactor . now if in_time > 3 @timer . start ( in_time ) else @time...
Ensures the current timer if any is still accurate by checking the head of the schedule
14,949
def on_timer @critical . synchronize { schedule = @scheduled . shift @schedules . delete ( schedule ) schedule . trigger now = @reactor . now + 3 while @scheduled . first && @scheduled . first . next_scheduled <= now schedule = @scheduled . shift @schedules . delete ( schedule ) schedule . trigger end check_timer } end
Is called when the libuv timer fires
14,950
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
Define a new Stately state machine .
14,951
def build_local_cmd ( task , cmd_str , input , given_opts ) Local :: Cmd . new ( cmd_str , given_opts ) end
input is needed for the TestRunner so it can use it with stubbing otherwise it is ignored when building a local cmd
14,952
def build_remote_cmd ( task , cmd_str , input , given_opts , ssh_opts ) Remote :: Cmd . new ( cmd_str , ssh_opts ) end
input and given opts are needed for the TestRunner so it can use it with stubbing otherwise they are ignored when building a remote cmd
14,953
def targets ( * names , & block ) if names . empty? UI . warning ( 'Book#targets to get all targets is deprecated, use #all_targets instead' , location : caller_locations . first ) return all_targets end names . map { | name | target ( name , & block ) } end
Defines several new targets with same configuration
14,954
def request ( api , args ) uri = api == :uploading ? UPLOAD_URI : API_URI args [ :method ] = "smugmug.#{api}" unless api == :uploading http = :: Net :: HTTP . new ( uri . host , uri . port , @http_proxy_host , @http_proxy_port , @http_proxy_user , @http_proxy_pass ) http . set_debug_output ( @config [ :debug_output ] )...
Creates a new HTTP wrapper to handle the network portions of the API requests
14,955
def sign_request ( method , uri , form_args ) args = { } if form_args form_args . each do | key , value | next unless value and value != "" key = key . to_s unless key . is_a? ( String ) args [ key ] = value end end args [ "oauth_version" ] = "1.0" args [ "oauth_consumer_key" ] = @config [ :api_key ] args [ "oauth_nonc...
Generates an OAuth signature and updates the args with the required fields
14,956
def get_user_by_id ( id ) resp = request ( 'getUserByID' , userID : id ) [ 'user' ] resp [ 'user_id' ] . nil? ? nil : User . new ( self , resp ) end
Find user by ID
14,957
def get_user_by_username ( name ) resp = request ( 'getUserByUsername' , username : name ) [ 'user' ] resp [ 'user_id' ] . nil? ? nil : User . new ( self , resp ) end
Find user by username
14,958
def popular_songs ( type = 'daily' ) fail ArgumentError , 'Invalid type' unless %w( daily monthly ) . include? ( type ) request ( 'popularGetSongs' , type : type ) [ 'songs' ] . map { | s | Song . new ( s ) } end
Get popular songs type = > daily monthly
14,959
def top_broadcasts ( count = 10 ) top_broadcasts = [ ] request ( 'getTopBroadcastsCombined' ) . each do | key , _val | broadcast_id = key . split ( ':' ) [ 1 ] top_broadcasts . push ( Broadcast . new ( self , broadcast_id ) ) count -= 1 break if count == 0 end top_broadcasts end
Get top broadcasts count = > specifies how many broadcasts to get
14,960
def search ( type , query ) results = [ ] search = request ( 'getResultsFromSearch' , type : type , query : query ) results = search [ 'result' ] . map do | data | next Song . new data if type == 'Songs' next Playlist . new ( self , data ) if type == 'Playlists' data end if search . key? ( 'result' ) results end
Perform search request for query
14,961
def get_stream_auth_by_songid ( song_id ) result = request ( 'getStreamKeyFromSongIDEx' , 'type' => 0 , 'prefetch' => false , 'songID' => song_id , 'country' => @country , 'mobile' => false ) if result == [ ] fail GeneralError , 'No data for this song. ' 'Maybe Grooveshark banned your IP.' end result end
Get stream authentication by song ID
14,962
def request ( method , params = { } , secure = false ) refresh_token if @comm_token url = "#{secure ? 'https' : 'http'}://grooveshark.com/more.php?#{method}" begin data = RestClient . post ( url , body ( method , params ) . to_json , 'Content-Type' => 'application/json' ) rescue StandardError => ex raise GeneralError ,...
Perform API request
14,963
def provider = ( sym ) klass = "#{sym.to_s.capitalize}Provider" begin java_import "de.schildbach.pte.#{klass}" @provider = Oeffi :: const_get ( klass ) . new rescue Exception => e raise "Unknown Provider name: #{klass}" end end
Configure a provider for the oeffi module
14,964
def check_addr_status ( hsh ) full_addr = hsh [ :full_addr ] full_addr_f = hsh [ :full_addr_f ] status = nil if full_addr && full_addr_f status = full_addr != full_addr_f ? 'formatted' : 'unchanged' end hsh [ :address_status ] = status hsh end
COMPARE ORIGINAL AND FORMATTED ADR
14,965
def make_full_address_original ( hsh ) full_adr = [ hsh [ :street ] , hsh [ :city ] , hsh [ :state ] , hsh [ :zip ] ] . compact . join ( ', ' ) full_adr end
FORMAT FULL ADDRESS
14,966
def add ( name , options ) fail ArgumentError , "A view hook '#{name}' already exists" if @hooks [ name ] context = options . delete ( :context ) hook = @hooks [ name ] = Hook . new ( name , context , options ) hook . apply! if @applied end
Registers a new view hook
14,967
def add_node ( namespace_inc_global , body , opts = { } ) data , _status_code , _headers = add_node_with_http_info ( namespace_inc_global , body , opts ) return data end
Add a node
14,968
def delete_node ( namespace , id , type , opts = { } ) delete_node_with_http_info ( namespace , id , type , opts ) return nil end
Delete a node
14,969
def get_node ( namespace , id , type , opts = { } ) data , _status_code , _headers = get_node_with_http_info ( namespace , id , type , opts ) return data end
Get details of a given node
14,970
def replace_node ( namespace , id , body , type , opts = { } ) data , _status_code , _headers = replace_node_with_http_info ( namespace , id , body , type , opts ) return data end
Replaces the node with the data sent in the body
14,971
def update_node ( namespace , id , body , type , opts = { } ) data , _status_code , _headers = update_node_with_http_info ( namespace , id , body , type , opts ) return data end
Perform a partial update of a node
14,972
def install if cached? Dir . chdir ( cache_path ) do hg %|pull| end else FileUtils . mkdir_p ( cache_path ) Dir . chdir ( cache_path ) do hg %|clone #{uri} .| end end Dir . chdir ( cache_path ) do hg %|update --clean --rev #{revision || ref}| @revision ||= hg %|id -i| end copy_path = rel ? cache_path . join ( rel ) : c...
Download the cookbook from the remote hg repository
14,973
def hg ( command , error = true ) unless Berkshelf . which ( 'hg' ) || Berkshelf . which ( 'hg.exe' ) raise HgNotInstalled . new end Berkshelf . log . debug ( "Running:hg #{command}" ) response = shell_out ( %|hg #{command}| ) Berkshelf . log . debug ( "response:hg #{response.stdout}" ) if response . error? raise HgCom...
Perform a mercurial command .
14,974
def cache_path Pathname . new ( Berkshelf . berkshelf_path ) . join ( '.cache' , 'hg' , Digest :: SHA1 . hexdigest ( uri ) ) end
The path where this hg repository is cached .
14,975
def create if env [ 'warden' ] . authenticate ( :password , :scope => :user ) render json : current_user , status : :created else render json : { errors : { user : [ "Invalid email or password" ] } } , status : :unprocessable_entity end end
create the session for the user using the password strategy and returning the user JSON
14,976
def delete user = Cadenero :: User . find_by_id ( params [ :id ] ) if user_signed_in? env [ 'warden' ] . logout ( :user ) render json : { message : "Successful logout" } , status : :ok else render json : { message : "Unsuccessful logout user with id" } , status : :forbidden end end
destroy the session for the user using params id
14,977
def file_exists? ( file_path ) if @site . respond_to? ( :in_source_dir ) File . exist? @site . in_source_dir ( file_path ) else File . exist? Bunto . sanitized_path ( @site . source , file_path ) end end
Checks if a file already exists in the site source
14,978
def internal_preview @preview_context = :: RiddlerAdmin :: PreviewContext . find_by_id params [ "pctx_id" ] if @preview_context . nil? render ( status : 400 , json : { message : "Invalid pctx_id" } ) and return end @use_case = :: Riddler :: UseCases :: AdminPreviewStep . new @step . definition_hash , preview_context_da...
Should always comes from the admin tool
14,979
def write_config_file return unless config_file File . open ( config_file , 'w' ) do | f | f . puts ( data . delete_if { | _ , v | v . nil? } . to_yaml ) end end
Write config data to config file .
14,980
def symbolise ( data ) return { } unless data Hash [ data . map { | k , v | [ k . to_sym , v ] } ] end
Symbolizes keys . Changes database key to database_dir .
14,981
def defaults { num_threads : 1 , mafft_threads : 1 , port : 5678 , ssl : false , host : '0.0.0.0' , serve_public_dir : File . join ( Dir . home , '.genevalidatorapp/' ) , max_characters : 'undefined' } end
Default configuration data .
14,982
def trustlines data = RippleRest . get ( "v1/accounts/#{@address}/trustlines" ) [ "trustlines" ] . map ( & Trustline . method ( :new ) ) obj = Trustlines . new data obj . account = self obj end
Returns a Trustlines object for this account .
14,983
def settings data = RippleRest . get ( "v1/accounts/#{@address}/settings" ) [ "settings" ] obj = AccountSettings . new data obj . account = self obj end
Returns a AccountSettings object for this account .
14,984
def payments payments ||= lambda { obj = Payments . new obj . account = self obj } . call end
Returns a Payments object for this account .
14,985
def find_path destination_account , destination_amount , source_currencies = nil uri = "v1/accounts/#{account.address}/payments/paths/#{destination_account.to_s}/#{destination_amount.to_s}" if source_currencies cur = source_currencies . join ( "," ) uri += "?source_currencies=#{cur}" end RippleRest . get ( uri ) [ "pay...
Query rippled for possible payment paths through the Ripple Network to deliver the given amount to the specified destination_account . If the destination_amount issuer is not specified paths will be returned for all of the issuers from whom the destination_account accepts the given currency .
14,986
def create destination_account , destination_amount payment = Payment . new payment . account = account payment . destination_account = destination_account . to_s payment . destination_amount = Amount . from_string ( destination_amount ) payment end
Create a Payment object with some field filled .
14,987
def query options = { } qs = "" if options && options . size > 0 qs = "?" + options . map { | k , v | "#{k}=#{CGI::escape(v.to_s)}" } . join ( '&' ) end uri = "v1/accounts/#{account.address}/payments#{qs}" RippleRest . get ( uri ) [ "payments" ] . map do | i | payment = Payment . new ( i [ "payment" ] ) payment . clien...
Browse historical payments in bulk .
14,988
def handle_options drivers = :: QUnited :: Driver . constants . reject { | d | d == :Base } valid_drivers_string = "Valid drivers include: #{drivers.map { |d| d.to_s }.join(', ')}" args_empty = ARGV . empty? double_dash_neg_index = ARGV . find_index ( '--' ) && ( ARGV . find_index ( '--' ) - ARGV . size ) optparse = Op...
Parse and handle command line options
14,989
def image_asset ( object , args = { } ) return if object . try ( :file ) . nil? && args [ :object ] . nil? opts = { :alt => '' , :video_dimensions => '500x350' , :encode => :png } . merge ( args ) opts [ :alt ] = escape_javascript ( object . title ) if object . respond_to? ( 'title' ) if opts [ :object ] attachment = o...
Returns image tag for an object s attachment with optional link element wrapped around it .
14,990
def get ( namespace , asset_type , opts = { } ) data , _status_code , _headers = get_with_http_info ( namespace , asset_type , opts ) return data end
get a template for a given asset type
14,991
def measure clusters silhouettes = [ ] average_distances = [ ] main_cluster . points . each do | point1 | a1 = calculate_a1 ( point1 ) ( clusters - [ main_cluster ] ) . each do | cluster | distances = [ ] cluster . points . each do | point2 | distances << euclidean_distance ( point1 , point2 ) . round ( 2 ) end average...
Measures the silhouette coefficient of a cluster compared to all other clusters Returns the average silhouette coefficient of a cluster
14,992
def calculate_a1 point distances = [ ] main_cluster . points . each do | point1 | distances << euclidean_distance ( point , point1 ) . round ( 2 ) end return 0 if distances . size == 1 ( distances . inject ( :+ ) / ( distances . size - 1 ) ) . round ( 2 ) end
Calculates the a1 value of a cluster
14,993
def get_solr_field_type ( field_type ) if field_type . is_a? ( Symbol ) t = TypeMapping [ field_type ] raise "Unknown field_type symbol: #{field_type}" if t . nil? t elsif field_type . is_a? ( String ) return field_type else raise "Unknown field_type class: #{field_type.class}: #{field_type}" end end
Converts field types into Solr types
14,994
def solr_add ( add_xml ) ActsAsSolr :: Post . execute ( Solr :: Request :: AddDocument . new ( add_xml ) ) end
Sends an add command to Solr
14,995
def solr_delete ( solr_ids ) ActsAsSolr :: Post . execute ( Solr :: Request :: Delete . new ( :id => solr_ids ) ) end
Sends the delete command to Solr
14,996
def build_ssh_cmd_str ( cmd_str , host , args , host_args ) Dk :: Remote . ssh_cmd_str ( cmd_str , host , args , host_args ) end
escape everything properly ; run in sh to ensure full profile is loaded
14,997
def files_array ( files ) return [ ] unless files files . is_a? ( Array ) ? files : pattern_to_filelist ( files . to_s ) end
Force convert to array of files if glob pattern
14,998
def introspect iface = Hash . new pin = Hash . new meth = Array . new if self . respond_to? ( :read ) meth << "read" end if self . respond_to? ( :write ) meth << "write" end iface [ @interface ] = meth pin [ @name ] = iface return pin end
Return introspect object that can be delivered to openplacos server
14,999
def << ( pin_ ) if pin_ . kind_of? ( Input ) @inputs << pin_ elsif pin_ . kind_of? ( Output ) @outputs << pin_ elsif pin_ . kind_of? ( Array ) pin_ . each { | p | self << p } end pin_ . set_component ( self ) end
Push pin to component