idx int64 0 24.9k | question stringlengths 68 4.14k | target stringlengths 9 749 |
|---|---|---|
10,100 | def create_path ( path , options = { } ) unless @zk . exists? ( path ) @zk . create ( path , options [ :initial_value ] , :ephemeral => options . fetch ( :ephemeral , false ) ) logger . info ( "Created ZK node #{path}" ) end rescue ZK :: Exceptions :: NodeExists end | Creates a znode path . |
10,101 | def write_state ( path , value , options = { } ) create_path ( path , options . merge ( :initial_value => value ) ) @zk . set ( path , value ) end | Writes state to a particular znode path . |
10,102 | def handle_manual_failover_update ( event ) if event . node_created? || event . node_changed? perform_manual_failover end rescue => ex logger . error ( "Error scheduling a manual failover: #{ex.inspect}" ) logger . error ( ex . backtrace . join ( "\n" ) ) ensure @zk . stat ( manual_failover_path , :watch => true ) end | Handles a manual failover znode update . |
10,103 | def update_master_state ( node , snapshots ) state = @node_strategy . determine_state ( node , snapshots ) case state when :unavailable handle_unavailable ( node , snapshots ) when :available if node . syncing_with_master? handle_syncing ( node , snapshots ) else handle_available ( node , snapshots ) end else raise Inv... | Used to update the master node manager state . These states are only handled if this node manager instance is serving as the master manager . |
10,104 | def update_current_state ( node , state , latency = nil ) old_unavailable = @monitored_unavailable . dup old_available = @monitored_available . dup case state when :unavailable unless @monitored_unavailable . include? ( node ) @monitored_unavailable << node @monitored_available . delete ( node ) write_current_monitored... | Updates the current view of the world for this particular node manager instance . All node managers write this state regardless of whether they are the master manager or not . |
10,105 | def current_node_snapshots nodes = { } snapshots = Hash . new { | h , k | h [ k ] = NodeSnapshot . new ( k ) } fetch_node_manager_states . each do | node_manager , states | available , unavailable = states . values_at ( :available , :unavailable ) available . each do | node_string , latency | node = nodes [ node_string... | Builds current snapshots of nodes across all running node managers . |
10,106 | def wait_until_master logger . info ( 'Waiting to become master Node Manager ...' ) with_lock do @master_manager = true logger . info ( 'Acquired master Node Manager lock.' ) logger . info ( "Configured node strategy #{@node_strategy.class}" ) logger . info ( "Configured failover strategy #{@failover_strategy.class}" )... | Waits until this node manager becomes the master . |
10,107 | def manage_nodes discover_nodes redirect_slaves_to ( @master ) while running? && master_manager? @zk_lock . assert! sleep ( CHECK_INTERVAL ) @lock . synchronize do snapshots = current_node_snapshots if ensure_sufficient_node_managers ( snapshots ) snapshots . each_key do | node | update_master_state ( node , snapshots ... | Manages the redis nodes by periodically processing snapshots . |
10,108 | def with_lock @zk_lock ||= @zk . locker ( current_lock_path ) begin @zk_lock . lock! ( true ) rescue Exception running? ? raise : return end if running? @zk_lock . assert! yield end ensure if @zk_lock begin @zk_lock . unlock! rescue => ex logger . warn ( "Failed to release lock: #{ex.inspect}" ) end end end | Executes a block wrapped in a ZK exclusive lock . |
10,109 | def perform_manual_failover @lock . synchronize do return unless running? && @master_manager && @zk_lock @zk_lock . assert! new_master = @zk . get ( manual_failover_path , :watch => true ) . first return unless new_master && new_master . size > 0 logger . info ( "Received manual failover request for: #{new_master}" ) l... | Perform a manual failover to a redis node . |
10,110 | def ensure_sufficient_node_managers ( snapshots ) currently_sufficient = true snapshots . each do | node , snapshot | node_managers = snapshot . node_managers if node_managers . size < @required_node_managers logger . error ( "Not enough Node Managers in snapshot for node #{node}. " + "Required: #{@required_node_manage... | Determines if each snapshot has a sufficient number of node managers . |
10,111 | def failover_strategy_candidate ( snapshots ) filtered_snapshots = snapshots . select do | node , snapshot | snapshot . viewable_by? ( manager_id ) end logger . info ( 'Attempting to find candidate from snapshots:' ) logger . info ( "\n" + filtered_snapshots . values . join ( "\n" ) ) @failover_strategy . find_candidat... | Invokes the configured failover strategy . |
10,112 | def C_Initialize ( args = nil ) case args when Hash pargs = CK_C_INITIALIZE_ARGS . new args . each { | k , v | pargs . send ( "#{k}=" , v ) } else pargs = args end unwrapped_C_Initialize ( pargs ) end | Initialize a pkcs11 dynamic library . |
10,113 | def C_GetSlotList ( tokenPresent = false ) slots = unwrapped_C_GetSlotList ( tokenPresent ) slots . map { | slot | Slot . new self , slot } end | Obtain an array of Slot objects in the system . |
10,114 | def C_FindObjects ( max_count ) objs = @pk . C_FindObjects ( @sess , max_count ) objs . map { | obj | Object . new @pk , @sess , obj } end | Continues a search for token and session objects that match a template obtaining additional object handles . |
10,115 | def C_GenerateKey ( mechanism , template = { } ) obj = @pk . C_GenerateKey ( @sess , to_mechanism ( mechanism ) , to_attributes ( template ) ) Object . new @pk , @sess , obj end | Generates a secret key Object or set of domain parameters creating a new Object . |
10,116 | def C_DeriveKey ( mechanism , base_key , template = { } ) obj = @pk . C_DeriveKey ( @sess , to_mechanism ( mechanism ) , base_key , to_attributes ( template ) ) Object . new @pk , @sess , obj end | Derives a key from a base key creating a new key object . |
10,117 | def C_OpenSession ( flags = CKF_SERIAL_SESSION ) nr = @pk . C_OpenSession ( @slot , flags ) sess = Session . new @pk , nr if block_given? begin yield sess ensure sess . close end else sess end end | Opens a Session between an application and a token in a particular slot . |
10,118 | def [] ( * attributes ) attrs = C_GetAttributeValue ( attributes . flatten ) if attrs . length > 1 || attributes . first . kind_of? ( Array ) attrs . map ( & :value ) else attrs . first . value unless attrs . empty? end end | Get the value of one or several attributes of the object . |
10,119 | def []= ( * attributes ) values = attributes . pop values = [ values ] unless values . kind_of? ( Array ) raise ArgumentError , "different number of attributes to set (#{attributes.length}) and given values (#{values.length})" unless attributes . length == values . length map = values . each . with_index . inject ( { }... | Modifies the value of one or several attributes of the object . |
10,120 | def C_GetAttributeValue ( * template ) case template . length when 0 return @pk . vendor_all_attribute_names . map { | attr | begin attributes ( @pk . vendor_const_get ( attr ) ) rescue PKCS11 :: Error end } . flatten . compact when 1 template = template [ 0 ] end template = to_attributes template @pk . C_GetAttributeV... | Obtains the value of one or more attributes of the object in a single call . |
10,121 | def get_campaigns_v2 ( data ) if data [ 'type' ] == "" and data [ 'status' ] == "" and data [ 'page' ] == "" and data [ 'page_limit' ] == "" return self . get ( "campaign/detailsv2/" , "" ) else return self . get ( "campaign/detailsv2/type/" + data [ 'type' ] + "/status/" + data [ 'status' ] + "/page/" + data [ 'page' ... | Get all campaigns detail . |
10,122 | def authenticate_with_auth_code ( authorization_code , redirect_uri ) response = @oauth_connection . post do | req | req . url '/oauth/token' req . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' req . body = { :grant_type => 'authorization_code' , :client_id => api_key , :client_secret => api_secret ,... | sign in as a user using the server side flow |
10,123 | def authenticate_with_credentials ( username , password , offering_id = nil ) body = { :grant_type => 'password' , :client_id => api_key , :client_secret => api_secret , :username => username , :password => password } body [ :offering_id ] = offering_id if offering_id . present? response = @oauth_connection . post do |... | Sign in as a user using credentials |
10,124 | def authenticate_with_app ( app_id , app_token ) response = @oauth_connection . post do | req | req . url '/oauth/token' req . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' req . body = { :grant_type => 'app' , :client_id => api_key , :client_secret => api_secret , :app_id => app_id , :app_token => a... | Sign in as an app |
10,125 | def authenticate_with_transfer_token ( transfer_token ) response = @oauth_connection . post do | req | req . url '/oauth/token' req . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' req . body = { :grant_type => 'transfer_token' , :client_id => api_key , :client_secret => api_secret , :transfer_token =... | Sign in with an transfer token only available for Podio |
10,126 | def authenticate_with_sso ( attributes ) response = @oauth_connection . post do | req | req . url '/oauth/token' , :grant_type => 'sso' , :client_id => api_key , :client_secret => api_secret req . body = attributes end @oauth_token = OAuthToken . new ( response . body ) configure_oauth [ @oauth_token , response . body ... | Sign in with SSO |
10,127 | def authenticate_with_openid ( identifier , type ) response = @trusted_connection . post do | req | req . url '/oauth/token_by_openid' req . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' req . body = { :grant_type => type , :client_id => api_key , :client_secret => api_secret , :identifier => identif... | Sign in with an OpenID only available for Podio |
10,128 | def authenticate_with_activation_code ( activation_code ) response = @oauth_connection . post do | req | req . url '/oauth/token' req . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' req . body = { :grant_type => 'activation_code' , :client_id => api_key , :client_secret => api_secret , :activation_co... | Sign in with an activation code only available for Podio |
10,129 | def oauth_token = ( new_oauth_token ) @oauth_token = new_oauth_token . is_a? ( Hash ) ? OAuthToken . new ( new_oauth_token ) : new_oauth_token configure_oauth end | reconfigure the client with a different access token |
10,130 | def distance return nil unless @locations . size > 1 locations . each_cons ( 2 ) . reduce ( 0 ) do | acc , ( loc1 , loc2 ) | acc + loc1 . distance_to ( loc2 ) end end | Give the distance in meters between ordered location points using the Haversine formula |
10,131 | def update! ( params ) self . name = params [ :name ] self . endpoint = params [ :endpoint ] self . secret = params [ :secret ] self . gitlab = params [ :gitlab ] || false self . shortener_url = params [ :shortener_url ] self . shortener_secret = params [ :shortener_secret ] set_channels params [ :channels ] , params [... | Creates a new integration from the supplied hash . |
10,132 | def add_channels! ( channels , conf ) channels . each_key do | identifier | if @channels . any? { | chan | chan . identifier_eql? ( identifier ) } raise CommandError , "channel #{identifier.inspect} already exists" end end new_channels = Channel . deserialize_all ( channels , conf ) @channels . push ( * new_channels ) ... | Adds the specified channels to this integration . |
10,133 | def delete_channels! ( identifiers ) identifiers . each do | identifier | channel = @channels . find { | chan | chan . identifier_eql? identifier } if channel . nil? raise CommandError , "channel #{identifier.inspect} does not exist" end @channels . delete channel end end | Deletes the specified channels from this integration . |
10,134 | def set_channels ( channels , conf ) if channels . nil? @channels = [ ] if @channels . nil? return end @channels = valid! ( channels , Channel . deserialize_all ( channels , conf ) , :@channels , invalid_error : 'invalid channel list %s' ) { [ ] } end | Sets the list of channels . |
10,135 | def serialize ( conf ) check_channel_networks! ( conf ) [ name , { 'endpoint' => endpoint , 'secret' => secret , 'gitlab' => gitlab , 'shortener_url' => shortener_url , 'shortener_secret' => shortener_secret , 'channels' => Channel . serialize_all ( channels , conf ) } ] end | Serializes this integration . |
10,136 | def command ( cmd , explicit ) return false unless check_pipe_exist ( explicit ) Timeout . timeout 5 do File . open @pipe , 'w' do | p | p . puts cmd end end true rescue Timeout :: Error communication_error! 'no response' end | Sends a command to the named pipe . |
10,137 | def create ( params ) integration = Integration . new ( params . merge ( config : { networks : @config . networks } ) ) @config . transaction do check_available! ( integration . name , integration . endpoint ) NetworkManager . new ( @config ) . check_channels! ( integration ) @config . integrations << integration integ... | Constructs a new integration manager for a specified configuration . |
10,138 | def update ( name , params ) @config . transaction do integration = find_integration! ( name ) check_available_except! ( params [ :name ] , params [ :endpoint ] , integration ) update_channels! ( integration , params ) NetworkManager . new ( @config ) . check_channels! ( integration ) integration . update! ( params ) i... | Updates an integration with the given parameters . |
10,139 | def destroy ( name , params ) @config . transaction do integration = find_integration! ( name ) @config . integrations . delete integration integration_feedback ( integration , :destroyed ) unless params [ :quiet ] end end | Destroys an integration . |
10,140 | def list ( search ) @config . transaction do integrations = @config . integrations . dup unless search . nil? integrations . select! do | intg | intg . name . downcase . include? search . downcase end end puts 'No integrations found' if integrations . empty? integrations . each { | intg | show_integration intg } end en... | Lists all integrations or integrations with names containing the given search term . |
10,141 | def find_integration! ( name ) integration = find_integration ( name ) return integration unless integration . nil? raise CommandError , "an integration with the name #{name.inspect} " 'does not exist' end | Finds an integration given its name . |
10,142 | def check_available! ( name , endpoint ) check_name_available! ( name ) unless name . nil? check_endpoint_available! ( endpoint ) unless endpoint . nil? end | Checks that the specified name and endpoint are available for use . |
10,143 | def check_available_except! ( name , endpoint , intg ) check_name_available! ( name ) unless name . nil? || intg . name_eql? ( name ) return if endpoint . nil? || intg . endpoint_eql? ( endpoint ) check_endpoint_available! ( endpoint ) end | Checks that the specified name and endpoint are available for use by the specified integration . |
10,144 | def update_channels! ( integration , params ) integration . channels . clear if params [ :clear_channels ] if params [ :delete_channel ] integration . delete_channels! ( params [ :delete_channel ] ) end return unless params [ :add_channel ] integration . add_channels! ( params [ :add_channel ] , networks : @config . ne... | Updates the channels associated with an integration from the specified parameters . |
10,145 | def show_integration ( integration ) puts "Integration: #{integration.name}" puts "\tEndpoint: #{integration.endpoint}" puts "\tSecret: #{show_integration_secret(integration)}" if integration . channels . empty? puts "\tChannels: (none)" else puts "\tChannels:" show_integration_channels ( integration ) end end | Prints information about an integration . |
10,146 | def show_integration_channels ( integration ) integration . channels . each do | channel | puts "\t\t- #{channel.name} on #{channel.network.name}" puts "\t\t\tKey: #{channel.key}" if channel . key? puts "\t\t\tMessages are sent without joining" if channel . send_external end end | Prints information about the channels associated with an integration . |
10,147 | def create ( params ) network = Network . new ( params . merge ( config : { } ) ) @config . transaction do check_name_available! ( network . name ) @config . networks << network network_feedback ( network , :created ) unless params [ :quiet ] end end | Constructs a new network manager for a specified configuration . |
10,148 | def update ( name , params ) @config . transaction do network = find_network! ( name ) unless params [ :name ] . nil? check_name_available_except! ( params [ :name ] , network ) end network . update! ( params ) network_feedback ( network , :updated ) unless params [ :quiet ] end end | Updates a network with the given parameters . |
10,149 | def destroy ( name , params ) @config . transaction do network = find_network! ( name ) @config . networks . delete network network_feedback ( network , :destroyed ) unless params [ :quiet ] end end | Destroys a network . |
10,150 | def list ( search ) @config . transaction do networks = @config . networks . dup unless search . nil? networks . select! { | net | net . name . downcase . include? search . downcase } end puts 'No networks found' if networks . empty? networks . each { | net | show_network net } end end | Lists all networks or networks with names containing the given search term . |
10,151 | def find_network! ( name ) network = find_network ( name ) return network unless network . nil? raise CommandError , "a network with the name #{name.inspect} " 'does not exist' end | Finds a network given its name . |
10,152 | def check_channels! ( integration ) integration . channels . map ( & :network ) . map ( & :name ) . each do | network | find_network! ( network ) end end | Checks that all channels associated with an integration belong to a valid network . |
10,153 | def check_name_available_except! ( name , network ) return if name . nil? || network . name_eql? ( name ) || ! find_network ( name ) raise CommandError , "a network with the name #{name.inspect} " 'already exists' end | Checks that the specified name is available for use by the specified network . |
10,154 | def show_network ( network ) puts "Network: #{network.name}" security = "#{network.secure ? 'secure' : 'insecure'} connection" password = network . server_password puts "\tServer: #{network.host}:#{network.real_port} (#{security})" puts "\tPassword: #{'*' * password.length}" unless password . to_s . empty? puts "... | Prints information about a network . |
10,155 | def join ipc = Thread . new { @ipc_server . join && stop } web = Thread . new { @web_server . join && stop } ipc . join web . join @irc_client . join end | Waits for this bot to stop . If any of the managed threads finish early the bot is shut down immediately . |
10,156 | def trap_signals shutdown = proc do | signal | STDERR . puts "\nReceived #{signal}, shutting down..." stop join exit 1 end trap ( 'INT' ) { shutdown . call 'SIGINT' } trap ( 'TERM' ) { shutdown . call 'SIGTERM' } end | Sets traps for SIGINT and SIGTERM so Codebot can shut down gracefully . |
10,157 | def create_server core = @core Sinatra . new do include WebListener configure { instance_eval ( & WebServer . configuration ) } post ( '/*' ) { handle_post ( core , request , params ) } error ( Sinatra :: NotFound ) { [ 405 , 'Method not allowed' ] } end end | Creates a new Sinatra server for handling incoming requests . |
10,158 | def handle_post ( core , request , params ) payload = params [ 'payload' ] || request . body . read dispatch ( core , request , * params [ 'splat' ] , payload ) rescue JSON :: ParserError [ 400 , 'Invalid JSON payload' ] end | Handles a POST request . |
10,159 | def dispatch ( core , request , endpoint , payload ) intg = integration_for ( core . config , endpoint ) return [ 404 , 'Endpoint not registered' ] if intg . nil? return [ 403 , 'Invalid signature' ] unless valid? ( request , intg , payload ) req = create_request ( intg , request , payload ) return req if req . is_a? A... | Dispatches a received payload to the IRC client . |
10,160 | def create_request ( integration , request , payload ) event = if integration . gitlab create_gitlab_event ( request ) else create_github_event ( request ) end return event if event . is_a? Array return [ 501 , 'Event not yet supported' ] if event . nil? Request . new ( integration , event , payload ) end | Creates a new request for the webhook . |
10,161 | def valid? ( request , integration , payload ) return true unless integration . verify_payloads? secret = integration . secret if integration . gitlab secret == request . env [ 'HTTP_X_GITLAB_TOKEN' ] else request_signature = request . env [ 'HTTP_X_HUB_SIGNATURE' ] Cryptography . valid_signature? ( payload , secret , ... | Verifies a webhook signature . |
10,162 | def dispatch ( request ) request . each_network do | network , channels | connection = connection_to ( network ) next if connection . nil? channels . each do | channel | message = request . to_message_for channel connection . enqueue message end end end | Creates a new IRC client . |
10,163 | def migrate! @semaphore . synchronize do return unless @active networks = @core . config . networks ( @checkpoint - networks ) . each { | network | disconnect_from network } ( networks - @checkpoint ) . each { | network | connect_to network } @checkpoint = networks end end | Connects to and disconnects from networks as necessary in order for the list of connections to reflect changes to the configuration . |
10,164 | def disconnect_from ( network ) connection = @connections . delete connection_to ( network ) connection . tap ( & :stop ) . tap ( & :join ) unless connection . nil? end | Disconnects from a given network if the network is currently connected . |
10,165 | def format_number ( num , singular = nil , plural = nil ) bold_num = :: Cinch :: Formatting . format ( :bold , num . to_s ) ( bold_num + ' ' + ( num == 1 ? singular : plural ) . to_s ) . strip end | Formats a number . |
10,166 | def ary_to_sentence ( ary , empty_sentence = nil ) case ary . length when 0 then empty_sentence . to_s when 1 then ary . first when 2 then ary . join ( ' and ' ) else * ary , last_element = ary ary_to_sentence ( [ ary . join ( ', ' ) , last_element ] ) end end | Constructs a sentence from array elements connecting them with commas and conjunctions . |
10,167 | def abbreviate ( text , suffix : ' ...' , length : 200 ) content_length = length - suffix . length short = text . to_s . lines . first . to_s . strip [ 0 ... content_length ] . strip yield text if block_given? short << suffix unless short . eql? text . to_s . strip short end | Truncates the given text appending a suffix if it was above the allowed length . |
10,168 | def prettify ( text ) pretty = abbreviate ( text ) { | short | short . sub! ( / \z / , '' ) } sanitize pretty end | Abbreviates the given text removes any trailing punctuation except for the ellipsis appended if the text was truncated and sanitizes the text for delivery to IRC . |
10,169 | def extract ( * path ) node = payload node if path . all? do | sub | break unless node . is_a? Hash node = node [ sub . to_s ] end end | Safely extracts a value from a JSON object . |
10,170 | def run ( * ) create_pipe file = File . open @pipe , 'r+' while ( line = file . gets . strip ) handle_command line end ensure delete_pipe end | Starts this IPC server . |
10,171 | def handle_command ( command ) case command when 'REHASH' then @core . config . load! when 'STOP' then Thread . new { @core . stop } else STDERR . puts "Unknown IPC command: #{command.inspect}" end end | Handles an incoming IPC command . |
10,172 | def valid_network ( name , conf ) return if name . nil? conf [ :networks ] . find { | net | net . name_eql? name } end | Sanitizes a network name . |
10,173 | def update! ( params ) set_identifier params [ :identifier ] , params [ :config ] if params [ :identifier ] self . name = params [ :name ] self . key = params [ :key ] self . send_external = params [ :send_external ] set_network params [ :network ] , params [ :config ] end | Creates a new channel from the supplied hash . |
10,174 | def set_network ( network , conf ) @network = valid! network , valid_network ( network , conf ) , :@network , required : true , required_error : 'channels must have a network' , invalid_error : 'invalid channel network %s' end | Sets the network for this channel . |
10,175 | def set_identifier ( identifier , conf ) network_name , self . name = identifier . split ( '/' , 2 ) if identifier set_network ( network_name , conf ) end | Sets network and channel name based on the given identifier . |
10,176 | def load_from_file! ( file ) data = Psych . safe_load ( File . read ( file ) ) if File . file? file data = { } unless data . is_a? Hash conf = { } conf [ :networks ] = Network . deserialize_all data [ 'networks' ] , conf conf [ :integrations ] = Integration . deserialize_all data [ 'integrations' ] , conf conf end | Loads the configuration from the specified file . |
10,177 | def save_to_file! ( file ) data = { } data [ 'networks' ] = Network . serialize_all @conf [ :networks ] , @conf data [ 'integrations' ] = Integration . serialize_all @conf [ :integrations ] , @conf File . write file , Psych . dump ( data ) end | Saves the configuration to the specified file . |
10,178 | def update! ( params ) self . name = params [ :name ] self . server_password = params [ :server_password ] self . nick = params [ :nick ] self . bind = params [ :bind ] self . modes = params [ :modes ] update_complicated! ( params ) end | Creates a new network from the supplied hash . |
10,179 | def update_connection ( host , port , secure ) @host = valid! host , valid_host ( host ) , :@host , required : true , required_error : 'networks must have a hostname' , invalid_error : 'invalid hostname %s' @port = valid! port , valid_port ( port ) , :@port , invalid_error : 'invalid port number %s' @secure = valid! ( ... | Updates the connection details of this network . |
10,180 | def update_sasl ( disable , user , pass ) @sasl_username = valid! user , valid_string ( user ) , :@sasl_username , invalid_error : 'invalid SASL username %s' @sasl_password = valid! pass , valid_string ( pass ) , :@sasl_password , invalid_error : 'invalid SASL password %s' return unless disable @sasl_username = nil @sa... | Updates the SASL authentication details of this network . |
10,181 | def update_nickserv ( disable , user , pass ) @nickserv_username = valid! user , valid_string ( user ) , :@nickserv_username , invalid_error : 'invalid NickServ username %s' @nickserv_password = valid! pass , valid_string ( pass ) , :@nickserv_password , invalid_error : 'invalid NickServ password %s' return unless disa... | Updates the NickServ authentication details of this network . |
10,182 | def serialize ( _conf ) [ name , Network . fields . map { | sym | [ sym . to_s , send ( sym ) ] } . to_h ] end | Serializes this network . |
10,183 | def start ( arg = nil ) return if running? @thread = Thread . new do Thread . current . abort_on_exception = true run ( arg ) end end | Starts a new managed thread if no thread is currently running . The thread invokes the + run + method of the class that manages it . |
10,184 | def run ( connection ) @connection = connection bot = create_bot ( connection ) thread = Thread . new { bot . start } @ready . pop loop { deliver bot , dequeue } ensure thread . exit unless thread . nil? end | Starts this IRC thread . |
10,185 | def deliver ( bot , message ) channel = bot . Channel ( message . channel . name ) message . format . to_a . each do | msg | channel . send msg end end | Delivers a message to an IRC channel . |
10,186 | def channels ( config , network ) config . integrations . map ( & :channels ) . flatten . select do | channel | network == channel . network end end | Gets the list of channels associated with this network . |
10,187 | def create_bot ( con ) net = con . network chan_ary = channel_array ( con . core . config , network ) cc = self Cinch :: Bot . new do configure do | c | c . channels = chan_ary c . local_host = net . bind c . modes = net . modes . to_s . gsub ( / \A \+ / , '' ) . chars . uniq c . nick = net . nick c . password = net . ... | Constructs a new bot for the given IRC network . |
10,188 | def user ( id ) if id cached_user = users . detect { | u | u [ :id ] == id } user = cached_user || fetch_user ( id ) self . users << user user end end | return the user with the given id ; if it isn t in our room cache do a request to get it |
10,189 | def fetch_user ( id ) user_data = connection . get ( "/users/#{id}.json" ) user = user_data && user_data [ :user ] user [ :created_at ] = Time . parse ( user [ :created_at ] ) user end | Perform a request for the user with the given ID |
10,190 | def start Signal . trap ( :INT ) do coordinator . running = false end Signal . trap ( :TERM ) do exit end coordinator . run end | Initialize a new CLI instance to handle option parsing from arguments into configuration to start the coordinator running on all mailboxes |
10,191 | def run @running = true connection . on_new_message do | message | @mailbox . deliver ( message ) end self . watching_thread = Thread . start do while ( running? ) do connection . wait end end watching_thread . abort_on_exception = true end | run the mailbox watcher |
10,192 | def start_watching start_original Kernel . loop do if @files . find { | file | FileTest . exist? ( file ) && File . stat ( file ) . mtime > @time } puts 'reloading sketch...' Processing . app && Processing . app . close java . lang . System . gc @time = Time . now start_runner reload_files_to_watch end sleep SLEEP_TIME... | Kicks off a thread to watch the sketch reloading JRubyArt and restarting the sketch whenever it changes . |
10,193 | def report_errors yield rescue Exception => e wformat = 'Exception occured while running sketch %s...' tformat = "Backtrace:\n\t%s" warn format ( wformat , File . basename ( SKETCH_PATH ) ) puts format ( tformat , e . backtrace . join ( "\n\t" ) ) end | Convenience function to report errors when loading and running a sketch instead of having them eaten by the thread they are loaded in . |
10,194 | def close control_panel . remove if respond_to? ( :control_panel ) surface . stopThread surface . setVisible ( false ) if surface . isStopped dispose Processing . app = nil end | Close and shutter a running sketch . But don t exit . |
10,195 | def buffer ( buf_width = width , buf_height = height , renderer = @render_mode ) create_graphics ( buf_width , buf_height , renderer ) . tap do | buffer | buffer . begin_draw yield buffer buffer . end_draw end end | Nice block method to draw to a buffer . You can optionally pass it a width a height and a renderer . Takes care of starting and ending the draw for you . |
10,196 | def hsb_color ( hue , sat , brightness ) Java :: Monkstone :: ColorUtil . hsbToRgB ( hue , sat , brightness ) end | hue sat brightness in range 0 .. 1 . 0 returns RGB color int |
10,197 | def dist ( * args ) case args . length when 4 return dist2d ( * args ) when 6 return dist3d ( * args ) else raise ArgumentError , 'takes 4 or 6 parameters' end end | explicitly provide processing . org dist instance method |
10,198 | def blend_color ( c1 , c2 , mode ) Java :: ProcessingCore :: PImage . blendColor ( c1 , c2 , mode ) end | Uses PImage class method under hood |
10,199 | def find_method ( method_name ) reg = Regexp . new ( method_name . to_s , true ) methods . sort . select { | meth | reg . match ( meth ) } end | There s just so many functions in Processing Here s a convenient way to look for them . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.