working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,920 snippets matching: handler

    public by JMichaelTX  351585  2  3  0

    AppleScript Trim Function / Handler Using ASObjC (Shane Stanley)

    AppleScript Trim Function / Handler Using ASObjC (Shane Stanley): trimThis Function AS.applescript
    ###BEGIN~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    #    trimThis()      Trim (remove) Characters from Left and/or Right of String
    #
    #    Ver 1.1          2016-02-25
    #    AUTHOR:          Shane Stanley
    #                     (minor revisions by JMichaelTX)
    #    REF:             MacScripter / Trim [Remove Spaces]
    #                     http://macscripter.net/viewtopic.php?pid=182209#p182209
    #  PARAMETERS:
    #    • pstrCharToTrim    : A list of characters to trim, or true to use default
    #    • pstrSourceText    : The text to be trimmed
    #    • pstrTrimDirection : Direction of Trim left, right or any value for full
    ###——————————————————————————————————————————————————————————————————————————————————
    
    on trimThis(pstrSourceText, pstrCharToTrim, pstrTrimDirection)
      
      --- SET CHARACTERS TO TRIM ---
      
      if pstrCharToTrim = missing value or pstrCharToTrim = true then
        -- SPACE, TAB, RETURN, newline characters (U+000A–U+000D, U+0085)
        -- Equiv to: ASCII character 10, return, ASCII character 0
        
        set setToTrim to current application's NSCharacterSet's whitespaceAndNewlineCharacterSet()
      else
        set setToTrim to current application's NSCharacterSet's characterSetWithCharactersInString:pstrCharToTrim
      end if
      
      set anNSString to current application's NSString's stringWithString:pstrSourceText
      
      --- TRIM STRING BASED ON REQUESTED DIRECTION ---
      
      if pstrTrimDirection = left then -- FROM LEFT SIDE OF STRING
        
        set theRange to anNSString's rangeOfCharacterFromSet:(setToTrim's invertedSet())
        if |length| of theRange = 0 then return ""
        set anNSString to anNSString's substringFromIndex:(theRange's location)
        
      else if pstrTrimDirection = right then -- FROM RIGHT SIDE OF STRING
        set theRange to anNSString's rangeOfCharacterFromSet:(setToTrim's invertedSet()) options:(current application's NSBackwardsSearch)
        if |length| of theRange = 0 then return ""
        set anNSString to anNSString's substringToIndex:(theRange's location)
        
      else -- FROM BOTH SIDES OF STRING
        set anNSString to anNSString's stringByTrimmingCharactersInSet:setToTrim
      end if
      
      return anNSString as text
    end trimThis
    ###END~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    

    public by Kingsley Huynh  5564  29  5  0

    Golang HTTP Handler to Upload Image => Resize => Convert to JPEG => Save to Disk.

    Golang HTTP Handler to Upload Image = Resize = Convert to JPEG = Save to Disk. : gistfile1.go
    Go
    func UploadHandler(w http.ResponseWriter, r *http.Request) {
    
    	file, _, err := r.FormFile("file")
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
    		return
    	}
    
    	img, _, err := image.Decode(file)
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusUnsupportedMediaType), http.StatusUnsupportedMediaType)
    		return
    	}
    
    	m := resize.Resize(1000, 0, img, resize.Lanczos3)
    
    	out, err := os.Create("test_resized.jpg")
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
    		return
    	}
    	defer out.Close()
    
    	// Encode into jpeg http://blog.golang.org/go-image-package
    	err = jpeg.Encode(out, m, nil)
    	if err != nil {
    		log.Println(err)
    		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
    		return
    	}
    }
    
    

    public by qxshower  2339  1  5  0

    Event handler for ApplicationCommands.Paste command.

    Event handler for ApplicationCommands.Paste command: paste plain text from Clipboard to PlainRichTextBox
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    
    //------------------------------------------------------
    //
    //  Constructors
    //
    //------------------------------------------------------
    // Ctor.
    static PlainRichTextBox()
            {
                RegisterCommandHandlers();
            }
    
    /// <summary>
    /// Event handler for ApplicationCommands.Paste command.
    /// <remarks>
    /// We want to allow paste only in plain text format.
    /// </remarks>
    /// </summary>
    private static void OnPaste(object sender, ExecutedRoutedEventArgs e)
    {
        PlainRichTextBox PlainRichTextBox = (PlainRichTextBox)sender;
                
        // Handle paste only if clipboard supports text format.
        if (Clipboard.ContainsText())
        {
            PlainRichTextBox.Selection.Text = Clipboard.GetText();
        }
        e.Handled = true;
    }            

    public by JKCPR  2316  1  6  3

    vanilla JS event handler and DOM selection

    Firstly select element from DOM and assign to var. Secondly store anon function in var for executing later. Thirdly assign event handler to first var used in DOM selection and give it the value of the var storing the anon function. In short : identify item and name it, stipulate desired behaviour and lastly give the eventHandler the behaviour to pe
    //js Event Handler assigned to page Element
    
    var theThing = document.getElementById("monsterInQuestion");
    var growls = function(){
      console.log('Grrrrr');
    }
    theThing.onclick = growls;

    public by zer00ne  2681  4  5  0

    Single Event Handler for Multiple Elements

    addEventListener to an ancestor element of multiple descendant elements
    /*
    HTML should comprise of a group of elements intended 
    to be clicked or any other event trigged by user interaction.
    The parentSelector parameter is any working selector to
    reference an element that is an ancestor to that group of
    elements.
    EX.
    <section id="perentEle">
      <a href="#" id='link1'>Link 1</a>
      <a href="#" id='link2'>Link 2</a>
      <a href="#" id='link3'>Link 3</a>
    </section>
    */
    var parentEle = document.querySelector(parentSelector);
    
    parentEle.addEventListener('click', testFunc, false);
    
    function testFunc(event) {
      event.preventDefault();
      if(event.target !== target.currentTarget) {
        var clickedChild = event.target.id;
        var child = document.getElementById(clickedChild);
        alert('ID: ' + child.id);
      }
      event.stopPropagation();
    }

    public by qxshower  1827  2  5  0

    Event handler for ApplicationCommands.Cut Command.

    Event handler for ApplicationCommands.Cut command: cut plain text from RichTextBox to the clipboard
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Controls.Primitives;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    
    //------------------------------------------------------
    //
    //  Constructors
    //
    //------------------------------------------------------
    // Ctor.
    static PlainRichTextBox()
            {
                RegisterCommandHandlers();
            }
    
    /// <summary>
    /// Event handler for ApplicationCommands.Cut command.
    /// <remarks>
    /// We want to enforce that data can be set on the clipboard 
    /// only in plain text format from this RichTextBox.
    /// </remarks>
    /// </summary>
    private static void OnCut(object sender, ExecutedRoutedEventArgs e)
    {
        PlainRichTextBox PlainRichTextBox = (PlainRichTextBox)sender;
        string selectionText = PlainRichTextBox.Selection.Text;
        PlainRichTextBox.Selection.Text = String.Empty;
        Clipboard.SetText(selectionText);
        e.Handled = true;
    }            

    public by MatteoP  2829  1  6  0

    textbox for doubles

    //handler for the keyPress event on a textbox to only allow writing doubles
    private void tbDouble_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!char.IsControl(e.KeyChar)
                    && !char.IsDigit(e.KeyChar)
                    && e.KeyChar != '.')
                {
                    e.Handled = true;
                }
                // only allow one decimal point
                if (e.KeyChar == '.'
                    && (sender as TextBox).Text.IndexOf('.') > -1)
                {
                    e.Handled = true;
                }
            }

    public by LaurenceTamatea  2382  1  4  0

    Event Handler onClick

     <!DOCTYPE html>
    <html lang="en">
    
    	<head>
    		<title>STANDARD TEMPLATE</title>
    		<meta charset="utf-8">
    		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    		<style> </style>
    	</head>
    
    	<body>
    
    <div>Event Handlers</div>
    
    
    		<form>
    			<input type="button" value="click me" onClick="alert('Hacked!');"/>
    
    		</form>
    
    		<script>
    		//end the js statment with a semi-colon//
    		//double quotation markets for attributes and single for JS//
    		//don't need to put the script between the script tags.//
    
    
    		</script>
        </body>
    
        </html>                       

    public by sa.guarda  2621  0  5  0

    Android new Handler

    return new Handler() {
    	@Override
    	public void handleMessage(Message msg) {
    		switch (msg.what) {
    
    		}
    	}
    };

    public by bfranzoi  1464  0  5  0

    event handler click

    /*
    HTML should comprise of a group of elements intended 
    to be clicked or any other event trigged by user interaction.
    The parentSelector parameter is any working selector to
    reference an element that is an ancestor to that group of
    elements.
    EX.
    <section id="perentEle">
      <a href="#" id='link1'>Link 1</a>
      <a href="#" id='link2'>Link 2</a>
      <a href="#" id='link3'>Link 3</a>
    </section>
    */
    var parentEle = document.querySelector(parentSelector);
    
    parentEle.addEventListener('click', testFunc, false);
    
    function testFunc(event) {
      event.preventDefault();
      if(event.target !== target.currentTarget) {
        var clickedChild = event.target.id;
        var child = document.getElementById(clickedChild);
        alert('ID: ' + child.id);
      }
      event.stopPropagation();
    }
    • Public Snippets
    • Channels Snippets