idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
14,400
def on_connection ( selector = nil , & block ) if selector . nil? || selector == '*' instance_eval ( & block ) else @current_connection = ConnectionScript . new instance_eval ( & block ) @connections << [ selector , @current_connection ] @current_connection = nil end end
Configuration API Specifies behavior to run for specific connections based on the id number assigned to that connection . Connection ids are 1 - based .
14,401
def add_command ( command = nil , & block ) command = Commands :: Command . new ( & block ) if block_given? current_connection . add_command ( command ) end
Not really part of the public API but users could use this to implement their own fancy command
14,402
def create_record attributes creator = @creator_class . new attributes , @context FactoryGirl . create @clazz . name . underscore . to_sym , creator . factorygirl_attributes end
Creates a new record with the given attributes in the database
14,403
def get_next_job_to_run ( targets_still_building ) targets_not_built_yet = targets_still_building + @jobs . keys side_effects = targets_not_built_yet . map do | target | @side_effects [ target ] || [ ] end . flatten targets_not_built_yet += side_effects @jobs . keys . each do | target | skip = false ( @jobs [ target ] ...
Get the next job that is ready to run from the JobSet .
14,404
def ask_stage question = I18n . t :ask_stage_name , scope : :negroku stage_name = Ask . input question raise "Stage name required" if stage_name . empty? stage_name end
Ask the stage name
14,405
def if_debug ( minimum = 1 , else_block = nil ) $CHEF_WORKFLOW_DEBUG ||= ENV . has_key? ( "CHEF_WORKFLOW_DEBUG" ) ? ENV [ "CHEF_WORKFLOW_DEBUG" ] . to_i : CHEF_WORKFLOW_DEBUG_DEFAULT if $CHEF_WORKFLOW_DEBUG >= minimum yield if block_given? elsif else_block else_block . call end end
Conditionally executes based on the level of debugging requested .
14,406
def read_inbound_data ZMachine . logger . debug ( "zmachine:tcp_msg_channel:#{__method__}" , channel : self ) if ZMachine . debug raise IOException . new ( "EOF" ) if @socket . read ( @buffer ) == - 1 pos = @buffer . position @buffer . flip if @buffer . remaining >= 4 bytes = java . util . Arrays . copyOfRange ( @buffe...
return nil if no addional data is available
14,407
def validate_attributes! self . class . required_attributes . each do | matcher | matched = self . attributes . any? do | key , value | key = key . to_s Rxhp :: AttributeValidator . match? matcher , key , value end if ! matched raise MissingRequiredAttributeError . new ( self , matcher ) end end return true if self . a...
Check if attributes are valid and raise an exception if they re not .
14,408
def render options = { } validate! options = fill_options ( options ) open = render_open_tag ( options ) inner = render_children ( options ) close = render_close_tag ( options ) if options [ :pretty ] indent = ' ' * ( options [ :indent ] * options [ :depth ] ) out = indent . dup out << open << "\n" out << inner if inne...
Render the element .
14,409
def render_string string , options escaped = html_escape ( string ) if options [ :pretty ] indent = ' ' * ( options [ :indent ] * options [ :depth ] ) indent + escaped + "\n" else escaped end end
html - escape a string paying attention to indentation too .
14,410
def render_open_tag options out = '<' + tag_name unless attributes . empty? attributes . each do | name , value | name = name . to_s . gsub ( '_' , '-' ) if name . is_a? Symbol value = value . to_s . gsub ( '_' , '-' ) if value . is_a? Symbol case value when false next when true if options [ :format ] == Rxhp :: XHTML_...
Render the opening tag .
14,411
def render_children options = { } return if children . empty? flattened_children . map { | child | render_child ( child , options ) } . join end
Iterate over all the children calling render .
14,412
def fill_options options { :pretty => true , :format => Rxhp :: HTML_FORMAT , :skip_doctype => false , :doctype => Rxhp :: HTML_5 , :depth => 0 , :indent => 2 , } . merge ( options ) end
Fill default render options .
14,413
def flattened_children no_frags = [ ] children . each do | node | if node . is_a? Rxhp :: Fragment no_frags += node . children else no_frags . push node end end previous = nil no_consecutive_strings = [ ] no_frags . each do | node | if node . is_a? ( String ) && previous . is_a? ( String ) previous << node else no_cons...
Normalize the children .
14,414
def render options = { } validate! self . compose do self . children . each do | child | fragment child end end . render ( options ) end
You don t want to implement this function in your subclasses - just reimplement compose instead .
14,415
def bind ( address , port_or_type , & block ) ZMachine . logger . debug ( "zmachine:connection:#{__method__}" , connection : self ) if ZMachine . debug klass = channel_class ( address ) @channel = klass . new @channel . bind ( sanitize_adress ( address , klass ) , port_or_type ) @block = block @block . call ( self ) if...
channel type dispatch
14,416
def usage ( start_time , end_time , period = '' ) params = { start : start_time , end : end_time } params . merge! ( period : period ) unless period . empty? DataSift . request ( :GET , 'account/usage' , @config , params ) end
Check your account usage for a given period and timeframe
14,417
def locate_input_element ( how , what , types , value = nil ) @browser . locate_input_element ( how , what , types , value ) end
Returns the specified ole object for input elements on a web page .
14,418
def click_button_with_caption ( caption , opts = { } ) all_buttons = button_elements matching_buttons = all_buttons . select { | x | x . attribute ( 'value' ) == caption } if matching_buttons . size > 0 if opts && opts [ :index ] the_index = opts [ :index ] . to_i ( ) - 1 puts "Call matching buttons: #{matching_buttons...
Click a button with caption
14,419
def submit ( buttonName = nil ) if ( buttonName . nil? ) then buttons . each { | button | next if button . type != 'submit' button . click return } else click_button_with_name ( buttonName ) end end
submit first submit button
14,420
def watch_request ( titles , unwatch = false ) titles = titles . is_a? ( Array ) ? titles : [ titles ] params = { action : 'watch' , titles : titles . shift ( get_limited ( titles . length , 50 , 500 ) ) . join ( '|' ) , token : get_token ( 'watch' ) } success_key = 'watched' if unwatch params [ :unwatch ] = 1 success_...
Submits a watch action request .
14,421
def failsafe ( & block ) begin yield rescue RWebSpec :: Assertion => e1 rescue ArgumentError => ae rescue RSpec :: Expectations :: ExpectationNotMetError => ree rescue => e end end
try operation ignore if errors occur
14,422
def random_string_in ( arr ) return nil if arr . empty? index = random_number ( 0 , arr . length - 1 ) arr [ index ] end
Return a random string in a rangeof pre - defined strings
14,423
def interpret_value ( value ) case value when Array then value . rand when Range then value_in_range ( value ) else value end end
If an array or range is passed a random value will be selected to match . All other values are simply returned .
14,424
def process_each_row_in_csv_file ( csv_file , & block ) require 'faster_csv' connect_to_testwise ( "CSV_START" , csv_file ) if $testwise_support has_error = false idx = 0 FasterCSV . foreach ( csv_file , :headers => :first_row , :encoding => 'u' ) do | row | connect_to_testwise ( "CSV_ON_ROW" , idx . to_s ) if $testwis...
Data Driven Tests
14,425
def top_crashes ( version , build ) @version = version @build = build @crashes = @crash_source . crashes ( @top , version , build , @show_only_unresolved ) @total_crashes = @crash_source . crash_count ( version : @version , build : @build ) report end
returns list of top crashes for the given build
14,426
def attach_browser ( how , what , options = { } ) options . merge! ( :browser => is_firefox? ? "Firefox" : "IE" ) unless options [ :browser ] begin options . merge! ( :base_url => browser . context . base_url ) rescue => e puts "failed to set base_url, ignore : #{e}" end WebBrowser . attach_browser ( how , what , optio...
Attach to existing browser window
14,427
def enter_text_with_id ( textfield_id , value , opts = { } ) if opts . nil? || opts . empty? opts [ :appending ] = false end perform_operation { begin text_field ( :id , textfield_id ) . set ( value ) rescue => e the_elem = element ( :xpath , "//input[@id='#{textfield_id}']" ) the_elem . send_keys ( :clear ) unless opt...
for text field can be easier to be identified by attribute id instead of name not recommended though
14,428
def absolutize_page ( content , base_url , current_url_parent ) modified_content = "" content . each_line do | line | if line =~ / \s /i then script_src = $1 substitute_relative_path_in_src_line ( line , script_src , base_url , current_url_parent ) elsif line =~ / \s /i then link_href = $1 substitute_relative_path_in_s...
Return page HTML with absolute references of images stylesheets and javascripts
14,429
def absolutize_page_hpricot ( content , base_url , parent_url ) return absolutize_page ( content , base_url , parent_url ) if RUBY_PLATFORM == 'java' begin require 'hpricot' doc = Hpricot ( content ) base_url . slice! ( - 1 ) if ends_with? ( base_url , "/" ) ( doc / 'link' ) . each { | e | e [ 'href' ] = absolutify_url...
absolutize_page using hpricot
14,430
def wait_for_element ( element_id , timeout = $testwise_polling_timeout , interval = $testwise_polling_interval ) start_time = Time . now until @web_browser . element_by_id ( element_id ) do sleep ( interval ) if ( Time . now - start_time ) > timeout raise RuntimeError , "failed to find element: #{element_id} for max #...
Wait the element with given id to be present in web page
14,431
def clear_popup ( popup_win_title , seconds = 10 , yes = true ) if is_windows? sleep 1 autoit = WIN32OLE . new ( 'AutoItX3.Control' ) ret = autoit . WinWait ( popup_win_title , '' , seconds ) if ret == 1 then puts "about to send click Yes" if debugging? button_id = yes ? "Button1" : "Button2" autoit . ControlClick ( po...
Clear popup windows such as Security Alert or Security Information popup window
14,432
def basic_authentication_ie ( title , username , password , options = { } ) default_options = { :textctrl_username => "Edit2" , :textctrl_password => "Edit3" , :button_ok => 'Button1' } options = default_options . merge ( options ) title ||= "" if title =~ / \s / full_title = title else full_title = "Connect to #{title...
Use AutoIT3 to send password title starts with Connect to ...
14,433
def presenter @presenter ||= begin controller = self klass = MetaPresenter :: Builder . new ( controller , action_name ) . presenter_class klass . new ( controller ) end end
Initialize presenter with the current controller
14,434
def create ( identity_id = '' , service = '' , token = '' ) fail BadParametersError , 'identity_id is required' if identity_id . empty? fail BadParametersError , 'service is required' if service . empty? fail BadParametersError , 'token is required' if token . empty? params = { service : service , token : token } DataS...
Creates a new Identity Token
14,435
def list ( identity_id = '' , per_page = '' , page = '' ) params = { identity_id : identity_id } requires params params . merge! ( per_page : per_page ) unless per_page . empty? params . merge! ( page : page ) unless page . empty? DataSift . request ( :GET , "account/identity/#{identity_id}/token" , @config , params ) ...
Returns a list of Tokens for a given Identity
14,436
def emitIzPackXML ( xm ) xm . pack ( @attributes ) { xm . description ( @description ) @files . each { | src , dest | xm . singlefile ( 'src' => src , 'target' => dest ) } } end
collect the XML representation for the pack using an XMLMarkup object
14,437
def create_from ( file_map ) @izpackVersion ||= '4.3.5' @appName ||= project . id @izpackBaseDir = File . dirname ( @output ) if ! @izpackBaseDir @installerType ||= 'standard' @inheritAll ||= 'true' @compression ||= 'deflate' @compressionLevel ||= '9' @locales ||= [ 'eng' ] @panels ||= [ 'TargetPanel' , 'InstallPanel' ...
The ArchiveTask class delegates this method so we can create the archive . the file_map is the result of the computations of the include and exclude filters .
14,438
def first_image ( obj , options = { } ) opts = { collection : :images , method : :image , style : :thumbnail , default : image_path ( 'noimage.jpg' ) } . merge ( options . symbolize_keys! ) image = obj . send ( opts [ :collection ] ) . first image ? image . send ( opts [ :method ] ) . url ( opts [ :style ] ) : opts [ :...
eg . first_image (
14,439
def human ( object ) if object . is_a? ( Date ) object . strftime ( '%B %d, %Y' ) elsif object . is_a? ( Time ) object . strftime ( '%B %d, %Y at %I:%M %p' ) elsif object . is_a? ( String ) object . humanize else object end end
humanizing various things
14,440
def mean_squared_error return @mean_squared_error if @mean_squared_error numerator = errors . drop ( @seasonality_strategy . start_index ) . map { | i | i ** 2 } . inject ( & :+ ) @mean_squared_error = numerator / ( errors . size - @seasonality_strategy . start_index ) . to_f end
Returns the mean squared error of the forecast .
14,441
def add ( id , resources , validate = 'true' ) params = { id : id , resources : resources , validate : validate } requires params DataSift . request ( :PUT , 'source/resource/add' , @config , params ) end
Add resources to a Managed Source
14,442
def remove ( id , resource_ids ) params = { id : id , resource_ids : resource_ids } requires params DataSift . request ( :PUT , 'source/resource/remove' , @config , params ) end
Remove resources from a Managed Source
14,443
def add ( id , auth , validate = 'true' ) params = { id : id , auth : auth , validate : validate } requires params DataSift . request ( :PUT , 'source/auth/add' , @config , params ) end
Add auth tokens to a Managed Source
14,444
def remove ( id , auth_ids ) params = { id : id , auth_ids : auth_ids } requires params DataSift . request ( :PUT , 'source/auth/remove' , @config , params ) end
Remove auth tokens from a Managed Source
14,445
def login ( username , password ) assertion_value = @assertion . clone @assertion = nil params = { action : 'login' , lgname : username , lgpassword : password , lgtoken : get_token ( 'login' ) } response = post ( params ) @assertion = assertion_value result = response [ 'login' ] [ 'result' ] if result == 'Success' @n...
Logs the user into the wiki . This is generally required for editing and getting restricted data .
14,446
def create_account ( username , password , language = 'en' , reason = nil ) params = { name : username , password : password , language : language , token : get_token ( 'createaccount' ) } params [ :reason ] = reason unless reason . nil? result = post ( params ) unless result [ 'error' ] . nil? raise MediaWiki :: Butt ...
Creates an account using the standard procedure .
14,447
def create_account_email ( username , email , language = 'en' , reason = nil ) params = { name : username , email : email , mailpassword : 'value' , language : language , token : get_token ( 'createaccount' ) } params [ :reason ] = reason unless reason . nil? result = post ( params ) unless result [ 'error' ] . nil? ra...
Creates an account using the random password sent by email procedure .
14,448
def save_current_page ( options = { } ) default_options = { :replacement => true } options = default_options . merge ( options ) to_dir = options [ :dir ] || default_dump_dir if options [ :filename ] file_name = options [ :filename ] else file_name = Time . now . strftime ( "%m%d%H%M%S" ) + ".html" end Dir . mkdir ( to...
For current page souce to a file in specified folder for inspection
14,449
def wait_until ( timeout = $testwise_polling_timeout || 30 , polling_interval = $testwise_polling_interval || 1 , & block ) end_time = :: Time . now + timeout until :: Time . now > end_time result = nil begin result = yield ( self ) return result if result rescue => e end sleep polling_interval end raise TimeoutError ,...
= Convenient functions
14,450
def block ( user , expiry = '2 weeks' , reason = nil , nocreate = true ) params = { action : 'block' , user : user , expiry : expiry } token = get_token params [ :reason ] = reason if reason params [ :nocreate ] = '1' if nocreate params [ :token ] = token response = post ( params ) if response . key? ( 'error' ) raise ...
Blocks the user .
14,451
def unblock ( user , reason = nil ) params = { action : 'unblock' , user : user } token = get_token params [ :reason ] = reason if reason params [ :token ] = token response = post ( params ) if response . key? ( 'error' ) raise MediaWiki :: Butt :: BlockError . new ( response . dig ( 'error' , 'code' ) || 'Unknown erro...
Unblocks the user .
14,452
def parse_message ( contact ) header = contact [ 0 ] body = contact [ 1 , contact . count ] items = process_item_body ( body ) combine_header_with_transmission ( items , header ) end
Pare one DS segment
14,453
def merge ( ds , measurement , cardinality ) m = ds . select { | k , v | k != :measurements and k != :errors and k != :warn } m = m . merge ( measurement ) m = m . merge ( { technology : "argos" , type : type , cardinality : cardinality } ) idbase = m . clone idbase . delete :errors idbase . delete :file idbase . delet...
Merges a DS header hash into each measurement
14,454
def create ( identity_id = '' , service = '' , total_allowance = nil , analyze_queries = nil ) fail BadParametersError , 'identity_id is required' if identity_id . empty? fail BadParametersError , 'service is required' if service . empty? fail BadParametersError , 'Must set total_allowance or analyze_queries' if total_...
Creates a Limit for an Identity
14,455
def get ( identity_id = '' , service = '' ) fail BadParametersError , 'identity_id is required' if identity_id . empty? fail BadParametersError , 'service is required' if service . empty? DataSift . request ( :GET , "account/identity/#{identity_id}/limit/#{service}" , @config ) end
Get the Limit for a given Identity and Service
14,456
def list ( service = '' , per_page = '' , page = '' ) fail BadParametersError , 'service is required' if service . empty? params = { } params [ :per_page ] = per_page unless per_page . empty? params [ :page ] = page unless page . empty? DataSift . request ( :GET , "account/identity/limit/#{service}" , @config , params ...
Returns a list Identities and their Limits for a given Service
14,457
def delete ( identity_id = '' , service = '' ) fail BadParametersError , 'identity_id is required' if identity_id . empty? fail BadParametersError , 'service is required' if service . empty? DataSift . request ( :DELETE , "account/identity/#{identity_id}/limit/#{service}" , @config ) end
Removes a Service Limit for an Identity
14,458
def generate if @yaml . has_key? ( "version" ) @yaml = @yaml . fetch ( "services" ) end containers = @yaml . map do | name , fields | begin mount_points = ( fields [ "volumes" ] || [ ] ) . map do | v | host , container , ro = v . split ( ':' ) { "sourceVolume" => path_to_vol_name ( host ) , "containerPath" => container...
Create a new generator specifying the family name to use and the raw YAML input . Generate an ECS task definition as a raw Ruby hash .
14,459
def mem_limit_to_mb ( mem_limit ) unless mem_limit . downcase =~ / \A \d \z / raise "Cannot parse docker memory limit: #{mem_limit}" end val = $1 . to_i case $2 when "b" then ( val / ( 1024.0 * 1024.0 ) ) . ceil when "k" then ( val / 1024.0 ) . ceil when "m" then ( val * 1.0 ) . ceil when "g" then ( val * 1024.0 ) . ce...
Parse a Docker - style mem_limit and convert to megabytes .
14,460
def port_mapping ( port ) case port . to_s when / \A \d \/ \z / port = $1 . to_i { "hostPort" => port , "containerPort" => port , "protocol" => $2 || "tcp" } when / \A \d \d \/ \z / { "hostPort" => $1 . to_i , "containerPort" => $2 . to_i , "protocol" => $3 || "tcp" } else raise "Cannot parse port specification: #{port...
Parse a Docker - style port mapping and convert to ECS format .
14,461
def increment ( index = - 1 ) value = @components [ index ] raise TypeError . new "'#{value}' is not an integer" unless value . is_a? Integer copy = Array . new @components copy [ index ] = value + 1 while index < copy . size && index != - 1 index += 1 value = copy [ index ] if value . is_a? Integer copy [ index ] = 0 ...
Construction can throw ArgumentError but does no parsing or type - conversion Returns a copy of the VersionCluster with the integer at the provided index incremented by one . Raises a TypeError if the value at that index is not an integer .
14,462
def decrement ( index = - 1 ) value = @components [ index ] raise TypeError . new "'#{value}' is not an integer" unless value . is_a? Integer raise RangeError . new "'#{value}' is zero or less" unless value > 0 copy = Array . new @components copy [ index ] = value - 1 self . class . new copy end
Returns a copy of the VersionCluster with the integer at the provided index decremented by one . Raises a TypeError if the value at that index is not an integer . Raises a RangeError if the value is zero or less
14,463
def compare_arrays ( a , b ) a . each_with_index do | v1 , i | v2 = b [ i ] if v1 . is_a? ( String ) && v2 . is_a? ( Integer ) return 1 elsif v1 . is_a? ( Integer ) && v2 . is_a? ( String ) return - 1 end comparison = v1 <=> v2 unless comparison == 0 return comparison end end 0 end
a & b must have the same length
14,464
def create ( source_type , name , parameters = { } , resources = [ ] , auth = [ ] , options = { } ) fail BadParametersError , 'source_type and name are required' if source_type . nil? || name . nil? params = { :source_type => source_type , :name => name } params . merge! ( options ) unless options . empty? params . mer...
Creates a new managed source
14,465
def update ( id , source_type , name , parameters = { } , resources = [ ] , auth = [ ] , options = { } ) fail BadParametersError , 'ID, source_type and name are required' if id . nil? || source_type . nil? || name . nil? params = { :id => id , :source_type => source_type , :name => name } params . merge! ( options ) un...
Update a Managed Source
14,466
def get ( id = nil , source_type = nil , page = 1 , per_page = 20 ) params = { :page => page , :per_page => per_page } params . merge! ( { :id => id } ) if ! id . nil? params . merge! ( { :source_type => source_type } ) if ! source_type . nil? DataSift . request ( :GET , 'source/get' , @config , params ) end
Retrieve details of a Managed Source
14,467
def log ( id , page = 1 , per_page = 20 ) fail BadParametersError , 'ID is required' if id . nil? DataSift . request ( :POST , 'source/log' , @config , { :id => id , :page => page , :per_page => per_page } ) end
Retrieve log details of Managed Sources
14,468
def compile ( lessfile , cssfile ) import_paths = options [ :import_paths ] . unshift ( File . dirname ( lessfile ) ) parser = :: Less :: Parser . new paths : import_paths , filename : lessfile File . open ( lessfile , 'r' ) do | infile | File . open ( cssfile , 'w' ) do | outfile | tree = parser . parse ( infile . rea...
Parse the source lessfile and write to target cssfile
14,469
def tags ( hash = '' , id = '' , service = 'facebook' ) fail BadParametersError , 'hash or id is required' if hash . empty? && id . empty? fail BadParametersError , 'service is required' if service . empty? params = { } params . merge! ( hash : hash ) unless hash . empty? params . merge! ( id : id ) unless id . empty? ...
Query the tag hierarchy on interactions populated by a particular recording
14,470
def sample ( hash = '' , count = nil , start_time = nil , end_time = nil , filter = '' , id = '' , service = 'facebook' ) fail BadParametersError , 'hash or id is required' if hash . empty? && id . empty? fail BadParametersError , 'service is required' if service . empty? params = { } params . merge! ( hash : hash ) un...
Hit the PYLON Sample endpoint to pull public sample data from a PYLON recording
14,471
def reference ( service : , slug : '' , ** opts ) params = { } params [ :per_page ] = opts [ :per_page ] if opts . key? ( :per_page ) params [ :page ] = opts [ :page ] if opts . key? ( :page ) DataSift . request ( :GET , "pylon/#{service}/reference/#{slug}" , @config , params ) end
Hit the PYLON Reference endpoint to expose reference data sets
14,472
def errors @errors ||= @time_series . zip ( one_step_ahead_forecasts ) . map do | ( observation , forecast ) | forecast - observation if forecast && observation end end
Returns the errors between the observed values and the one step ahead forecasts .
14,473
def action_link ( title , link , icon , options = { } ) icon_tag = content_tag ( :i , '' , class : "fa fa-#{icon} fa-fw" ) default_options = { title : title , data : { tooltip : title } } link_to icon_tag , link , default_options . deep_merge ( options ) end
default tenon action link
14,474
def toggle_link ( object , field , link , true_values , false_values ) state = object . send ( field ) icon = state ? true_values [ 0 ] : false_values [ 0 ] tooltip = state ? true_values [ 1 ] : false_values [ 1 ] data = { trueicon : true_values [ 0 ] , falseicon : false_values [ 0 ] , truetooltip : true_values [ 1 ] ,...
extention of action_link for boolean toggles
14,475
def edit_link ( obj , options = { } ) if policy ( obj ) . edit? url = polymorphic_url ( [ :edit ] + Array ( obj ) ) action_link ( 'Edit' , url , 'pencil' , options ) end end
default tenon edit link
14,476
def delete_link ( obj , options = { } ) if policy ( obj ) . destroy? default_options = { data : { confirm : 'Are you sure? There is no undo for this!' , tooltip : 'Delete' , method : 'Delete' , remote : 'true' } } url = polymorphic_url ( obj ) action_link ( 'Delete' , url , 'trash-o' , default_options . deep_merge ( op...
default tenon delete link
14,477
def _call_xml_operation ( op_sym , body , extract = nil ) @operation = _operation ( op_sym ) @operation . body = body @response = operation . call _envelope . xpath ( "soap:Body/soap:Fault" , namespaces ) . each do | fault | raise Exception , fault . to_s end if extract . respond_to? ( :call ) @xml = extract . call ( r...
Build and call
14,478
def _extract_motm lambda { | response | if response . raw =~ ( / \w / ) xml = response . raw . split ( $1 ) [ - 2 ] . strip if xml =~ / \r \n \r \n / xml = xml . split ( / \r \n \r \n / ) [ - 1 ] end else raise "Cannot parse MOTM" end } end
This is proof - of - concept quality code .
14,479
def ole ( type , requiremet = '>= 0' ) AssLauncher :: Enterprise :: Ole . ole_client ( type ) . new ( requiremet ) end
Return 1C ole client suitable class instance
14,480
def check_for_security_alerts autoit = WIN32OLE . new ( 'AutoItX3.Control' ) loop do [ "Security Alert" , "Security Information" ] . each do | win_title | ret = autoit . WinWait ( win_title , '' , 1 ) if ( ret == 1 ) then autoit . Send ( '{Y}' ) end end sleep ( 3 ) end end
Check for Security Information and Security Alert alert popup click Yes
14,481
def start_checking_js_dialog ( button = "OK" , wait_time = 3 ) w = WinClicker . new longName = File . expand_path ( File . dirname ( __FILE__ ) ) . gsub ( "/" , "\\" ) shortName = w . getShortFileName ( longName ) c = "start ruby #{shortName}\\clickJSDialog.rb #{button} #{wait_time} " w . winsystem ( c ) w = nil end
Start a background process to click the button on a javascript popup window
14,482
def query ( params , base_return = [ ] ) params [ :action ] = 'query' params [ :continue ] = '' loop do result = post ( params ) yield ( base_return , result [ 'query' ] ) if result . key? ( 'query' ) break unless @use_continuation break unless result . key? ( 'continue' ) continue = result [ 'continue' ] continue . ea...
Performs a Mediawiki API query and provides the response dealing with continuation as necessary .
14,483
def query_ary_irrelevant_keys ( params , base_response_key , property_key ) query ( params ) do | return_val , query | return_val . concat ( query [ base_response_key ] . values . collect { | obj | obj [ property_key ] } ) end end
Helper method for query methods that return a two - dimensional hashes in which the keys are not relevant to the returning value . In most cases this key is a redundant page or revision ID that is also available in the object .
14,484
def query_ary ( params , base_response_key , property_key ) query ( params ) do | return_val , query | return_val . concat ( query [ base_response_key ] . collect { | obj | obj [ property_key ] } ) end end
Helper method for query methods that return an array built from the query objects .
14,485
def get_limited ( integer , max_user = 500 , max_bot = 5000 ) if integer . is_a? ( String ) return integer if integer == 'max' return 500 end return integer if integer <= max_user if user_bot? integer > max_bot ? max_bot : integer else max_user end end
Gets the limited version of the integer to ensure nobody provides an int that is too large .
14,486
def ancestors_until ( until_class ) ancestors_list = all_ancestors [ 0 .. all_ancestors . index ( until_class ) ] ancestors_list . map { | klass | yield ( klass ) } end
The list of ancestors is very long . Trim it down to just the length of the class we are looking for .
14,487
def rate_limit ( options = { } , & block ) raise Error , 'Handling block was not provided' unless block_given? strategy = ( options . delete ( :strategy ) || 'sliding_window_log' ) . to_s limit = options . delete ( :limit ) || 100 per = options . delete ( :per ) || 3600 pattern = options . delete ( :pattern ) client = ...
Sets callback that handles rate limit exceeding . Additionally to described options supports all the before_action options .
14,488
def prepare ( hash , start , end_time , name , sources = '' , sample = 100 ) params = { :hash => hash , :start => start , :end => end_time , :name => name , :sources => sources , :sample => sample } requires params DataSift . request ( :POST , 'historics/prepare' , @config , params ) end
Prepare a new Historics query
14,489
def pause ( id , reason = '' ) params = { :id => id } requires params params [ :reason ] = reason DataSift . request ( :PUT , 'historics/pause' , @config , params ) end
Pause Historics query
14,490
def stop ( id , reason = '' ) params = { :id => id } requires params params [ :reason ] = reason DataSift . request ( :POST , 'historics/stop' , @config , params ) end
Stop Historics query
14,491
def status ( start , end_time , sources = '' ) params = { :start => start , :end => end_time , :sources => sources } requires params DataSift . request ( :GET , 'historics/status' , @config , params ) end
Check the data coverage in the archive for a specified interval
14,492
def update ( id , name ) params = { :id => id , :name => name } requires params DataSift . request ( :POST , 'historics/update' , @config , params ) end
Update the name of an Historics query
14,493
def get_by_id ( id , with_estimate = 1 ) params = { :id => id , :with_estimate => with_estimate } requires params DataSift . request ( :GET , 'historics/get' , @config , params ) end
Get details for a given Historics query
14,494
def get ( max = 20 , page = 1 , with_estimate = 1 ) params = { :max => max , :page => page , :with_estimate => with_estimate } requires params DataSift . request ( :GET , 'historics/get' , @config , params ) end
Get details for a list of Historics within the given page constraints
14,495
def to_script_pubkey v = ver == 0 ? ver : ver + 0x50 ( [ v , prog . length ] . pack ( "CC" ) + prog . map { | p | [ p ] . pack ( "C" ) } . join ) . unpack ( 'H*' ) . first end
witness program Returns segwit script pubkey which generated from witness version and witness program .
14,496
def script_pubkey = ( script_pubkey ) values = [ script_pubkey ] . pack ( 'H*' ) . unpack ( "C*" ) @ver = values [ 0 ] == 0 ? values [ 0 ] : values [ 0 ] - 0x50 @prog = values [ 2 .. - 1 ] end
parse script pubkey into witness version and witness program
14,497
def add_work_item_to ( issue_id , attributes = { } ) attributes = attributes . to_hash attributes . symbolize_keys! attributes [ :date ] ||= Date . current . iso8601 epoc_date = Date . parse ( attributes [ :date ] ) . to_time . to_i * 1000 attributes [ :user ] ||= self . service . login work_items = REXML :: Element . ...
Add new work item to issue
14,498
def parse_setlist_items ( setlist_item_array = nil ) return [ ] unless setlist_item_array setlist_item_array . inject ( [ ] ) do | setlist_items , item | setlist_items << Songkickr :: SetlistItem . new ( item ) end end
Takes the array of setlist items and create SetLists
14,499
def get_frame raise SocketError . new ( "Connection closed by remote server" ) if ! @socket or @socket . eof? header = @socket . read ( 4 ) raise SocketError . new ( "Error reading frame from remote server" ) if header . nil? length = header_size ( header ) raise SocketError . new ( "Got bad frame header length of #{le...
Receive an EPP frame from the server . Since the connection is blocking this method will wait until the connection becomes available for use . If the connection is broken a SocketError will be raised . Otherwise it will return a string containing the XML from the server .