idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
22,900 | def parse ( field ) case @format when :delimited field . split ( field_delimiter ) when :json parsed = JSON . parse ( field ) [ parsed [ 'iv' ] , parsed [ 'key' ] , parsed [ 'message' ] ] end end | Extracts the initialization vector encrypted key and cipher text according to the specified format . |
22,901 | def page_header * args , & block if block_given? size = ( 1 .. 6 ) === args . first ? args . first : 1 content_tag :div , :class => "page-header" do content_tag "h#{size}" do capture ( & block ) end end else title = args . first size = ( 1 .. 6 ) === args . second ? args . second : 1 content_tag :div , content_tag ( "h... | title size = 1 |
22,902 | def nav_li * args , & block options = ( block_given? ? args . first : args . second ) || { } url = url_for ( options ) active = "active" if url == request . path || url == request . url content_tag :li , :class => active do link_to * args , & block end end | Just like + link_to + but wrap with li tag and set + class = active + to corresponding page . |
22,903 | def find_servers return nil unless run_context return node [ :etcd ] [ :servers ] if node . key? ( :etcd ) && node [ :etcd ] . key? ( :servers ) return node . run_state [ :etcd_servers ] if node . run_state . key? :etcd_servers etcd_nodes = search ( :node , search_query ) servers = etcd_nodes . map { | n | n [ :ipaddre... | Find other Etd Servers by looking at node attributes or via Chef Search |
22,904 | def try_connect ( server ) c = :: Etcd . client ( host : server , port : port , allow_redirect : @redirect ) begin c . get '/_etcd/machines' return c rescue puts "ETCD: failed to connect to #{c.host}:#{c.port}" return nil end end | Try to grab an etcd connection |
22,905 | def run time = nil puts "[cron] run called #{Time.now}" if @debug time = self . time if time . nil? self . each { | cron_job | ok , details = cron_job . runnable? ( time ) if ok then @queue . enq ( cron_job ) if cron_job . once? then cron_job [ :delete ] = true end end } self . reject! { | cron_job | cron_job [ :delete... | Check each item in this array if runnable push it on a queue . |
22,906 | def start debug = false , method = :every_minute , * args @stopped = false @suspended = false @dead = Queue . new @thread = CronR :: Utils . send ( method , debug , * args ) { time = self . time @mutex . synchronize { if @stopped then @dead . enq ( true ) true elsif @suspended then else self . run ( time ) end } } end | Start cron . |
22,907 | def stop & block if block_given? then @stopped = true @suspended = false sig = @dead . deq @mutex . synchronize { while @thread . alive? sleep 0.2 end block . call ( self ) } end end | Gracefully stop the thread . |
22,908 | def provide_login_html ( env ) request = :: Rack :: Request . new ( env ) html = login_html ( env , :url => request [ 'url' ] , :session_expired => request [ 'session_expired' ] ) html_response ( html ) . finish end | An HTML form for logging in . |
22,909 | def filter_for_main_fields ( klass , options = { } ) klass . main_fields . each do | f | if f == :gender filter ExtensionedSymbol . new ( f ) . cut_id , collection : genders else filter ExtensionedSymbol . new ( f ) . cut_id end end end | it check only for gender field for now |
22,910 | def nested_form_for_main_fields ( klass , nested_klass , options = { } ) form_for_main_fields ( klass , options ) do | form_field | nested_table_name = nested_klass . to_s . underscore . pluralize . to_sym main_model_name = klass . to_s . underscore . to_sym form_field . has_many nested_table_name , allow_destroy : tru... | simple nested set for 2 classes with defined main_fields |
22,911 | def authenticate_using_http_basic return if current_user authenticate_with_http_basic do | email , password | signin = Session . new email : email , password : password auth = User . authenticate_signin signin self . current_user = auth unless auth . kind_of? Symbol end end | The before_action that implements authenticates_using_http_basic . |
22,912 | def translate ( * attributes ) self . _translatable ||= Hash . new { | h , k | h [ k ] = [ ] } self . _translatable [ base_name ] = translatable . concat ( attributes ) . uniq end | Define attribute as translatable |
22,913 | def execute & block raise 'Previous process still exists' unless pipes . empty? @callbacks = [ ] @errbacks = [ ] pid , stdin , stdout , stderr = POSIX :: Spawn . popen4 @command . to_s @pid = pid @stdin = attach_pipe_handler :stdin , stdin @stdout = attach_pipe_handler :stdout , stdout @stderr = attach_pipe_handler :st... | Executes the command from the Builder object . If there had been given a block at instantiation it will be called after the popen3 call and after the pipes have been attached . |
22,914 | def unbind name pipes . delete name if pipes . empty? exit_callbacks . each do | cb | EM . next_tick do cb . call status end end if status . exitstatus == 0 EM . next_tick do succeed self end else EM . next_tick do fail self end end end end | Called by child pipes when they get unbound . |
22,915 | def kill signal = 'TERM' , wait = false Process . kill signal , self . pid val = status if wait @stdin . close @stdout . close @stderr . close val end | Kills the child process . |
22,916 | def run AiGames :: Logger . info 'Parser.run : Starting loop' loop do command = read_from_engine break if command . nil? command . strip! next if command . length == 0 response = parse split_line command write_to_engine response unless response . nil? || response . length < 1 end AiGames :: Logger . info 'Parser.run : ... | Initializes the parser . Pass in options using a hash structure . Starts the main loop . This loop runs until the game engine closes the console line . During the loop the parser reads from the game engine sanitizes the input a little bit and then passes it to a method that needs to be overwritten by parsers extending ... |
22,917 | def valid? ( enumerator ) return false unless Is [ Enumerator ] . valid? ( enumerator ) enumerator . all? { | obj | Is [ type ] . valid? ( obj ) } end | Notice that the method will actually iterate over the enumerator |
22,918 | def to_hash result = { } result [ '_id' ] = @_id if @_id result [ 'at' ] = @at result [ 'kind' ] = kind . to_s @entities . each do | entity_name , entity | result [ entity_name . to_s ] = entity . model_id end result [ 'meta' ] = @meta . stringify_keys unless @meta . blank? result end | Serialize activity to a hash |
22,919 | def humanization_bindings ( options = { } ) result = { } @entities . each do | entity_name , entity | result [ entity_name ] = entity . humanize ( options . merge ( :activity => self ) ) result [ "#{entity_name}_model" . to_sym ] = entity . model end result . merge ( @meta ) end | Bindings for humanization sentence |
22,920 | def humanize ( options = { } ) raise "No humanize_tpl defined" if self . humanize_tpl . blank? Activr . sentence ( self . humanize_tpl , self . humanization_bindings ( options ) ) end | Humanize that activity |
22,921 | def check! self . allowed_entities . each do | entity_name , entity_options | if ! entity_options [ :optional ] && @entities [ entity_name ] . blank? raise Activr :: Activity :: MissingEntityError , "Missing '#{entity_name}' entity in this '#{self.kind}' activity: #{self.inspect}" end end end | Check if activity is valid |
22,922 | def deep_merge! ( other_hash ) other_hash . each_pair do | k , v | tv = self [ k ] self [ k ] = tv . is_a? ( Hash ) && v . is_a? ( Hash ) ? self . class . new ( tv ) . deep_merge ( v ) : v end self end | Returns a new hash with + self + and + other_hash + merged recursively . Modifies the receiver in place . |
22,923 | def ids ( data ) return data if data and data . empty? data = { '_id' => data } if ! data or data . is_a? ( String ) data = data . stringify_keys data [ '_id' ] = data . delete ( 'id' ) if data [ 'id' ] data . each do | k , v | if v . is_a? ( String ) and v =~ / / data [ k ] = oid ( v ) end end data end | Make sure data is optimal |
22,924 | def oid ( v = nil ) return BSON :: ObjectId . new if v . nil? ; BSON :: ObjectId . from_string ( v ) rescue v end | Convert to BSON ObjectId or make a new one |
22,925 | def encrypts ( * attr_names , & config ) base_options = attr_names . last . is_a? ( Hash ) ? attr_names . pop : { } attr_names . each do | attr_name | options = base_options . dup attr_name = attr_name . to_s to_attr_name = ( options . delete ( :to ) || attr_name ) . to_s mode = options . delete ( :mode ) || :sha class... | Encrypts the given attribute . |
22,926 | def write_encrypted_attribute ( attr_name , to_attr_name , cipher_class , options ) value = send ( attr_name ) unless value . blank? || value . encrypted? callback ( "before_encrypt_#{attr_name}" ) cipher = create_cipher ( cipher_class , options , value ) value = cipher . encrypt ( value ) value . cipher = cipher send ... | Encrypts the given attribute to a target location using the encryption options configured for that attribute |
22,927 | def read_encrypted_attribute ( to_attr_name , cipher_class , options ) value = read_attribute ( to_attr_name ) unless value . blank? || value . encrypted? || attribute_changed? ( to_attr_name ) value . cipher = create_cipher ( cipher_class , options , value ) end value end | Reads the given attribute from the database adding contextual information about how it was encrypted so that equality comparisons can be used |
22,928 | def create_cipher ( klass , options , value ) options = options . is_a? ( Proc ) ? options . call ( self ) : options . dup klass . parent == EncryptedAttributes ? klass . new ( value , options ) : klass . new ( options ) end | Creates a new cipher with the given configuration options |
22,929 | def add_iota i raise Edoors :: Exception . new "Iota #{i.name} already has #{i.parent.name} as parent" if not i . parent . nil? and i . parent! = self raise Edoors :: Exception . new "Iota #{i.name} already exists in #{path}" if @iotas . has_key? i . name i . parent = self if i . parent . nil? @iotas [ i . name ] = i e... | adds the given Iota to this Room |
22,930 | def add_link l l . door = @iotas [ l . src ] raise Edoors :: Exception . new "Link source #{l.src} does not exist in #{path}" if l . door . nil? ( @links [ l . src ] ||= [ ] ) << l end | adds the given Link to this Room |
22,931 | def _try_links p puts " -> try_links ..." if @spin . debug_routing links = @links [ p . src . name ] return false if links . nil? pending_link = nil links . each do | link | if p . link_with? link if pending_link p2 = @spin . require_p p . class p2 . clone_data p p2 . apply_link! pending_link send_p p2 end pending_li... | search for a matching link |
22,932 | def _route p if p . room . nil? or p . room == path if door = @iotas [ p . door ] p . dst_routed! door else p . error! Edoors :: ERROR_ROUTE_RRWD end elsif door = @spin . search_world ( p . room + Edoors :: PATH_SEP + p . door ) p . dst_routed! door else p . error! Edoors :: ERROR_ROUTE_DNE end end | route the given Particle |
22,933 | def _send p , sys = false if not sys and p . src . nil? p . error! Edoors :: ERROR_ROUTE_NS , @spin elsif p . dst return elsif p . door _route p elsif p . next_dst p . split_dst! if p . door _route p elsif not sys p . dst_routed! p . src elsif p . action p . dst_routed! @spin end elsif not sys and _try_links p return e... | send the given Particle |
22,934 | def send_p p puts " * send_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin . debug_routing _send p puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin . debug_routing @spin . post_p p end | send the given Particle to application Particle fifo |
22,935 | def send_sys_p p puts " * send_sys_p #{(p.next_dst.nil? ? 'no dst' : p.next_dst)} ..." if @spin . debug_routing _send p , true puts " -> #{p.dst.path}#{Edoors::ACT_SEP}#{p.action}" if @spin . debug_routing @spin . post_sys_p p end | send the given Particle to system Particle fifo |
22,936 | def process_sys_p p if p . action == Edoors :: SYS_ACT_ADD_LINK add_link Edoors :: Link . from_particle p elsif p . action == Edoors :: SYS_ACT_ADD_ROOM Edoors :: Room . from_particle p , self end @spin . release_p p end | process the given system Particle |
22,937 | def out_XML io , indent = nil if indent Xyml . rawobj2domobj ( @root ) . write ( io , indent . to_i ) else sio = StringIO . new Xyml . rawobj2domobj ( @root ) . write ( sio ) sio . rewind io . print sio . read , "\n" end io . close end | save an XML file corresponding to the tree data in the self through the designated IO . |
22,938 | def load_XYML io raw_yaml = YAML . load ( io ) @root = Xyml . rawobj2element raw_yaml [ 0 ] self . clear . push @root io . close end | load an XYML file through the designated IO and set the tree data in the file to the self . |
22,939 | def out_JSON io serialized = JSON . generate ( Xyml . remove_parent_rcsv ( self ) ) io . print serialized io . close end | save a JSON file corresponding to the tree data in the self through the designated IO . Note that a JSON file can be loaded by load_XYML method because JSON is a part of YAML . |
22,940 | def public_endpoint ( service_name , region = nil ) return IDENTITY_URL if service_name == "identity" endpoints = service_endpoints ( service_name ) if endpoints . size > 1 && region region = region . to_s . upcase endpoints = endpoints . select { | e | e [ "region" ] == region } || { } elsif endpoints . size > 1 && re... | Return the public API URL for a particular rackspace service . |
22,941 | def refresh_cache Net :: HTTP . new ( identity_host , 443 ) . tap { | http | http . use_ssl = true } . start { | http | payload = { auth : { 'RAX-KSKEY:apiKeyCredentials' => { username : @username , apiKey : @key } } } response = http . post ( tokens_path , JSON . dump ( payload ) , { 'Content-Type' => 'application/jso... | Raca classes use this method to occasionally re - authenticate with the rackspace servers . You can probably ignore it . |
22,942 | def extract_value ( data , * keys ) if keys . empty? data elsif data . respond_to? ( :[] ) && data [ keys . first ] extract_value ( data [ keys . first ] , * keys . slice ( 1 , 100 ) ) else nil end end | This method is opaque but it was the best I could come up with using just the standard library . Sorry . |
22,943 | def generate_payload payload = { } payload [ :channel ] = self . channel unless self . channel . nil? payload [ :username ] = self . username unless self . username . nil? payload [ :icon_url ] = self . icon_url unless self . icon_url . nil? payload [ :icon_emoji ] = self . icon_emoji unless self . icon_emoji . nil? pa... | Generate the payload if stuff was provided |
22,944 | def set_basic_auth ( uri , user , passwd ) uri = urify ( uri ) @www_auth . basic_auth . set ( uri , user , passwd ) reset_all end | for backward compatibility |
22,945 | def set_client_cert_file ( cert_file , key_file ) @client_cert = OpenSSL :: X509 :: Certificate . new ( File . open ( cert_file ) . read ) @client_key = OpenSSL :: PKey :: RSA . new ( File . open ( key_file ) . read ) change_notify end | don t use if you don t know what it is . |
22,946 | def set_context ( ctx ) ctx . cert_store = @cert_store ctx . verify_mode = @verify_mode ctx . verify_depth = @verify_depth if @verify_depth ctx . verify_callback = @verify_callback || method ( :default_verify_callback ) ctx . cert = @client_cert ctx . key = @client_key ctx . client_ca = @client_ca ctx . timeout = @time... | interfaces for SSLSocketWrap . |
22,947 | def set ( uri , user , passwd ) if uri . nil? @cred = [ "#{user}:#{passwd}" ] . pack ( 'm' ) . tr ( "\n" , '' ) else uri = Util . uri_dirname ( uri ) @auth [ uri ] = [ "#{user}:#{passwd}" ] . pack ( 'm' ) . tr ( "\n" , '' ) end end | uri == nil for generic purpose |
22,948 | def connect site = @proxy || @dest begin retry_number = 0 timeout ( @connect_timeout ) do @socket = create_socket ( site ) begin @src . host = @socket . addr [ 3 ] @src . port = @socket . addr [ 1 ] rescue SocketError end if @dest . scheme == 'https' @socket = create_ssl_socket ( @socket ) connect_ssl_proxy ( @socket )... | Connect to the server |
22,949 | def read_header if @state == :DATA get_data { } check_state ( ) end unless @state == :META raise InvalidState , 'state != :META' end parse_header ( @socket ) @content_length = nil @chunked = false @headers . each do | line | case line when / \s \d /i @content_length = $1 . to_i when / \s /i @chunked = true @content_len... | Read status block . |
22,950 | def upload ( bucket , key , path ) Mongolicious . logger . info ( "Uploading archive to #{key}" ) @con . put_object ( bucket , key , File . open ( path , 'r' ) , { 'x-amz-acl' => 'private' , 'Content-Type' => 'application/x-tar' } ) end | Upload the given path to S3 . |
22,951 | def upload_part ( bucket , key , upload_id , part_number , data ) response = @con . upload_part ( bucket , key , upload_id , part_number , data ) return response . headers [ 'ETag' ] end | Upload a part for a multipart upload |
22,952 | def complete_multipart_upload ( bucket , key , upload_id , parts ) response = @con . complete_multipart_upload ( bucket , key , upload_id , parts ) return response end | Complete a multipart upload |
22,953 | def cleanup ( bucket , prefix , versions ) objects = @con . get_bucket ( bucket , :prefix => prefix ) . body [ 'Contents' ] return if objects . size <= versions objects [ 0 ... ( objects . size - versions ) ] . each do | o | Mongolicious . logger . info ( "Removing outdated version #{o['Key']}" ) @con . delete_object (... | Remove old versions of a backup . |
22,954 | def format ( twt , idx = nil ) idx = pad ( idx ) if idx text = deentitize ( twt . text ) if config . colors? buf = idx ? "#{idx.cyan}:" : "" if twt . as_user == config . account_name . to_s buf += "#{twt.as_user.bold.blue}: #{text}" elsif text . mentions? ( config . account_name ) buf += "#{twt.as_user.bold.red}: #{tex... | Format a tweet all pretty like |
22,955 | def write ( key , value , binary = false ) result = req_list ( new_req_list ( ) . add_write ( key , value , binary ) ) [ 0 ] _process_result_commit ( result ) end | Issues a write operation to Scalaris and adds it to the current transaction . |
22,956 | def add_del_on_list ( key , to_add , to_remove ) result = req_list ( new_req_list ( ) . add_add_del_on_list ( key , to_add , to_remove ) ) [ 0 ] process_result_add_del_on_list ( result ) end | Issues a add_del_on_list operation to scalaris and adds it to the current transaction . Changes the list stored at the given key i . e . first adds all items in to_add then removes all items in to_remove . Both to_add and to_remove must be lists . Assumes en empty list if no value exists at key . |
22,957 | def add_on_nr ( key , to_add ) result = req_list ( new_req_list ( ) . add_add_on_nr ( key , to_add ) ) [ 0 ] process_result_add_on_nr ( result ) end | Issues a add_on_nr operation to scalaris and adds it to the current transaction . Changes the number stored at the given key i . e . adds some value . Assumes 0 if no value exists at key . |
22,958 | def outcome num = random_float_including_zero_and_excluding_one @probability_range_to_outcome . detect { | probability_range , _ | num . in? probability_range } . last end | creates a new Simulator which will return the desired outcomes with the given probability |
22,959 | def add_route ( route ) raise InvalidRouteError . new ( 'Route must respond to #url_for' ) unless valid_route? ( route ) @routes << route unless route_exists? ( route ) end | Add a new route to the Routes collection |
22,960 | def add_route! ( route ) raise InvalidRouteError . new ( 'Route must respond to #url_for' ) unless valid_route? ( route ) raise ExistingRouteError . new ( ( "Route already exists for %s" % [ route . name ] ) ) if route_exists? ( route ) @routes << route end | Raise an exception if the route is invalid or already exists |
22,961 | def route_for ( name ) name = name . to_s @routes . select { | entry | entry . name == name } . first end | Retrieve a route by it s link relationship name |
22,962 | def route_for! ( name ) route = route_for ( name ) raise RouteNotFoundError . new ( ( "Route not found for %s" % [ name ] ) ) if route . nil? route end | Raise an exception of the route s not found |
22,963 | def audit_enabled ( opts = { } ) include InstanceMethods class_attribute :auditing_fields has_many :audits , :as => :auditable , :order => 'created_at DESC, id DESC' self . auditing_fields = gather_fields_for_auditing ( opts [ :fields ] ) after_create :log_creation after_update :log_update end | Auditing creates audit objects for a record . |
22,964 | def method_missing ( method , * args , & block ) instance_variable = instance_variablize ( method ) if respond_to_missing? ( method ) and instance_variable_defined? ( instance_variable ) self . class . send :attr_reader , method . to_sym instance_variable_get instance_variable else super end end | Dynamically sets attr_readers for elements |
22,965 | def respond_to_missing? ( method , include_private = false ) return super unless valid_instance_variable? method if instance_variable_defined? instance_variablize ( method ) true else super end end | Tells users that we respond to missing methods if they are instance variables . |
22,966 | def in? ( bounding_box ) top , left , bottom , right = bounding_box . coords ( left .. right ) === @lng && ( top .. bottom ) === @lat end | initializes a point object using latitude and longitude returns true if point is in bounding_box false otherwise |
22,967 | def pixel ( bounding_box ) x , y = MapKit . latlng2pixel ( @lat , @lng , bounding_box . zoom ) tile_x , tile_y = MapKit . latlng2pixel ( bounding_box . top , bounding_box . left , bounding_box . zoom ) [ x - tile_x , y - tile_y ] end | returns relative x and y for point in bounding_box |
22,968 | def grow! ( percent ) lng = ( ( 100.0 + percent ) * ( width / 2.0 / 100.0 ) ) / 2.0 lat = ( ( 100.0 + percent ) * ( height / 2.0 / 100.0 ) ) / 2.0 @top += lat @left -= lng @bottom -= lat @right += lng end | grow bounding box by percentage |
22,969 | def blog__sync_config_post_fields_with_db_post_fields posts = LatoBlog :: Post . all posts . map { | p | blog__sync_config_post_fields_with_db_post_fields_for_post ( p ) } end | This function syncronizes the config post fields with the post fields on database . |
22,970 | def blog__sync_config_post_fields_with_db_post_fields_for_post ( post ) post_fields = CONFIGS [ :lato_blog ] [ :post_fields ] post_fields . map { | key , content | blog__sync_config_post_field ( post , key , content ) } db_post_fields = post . post_fields . visibles . roots db_post_fields . map { | dbpf | blog__sync_db... | This function syncronizes the config post fields with the post fields on database for a single post object . |
22,971 | def blog__sync_config_post_field ( post , key , content ) db_post_field = LatoBlog :: PostField . find_by ( key : key , lato_blog_post_id : post . id , lato_blog_post_field_id : nil ) if content [ :categories ] && ! content [ :categories ] . empty? db_categories = LatoBlog :: Category . where ( meta_permalink : content... | This function syncronizes a single post field of a specific post with database . |
22,972 | def blog__sync_db_post_field ( post , db_post_field ) post_fields = CONFIGS [ :lato_blog ] [ :post_fields ] content = post_fields [ db_post_field . key ] db_post_field . update ( meta_visible : false ) && return unless content if content [ :categories ] && ! content [ :categories ] . empty? db_categories = LatoBlog :: ... | This function syncronizes a single post field of a specific post with config file . |
22,973 | def blog__update_db_post_field ( db_post_field , content , post_field_parent = nil ) db_post_field . update ( position : content [ :position ] , meta_visible : true ) case db_post_field . typology when 'text' update_db_post_field_text ( db_post_field , content , post_field_parent ) when 'textarea' update_db_post_field_... | This function update an existing post field on database with new content . |
22,974 | def json_data begin return JSON . parse ( self . data ) rescue JSON :: ParserError , TypeError => e logger . warn "Error while parsing raw transaction data: #{e.message}" return { } end end | Return the JSON data on this record as a hash |
22,975 | def md5_hash_is_valid? ( json ) if AuthNetReceiver . config . hash_value . nil? || AuthNetReceiver . config . gateway_login . nil? raise StandardError , 'AuthNetReceiver hash_value and gateway_login cannot be nil!' end parts = [ ] parts << AuthNetReceiver . config . hash_value parts << AuthNetReceiver . config . gatewa... | Check that the x_MD5_Hash value matches our expectations |
22,976 | def button ( type , * args , & block ) options = args . extract_options! button_type = 'dijit/form/Button' button_type = 'dojox/form/BusyButton' if options [ :busy ] options . reverse_merge! ( :' ' => button_type ) content = '' if value = options . delete ( :value ) content = value . html_safe else content = button_def... | Simple override of initializer in order to add in the dojo_props attribute Creates a button |
22,977 | def button_default_value obj = object . respond_to? ( :to_model ) ? object . to_model : object key = obj ? ( obj . persisted? ? :edit : :new ) : :submit model = if obj . class . respond_to? ( :model_name ) obj . class . model_name . human else object_name . to_s . humanize end defaults = [ ] defaults << "helpers.submit... | Basically the same as rails submit_default_value |
22,978 | def run ( command : , params : , output : nil ) answer = { } params [ :format ] = output params [ :record_name ] = nil ssh_cmds = send ( command , params , dir_info ) results = send_cmds_to_od_server ( ssh_cmds ) answer = process_results ( results , command , params , ssh_cmds ) params [ :value ] = nil return answer re... | after configuring a connection with . new - send commands via ssh to open directory |
22,979 | def local_count ( duration , type ) aggr = { } Octo :: Enterprise . each do | enterprise | args = { enterprise_id : enterprise . id , ts : duration , type : type } aggr [ enterprise . id . to_s ] = { } unless aggr . has_key? ( enterprise . id . to_s ) results = where ( args ) results_group = results . group_by { | x | ... | Does the counting from DB . Unlike the other counter that uses Redis . Hence the name local_count |
22,980 | def script_file_changed ( path ) Ichiban . logger . script_run ( path ) script = Ichiban :: Script . new ( path ) . run end | Takes an absolute path |
22,981 | def reblog_post ( id , reblog_key , options = { } ) @connection . post ( "/blog/#{name}/post/reblog" , options . merge ( 'id' => id , 'reblog_key' => reblog_key ) ) . response end | Reblog a Post |
22,982 | def create_file_blobs_table ( table_name = :file_blobs , options = { } , & block ) blob_limit = options [ :blob_limit ] || 1 . megabyte create_table table_name , id : false do | t | t . primary_key :id , :string , null : false , limit : 48 t . binary :data , null : false , limit : blob_limit block . call t end end | Creates the table used to hold file blobs . |
22,983 | def crop_resized ( image , size , gravity = "Center" ) size =~ / \d \d / width = $1 . to_i height = $2 . to_i cols , rows = image [ :dimensions ] if ( width != cols && height != rows ) image . combine_options do | c | if ( width != cols || height != rows ) scale = [ width / cols . to_f , height / rows . to_f ] . max * ... | Scale an image down and crop away any extra to achieve a certain size . This is handy for creating thumbnails of the same dimensions without changing the aspect ratio . |
22,984 | def megam_rest options = { :email => email , :api_key => api_key , :org_id => org_id , :password_hash => password_hash , :master_key => master_key , :host => host } if headers options [ :headers ] = headers end Megam :: API . new ( options ) end | clean up this module later . Build a megam api client |
22,985 | def add_attribute ( name , type , metadata = { } ) attr_reader name attributes << ( metadata || { } ) . merge ( :name => name . to_sym , :type => type . to_sym ) end | Attribute macros Defines an attribute |
22,986 | def string ( attr , metadata = { } ) add_attribute ( attr , :string , metadata ) define_method ( "#{attr}=" ) do | arg | instance_variable_set ( "@#{attr}" , arg . nil? ? nil : arg . to_s ) end end | Defines a string attribute |
22,987 | def boolean ( attr , metadata = { } ) add_attribute ( attr , :boolean , metadata ) define_method ( "#{attr}=" ) do | arg | v = case arg when String then BOOLEAN_TRUE_STRINGS . include? ( arg . downcase ) when Numeric then arg == 1 when nil then nil else ! ! arg end instance_variable_set ( "@#{attr}" , v ) end alias_met... | Defines a boolean attribute |
22,988 | def integer ( attr , metadata = { } ) add_attribute ( attr , :integer , metadata ) define_method ( "#{attr}=" ) do | arg | instance_variable_set ( "@#{attr}" , arg . nil? ? nil : arg . to_i ) end end | Defines a integer attribute |
22,989 | def float ( attr , metadata = { } ) add_attribute ( attr , :float , metadata ) define_method ( "#{attr}=" ) do | arg | instance_variable_set ( "@#{attr}" , arg . nil? ? nil : arg . to_f ) end end | Defines a float attribute |
22,990 | def decimal ( attr , metadata = { } ) add_attribute ( attr , :decimal , metadata ) define_method ( "#{attr}=" ) do | arg | instance_variable_set ( "@#{attr}" , arg . nil? ? nil : BigDecimal . new ( arg . to_s ) ) end end | Defines a decimal attribute |
22,991 | def date ( attr , metadata = { } ) add_attribute ( attr , :date , metadata ) define_method ( "#{attr}=" ) do | arg | v = case arg when Date then arg when Time , DateTime then arg . to_date when String then Date . parse ( arg ) when Hash args = Util . extract_values ( arg , :year , :month , :day ) args . present? ? Date... | Defines a date attribute |
22,992 | def array ( attr , metadata = { } ) add_attribute ( attr , :array , metadata ) define_method ( "#{attr}=" ) do | arg | instance_variable_set ( "@#{attr}" , Array ( arg ) ) end end | Defines an array attribute |
22,993 | def add_association ( name , type , metadata = { } ) associations << ( metadata || { } ) . merge ( :name => name . to_sym , :type => type . to_sym ) end | Defines an association |
22,994 | def has_many ( association_name , metadata = { } ) add_association association_name , :has_many , metadata association_class_name = metadata . try ( :fetch , :class_name , [ name . split ( '::' ) [ 0 .. - 2 ] . join ( '::' ) , association_name . to_s . classify ] . reject ( & :blank? ) . join ( '::' ) ) define_method (... | Defines an association that is a reference to an Array of another Attribution class . |
22,995 | def update_schema config . update_schema = config . update_schema . call if config . update_schema . respond_to? ( :call ) config . update_schema end | for lazy load |
22,996 | def to_h result = { } result [ :dataLength ] = @info ? @info . dataLength : 0 pct = withCurrentAndTotalBytes { | cur , total | ( cur . to_f / total . to_f * 100.0 ) . round 1 } result [ :percentComplete ] = pct secondsLeft = withCurrentAndTotalBytes do | cur , total | if @downloadRateDataOnly && @downloadRateDataOnly >... | Convert to a hash . Also flattens some of the data into new fields . |
22,997 | def list ( type , sym , count : nil ) if count raise BadCountError unless count . positive? end @expected << [ :list , type , sym , count ] end | Specifies a list of arguments of a given type to be parsed . |
22,998 | def parse! check_absorption! @expected . each do | type , * rest | case type when :list parse_list! ( * rest ) else parse_type! ( type , * rest ) end end self end | Perform the actual parsing . |
22,999 | def check_absorption! count , greedy = count_expected return unless strict? raise GreedyAbsorptionError . new ( count , @args . size ) if count >= @args . size && greedy raise AbsorptionError . new ( count , @args . size ) if count != @args . size && ! greedy end | Check whether the expected arguments absorb all supplied arguments . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.