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

showing 1-20 of 81 snipts
  • JS: onfocus and onblur
    $("#email").focus(function() {
        if ($(this).val() == $(this).attr('rel'))
            $(this).val('');
    });
    $("#email").blur(function() {
        if ($(this).val() == '')
            $(this).val($(this).attr("rel"));
    });
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Sep 01, 2010 at 9:54 p.m. EDT
  • JW Player tips
    <?php
    
    // jw player tips
    //
    // http://www.longtailvideo.com/support/jw-player-setup-wizard
    //
    // http://www.longtailvideo.com/support/jw-player/jw-player-for-flash-v5/12536/configuration-options
    
    
    // build flashvars in case the user doesn't have js enabled
    $flash_vars = "&autostart=true&dock=false&file=".urlencode('blah.flv')."&image=".urlencode('blah.jpg')."&plugins=captions-1&captions.file=".urlencode('blah.xml');
            
    ?>
        <h3></h3>
        <p id='preview'>
        <embed src='http://www.blah.com/video/player.swf' height='360' width='640' allowscriptaccess='always' allowfullscreen='true' flashvars='<?php echo $flash_vars; ?>'/>
        </p>
    
        <script type='text/javascript' src='/video/swfobject.js'></script>
        <script type='text/javascript'>
            var s1 = new SWFObject('/video/player.swf','player','640','360','9');
            s1.addParam('allowfullscreen','true');
            s1.addParam('allowscriptaccess','always');
            s1.addVariable('file', 'blah.flv');
            s1.addVariable('autostart','true');
            s1.addVariable('dock','false');
            s1.addVariable('image','blah.jpg');
            s1.addVariable('captions.file', 'blah.xml');
            s1.addVariable('author','Me');
            s1.addVariable('description','Video of Me');
            s1.addVariable('title','Title');
            s1.addVariable('plugins','viral-2d,captions-1');
            s1.write('preview');
        </script>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Sep 01, 2010 at 10:31 a.m. EDT
  • Magento: custom advance search
    <form id="customsearch" method="get" action="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); ?>catalogsearch/advanced/result?">
    <?php
        $advanceSearch = array(
            array(
                'attrib' => 'color',
                'selectName' => 'color[]',
                'labelName' => 'Color'
                ),
            array(
                'attrib' => 'style',
                'selectName' => 'style[]',
                'labelName' => 'Style'
                )
        );
        $html = '';
        $attributes = Mage::getModel('catalogsearch/advanced')->getAttributes();
        foreach ($advanceSearch as $as)
        {
            $html .= " <label for='as-" . $as['labelName'] . "'></label> <select id='as-" . $as['attrib'] . "' name='" . $as['selectName'] . "'><option value=''>All</option>";
            foreach ($attributes as $a)
            {
                if ($a->getAttributeCode() == $as['attrib'])
                {
                    foreach ($a->getSource()->getAllOptions(false) as $option)
                    {
                        $html .= "<option value='" . $option['value'] . "'>" . $option['label'] ."</option>";
                    }
                }
            }
            $html .= "</select> ";
        }
        echo $html;
    ?>
    <input type="submit" value="search">
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Aug 29, 2010 at 6:50 p.m. EDT
  • Magento: update custom product attrib
    <?php
    
    // update a custom attribute in 1 product:
    // 
    $product = Mage::getModel('catalog/product')
        ->setCurrentStore(1)
        ->load($entity_id);
    
    // note: the 3rd param is the store id
    $product->addAttributeUpdate('rbanh_custom_attrib', $value, 1);
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Aug 28, 2010 at 11:26 p.m. EDT
  • Magento: extract data from 1 product
    <?php
    
    // Sometimes you don't need a collection, just 1 product.
    //
    $product = Mage::getSingleton('catalog/product')
                ->load($entity_id)
                ->getData();
    
    var_export($product);
    die();
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Aug 28, 2010 at 10:46 p.m. EDT
  • JS: onload fix for resetting when back button is used
    <script>
    // reset fix for selectbox when the back button is used
    // place this code in the body, not the head.
    window.onload = function(){
        $('#selectbox1').val('');
        $('#selectobx2').val('');
        };
    </script>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Aug 06, 2010 at 11:47 a.m. EDT
  • Magento: SQL filter by custom product attrib
    <?php
    
    // SQL call where custom product attrib 'promo' == 1
    
    $pcollection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*')
                //->addAttributeToFilter('sku',array('like' => '%ABC%'))
                ->addAttributeToFilter('promo', '1');
    foreach($pcollection as $pp)
    {
        // method 1
        $_promoProduct = $pp->_data;
    
        Zend_Debug::dump($_promoProduct); 
        die();
     
        // method 2
        $url = $pp->getProductUrl();
        $name = $this->htmlEscape($pp->getName());
        $img_src = $pp->getThumbnailUrl(325, 215);
        $price = number_format($pp->getPrice(), 2);
        // etc
    }
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 23, 2010 at 9:54 p.m. EDT
  • EE: .htaccess file
    DirectoryIndex index.php index.html
    Options -Indexes
    
    <FilesMatch "_CHANGELOG">
    deny from all
    </FilesMatch>
    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
    # Increase mem for EE - large data sets
    php_value memory_limit 64M
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 13, 2010 at 4:02 p.m. EDT
  • Magento: extract category info given product obj
    <?php
    
    // fetch the category if we have the product object
    
    // record the category info for this product
    $category = array();
    $cat_ids = $_product->getCategoryIds();
    $cat = new Mage_Catalog_Model_Category();
    foreach ($cat_ids as $cid)
    {
        $cat->load($cid);
        // var_export($cat);
    
        $cat_data = $cat->_data;
        $category[] = array(
            'name' => $cat_data['name'],
            'url_key' => $cat_data['url_key']
            );
    }
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 07, 2010 at 10:32 p.m. EDT
  • Magento: add extra attribs to product collection
    <?php
    
    // sometimes you need to add extra attribs
    
    $_products = $this->getProductCollection()
                     ->addAttributeToSelect('description');
    
    
    Zend_Debug::dump($_product->getData()); 
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 07, 2010 at 9:34 p.m. EDT
  • Magento: debug
    <?php 
    
    // debug in magento
    
    Zend_Debug::dump($_product->getData()); 
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 07, 2010 at 9:29 p.m. EDT
  • .htaccess: Allow only from IP
    # Allow only from these 2 IPs
    
    Order Deny,Allow
    Deny from all
    Allow from 311.311.311 322.322.322.322
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 06, 2010 at 4:32 p.m. EDT
  • EE: ngen and imgsizer
    <?php
    
    // EE - ngen + imgsizer
    //
    // http://www.lumis.com/page/imgsizer/
    
    {exp:weblog:entries ...}
    
    // ngen - display filename only
    {customFieldNamePhoto show='filename'}
    
    // ngen - display full path
    {customFieldNamePhoto}
    
    // ngen + imgsizer
    {exp:imgsizer:size src="{customFieldNamePhoto}" 
         width="98" alt="profile pic"}
    
    {/exp:weblog:entries}
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jul 02, 2010 at 12:04 p.m. EDT
  • EE: getting php segment vars
    <?php
    
    global $IN;
    
    $segment_2 = $IN->fetch_uri_segment('2');
    
    // get array of segments
    $seg_array = $IN->SEGS;
    
    // get the last segment
    $entry_id = $IN->QSTR;
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 28, 2010 at 5:24 p.m. EDT
  • Rewrite URL
    # rbanh add for soft linking old dir
    RewriteEngine On
    Options +FollowSymlinks
    RewriteRule ^aaa/(.*)$ /bbb/$1 [L]
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 23, 2010 at 12:38 p.m. EDT
  • EE: clean vars
    <?php
    
    global $IN, $REGX;
    
    $str = $REGX->xss_clean($_POST['abc']);
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 23, 2010 at 11:14 a.m. EDT
  • EE: plugin - return var pairs
    <?php
    
        // EE plugin - returning as tag paired
        //
        // usage:
        //
        // {exp:blah}
        //    {aaa}
        //       {bbb}
        //       {ccc}
        //    {/aaa}
        // {/exp:blah}
        //
    
        // now we build the return data structured for EE
        $tagdata = "";
        foreach ($returnArray as $entry_id => $obj)
        {
            // start the tagdata
            $temp = $TMPL->tagdata;
            
            if (preg_match('/{aaa}/', $temp))
            {
                // remove tag pairs
                $temp = str_replace('{aaa}', '', $temp);
                $temp = str_replace("{".SLASH."aaa}", '', $temp);
                
                $temp = str_replace('{bbb}', $obj['entry_id'], $temp);
                $temp = str_replace('{ccc}', $obj['title'], $temp);
                
                // store the tagdata
                $tagdata .= $temp;
            }
        }
    
        $this->return_data = $tagdata;
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 23, 2010 at 10:11 a.m. EDT
  • JS: prepend ajax text to url
    function addAjax(origHref)
    {
        //var origHref = $('.add-student').attr('href');
        var urlArray = origHref.split(/[\/]/);
        if (urlArray.length > 1)
        {
            var filename = urlArray.pop();
            // if there's a trailing slash, get the next iteration
            if (filename.length < 1) filename = urlArray.pop();
            filename = "/ajax-" + filename;
            return urlArray.join("/") + filename;
        }
        return origHref;
    }
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 22, 2010 at 10:50 a.m. EDT
  • EE: commenting blocks of code
    <?php
    
    // When using EE, you can comment out a section of code using
    // the following:
    
     {!--
    
     <p>Blah</p> 
    
      --}
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 18, 2010 at 8:45 a.m. EDT
  • EE: set and return vars in plugin
    <?php
    
    // for custom plugin in EE, setting variables 
    $tagdata = $TMPL->tagdata;    
    //var_export($TMPL->var_single);
    
    $tagdata = $TMPL->swap_var_single("rbanh_var","hello", $tagdata);
    $this->return_data .= $tagdata; 
    
    // usage:
    // {plugin_name}
    //    {rbanh_var}
    // {/plugin_name}
    ?>
    

    copy | embed

    0 comments - tagged in  posted by robertbanh on Jun 15, 2010 at 11:50 a.m. EDT
Sign up to create your own snipts, or login.