Public snipts »
d13t's
snipts
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"; ?>
-
∞ 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; }
-
∞ css baseline grid
body { font-family: Helvetica, Arial, sans-serif; font-size: 13px; line-height: 18px; } p { margin: 0 0 18px 0; }
-
∞ get data:image
<img alt=”logo” src=”data:image/gif;base64,<?php echo base64_encode(file_get_contents("logo.gif")) ?>”>
-
∞ 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
-
∞ 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
-
∞ html as php .htaccess
# let html files act as php files AddType application/x-httpd-php .php .htm .html
-
∞ base .htaccess (rewrite)
Options +FollowSymLinks RewriteEngine On
-
∞ pooper snooper
# prevent open directories from browsing Options All -Indexes
-
∞ force download .htaccess
# force download certain file types AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4
-
∞ 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>
-
∞ compress output php
<?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?>
-
∞ php info
<?php phpinfo(); ?>
-
∞ vertical rhythm
/* VERTICAL RHYTHM */ /* p margin-bottom = line-height */ body { font-size: 12px; line-height: 15px; } p { margin-bottom: 15px; }
-
∞ 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'); } } ?>
-
∞ 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
-
∞ 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 ?>
-
∞ 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>"; ?>



High Performance MySQL