idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
22,700 | def pubsub ( nid = nil ) node_jid = if nid JID . new ( jid . node , jid . domain , nid ) else jid . to_s end PubSub . new ( connection , node_jid ) end | returns a PubSub entity with same bare jid accepts an optional node - id |
22,701 | def muc ( nick = nil ) muc_jid = JID . new jid . node , jid . domain , nick Muc . new ( connection , muc_jid ) end | Generates a MUC entity from this entity . If the nick argument is null then the entity is the MUC itself . If the nick argument is present then the entity is the user with the corresponding nickname . |
22,702 | def versions_average_for_attribute ( att , opts = { } ) _use_delta = opts [ :delta ] || false if _use_delta return historical_rate_per_day ( att , nil , nil ) else data = versions_complete_data_for_attribute ( att , opts ) return data . e_mean end end | returns Float this is wonky because of the wonky way we use historical_rate_by_day |
22,703 | def phone @phone ||= -> { mac = Jia :: Utils . load_data ( 'phone_mac' ) . sample area_code = rand ( 9999 ) . to_s . center ( 4 , rand ( 9 ) . to_s ) user_identifier = rand ( 9999 ) . to_s . center ( 4 , rand ( 9 ) . to_s ) "#{mac}#{area_code}#{user_identifier}" } . call end | Get phone number |
22,704 | def match? ( time , base ) aligned? ( time , base ) && @filters . all? { | f | f . match? ( time ) } end | returns true if time is aligned to the recurrence pattern and matches all the filters |
22,705 | def potential_previous ( current , base ) @filters . map { | f | f . previous ( current ) } . min || current end | Find a potential previous date matching the rule as a minimum of previous valid dates from all the filters . Subclasses should add a check of recurrence pattern match |
22,706 | def to_hash self . instance_variables . inject ( { } ) { | m , v | m [ v [ 1 , v . length ] . to_sym ] = instance_variable_get ( v ) ; m } end | Creates a Hash representation of self |
22,707 | def build_tasks load_rakefile Rake . application . tasks . reject { | t | t . comment . nil? } end | Coals assumes that any task lacking a description is not meant to be called directly i . e . a subtask This is in line with the list rendered by rake - T |
22,708 | def check_lato_blog_post_parent post_parent = LatoBlog :: PostParent . find_by ( id : lato_blog_post_parent_id ) if ! post_parent errors . add ( 'Post parent' , 'not exist for the post' ) throw :abort return end same_language_post = post_parent . posts . find_by ( meta_language : meta_language ) if same_language_post &... | This function check that the post parent exist and has not others post for the same language . |
22,709 | def add_to_default_category default_category_parent = LatoBlog :: CategoryParent . find_by ( meta_default : true ) return unless default_category_parent category = default_category_parent . categories . find_by ( meta_language : meta_language ) return unless category LatoBlog :: CategoryPost . create ( lato_blog_post_i... | This function add the post to the default category . |
22,710 | def call ( function , params ) start req = Net :: HTTP :: Post . new ( DEFAULT_PATH ) req . add_field ( 'Content-Type' , 'application/json; charset=utf-8' ) req . body = URI :: encode ( { :jsonrpc => :' ' , :method => function , :params => params , :id => 0 } . to_json ( { :ascii_only => true } ) ) begin res = @conn . ... | Calls the given function with the given parameters via the JSON interface of Scalaris . |
22,711 | def string_format ( command_environment . map do | key , value | [ key , value ] . join ( "=" ) end + [ command ] ) . join ( " " ) end | The command as a string including arguments and options plus prefixed environment variables . |
22,712 | def call ( severity , time , progname , msg ) msg = Format % [ format_datetime ( time ) , severity , $$ , progname , msg2str ( msg ) ] msg = @@colors [ severity ] + msg + @@colors [ 'DEFAULT' ] if @@colorize msg << "\n" end | This method is invoked when a log event occurs |
22,713 | def search ( query , pages = 1 , orderby = 99 ) get = make_search_request ( query , pages , orderby ) raise "Invalid response: #{get.response.code}" unless get . response . code == "200" return parse_search_results ( get . response . body ) end | remember the domain name and get the cookie to use from the TPB server search torrents |
22,714 | def post ( path , options = { } , headers = { } , raw = false ) request ( :post , path , options , headers , raw ) end | Performs an HTTP POST request |
22,715 | def put ( path , options = { } , headers = { } , raw = false ) request ( :put , path , options , headers , raw ) end | Performs an HTTP PUT request |
22,716 | def delete ( path , options = { } , headers = { } , raw = false ) request ( :delete , path , options , headers , raw ) end | Performs an HTTP DELETE request |
22,717 | def to_stub stub = "## #{name}\n" stub << "# #{description}\n" unless description . nil? stub << "#{entry_for_refuse_allow_behavior}\n" unless refuses . nil? and allows . nil? stub << "#{entry_for_key_value}\n" stub << "\n" end | Initialize the option |
22,718 | def format ( message , colour = nil , style = nil ) c = @map [ :colour ] [ colour . to_sym ] unless colour . nil? if style . nil? t = 0 else t = @map [ :style ] [ style . to_sym ] end "\e[#{t};#{c}m#{message}\e[0m" end | Create the map hash |
22,719 | def update if ( results = what_changed? ) [ :ary ] update_ptr update_ary_cache true elsif results [ :ptr ] update_ary update_ptr_cache true else false end end | detects what changed and updates as needed |
22,720 | def update_ptr ptr . clear if ( not ( arry_type = self . class . ary_type ) . is_a? ( Symbol ) ) if arry_type . respond_to? :to_native ary . each { | item | ptr . write_pointer ( arry_type . to_native ( item , nil ) ) } elsif arry_type . method_defined? :bytes ptr . write_bytes ( ary . map { | item | item . respond . b... | this is slightly dangerous if anything was still pointing to old pointer location now its being reclaimed this will change it |
22,721 | def method_missing m , * args , & block if method_name_is_tag_name? m return assign_tag ( m , args , & block ) elsif method_name_is_tag_adder_method? m return extend_tag_list ( m , args , & block ) elsif method_name_is_tag_list_method? m return child_tags [ m [ 0 .. - 6 ] . to_sym ] ||= [ ] elsif method_name_is_attr_ac... | Handles methods corresponding to a tag name ending with either _list or _attr or starting with add_ . |
22,722 | def summary text_array = to_text . split ( "\n" ) text = text_array [ 0 ] i = 1 while text . length <= 140 && i < text_array . length text << "\n" + text_array [ i ] i += 1 end text end | Returns a short summary that is at least 140 characters long |
22,723 | def upgrade! access_token = nil transaction do access_token = OauthProviderEngine :: AccessToken . create! ( { :application_id => self . application_id , :user_id => self . user_id , } ) self . destroy || raise ( ActiveRecord :: Rollback ) end return access_token end | this method with upgrade the RequestToken to an AccessToken note that this will destroy the current RequestToken |
22,724 | def sorted_puts ( line ) if line == nil || line . size == 0 raise ArgumentError , 'Line cannot be blank!' end if line . index ( $/ ) raise ArgumentError , "Cannot `puts` a line with extra line endings. Make sure the line does not contain `#{$/.inspect}`" end matched , idx = binary_seek ( line ) if matched else if idx =... | adds the line to the while maintaining the data s sort order |
22,725 | def index_each_line positions = [ ] size = 0 each_line do | line | positions << [ size , line . size ] size += line . size end rewind positions end | Builds an Array of position and length of the current file . |
22,726 | def do_at_current_position ( & block ) current_position = self . tell huge_buffer = self . read self . seek ( current_position , IO :: SEEK_SET ) block . call ensure self . write huge_buffer end | remembers current file position reads everything at the position execute the block and put everything back . This routine is really bad for huge files since it could run out of memory . |
22,727 | def prepare ( method , request_uri , params = { } ) method = method . downcase . to_s if TheBigDB . api_key . is_a? ( String ) and ! TheBigDB . api_key . empty? params . merge! ( "api_key" => TheBigDB . api_key ) end request_uri = "/v#{TheBigDB.api_version}" + ( request_uri . start_with? ( "/" ) ? request_uri : "/#{req... | Prepares the basic |
22,728 | def execute params = Rack :: Utils . parse_nested_query ( URI . parse ( @http_request . path ) . query ) params . merge! ( Rack :: Utils . parse_nested_query ( @http_request . body . to_s ) ) @data_sent = { "headers" => Hash [ @http_request . to_hash . map { | k , v | [ k , v . join ] } ] , "host" => @http . address , ... | Actually makes the request prepared in |
22,729 | def find ( group , * affiliate_ids ) candidates = self . select { | gm | gm . group . include? ( group ) } return candidates if affiliate_ids . empty? candidates . select { | gm | affiliate_ids . detect { | id | gm . include_affiliate? ( id ) } } end | Finds the group memberships that match the given group possibly constrained by one or more affiliates . |
22,730 | def session ( driver_config , & block ) driver_config = validate_driver_config! ( driver_config ) driver_connection_pool ( self , driver_config ) . with do | kvs_instance | block . call ( self . new ( kvs_instance , driver_config ) ) end end | connect kvs and exec block . This function pools the connecting driver . |
22,731 | def driver_connection_pool ( driver_class , driver_config ) pool = search_driver_connection_pool ( driver_class , driver_config ) return ( pool . nil? ) ? set_driver_connection_pool ( driver_class , driver_config ) : pool end | get driver connection pool if doesn t exist pool it s made newly . |
22,732 | def set_driver_connection_pool ( driver_class , driver_config ) conf = { size : driver_config [ :pool_size ] , timeout : driver_config [ :timeout_sec ] } pool = ConnectionPool . new ( conf ) { driver_class . connect ( driver_config ) } RailsKvsDriver :: KVS_CONNECTION_POOL [ driver_class . name ] ||= Array . new RailsK... | set driver connection pool |
22,733 | def search_driver_connection_pool ( driver_class , driver_config ) if RailsKvsDriver :: KVS_CONNECTION_POOL . has_key? ( driver_class . name ) RailsKvsDriver :: KVS_CONNECTION_POOL [ driver_class . name ] . each do | pool_set | return pool_set [ :pool ] if equal_driver_config? ( pool_set [ :config ] , driver_config ) e... | search driver connection pool |
22,734 | def equal_driver_config? ( config1 , config2 ) return false unless config1 [ :host ] == config2 [ :host ] return false unless config1 [ :port ] == config2 [ :port ] return false unless config1 [ :timeout_sec ] == config2 [ :timeout_sec ] return false unless config1 [ :pool_size ] == config2 [ :pool_size ] return false ... | compare driver config . |
22,735 | def validate_args_count ( expected , got ) if ( expected . is_a? ( Numeric ) and expected != got ) or ( expected . is_a? ( Range ) and ! ( expected === got ) ) raise ArgumentError , "wrong number of arguments for '#{name}' (#{got} for #{expected})" end end | following methods are used for calling from the function block raise an error if argument count got does not match the expected |
22,736 | def extensions! ( * extension_syms ) return extension_syms if extension_syms . length == 0 extension_syms = extension_syms . flatten . collect { | es | es . to_sym } . compact if extension_syms . include? ( :all ) ordered_extension_syms = self . extension_include_order . dup else extensions_without_defined_order = exte... | Load specified extensions in the order defined by self . extension_include_order . |
22,737 | def new @element = Humpyard :: config . element_types [ params [ :type ] ] . new ( :page_id => params [ :page_id ] , :container_id => params [ :container_id ] . to_i > 0 ? params [ :container_id ] . to_i : nil , :page_yield_name => params [ :yield_name ] . blank? ? 'main' : params [ :yield_name ] , :shared_state => 0 )... | Dialog content for a new element |
22,738 | def create @element = Humpyard :: config . element_types [ params [ :type ] ] . new params [ :element ] unless can? :create , @element . element render :json => { :status => :failed } , :status => 403 return end if @element . save @prev = Humpyard :: Element . find_by_id ( params [ :prev_id ] ) @next = Humpyard :: Elem... | Create a new element |
22,739 | def update @element = Humpyard :: Element . find ( params [ :id ] ) if @element unless can? :update , @element render :json => { :status => :failed } , :status => 403 return end if @element . content_data . update_attributes params [ :element ] render :json => { :status => :ok , :dialog => :close , :replace => [ { :ele... | Update an existing element |
22,740 | def move @element = Humpyard :: Element . find ( params [ :id ] ) if @element unless can? :update , @element render :json => { :status => :failed } , :status => 403 return end @element . update_attributes ( :container => Humpyard :: Element . find_by_id ( params [ :container_id ] ) , :page_yield_name => params [ :yield... | Move an element |
22,741 | def api_modes = ( * new_modes ) new_modes = new_modes . first if new_modes . size == 1 && Array === new_modes . first @api_modes = new_modes . compact . collect ( & :to_sym ) end | Replaces the non - interactive authentication modes . |
22,742 | def central ( filename ) params = :: Aker :: CentralParameters . new ( filename ) params . each { | k , v | add_parameters_for ( k , v ) } end | Loads parameters from the given aker central parameters file . |
22,743 | def configure ( elf_file , target = @targets . keys . first ) target = target . to_s memory_map = "#@base_path/#{@targets[target]['memory_map']}" bit_file = "#@base_path/#{@targets[target]['bit_file']}" p target , bit_file hex = with_temporary_files { | dest , _ | system ( "avr-objcopy -O ihex -R .eeprom -R .fuse -R .l... | Initializes a new instance of a Core object . |
22,744 | def with_temporary_files ( file_contents = '' , dest_extension = '' , source_extension = '' , message = nil ) file_mode = File :: CREAT | File :: RDWR Tempfile . open ( [ 'core_prev' , source_extension ] , :mode => file_mode ) do | source_file | source_file . write ( file_contents ) source_file . flush Tempfile . open ... | Executes a given block with an anonymous temporary file . The temporary file is deleted at the end of the block and its contents are returned . |
22,745 | def to_s return '#' + r . to_s ( 16 ) . rjust ( 2 , '0' ) + g . to_s ( 16 ) . rjust ( 2 , '0' ) + b . to_s ( 16 ) . rjust ( 2 , '0' ) end | Create new color from a hex value |
22,746 | def request ( method , path , params = { } ) headers = @default_headers . merge ( { 'Authorization' => "Bearer #{@access_token}" } ) result = http_client . send_request ( method , path , { :params => params , :headers => headers } ) result end | Makes an HTTP request using the provided parameters |
22,747 | def app_servers ret = @servers . select { | s | s . nickname =~ / / } raise "No app servers in deployment" unless ret . length > 0 ret end | returns an Array of the App Servers in the deployment |
22,748 | def duration return nil unless valid? units = raw_duration . split ( ":" ) ( units [ 0 ] . to_i * 60 * 60 * 1000 ) + ( units [ 1 ] . to_i * 60 * 1000 ) + ( units [ 2 ] . to_f * 1000 ) . to_i end | The duration of the movie in milliseconds as an integer . |
22,749 | def valid? return false unless @domain Timeout . timeout ( SERVER_TIMEOUT ) do return true if valid_mx_records? return true if a_records? end rescue Timeout :: Error , Errno :: ECONNREFUSED false end | Returns a new instance of Domain |
22,750 | def valid_mx_records? mx_servers . each do | server | exchange_a_records = dns . getresources ( server [ :address ] , Resolv :: DNS :: Resource :: IN :: A ) return true if exchange_a_records . any? end false end | Check if the domian has valid MX records and it can receive emails . The MX server exists and it has valid A records . |
22,751 | def mx_servers return @mx_servers if @mx_servers @mx_servers = [ ] mx_records . each do | mx | @mx_servers . push ( preference : mx . preference , address : mx . exchange . to_s ) end @mx_servers end | The servers that this domian MX records point at . |
22,752 | def bits_for ( * field_names ) bits = [ ] field_names . flatten . each do | i | if i . is_a? ( Integer ) bits << i next end if i . respond_to? ( :to_sym ) and @field_list [ i . to_sym ] bits << @field_list [ i . to_sym ] end end bits . flatten end | Initialize the generator . |
22,753 | def each_value ( each_bits = nil , & block ) yield 0 count = 1 if @options [ :default ] != 0 yield @options [ :default ] count += 1 end each_bits = self . bits if each_bits == nil 1 . upto ( each_bits . length ) . each do | i | each_bits . combination ( i ) . each do | bits_list | num = bits_list . reduce ( 0 ) { | m ,... | Iterates over the entire combination of all possible values utilizing the list of bits we are given . |
22,754 | def all_values ( each_bits = nil , opts = { warn_threshold : 12 } ) if each_bits . is_a? ( Hash ) opts = each_bits each_bits = nil end each_bits = self . bits if each_bits == nil if opts [ :warn_threshold ] and each_bits . length > opts [ :warn_threshold ] warn "There are #{each_bits.length} bits. You will have #{2**(e... | Gives you an array of all possible integer values based off the bit combinations of the bit list . |
22,755 | def equal_to ( field_values = { } ) all_num , none_num = self . equal_to_numbers ( field_values ) [ ] . tap do | list | self . each_value { | num | list << num if ( num & all_num ) == all_num and ( num & none_num ) == 0 } end end | Gives you an array of values where the given field names are exactly equal to their given field values . |
22,756 | def equal_to_numbers ( field_values = { } ) fields = { } field_values . each_pair do | field_name , v | bits = self . bits_for ( field_name ) fields [ bits ] = v if bits . length > 0 end all_num = 0 none_num = 0 fields . each_pair { | field_bits , val | field_bits . each_with_index do | bit , i | if @options [ :bool_ca... | Will return an array of two numbers the first of which has all bits set where the corresponding value bit is 1 and the second has all bits set where the corresponding value bit is 0 . These numbers can be used in advanced bitwise operations to test fields for exact equality . |
22,757 | def get_all_category_children direct_children = self . category_children all_children = [ ] direct_children . each do | direct_child | all_children . push ( direct_child ) all_children = all_children + direct_child . get_all_category_children end all_children end | This function return all category children of the current category . |
22,758 | def lunar_date ( ) l = convert ( @date . year , @date . month , @date . day ) l [ 0 ] . to_s + "-" + l [ 1 ] . to_s + "-" + ( / \d / . match ( l [ 2 ] . to_s ) ) . to_s end | Get the Lundar date in xxxx - xx - xx fromat |
22,759 | def days_in_lunar_date ( y ) sum = 348 i = 0x8000 while i > 0x8 if ( ( @@lunar_info [ y - 1900 ] & i ) != 0 ) sum += 1 end i >>= 1 end sum + leap_days ( y ) end | Return the days in lunar of y year . |
22,760 | def to_dropdown ( selection = nil , nil_name = '** UNDEFINED **' ) dropdown_cache . inject ( "<option value=''>#{nil_name}</option>\n" ) do | out , row | selected = 'selected' if row [ 0 ] == selection "%s%s%s%s" % [ out , row [ 1 ] , selected , row [ 2 ] ] end end | Cache dropdown options for children classes to use Meant to be reseted each time an entry is created updated or destroyed So it is only rebuild once required after the list has changed Maintaining an array and not rebuilding it all might be faster But it will not happen much so that it is fairly acceptable |
22,761 | def crushyfield ( col , o = { } ) return '' if ( o [ :type ] == :none || model . crushyform_schema [ col ] [ :type ] == :none ) field_name = o [ :name ] || model . crushyform_schema [ col ] [ :name ] || col . to_s . sub ( / / , '' ) . tr ( '_' , ' ' ) . capitalize error_list = errors . on ( col ) . map { | e | " - #{e}... | crushyfield is crushyinput but with label + error |
22,762 | def to_thumb ( c ) current = self . __send__ ( c ) if model . respond_to? ( :stash_reflection ) && model . stash_reflection . key? ( c ) ! current . nil? && current [ :type ] [ / \/ / ] ? "<img src='#{file_url(c, 'stash_thumb.gif')}?#{::Time.now.to_i.to_s}' /><br />\n" : '' else "<img src='#{current}?#{::Time.now.to_i.... | Provide a thumbnail for the column |
22,763 | def parse ( message ) message . chomp! if message =~ / \S / if @config . hide_ping_pongs send_data message . sub ( / / , 'PONG' ) else @loggers . info "<< #{message}" raw message . sub ( / / , 'PONG' ) end else @loggers . info "<< #{message}" event_data = IRC :: Events :: Parser . parse ( message , @isupport [ 'CHANTYP... | parsing incoming traffic |
22,764 | def setup_default_callbacks on :query , / \001 \d \001 / do | event_data | time = event_data [ :message ] . scan ( / \d / ) [ 0 ] notice event_data [ :nick ] , "\001PING #{time}\001" end on :query , / \001 \001 / do | event_data | notice event_data [ :nick ] , "\001VERSION Ponder #{Ponder::VERSION} (https://github.com/... | Default callbacks for PING VERSION TIME and ISUPPORT processing . |
22,765 | def lut_write_to_cache ( lut_key ) if lut_options ( lut_key ) [ :sql_mode ] count = lut_write_to_cache_sql_mode ( lut_key ) else count = lut_write_to_cache_no_sql_mode ( lut_key ) end lut_write_cache_item ( lut_key , count , nil ) end | Write a LookUpTable into Cache |
22,766 | def template ( src , dst , ** context ) rendered = TemplateRenderer . render ( File . read ( src ) , context ) File . write ( dst , rendered ) end | Reads from a erb file and renders the content with context |
22,767 | def inline_template ( name , dst , ** context ) templates = { } begin app , data = File . read ( caller . first . split ( ":" ) . first ) . split ( "__END__" , 2 ) rescue Errno :: ENOENT app , data = nil end data . strip! if data template = nil data . each_line do | line | if line =~ / \s \S \s / template = String . ne... | Reads from a embedded template in the rake task itself . |
22,768 | def delete ( key ) log "deleting #{key} from #{container_path}" object_path = File . join ( container_path , Raca :: Util . url_encode ( key ) ) response = storage_client . delete ( object_path ) ( 200 .. 299 ) . cover? ( response . code . to_i ) end | Delete + key + from the container . If the container is on the CDN the object will still be served from the CDN until the TTL expires . |
22,769 | def object_metadata ( key ) object_path = File . join ( container_path , Raca :: Util . url_encode ( key ) ) log "Requesting metadata from #{object_path}" response = storage_client . head ( object_path ) { :content_type => response [ "Content-Type" ] , :bytes => response [ "Content-Length" ] . to_i } end | Returns some metadata about a single object in this container . |
22,770 | def download ( key , filepath ) log "downloading #{key} from #{container_path}" object_path = File . join ( container_path , Raca :: Util . url_encode ( key ) ) outer_response = storage_client . get ( object_path ) do | response | File . open ( filepath , 'wb' ) do | io | response . read_body do | chunk | io . write ( ... | Download the object at key into a local file at filepath . |
22,771 | def list ( options = { } ) max = options . fetch ( :max , 100_000_000 ) marker = options . fetch ( :marker , nil ) prefix = options . fetch ( :prefix , nil ) details = options . fetch ( :details , nil ) limit = [ max , MAX_ITEMS_PER_LIST ] . min log "retrieving up to #{max} items from #{container_path}" request_path = ... | Return an array of files in the container . |
22,772 | def metadata log "retrieving container metadata from #{container_path}" response = storage_client . head ( container_path ) custom = { } response . each_capitalized_name { | name | custom [ name ] = response [ name ] if name [ / \A / ] } { :objects => response [ "X-Container-Object-Count" ] . to_i , :bytes => response ... | Return some basic stats on the current container . |
22,773 | def set_metadata ( headers ) log "setting headers for container #{container_path}" response = storage_client . post ( container_path , '' , headers ) ( 200 .. 299 ) . cover? ( response . code . to_i ) end | Set metadata headers on the container |
22,774 | def cdn_metadata log "retrieving container CDN metadata from #{container_path}" response = cdn_client . head ( container_path ) { :cdn_enabled => response [ "X-CDN-Enabled" ] == "True" , :host => response [ "X-CDN-URI" ] , :ssl_host => response [ "X-CDN-SSL-URI" ] , :streaming_host => response [ "X-CDN-STREAMING-URI" ]... | Return the key details for CDN access to this container . Can be called on non CDN enabled containers but the details won t make much sense . |
22,775 | def cdn_enable ( ttl = 259200 ) log "enabling CDN access to #{container_path} with a cache expiry of #{ttl / 60} minutes" response = cdn_client . put ( container_path , "X-TTL" => ttl . to_i . to_s ) ( 200 .. 299 ) . cover? ( response . code . to_i ) end | use this with caution it will make EVERY object in the container publicly available via the CDN . CDN enabling can be done via the web UI but only with a TTL of 72 hours . Using the API it s possible to set a TTL of 50 years . |
22,776 | def temp_url ( object_key , temp_url_key , expires_at = Time . now . to_i + 60 ) private_url ( "GET" , object_key , temp_url_key , expires_at ) end | Generate an expiring URL for downloading a file that is otherwise private . Useful for providing temporary access to files . |
22,777 | def temp_upload_url ( object_key , temp_url_key , expires_at = Time . now . to_i + 60 ) private_url ( "PUT" , object_key , temp_url_key , expires_at ) end | Generate a temporary URL for uploading a file to a private container . Anyone can perform a PUT request to the URL returned from this method and an object will be created in the container . |
22,778 | def list_request_path ( marker , prefix , details , limit ) query_string = "limit=#{limit}" query_string += "&marker=#{Raca::Util.url_encode(marker)}" if marker query_string += "&prefix=#{Raca::Util.url_encode(prefix)}" if prefix query_string += "&format=json" if details container_path + "?#{query_string}" end | build the request path for listing the contents of a container |
22,779 | def method_missing ( name , * args ) add_regex = %r{ \. \d \. }x weekday_regex = %r{ }xi next_weekday_regex = %r{ \. }xi next_weekday_in_regex = %r{ \d }xi return add ( $1 , $2 , $3 ) if name =~ add_regex return weekday ( $1 ) if name =~ weekday_regex return next_weekday ( $1 , $2 ) if name =~ next_weekday_regex return... | Creates a new Temp and initializes it with the current date if no date is provided Provides the date calculation methods dynamically |
22,780 | def convert ( data ) data . each do | k , v | k = KEYS [ k ] if KEYS . include? ( k ) v = v . to_s if k . eql? 'zip' if NIDT . include? ( k ) instance_variable_set ( '@nidt' , k ) k = 'nidn' v = v . to_s end var_set ( k , v ) end end | Creates a new person object |
22,781 | def var_set ( k , v ) varget = proc { instance_variable_get ( "@#{k}" ) } varset = proc { | y | instance_variable_set ( "@#{k}" , y ) } v . is_a? ( Hash ) ? convert ( v ) : instance_variable_set ( "@#{k}" , v ) self . class . send ( :define_method , k , varget ) self . class . send ( :define_method , "#{k}=" , varset )... | Sets all instance variables |
22,782 | def expand_hash_conditions_for_aggregates ( attrs ) expanded_attrs = attrs . dup attr_enumeration_mapping_classes . each do | attr , klass | if expanded_attrs [ attr ] . is_a? ( Symbol ) expanded_attrs [ attr ] = klass . from_sym ( expanded_attrs [ attr ] ) end end super ( expanded_attrs ) end | Override the aggregate hash conditions behavior to coerce has_enumeration attributes that show up in finder options as symbols into instances of the aggregate class before hash expansion . |
22,783 | def ignore! ( update_value : false ) Petra . current_transaction . current_section . log_read_integrity_override ( object , attribute : attribute , external_value : external_value , update_value : update_value ) end | The new external attribute value |
22,784 | def undo_changes! Petra . current_transaction . current_section . log_attribute_change_veto ( object , attribute : attribute , external_value : external_value ) end | Tells the transaction to ignore all changes previously done to the current attribute in the transaction . |
22,785 | def download ( args ) if args . length != 1 puts "missing report id for 'download' subcommand" return false end report_id = args [ 0 ] . to_i report = @common_args . account . reports . find { | r | r . id == report_id } if report . nil? puts "report '#{report_id}' not found" return false end if report . status != 'Com... | download a v13 report |
22,786 | def schedule ( argv ) report = @account . report do name 'boh' type 'Url' aggregation 'Daily' cross_client true zero_impression true start_day '2010-01-01' end_day '2010-01-30' column "CustomerName" column "ExternalCustomerId" column "CampaignStatus" column "Campaign" column "CampaignId" column "AdGroup" column "AdGrou... | schedule and download a v13 report |
22,787 | def make_patch ( expected , actual ) diffs = Diff :: LCS . sdiff ( expected . split ( "\n" ) , actual . split ( "\n" ) , Diff :: LCS :: ContextDiffCallbacks ) maxcol = diffs . flatten . collect { | d | [ d . old_element . to_s . length , d . new_element . to_s . length ] } . flatten . max || 0 maxcol += 4 patch = " ... | Compute a patch between the given + expected + output and the + actual + output and return it as a string . |
22,788 | def initialize_polypaperclip if polypaperclip_definitions . nil? after_save :save_attached_files before_destroy :destroy_attached_files has_many_attachments_association write_inheritable_attribute ( :polypaperclip_definitions , { } ) include Paperclip :: InstanceMethods include InstanceMethods end end | initialize a polypaperclip model if a configuration hasn t already been loaded |
22,789 | def method_missing ( name , * args , & block ) sym_name = name . to_sym return fetch ( sym_name ) if key? ( sym_name ) str_name = name . to_s modifier = str_name [ - 1 ] return super unless %w[ ? ! ] . include? ( modifier ) base = str_name [ 0 ... - 1 ] . to_sym known = key? ( base ) return known if modifier == '?' ret... | Dynamically pass unknown messages to the underlying state storage |
22,790 | def respond_to_missing? ( name , _include_private = false ) str_name = name . to_s key? ( name . to_sym ) || %w[ ? ! ] . any? ( & str_name . method ( :end_with? ) ) || super end | Companion to method_missing |
22,791 | def bump! ( term ) fail NotSupportedTerm . new ( term ) unless TERMS . include? ( term . to_sym ) new_version = clone new_value = increment send ( term ) new_version . send ( "#{term}=" , new_value ) new_version . reset_terms_for ( term ) end | Bumps a version by incrementing one of its terms and reseting the others according to semver specification . |
22,792 | def reset_terms_for ( term ) self . minor = 0 if term == :major self . patch = 0 if term == :major || term == :minor self . pre = nil if [ :major , :minor , :patch ] . include? term self . build = nil if [ :major , :minor , :patch , :pre ] . include? term self end | Resets all the terms which need to be reset after a bump |
22,793 | def send_sms ( to : sms_to , body : sms_body ) [ to , body ] generate_token options = { body : { body : body , to : to } . to_json , headers : { "Content-Type" => "application/json" , "Authorization" => "Bearer #{@token}" } } response = HTTParty . post ( "https://api.telstra.com/v1/sms/messages" , options ) return JSON... | Receipient number should be in the format of 04xxxxxxxx where x is a digit . Authorization header value should be in the format of Bearer xxx where xxx is the access token returned from a token request . |
22,794 | def save body = { provider : to_hash } begin response = Atlas . client . put ( url_builder . box_provider_url , body : body ) rescue Atlas :: Errors :: NotFoundError response = Atlas . client . post ( "#{url_builder.box_version_url}/providers" , body : body ) end update_with_response ( response ) end | Initialize a provider from a tag and object hash . |
22,795 | def upload ( file ) response = Atlas . client . get ( "#{url_builder.box_provider_url}/upload" ) upload_url = response [ 'upload_path' ] Excon . put ( upload_url , body : file ) end | Upload a . box file for this provider . |
22,796 | def runnable? time result = [ :minute , :hour , :day , :dow , :month ] . map { | ct | if self [ ct ] == true then true else case ct when :month , :day , :hour val = time . send ( ct ) when :dow val = time . wday when :minute val = time . min end case self [ ct ] when Numeric self [ ct ] == val else self [ ct ] . includ... | Return true if job is runnable at the given time . |
22,797 | def allow ( roles , options = { } ) actions = options . delete ( :to ) rule = PermitRule . new ( roles , options ) index_rule_by_actions @action_allow_rules , actions , rule return rule end | Adds an allow rule for the given actions to the collection . |
22,798 | def indexed_with_cloud_search ( & block ) mods = [ Tinia :: Connection , Tinia :: Index , Tinia :: Search ] mods . each do | mod | unless self . included_modules . include? ( mod ) self . send ( :include , mod ) end end yield ( self ) if block_given? unless self . cloud_search_domain . present? raise Tinia :: MissingSe... | activation method for an AR class |
22,799 | def create_inbound_subscription ( destination_address , options ) query = options . merge ( { :destination_address => destination_address } ) Response . new self . class . post ( "/smsmessaging/inbound/subscriptions" , :basic_auth => @auth , :body => camelcase_keys ( query ) , :headers => SMSIFIED_HTTP_HEADERS ) end | Intantiate a new class to work with subscriptions |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.