working on it ...

Filters

Explore Public Snippets

Sort by

Found 29k snippets matching: best

    public by clsw  350052  0  6  1

    Image upload to API, return direct link. (IMGUR)

    Imgur, one of the best image hosts in the world, has a fantastic API, this is a VERY simple and usable implementation of it, just pass an image to the function and it will return the direct link to yout image, heavily commented and easy to use.
    public string UploadImage(Image img)
            {
                //get a dev key from api.imgur.com, anonymous usage (no user auth) only.
                string devkey = "YOUR_CLIENT_ID (e.g. abcde1f234567g8)";
    
                //define the WebClient we'll use to communicate with Imgur.
                WebClient w = new WebClient();
                
                //adds the Header to authorize this application with Imgur, must include a valid CLIENT_ID from 'devkey' above.
                w.Headers.Add("Authorization", "Client-ID " + devkey);
    
                System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
                try
                {
                    //Converts the image to a byte array so it can be turned into a string for upload.
                    using (MemoryStream stream = new MemoryStream())
                    {
                        img.Save(stream, ImageFormat.Png);
                        Keys.Add("image", Convert.ToBase64String(stream.ToArray()));
                    }
                    
                    //uploads the string-formatted-image and waits for the response.
                    byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);
                    dynamic result = Encoding.ASCII.GetString(responseArray);
    
                    //formats the (long and technical) result into just the direct image link.
                    Regex reg = new Regex("link\":\"(.*?)\""); Match match = reg.Match(result);
                    string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
    
                    //returns the online address of the image.
                    return url;
                }
                catch (Exception s) { MessageBox.Show(s.Message); return "err"; }
            }

    public by talaverars  168565  0  4  0

    the imagestock the best way to design

    the imagestock the best way to design : gistfile1.txt
    enter www.imagestock.com.mx
    
    

    public by sTiLL-iLL @ SniPitz-KND  2612  1  8  14

    ANonyMUs inLINe WERKuh C#

    ILYNe exeKutin oF wutteva INda BaKGRownD.. SwEET
    
    //run a worker like an anonymous function
    
    public class AnonWorker
    {
        private BackgroundWorker bw = new BackgroundWorker();
        private AnonWorker(){   }
     
        public static AnonWorker Create
        {
            get { return new AnonWorker(); }
        }
     
        public void Execute(DoWorkEventHandler begin, 
              RunWorkerCompletedEventHandler completed = null,
                     ProgressChangedEventHandler progress = null)
        {
            bw.DoWork += begin;
            (completed != null) ? addComplete() : noop();
            (progress != null) ? addProgress() : noop();
            bw.RunWorkerAsync();
        }
        
        private void noop()
        {  // nada...  }
        
        private void addComplete()
        {
          bw.RunWorkerCompleted += completed;
        }
        
        private void addProgress()
        {
          bw.ProgressChanged += progress;
        }
    }
    
    
    
          // Now.....  run it like this and its gonna be on a separate thread
    
      AnonWorker.Create.Execute((sender, data) => {
          // work here ....
      }, 
      (sender, data) => {
          // all done
      });
     
     
      
          // Old Skool.....
    
      AnonWorker.Create.Execute(delegate {
          // work
      },
      delegate {
          // done
      });                        

    public by pplant  2979  2  6  2

    Scale Image to fit dimensions

    This snippet of code allows you to scale a image proportional such that it fits the provided dimensions.
    public static ImageIcon getScaledImage(ImageIcon srcImg, int w, int h){
    		int imgWidth = srcImg.getIconWidth();
    		int imgHeight = srcImg.getIconHeight();
    		
    		//Find the right width
    		if(imgWidth > w){
    			float sWidth = imgWidth-w;
    			float sFactor = (sWidth/imgWidth);
    			imgWidth = w;
    			imgHeight = (int) (imgHeight-(imgHeight*sFactor));
    		}
    		
    		//Find the right hight 
    		if(imgHeight > h){
    			float sHeight = imgHeight-h;
    			float sFactor = sHeight/imgHeight;
    			imgHeight = h;
    			imgWidth = (int) (imgWidth-(imgWidth*sFactor));
    		}
    		
    		BufferedImage resizedImg = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
    		Graphics2D g2 = resizedImg.createGraphics();
    		g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    		g2.drawImage(srcImg.getImage(), 0, 0, imgWidth, imgHeight, null);
    		g2.dispose();
    		return new ImageIcon(resizedImg);
    	}

    public by CodeGuru  2051  0  4  3

    Best way to iterate Map or Properties in Java

    If you're only interested in the keys, you can iterate through the keySet() of the map:
    
        Map<String, Object> map = ...;
    
        for (String key : map.keySet()) {
            // ...
        }
    
        If you only need the values, use values():
    
        for (Object value : map.values()) {
            // ...
        }
    
        Finally, if you want both the key and value, use entrySet():
    
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            // ...
        }

    public by jewie1000  631  9  4  1

    Best Forty Aimbot/ESP Users | CB:RO Hackers

    DanielTCZ#0768
    ! Yu_riTCZ#2291
    fire#1443
    krump#8883
    x0hs#9452
    Frost#7467
    DaveTCZ#1966
    Arkey#9403
    Duke101#1210
    FallenGrim#8461
    GhOoOsT_T#4768
    ugunszelis#7328
    Milooue#6934
    tristris#3368
    floppib#2082
    mightybaseplate#0001
    Kroucher#7634
    remm#1160
    ItsFergLad#0761
    Wood#4408
    Paragon#7930
    Foamy#2227
    XexerTV(RipX)#4660
    ProToType#9739
    MaxNero#9511
    𝓀𝑒𝓋𝒾𝓂𝑒𝒽𝒢𝓂#7092
    Flaming#4421
    Lun4rSpy#3839
    Khayso#3875
    gnome#0962
    oRq_z#6991
    Corn#0505
    Cold#1621
    EU | βœͺ EzGamingTv12#8168
    StatTrakDoggo#7793
    Ziovixx#5012
    γƒ¬γ‚€γƒγ‚§γƒ«γƒ»γ‚¬γƒΌγƒ‰γƒŠ#0890
    DeclaredTruth#3896
    J0sh#4948
    ο½—ο½—ο½—#8902												

    public by iansheridan  260  0  3  0

    The best and greatest tmux.conf ever

    The best and greatest tmux.conf ever: tmux.conf
    # 0 is too far from ` ;)
    set -g base-index 1
    
    # Automatically set window title
    set-window-option -g automatic-rename on
    set-option -g set-titles on
    
    #set -g default-terminal screen-256color
    set -g status-keys vi
    set -g history-limit 10000
    
    setw -g mode-keys vi
    setw -g mode-mouse on
    setw -g monitor-activity on
    
    bind-key v split-window -h
    bind-key s split-window -v
    
    bind-key J resize-pane -D 5
    bind-key K resize-pane -U 5
    bind-key H resize-pane -L 5
    bind-key L resize-pane -R 5
    
    bind-key M-j resize-pane -D
    bind-key M-k resize-pane -U
    bind-key M-h resize-pane -L
    bind-key M-l resize-pane -R
    
    # Vim style pane selection
    bind h select-pane -L
    bind j select-pane -D 
    bind k select-pane -U
    bind l select-pane -R
    
    # Use Alt-vim keys without prefix key to switch panes
    bind -n M-h select-pane -L
    bind -n M-j select-pane -D 
    bind -n M-k select-pane -U
    bind -n M-l select-pane -R
    
    # Use Alt-arrow keys without prefix key to switch panes
    bind -n M-Left select-pane -L
    bind -n M-Right select-pane -R
    bind -n M-Up select-pane -U
    bind -n M-Down select-pane -D
    
    # Shift arrow to switch windows
    bind -n S-Left  previous-window
    bind -n S-Right next-window
    
    # No delay for escape key press
    set -sg escape-time 0
    
    # Reload tmux config
    bind r source-file ~/.tmux.conf
    
    # THEME
    set -g status-bg black
    set -g status-fg white
    set -g window-status-current-bg white
    set -g window-status-current-fg black
    set -g window-status-current-attr bold
    set -g status-interval 60
    set -g status-left-length 30
    set -g status-left '#[fg=green](#S) #(whoami)'
    set -g status-right '#[fg=yellow]#(cut -d " " -f 1-3 /proc/loadavg)#[default] #[fg=white]%H:%M#[default]'
    
    
    

    public by maholtz  1929  0  5  0

    Bestimmte Zeile im CSV finden

    Für Notepad++ - Zeilen mit bestimmten Inhalt in CSV Suchen bzw. Zeile löschen (Ersetzen durch nichts)
    // Für Notepad++
    // Regulärer Ausdruck um in einer CSV-Datei eine Zeile mit dem Wert 'abcd' zu finden
    // Spalte ist dabei egal, Zeilenende mit Windows-Umbruch \r\n
    
    // Reguläre Ausdrücke aktivieren und [x] findet \r und \n aktivieren
    ^[^\r]*'abcd';[^\r]*\r\n

    public by marksimon232  11150  82  6  3

    How to add Cookies and Headers in HTTP requests in Python

    Let's say I have an HTTP GET request and I want to decorate it with some Headers (e.g. "Accept" or "Authorization") and with some Cookies. What's the best way to do this in Python?
    => According to the api - http://docs.python-requests.org/en/latest/api/, the headers can all be passed in using requests.get:
    r=requests.get("http://www.example.com/", headers={"content-type":"text"});
    
    
    => Response Headers:
    We can view the server’s response headers using a Python dictionary:
    >>> r.headers
    {
        'status': '200 OK',
        'content-encoding': 'gzip',
        'transfer-encoding': 'chunked',
        'connection': 'close',
        'server': 'nginx/1.0.4',
        'x-runtime': '148ms',
        'etag': '"e1ca502697e5c9317743dc078f67693f"',
        'content-type': 'application/json; charset=utf-8'
    }
    
    
    => HTTP Headers are case-insensitive, so we can access the headers using any
    capitalization we want.
    >>> r.headers['Content-Type']
    'application/json; charset=utf-8'
    
    >>> r.headers.get('content-type')
    'application/json; charset=utf-8'
    
    # If a header doesn’t exist in the Response, its value defaults to None:
    >>> r.headers['X-Random']
    None
    
    
    => Cookies
    If a response contains some Cookies, you can get quick access to them:
    >>> url = 'http://http.org/cookies/set/requests-is/awesome'
    >>> r = requests.get(url)
    
    >>> r.cookies['requests-is']
    'awesome'
    # To send your own cookies to the server, you can use the cookies parameter:
    
    >>> url = 'http://http.org/cookies'
    >>> cookies = dict(cookies_are='working')
    
    >>> r = requests.get(url, cookies=cookies)
    
    >>> r.text
    '{"cookies": {"cookies_are": "working"}}'
    

    public by sTiLL-iLL @ SniPitz-KND  2923  1  7  16

    PromDuffuhrd.js wuhrkz gouuwd. eY PruMISe!

    best yet....
    
    (function (GlOb) {
        function isItArray(ary) {
            return (ary.prototype ===  Array);
        }
    
        function foreach(ary, cBak) {
            if (isItArray(ary)) {
                for (var i = 0; i < ary.length; i++) {
                    cBak(ary[i]);
                }
            }
            else {
                cBak(ary);
            }
        }
    
        function stoopiD(fn) {
            var status = 'pending', dunMemberz = [], failedMemberz = [],
                proggyMemberz = [], nArgz = null,
    		    promise = {
    		        done: function () {
    		          for (var i = 0; i < arguments.length; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i], j = 0,
                                ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'resolved') {
    		                        ary[j].apply(this, nArgz);
    		                    }
    		                    dunMemberz.push(ary[j]);
    		                }
    		            }
    		            else {
    		                if (status === 'resolved') {
    		                    arguments[i].apply(this, nArgz);
    		                }
    		                dunMemberz.push(arguments[i]);
    		            }
    		        }
    
    		        return this;
    		    },
    
    		    fail: function () {
    		        for (var i = 0; i < arguments.length; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i],
                                j = 0, ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'rejected') {
    		                        ary[j].apply(this, nArgz);
    		                    }
    
    		                    failedMemberz.push(ary[j]);
    		                }
    		            }
    		            else {
    		                if (status === 'rejected') {
    		                    arguments[i].apply(this, nArgz);
    		                }
    
    		                failedMemberz.push(arguments[i]);
    		            }
    		        }
    		        return this;
    		    },
    
    		    always: function () {
    		        return this.done.apply(this, arguments).fail.apply(this, arguments);
    		    },
    
    		    progress: function () {
    		        var i = 0, ln = ary.length;
    		        for (; i < ln; i++) {
    		            if (!arguments[i]) {
    		                continue;
    		            }
    
    		            if (isItArray(arguments[i])) {
    		                var ary = arguments[i],
                                j = 0, ln = ary.length;
    		                for (; j < ln; j++) {
    		                    if (status === 'pending') {
    		                        proggyMemberz.push(ary[j]);
    		                    }
    		                }
    		            }
    		            else {
    		                if (status === 'pending') {
    		                    proggyMemberz.push(arguments[i]);
    		                }
    		            }
    		        }
    
    		        return this;
    		    },
    
    		    then: function () {
    		        if (arguments.length > 1 && arguments[1]) {
    		            this.fail(arguments[1]);
    		        }
    		        if (arguments.length > 0 && arguments[0]) {
    		            this.done(arguments[0]);
    		        }
    		        if (arguments.length > 2 && arguments[2]) {
    		            this.progress(arguments[2]);
    		        }
    		    },
    
    		    promise: function (objkt) {
    		        if (objkt == null) {
    		            return promise;
    		        } else {
    		            for (var i in promise) {
    		                objkt[i] = promise[i];
    		            }
    		            return objkt;
    		        }
    		    },
    
    		    state: function () {
    		        return status;
    		    },
    
    		    isRejected: function () {
    		        return status === 'rejected';
    		    },
    
    		    isResolved: function () {
    		        return status === 'resolved';
    		    },
    
    		    pipe: function (done, fail, progress) {
    		        return stoopiD(function (def) {
    		            foreach(done, function (func) {
    		                if (typeof func === 'function') {
    		                    deferred.done(function () {
    		                        var returnval = func.apply(this, arguments);
    		                        if (returnval && typeof returnval === 'function') {
    		                            returnval.promise().then(def.resolve, def.reject, def.notify);
    		                        }
    		                        else {
    		                            def.resolve(returnval);
    		                        }
    		                    });
    		                }
    		                else {
    		                    deferred.done(def.resolve);
    		                }
    		            });
    
    		            foreach(fail, function (func) {
    		                if (typeof func === 'function') {
    		                    deferred.fail(function () {
    		                        var returnval = func.apply(this, arguments);
    
    		                        if (returnval && typeof returnval === 'function') {
    		                            returnval.promise().then(def.resolve, def.reject, def.notify);
    		                        } else {
    		                            def.reject(returnval);
    		                        }
    		                    });
    		                }
    		                else {
    		                    deferred.fail(def.reject);
    		                }
    		            });
    		        }).promise();
    		    }
    		},
    
    		deferred = {
    		    resolveWith: function (context) {
    		        if (status === 'pending') {
    		            status = 'resolved';
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < dunMemberz.length; i++) {
    		                dunMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    rejectWith: function (context) {
    		        if (status === 'pending') {
    		            status = 'rejected';
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < failedMemberz.length; i++) {
    		                failedMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    notifyWith: function (context) {
    		        if (status === 'pending') {
    		            var argz = (nArgz = (arguments.length > 1) ? arguments[1] : []);
    		            for (var i = 0; i < proggyMemberz.length; i++) {
    		                proggyMemberz[i].apply(context, argz);
    		            }
    		        }
    		        return this;
    		    },
    
    		    resolve: function () {
    		        return this.resolveWith(this, arguments);
    		    },
    
    		    reject: function () {
    		        return this.rejectWith(this, arguments);
    		    },
    
    		    notify: function () {
    		        return this.notifyWith(this, arguments);
    		    }
    		};
    
            var objkt = promise.promise(deferred);
    
            if (fn) {
                fn.call(objkt, objkt);
            }
    
            return objkt;
        }
    
        stoopiD.when = function () {
            if (arguments.length < 2) {
                var objkt = arguments.length ? arguments[0] : undefined;
                if (objkt && (typeof objkt.isResolved === 'function' && typeof objkt.isRejected === 'function')) {
                    return objkt.promise();
                }
                else {
                    return stoopiD().resolve(objkt).promise();
                }
            }
            else {
                return (function (argz) {
                    var dufurd = stoopiD(),
    					size = argz.length,
    					done = 0, fuk = new Array(size);
                    var i = 0, ln = ary.length;
                    for (; i < ln; i++) {
                        (function (j) {
                            var objkt = null;
                            if (argz[j].done) {
                                argz[j].done(function () {
                                    fuk[j] = (arguments.length < 2) ? arguments[0] : arguments;
                                    if (++done == size) {
                                        dufurd.resolve.apply(dufurd, fuk);
                                    }
                                })
                                .fail(function () {
                                    dufurd.reject(arguments);
                                });
                            } else {
                                objkt = argz[j];
                                argz[j] = new Deferred();
                                argz[j].done(function () {
                                    fuk[j] = (arguments.length < 2) ? arguments[0] : arguments;
                                    if (++done == size) {
                                        dufurd.resolve.apply(dufurd, fuk);
                                    }
                                })
                                .fail(function () {
                                    dufurd.reject(arguments);
                                }).resolve(objkt);
                            }
                        })(i);
                    }
                    return dufurd.promise();
                })(arguments);
            }
        };
        GlOb.Deferred = stoopiD;
    })(window);            
    • Public Snippets
    • Channels Snippets