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 » jrguitar21's snipts The latest snipts from jrguitar21.

showing 1-20 of 44 snipts
  • Htaccess Private Files (svn, cvs, sql, etc)
    # Drupal's way of denying access to delicate server files
    <FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
      Order allow,deny
    </FilesMatch>
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 27, 2010 at 1:48 p.m. EDT
  • free binaural beats
    # A little snippet to download a bunch of free binaural beats
    # to your hard drive.
    
    cd ~/Downloads && curl -O http://mayhem-chaos.net/stuff/xspf-download-0.1.0.py && chmod 755 xspf-download-0.1.0.py && ./xspf-download-0.1.0.py http://healingbeats.com/beats.xspf &
    
    # After the downloads finish, simply 
    #  1) open Finder
    #  2) Navigate to Downloads folder,
    #  3) Drag the folder 'beats' over the itunes icon in your Dock.
    #  4) delete the xspf-download-0.1.0.py file from Downloads folder.
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 11, 2010 at 6:46 p.m. EDT
  • svn ignore passwords
    # on production servers its often a good idea not to store svn passwords.
    # heres a one-liner to do just that:
    echo "store-passwords=no" >> ~/.subversion/servers && rm -f ~/.subversion/auth/svn.simple/*
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 11, 2010 at 6:14 p.m. EDT
  • drupal_get_machinename
    <?php
    /**
     * Most machine names are generated as-you-type via Javascript helpers on the
     * client side. This helper function automates server-side conversions from
     * regular text strings into valid Drupal machine names.
     *
     * Machine names must contain only lowercase alpha-numerics and underscores. 
     * Non-alphanumeric characters are converted to underscores, and sequential 
     * underscore characters are trimmed to a single character.
     * 
     * Additionally, if the transliteration module is enabled, then it will be 
     * used to first convert non-ascii Unicode characters to standard Roman ASCII
     * characters on a best-effort basis, and replacing all unknown characters
     * with underscores.
     *
     * @param $text 
     *   A string of characters to be converted.
     *
     * @return
     *   A string containing the valid Drupal machine name for the specified text.
     *   Returns the empty string if invalid input was provided.
     *
     * @see
     *   See the transliteration module in the drupal contrib repository for more 
     *   information on non-ascii character transliterations.
     */
    function drupal_get_machinename($text) {
      // Cache machine name conversions locally for performance boost.
      static $texts;
      
      // If the input string is not valid, return an empty string.
      if (empty($text) || !is_string($text)) {
        return '';
      }
    
      // Setup the local static variable cache if it doesnt exist.
      if (!is_array($texts)) {
        $texts = array();
      }
    
      // Save the machine name conversion to the static cache if it doesnt exist. 
      if (!isset($texts[$text])) {
        $out = $text;
        if (module_exists('transliteration')) {
          $out = transliteration_get($out, '_');
        }
        $out = strtolower($out);
        $out = preg_replace('/[^a-z0-9]/', '_', $out);
        $out = preg_replace('/_+/', '_', $out);
        $texts[$text] = $out;
      }
      return $texts[$text];
    }
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Aug 04, 2010 at 9:38 p.m. EDT
  • grep find
    # grep find excluding .svn directories
    # from http://wordaligned.org/articles/ignoring-svn-directories
    alias gf='find . -path "*/.svn" -prune -o -type f -print0 | xargs -0 grep -I -n'
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jun 15, 2010 at 9:07 p.m. EDT
  • find exclude .svn
    # exclude .svn folders with find
    find . -name "myfile*.*" \( -not -iname "*.svn*" \)
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jun 15, 2010 at 8:32 p.m. EDT
  • uncompress css stylesheet
    # quick one-liner to uncompress a stylesheet that has been 
    # compressed down to one line. This will add the newlines back.
    perl -pi -e "s/\}/\}\n/g" *.css
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 17, 2010 at 6:03 p.m. EDT
  • drupal files folder svn externals
    # go to working copy
    cd ~/public_html/sites/default/
    
    # take a backup
    tar zcvf files.tar.gz --exclude=.svn files
    
    # move drupal files folder out of trunk, and replace with externals, to keep trunk lightweight.
    svn mv http://svn/project/trunk/sites/default/files http://svn/project/assets/files -m "moved files folder out of trunk to assets"
    
    # delete files on working copy
    svn up
    
    # setup the external reference
    svn propset svn:externals 'files http://svn/project/assets/files' .
    
    # fetch external file
    svn up
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on May 04, 2010 at 6:50 p.m. EDT
  • prevent dot underscore mac os x tar
    # prevent tar from creating those blasted 
    # dot-underscore (aka ._) alias 'Apple Double'  files.
    # put this in your .bashrc file.
    
    export COPYFILE_DISABLE=true
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Apr 09, 2010 at 7:30 p.m. EDT
  • php clean folder listing
    <?php
    // a clean replacement for default apache file listing
    // this version only shows subfolders, not files
    $path = dirname(__FILE__);
    $folder = @opendir($path) or die("Unable to open $path");
    
    $host = $_SERVER['SERVER_NAME'];
    echo "<h2>Folder listing for $host</h2>";
    echo '<ul>';
    while ($file = readdir($folder)) {
      if ($file != '.' && $file != '..' && is_dir($path . $file)) {
        echo "<li><a href='$file'>$file</a></li>";
      }
    }
    echo '</ul>';
    closedir($folder);
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Apr 06, 2010 at 11:30 p.m. EDT
  • install Drush from CVS HEAD on any unix server
    ##
    ## Installs Drush (the Drupal Shell command line utility) from CVS HEAD 
    ## on any UNIX machine, such that all users that have /usr/local/bin in
    ## their $PATH can use Drush (granted they have access to a Drupal install).
    ##
    ##
    
    cd /usr/local/src
    cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d drush-HEAD contributions/modules/drush/
    curl -O http://download.pear.php.net/package/Console_Table-1.1.3.tgz
    tar zxvf Console_Table-1.1.3.tgz
    cp Console_Table-1.1.3/Table.php drush-HEAD/includes/table.inc
    ln -s /usr/local/src/drush-HEAD/drush /usr/local/bin/drush
    
    ##
    ## now any user that has /usr/local/bin in their $PATH can use Drush.
    ##
    ##
    ## ... later on, to keep drush up to date, run the following:
    
    #cd /usr/local/src/drush-HEAD
    #cvs update -dPA
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Mar 05, 2010 at 11:38 a.m. EST
  • create ssh RSA id
    # Create an SSH id and public key pair (RSA) on your laptop/local machine
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    ssh-keygen -q -f ~/.ssh/id_rsa -t rsa
    ## Enter passphrase (empty for no passphrase): …
    ## Enter same passphrase again: …
    
    # protect your SSH keys
    chmod go-w ~/
    chmod 700 ~/.ssh
    chmod go-rwx ~/.ssh/*
    
    # Send your public id to the server. 
    # @see http://snipt.net/jrguitar21/passwordless-rsa-ssh-1-liner/
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 29, 2010 at 10:26 a.m. EST
  • install svn on shared host
    #Install subversion on a shared host
    
    
    curl -O http://subversion.tigris.org/downloads/subversion-1.6.9.tar.gz
    curl -O http://subversion.tigris.org/downloads/subversion-deps-1.6.9.tar.gz
    curl -O http://www.openssl.org/source/openssl-0.9.8l.tar.gz
    
    tar zxvf openssl-0.9.8l.tar.gz
    tar zxvf subversion-1.6.9.tar.gz
    tar zxvf subversion-deps-1.6.9.tar.gz
    
    cd openssl-0.9.8l/
    ./config shared --prefix=$HOME/installs && make clean && make && make install
    cd ../
    
    export CFLAGS="-O2 -g -I$HOME/installs/include"
    export LDFLAGS="-L$HOME/installs/lib"
    export CPP="gcc -E -I$HOME/installs/include"
    
    cd subversion-1.6.9/neon/
    ./configure --with-ssl=openssl --prefix=$HOME/installs
    cd ../
    ./configure --with-ssl --prefix=$HOME/installs --with-neon=$HOME/installs/bin/neon-config
    make clean && make && make install
    
    echo 'store-plaintext-passwords=no' >> ~/.subversion/servers
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 28, 2010 at 8:01 p.m. EST
  • remove .svn folders
    find . -name ".svn" -type d -exec rm -rf {} \;
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 06, 2010 at 11:47 a.m. EST
  • detect linux distro
    #!/bin/sh
    # Detects which OS and if it is Linux then it will detect 
    # which Linux Distribution.
    
    OS=`uname -s`
    REV=`uname -r`
    MACH=`uname -m`
    
    GetVersionFromFile()
    {
    	VERSION=`cat $1 | tr "\n" ' ' | sed s/.*VERSION.*=\ // `
    }
    
    if [ "${OS}" = "SunOS" ] ; then
    	OS=Solaris
    	ARCH=`uname -p`	
    	OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
    elif [ "${OS}" = "AIX" ] ; then
    	OSSTR="${OS} `oslevel` (`oslevel -r`)"
    elif [ "${OS}" = "Linux" ] ; then
    	KERNEL=`uname -r`
    	if [ -f /etc/redhat-release ] ; then
    		DIST='RedHat'
    		PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
    		REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
    	elif [ -f /etc/SUSE-release ] ; then
    		DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
    		REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
    	elif [ -f /etc/mandrake-release ] ; then
    		DIST='Mandrake'
    		PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
    		REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
    	elif [ -f /etc/debian_version ] ; then
    		DIST="Debian `cat /etc/debian_version`"
    		REV=""
    
    	fi
    	if [ -f /etc/UnitedLinux-release ] ; then
    		DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
    	fi
    	
    	OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
    
    fi
    
    
    echo ${OSSTR}
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Jan 06, 2010 at 11:20 a.m. EST
  • outdated drupal module with svn
    ## In a nutshell, how to update a module from Drupal contrib, 
    ## on a production site that is under revision control (subversion).
    
    # If you turn on a module (that just happens to already be
    # present in the list on admin/build/modules), then you MUST
    # 1)  go to the update status page
    # 2)  find out if the module you just turned on is up to date
    # 3)  if it is,  fine (your done! stop here),  
    # 4)  if there are updates... then go to the drupal.org site first
    #     to see if there are any "gotchas" for the upgrade.  As you'll
    #     be turning the module on for the first time on a new site,
    #     then you shouldnt have to worry too much.
    # 5)  To run the updates: login via ssh
    
    ssh username@server.com
    
    # 6) go to the right folder and execute drush update
    
    cd domains/example.com/public_html/sites/all/modules
    drush --uri=example.com update modulename
    
    # 7) confirm that the update was successful on the site
    # 8) then check in the code
    
    svn commit -u username -m "updated modulename to the latest version"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 23, 2009 at 4:49 p.m. EST
  • apache configure htaccess defaults
    #
    # AccessFileName: The name of the file to look for in each directory
    # for additional configuration directives.  See also the AllowOverride
    # directive.
    #
    AccessFileName .htaccess
    
    #
    # The following lines prevent .htaccess and .htpasswd files from being 
    # viewed by Web clients. 
    #
    <Files ~ "^\.ht">
        Order allow,deny
        Deny from all
    </Files>
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 15, 2009 at 7:59 a.m. EST
  • protect svn/cvs in apache conf
    # Protect revision controlled web projects. This version is 
    # for Apache's global configuration (conf) file. Protection
    # can also be done if you dont have access to Apache conf, 
    # in any directorie's .htaccess file, in which case,  Apache 
    # conf must aleady be configured to use htaccess.
    <DirectoryMatch "^/.*/(\.svn|CVS)/">
      Order deny,allow
      Deny from all 
    </DirectoryMatch>
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 15, 2009 at 7:57 a.m. EST
  • svn bash shortcuts
    alias .s='svn stat'
    alias .c='svn ci -m'
    alias .u='svn up'
    alias .a='svn stat | grep "^\?" | awk "{print \$2}" | xargs svn add'
    alias .d='svn stat | grep "^\!" | awk "{print \$2}" | xargs svn delete'
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 14, 2009 at 2:48 p.m. EST
  • divide and conquer svn repo
    # The following structure exists:
    #
    #  originalrepository/
    #    project_name/
    #      trunk/
    #      branches/
    #      tags/
    #
    # I want to move it to its *own* repository and give the following structure:
    #
    #  newrepositoryname/
    #    trunk/
    #    branches/
    #    tags/
    #
    
    export LOCAL='file:/'
    export SVN_DIR='/home/bluespark/svn'
    export SVN_OLD_REPO='originalrepository'
    export SVN_PROJ='project_name'
    export SVN_REPO='newrepositoryname'
    
    cd $SVN_DIR
    
    ## Create dumps
    mkdir $SVN_DIR/dumps
    svnadmin dump $SVN_OLD_REPO > dumps/$SVN_OLD_REPO.dump
    
    ## Filter the specific project_name out of the dump
    svndumpfilter include $SVN_PROJ \
         --drop-empty-revs \
         --preserve-revprops \
         --renumber-revs \
         < dumps/$SVN_OLD_REPO.dump \
         > dumps/$SVN_PROJ.dump
    
    ## Create the new repository...
    ## NOTE: You may need to do this step in the cpanel!!
    ## Here is how to do it on the comand line:
    # svnadmin create $SVN_DIR/$SVN_REPO
    
    
    ## Load the new repository with the contents of the
    ## filtered dump file.
    svnadmin load $SVN_REPO < dumps/$SVN_PROJ.dump
    
    
    ## Move the contens of the project_name to the repo root.
    svn mv $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/branches \
           $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/tags \
           $LOCAL/$SVN_DIR/$SVN_REPO/$SVN_PROJ/trunk \
           $LOCAL/$SVN_DIR/$SVN_REPO/ \
           -m "moved $SVN_PROJ contents to root"
    
    ## Delete the old (empty) project directory.
    ## Note:  you need to make sure the directory 
    ##        is really empty before deleting!
    svn del $SVN_DIR/$SVN_REPO/$SVN_PROJ -m "removed old project directory"
    

    copy | embed

    0 comments - tagged in  posted by jrguitar21 on Dec 14, 2009 at 2:34 p.m. EST
Sign up to create your own snipts, or login.