IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » TomL's snipts The latest snipts from TomL.

showing 1-6 of 6 snipts
  • Re-check pass form
    class PasswordCheckForm(forms.Form):
        password = forms.CharField(widget=forms.PasswordInput)
        
        def __init__(self, user, *args, **kwargs):
            self.user = user
            super(PasswordCheckForm, self).__init__(*args, **kwargs)
        
        def clean(self):
            password = self.cleaned_data.get('password')
            if self.user.check_password(password):
                raise forms.ValidationError(_('Password is incorrect.'))
            
            return self.cleaned_data
    
    def recheck_pass(request, template_name='registration/recheck_pass.html',
                     redirect_field_name=REDIRECT_FIELD_NAME,
                     authentication_form=PasswordCheckForm):
        
        redirect_to = request.REQUEST.get(redirect_field_name, '')
        
        if request.method == 'POST':
            form = authentication_form(request.user, request.POST)
            
            if form.is_valid():
                if not redirect_to or ' ' in redirect_to:
                    redirect_to = settings.LOGIN_REDIRECT_URL
                if '//' in redirect_to and re.match(r'[^\?]*//', redirect_to):
                    redirect_to = settings.LOGIN_REDIRECT_URL
        else:
            form = authentication_form(request.user)
            
        return render_to_response(template_name, {
            'form': form,
        }, RequestContext(request))
    

    copy | embed

    0 comments - tagged in  posted by TomL on Aug 25, 2010 at 10:51 a.m. EDT
  • Randomise selected elements
    $(document).ready(function() {
        $("#choices").randomize("p");
    });
    
    // I think i'm in love with stackoverflow
    // Thanks to Russ Cam for this snippet to randomise selected elements
    // http://stackoverflow.com/questions/1533910/randomize-a-sequence-of-div-elements-with-jquery
    (function($) {
    $.fn.randomize = function(childElem) {
      return this.each(function() {
          var $this = $(this);
          var elems = $this.children(childElem);
    
          elems.sort(function() { return (Math.round(Math.random())-0.5); });  
    
          $this.remove(childElem);  
    
          for(var i=0; i < elems.length; i++)
            $this.append(elems[i]);      
    
      });    
    }
    })(jQuery);
    

    copy | embed

    0 comments - tagged in  posted by TomL on Jul 02, 2010 at 9:30 a.m. EDT
  • Get a list of links from html doc
    def get_links(text):
        try:
            from BeautifulSoup import BeautifulSoup
        except ImportError:
            from beautifulsoup import BeautifulSoup
        
        soup = BeautifulSoup(text)
        
        link_list = []
        for link in soup.findAll('a'):
            link_list.append(link['href'])
            
        return link_list
    

    copy | embed

    0 comments - tagged in  posted by TomL on Mar 19, 2010 at 5:41 p.m. EDT
  • Paste to paste2.org
    """
    Posts a file to paste2.org. Can post multiple files at once.
    
    paste2.py [options] [files]
      -h, --help     : Print this help
      -l, --lang     : Specify the language for the paste
      -p, --parent   : Sprecify parent paste
      
    """
    
    import urllib
    import urllib2
    import sys
    import getopt
    
    DEFAULT_LANG = 'python'
    PASTE2_URL = 'http://paste2.org/new-paste'
    
    def post_to_paste2(code, lang=DEFAULT_LANG, parent=0):
        """
        Post to paste2, return url of new paste
        """
        url = PASTE2_URL
        values = {
            'lang': lang,
            'description': '',
            'code': code,
            'parent': 0,
        }
        
        data = urllib.urlencode(values)
        req = urllib2.Request(url, data)
        paste_url = urllib2.urlopen(req).geturl()
        
        return paste_url
    
    def usage():
        print "paste2.py [options] [files]"
        print "  -h, --help     : Print this help"
        print "  -l, --lang     : Specify the language for the paste"
        print "  -p, --parent   : Sprecify parent paste"
    
    def main():
        try:
            opts, args = getopt.gnu_getopt(sys.argv[1:], "hl:p:v", ["help", "lang=", "parent="])
        except getopt.GetoptError, err:
            # print help information and exit:
            print str(err) # will print something like "option -a not recognized"
            usage()
            sys.exit(2)
        lang = DEFAULT_LANG
        parent = None
        for o, a in opts:
            if o in ("-l", "--lang"):
                language = a
            elif o in ("-p", "--parent"):
                parent = a
            elif o in ("-h", "--help"):
                usage()
                sys.exit()
            else:
                assert False, "unhandled option"
        
        #loop through all files passed
        for file_name in args:
            file = open(file_name, 'r')
            paste_url = post_to_paste2(file.read(), lang=lang, parent=parent)
            print "%s -> %s" % (file_name, paste_url)
            
    if __name__ == "__main__":
        main()
    

    copy | embed

    0 comments - tagged in  posted by TomL on Jan 24, 2010 at 3:58 p.m. EST
  • Revoke all mysql priveleges
    REVOKE ALL PRIVILEGES, GRANT OPTION ON *.* FROM jimmy@localhost;
    REVOKE ALL PRIVILEGES, GRANT OPTION ON *.* FROM jimmy@localhost.localdomain;
    FLUSH PRIVILEGES;
    

    copy | embed

    0 comments - tagged in  posted by TomL on Nov 30, 2009 at 4:10 p.m. EST
  • Validate email address (based on example from django source)
    import re
    
    if re.match(r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*"r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-011\013\014\016-\177])*"'r')@(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?$', email_address, re.IGNORECASE):
    	print "valid email"
    else:
    	print "invalid email"
    

    copy | embed

    0 comments - tagged in  posted by TomL on Nov 09, 2009 at 2:23 p.m. EST
Sign up to create your own snipts, or login.