Sign up to create your own snipts, or login.

Public snipts » d13t's snipts The latest snipts from d13t.

showing 1-18 of 18 snipts
  • getting rid of foreach error
    <?php
    // double any value whose key starts with 'b'
    $arr = array('a'=>1, 'b1'=>2, 'b2'=>3, 'c'=>4, 'd'=>5);
    $non_array = null;
    
    // Normal usage with an array
    print "Test 1:\n";
    foreach ($arr as $key => $val) {
        print "Key $key, Value $val\n";
    
    }
    
    // Normal usage with a non-array (undefined or otherwise empty data set)
    // Outputs: Warning: Invalid argument supplied for foreach() in test.php on line 16
    print "Test 2:\n";
    foreach ($non_array as $key => $val) {
        print "Key $key, Value $val\n";
    }
    
    // By casting the $non_array to an (array) type, it will function without error, skipping the loop
    print "Test 3:\n";
    foreach ((array) $non_array as $key => $val) {
        print "Key $key, Value $val\n";
    }
    
    print "Done.\n";
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Feb 22, 2010 at 4:39 a.m. EST
  • css image hover
    .image {
    /* image properties */
    }
    
    .image:hover {
    -o-transition-duration: .33s;
    -o-transition-property: border, color, opacity, -moz-opacity;
    -webkit-transition-duration: .33s;
    -webkit-transition-property: border, color, opacity, -moz-opacity;
    filter:alpha(opacity=50);
    -moz-opacity:0.5;
    -khtml-opacity: 0.5;
    opacity: 0.5;
    }
    

    copy | embed

    0 comments - tagged in  posted by d13t on Jan 19, 2010 at 7:42 a.m. EST
  • css baseline grid
    body {
    	font-family: Helvetica, Arial, sans-serif;
    	font-size: 13px;
    	line-height: 18px;
    }
    
    p { margin: 0 0 18px 0; }
    

    copy | embed

    0 comments - tagged in  posted by d13t on Nov 16, 2009 at 2:50 a.m. EST
  • get data:image
    <img alt=”logo” src=”data:image/gif;base64,<?php echo base64_encode(file_get_contents("logo.gif")) ?>”>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Sep 30, 2009 at 2:42 a.m. EDT
  • disable Spotlight
    // disable spotlight indexing
    
    sudo mdutil -i off  
    
    // enable spotlight indexing
    
    sudo mdutil -i on
    
    // delete existing spotlight indexes
    sudo mdutil -E 
    
    // some other options:  -s = display status, -v = verbose
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 27, 2009 at 3:30 a.m. EDT
  • symbolic link
    #syntax to create symbolic link
    ln -s /export/space/common/archive /archive
    
    #example, link would be created in directory 'placement'
    ln -s /path/to/original/file/or/directory /path/to/the/placement
    
    #dropbox example
    ln -s /Users/username/Dropbox/theFolder /path/to/symbolic/links/directory
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 21, 2009 at 8:24 a.m. EDT
  • html as php .htaccess
    # let html files act as php files
    AddType application/x-httpd-php .php .htm .html
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:44 a.m. EDT
  • base .htaccess (rewrite)
    Options +FollowSymLinks
    
    RewriteEngine On
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:42 a.m. EDT
  • pooper snooper
    # prevent open directories from browsing
    Options All -Indexes
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:42 a.m. EDT
  • force download .htaccess
    # force download certain file types
    AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:41 a.m. EDT
  • speed things up in .htaccess
    # speed things up
    <ifModule mod_gzip.c>
      mod_gzip_on Yes
      mod_gzip_dechunk Yes
      mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
      mod_gzip_item_include handler ^cgi-script$
      mod_gzip_item_include mime ^text/.*
      mod_gzip_item_include mime ^application/x-javascript.*
      mod_gzip_item_exclude mime ^image/.*
      mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:41 a.m. EDT
  • compress output php
    <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:37 a.m. EDT
  • php info
    <?php 
    phpinfo(); 
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 19, 2009 at 7:21 a.m. EDT
  • vertical rhythm
    /* VERTICAL RHYTHM */
    /* p margin-bottom = line-height */
    
    body {
     font-size: 12px;
     line-height: 15px;
    }
    
    p {
     margin-bottom: 15px;
    }
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 18, 2009 at 5:35 a.m. EDT
  • ie6 browser redirect
    <?php
    $ua = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($ua,'MSIE') != false && strpos($ua,'Opera') === false)
    {
    if (strpos($ua,'Windows NT 5.2') != false)
    {
    if(strpos($ua,'.NET CLR') === false) return;
    }
    if (substr($ua,strpos($ua,'MSIE')+5,1) < 7)
    {
    header('Location: http://www.mozilla.org');
    }
    }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Aug 11, 2009 at 6:43 a.m. EDT
  • lpr command
    # print text file from the command line:
    
    lpr /path/to/text.txt
    
    # get available printers:
    
    lpstat -a
    
    # print via printer Printer_name:
    
    lpr -P Printer_name /path/to/text.txt
    

    copy | embed

    0 comments - tagged in  posted by d13t on Apr 07, 2009 at 10:25 a.m. EDT
  • php print
    <?php 
    Print "Hello"; 
    //Outputs a string 
    Print $variable; 
    //Outputs a variable 
    Print "Multiple things " . $on . " one line"; 
    //Outputs a string, then a variable, then a string. All are separated with a [.] period 
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Feb 17, 2009 at 3:46 a.m. EST
  • php print time
    <?php 
    $b = time (); 
    print date("m/d/y",$b) . "<br>"; 
    print date("D, F jS",$b) . "<br>"; 
    print date("l, F jS Y",$b) . "<br>"; 
    print date("g:i A",$b) . "<br>"; 
    print date("r",$b) . "<br>"; 
    print date("g:i:s A D, F jS Y",$b) . "<br>"; 
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d13t on Feb 17, 2009 at 3:46 a.m. EST
Sign up to create your own snipts, or login.