working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,415 snippets matching: syntax

    public by bkozora  34862  0  3  0

    Twig Syntax Example

    Twig Syntax Example: twig.html
    <!DOCTYPE html>
    <html>
        <head>
            <title>My Webpage</title>
        </head>
        <body>
            <ul id="navigation">
            {% for item in navigation %}
                <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
            {% endfor %}
            </ul>
    
            <h1>My Webpage</h1>
            {{ a_variable }}
        </body>
    </html>
    
    

    public by cghersi  3774  0  7  0

    Create a <a> tag in MVC with Razor syntax

    This is how to embed in a cshtml file the code to display a link that result in an HTML like: &lt;a href="/Public/Home"&gt;Go To Home Page&lt;/a&gt;
    @Html.ActionLink("Go To Home Page", "Home", "Public") 

    public by cghersi  3310  1  8  1

    LINQ: How to retrieve an IEnumerable collection with simple query

    This is a simple query in Linq to retrieve the list of Users that have some specified condition (in this case Active == true). Please note the == operator in the where clause (and in general all C# operators apply). Linq is excellent in writing fast and effective in-memory query on lists, dictionaries, etc.
    ICollection<User> users = new List<User>();
    users.Add(new User("Tom"));
    users.Add(new User("Mark"));
    
    IEnumerable<User> result = (
    	from user in users 
    	where user.Active == true 
    	select user); 

    public by cghersi @ Thotpot alumni  3066  2  5  0

    New try-catch block syntax

    Starting from java 7, try catch blocks can be written in a more strict way...
    try {
    	//my instructions here...
    } catch(RuntimeException e, Exception e1) {
    	System.err.println("Generic exception");
    	if (e != null)
    		e.printStrackTrace();
    	if (e1 != null)
    		e1.printStrackTrace();
    }

    public by virgilwashere  3778  6  6  0

    Powershell advanced function syntax

    Powershell advanced function syntax with most parameters added
    <# Insert Comment-based Help template snippet here 
    #>
    function Verb-Noun
    {
        [CmdletBinding(DefaultParameterSetName='Parameter Set 1', 
                      SupportsShouldProcess=$true, 
                      PositionalBinding=$false,
                      HelpUri = 'http://www.microsoft.com/',
                      ConfirmImpact='Medium')]
        [OutputType([String])]
        Param
        (
            # Param1 help description
            [Parameter(Mandatory=$true, 
                       ValueFromPipeline=$true,
                       ValueFromPipelineByPropertyName=$true, 
                       ValueFromRemainingArguments=$false, 
                       Position=0,
                       ParameterSetName='Parameter Set 1')]
            [HelpMessage('help description')]
    		[ValidateNotNull()]
            [ValidateNotNullOrEmpty()]
            [ValidateCount(0,5)]
            [ValidateSet("sun", "moon", "earth")]
            [Alias("p1")] 
            $Param1,
    
            # Param2 help description
            [Parameter(ParameterSetName='Parameter Set 1')]
            [AllowNull()]
            [AllowEmptyCollection()]
            [AllowEmptyString()]
            [ValidateScript({$true})]
            [ValidateRange(0,5)]
            [int]
            $Param2,
    
            # Param3 help description
            [Parameter(ParameterSetName='Another Parameter Set')]
            [ValidatePattern("[a-z]*")]
            [ValidateLength(0,15)]
            [String]
            $Param3
        )
    
        Begin {
        }
    	
        Process {
            if ($pscmdlet.ShouldProcess("Target", "Operation"))
            {
            }
        }
        
    	End {
        }
    }
    

    public by marksimon232  2967  0  6  1

    Swift Collections: Declaring a protocol

    In Objective-C, protocols are declared with the “@protocol” keyword. Below is an example of declaring a protocol containing one required method.
    Objective-C:
    @protocol SampleProtocol <NSObject>
    - (void)someMethod;
    @end
    
    -----------------
    
    Swift:
    In Swift, the syntax is a little different but the idea is the same.
    
    protocol SampleProtocol 
    {
        func someMethod()
    }

    public by marcospinello  2797  0  3  0

    Programmatically handle relative links in Jekyll using Liquid templating syntax

    Programmatically handle relative links in Jekyll using Liquid templating syntax: jekyll_links_liquid_syntax.md
    ```markdown
    {% comment %}
      source: http://stackoverflow.com/questions/4629675/jekyll-markdown-internal-links
      code snippet author: http://stackoverflow.com/users/399105/bmaupin
    {% endcomment %}
    
    {% for page in site.pages %}
      {% if page.url == '/path/to/page.html' %}
        [{{ page.title }}]({{ page.url }})
      {% endif %}
    {% endfor %}
    ```
    
    

    public by BrentHoover  1593  0  4  0

    For some reason I can never remember this syntax

    For some reason I can never remember this syntax: domready.js
    $(document).ready(function() {
      // Handler for .ready() called.
    });
    
    

    public by micurs  3842  2  7  3

    Generate comma separated value string in Typescript using underscore _.reduce()

    Underscore work well with Typescript lambda syntax.
    import _ = require("underscore");
    
    var values: number[] = [ 5, 19, 64, 12, 45 ];
    
    var csv: string = 
     _.reduce( values, 
              ( acc: string, item ) => acc+= ','+item.toString() 
             );
         

    public by lbottaro  4271  1  6  2

    A simple IIFE and closure example in Javascript

    This snippet shows the beauty of Immediately Invoked Function Expression (IIFE) and closures in Javascript. Here we create a function and immediately invoke it. This is also known as 'self executing function'. With the syntax var car = (function(){...})(); we define the function and execute it at the same time. Closure instead allows develop
    var car=(function(){
    	var _name='Ferrari GTO'; 
    	return {
    		getName: function(){
    			return _name;
    		}
    	}
    })(); //function created and invoked
    
    console.log(car.getName()); //Ferrari GTO
    • Public Snippets
    • Channels Snippets