idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
20,000
def tweet ( * args ) load_default_token tweet_text = args . join ( ' ' ) . strip tweet_text += ( tweet_text . empty? ? '' : ' ' ) + STDIN . read unless STDIN . tty? if tweet_text . empty? print 'Tweet (Press return to finish): ' tweet_text = STDIN . gets . strip end return failtown ( "Empty Tweet" ) if tweet_text . emp...
Send a tweet for the user
20,001
def show ( args ) return timeline ( args ) if args . nil? || args . count == 0 target_user = args [ 0 ] load_default_token res = @client . user_timeline ( :screen_name => target_user ) return failtown ( "show :: #{res['error']}" ) if ! res || res . include? ( 'error' ) print_tweets ( res ) end
Get 20 most recent statuses of user or specified user
20,002
def status ( * args ) load_default_token return failtown ( "Unauthorized, re-run setup!" ) unless @client && @client . authorized? user = @client . info status = user [ 'status' ] puts "#{user['name']} (at #{status['created_at']}) #{status['text']}" unless status . nil? end
Get the user s most recent status
20,003
def setup ( * args ) until @access_token = self . get_access_token print "Try again? [Y/n] " return false if self . class . get_input . downcase == 'n' end tokens = { :default => { :token => @access_token . token , :secret => @access_token . secret } } save_tokens ( tokens ) end
Get the access token for the user and save it
20,004
def replies ( * args ) load_default_token return failtown ( "Unauthorized, re-run setup!" ) unless @client && @client . authorized? mentions = since_id_replies ? @client . mentions ( :since_id => since_id_replies ) : @client . mentions if mentions . any? print_tweets ( mentions ) self . since_id_replies = mentions . la...
Returns the 20 most recent
20,005
def help ( * args ) puts "#{NameColor}console-tweet#{DefaultColor} by John Crepezzi <john.crepezzi@gmail.com>" puts 'http://github.com/seejohnrun/console-tweet' puts puts "#{CommandColor}twitter#{DefaultColor} View your timeline, since last view" puts "#{CommandColor}twitter setup#{DefaultColor} Setup your account" put...
Display help section
20,006
def detect! ( time = 2 , warmup = 1 ) :: Benchmark . ips do | x | x . config ( time : time , warmup : warmup ) TEST_STRINGS_FLAT . each do | scheme , string | x . report ( "Detect #{scheme}" ) do Sanscript :: Detect . detect_scheme ( string ) end end x . compare! end true end
Runs benchmark - ips test on detection methods .
20,007
def transliterate_roman! ( time = 2 , warmup = 1 ) :: Benchmark . ips do | x | x . config ( time : time , warmup : warmup ) TEST_STRINGS [ :roman ] . to_a . product ( TEST_STRINGS_FLAT . keys ) . each do | ( ak , av ) , bk | next if ak == bk x . report ( "#{ak} => #{bk}" ) do Sanscript . transliterate ( av , ak , bk ) ...
Runs benchmark - ips test on roman - source transliteration methods .
20,008
def on_or ( node ) a , b = node . children . map { | c | @truth . fetch ( c , process ( c ) ) } if a == :true || b == :true :true elsif a == :false && b == :false :false else nil end end
Handle the || statement .
20,009
def on_send ( node ) _target , _method , _args = node . children if _method == :! case @truth . fetch ( _target , process ( _target ) ) when :true :false when :false :true else nil end else nil end end
Handles the ! statement .
20,010
def on_begin ( node ) child , other_children = * node . children raise LogicError if other_children case @truth . fetch ( child , process ( child ) ) when :true :true when :false :false else nil end end
Handle logic statements explicitly wrapped in parenthesis .
20,011
def remote_shell ( & block ) each_dest . map do | dest | shell = if dest . scheme == 'file' LocalShell else RemoteShell end shell . new ( dest , self , & block ) end end
Creates a remote shell with the destination server .
20,012
def exec ( command ) remote_shell do | shell | shell . cd ( shell . uri . path ) shell . exec ( command ) end return true end
Runs a command on the destination server in the destination directory .
20,013
def rake ( task , * arguments ) remote_shell do | shell | shell . cd ( shell . uri . path ) shell . rake ( task , * arguments ) end return true end
Executes a Rake task on the destination server in the destination directory .
20,014
def ssh ( * arguments ) each_dest do | dest | RemoteShell . new ( dest ) . ssh ( * arguments ) end return true end
Starts an SSH session with the destination server .
20,015
def setup ( shell ) shell . status "Cloning #{@source} ..." shell . run 'git' , 'clone' , '--depth' , 1 , @source , shell . uri . path shell . status "Cloned #{@source}." end
Sets up the deployment repository for the project .
20,016
def update ( shell ) shell . status "Updating ..." shell . run 'git' , 'reset' , '--hard' , 'HEAD' shell . run 'git' , 'pull' , '-f' shell . status "Updated." end
Updates the deployed repository for the project .
20,017
def invoke_task ( task , shell ) unless TASKS . include? ( task ) raise ( "invalid task: #{task}" ) end if @before . has_key? ( task ) @before [ task ] . each { | command | shell . exec ( command ) } end send ( task , shell ) if respond_to? ( task ) if @after . has_key? ( task ) @after [ task ] . each { | command | she...
Invokes a task .
20,018
def invoke ( tasks ) remote_shell do | shell | invoke_task ( :setup , shell ) if tasks . include? ( :setup ) shell . cd ( shell . uri . path ) invoke_task ( :update , shell ) if tasks . include? ( :update ) invoke_task ( :install , shell ) if tasks . include? ( :install ) invoke_task ( :migrate , shell ) if tasks . inc...
Deploys the project .
20,019
def load_framework! if @orm unless FRAMEWORKS . has_key? ( @framework ) raise ( UnknownFramework , "Unknown framework #{@framework}" , caller ) end extend FRAMEWORKS [ @framework ] initialize_framework if respond_to? ( :initialize_framework ) end end
Loads the framework configuration .
20,020
def load_server! if @server_name unless SERVERS . has_key? ( @server_name ) raise ( UnknownServer , "Unknown server name #{@server_name}" , caller ) end extend SERVERS [ @server_name ] initialize_server if respond_to? ( :initialize_server ) end end
Loads the server configuration .
20,021
def core__create_superuser_session ( superuser , lifetime ) token = core__encode_token ( lifetime , superuser_id : superuser . id ) session [ :lato_core__superuser_session_token ] = token end
This function set a cookie to create the superuser session .
20,022
def core__manage_superuser_session ( permission = nil ) decoded_token = core__decode_token ( session [ :lato_core__superuser_session_token ] ) if decoded_token @core__current_superuser = LatoCore :: Superuser . find_by ( id : decoded_token [ :superuser_id ] ) unless @core__current_superuser core__destroy_superuser_sess...
This function check the session for a superuser and set the variable
20,023
def matcher ( key , value ) if value . is_a? ( Hash ) name = "Mongoid::Matchers::#{value.keys.first.gsub("$", "").camelize}" return name . constantize . new ( send ( key ) ) end Mongoid :: Matchers :: Default . new ( send ( key ) ) end
Get the matcher for the supplied key and value . Will determine the class name from the key .
20,024
def process_power_level ( room , level ) membership = ( @memberships [ room ] ||= { } ) membership [ :power ] = level broadcast ( :power_level , self , room , level ) end
Process a power level update in a room .
20,025
def process_invite ( room , sender , event ) membership = ( @memberships [ room ] ||= { } ) return if membership [ :type ] == :join process_member_event room , event broadcast ( :invited , self , room , sender ) end
Process an invite to a room .
20,026
def update ( data ) update_avatar ( data [ 'avatar_url' ] ) if data . key? 'avatar_url' update_displayname ( data [ 'displayname' ] ) if data . key? 'displayname' end
Updates metadata for this user .
20,027
def wedge ( otype ) if superior? ( otype ) self elsif otype . respond_to? ( :superior? ) && otype . superior? ( self ) otype else raise "wedge: unknown pair (#{self}) .wedge (#{otype})" end end
Needed in the type conversion of MatrixAlgebra
20,028
def delete_kb response = @http . delete ( "#{BASE_URL}/#{knowledgebase_id}" ) case response . code when 204 nil when 400 raise BadArgumentError , response . parse [ 'error' ] [ 'message' ] . join ( ' ' ) when 401 raise UnauthorizedError , response . parse [ 'error' ] [ 'message' ] when 403 raise ForbiddenError , respon...
Deletes the current knowledge base and all data associated with it .
20,029
def start_span ( operation_name , child_of : active_span , ** args ) span = @tracer . start_span ( operation_name , child_of : child_of , ** args ) @managed_span_source . make_active ( span ) end
Starts a new active span .
20,030
def handle_response ( response ) return super ( response ) rescue ActiveResource :: ClientError => exc begin error_message = "#{format.decode response.body}" if not error_message . nil? or error_message == "" exc . response . instance_eval do | | @message = error_message end end ensure raise exc end end
make handle_response public and add error message from body if possible
20,031
def add_to_previous_rolling_n_minutes ( minutes , origin_epoch , cycle_to_add ) rolling_n_minutes_less_than_that = minutes . keys . select { | c | c < origin_epoch } end_min = rolling_n_minutes_less_than_that . size < Auth . configuration . rolling_minutes ? rolling_n_minutes_less_than_that . size : Auth . configuratio...
so we have completed the rolling n minutes .
20,032
def parse_check_defined_node ( name , flag ) isdef = node_defined? ( name ) if isdef != flag isdef ? err ( RedefinedError , "#{name} already defined" ) : err ( UndefinedError , "#{name} not defined yet" ) end end
Check to see if node with given name is defined . flag tells the method about our expectation . flag = true means that we make sure that name is defined . flag = false is the opposite .
20,033
def parse_call_attr ( node_name , attr_name ) return [ ] if comp_set . member? ( attr_name ) klass = @pm . module_eval ( node_name ) begin klass . send ( "#{attr_name}#{POST}" . to_sym , [ ] ) rescue NoMethodError err ( UndefinedError , "'#{attr_name}' not defined in #{node_name}" ) end end
Parse - time check to see if attr is available . If not error is raised .
20,034
def parse_define_attr ( name , spec ) err ( ParseError , "Can't define '#{name}' outside a node" ) unless @last_node err ( RedefinedError , "Can't redefine '#{name}' in node #{@last_node}" ) if @node_attrs [ @last_node ] . member? name @node_attrs [ @last_node ] << name checks = spec . map do | a | n = a . index ( '.' ...
parse - time attr definition
20,035
def enumerate_params_by_node ( node ) attrs = enumerate_attrs_by_node ( node ) Set . new ( attrs . select { | a | @param_set . include? ( a ) } ) end
enumerate params by a single node
20,036
def class_instrument_method ( klass , method_to_instrument , event_name , payload = { } ) class << klass ; self ; end . class_eval do Instrumentality . begin ( self , method_to_instrument , event_name , payload ) end end
Class implementation of + instrument_method +
20,037
def snippet_objects ( locals = { } ) locals = { } unless locals . kind_of? ( Hash ) @snippet_objects ||= snippets . map do | key , snippet | if snippet [ 'class_name' ] klass = "Effective::Snippets::#{snippet['class_name'].classify}" . safe_constantize klass . new ( snippet . merge! ( locals ) . merge! ( :region => sel...
Hash of the Snippets objectified
20,038
def draw r = @dist . rng . to_i raise "drawn number must be an integer" unless r . is_a? Integer r = 0 - r if r < 0 if r >= @range . size diff = 1 + r - @range . size r = @range . size - diff end @range [ r ] end
draw from the distribution
20,039
def generate_neighbour n = 0 begin if n >= 100 @distributions . each do | param , dist | dist . loosen end end neighbour = Hash [ @distributions . map { | param , dist | [ param , dist . draw ] } ] n += 1 end while self . is_tabu? ( neighbour ) @tabu << neighbour @members << neighbour end
generate a single neighbour
20,040
def update_neighbourhood_structure self . update_recent_scores best = self . backtrack_or_continue unless @distributions . empty? @standard_deviations = Hash [ @distributions . map { | k , d | [ k , d . sd ] } ] end best [ :parameters ] . each_pair do | param , value | self . update_distribution ( param , value ) end e...
update the neighbourhood structure by adjusting the probability distributions according to total performance of each parameter
20,041
def backtrack_or_continue best = nil if ( @iterations_since_best / @backtracks ) >= @backtrack_cutoff * @max_hood_size self . backtrack best = @best else best = @current_hood . best self . adjust_distributions_using_gradient end if best [ :parameters ] . nil? best = @best end best end
return the correct best location to form a new neighbourhood around deciding whether to continue progressing from the current location or to backtrack to a previous good location to explore further
20,042
def adjust_distributions_using_gradient return if @recent_scores . length < 3 vx = ( 1 .. @recent_scores . length ) . to_a . to_numeric vy = @recent_scores . reverse . to_numeric r = Statsample :: Regression :: Simple . new_from_vectors ( vx , vy ) slope = r . b if slope > 0 @distributions . each_pair { | k , d | d . t...
use the gradient of recent best scores to update the distributions
20,043
def finished? return false unless @threads . all? do | t | t . recent_scores . size == @jump_cutoff end probabilities = self . recent_scores_combination_test n_significant = 0 probabilities . each do | mann_u , levene | if mann_u <= @adjusted_alpha && levene <= @convergence_alpha n_significant += 1 end end finish = n_s...
check termination conditions and return true if met
20,044
def initialize_rails ( name , log_subscriber , controller_runtime ) log_subscriber . attach_to name . to_sym ActiveSupport . on_load ( :action_controller ) do include controller_runtime end end
Attach LogSubscriber and ControllerRuntime to a notifications namespace
20,045
def railtie ( name , log_subscriber , controller_runtime ) Class . new ( Rails :: Railtie ) do railtie_name name initializer "#{name}.notifications" do SweetNotifications :: Railtie . initialize_rails ( name , log_subscriber , controller_runtime ) end end end
Create a Railtie for LogSubscriber and ControllerRuntime mixin
20,046
def sort ( opts = { } ) return [ ] if not distkey opts [ :by ] = sortables [ opts [ :by ] ] if opts [ :by ] if opts [ :start ] && opts [ :limit ] opts [ :limit ] = [ opts [ :start ] , opts [ :limit ] ] end objects ( distkey . sort ( opts ) ) end
Gives the ability to sort the search results via a sortable field in your index .
20,047
def padding last = bytes . last subset = subset_padding if subset . all? { | e | e == last } self . class . new ( subset ) else self . class . new ( [ ] ) end end
Return any existing padding
20,048
def strip_padding subset = bytes if padding? pad = padding len = pad . length subset = bytes [ 0 , bytes . length - len ] end self . class . new ( subset ) end
Strip the existing padding if present
20,049
def to_parser ( * args , & block ) parser = ConfigParser . new ( * args , & block ) traverse do | nesting , config | next if config [ :hidden ] == true || nesting . any? { | nest | nest [ :hidden ] == true } nest_keys = nesting . collect { | nest | nest . key } long , short = nesting . collect { | nest | nest . name } ...
Initializes and returns a ConfigParser generated using the configs for self . Arguments given to parser are passed to the ConfigParser initializer .
20,050
def to_default default = { } each_pair do | key , config | default [ key ] = config . default end default end
Returns a hash of the default values for each config in self .
20,051
def traverse ( nesting = [ ] , & block ) each_value do | config | if config . type . kind_of? ( NestType ) nesting . push config configs = config . type . configurable . class . configs configs . traverse ( nesting , & block ) nesting . pop else yield ( nesting , config ) end end end
Yields each config in configs to the block with nesting after appened self to nesting .
20,052
def clean_tmpdir self . root_dir . each do | d | if d != '..' and d! = '.' if d . to_i < Time . now . to_i - TIME_LIMIT FileUtils . rm_rf ( File . join ( self . root_dir . path , d ) ) end end end end
Clean the directory
20,053
def charset_from_meta_content ( string ) charset_match = string . match ( / \s \= \s /i ) if charset_match charset_value = charset_match [ 1 ] charset_value [ / \A \" \" / , 1 ] || charset_value [ / \A \' \' / , 1 ] || charset_value [ / \s / , 1 ] || charset_value [ / / , 1 ] else nil end end
Given a string representing the content attribute value of a meta tag with an http - equiv attribute returns the charset specified within that value or nil .
20,054
def attribute_value ( string ) attribute_value = '' position = 0 length = string . length while position < length if string [ position ] =~ / \u{09} \u{0A} \u{0C} \u{0D} \u{20} / position += 1 elsif string [ position ] =~ / / attribute_value , position = quoted_value ( string [ position , length ] ) break elsif string ...
Given a string this returns the attribute value from the start of the string and the position of the following character in the string
20,055
def create_edge_to_and_from ( other , weight = 1.0 ) self . class . edge_class . create! ( :from_id => id , :to_id => other . id , :weight => weight ) self . class . edge_class . create! ( :from_id => other . id , :to_id => id , :weight => weight ) end
+ other + graph node to edge to + weight + positive float denoting edge weight Creates a two way edge between this node and another .
20,056
def path_weight_to ( other ) shortest_path_to ( other , :method => :djikstra ) . map { | edge | edge . weight . to_f } . sum end
+ other + The target node to find a route to Gives the path weight as a float of the shortest path to the other
20,057
def bound ( val ) case val when Rectangle then r = val . clone r . size = r . size . min ( size ) r . loc = r . loc . bound ( loc , loc + size - val . size ) r when Point then ( val - loc ) . bound ( point , size ) + loc else raise ArgumentError . new ( "wrong type: (#{val.class}) - Rectangle or Point expected" ) end e...
val can be a Rectangle or Point returns a Rectangle or Point that is within this Rectangle For Rectangles the size is only changed if it has to be
20,058
def disjoint ( b ) return self if ! b || contains ( b ) return b if b . contains ( self ) return self , b unless overlaps? ( b ) tl_contained = contains? ( b . tl ) ? 1 : 0 tr_contained = contains? ( b . tr ) ? 1 : 0 bl_contained = contains? ( b . bl ) ? 1 : 0 br_contained = contains? ( b . br ) ? 1 : 0 sum = tl_contai...
return 1 - 3 rectangles which together cover exactly the same area as self and b but do not overlapp
20,059
def version response = get ( '/getVersion' , { } , false ) ApiVersion . new ( response . body [ 'version' ] , response . body [ 'builddate' ] ) end
Retrieve the current version information of the service
20,060
def devices response = get ( '/listDevices' ) devices = [ ] response . body [ 'devices' ] . each do | d | devices << Device . from_json ( d , @token , @logger ) end devices end
Retrieve a list of devices that are registered with the PogoPlug account
20,061
def services ( device_id = nil , shared = false ) params = { shared : shared } params [ :deviceid ] = device_id unless device_id . nil? response = get ( '/listServices' , params ) services = [ ] response . body [ 'services' ] . each do | s | services << Service . from_json ( s , @token , @logger ) end services end
Retrieve a list of services
20,062
def render ( context ) return "" unless ENV [ "ENV" ] == "production" full_path = File . join ( context [ "site" ] [ "__directory" ] , @path . strip ) return @prefix + DIGEST_CACHE [ full_path ] if DIGEST_CACHE [ full_path ] digest = Digest :: MD5 . hexdigest ( File . read ( full_path ) ) DIGEST_CACHE [ full_path ] = d...
Takes the given path and returns the MD5 hex digest of the file s contents .
20,063
def call ( name , input ) fetch ( name ) . call ( Request . new ( name , env , input ) ) end
Invoke the action identified by + name +
20,064
def create_kb ( name , qna_pairs = [ ] , urls = [ ] ) response = @http . post ( "#{BASE_URL}/create" , json : { name : name , qnaPairs : qna_pairs . map { | pair | { question : pair [ 0 ] , answer : pair [ 1 ] } } , urls : urls } ) case response . code when 201 QnAMaker :: Client . new ( response . parse [ 'kbId' ] , @...
Creates a new knowledge base .
20,065
def index ( * args ) options_and_fields = args . extract_options! if args . any? collection . create_index ( args . first , options_and_fields ) else fields = options_and_fields . except ( * OPTIONS ) options = options_and_fields . slice ( * OPTIONS ) collection . create_index ( to_mongo_direction ( fields ) , options ...
Create an index on a collection .
20,066
def + ( value = 1 ) return if ( value <= 0 ) || ( @value == @maximum ) @value += value old_progress = @progress add_progress = ( ( @value - @progress / @factor ) * @factor ) . round @progress += add_progress if @progress > @size @progress = @size add_progress = @size - old_progress end if add_progress > 0 @ostream << @...
Create a new ProgressBar using the given options .
20,067
def put content , destination , on_conflict = :overwrite if on_conflict != :overwrite && Content :: Item . new ( destination ) . exists? case on_conflict when :skip then return when :prompt then input = Util . get_input "a file already exists at #{destination}\noverwrite? (y|n): " return unless input . downcase == "y" ...
write the content to a destination file
20,068
def encipher ( message , shift ) assert_valid_shift! ( shift ) real_shift = convert_shift ( shift ) message . split ( "" ) . map do | char | mod = ( char =~ / / ) ? 123 : 91 offset = ( char =~ / / ) ? 97 : 65 ( char =~ / / ) ? char : CryptBuffer ( char ) . add ( real_shift , mod : mod , offset : offset ) . str end . jo...
= begin Within encipher and decipher we use a regexp comparision . Array lookups are must slower and byte comparision is a little faster but much more complicated
20,069
def create_entity ( file , io = nil , properties = { } ) params = { deviceid : @device_id , serviceid : @service_id , filename : file . name , type : file . type } . merge ( properties ) params [ :parentid ] = file . parent_id unless file . parent_id . nil? if params [ :properties ] params [ :properties ] = params [ :p...
Creates a file handle and optionally attach an io . The provided file argument is expected to contain at minimum a name type and parent_id . If it has a mimetype that will be assumed to match the mimetype of the io .
20,070
def load_assemblers Biopsy :: Settings . instance . target_dir . each do | dir | Dir . chdir dir do Dir [ '*.yml' ] . each do | file | name = File . basename ( file , '.yml' ) target = Assembler . new target . load_by_name name unless System . match? target . bindeps [ :url ] logger . info "Assembler #{target.name} is ...
Discover and load available assemblers .
20,071
def assembler_names a = [ ] @assemblers . each do | t | a << t . name a << t . shortname if t . shortname end a end
load_assemblers Collect all valid names for available assemblers
20,072
def list_assemblers str = "" if @assemblers . empty? str << "\nNo assemblers are currently installed! Please install some.\n" else str << <<-EOS EOS @assemblers . each do | a | p = " - #{a.name}" p += " (#{a.shortname})" if a . respond_to? :shortname str << p + "\n" end end if @assemblers_uninst . empty? str << "\nAll...
assemblers Return a help message listing installed assemblers .
20,073
def get_assembler assembler ret = @assemblers . find do | a | a . name == assembler || a . shortname == assembler end raise "couldn't find assembler #{assembler}" if ret . nil? ret end
Given the name of an assembler get the loaded assembler ready for optimisation .
20,074
def run_all_assemblers options res = { } subset = false unless options [ :assemblers ] == 'all' subset = options [ :assemblers ] . split ( ',' ) missing = [ ] subset . each do | choice | missing < choice unless @assemblers . any do | a | a . name == choice || a . shortname == choice end end unless missing . empty? log ...
Run optimisation and final assembly for each assembler
20,075
def run_assembler assembler opts = @options . clone opts [ :left ] = opts [ :left_subset ] opts [ :right ] = opts [ :right_subset ] if @options [ :optimiser ] == 'sweep' logger . info ( "Using full parameter sweep optimiser" ) algorithm = Biopsy :: ParameterSweeper . new ( assembler . parameters ) elsif @options [ :opt...
Run optimisation for the named assembler
20,076
def [] ( id ) return @rooms [ id ] if id . start_with? '!' if id . start_with? '#' res = @rooms . find { | _ , r | r . canonical_alias == id } return res . last if res . respond_to? :last end res = @rooms . find { | _ , r | r . name == id } res . last if res . respond_to? :last end
Initializes a new Rooms instance .
20,077
def process_events ( events ) process_join events [ 'join' ] if events . key? 'join' process_invite events [ 'invite' ] if events . key? 'invite' process_leave events [ 'leave' ] if events . key? 'leave' end
Processes a list of room events from syncs .
20,078
def get_room ( id ) return @rooms [ id ] if @rooms . key? id room = Room . new id , @users , @matrix @rooms [ id ] = room broadcast ( :added , room ) room end
Gets the Room instance associated with a room ID . If there is no Room instance for the ID one is created and returned .
20,079
def process_join ( events ) events . each do | room , data | get_room ( room ) . process_join data end end
Process join room events .
20,080
def process_invite ( events ) events . each do | room , data | get_room ( room ) . process_invite data end end
Process invite room events .
20,081
def process_leave ( events ) events . each do | room , data | get_room ( room ) . process_leave data end end
Process leave room events .
20,082
def method_missing ( method , * args , & block ) if controller . resource_named_route_helper_method? ( method ) self . class . send ( :delegate , method , :to => :controller ) controller . send ( method , * args ) else super ( method , * args , & block ) end end
Delegate named_route helper method to the controller . Create the delegation to short circuit the method_missing call for future invocations .
20,083
def generate_table_head labels = [ ] if @args [ :head ] && @args [ :head ] . length > 0 labels = [ ] if @args [ :actions_on_start ] && @show_row_actions labels . push ( LANGUAGES [ :lato_core ] [ :mixed ] [ :actions ] ) end @args [ :head ] . each do | head | if head . is_a? ( Hash ) sort_value = @args [ :records ] . is...
This function generate the head for the table .
20,084
def generate_table_rows table_rows = [ ] if @args [ :columns ] && @args [ :columns ] . length > 0 table_rows = generate_table_rows_from_columns_functions ( @args [ :columns ] ) elsif @records && @records . length > 0 table_rows = generate_table_rows_from_columns_functions ( @records . first . attributes . keys ) end re...
This function generate the rows fr the table .
20,085
def generate_table_rows_from_columns_functions columns_functions table_rows = [ ] @records . each do | record | labels = [ ] if @args [ :actions_on_start ] && @show_row_actions labels . push ( generate_actions_bottongroup_for_record ( record ) ) end columns_functions . each do | column_function | labels . push ( record...
This function generate the rows for a list of columns .
20,086
def generate_actions_bottongroup_for_record record action_buttons = [ ] action_buttons . push ( generate_show_button ( record . id ) ) if @args [ :actions ] [ :show ] action_buttons . push ( generate_edit_button ( record . id ) ) if @args [ :actions ] [ :edit ] action_buttons . push ( generate_delete_button ( record . ...
This function generate row actions for a table row .
20,087
def generate_delete_button record_id return unless @args [ :index_url ] url = @args [ :index_url ] . end_with? ( '/' ) ? "#{@args[:index_url].gsub(/\?.*/, '')}#{record_id}" : "#{@args[:index_url].gsub(/\?.*/, '')}/#{record_id}" return LatoCore :: Elements :: Button :: Cell . new ( label : LANGUAGES [ :lato_core ] [ :mi...
This function generate the delete button for a record .
20,088
def generate_new_button return unless @args [ :index_url ] url = "#{@args[:index_url].gsub(/\?.*/, '')}/new" return LatoCore :: Elements :: Button :: Cell . new ( label : LANGUAGES [ :lato_core ] [ :mixed ] [ :new ] , url : url , icon : 'plus' ) end
This function generate new button .
20,089
def generate_search_input search_placeholder = '' if @args [ :records ] . is_a? ( Hash ) search_placeholder = @args [ :records ] [ :search_key ] . is_a? ( Array ) ? @args [ :records ] [ :search_key ] . to_sentence : @args [ :records ] [ :search_key ] . humanize end search_value = @args [ :records ] . is_a? ( Hash ) ? @...
This function generate and return the search input .
20,090
def generate_search_submit return LatoCore :: Elements :: Button :: Cell . new ( label : ' ' , icon : 'search' , type : 'submit' , icon_align : 'right' ) end
This function generate the search submit button .
20,091
def install_file FileUtils . mkdir_p File . dirname ( destination_path ) FileUtils . copy source_path , destination_path , preserve : true end
Recursively creates the necessary directories and install the file .
20,092
def need_paren_in_coeff? if constant? c = @coeff [ 0 ] if c . respond_to? ( :need_paren_in_coeff? ) c . need_paren_in_coeff? elsif c . is_a? ( Numeric ) false else true end elsif ! monomial? true else false end end
def cont ;
20,093
def reports ( from_id , start_date = nil , end_date = nil ) params = [ ] if from_id params << "from_id=#{from_id}" end if start_date and not end_date raise 'must include both start_date and end_date' end if end_date and not start_date raise 'must include both start_date and end_date' end if start_date and end_date para...
Report for a group of messages in a given time period .
20,094
def train_kb ( feedback_records = [ ] ) feedback_records = feedback_records . map do | record | { userId : record [ 0 ] , userQuestion : record [ 1 ] , kbQuestion : record [ 2 ] , kbAnswer : record [ 3 ] } end response = @http . patch ( "#{BASE_URL}/#{@knowledgebase_id}/train" , json : { feedbackRecords : feedback_reco...
The developer of the knowledge base service can use this API to submit user feedback for tuning question - answer matching . QnA Maker uses active learning to learn from the user utterances that come on a published Knowledge base service .
20,095
def convert_mjd_to_date ( mjd ) y_ = ( ( mjd - 15078.2 ) / 365.25 ) . to_i m_ = ( ( mjd - 14956.1 - ( y_ * 365.25 ) . to_i ) / 30.6001 ) . to_i d = mjd - 14956 - ( y_ * 365.25 ) . to_i - ( m_ * 30.6001 ) . to_i k = ( m_ == 14 || m_ == 15 ) ? 1 : 0 y = y_ + k m = m_ - 1 - k * 12 return Date . new ( 1900 + y , m , d ) en...
ARIB STD - B10 2 appendix - C
20,096
def call ( request ) reduce ( request ) { | result , processor | begin response = processor . call ( result ) return response unless processor . success? ( response ) processor . result ( response ) rescue => exception return on_exception ( request , result . data , exception ) end } end
Call the chain
20,097
def on_exception ( state , data , exception ) response = self . class . exception_response ( state , data , exception ) exception_chain . call ( response ) end
Call the failure chain in case of an uncaught exception
20,098
def update_state Thread . new do Dictionary . commands . each do | zone , commands | Dictionary . commands [ zone ] . each do | command , info | info [ :values ] . each do | value , _ | if value == 'QSTN' send ( Parser . parse ( command + "QSTN" ) ) sleep DEFAULT_TIMEOUT end end end end end end
Runs every command that supports the QSTN value . This is a good way to get the sate of the receiver after connecting .
20,099
def controller_runtime ( name , log_subscriber ) runtime_attr = "#{name.to_s.underscore}_runtime" . to_sym Module . new do extend ActiveSupport :: Concern attr_internal runtime_attr protected define_method :process_action do | action , * args | log_subscriber . reset_runtime super ( action , * args ) end define_method ...
Define a controller runtime logger for a LogSusbcriber