This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function file_content($_path) { | |
| $ch = curl_init(); | |
| curl_setopt($ch, CURLOPT_HEADER, 0); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser. | |
| curl_setopt($ch, CURLOPT_URL, $_path); | |
| $data = curl_exec($ch); | |
| curl_close($ch); | |
| return $data; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function file_mime($_path) { | |
| $ch = curl_init($_path); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| curl_exec($ch); | |
| $content_info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); | |
| curl_close($ch); | |
| $content_parts = explode(";", $content_info); | |
| $mime = $content_parts[0]; | |
| if(isset($mime) && !empty($mime)){return $mime;} | |
| else if (function_exists('finfo_open')) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function file_size($_path, $_unit, $_float = null, $_username = null, $_password = null) { | |
| $_unit = trim(strtoupper($_unit)); //Making the unit compatible | |
| function unit_size($data, $_unit, $_float) { | |
| if (!isset($_float)) {$_float = 3;} // float 3 decimal places by default | |
| $sizes = array("B"=>0, "KB"=>1, "MB"=>2, "GB"=>3, "TB"=>4, "PB"=>5, "EB"=>6, "ZB"=>7, "YB"=>8); //Associated with each unit is the exponent that will be used to do the conversion from bytes | |
| if (array_key_exists($_unit, $sizes) && $sizes[$_unit] != 0) { // If the unit is not bytes we get down to business | |
| $number = $sizes[$_unit]; | |
| $total = $data / (pow(1024, $number)); | |
| return round($total, $_float)." ".$_unit; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function get_ip(){ | |
| if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } // Check if the IP is from a shared internet connection | |
| else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } // Check if the IP is passed from a proxy | |
| else{ $ip = $_SERVER['REMOTE_ADDR']; } // The real IP address | |
| return $ip; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function file_alive($_path) { | |
| $handle = curl_init($_path); | |
| if (false === $handle) {return false;} | |
| curl_setopt($handle, CURLOPT_HEADER, false); | |
| curl_setopt($handle, CURLOPT_FAILONERROR, true); | |
| curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox because some sites request a valid header from you | |
| curl_setopt($handle, CURLOPT_NOBODY, true); | |
| curl_setopt($handle, CURLOPT_RETURNTRANSFER, false); | |
| $alive = curl_exec($handle); | |
| curl_close($handle); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var $ = function(selector, node) { // Bare-Bones Selector Engine | |
| var selector, node; | |
| selector = selector.trim(); | |
| node = node || document.body; | |
| if (selector != null) { | |
| return Array.prototype.slice.call(node.querySelectorAll(selector), 0); | |
| } | |
| } | |
| Array.prototype.put = function(html) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function crush($_file) { | |
| $_file = preg_replace(array("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/","!/\*[^*]*\*+([^/][^*]*\*+)*/!"), "", $_file); /* remove comments */ | |
| $_file = str_replace(array('\r\n','\r','\t','\n',' ',' ',' '), '', $_file); /* remove tabs, spaces, newlines, etc. */ | |
| /* remove spaces before/after certain characters */ | |
| $_file = preg_replace(array('(( )+\))','(\)( )+)'), ')', $_file); $_file = preg_replace(array('(( )+\()','(\(( )+)'), '(', $_file); | |
| $_file = preg_replace(array('(( )+\})','(\}( )+)'), '}', $_file); $_file = preg_replace(array('(( )+\{)','(\{( )+)'), '{', $_file); | |
| $_file = preg_replace(array('(( )+\:)','(\:( )+)'), ':', $_file); $_file = preg_replace(array('(( )+\;)','(\;( )+)'), ';', $_file); | |
| $_file = preg_replace(array('(( )+\,)','(\,( )+)'), ',', $_file); return $_file; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CSS HACKS | |
| ----------------------------------------------------------------- | |
| All except IE5 | |
| selector { property/**/: value; } | |
| All except IE5/Mac | |
| /*\*/ selector { property:value; } /**/ | |
| IE5/Mac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def report(count, blockSize, totalSize): | |
| percent = int(count*blockSize*100/totalSize) | |
| sys.stdout.write("\r%d%%" % percent + ' complete') | |
| sys.stdout.flush() | |
| sys.stdout.write('\rFetching ' + name + '...\n') | |
| urllib.urlretrieve(getFile, saveFile, reporthook=report) | |
| sys.stdout.write("\rDownload complete, saved as %s" % (fileName) + '\n\n') | |
| sys.stdout.flush() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // display source code | |
| $lines = file('http://google.com/'); | |
| foreach ($lines as $line_num => $line) { | |
| // loop thru each line and prepend line numbers | |
| echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n"; | |
| } |