<?php print($_SERVER['DOCUMENT_ROOT']); ?>
Tag Archive for path
Print out your shared server’s real path
.bat file that calls a script and passes arguments to the script
%~dp$PATH:1FOO.pl %*
Category: Uncategorized |
Tags: bat, batch, batchfile, environment, name, os, parameters, path, scripting, windows, wrapper
Create a directory recursively
mkdir -p /Users/Shared/Desktop/homer/marge/bart/lisa/maggie/snowball2 #or, in a .bash_profile alias mkdir="mkdir -p "
Category: Uncategorized |
Tags: basic, commandline, commands, create, easy, FileSystem, mkdir, name, path, recurse, scripting, subdirectories, tools
php absolute path include
<?php include ($_SERVER['DOCUMENT_ROOT'] . '/inc/file.php');?>
Python – randomFlickr
import os
import random
import re
import urllib
import urllib2
class flickrImages(object):
RE_IMAGEURL = re.compile('src="(http://static.flickr.com/.+?_t.jpg)"', re.DOTALL | re.IGNORECASE)
def __init__(self):
self.imagesURLs = {}
def getRandomImages(self):
'''
Scarica dal sito FlickrImages delle immagini in maniera random...
'''
htmlPage = ''
request = ''
requestURL = 'http://flickr.com/photos?start=%d' % (random.randint(0, 5000))
requestHeaders = {'User-Agent':'flickrImages/1.0'}
try:
request = urllib2.Request(requestURL, None, requestHeaders)
htmlPage = urllib2.urlopen(request).read(500000)
except:
pass
results = flickrImages.RE_IMAGEURL.findall(htmlPage)
if len(results) > 0:
for image in results:
imageURL = urllib.unquote_plus(image)
if not imageURL.startswith('http://'): imageURL = 'http://'+imageURL
imageURL = imageURL.replace('_t.jpg', '_o.jpg') # Prende il formato piu' grande
self.imagesURLs[imageURL] = 0
def downloadImages(self):
'''
Scarica nella cartella googleIMGs le foto che vengono trovate in rete...
'''
numberIMGs = len(self.imagesURLs)
posIMGs = 1
for imageName in self.imagesURLs:
print '[' + str(posIMGs) + '/' + str(numberIMGs) + '] - ' + imageName
urllib.urlretrieve(imageName, 'flickrIMGs' + os.sep + os.path.split(imageName)[1])
posIMGs += 1
if __name__ == '__main__':
test = flickrImages()
test.getRandomImages()
test.downloadImages()
print 'Finito...'
Python – randomYahoo
import os
import random
import re
import urllib
import urllib2
class yahooImages(object):
RE_IMAGEURL = re.compile('&imgurl=(.+?)&', re.DOTALL | re.IGNORECASE)
def __init__(self):
self.imagesURLs = {}
def getRandomImages(self, imageName=None):
'''
imageName = Nome dell'immagine da cercare, se non impostato viene generato un nome Random
Scarica dal sito YahooImages delle immagini in maniera random...
'''
htmlPage = ''
request = ''
if imageName == None: imageName = self._randomWords()
requestURL = 'http://it.search.yahoo.com/search/images?p=%s&b=%d' % (imageName, (random.randint(0, 50)*10))
requestHeaders = {'User-Agent':'yahooImages/1.0'}
try:
request = urllib2.Request(requestURL, None, requestHeaders)
htmlPage = urllib2.urlopen(request).read(500000)
except:
pass
results = yahooImages.RE_IMAGEURL.findall(htmlPage)
if len(results) > 0:
for image in results:
imageURL = urllib.unquote_plus(image)
if not imageURL.startswith('http://'): imageURL = 'http://'+imageURL
self.imagesURLs[imageURL] = 0
def _randomWords(self):
'''
Viene generata una parola in maniera Random...
'''
words = ''
charset = 'abcdefghijklmnopqrtuvwxyz'*2 + '0123456789'
for i in range(random.randint(2, 7)): words += random.choice(charset)
return words
def downloadImages(self):
'''
Scarica nella cartella yahooIMGs le foto che vengono trovate in rete...
'''
numberIMGs = len(self.imagesURLs)
posIMGs = 1
for imageName in self.imagesURLs:
print '[' + str(posIMGs) + '/' + str(numberIMGs) + '] - ' + imageName
urllib.urlretrieve(imageName, 'yahooIMGs' + os.sep + os.path.split(imageName)[1])
posIMGs += 1
if __name__ == '__main__':
test = yahooImages()
test.getRandomImages()
test.downloadImages()
print 'Finito...'
Python – randomLocal
import os
import random
class localImages(object):
def __init__(self, directory='/home/Foto'):
self.directoryScan = directory # Cartella da cui cominciare a prelevare le foto
self.directoryRemain = [self.directoryScan]
self.filePath = {}
def getRandomImages(self):
'''
Prelieva dal proprio disco delle immagini in maniera random...
'''
for i in range(5): # Scansiona 5 directory
if len(self.directoryRemain) > 0:
directory = random.choice(self.directoryRemain)
self.directoryRemain.remove(directory)
files = []
try:
files = os.listdir(directory)
except:
pass
# Serve per aumentare il Random delle Foto
# FIXME: cercare di aumentare questo random
if len(files) > 0:
for i in range(len(files)/2):
files_remove = random.choice(files)
files.remove(files_remove)
##########################################
for filename in files:
filepath = os.path.join(directory, filename)
if os.path.isdir(filepath):
self.directoryRemain.append(filepath)
elif os.path.isfile(filepath):
(name, ext) = os.path.splitext(filepath)
if ext.lower() in ('.jpg', '.gif'):
self.filePath[filepath] = 0
if len(self.directoryRemain) == 0: self.directoryRemain = [self.directoryScan]
def downloadImages(self):
'''
Scarica nella cartella localIMGs le foto che vengono trovate nel disco...
'''
numberIMGs = len(self.filePath)
posIMGs = 1
for imageName in self.filePath:
print '[' + str(posIMGs) + '/' + str(numberIMGs) + '] - ' + imageName
fread = open(imageName, 'rb')
fwrite = open('localIMGs' + os.sep + os.path.split(imageName)[1], 'wb')
fwrite.write(fread.read())
fread.close()
fwrite.close()
posIMGs += 1
if __name__ == '__main__':
test = localImages()
test.getRandomImages()
test.downloadImages()
print 'Finito...'
PHP – Finger PHP Simple Client
<?php
// Client di Finger
$fp = fsockopen('kernel.org', 79); // Si collega al seguente server nella porta 79
fputs($fp, '@kernel.org
'); // Manda una richiesta
echo '<table border='0' cellspacing='1' cellpadding='1' bgcolor='black'>';
while( !feof($fp) )
{
$text = fgets($fp, 128); // Ritorna una risposta
if(trim($text) != '')
{
echo '<tr bgcolor='white'>';
echo '<td>';
echo '<font face='Arial' size='-2'>' . trim($text) . '</font>';
echo '</td>';
echo '</tr>';
}
}
echo '</table>';
fclose($fp);
?>
array_get_path
function array_get_path($data, $path, &$result){
$found = true;
$path = explode("/", $path);
for ($x=0; ($x < count($path) and $found); $x++){
$key = $path[$x];
if (isset($data[$key])){
$data = $data[$key];
}
else { $found = false; }
}
$result = $data;
return $found;
}
// test array:
$tree = array(
'red' => array(),
'blue' => 'water',
'green' => 'flowers',
'grey' => array(
'light' => array('eeeeee', 'e7e7e7'),
'dark' => array('cccccc')
),
7 => 'foobar'
);
// path tests:
if (array_get_path($tree, 'grey/light/1', $result)){
print $result;
// should print --> e7e7e7
}
Include PEAR Directory
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . "$HOME/pear/php");