working on it ...

Filters

Explore Public Snippets

Sort by

Found 6,853 snippets matching: extension

    public by zonaro modified Nov 13, 2015  322994  2  7  0

    Crop Image on C#

    Simple snippet to Crop Image from up-left point
    public static Bitmap CropImage(this Bitmap source, Rectangle section)
           {
               Bitmap bmp = new Bitmap(section.Width, section.Height);
               Graphics g = Graphics.FromImage(bmp); 
               g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel); 
               return bmp;
           }
    

    public by pan modified Jan 17, 2015  312424  0  7  4

    CSS Regex Selector Extension For jQuery

    Using this extension enables regular expresions css selectors in jQuery
    /**
     * CSS Regex Selector Extension For jQuery
     * 
     */
    jQuery.expr[':'].regex = function(elem, index, match) {
       var matchParams = match[3].split(','),
           validLabels = /^(data|css):/,
           attr = {
               method: matchParams[0].match(validLabels) ?
                   matchParams[0].split(':')[0] : 'attr',
               property: matchParams.shift().replace(validLabels,'')
           },
           regexFlags = 'ig',
           regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
       return regex.test(jQuery(elem)[attr.method](attr.property));
    }

    public by zonaro modified Oct 23, 2015  205184  1  7  0

    Image toBase64 String

    Extension method to convert a System.Drawing.Image to Base64 String
    public static string toBase64(this System.Drawing.Image OriginalImage)
          {
              using (MemoryStream ms = new MemoryStream())
              {
                  OriginalImage.Save(ms, OriginalImage.RawFormat);
                  byte[] imageBytes = ms.ToArray();
                  return Convert.ToBase64String(imageBytes);
              }
          }
    

    public by cghersi modified Jan 31, 2014  3986  1  6  0

    C#: Convert Extensions to MIME types

    This is a large set of extensions that can be converted in vlid MIME Types
    public static string ConvertExtensionToMimeType(string extension)
    {
        string ext = extension.ToLower().Trim(new char[] { ' ', '.' });
        switch (ext)
        {
            case "ai": return "application/postscript";
            case "aif": return "audio/x-aiff";
            case "aifc": return "audio/x-aiff";
            case "aiff": return "audio/x-aiff";
            case "asc": return "text/plain";
            case "asf": return "video/x-ms-asf";
            case "au": return "audio/basic";
            case "avi": return "video/x-msvideo";
            case "bcpio": return "application/x-bcpio";
            case "bin": return "application/octet-stream";
            case "c": return "text/plain";
            case "cc": return "text/plain";
            case "ccad": return "application/clariscad";
            case "cdf": return "application/x-netcdf";
            case "class": return "application/octet-stream";
            case "cpio": return "application/x-cpio";
            case "cpp": return "text/plain";
            case "cpt": return "application/mac-compactpro";
            case "cs": return "text/plain";
            case "csh": return "application/x-csh";
            case "css": return "text/css";
            case "dcr": return "application/x-director";
            case "dir": return "application/x-director";
            case "dms": return "application/octet-stream";
            case "doc": return "application/msword";
            case "drw": return "application/drafting";
            case "dvi": return "application/x-dvi";
            case "dwg": return "application/acad";
            case "dxf": return "application/dxf";
            case "dxr": return "application/x-director";
            case "eps": return "application/postscript";
            case "etx": return "text/x-setext";
            case "exe": return "application/octet-stream";
            case "ez": return "application/andrew-inset";
            case "f": return "text/plain";
            case "f90": return "text/plain";
            case "fli": return "video/x-fli";
            case "flv": return "video/x-flv";
            case "gif": return "image/gif";
            case "gtar": return "application/x-gtar";
            case "gz": return "application/x-gzip";
            case "h": return "text/plain";
            case "hdf": return "application/x-hdf";
            case "hh": return "text/plain";
            case "hqx": return "application/mac-binhex40";
            case "htm": return "text/html";
            case "html": return "text/html";
            case "ice": return "x-conference/x-cooltalk";
            case "ief": return "image/ief";
            case "iges": return "model/iges";
            case "igs": return "model/iges";
            case "ips": return "application/x-ipscript";
            case "ipx": return "application/x-ipix";
            case "jpe": return "image/jpeg";
            case "jpeg": return "image/jpeg";
            case "jpg": return "image/jpeg";
            case "js": return "application/x-javascript";
            case "kar": return "audio/midi";
            case "latex": return "application/x-latex";
            case "lha": return "application/octet-stream";
            case "lsp": return "application/x-lisp";
            case "lzh": return "application/octet-stream";
            case "m": return "text/plain";
            case "man": return "application/x-troff-man";
            case "me": return "application/x-troff-me";
            case "mesh": return "model/mesh";
            case "mid": return "audio/midi";
            case "midi": return "audio/midi";
            case "mime": return "www/mime";
            case "mov": return "video/quicktime";
            case "movie": return "video/x-sgi-movie";
            case "mp2": return "audio/mpeg";
            case "mp3": return "audio/mpeg";
            case "mpe": return "video/mpeg";
            case "mpeg": return "video/mpeg";
            case "mpg": return "video/mpeg";
            case "mpga": return "audio/mpeg";
            case "ms": return "application/x-troff-ms";
            case "msh": return "model/mesh";
            case "nc": return "application/x-netcdf";
            case "oda": return "application/oda";
            case "pbm": return "image/x-portable-bitmap";
            case "pdb": return "chemical/x-pdb";
            case "pdf": return "application/pdf";
            case "pgm": return "image/x-portable-graymap";
            case "pgn": return "application/x-chess-pgn";
            case "png": return "image/png";
            case "pnm": return "image/x-portable-anymap";
            case "pot": return "application/mspowerpoint";
            case "ppm": return "image/x-portable-pixmap";
            case "pps": return "application/mspowerpoint";
            case "ppt": return "application/mspowerpoint";
            case "ppz": return "application/mspowerpoint";
            case "pre": return "application/x-freelance";
            case "prt": return "application/pro_eng";
            case "ps": return "application/postscript";
            case "qt": return "video/quicktime";
            case "ra": return "audio/x-realaudio";
            case "ram": return "audio/x-pn-realaudio";
            case "ras": return "image/cmu-raster";
            case "rgb": return "image/x-rgb";
            case "rm": return "audio/x-pn-realaudio";
            case "roff": return "application/x-troff";
            case "rpm": return "audio/x-pn-realaudio-plugin";
            case "rtf": return "text/rtf";
            case "rtx": return "text/richtext";
            case "scm": return "application/x-lotusscreencam";
            case "set": return "application/set";
            case "sgm": return "text/sgml";
            case "sgml": return "text/sgml";
            case "sh": return "application/x-sh";
            case "shar": return "application/x-shar";
            case "silo": return "model/mesh";
            case "sit": return "application/x-stuffit";
            case "skd": return "application/x-koan";
            case "skm": return "application/x-koan";
            case "skp": return "application/x-koan";
            case "skt": return "application/x-koan";
            case "smi": return "application/smil";
            case "smil": return "application/smil";
            case "snd": return "audio/basic";
            case "sol": return "application/solids";
            case "spl": return "application/x-futuresplash";
            case "src": return "application/x-wais-source";
            case "step": return "application/STEP";
            case "stl": return "application/SLA";
            case "stp": return "application/STEP";
            case "sv4cpio": return "application/x-sv4cpio";
            case "sv4crc": return "application/x-sv4crc";
            case "swf": return "application/x-shockwave-flash";
            case "t": return "application/x-troff";
            case "tar": return "application/x-tar";
            case "tcl": return "application/x-tcl";
            case "tex": return "application/x-tex";
            case "tif": return "image/tiff";
            case "tiff": return "image/tiff";
            case "tr": return "application/x-troff";
            case "tsi": return "audio/TSP-audio";
            case "tsp": return "application/dsptype";
            case "tsv": return "text/tab-separated-values";
            case "txt": return "text/plain";
            case "unv": return "application/i-deas";
            case "ustar": return "application/x-ustar";
            case "vcd": return "application/x-cdlink";
            case "vda": return "application/vda";
            case "vrml": return "model/vrml";
            case "wav": return "audio/x-wav";
            case "wm": return "video/x-ms-wm";
            case "wma": return "audio/x-ms-wma";
            case "wmv": return "video/x-ms-wmv";
            case "wrl": return "model/vrml";
            case "xbm": return "image/x-xbitmap";
            case "xlc": return "application/vnd.ms-excel";
            case "xll": return "application/vnd.ms-excel";
            case "xlm": return "application/vnd.ms-excel";
            case "xls": return "application/vnd.ms-excel";
            case "xlw": return "application/vnd.ms-excel";
            case "xml": return "text/xml";
            case "xpm": return "image/x-xpixmap";
            case "xwd": return "image/x-xwindowdump";
            case "xyz": return "chemical/x-pdb";
            case "zip": return "application/zip";
            case "docm": return "application/vnd.ms-word.document.macroEnabled.12";
            case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            case "dotm": return "application/vnd.ms-word.template.macroEnabled.12";
            case "dotx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
            case "potm": return "application/vnd.ms-powerpoint.template.macroEnabled.12";
            case "potx": return "application/vnd.openxmlformats-officedocument.presentationml.template";
            case "ppam": return "application/vnd.ms-powerpoint.addin.macroEnabled.12";
            case "ppsm": return "application/vnd.ms-powerpoint.slideshow.macroEnabled.12";
            case "ppsx": return "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
            case "pptm": return "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
            case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
            case "xlam": return "application/vnd.ms-excel.addin.macroEnabled.12";
            case "xlsb": return "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
            case "xlsm": return "application/vnd.ms-excel.sheet.macroEnabled.12";
            case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            case "xltm": return "application/vnd.ms-excel.template.macroEnabled.12";
            case "xltx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
            default: return "text/plain";
        }
    }
    

    public by zonaro modified Oct 28, 2015  2004  1  6  0

    Toggle Method for Integer and Boolean Types (Extension Method)

    Allow you to use Variable.Toggle() to invert the current value of a Boolean Variable. Also works with Integer type too!
    Public Module Toggles
         
        <Extension()>
        Public Sub Toggle(ByRef Bool As Boolean)
            Bool = Not Bool
        End Sub
        
        <Extension()>
        Public Sub Toggle(ByRef Int As Integer)
            If Int > 0 Then
                Int = 0
            Else
                Int = 1
            End If
        End Sub 
    End Module

    public by paulsimmons modified May 10, 2017  392  1  4  0

    Magento Facebook Login Extension by FMEAddons

    Magento Facebook login extension by FMEAddons allows the customers to connect on your website by using their Facebook profile. This addon enables 4 social login buttons on registration page which are Facebook, Twitter, Yahoo, and Gmail. Customers can select any of these social accounts to get the login to your website. Customers can now place the o
    // Enter here the actual content of the snippet.            

    public by Timothy Cyrus modified Sep 7, 2015  66820  0  3  0

    Example of how to have Google Chrome extensions auto update to Github releases

    Example of how to have Google Chrome extensions auto update to Github releases: updates.xml
    <?xml version='1.0' encoding='UTF-8'?>
    <gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
      <app appid='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'>
        <updatecheck codebase='https://github.com/tcyrus/sample-chrome-extension/releases/download/v2.0/sce.crx' version='2.0' />
      </app>
    </gupdate>
    
    

    public by sTiLL-iLL @ SniPitz-KND modified Dec 1, 2015  4468  2  7  16

    kwik dirty arraySort....

    kwik example of a complex array sort
    // sort a complex array
    
    var mehAry = [{id: 140, name: "abc", age: "twenty"},
                  {id: 62009, name: "def", age: "thirty"},
                  {id: 3030, name: "ghi", age: "forty" },
                  {id: 455, name: "jkl", age: "fifty" }];
          
    function complexSort (itm1, itm2) {
        var a = itm1.id, b = itm2.id;
        return (a - b);
    }
    
    var sortedArray = mehAry.sort(complexSort);  
    
    //  sortedArray = [{id: 140, name: "abc", age: "twenty"},{id: 455, name: "jkl", age: "fifty" },
    //                 {id: 62009, name: "def", age: "thirty"},{id: 3030, name: "ghi", age: "forty" }];                        

    public by sTiLL-iLL @ SniPitz-KND modified Nov 10, 2014  2560  2  8  25

    ...... SkRoLLa.js sOOooOOOoo SmOooOOOootH...

    JuSt Give A liNk the ID: 'arrow", call Skrolla.start() some where after the document.ready and there ya have, animated-one-click, scroll to the top control for your page. oh YeaH!
    	// Skrolla! NoW yeR a RoLLA!
    
    var Skrolla = (function (wdw, $) {  
        function scrolld () {
            if ($(this).scrollTop() > 100) {
                $('#arrow').fadeIn();
            }
            else {
                $('#arrow').fadeOut();
            }
        }  
        function doScroll () {
            $("body,html").animate({
                scrollTop: 0
             }, 1200);
            return false;
        }
        var startMe = function () {
            $(wdw).scroll(scrolld());
            $("#arrow a").click(doScroll());
        };
    	return {
    		start: startMe
    	};
    }(window, jquery));
    

    public by sTiLL-iLL @ SniPitz-KND modified Aug 28, 2014  2126  3  7  15

    extend, toggleClass, equals, inArray.... functional javascript prototypes

    // functional additions to the Object prototype
     
    Object.prototype.extend = function() {
      if (arguments.length === 0)
        return this;
     
      for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
          if (arguments[i].hasOwnProperty(property))
            this[property] = arguments[i][property];
        }
      }
      return this;
    };
     
     
    Object.prototype.equals = function(x) {
      var p;
      for(p in this) {
        if (typeof(x[p]) == "undefined")
          return false;
      }
      
      for(p in this) {
        if (this[p]) {
          switch(typeof(this[p])) {
            case "object":
              if (!this[p].equals(x[p])) {
                return false;
              }
              break;
            case "function":
              if (typeof(x[p]) == "undefined" ||(p != "equals" && this[p].toString() != x[p].toString())) {
                return false;
              }
              break;
            default:
              if (this[p] != x[p]) {
                return false;
              }
          }
        }
        else {
          if (x[p]) {
            return false;
          }
        }
      }
      
      for(p in x) {
        if(typeof(this[p])=="undefined") {
          return false;
        }
      }
      
      return true;
    };
     
     
    Array.prototype.inArray = function (value) {
      for (var i = 0; i < this.length; i++) {
        if (typeof value === "object") {
        
          // If both are objects, uses the equals function
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }
        }
        else if (this[i] === value) {
          return i;
        }
      }
      
      return false;
    };
     
     
    function toggleClass(id, className) {
      var element = document.getElementById(id);
      var classes = element.className.split(/s+/);
      var length = classes.length;
      var found = classes.inArray(className);
      
      if (found !== false) {
        classes.splice(found, 1);
      }
        
      // The className is not found
      if (length === classes.length) {
        classes.push(className);
      }
        
      element.className = classes.join(" ");
    };
    • Public Snippets
    • Channels Snippets