- 1
- 2
- 3
- 4
- 5
- 6
- 7
> cat 1.pl
$owner = "Jack";
print "This is $owner\n";
print "This is $owner's house\n";
> perl 1.pl
This is Jack
This is house
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−124
> cat 1.pl
$owner = "Jack";
print "This is $owner\n";
print "This is $owner's house\n";
> perl 1.pl
This is Jack
This is house
The old package delimiter was a single quote, but double colon is now the preferred delimiter, in part because it's more readable to humans, and in part because it's more readable to emacs macros. It also makes C++ programmers feel like they know what's going on--as opposed to using the single quote as separator, which was there to make Ada programmers feel like they knew what was going on. Because the old-fashioned syntax is still supported for backwards compatibility, if you try to use a string like "This is $owner's house" , you'll be accessing $owner::s ; that is, the $s variable in package owner , which is probably not what you meant. Use braces to disambiguate, as in "This is ${owner}'s house" .
+50
<?php
require('url_to_absolute.php');
ini_set('display_errors','On');
error_reporting('E_ALL');
$ext=array(
'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
'docs'=>array('rtf','doc','docx','pdf','txt'),
'html'=>array('shtml','html','xml','css','htm','xhtml'),
'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
'pack'=>array('deb','rpm','jar'),
'scripts'=>array('sh','pl','py','php','js')
);
$murl="";
$sext="";
$routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
foreach($ext as $sk=>$sval){
foreach($sval as $exts){
$routh.='(?!'.$exts.'")';
}
}
$routh.='[a-z0-9]{1,5}(?=[" ]))|i';
echo $routh."<br\ >";
if(isset($_GET['url'])){
$url=$_GET['url'];echo $url."<br>";
preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
$html=file_get_contents($url);
foreach($ext as $key=>$val){
echo "<h2>$key</h2><br\>";
foreach($val as $mext){
echo "$mext<br>";
preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
}
}
preg_match_all($routh,$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
echo "<br><h2>Other documents</h2><br>";
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
}
}
}
} else { printf("No url\n");}
?>
Вытягивает ссылки на картинки с html файла
+142
<?php
require('url_to_absolute.php');
ini_set('display_errors','On');
error_reporting('E_ALL');
$ext=array(
'pictures'=>array('bmp','jpg','jpeg','pgm','rgb','tga','png','gif','ico'),
'docs'=>array('rtf','doc','docx','pdf','txt'),
'html'=>array('shtml','html','xml','css','htm','xhtml'),
'audio'=>array('mp3','mp4','mpeg','flv','3gp','webm'),
'arch'=>array('zip','rar','gz','bz2','tar','7zip','ar','tar\.gz','tar\.bz2','xz'),
'pack'=>array('deb','rpm','jar'),
'scripts'=>array('sh','pl','py','php','js')
);
$murl="";
$sext="";
$routh='|((?<=[" ])[^" ]+/[a-z0-9-_%.]+\.';
foreach($ext as $sk=>$sval){
foreach($sval as $exts){
$routh.='(?!'.$exts.'")';
}
}
$routh.='[a-z0-9]{1,5}(?=[" ]))|i';
echo $routh."<br\ >";
if(isset($_GET['url'])){
$url=$_GET['url'];echo $url."<br>";
preg_match('|(ftp)?(http)?(?:s)?://[a-z0-9-]+\.[a-z]+(\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?|i',$url,$ures);
if(!empty($ures[0])){echo $ures[0];$murl=$ures[0];echo "<br>murl ".$murl."<br> ";}
$html=file_get_contents($url);
foreach($ext as $key=>$val){
echo "<h2>$key</h2><br\>";
foreach($val as $mext){
echo "$mext<br>";
preg_match_all('|((/[.a-z0-9_-]*)*/[a-z0-9-_.%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((http(?:s)?://)[a-z0-9-]+\.[a-z]+(?:\.[a-z0-9-_&+?=%]+)*(?::[0-9]+)?(?:/[a-z0-9_-.]*)/[.a-z0-9-_%]+\.'.$mext.'(?![a-z])(?!/))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
preg_match_all('|((?<=[" ])[^" ]+\.'.$mext.'(?=[" ]))|i',$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a> ");}
}
}
}
}
preg_match_all($routh,$html,$result);
if(!empty($result)){
if(!empty($result[0])){
$result[0]=array_unique($result[0]);
echo "<br><h2>Other documents</h2><br>";
foreach($result[0] as $vres){
$aurl=url_to_absolute($url,$vres);
echo("<a href=\"$aurl\">".$aurl."</a><br \> ");
}
}
}
} else { printf("No url\n");}
?>
Вытягивает ссылки на картинки с html файла
+41
<?php
ini_set('display_errors','On');
error_reporting('E_ALL');
mysql_connect("localhost","MySQL","satanus") or die(mysql_error());
echo "Connected to mysql<br>";
mysql_select_db("myurl") or die(mysql_error());
echo "Connected to Database";
$ms=mysql_info();
echo $ms;
function isValidURL($url)
{
return preg_match('|^(http)(s)?://([a-z0-9-]+\.[a-z-]+)?(localhost)?(\.[a-z0-9-_/&+?=%]+)*(:[0-9]+)?(/[^.]+)?$|i', $url);
}
function parse_secure($arg){
$txt=preg_replace('/((<[^>]*>(.*)<\/[^>]*>|\'|")|(<[^>]*>)|(?:(\s+|>|<|\d+)(?:SELECT|FROM|UNION|ORDER BY|GROUP BY|UPDATE|DELETE|INSERT|OR|AND|NOT)(\s+|>|<|\d+))|<)/i','',$arg);
return $txt;
}
if(isset($_GET['pid'])){
$pid=$_GET['pid'];
$pid=parse_secure($pid);
$options=array('options'=>array('min_range'=>0,'max_range'=>1000001));
if(filter_var($pid,FILTER_VALIDATE_INT,$options)){
printf("pid correct %d",$pid);
} else {
printf("pid incorrect");exit(2);
}
$query="SELECT url FROM myurl.base WHERE id='$pid'";
$res=mysql_query($query);
if($res){
$row=mysql_fetch_assoc($res);
header('Location: '.$row['url']);
}
};
if(isset($_GET['cat']) && isset($_GET['scat'])){
$cat=$_GET['cat'];
$cat=parse_secure($cat);
if(isset($_GET['ps'])){
$ps = $_GET['ps'];
$ps=parse_secure($ps);
} else {
$ps =0;
};
$catl=iconv_strlen($thm);
echo "<html><head><title>Short url generator</title></head><body>";
echo "<h1>$cat</h1><br>";
$qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.subcategory=\"".$_GET['scat']."\" AND bs.category=\"".parse_secure($_GET['cat'])."\"";
$res=mysql_query($qry);
if($res){
while($row=mysql_fetch_assoc($res)){
echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a> ".$row['url'];
echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
echo "<br>";
}
}
exit(3);
};
if(isset($_GET['cat'])){
$cat=parse_secure($_GET['cat']);
$scat=parse_secure($_GET['scat']);
if(isset($_GET['ps'])){
$ps = $_GET['ps'];
} else {
$ps =0;
};
$catl=iconv_strlen($thm);
echo "<html><head><title>Short url generator</title></head><body>";
echo "<h1>$cat</h1><br>";
$qry="SELECT bs.id as pid,bs.url url,bs.subcategory scat,bs.category cat FROM base bs INNER JOIN category ct ON ct.id=bs.category WHERE bs.category=\"".$cat."\" OR ( bs.subcategory=\"".$scat."\" AND bs.category=\"".$cat."\")";
$res=mysql_query($qry);
if($res){
while($row=mysql_fetch_assoc($res)){
echo "<a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?pid=".$row['pid']."</a>".$row['url'];
echo " <a href=\"http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."\">http://".$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']."?cat=".$row['cat']."&scat=".$row['scat']."</a>".$row['url'];
echo "<br>";
}
}
};
if(isset($_POST['url']) && (isset($_POST['category']) || isset($_POST['cat'])) && (isset($_POST['subcat']) || isset($_POST['scat']))){
$url=$_POST['url'];
$purl=substr($url,0,26);
if($purl=="http://".$_SERVER['SERVER_NAME']."/")exit(0);
$purl=substr($url,0,30);
if($purl=="http://www.".$_SERVER['SERVER_NAME']."/")exit(0);
$cat=parse_secure($_POST['category']);
$catid=parse_secure($_POST['cat']);
$scat=parse_secure($_POST['subcat']);
$scatid=parse_secure($_POST['scat']);
if($url) {
if(!isValidURL($url))
{
$errMsg .= "* Please enter valid URL including http://<br>";
−40
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
static char ifnm[100];
string *tags = new string [100];
int tags_init(string stag[]){
int i=0;
stag[i++]="root";
stag[i++]="word";
stag[i++]="english";
stag[i++]="russian";
stag[i++]="russian2";
// stag[i++]="id";
return i;
};
int main(int argc,char *argv[]){
FILE *fp;
if(argc=0){printf("No file name\n");exit(0);}
strcpy(ifnm,argv[1]);
fp = fopen(ifnm, "r");
if (fp == NULL)exit(-1);
//Error;
char str[180];
int tn=tags_init(tags);
cout<<"<"<<tags[0]<<">"<<endl;
while(fgets(str, 180,fp))
{
fgets(str,180, fp);
//cout<<str<<endl;
char *pname;
pname = strtok (str,"-");
int ti=0;
cout<<"<"<<tags[1]<<">"<<endl;
ti=1;
while (pname != NULL && ti<=tn)
{
ti++;
cout<<"<"<<tags[ti]<<">"<<endl;
printf ("\t%s\n",pname);
cout<<"</"<<tags[ti]<<">"<<endl;
pname = strtok (NULL, "-");
}
cout<<"</"<<tags[1]<<">"<<endl;
}
cout<<"</"<<tags[0]<<">"<<endl;
fclose(fp);
}
Преобразует текстовый файл в xml формат
+141
if (value != null)
{
bool boolValue = (Boolean)value;
switch (boolValue)
{
case true:
return true;
case false:
return false;
}
}
Конвертер для CheckBox в WPF
+135
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define MAX_STEP 6
static int num;
int seq_gen(int step){
if(step<MAX_STEP){
for(int idx=1;idx<=MAX_STEP;idx++){
for(int i=0;i<=step;i++)printf(" ");
printf("<id%d step=\"%d\">\n",idx,step);
seq_gen(++step);
--step;
printf("</id%d>\n",idx);
};
};
if(step==MAX_STEP){
for(int i=1;i<=MAX_STEP;i++){
for(int si=0;si<=step;si++)printf(" ");
printf("<id%d>%d</id%d>\n",i,num++,i);
}
}
};
int main(){
printf("<root>\n");
seq_gen(1);
printf("</root>");
return 0;
};
Создает xml файл с 6 элементов с 6 вложенными элементами пока уровень вложенности достигнет 6.
+56
if ('cardiscon' == $key) {
echo '<td class="even cardiscon">'.$row['name'].':</td>';
} elseif ('cardprice' == $key) {
echo '<td class="even cardiscon">'.$row['name'].':</td>';
} else {
echo '<td class="even">'.$row['name'].':</td>';
}
Странная конструкция
+48
if (
($my_var[1] == "add_article" ||
$my_var[1] == "add_topic" ||
$my_var[1] == "add_topic2" ||
$my_var[1] == "add_initiative"
) && (
$_REQUEST["publish"] == "before" ||
$_REQUEST["publish"] == "current")
) {
} else {
echo <<<EOD
<!doctype html>
EOD;
}
форматирование сохранено
+137
#define FMT_2_LEN 16
#define FMT_4_LEN 24
// и т.д. всего около десятка форматов
void calc_check_code(const unsigned char * from, unsigned fmt, unsigned * code)
{
switch (fmt) {
case 2:
//...
memset(data, 0, sizeof(FMT_2_LEN));
// выборочное наполнение data из from
make_code(data, FMT_2_LEN, code);
break;
case 4:
//...
memset(data, 0, sizeof(FMT_4_LEN));
// выборочное наполнение data из from
make_code(data, FMT_2_LEN, code);
break;
// для всех остальных аналогично
}
странно, и почему контрольный код не совпадает с эталонными примерами...