idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
17,100 | def drop_while ( & block ) raise Erlang :: ImproperListError if improper? return enum_for ( :drop_while ) unless block_given? list = self list = list . tail while ! list . empty? && yield ( list . head ) return list end | Return a List which contains all elements starting from the first element for which the block returns nil or false . |
17,101 | def pop raise Erlang :: ImproperListError if improper? return self if empty? new_size = size - 1 return Erlang :: List . new ( head , tail . take ( new_size - 1 ) ) if new_size >= 1 return Erlang :: Nil end | Return a List containing all but the last item from this List . |
17,102 | def drop ( number ) raise Erlang :: ImproperListError if improper? list = self while ! list . empty? && number > 0 number -= 1 list = list . tail end return list end | Return a List containing all items after the first number items from this List . |
17,103 | def append ( other ) other = Erlang . from ( other ) return self if not improper? and Erlang . is_list ( other ) and other . empty? return other if Erlang . is_list ( other ) and empty? is_improper = Erlang . is_list ( other ) ? other . improper? : true out = tail = Erlang :: Cons . allocate list = self until list . em... | Return a List with all items from this List followed by all items from other . |
17,104 | def transpose raise Erlang :: ImproperListError if improper? return Erlang :: Nil if empty? return Erlang :: Nil if any? { | list | list . empty? } heads , tails = Erlang :: Nil , Erlang :: Nil reverse_each { | list | heads , tails = heads . cons ( list . head ) , tails . cons ( list . tail ) } return Erlang :: Cons . ... | Gather the first element of each nested list into a new List then the second element of each nested list then the third and so on . In other words if each nested list is a row return a List of columns instead . |
17,105 | def rotate ( count = 1 ) raise Erlang :: ImproperListError if improper? raise TypeError , "expected Integer" if not count . is_a? ( Integer ) return self if empty? || ( count % size ) == 0 count = ( count >= 0 ) ? count % size : ( size - ( ~ count % size ) - 1 ) return drop ( count ) . append ( take ( count ) ) end | Return a new List with the same elements but rotated so that the one at index count is the first element of the new list . If count is positive the elements will be shifted left and those shifted past the lowest position will be moved to the end . If count is negative the elements will be shifted right and those shifte... |
17,106 | def sort ( & comparator ) comparator = Erlang . method ( :compare ) unless block_given? array = super ( & comparator ) return List . from_enum ( array ) end | Return a new List with the same items but sorted . |
17,107 | def intersperse ( sep ) raise Erlang :: ImproperListError if improper? return self if tail . empty? sep = Erlang . from ( sep ) out = tail = Erlang :: Cons . allocate list = self until list . empty? new_node = Erlang :: Cons . allocate new_node . instance_variable_set ( :@head , list . head ) new_node . instance_variab... | Return a new List with sep inserted between each of the existing elements . |
17,108 | def union ( other ) raise Erlang :: ImproperListError if improper? other = Erlang . from ( other ) raise ArgumentError , "other must be of Erlang::List type" if not Erlang . is_list ( other ) raise Erlang :: ImproperListError if other . improper? items = :: Set . new return _uniq ( items ) . append ( other . _uniq ( it... | Return a List with all the elements from both this list and other with all duplicates removed . |
17,109 | def init raise Erlang :: ImproperListError if improper? return Erlang :: Nil if tail . empty? out = tail = Erlang :: Cons . allocate list = self until list . tail . empty? new_node = Erlang :: Cons . allocate new_node . instance_variable_set ( :@head , list . head ) new_node . instance_variable_set ( :@improper , false... | Return a List with all elements except the last one . |
17,110 | def last ( allow_improper = false ) if allow_improper and improper? list = self list = list . tail while list . tail . kind_of? ( Erlang :: List ) return list . tail else raise Erlang :: ImproperListError if improper? list = self list = list . tail until list . tail . empty? return list . head end end | Return the last item in this list . |
17,111 | def tails raise Erlang :: ImproperListError if improper? return self if empty? out = tail = Erlang :: Cons . allocate list = self until list . empty? new_node = Erlang :: Cons . allocate new_node . instance_variable_set ( :@head , list ) new_node . instance_variable_set ( :@improper , false ) tail . instance_variable_s... | Return a List of all suffixes of this list . |
17,112 | def inits raise Erlang :: ImproperListError if improper? return self if empty? prev = nil return map do | head | if prev . nil? Erlang :: List . from_enum ( prev = [ head ] ) else Erlang :: List . from_enum ( prev . push ( head ) ) end end end | Return a List of all prefixes of this list . |
17,113 | def combination ( n ) raise Erlang :: ImproperListError if improper? return Erlang :: Cons . new ( Erlang :: Nil ) if n == 0 return self if empty? return tail . combination ( n - 1 ) . map { | list | list . cons ( head ) } . append ( tail . combination ( n ) ) end | Return a List of all combinations of length n of items from this List . |
17,114 | def chunk ( number ) raise Erlang :: ImproperListError if improper? return self if empty? out = tail = Erlang :: Cons . allocate list = self until list . empty? first , list = list . split_at ( number ) new_node = Erlang :: Cons . allocate new_node . instance_variable_set ( :@head , first ) new_node . instance_variable... | Split the items in this list in groups of number . Return a list of lists . |
17,115 | def flatten raise Erlang :: ImproperListError if improper? return self if empty? out = tail = Erlang :: Cons . allocate list = self until list . empty? if list . head . is_a? ( Erlang :: Cons ) list = list . head . append ( list . tail ) elsif Erlang :: Nil . equal? ( list . head ) list = list . tail else new_node = Er... | Return a new List with all nested lists recursively flattened out that is their elements inserted into the new List in the place where the nested list originally was . |
17,116 | def slice ( arg , length = ( missing_length = true ) ) raise Erlang :: ImproperListError if improper? if missing_length if arg . is_a? ( Range ) from , to = arg . begin , arg . end from += size if from < 0 return nil if from < 0 to += size if to < 0 to += 1 if ! arg . exclude_end? length = to - from length = 0 if lengt... | Return specific objects from the List . All overloads return nil if the starting index is out of range . |
17,117 | def indices ( object = Erlang :: Undefined , i = 0 , & block ) raise Erlang :: ImproperListError if improper? object = Erlang . from ( object ) if object != Erlang :: Undefined return indices { | item | item == object } if not block_given? return Erlang :: Nil if empty? out = tail = Erlang :: Cons . allocate list = sel... | Return a List of indices of matching objects . |
17,118 | def merge ( & comparator ) raise Erlang :: ImproperListError if improper? return merge_by unless block_given? sorted = reject ( & :empty? ) . sort do | a , b | yield ( a . head , b . head ) end return Erlang :: Nil if sorted . empty? return Erlang :: Cons . new ( sorted . head . head , sorted . tail . cons ( sorted . h... | Merge all the nested lists into a single list using the given comparator block to determine the order which items should be shifted out of the nested lists and into the output list . |
17,119 | def insert ( index , * items ) raise Erlang :: ImproperListError if improper? if index == 0 return Erlang :: List . from_enum ( items ) . append ( self ) elsif index > 0 out = tail = Erlang :: Cons . allocate list = self while index > 0 new_node = Erlang :: Cons . allocate new_node . instance_variable_set ( :@head , li... | Return a new List with the given items inserted before the item at index . |
17,120 | def delete_at ( index ) raise Erlang :: ImproperListError if improper? if index == 0 tail elsif index < 0 index += size if index < 0 return self if index < 0 delete_at ( index ) else out = tail = Erlang :: Cons . allocate list = self while index > 0 new_node = Erlang :: Cons . allocate new_node . instance_variable_set ... | Return a List containing the same items minus the one at index . If index is negative it counts back from the end of the list . |
17,121 | def permutation ( length = size , & block ) raise Erlang :: ImproperListError if improper? return enum_for ( :permutation , length ) if not block_given? if length == 0 yield Erlang :: Nil elsif length == 1 each { | obj | yield Erlang :: Cons . new ( obj , Erlang :: Nil ) } elsif not empty? if length < size tail . permu... | Yields all permutations of length n of the items in the list and then returns self . If no length n is specified permutations of the entire list will be yielded . |
17,122 | def partition ( & block ) raise Erlang :: ImproperListError if improper? return enum_for ( :partition ) if not block_given? left = left_tail = Erlang :: Cons . allocate right = right_tail = Erlang :: Cons . allocate list = self while ! list . empty? if yield ( list . head ) new_node = Erlang :: Cons . allocate new_node... | Return two List s the first containing all the elements for which the block evaluates to true the second containing the rest . |
17,123 | def inspect if improper? result = 'Erlang::List[' list = to_proper_list list . each_with_index { | obj , i | result << ', ' if i > 0 ; result << obj . inspect } result << ']' result << " + #{last(true).inspect}" return result else result = '[' list = self list . each_with_index { | obj , i | result << ', ' if i > 0 ; r... | Return the contents of this List as a programmer - readable String . If all the items in the list are serializable as Ruby literal strings the returned string can be passed to eval to reconstitute an equivalent List . |
17,124 | def copy ( n = 1 ) raise ArgumentError , 'n must be a non-negative Integer' if not n . is_a? ( :: Integer ) or n < 0 return self if n == 1 return Erlang :: Binary [ ( @data * n ) ] end | Returns a new Binary containing n copies of itself . n must be greater than or equal to 0 . |
17,125 | def each_bit return enum_for ( :each_bit ) unless block_given? index = 0 bitsize = self . bitsize @data . each_byte do | byte | loop do break if index == bitsize bit = ( byte >> ( 7 - ( index & 7 ) ) ) & 1 yield bit index += 1 break if ( index & 7 ) == 0 end end return self end | Call the given block once for each bit in the Binary passing each bit from first to last successively to the block . If no block is given returns an Enumerator . |
17,126 | def part ( position , length ) raise ArgumentError , 'position must be an Integer' if not position . is_a? ( :: Integer ) raise ArgumentError , 'length must be a non-negative Integer' if not length . is_a? ( :: Integer ) or length < 0 return Erlang :: Binary [ @data . byteslice ( position , length ) ] end | Returns the section of this Binary starting at position of length . |
17,127 | def wait_until time_to_wait = 30 , & block time_limit = Time . now + time_to_wait until block . call if Time . now > time_limit raise "wait_until timeout after #{time_to_wait} seconds" end sleep 0.1 end true end | Calls the block until it returns true or + time_to_wait + is reached . + time_to_wait + is 30 seconds by default |
17,128 | def confirm ( bool , & block ) blk = "lambda { #{bool} }" self . send_remote ( :add_listener , :confirm ) { blk } block . call self . send_remote ( :remove_listener , :confirm , lambda { blk } ) end | Specify whether to accept or reject all confirm js dialogs for the code in the block that s run . |
17,129 | def bind ( client ) if self . class . const_defined? ( :WithClient ) mod = self . class . const_get ( :WithClient ) else mod = Page :: WithClient end unless singleton_class . include? ( mod ) extend ( mod ) end self . client = client self end | Bind + self + to + client + |
17,130 | def login ( pixiv_id , password ) doc = agent . get ( "https://accounts.pixiv.net/login?lang=ja&source=pc&view_type=page" ) return if doc && doc . body =~ / / form = doc . forms_with ( action : '/login' ) . first puts doc . body and raise Error :: LoginFailed , 'login form is not available' unless form form . pixiv_id ... | A new instance of Client logged in with the given credentials |
17,131 | def download_illust ( illust , io_or_filename , size = :original ) size = { :s => :small , :m => :medium , :o => :original } [ size ] || size url = illust . __send__ ( "#{size}_image_url" ) referer = case size when :small then nil when :medium then illust . url when :original then illust . url else raise ArgumentError ... | Downloads the image to + io_or_filename + |
17,132 | def download_manga ( illust , pattern , & block ) action = DownloadActionRegistry . new ( & block ) illust . original_image_urls . each_with_index do | url , n | begin action . before_each . call ( url , n ) if action . before_each filename = filename_from_pattern ( pattern , illust , url ) FileUtils . mkdir_p ( File .... | Downloads the images to + pattern + |
17,133 | def filename_from_pattern ( pattern , illust , url ) pattern . map { | i | if i == :image_name name = File . basename ( url ) if name =~ / \. \w \? \d / name += '.' + $1 end name elsif i . is_a? ( Symbol ) then illust . send ( i ) elsif i . respond_to? ( :call ) then i . call ( illust ) else i end } . join ( '' ) end | Generate filename from + pattern + in context of + illust + and + url + |
17,134 | def soa rr = @records . find { | rr | rr . type == "SOA" } return rr if rr rr = DNS :: Zone :: RR :: SOA . new rr . serial = Time . now . utc . strftime ( "%Y%m%d01" ) rr . refresh_ttl = '3h' rr . retry_ttl = '15m' rr . expiry_ttl = '4w' rr . minimum_ttl = '30m' @records << rr return rr end | Create an empty instance of a DNS zone that you can drive programmatically . |
17,135 | def dump_pretty content = [ ] last_type = "SOA" sorted_records . each do | rr | content << '' if last_type != rr . type content << rr . dump last_type = rr . type end content . join ( "\n" ) << "\n" end | Generates pretty output of the zone and its records . |
17,136 | def sorted_records top_rrs = { } top = %w{ SOA NS MX SPF TXT } top . each { | t | top_rrs [ t ] = @records . select { | rr | rr . type == t } } remaining = @records . reject { | rr | top . include? ( rr . type ) } remaining . sort! { | a , b | a . type <=> b . type } top_rrs . values . flatten + remaining end | Records sorted with more important types being at the top . |
17,137 | def update_in ( * key_path , & block ) if key_path . empty? raise ArgumentError , "must have at least one key in path" end key = key_path [ 0 ] if key_path . size == 1 new_value = block . call ( fetch ( key , nil ) ) else value = fetch ( key , EmptyMap ) new_value = value . update_in ( * key_path [ 1 .. - 1 ] , & block... | Return a new container with a deeply nested value modified to the result of the given code block . When traversing the nested containers non - existing keys are created with empty Hash values . |
17,138 | def dig ( key , * rest ) value = get ( key ) if rest . empty? || value . nil? return value elsif value . respond_to? ( :dig ) return value . dig ( * rest ) end end | Return the value of successively indexing into a collection . If any of the keys is not present in the collection return nil . keys that the Erlang type doesn t understand raises an argument error |
17,139 | def download_all_data ( url ) next_data_indices = { } while next_data_indices html = Downloader . read_page ( url ) prev_next_data_indices = next_data_indices next_data_indices = @parser . get_next_data_indices ( html ) next_data_indices = false if prev_next_data_indices == next_data_indices url = yield ( html , next_d... | Downloads all data given a starting URL . Some Pandora feeds only return 5 - 10 items per page but contain a link to the next set of data . Threads cannot be used because page A be must visited to know how to obtain page B . |
17,140 | def get_url ( data_name , next_data_indices = { } ) if next_data_indices . empty? next_data_indices = { nextStartIndex : 0 , nextLikeStartIndex : 0 , nextThumbStartIndex : 0 } else next_data_indices = next_data_indices . dup end next_data_indices [ :webname ] = @webname next_data_indices [ :pat ] = Downloader . get_pat... | Grabs a URL from DATA_FEED_URLS and formats it appropriately . |
17,141 | def yubikey_authenticated? ( otp ) if yubico_identity? && Account . verify_yubico_otp ( otp ) ( Account . extract_yubico_identity_from_otp ( otp ) == yubico_identity ) else false end end | Is the Yubico OTP valid and belongs to this account? |
17,142 | def [] ( name ) enum_by_name ( name ) . each { | f | return f . value if f . value != "" } enum_by_name ( name ) . each { | f | return f . value } nil end | The value of the first field named + name + or nil if no match is found . |
17,143 | def push_unique ( field ) push ( field ) unless @fields . detect { | f | f . name? field . name } self end | Push + field + onto the fields unless there is already a field with this name . |
17,144 | def delete ( field ) case when field . name? ( "BEGIN" ) , field . name? ( "END" ) raise ArgumentError , "Cannot delete BEGIN or END fields." else @fields . delete field end self end | Delete + field + . |
17,145 | def number ( n ) n . is_a? ( Range ) ? n . to_a . rand : rand ( n ) end | n can be an Integer or a Range . If it is an Integer it just returns a random number greater than or equal to 0 and less than n . If it is a Range it returns a random number within the range Examples |
17,146 | def rewrite_css ( css_module_code ) css_root = Sass :: SCSS :: CssParser . new ( css_module_code , "(CSSModules)" , 1 ) . parse Sass :: Tree :: Visitors :: SetOptions . visit ( css_root , { } ) ModuleVisitor . visit ( css_root ) css_root . render end | Take css module code as input and rewrite it as browser - friendly CSS code . Apply opaque transformations so that selectors can only be accessed programatically not by class name literals . |
17,147 | def grammatical_construct ( grammar , what = nil ) output = "" if what . nil? case grammar when Hash a_key = grammar . keys . sort_by { rand } [ 0 ] output += grammatical_construct ( grammar , a_key ) when Array grammar . each do | item | output += grammatical_construct ( item ) end when String output += grammar end el... | Returns simple sentences based on a supplied grammar which must be a hash the keys of which are symbols . The values are either an array of successive values or a grammar ( i . e hash with symbols as keys and hashes or arrays as values . The arrays contain symbols referencing the keys in the present grammar or strings ... |
17,148 | def endpoints_for_circle_with_radius ( radius , steps = 30 ) raise ArgumentError , "Number of points has to be in range of 1..360!" unless ( 1 .. 360 ) . include? steps points = [ ] steps . times do | i | points << endpoint ( radius , i * 360 / steps ) end points << points . first points end | Returns ends poionts which will make up a circle around current location and have given radius |
17,149 | def companyname num = rand ( 5 ) if num == 0 num = 1 end final = num . times . collect { @@lastnames . rand . capitalize } if final . count == 1 "#{final.first} #{@@company_types.rand}, #{@@incorporation_types.rand}" else incorporation_type = rand ( 17 ) % 2 == 0 ? @@incorporation_types . rand : nil company_type = rand... | Returns a random company name |
17,150 | def base base = Base . new type = @parser . graph . fetch ( "og:type" , "website" ) . downcase validate_type type @parser . graph . each do | property | build_property base , property end synthesize_required_properties base drop_empty_children base validate base base end | Create a new builder . |
17,151 | def nav ( name , url , pages = nil , active = false ) content_tag :li , link_to ( name , url ) , :class => ( active || ( pages && active_page? ( pages ) ) ? 'act' : nil ) end | Renders a navigation element and marks it as active where appropriate . See active_page? for details |
17,152 | def active_page? ( pages = { } ) is_active = pages . include? ( params [ :controller ] ) is_active = pages [ params [ :controller ] ] . include? ( params [ :action ] ) if is_active && ! pages [ params [ :controller ] ] . empty? is_active end | Takes a hash with pages and tells whether the current page is among them . The keys must be controller names and their value must be an array of action names . If the array is empty every action is supposed to be valid . |
17,153 | def get_webnames_from_search ( html ) user_links = Nokogiri :: HTML ( html ) . css ( '.user_name a' ) webnames = [ ] user_links . each do | link | webnames << link [ 'webname' ] end webnames end | Get the webnames from a user ID search . |
17,154 | def get_next_data_indices ( html ) show_more = Nokogiri :: HTML ( html ) . css ( '.show_more, .js-more-link' ) [ 0 ] if show_more next_indices = { } data_attributes = [ 'nextStartIndex' , 'nextLikeStartIndex' , 'nextThumbStartIndex' ] data_attributes . each do | attr_name | attr = show_more . attributes [ 'data-' + att... | Get the query parameters necessary to get the next page of data from Pandora . |
17,155 | def infobox_each_link ( html ) Nokogiri :: HTML ( html ) . css ( '.infobox' ) . each do | infobox | infobox_body = infobox . css ( '.infobox-body' ) title_link = infobox_body . css ( 'h3 a' ) . text . strip subtitle_link = infobox_body . css ( 'p a' ) . first subtitle_link = subtitle_link . text . strip if subtitle_lin... | Loops over each . infobox container and yields the title and subtitle . |
17,156 | def doublelink_each_link ( html ) Nokogiri :: HTML ( html ) . css ( '.double-link' ) . each do | doublelink | title_link = doublelink . css ( '.media__bd__header' ) . text . strip subtitle_link = doublelink . css ( '.media__bd__subheader' ) . text . strip yield ( title_link , subtitle_link ) end end | Loops over each . double - link container and yields the title and subtitle . Encountered on mobile pages . |
17,157 | def get_followx_users ( html ) users = [ ] Nokogiri :: HTML ( html ) . css ( '.follow_section' ) . each do | section | listener_name = section . css ( '.listener_name' ) . first webname = listener_name [ 'webname' ] listener_name . css ( 'span' ) . each ( & :remove ) name = listener_name . text . strip href = section .... | Loops over each . follow_section container . |
17,158 | def detect_system_properties ( arch ) parts = ( arch || architecture ) . split ( '-' , 2 ) if parts . length == 1 @cpu , system = nil , parts . shift else @cpu , system = * parts end @os , @version = * find_os_and_version ( system ) [ @cpu , @os , @version ] end | Infer system properties from architecture information |
17,159 | def decide @site = current_account . sites . find_or_initialize_by_url ( checkid_request . trust_root ) @site . persona = current_account . personas . find ( params [ :persona_id ] || :first ) if sreg_request || ax_store_request || ax_fetch_request end | Displays the decision page on that the user can confirm the request and choose which data should be transfered to the relying party . |
17,160 | def complete if params [ :cancel ] cancel else resp = checkid_request . answer ( true , nil , identifier ( current_account ) ) if params [ :always ] @site = current_account . sites . find_or_create_by_persona_id_and_url ( params [ :site ] [ :persona_id ] , params [ :site ] [ :url ] ) @site . update_attributes ( params ... | This action is called by submitting the decision form the information entered by the user is used to answer the request . If the user decides to always trust the relying party a new site according to the release policies the will be created . |
17,161 | def handle_checkid_request if allow_verification? save_checkid_request redirect_to proceed_path elsif openid_request . immediate render_response ( openid_request . answer ( false ) ) else reset_session request = save_checkid_request session [ :return_to ] = proceed_path redirect_to ( request . from_trusted_domain? ? lo... | Decides how to process an incoming checkid request . If the user is already logged in he will be forwarded to the proceed action . If the user is not logged in and the request is immediate the request cannot be answered successfully . In case the user is not logged in the request will be stored and the user is asked to... |
17,162 | def save_checkid_request clear_checkid_request request = OpenIdRequest . create! ( :parameters => openid_params ) session [ :request_token ] = request . token request end | Stores the current OpenID request . Returns the OpenIdRequest |
17,163 | def ensure_valid_checkid_request self . openid_request = checkid_request if ! openid_request . is_a? ( OpenID :: Server :: CheckIDRequest ) redirect_to root_path , :alert => t ( :identity_verification_request_invalid ) elsif ! allow_verification? flash [ :notice ] = logged_in? && ! pape_requirements_met? ( auth_time ) ... | Use this as before_filter for every CheckID request based action . Loads the current openid request and cancels if none can be found . The user has to log in if he has not verified his ownership of the identifier yet . |
17,164 | def transform_ax_data ( parameters ) data = { } parameters . each_pair do | key , details | if details [ 'value' ] data [ "type.#{key}" ] = details [ 'type' ] data [ "value.#{key}" ] = details [ 'value' ] end end data end | Transforms the parameters from the form to valid AX response values |
17,165 | def render_openid_error ( exception ) error = case exception when OpenID :: Server :: MalformedTrustRoot then "Malformed trust root '#{exception.to_s}'" else exception . to_s end render :text => h ( "Invalid OpenID request: #{error}" ) , :status => 500 end | Renders the exception message as text output |
17,166 | def add_input_option ( option_name , * args ) ( @input_options ||= [ ] ) . push ( option_name ) args . each { | ea | @input_options . push ( Shellwords . escape ( ea . to_s ) ) } self end | If you need to add an option that affects processing of input files you can use this method . |
17,167 | def square_crop ( gravity = 'Center' ) gravity ( gravity ) unless gravity . nil? d = [ width , height ] . min crop ( "#{d}x#{d}+0+0!" ) end | Crop to a square using the specified gravity . |
17,168 | def method_missing ( method , * args , & block ) name = method . to_s if respond_to_missing? name @bases [ name ] else super ( method , * args , & block ) end end | Makes the found root objects available . |
17,169 | def uk_post_code post_towns = %w( BM CB CV LE LI LS KT MK NE OX PL YO ) number_1 = rand ( 100 ) . to_s number_2 = rand ( 100 ) . to_s letters = ( "AA" .. "ZZ" ) . to_a . rand return "#{post_towns.rand}#{number_1} #{number_2}#{letters}" end | Returns a string providing something in the general form of a UK post code . Like the zip codes this might not actually be valid . Doesn t cover London whose codes are like SE1 . |
17,170 | def url raise BuildDataMissing , "We have to have markers, paths or center and zoom set when url is called!" unless can_build? out = "#{API_URL}?" params = [ ] ( REQUIRED_OPTIONS + OPTIONAL_OPTIONS ) . each do | key | value = send ( key ) params << "#{key}=#{URI.escape(value.to_s)}" unless value . nil? end out += param... | Creates a new Map object |
17,171 | def grouped_markers markers . inject ( Hash . new { | hash , key | hash [ key ] = [ ] } ) do | groups , marker | groups [ marker . options_to_url_params ] << marker groups end end | Returns the markers grouped by it s label color and size . |
17,172 | def size = ( size ) unless size . nil? case size when String width , height = size . split ( 'x' ) when Array width , height = size when Hash width = size [ :width ] height = size [ :height ] else raise "Don't know how to set size from #{size.class}!" end self . width = width if width self . height = height if height e... | Sets the size of the map |
17,173 | def alphanumeric ( size = 16 ) s = "" size . times { s << ( i = Kernel . rand ( 62 ) ; i += ( ( i < 10 ) ? 48 : ( ( i < 36 ) ? 55 : 61 ) ) ) . chr } s end | Methods to create random strings and paragraphs . Returns a string of random upper - and lowercase alphanumeric characters . Accepts a size parameters defaults to 16 characters . |
17,174 | def insert ( result ) tabindex = Marshal . dump ( @state ) if @table [ tabindex ] . has_key? ( result ) @table [ tabindex ] [ result ] += 1 else @table [ tabindex ] [ result ] = 1 end next_state ( result ) end | given the next token of input add it to the table |
17,175 | def countries_for_select :: I18nData . countries . map { | pair | pair . reverse } . sort { | x , y | x . first <=> y . first } end | get list of codes and names sorted by country name |
17,176 | def languages_for_select :: I18nData . languages . map { | pair | pair . reverse } . sort { | x , y | x . first <=> y . first } end | get list of codes and names sorted by language name |
17,177 | def lines ( name = nil ) unless block_given? map do | f | if ( ! name || f . name? ( name ) ) f2l ( f ) else nil end end . compact else each do | f | if ( ! name || f . name? ( name ) ) line = f2l ( f ) if line yield line end end end self end end | With no block returns an Array of Line . If + name + is specified the Array will only contain the + Line + s with that + name + . The Array may be empty . |
17,178 | def delete_if rm = [ ] each do | f | line = f2l ( f ) if line && yield ( line ) rm << f if f . name? "N" rm << field ( "FN" ) end end end rm . each do | f | @fields . delete ( f ) @cache . delete ( f ) end end | Delete + line + if block yields true . |
17,179 | def add_breadcrumb_to ( name , url , trail_index ) breadcrumb_trails @breadcrumb_trails [ trail_index ] ||= [ ] @breadcrumb_trails [ trail_index ] << { name : case name when Proc then name . call ( self ) else name end , url : case url when Proc then url . call ( self ) else url ? url_for ( url ) : nil end } end | Add a breadcrumb to breadcrumb trail . |
17,180 | def current_account = ( new_account ) if self . auth_type_used != :basic session [ :account_id ] = ( new_account . nil? || new_account . is_a? ( Symbol ) ) ? nil : new_account . id end @current_account = new_account || :false end | Store the given account id in the session . |
17,181 | def access_denied respond_to do | format | format . html do store_location redirect_to login_path end format . any do request_http_basic_authentication 'Web Password' end end end | Redirect as appropriate when an access request fails . |
17,182 | def []= name , value if property? ( name ) public_send "#{name}=" , value elsif OpenGraphReader . config . strict raise UndefinedPropertyError , "Undefined property #{name} on #{inspect}" end end | Set the property to the given value . |
17,183 | def date ( dayrange = 10 ) if dayrange . is_a? ( Range ) offset = rand ( dayrange . max - dayrange . min ) + dayrange . min else offset = rand ( dayrange * 2 ) - dayrange end Date . today + offset end | Returns a date within a specified range of days . If dayrange is an Integer then the date returned will be plus or minus half what you specify . The default is ten days so by default you will get a date within plus or minus five days of today . |
17,184 | def date_between ( range ) min_date = range . min . is_a? ( Date ) ? range . min : Date . parse ( range . min ) max_date = range . max . is_a? ( Date ) ? range . max : Date . parse ( range . max ) diff = ( max_date - min_date ) . to_i min_date + rand ( diff ) end | Returns a date within the specified Range . The Range can be Date or String objects . |
17,185 | def url_params raise BuildDataMissing , "Need at least 2 points to create a path!" unless can_build? out = 'path=' path_params = OPTIONAL_OPTIONS . inject ( [ ] ) do | path_params , attribute | value = send ( attribute ) path_params << "#{attribute}:#{URI.escape(value.to_s)}" unless value . nil? path_params end . join ... | Creates a new Path which you can push points on to to make up lines or polygons |
17,186 | def points = ( array ) raise ArgumentError unless array . is_a? Array @points = [ ] array . each { | point | self << point } end | Sets the points of this Path . |
17,187 | def add_pape ( resp , policies = [ ] , nist_auth_level = 0 , auth_time = nil ) if papereq = OpenID :: PAPE :: Request . from_openid_request ( openid_request ) paperesp = OpenID :: PAPE :: Response . new policies . each { | p | paperesp . add_policy_uri ( p ) } paperesp . nist_auth_level = nist_auth_level paperesp . aut... | Adds PAPE information for your server to an OpenID response . |
17,188 | def render_openid_response ( resp ) signed_response = openid_server . signatory . sign ( resp ) if resp . needs_signing web_response = openid_server . encode_response ( resp ) case web_response . code when OpenID :: Server :: HTTP_OK then render ( :text => web_response . body , :status => 200 ) when OpenID :: Server ::... | Renders the final response output |
17,189 | def property ( type ) prop = Persona . mappings . detect { | i | i [ 1 ] . include? ( type ) } prop ? self . send ( prop [ 0 ] ) . to_s : nil end | Returns the personas attribute for the given SReg name or AX Type URI |
17,190 | def format_data ( data , json = false ) if json JSON . generate ( data ) else data . map do | category , cat_data | title = category . to_s . split ( '_' ) . map ( & :capitalize ) . join ( ' ' ) output = if cat_data . empty? " ** No Data **\n" else case category when / / formatter . tracks ( cat_data ) when / / format... | Formats data as a string list or JSON . |
17,191 | def download_data scraper_data = { } @data_to_get . each do | data_category | if / / =~ data_category argument = $1 . to_sym scraper_data [ data_category ] = @scraper . public_send ( :likes , argument ) else scraper_data [ data_category ] = @scraper . public_send ( data_category ) end end scraper_data end | Downloads the user s desired data . |
17,192 | def scraper_for ( user_id ) scraper = Pandata :: Scraper . get ( user_id ) if scraper . kind_of? ( Array ) log "No exact match for '#{user_id}'." unless scraper . empty? log "\nWebname results for '#{user_id}':\n#{formatter.list(scraper)}" end raise PandataError , "Could not create a scraper for '#{user_id}'." end scra... | Returns a scraper for the user s id . |
17,193 | def ax_fetch = ( props ) props . each_pair do | property , details | release_policies . build ( :property => property , :type_identifier => details [ 'type' ] ) if details [ 'value' ] end end | Generates a release policy for each property that has a value . This setter is used in the server controllers complete action to set the attributes recieved from the decision form . |
17,194 | def sreg_properties props = { } release_policies . each do | rp | is_sreg = ( rp . property == rp . type_identifier ) props [ rp . property ] = persona . property ( rp . property ) if is_sreg end props end | Returns a hash with all released SReg properties . SReg properties have a type_identifier matching their property name |
17,195 | def ax_properties props = { } release_policies . each do | rp | if rp . type_identifier . match ( "://" ) props [ "type.#{rp.property}" ] = rp . type_identifier props [ "value.#{rp.property}" ] = persona . property ( rp . type_identifier ) end end props end | Returns a hash with all released AX properties . AX properties have an URL as type_identifier . |
17,196 | def custom_sort ( enumerable ) sorted_array = enumerable . sort_by do | key , _ | key . sub ( / \s /i , '' ) . downcase end if enumerable . kind_of? ( Hash ) sorted_hash = { } sorted_array . each { | item | sorted_hash [ item [ 0 ] ] = item [ 1 ] } sorted_hash else sorted_array end end | Sorts alphabetically ignoring the initial The when sorting strings . Also case - insensitive to prevent lowercase names from being sorted last . |
17,197 | def roulette ( k = 1 ) wheel = [ ] weight = 0 self . each do | x | raise "Illegal negative weight #{x}" if x < 0 wheel . push ( weight += x ) end raise "Array had all zero weights" if weight . zero? wheel . push ( weight + 1 ) if block_given? k . times do r = Kernel . rand ( ) roll = weight . to_f * r 0 . upto ( self .... | Takes an array of non - negative weights and returns the index selected by a roulette wheel weighted according to those weights . If a block is given then k is used to determine how many times the block is called . In this case nil is returned . |
17,198 | def body fetch_body unless fetched? raise NoOpenGraphDataError , "No response body received for #{@uri}" if fetch_failed? raise NoOpenGraphDataError , "Did not receive a HTML site at #{@uri}" unless html? @get_response . body end | Retrieve the body |
17,199 | def html? fetch_headers unless fetched_headers? response = @get_response || @head_response return false if fetch_failed? return false unless response return false unless response . success? return false unless response [ "content-type" ] response [ "content-type" ] . include? "text/html" end | Whether the target URI seems to return HTML |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.