working on it ...


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>
            <title>My Webpage</title>
            <ul id="navigation">
            {% for item in navigation %}
                <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
            {% endfor %}
            <h1>My Webpage</h1>
            {{ a_variable }}

    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)
    	if (e1 != null)

    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', 
                      HelpUri = '',
            # Param1 help description
                       ParameterSetName='Parameter Set 1')]
            [HelpMessage('help description')]
            [ValidateSet("sun", "moon", "earth")]
            # Param2 help description
            [Parameter(ParameterSetName='Parameter Set 1')]
            # Param3 help description
            [Parameter(ParameterSetName='Another Parameter Set')]
        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.
    @protocol SampleProtocol <NSObject>
    - (void)someMethod;
    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:
    {% comment %}
      code snippet author:
    {% 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