working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,577 snippets matching: parameter

    public by micurs  6865990  355  9  18

    Typescript: passing a class member function as parameter to another function

    Typescript introduces the class construct and the concept of member functions. However if you try to pass a instance member function as parameter to another function the binding with the instance is lost. To solve this problem you can use the capability of javascript (and Typescript) to support closures on anonymous function (or lambda expressio
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    
    import _ = require("underscore");
    
    class SomePeople {
      values : string[] = [ 'John', 'Mary', 'Peter'];
    
      out() {
        _.each( this.values, (v) => process.stdout.write( v + '\n') );
      }
    }
    // This function accept a function it will execute internally
    function outSomething( outFunc : () => any ) {
      outFunc();
    }
    
    var crowd = new SomePeople();
    
    // This won't work since the actual crowd instance binding will be lost
    outSomething( crowd.out );
    
    // This will work: the closure within the lambda expression retain the
    // crowd instance and its data
    outSomething( () => crowd.out() );
        

    public by lbottaro  476197  8  6  2

    JavaScript equivalent to C# String.format

    The code below is the Javascript equivalent to C# String.Format() for replacing elements like {0}, {1}, {2} with parameters. In this case the String prototype is modified, adding the new format() method to all string instances. How to use var mystring = "Hello {0}, how are you? My name is {1}. Bye {0}!" mystring.format("Alice", "Bob") //
    // First, checks if it isn't implemented yet.
    if (!String.prototype.format) {
      String.prototype.format = function() {
        var args = arguments;
        return this.replace(/{(\d+)}/g, function(match, number) { 
          return typeof args[number] != 'undefined'
            ? args[number]
            : match
          ;
        });
      };
    }            

    public by lbottaro  172525  10  6  0

    curl to send a GET HTTP request with query parameters

    Try to perform a GET HTTP to snip2code server, to list the public snippets in Channels. URL example to get: https://www.snip2code.com/Explore/InChannel?q=test&sort=0&direction=1 Options: -d: list all query parameters -G: perform GET verb
    curl -v -L -G -d "q=test&sort=0&direction=1" https://www.snip2code.com/Explore/InChannel                               

    public by Geometry  1238  7  5  0

    Discrete: Creates a new <see cref="MetropolisHasting"/> sampler using symmetric geometric distributions as the parameter proposal generation priors.

    Creates a new sampler using symmetric geometric distributions as the parameter proposal generation priors. The number of dimensions in each observation. The target distribution whose samples should be generated. A sampling algorithm that can generate samples from the target distribution.
    /// <summary>
    ///   Creates a new <see cref="MetropolisHasting"/> sampler using symmetric geometric distributions
    ///   as the parameter proposal generation priors. 
    /// </summary>
    /// 
    /// <param name="dimensions">The number of dimensions in each observation.</param>
    /// <param name="distribution">The target distribution whose samples should be generated.</param>
    /// 
    /// <returns>A sampling algorithm that can generate samples from the target distribution.</returns>
    /// 
    public static MetropolisHasting<int, Independent<SymmetricGeometricDistribution>, T> Discrete<T>(int dimensions, T distribution)
        where T : IMultivariateDistribution<int[]>
    {
        return new MetropolisHasting<int, Independent<SymmetricGeometricDistribution>, T>(
            distribution, new Independent<SymmetricGeometricDistribution>(dimensions,
                () => new SymmetricGeometricDistribution(0.5)));
    }

    public by lbottaro  2147  0  8  0

    How to check the presence of argv parameter in python

    This script checks the parameters passed via command line. If the parameter is present a check on its value and cast are performed. The script handles exception as well.
    #!/usr/bin/python
    
    import sys
    
    # ------------------------------- Main program -------------------------------
    
    # The default value for command line argv parameter
    default_size = 70
    actual_value = default_size
    
    if (len(sys.argv) > 1):
        try:
            if(int(sys.argv[1]) > 0):
                actual_value = int(sys.argv[1])
                print "Actual size: " + str(actual_value)
            else:
                print("Please specify only positive integer as parameter! " + str(sys.argv[1]))
                print("Actual size set with default value: " + str(actual_value))
        except Exception:
            print("Ouch!... Please review the parameter! " + str(sys.argv[1]))
            sys.exit(-1)
    
    

    public by cghersi  2397  1  6  2

    C#: Read the output parameter of a stored procedure

    fetch the output parameter of the given SP and try to read it
    static public string ReadOutputParam(this SqlCommand sqlCmd, string outputParamName, string defaultValue = "")
    {
      object outputValue = defaultValue;
      if (!string.IsNullOrEmpty(outputParamName))
        outputValue = sqlCmd.Parameters[outputParamName].Value;
    
      if ((outputValue == null) || (outputValue.Equals(DBNull.Value)))
        return defaultValue;
      else
        return outputValue.ToString();
    }
    

    public by cghersi @ MailUp API DEV  998  4  6  0

    Data Contract as input parameter for Create/Update List

    This bean collects all the parameters that should be passed to the methods regarding the management of Lists. There are two distinguished beans for the creation and for the update so that the "required" attributes can be set properly for the two different cases. The attribute 'scope' is designed as String, and will be managed in the backend code
    namespace MailUpSOA.Ws.Contract.API.DataContracts.Console
    {
        [DataContract(Name = "ConsoleListCreateDetails", Namespace = "http://MailupSoa.Ws.Schema.API.Console")]
        public class ConsoleListCreateDetails : ConsoleListDetails
        {
            [DataMember(IsRequired = true)]
            public String Name { get; set; }
    
            [DataMember(IsRequired = true)]
            public Int32 idSettings { get; set; }
    
            [DataMember(IsRequired = true)]
            public Boolean useDefaultSettings { get; set; }
    
            [DataMember(IsRequired = true)]
            public Boolean copyTemplate { get; set; }
    
            [DataMember(IsRequired = true)]
            public String scope { get; set; }
    
            [DataMember(IsRequired = true)]
            public Boolean business { get; set; }
    
            [DataMember(IsRequired = true)]
            public Boolean Customer { get; set; }
    
            [DataMember(IsRequired = true)]
            public Boolean copyWebhooks { get; set; }
        }
        
        [DataContract(Name = "ConsoleListUpdateDetails", Namespace = "http://MailupSoa.Ws.Schema.API.Console")]
        public class ConsoleListUpdateDetails : ConsoleListDetails
        {
            [DataMember(IsRequired = true)]
            public Int32 IdList { get; set; }
    
            [DataMember(IsRequired = false)]
            public String Name { get; set; }
    
            [DataMember(IsRequired = false)]
            public String scope { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? business { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? Customer { get; set; }
        }
        
        [DataContract(Name = "ConsoleListDetails", Namespace = "http://MailupSoa.Ws.Schema.API.Console")]
        public class ConsoleListDetails : BaseDataContract
        {
            #region OPTIONS
    
            [DataMember(IsRequired = false)]
            public String format { get; set; }
    
            [DataMember(IsRequired = false)]
            public String owneremail { get; set; }
    
            [DataMember(IsRequired = false)]
            public String bouncedemail { get; set; }
    
            [DataMember(IsRequired = false)]
            public String description { get; set; }
    
            [DataMember(IsRequired = false)]
            public String charset { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? @public { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? tracking { get; set; }
    
            [DataMember(IsRequired = false)]
            public String nl_sendername { get; set; }
    
            [DataMember(IsRequired = false)]
            public String sms_sendername { get; set; }
    
            [DataMember(IsRequired = false)]
            public Int32? optout_type { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? sendemailoptout { get; set; }
    
            [DataMember(IsRequired = false)]
            public String notifyemail { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? frontendform { get; set; }
    
            [DataMember(IsRequired = false)]
            public String disclaimer { get; set; }
    
            [DataMember(IsRequired = false)]
            public String headerxabuse { get; set; }
    
            [DataMember(IsRequired = false)]
            public Int32? kbmax { get; set; }
    
            [DataMember(IsRequired = false)]
            public String replyto { get; set; }
    
            [DataMember(IsRequired = false)]
            public String displayas { get; set; }
    
            [DataMember(IsRequired = false)]
            public String headerlistunsubscriber { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? multipart_text { get; set; }
    
            [DataMember(IsRequired = false)]
            public String conversionlab_trackcode { get; set; }
    
            [DataMember(IsRequired = false)]
            public String default_prefix { get; set; }
    
            [DataMember(IsRequired = false)]
            public String multi_optout_list { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? subscribedemail { get; set; }
    
            [DataMember(IsRequired = false)]
            public Boolean? sendconfirmsms { get; set; }
    
            [DataMember(IsRequired = false)]
            public String senderfaxname { get; set; }
    
            [DataMember(IsRequired = false)]
            public String senderfax { get; set; }
    
            #endregion
        }
        
        /// <summary>
        /// Provides an enumeration of the possible scopes of a list
        /// </summary>
        public enum ListScopeEnum
        {
            /// <summary>
            /// List to be used to send newsletters
            /// </summary>
            newsletters,
            /// <summary>
            /// List to be used to send direct messages
            /// </summary>
            Direct_Advertising,
            /// <summary>
            /// List to be used to send transactional emails
            /// </summary>
            Transactional
        }
    }

    public by marksimon232  3431  0  6  1

    Swift Collections: Simple function with return value

    I want to our function to get the current time, formatted and returned as a String.
    => Objective-C:
    -(NSString *)getCurrentTime {
        
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        NSString *currentTime = [dateFormatter stringFromDate:[NSDate date]];
    
        return currentTime;
        
    }
    
    To call this method within the same class:
    NSString *time = [self getCurrentTime];
    NSLog(@"%@",time);
    //Results in the getCurrentTime function being called and the current time printed to the console.
    
    
    => Swift 
    In Swift, we include the return arrow “->” which specifies that the function will return and the type of object that will be returned (String).
        func getCurrentTime() -> String {
            
            let date = NSDate()
            let formatter = NSDateFormatter()
            formatter.timeStyle = .ShortStyle
            var stringValue = formatter.stringFromDate(date)
            
            return stringValue
            
        }
        
    To call this method within the same class:
    let time = getCurrentTime()
    println(time)
    //Results in the getCurrentTime function being called and the current time printed to the console.

    public by marksimon232  3010  0  6  1

    Swift Collections: Simple function with parameter

    I want to pass a name (String) to a function and then print it out to the console.
    => Objective-C:
    -(void)outputName:(NSString *)nameString {
    
       NSLog(@"My name is %@",nameString);
    
    }
    
    To call this method within the same class:
    [self outputName:@"Mark"];
    //Results in the outputName function being called and "My name is Mark" printed to the console.
    
    
    => Swift:
    In Swift, we define the input value first (in our case, the string value), followed by the Type (String).
    func outputName(nameString:String){
    
        println("My name is: \(nameString)")
    
    }
    To call this method within the same class:
    outputName(@"Mark")
    //Results in the outputName function being called and "My name is Mark" printed to the console.

    public by fadzly  2499  0  6  0

    Magento PHTML Ajax with parameter

    function generatereport()
    		{
    			var AjaxURL = "<?php echo $this->getURL('inventorycostadmin/adminhtml_report/generateestgrprofitcogs');?>";
    			AjaxURL = AjaxURL + (AjaxURL.match(new RegExp('\\?')) ? '&isAjax=true' : '?isAjax=true');
    			
    			new Ajax.Request(AjaxURL, {
    				parameters: {querystr: "<?php echo $newQuery; ?>"},
    				onSuccess: function(valueinfo) {
    					if (valueinfo.responseText.isJSON()) {
    						var response = valueinfo.responseText.evalJSON();
    						if (response.error) {
    							alert(response.message);
    						} else {
    							$('reportdiv').update('<b>Total Gross Profit for filtered period : </b>'+response.formattedgrossprofit+'<br><b>Total Cost of Goods Sold for filtered period : </b>'+response.formattedcostofgoodssold+'<br><b>Total Sales  for filtered period : </b>'+response.formattedgoodssoldprice);
    						}
    					}
    				}
    			});
    		}
    • Public Snippets
    • Channels Snippets