idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
24,900 | def add_link_attribute ( mut_attr_string ) range_pointer = Pointer . new ( NSRange . type ) attributes = mut_attr_string . attributesAtIndex ( 0 , effectiveRange : range_pointer ) . dup attributes [ NSFontAttributeName ] = self . font attributes [ NSForegroundColorAttributeName ] = self . textColor mut_attr_string . addAttributes ( attributes , range : range_pointer [ 0 ] ) active_elements . each do | type , elements | case type when :mention then attributes [ NSForegroundColorAttributeName ] = mention_color when :hashtag then attributes [ NSForegroundColorAttributeName ] = hashtag_color when :url then attributes [ NSForegroundColorAttributeName ] = url_color when :category then attributes [ NSForegroundColorAttributeName ] = category_color end elements . each do | element | mut_attr_string . setAttributes ( attributes , range : element . range ) end end end | add link attribute |
24,901 | def empty_nil_blank? ( str , raize = false ) result = ( str !~ / / || str . nil? || str . empty? ) raise ShellTastic :: CommandException . new ( "Command is emtpy or nil" ) if result and raize result end | like the other methods but allow to set an exception flag |
24,902 | def load_config path = ENV [ 'HOME' ] + '/.nadb.config' if ! File . exists? ( path ) return end @config = JSON . parse ( File . read ( path ) ) end | Load config from the file if any exists |
24,903 | def run_adb_command ( command , device = nil ) full_command = construct_adb_command command , device puts full_command pio = IO . popen ( full_command , 'w' ) Process . wait ( pio . pid ) end | Run an adb commd on specified device optionally printing the output |
24,904 | def get_connected_devices get_adb_command_output ( 'devices' ) . drop ( 1 ) . map { | line | line . split [ 0 ] } . reject { | d | d . nil? || d . empty? } end | Get all currently connected android devices |
24,905 | def fridge_asset ( input ) return input unless input if input . respond_to? ( 'first' ) input = input . first [ 'name' ] end site = @context . registers [ :site ] asset_dir = site . config [ 'fridge' ] . config [ 'asset_dir' ] dest_path = File . join ( site . dest , asset_dir , input ) path = File . join ( asset_dir , input ) if site . keep_files . index ( path ) != nil return "/#{path}" end asset = site . config [ 'fridge' ] . client . get ( "content/upload/#{input}" ) return input unless asset site . keep_files << path FileUtils . mkdir_p ( File . dirname ( dest_path ) ) File . write ( dest_path , asset ) "/#{path}" end | Filter for fetching assets Writes static file to asset_dir and returns absolute file path |
24,906 | def cover ( path , options = { } ) reset = options . delete :reset cook_layer do @dressing << Proc . new { self . reset if commits . any? } if reset Git :: Base . open path if can_cover? path end end | hands on the handler |
24,907 | def matches? query query . reduce ( true ) do | matches , ( key , value ) | matches = if key == 'tag' return false unless tags . present? tags . include? value else attributes [ key ] == value end end end | Test if the query matches this particular model . |
24,908 | def validate_driver_config! ( driver_config ) raise_argument_error! ( :host ) unless driver_config . has_key? :host raise_argument_error! ( :port ) unless driver_config . has_key? :port raise_argument_error! ( :namespace ) unless driver_config . has_key? :namespace raise_argument_error! ( :timeout_sec ) unless driver_config . has_key? :timeout_sec raise_argument_error! ( :pool_size ) unless driver_config . has_key? :pool_size driver_config [ :config_key ] = :none unless driver_config . has_key? :config_key return driver_config end | Validate driver_config . This method raise ArgumentError if missing driver_config . |
24,909 | def update_on_instance_created ( clazz , on_instance_created ) return unless on_instance_created clazz . instance_eval do def instance_hooks hooks = ( self . ancestors + [ self ] ) . map do | target | target . instance_variable_get ( :@instance_hooks ) end hooks . flatten! hooks . compact! hooks . uniq! hooks end @instance_hooks ||= [ ] @instance_hooks << on_instance_created end end | This hook allows other tracing in Hometown to get a whack at an object after it s been created without forcing them to patch new themselves |
24,910 | def encrypt ( field ) return if field !~ / \S / aes = OpenSSL :: Cipher . new ( symmetric_algorithm ) aes_key = aes . random_key iv = aes . random_iv encrypt_data ( iv , aes_key , field . force_encoding ( encoding ) ) end | Return encrypted string according to specified format . Return nil if field is whitespace . |
24,911 | def parse ( iv , encrypted_key , encrypted_text ) case @format when :delimited [ iv , field_delimiter , encrypted_key , field_delimiter , encrypted_text ] . join ( '' ) when :json hash = { } hash [ 'iv' ] = iv hash [ 'key' ] = encrypted_key hash [ 'message' ] = encrypted_text hash . to_json end end | Format the final encrypted string to be returned depending on specified format . |
24,912 | def save_cfror_fields ( fields ) fields . each do | field , value | field = Cfror :: Field . find ( field ) field . save_value! ( self , value ) end end | save fields value |
24,913 | def value_fields_for ( source , order = nil ) fields = self . send ( source ) . fields fields = fields . order ( order ) if order fields . each do | i | i . set_value_for ( self ) end fields end | set values for fields |
24,914 | def method_missing ( meth , * _args , & block ) format = FormatRegistry . formats [ meth ] return unless format && format . match? ( @route_handler . request ) @candidates << format @blocks [ meth ] = block end | Creates a format handler for a route handler |
24,915 | def parse_params ( request ) json = request . body . read JSON . parse ( json ) . symbolize_keys if json . is_a? ( String ) && ! json . empty? end | Parses JSON string in request body if present and converts it to a hash . |
24,916 | def encode ( response ) json = response . to_json [ 200 , { Rack :: CONTENT_TYPE => 'application/json' , Rack :: CONTENT_LENGTH => json . length . to_s } , [ json ] ] end | Encodes response appropriately by converting it to a JSON string . |
24,917 | def upload! ( local_file ) @remote . directory . files . create ( key : local_file . key , body : local_file . body , cache_control : "public, max-age=#{max_age(local_file)}" , public : true ) end | If file already exists on remote it will be overwritten . |
24,918 | def obfuscate ( plain ) codepoints = plain . codepoints raise FormatError if codepoints . length > 8 password = Array . new ( 8 , 0x0E ) codepoints . each_with_index do | c , i | password [ i ] = ( c & 0x40 ) | ( ~ c & 0x3F ) end password . pack 'c*' end | Transforms a plain text password into an 8 character string recognised by the ADAM - 6050 . The algorithm if you can even call it that used to perform the transformation was found by trial and error . |
24,919 | def to_yaml ( opts = { } ) if YAML . const_defined? ( :ENGINE ) && ! YAML :: ENGINE . syck? super else coder = { } encode_with ( coder ) YAML . quick_emit ( self , opts ) do | out | out . map ( taguri , to_yaml_style ) do | map | coder . each { | k , v | map . add ( k , v ) } end end end end | Hackery to accomodate Syck . Remove for 4 . 0 . |
24,920 | def walk ( s = nil ) s ||= @root if [ :module , :class ] . member? ( s [ 0 ] ) add_node s elsif find_relations? && s [ 0 ] == :call && s . length >= 4 && [ :extend , :include ] . member? ( s [ 2 ] ) && ! @graph . scope . empty? add_relation s else walk_siblings s . slice ( 1 .. - 1 ) end end | Initialize a walker with a graph and sexp |
24,921 | def delimited ( nodes , delimiter = ', ' ) max = nodes . length - 1 nodes . each_with_index do | element , index | element . visit ( self ) append ( delimiter ) if index < max end self end | Emit delimited nodes |
24,922 | def rates ( rates_request ) rates_uri = "#{oanda_endpoint}#{RATES_BASE_PATH}#{rates_request.base_currency}.json?#{rates_request.query_string}" rates_response = HTTParty . get ( rates_uri , headers : oanda_headers ) handle_response ( rates_response . response ) OpenStruct . new ( rates_response . parsed_response ) end | Returns the exchanges rates based on the specified request |
24,923 | def remaining_quotes remaining_quotes_response = HTTParty . get ( "#{oanda_endpoint}#{REMAINING_QUOTES_PATH}" , headers : oanda_headers ) handle_response ( remaining_quotes_response . response ) remaining_quotes_response . parsed_response [ 'remaining_quotes' ] end | Returns the number of remaining quote requests |
24,924 | def reset_motor_position port , set_relative transmit ( DirectOps :: NO_RESPONSE , DirectOps :: RESETMOTORPOSITION , normalize_motor_port ( port ) , normalize_boolean ( set_relative ) ) end | Resets the tracking for the motor position . |
24,925 | def run_motor port , power = 100 raise ArgumentError . new ( "Power must be -100 through 100" ) if power < - 100 || power > 100 transmit ( DirectOps :: NO_RESPONSE , DirectOps :: SETOUTPUTSTATE , normalize_motor_port ( port , true ) , sbyte ( power ) , byte ( 1 ) , byte ( 0 ) , sbyte ( 0 ) , byte ( 0x20 ) , long ( 0 ) , ) end | Runs the motor |
24,926 | def transceive * bits bitstring = bits . map ( & :byte_string ) . join ( "" ) retval = connection . transceive bitstring raise :: LegoNXT :: BadResponseError unless retval [ 0 ] == "\x02" raise :: LegoNXT :: BadResponseError unless retval [ 1 ] == bitstring [ 1 ] raise :: LegoNXT :: StatusError unless retval [ 2 ] == "\x00" return retval [ 3 .. - 1 ] end | A wrapper around the transceive function for the connection . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.