idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
8,900 | def update_state current_state . dup . tap do | s | src = eval_parameter :src s [ src ] = next_state s [ src ] end end | Protocol is symmetrical . Each endpoint has its own state . This is a bit clunky and maybe should be abstracted into a module? Or update parser . rb to differentiate between proto - shared and endpoint - separate state? |
8,901 | def create_bucket ( name , options = { } ) defaults = { :type => "couchbase" , :ram_quota => 100 , :replica_number => 1 , :auth_type => "sasl" , :sasl_password => "" , :proxy_port => nil , :flush_enabled => false , :replica_index => true , :parallel_db_and_view_compaction => false } options = defaults . merge ( options... | Establish connection to the cluster for administration |
8,902 | def locate ( name , bootstrap_protocol = :http ) service = case bootstrap_protocol when :http "_cbhttp" when :cccp "_cbmcd" else raise ArgumentError , "unknown bootstrap protocol: #{bootstrap_transports}" end hosts = [ ] Resolv :: DNS . open do | dns | resources = dns . getresources ( "#{service}._tcp.#{name}" , Resolv... | Locate bootstrap nodes from a DNS SRV record . |
8,903 | def fetch ( params = { } ) params = @params . merge ( params ) options = { } options [ :include_docs ] = params . delete ( :include_docs ) if params . key? ( :include_docs ) options [ :format ] = params . delete ( :format ) if params . key? ( :format ) options [ :transcoder ] = params . delete ( :transcoder ) if params... | Performs query to Couchbase view . This method will stream results if block given or return complete result set otherwise . In latter case it defines method + total_rows + returning corresponding entry from Couchbase result object . |
8,904 | def method_missing ( meth , * args ) name , options = @all_views [ meth . to_s ] if name View . new ( @bucket , @id , name , ( args [ 0 ] || { } ) . merge ( options ) ) else super end end | Initialize the design doc instance |
8,905 | def cas ( key , options = { } ) retries_remaining = options . delete ( :retry ) || 0 loop do res = get ( key , options ) val = yield ( res . value ) res = set ( key , val , options . merge ( :cas => res . cas ) ) if res . error && res . error . code == Couchbase :: LibraryError :: LCB_KEY_EEXISTS if retries_remaining >... | Compare and swap value . |
8,906 | def design_docs req = __http_query ( :management , :get , "/pools/default/buckets/#{bucket}/ddocs" , nil , nil , nil , nil , nil ) docmap = { } res = MultiJson . load ( req [ :chunks ] . join ) res [ "rows" ] . each do | obj | obj [ 'doc' ] [ 'value' ] = obj [ 'doc' ] . delete ( 'json' ) if obj [ 'doc' ] doc = DesignDo... | Fetch design docs stored in current bucket |
8,907 | def save_design_doc ( data ) attrs = case data when String MultiJson . load ( data ) when IO MultiJson . load ( data . read ) when Hash data else raise ArgumentError , "Document should be Hash, String or IO instance" end id = attrs . delete ( '_id' ) . to_s attrs [ 'language' ] ||= 'javascript' raise ArgumentError , "'... | Update or create design doc with supplied views |
8,908 | def delete_design_doc ( id , rev = nil ) ddoc = design_docs [ id . sub ( / \/ / , '' ) ] return false unless ddoc path = Utils . build_query ( ddoc . id , :rev => rev || ddoc . meta [ 'rev' ] ) res = __http_query ( :view , :delete , path , nil , nil , nil , nil , nil ) return true if res [ :status ] == 200 val = MultiJ... | Delete design doc with given id and revision . |
8,909 | def observe_and_wait ( * keys , & block ) options = { :timeout => default_observe_timeout } options . update ( keys . pop ) if keys . size > 1 && keys . last . is_a? ( Hash ) verify_observe_options ( options ) raise ArgumentError , "at least one key is required" if keys . empty? key_cas = if keys . size == 1 && keys [ ... | Wait for persistence condition |
8,910 | def resource_scope @_effective_resource_relation ||= ( relation = case @_effective_resource_scope when ActiveRecord :: Relation @_effective_resource_scope when Hash effective_resource . klass . where ( @_effective_resource_scope ) when Symbol effective_resource . klass . send ( @_effective_resource_scope ) when nil eff... | Returns an ActiveRecord relation based on the computed value of resource_scope dsl method |
8,911 | def must_impl ( * methods ) return if methods . nil? fail TypeError , "invalid args type #{methods.class}. you must use Array or Symbol" unless methods . class . any_of? Array , Symbol methods = ( methods . class . is_a? Symbol ) ? [ methods ] : methods methods . each do | method_name | fail TypeError , "invalid args t... | template method force class macro |
8,912 | def each_with_depth ( from : nil , to : nil , & block ) Array ( lines ) . each_with_index do | line , index | next if index < ( from || 0 ) depth = line . length - line . lstrip . length block . call ( line . strip , depth , index ) break if to == index end nil end | Iterate over the lines with a depth and passed the stripped line to the passed block |
8,913 | def index ( from : nil , to : nil , & block ) each_with_depth ( from : from , to : to ) do | line , depth , index | return index if block . call ( line , depth , index ) end end | Returns the index of the first line where the passed block returns true |
8,914 | def last ( from : nil , to : nil , & block ) retval = nil each_with_depth ( from : from , to : nil ) do | line , depth , index | retval = line if block . call ( line , depth , index ) end retval end | Returns the stripped contents of the last line where the passed block returns true |
8,915 | def select ( from : nil , to : nil , & block ) retval = [ ] each_with_depth ( from : from , to : to ) do | line , depth , index | retval << line if ( block_given? == false || block . call ( line , depth , index ) ) end retval end | Returns an array of stripped lines for each line where the passed block returns true |
8,916 | def acts_as_statused ( klass , only : nil , except : nil ) raise "klass does not implement acts_as_statused" unless klass . acts_as_statused? statuses = klass . const_get ( :STATUSES ) instance = klass . new only = Array ( only ) . compact except = Array ( except ) . compact statuses . each_with_index do | status , ind... | The idea here is you can go forward but you can t go back . |
8,917 | def status_active_verb ( status , instance ) status = status . to_s . strip if status . end_with? ( 'ied' ) action = status [ 0 ... - 3 ] + 'y' return action . to_sym if instance . respond_to? ( action + '!' ) end [ - 1 , - 2 , - 3 ] . each do | index | action = status [ 0 ... index ] return action . to_sym if instance... | requested - > request approved - > approve declined - > decline pending - > pending |
8,918 | def dates ( event , date_range ) result = [ ] date_range . each do | date | result . push date if include? ( event , date ) end result end | For the given date range returns an Array of PDate objects at which the supplied event is scheduled to occur . |
8,919 | def include? ( event , date ) return false unless @elems . include? ( event ) return 0 < ( self . select { | ev , xpr | ev . eql? ( event ) && xpr . include? ( date ) ; } ) . size end | Return true or false depend on if the supplied event is scheduled to occur on the given date . |
8,920 | def generate ( debug = false ) decorator = debug ? Fixy :: Decorator :: Debug : Fixy :: Decorator :: Default output = '' current_position = 1 current_record = 1 while current_position <= self . class . record_length do field = record_fields [ current_position ] raise StandardError , "Undefined field for position #{curr... | Generate the entry based on the record structure |
8,921 | def exists? ( nickname ) users . each do | user | if user . nickname == nickname return true ; end end false end | Initializes the object . If no users are supplied we look for a config file if none then create it and parse it to load users |
8,922 | def get ( nickname ) users . each do | user | if user . nickname == nickname . to_s return user end end nil end | Returns the user with nickname nil if no such user exists |
8,923 | def to_s current_user = GitConfig . current_user users . map do | user | if current_user == user " ==> #{user.to_s[5,user.to_s.length]}" else user . to_s end end . join "\n" end | Override to_s to output correct format |
8,924 | def desc fsym = FieldSymbol . new ( self , respond_to? ( :desc? ) ? ! desc? : true ) fsym . type = respond_to? ( :type ) ? type : nil fsym end | Set a field to be a descending field . This only makes sense in sort specifications . |
8,925 | def to_s buf = [ "Document {" ] self . keys . sort_by { | key | key . to_s } . each do | key | val = self [ key ] val_str = if val . instance_of? Array then %{["#{val.join('", "')}"]} elsif val . is_a? Field then val . to_s else %{"#{val.to_s}"} end buf << " :#{key} => #{val_str}" end buf << [ "}#{@boost == 1.0 ? "" :... | Create a string representation of the document |
8,926 | def highlight ( query , doc_id , options = { } ) @dir . synchronize do ensure_searcher_open ( ) @searcher . highlight ( do_process_query ( query ) , doc_id , options [ :field ] || @options [ :default_field ] , options ) end end | If you create an Index without any options it ll simply create an index in memory . But this class is highly configurable and every option that you can supply to IndexWriter and QueryParser you can also set here . Please look at the options for the constructors to these classes . |
8,927 | def term_vector ( id , field ) @dir . synchronize do ensure_reader_open ( ) if id . kind_of? ( String ) or id . kind_of? ( Symbol ) term_doc_enum = @reader . term_docs_for ( @id_field , id . to_s ) if term_doc_enum . next? id = term_doc_enum . doc else return nil end end return @reader . term_vector ( id , field ) end ... | Retrieves the term_vector for a document . The document can be referenced by either a string id to match the id field or an integer corresponding to Ferret s document number . |
8,928 | def query_delete ( query ) @dir . synchronize do ensure_writer_open ( ) ensure_searcher_open ( ) query = do_process_query ( query ) @searcher . search_each ( query , :limit => :all ) do | doc , score | @reader . delete ( doc ) end flush ( ) if @auto_flush end end | Delete all documents returned by the query . |
8,929 | def update ( id , new_doc ) @dir . synchronize do ensure_writer_open ( ) delete ( id ) if id . is_a? ( String ) or id . is_a? ( Symbol ) @writer . commit else ensure_writer_open ( ) end @writer << new_doc flush ( ) if @auto_flush end end | Update the document referenced by the document number + id + if + id + is an integer or all of the documents which have the term + id + if + id + is a term .. For batch update of set of documents for performance reasons see batch_update |
8,930 | def batch_update ( docs ) @dir . synchronize do ids = nil case docs when Array ids = docs . collect { | doc | doc [ @id_field ] . to_s } if ids . include? ( nil ) raise ArgumentError , "all documents must have an #{@id_field} " "field when doing a batch update" end when Hash ids = docs . keys docs = docs . values else ... | Batch updates the documents in an index . You can pass either a Hash or an Array . |
8,931 | def query_update ( query , new_val ) @dir . synchronize do ensure_writer_open ( ) ensure_searcher_open ( ) docs_to_add = [ ] query = do_process_query ( query ) @searcher . search_each ( query , :limit => :all ) do | id , score | document = @searcher [ id ] . load if new_val . is_a? ( Hash ) document . merge! ( new_val ... | Update all the documents returned by the query . |
8,932 | def explain ( query , doc ) @dir . synchronize do ensure_searcher_open ( ) query = do_process_query ( query ) return @searcher . explain ( query , doc ) end end | Returns an Explanation that describes how + doc + scored against + query + . |
8,933 | def ensure_reader_open ( get_latest = true ) raise "tried to use a closed index" if not @open if @reader if get_latest latest = false begin latest = @reader . latest? rescue Lock :: LockError sleep ( @options [ :lock_retry_time ] ) latest = @reader . latest? end if not latest @searcher . close if @searcher @reader . cl... | returns the new reader if one is opened |
8,934 | def truncate ( str , len = 80 ) if str and str . length > len and ( add = str [ len .. - 1 ] . index ( ' ' ) ) str = str [ 0 , len + add ] + '…' end str end | truncates the string at the first space after + len + characters |
8,935 | def paginate ( idx , max , url , & b ) return '' if max == 0 url = url . gsub ( %r{ } , '\1' ) b ||= lambda { } link = lambda { | * args | i , title , text = args "<a href=\"/#{url}/#{i}#{'?' + @query_string if @query_string}\" " + "#{'onclick="return false;"' if (i == idx)} " + "class=\"#{'disabled ' if (i == idx)}#{b... | takes an optional block to set optional attributes in the links |
8,936 | def weight ( w ) OpenStruct . new ( { :x => w [ 0 ] * p0 . left + w [ 1 ] * p1 . left + w [ 2 ] * p2 . left + w [ 3 ] * p3 . left , :y => w [ 0 ] * p0 . top + w [ 1 ] * p1 . top + w [ 2 ] * p2 . top + w [ 3 ] * p3 . top } ) end | Returns the point that is the weighted sum of the specified control points using the specified weights . This method requires that there are four weights and four control points . |
8,937 | def save ( filename ) speech = bytes_wav res = IO . popen ( lame_command ( filename , command_options ) , 'r+' ) do | process | process . write ( speech ) process . close_write process . read end res . to_s end | Generates mp3 file as a result of Text - To - Speech conversion . |
8,938 | def bytes ( ) speech = bytes_wav res = IO . popen ( std_lame_command ( command_options ) , 'r+' ) do | process | process . write ( speech ) process . close_write process . read end res . to_s end | Returns mp3 file bytes as a result of Text - To - Speech conversion . |
8,939 | def array @entries = [ ] @stack = [ ] if @leaf recurse ( @map , 0 ) return @entries end visit ( @map , 0 ) @entries . map { | stack | m = { } @keys . each_with_index { | k , i | v = stack [ i ] m [ k . name ] = k . value ? k . value . js_call ( self , v ) : v } m } end | Returns the flattened array . Each entry in the array is an object ; each object has attributes corresponding to this flatten operator s keys . |
8,940 | def bind mark_bind bind = self . binds mark = self begin binds . image = mark . _image end while ( ! binds . image and ( mark == mark . proto ) ) end | Scan the proto chain for an image function . |
8,941 | def scale ( x ) return nil if x . nil? x = x . to_f j = Rubyvis . search ( @d , x ) j = - j - 2 if ( j < 0 ) j = [ 0 , [ @i . size - 1 , j ] . min ] . max @i [ j ] . call ( ( @f . call ( x ) - @l [ j ] ) . quo ( @l [ j + 1 ] - @l [ j ] ) ) ; end | Transform value + x + according to domain and range |
8,942 | def ticks ( subdivisions = nil ) d = domain n = d [ 0 ] < 0 subdivisions ||= @b span = @b . to_f / subdivisions i = ( n ? - log ( - d [ 0 ] ) : log ( d [ 0 ] ) ) . floor j = ( n ? - log ( - d [ 1 ] ) : log ( d [ 1 ] ) ) . ceil ticks = [ ] ; if n ticks . push ( - pow ( - i ) ) ( i .. j ) . each { | ii | ( ( @b - 1 ) ...... | Returns an array of evenly - spaced suitably - rounded values in the input domain . These values are frequently used in conjunction with Rule to display tick marks or grid lines . |
8,943 | def try ( * method_chain ) obj = self . element method_chain . each do | m | ( obj = nil ) && break unless obj . respond_to? ( m ) obj = obj . send ( m ) end obj end | Convenience method that takes a list of method calls and tries them end - to - end returning nil if any fail to respond to that method name . Very similar to ActiveSupport s . try method . |
8,944 | def memoize ( klass ) @memoize ||= { } @memoize [ klass ] ||= begin while klass break if registered_class = target_klasses [ klass ] klass = klass . superclass end @memoize [ klass ] = registered_class if registered_class end @memoize [ klass ] end | Cache registered classes |
8,945 | def create ( element , element_id = nil , & block ) element = initialize_element ( element , element_id ) style_and_context ( element , element_id , & block ) element end | instantiates a view possibly running a layout block to add child views . |
8,946 | def reapply ( & block ) raise ArgumentError . new ( 'Block required' ) unless block raise InvalidDeferredError . new ( 'reapply must be run inside of a context' ) unless @context if reapply? yield end block = block . weak! parent_layout . reapply_blocks << [ @context , block ] return self end | Blocks passed to reapply are only run when reapply! is called . |
8,947 | def get_view ( element_id ) element = get ( element_id ) if element . is_a? ( Layout ) element = element . view end element end | Just like get but if get returns a Layout this method returns the layout s view . |
8,948 | def last_view ( element_id ) element = last ( element_id ) if element . is_a? ( Layout ) element = element . view end element end | Just like last but if last returns a Layout this method returns the layout s view . |
8,949 | def all_views ( element_id ) element = all ( element_id ) if element . is_a? ( Layout ) element = element . view end element end | Just like all but if all returns a Layout this method returns the layout s view . |
8,950 | def nth_view ( element_id , index ) element = nth ( element_id ) if element . is_a? ( Layout ) element = element . view end element end | Just like nth but if nth returns a Layout this method returns the layout s view . |
8,951 | def forget ( element_id ) unless is_parent_layout? return parent_layout . remove ( element_id ) end removed = nil context ( self . view ) do removed = all ( element_id ) @elements [ element_id ] = nil end removed end | Removes a view from the list of elements this layout is tracking but leaves it in the view hierarchy . Returns the views that were removed . |
8,952 | def forget_tree ( element_id , view ) removed = forget_view ( element_id , view ) if view . subviews view . subviews . each do | sub | if ( sub_ids = sub . motion_kit_meta [ :motion_kit_ids ] ) sub_ids . each do | sub_id | forget_tree ( sub_id , sub ) || [ ] end end end end removed end | returns the root view that was removed if any |
8,953 | def build_view @assign_root = true prev_should_run = @should_run_deferred @should_run_deferred = true layout unless @view if @assign_root create_default_root_context @view = @context else NSLog ( 'Warning! No root view was set in TreeLayout#layout. Did you mean to call `root`?' ) end end run_deferred ( @view ) @should_... | This method builds the layout and returns the root view . |
8,954 | def initialize_element ( elem , element_id ) if elem . is_a? ( Class ) && elem < TreeLayout layout = elem . new elem = layout . view elsif elem . is_a? ( Class ) elem = elem . new elsif elem . is_a? ( TreeLayout ) layout = elem elem = elem . view end if layout if element_id name_element ( layout , element_id ) end @chi... | Initializes an instance of a view . This will need to be smarter going forward as new isn t always the designated initializer . |
8,955 | def style_and_context ( element , element_id , & block ) style_method = "#{element_id}_style" if parent_layout . respond_to? ( style_method ) || block_given? parent_layout . context ( element ) do if parent_layout . respond_to? ( style_method ) parent_layout . send ( style_method ) end if block_given? yield end end end... | Calls the _style method with the element as the context and runs the optional block in that context . This is usually done immediately after initialize_element except in the case of add which adds the item to the tree before styling it . |
8,956 | def context ( new_target , & block ) return new_target unless block return parent_layout . context ( new_target , & block ) unless is_parent_layout? if new_target . is_a? ( Symbol ) new_target = self . get_view ( new_target ) end context_was , parent_was , delegate_was = @context , @parent , @layout_delegate prev_shoul... | Runs a block of code with a new object as the context . Methods from the Layout classes are applied to this target object and missing methods are delegated to a new Layout instance that is created based on the new context . |
8,957 | def root ( element , element_id = nil , & block ) if element && element . is_a? ( NSString ) element = NSMenu . alloc . initWithTitle ( element ) end super ( element , element_id , & block ) end | override root to allow a menu title for the top level menu |
8,958 | def add ( title_or_item , element_id = nil , options = { } , & block ) if element_id . is_a? ( NSDictionary ) options = element_id element_id = nil end if title_or_item . is_a? ( NSMenuItem ) item = title_or_item menu = nil retval = item elsif title_or_item . is_a? ( NSMenu ) menu = title_or_item item = self . item ( m... | override add ; menus are just a horse of a different color . |
8,959 | def start_with_retry ( current_thread : false , ** retryable_options ) unless started? @retryable_options . set ( retryable_options ) start ( current_thread : current_thread ) end self end | Equivalent to retryable gem options |
8,960 | def on_complete ( & block ) on do | _ , value , reason | block . call ( reason == nil , value , reason ) end end | command . on_complete do |success value reason| ... end |
8,961 | def on_success ( & block ) on do | _ , value , reason | block . call ( value ) unless reason end end | command . on_success do |value| ... end |
8,962 | def on_failure ( & block ) on do | _ , _ , reason | block . call ( reason ) if reason end end | command . on_failure do |e| ... end |
8,963 | def prepare ( executor = @service . executor ) @normal_future = initial_normal ( executor , & @normal_block ) @normal_future . add_observer do | _ , value , reason | if reason if @fallback_block future = RichFuture . new ( executor : executor ) do success , value , reason = Concurrent :: SafeTaskExecutor . new ( @fallb... | set future set fallback future as an observer start dependencies |
8,964 | def initial_normal ( executor , & block ) future = RichFuture . new ( executor : executor ) do args = wait_dependencies timeout_block ( args , & block ) end future . add_observer do | _ , _ , reason | metrics ( reason ) end future end | timeout_block do retryable_block do breakable_block do block . call end end end |
8,965 | def invoke_pry org = Pry . config . history . file Pry . config . history . file = '~/.gdb-pry_history' $stdin . cooked { pry } Pry . config . history . file = org end | Invoke pry wrapper with some settings . |
8,966 | def text_base check_alive! base = Integer ( execute ( 'info proc stat' ) . scan ( / / ) . flatten . first ) execute ( "set $text = #{base}" ) base end | Get the process s text base . |
8,967 | def read_memory ( addr , num_elements , options = { } , & block ) check_alive! options [ :as ] = block if block_given? MemoryIO . attach ( @pid ) . read ( addr , num_elements , ** options ) end | Read current process s memory . |
8,968 | def write_memory ( addr , objects , options = { } , & block ) check_alive! options [ :as ] = block if block_given? MemoryIO . attach ( @pid ) . write ( addr , objects , ** options ) end | Write an object to process at specific address . |
8,969 | def lint ( config = nil ) config = config . is_a? ( Hash ) ? config : { files : config } files = config [ :files ] force_exclusion = config [ :force_exclusion ] || false report_danger = config [ :report_danger ] || false inline_comment = config [ :inline_comment ] || false fail_on_inline_comment = config [ :fail_on_inl... | Runs Ruby files through Rubocop . Generates a markdown list of warnings . |
8,970 | def name_for ( b , mod , val ) b . name_for ( mod , val ) . to_s . gsub ( / / , "" ) . downcase end | Determines the name for a |
8,971 | def scrub_sentence ( sentence ) sentence . split ( / \s / ) . collect { | a | scrub_word ( a ) } . select { | a | a . length > 0 } end | clean up all words in a string returning an array of clean words |
8,972 | def next_word ( word , randomizer = @randomizer ) return if ! markov_chains [ word ] sum = @markov_weighted_sum [ word ] random = randomizer . rand ( sum ) + 1 partial_sum = 0 ( markov_chains [ word ] . find do | w , count | partial_sum += count w! = word && partial_sum >= random end || [ ] ) . first end | Initialize a new instance . |
8,973 | def extend_trailing_preposition ( max_words , words ) while words . length < max_words && words [ - 1 ] && words [ - 1 ] [ PREPOSITION_REGEX ] words << model . next_word ( words [ - 1 ] , randomizer ) end words end | Check to see if the sentence ends in a PREPOSITION_REGEX word . If so add more words up to max - words until it does . |
8,974 | def sentence ( options = { } ) word = options [ :first_word ] || self . first_word num_words_option = options [ :words ] || ( 3 .. 15 ) count = Util . rand_count ( num_words_option , randomizer ) punctuation = options [ :punctuation ] || self . punctuation words = count . times . collect do word . tap { word = model . ... | return a random sentence |
8,975 | def paragraph ( options = { } ) count = Util . rand_count ( options [ :sentences ] || ( 5 .. 15 ) , randomizer ) count . times . collect do | i | op = options . clone op . delete :punctuation unless i == count - 1 op . delete :first_word unless i == 0 sentence op end . join ( " " ) end | return a random paragraph |
8,976 | def paragraphs ( options = { } ) count = Util . rand_count ( options [ :paragraphs ] || ( 3 .. 5 ) , randomizer ) join_str = options [ :join ] res = count . times . collect do | i | op = options . clone op . delete :punctuation unless i == count - 1 op . delete :first_word unless i == 0 paragraph op end join_str! = fal... | return random paragraphs |
8,977 | def index ( idx ) unless ( 0 ... length ) . cover? idx raise IndexError , "Index #{idx} outside of bounds 0..#{length - 1}" end ptr = GirFFI :: InOutPointer . new element_type , data_ptr + idx * element_size ptr . to_ruby_value end | Re - implementation of the g_array_index and g_ptr_array_index macros |
8,978 | def call ( env ) method = env [ REQUEST_METHOD ] context = @tracer . extract ( OpenTracing :: FORMAT_RACK , env ) if @trust_incoming_span scope = @tracer . start_active_span ( method , child_of : context , tags : { 'component' => 'rack' , 'span.kind' => 'server' , 'http.method' => method , 'http.url' => env [ REQUEST_U... | Create a new Rack Tracer middleware . |
8,979 | def mirror Minimart :: Commands :: Mirror . new ( options ) . execute! rescue Minimart :: Error :: BaseError => e Minimart :: Error . handle_exception ( e ) end | Mirror cookbooks specified in an inventory file . |
8,980 | def web Minimart :: Commands :: Web . new ( options ) . execute! rescue Minimart :: Error :: BaseError => e Minimart :: Error . handle_exception ( e ) end | Generate a web interface to download any mirrored cookbooks . |
8,981 | def cmd_pass ( param ) send_response "202 User already logged in" and return unless @user . nil? send_param_required and return if param . nil? send_response "530 password with no username" and return if @requested_user . nil? @driver . authenticate ( @requested_user , param ) do | result | if result @name_prefix = "/"... | handle the PASS FTP command . This is the second stage of a user logging in |
8,982 | def cmd_dele ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? path = build_path ( param ) @driver . delete_file ( path ) do | result | if result send_response "250 File deleted" else send_action_not_taken end end end | delete a file |
8,983 | def cmd_retr ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? path = build_path ( param ) @driver . get_file ( path ) do | data | if data send_response "150 Data transfer starting #{data.size} bytes" send_outofband_data ( data , @restart_pos || 0 ) else send_respon... | send a file to the client |
8,984 | def cmd_size ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? @driver . bytes ( build_path ( param ) ) do | bytes | if bytes send_response "213 #{bytes}" else send_response "450 file not available" end end end | return the size of a file in bytes |
8,985 | def cmd_stor ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? path = build_path ( param ) if @driver . respond_to? ( :put_file_streamed ) cmd_stor_streamed ( path ) elsif @driver . respond_to? ( :put_file ) cmd_stor_tempfile ( path ) else raise "driver MUST respond... | save a file from a client |
8,986 | def cmd_nlst ( param ) send_unauthorised and return unless logged_in? send_response "150 Opening ASCII mode data connection for file list" @driver . dir_contents ( build_path ( param ) ) do | files | send_outofband_data ( files . map ( & :name ) ) end end | return a listing of the current directory one per line each line separated by the standard FTP EOL sequence . The listing is returned to the client over a data socket . |
8,987 | def cmd_list ( param ) send_unauthorised and return unless logged_in? send_response "150 Opening ASCII mode data connection for file list" param = '' if param . to_s == '-a' @driver . dir_contents ( build_path ( param ) ) do | files | now = Time . now lines = files . map { | item | sizestr = ( item . size || 0 ) . to_s... | return a detailed list of files and directories |
8,988 | def cmd_rmd ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? @driver . delete_dir ( build_path ( param ) ) do | result | if result send_response "250 Directory deleted." else send_action_not_taken end end end | delete a directory |
8,989 | def parse_request ( data ) data . strip! space = data . index ( " " ) if space cmd = data [ 0 , space ] param = data [ space + 1 , data . length - space ] param = nil if param . strip . size == 0 else cmd = data param = nil end [ cmd . downcase , param ] end | split a client s request into command and parameter components |
8,990 | def cmd_help ( param ) send_response "214- The following commands are recognized." commands = COMMANDS str = "" commands . sort . each_slice ( 3 ) { | slice | str += " " + slice . join ( "\t\t" ) + LBRK } send_response str , true send_response "214 End of list." end | handle the HELP FTP command by sending a list of available commands . |
8,991 | def cmd_pasv ( param ) send_unauthorised and return unless logged_in? host , port = start_passive_socket p1 , p2 = * port . divmod ( 256 ) send_response "227 Entering Passive Mode (" + host . split ( "." ) . join ( "," ) + ",#{p1},#{p2})" end | Passive FTP . At the clients request listen on a port for an incoming data connection . The listening socket is opened on a random port so the host and port is sent back to the client on the control socket . |
8,992 | def cmd_port ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? nums = param . split ( ',' ) port = nums [ 4 ] . to_i * 256 + nums [ 5 ] . to_i host = nums [ 0 .. 3 ] . join ( '.' ) close_datasocket puts "connecting to client #{host} on #{port}" @datasocket = ActiveS... | Active FTP . An alternative to Passive FTP . The client has a listening socket open waiting for us to connect and establish a data socket . Attempt to open a connection to the host and port they specify and save the connection ready for either end to send something down it . |
8,993 | def cmd_type ( param ) send_unauthorised and return unless logged_in? send_param_required and return if param . nil? if param . upcase . eql? ( "A" ) send_response "200 Type set to ASCII" elsif param . upcase . eql? ( "I" ) send_response "200 Type set to binary" else send_response "500 Invalid type" end end | like the MODE and STRU commands TYPE dates back to a time when the FTP protocol was more aware of the content of the files it was transferring and would sometimes be expected to translate things like EOL markers on the fly . |
8,994 | def send_outofband_data ( data , restart_pos = 0 ) wait_for_datasocket do | datasocket | if datasocket . nil? send_response "425 Error establishing connection" else if data . is_a? ( Array ) data = data . join ( LBRK ) << LBRK end data = StringIO . new ( data ) if data . kind_of? ( String ) data . seek ( restart_pos ) ... | send data to the client across the data socket . |
8,995 | def wait_for_datasocket ( interval = 0.1 , & block ) if @datasocket . nil? && interval < 25 if EM . reactor_running? EventMachine . add_timer ( interval ) { wait_for_datasocket ( interval * 2 , & block ) } else sleep interval wait_for_datasocket ( interval * 2 , & block ) end return end yield @datasocket end | waits for the data socket to be established |
8,996 | def receive_outofband_data ( & block ) wait_for_datasocket do | datasocket | if datasocket . nil? send_response "425 Error establishing connection" yield false else send_response "150 Data transfer starting" datasocket . callback do | data | block . call ( data ) end end end end | receive a file data from the client across the data socket . |
8,997 | def where ( options = { } ) options . merge! ( key : @api_key , vintage : @api_vintage ) fail "Client requires a dataset (#{DATASETS})." if @dataset . nil? [ :fields , :level ] . each do | f | fail ArgumentError , "#{f} is a requied parameter" if options [ f ] . nil? end options [ :within ] = [ options [ :within ] ] un... | can add more datasets as support becomes available |
8,998 | def add_dnsbl ( name , domain , type = 'ip' , codes = { "0" => "OK" , "127.0.0.2" => "Blacklisted" } ) @dnsbls [ name ] = codes @dnsbls [ name ] [ 'domain' ] = domain @dnsbls [ name ] [ 'type' ] = type end | allows the adding of a new DNSBL to the set of configured DNSBLs |
8,999 | def _encode_query ( item , itemtype , domain , apikey = nil ) label = nil if itemtype == 'ip' label = item . split ( / \. / ) . reverse . join ( "." ) elsif itemtype == 'domain' label = normalize ( item ) end lookup = "#{label}.#{domain}" if apikey lookup = "#{apikey}.#{lookup}" end txid = lookup . sum message = Resolv... | converts an ip or a hostname into the DNS query packet requires to lookup the result |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.