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

showing 1-4 of 4 snipts
  • Strip a string
    <?php
      public static function stripText($text)
      {
        // rewrite critical characters
        // French
        $text = str_replace(array('À', 'Â', 'à', 'â'), 'a', $text);
        $text = str_replace(array('É', 'È', 'Ê', 'Ë', 'é', 'è', 'ê', 'ë'), 'e', $text);
        $text = str_replace(array('Î', 'Ï', 'î', 'ï'), 'i', $text);
        $text = str_replace(array('Ô', 'ô'), 'o', $text);
        $text = str_replace(array('Ù', 'Û', 'ù', 'û'), 'u', $text);
        $text = str_replace(array('Ç', 'ç'), 'c', $text);
        // German
        $text = str_replace(array('Ä', 'ä'), 'ae', $text);
        $text = str_replace(array('Ö', 'ö'), 'oe', $text);
        $text = str_replace(array('Ü', 'ü'), 'ue', $text);
        $text = str_replace('ß', 'ss', $text);
        // Spanish
        $text = str_replace(array('Ñ', 'ñ'), 'n', $text);
        $text = str_replace(array('Á', 'á'), 'a', $text);
        $text = str_replace(array('Í', 'í'), 'i', $text);
        $text = str_replace(array('Ó', 'ó'), 'o', $text);
        $text = str_replace(array('Ú', 'ú'), 'u', $text);
        // Polish
        $text = str_replace(array('?', '?'), 'a', $text);
        $text = str_replace(array('?', '?'), 'c', $text);
        $text = str_replace(array('?', '?'), 'e', $text);
        $text = str_replace(array('?', '?'), 'l', $text);
        $text = str_replace(array('?', '?'), 'n', $text);
        $text = str_replace(array('?', '?'), 's', $text);
        $text = str_replace(array('Ó', 'ó'), 'o', $text);
        $text = str_replace(array('?', '?', '?', '?'), 'z', $text);
        
        // strip all non word chars
        $text = preg_replace('/[^a-z0-9_-]/i', ' ', $text);
    
        // strtolower is not utf8-safe, therefore it can only be done after special characters replacement
        $text = strtolower($text);
    
        // replace all white space sections with a dash
        $text = preg_replace('/\ +/', '-', $text);
    
        // trim dashes
        $text = preg_replace('/\-$/', '', $text);
        $text = preg_replace('/^\-/', '', $text);
    
        return $text;
      }
    

    copy | embed

    0 comments - tagged in  posted by Tram on Jan 16, 2009 at 5:20 a.m. EST
  • Symfony - Action for text image generation (using GD)
    <?php
      public function executeGenerateText (sfWebRequest $request) {
        $font = '/images/ROTISSAS.TTF';
        $bbox = imageftbbox(20, 0, $font, $this->getRequestParameter('text') );
        
        $width = $bbox[2] - $bbox[0] + 10;
        $height = $bbox[1] - $bbox[7] + 10;
        
        $im = imagecreatetruecolor($width, $height);
        $black = imagecolorallocate($im, 0, 0, 0);
        $white = imagecolorallocate($im, 255, 255, 255);
        
        // Set the background to be white
        // Path to our font file
        // First we create our bounding box
        
        
        imagefilledrectangle($im, 0, 0, $width, $height, $black);
    
        // This is our cordinates for X and Y
        $x = $bbox[0] + (imagesx($im) / 2) - ($bbox[4] / 2);
        //$y = $bbox[1] + (imagesy($im) / 2) - ($bbox[5] / 2) + 3 ;
        $y = 28;
        
        imagefttext($im, 20, 0, 0, $y, $white, $font, $this->getRequestParameter('text'));
        
        // Output to browser
        header('Content-type: image/png');
        
        imagepng($im);
        imagedestroy($im);
    
        return sfView::NONE;
      }//executeGenerateText
    ?>
    
    
    # USAGE
    
    <img src="<? echo url_for('modulename/generateText?text=My text'); ?>" alt="" title="" />
    

    copy | embed

    0 comments - tagged in  posted by Tram on Jan 15, 2009 at 10:11 a.m. EST
  • symfony 1.2 - Add a custom filter field for generated admin
    <?php
      public function configure() {
        
        $this->widgetSchema['title'] = new sfWidgetFormFilterInput();
    
        $this->validatorSchema['title'] = new sfValidatorPass(array('required' => false));
      }//configure
    
      public function getFields() {
        return array_merge(array(
            'title'=> 'Title',
          ), parent::getFields()
        );
      } //getFields
    
      protected function addTitleColumnCriteria(Criteria $criteria, $field, $values) {
    
        // $values['text'] contains the field value, use it to change $criteria object
    
        // es. $criteria->add ('column', $values['text'])
    
      }//addTitleColumnCriteria
    
    ?>
    

    copy | embed

    1 comment - tagged in  posted by Tram on Jan 14, 2009 at 12:17 p.m. EST
  • symfony 1.2 - validation for a date range, with 'to date' field not mandatory.
    <?php
    # use it into configure() method in a myForm.class.php file
    
        $this->validatorSchema->setPostValidator( new sfValidatorOr( array (
            new sfValidatorAnd( array (
              new sfValidatorSchemaCompare ('from_date', sfValidatorSchemaCompare::NOT_EQUAL, null ), 
              new sfValidatorSchemaCompare ('to_date', sfValidatorSchemaCompare::EQUAL, null )
            )) ,
            new sfValidatorSchemaCompare('from_date', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'to_date',array('throw_global_error' => false), array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")' ))
        )));
    ?>
    

    copy | embed

    1 comment - tagged in  posted by Tram on Jan 14, 2009 at 7:08 a.m. EST
Sign up to create your own snipts, or login.