- 1
- 2
- 3
- 4
- 5
- 6
- 7
Select *
From Table1
Where (
(id = 2000)
or
id = ( Select max(id) from Table1 )
)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−854
Select *
From Table1
Where (
(id = 2000)
or
id = ( Select max(id) from Table1 )
)
а я дивувався, чому цей код в табличці > 300 000 записів виконується так довго ...
+157
/**********************************************************************
* Connect to DB - over-ridden by specific DB class
*/
function connect()
{
die(EZSQL_CORE_ERROR);
}
/**********************************************************************
* Select DB - over-ridden by specific DB class
*/
function select()
{
die(EZSQL_CORE_ERROR);
}
/**********************************************************************
* Basic Query - over-ridden by specific DB class
*/
function query()
{
die(EZSQL_CORE_ERROR);
}
/**********************************************************************
* Format a string correctly for safe insert - over-ridden by specific
* DB class
*/
function escape()
{
die(EZSQL_CORE_ERROR);
}
/**********************************************************************
* Return database specific system date syntax
* i.e. Oracle: SYSDATE Mysql: NOW()
*/
function sysdate()
{
die(EZSQL_CORE_ERROR);
}
Продвинутый способ создания абстрактных методов. Это кагбе абстрактный класс, от которого наследуются БД-специфичные классы. Затем какая вам БД нужна, под такую руками и создавайте экземпляр нужного класса, "фабрикой" даже и не пахнет.
Зовётся сие чудо ezSQL. Используется в NetCat. Ладно хоть не сами наложили (налажали?), но всё ж головой не подумали, когда брали.
−142
#!/bin/bash
#
# program file name: urlmin.sh
# program version: 0.4
_help()
{
prg=$(basename $0)
cat << EOF
options:
-h See this page
-l Viewed all names of minifer sites
-s
lb.vg
minify.me
is.gd
-r Random mode of minifiers
-u url link
examples:
random mode - minifiers: ${prg} -r -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
only 1 minifier - is.gd minifier: ${prg} -s is.gd -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
or lb.vg minifier: ${prg} -s lb.vg -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1&m=b'
and other
EOF
exit 0
}
[ ! -f "$(which curl)" ] && { echo "Установите утилиту curl" ; exit 1 ;}
_user_agent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.4) Gecko/20100503 Firefox/3.6.4"
_sets_minifiers=( "lb.vg" "is.gd" "minify.me" )
_e() { echo -e "${*}" ;}
_get_page() { curl -s -A "$USER_AGENT" ${1} | tr -d '\n' || { clear ; echo -e "${B_T}${RC}Error${CRS}! curl in function _get_page has exited abnormaly: ${1}" ; exit 1 ;} ;}
_post_page() { curl -s -A "$USER_AGENT" -d "${2}" "${1}" | tr -d "\n" || { clear ; echo -e "${B_T}${RC}Error!${CRS} curl in function _post_page has exited abnormaly: ${1} -> ${2}" ; exit 1 ;} ;}
_urlencode() { LANG=C awk 'BEGIN { EOL = "%0A" ; split ("1 2 3 4 5 6 7 8 9 A B C D E F", hextab, " ") ; hextab [0] = 0 ; for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0 } ; { encoded = "" ; for ( i=1; i<=length ($0); ++i ) { c = substr ($0, i, 1) ; if ( c ~ /[a-zA-Z0-9.-]/ ) { encoded = encoded c } else if ( c == " " ) { encoded = encoded "+" } else { lo = ord [c] % 16 ; hi = int (ord [c] / 16); encoded = encoded "%" hextab [hi] hextab [lo] } } ; printf ("%s", encoded EOL) } END { }' "$@" | sed 's|%0A||g' ;}
_random() { [ -n "${1}" ] && { while :; do zz=$(y=0;for ((x=${1};x>=y;y++)) ; do [ "$y" == "${RANDOM[@]:2:1}" ] && [ -n "$y" ] && { echo $y ; break ;} ; done ) ; [ -n "$zz" ] && { echo "$zz" ; break ;} ; done ;} ;}
# sets
while getopts "hu:s:rl" option ; do case $option in
h) _help ;;
u) url_path="$OPTARG" ;;
s) _set_min="$OPTARG" ; set_min_num=$(j=0 ; for x in ${_sets_minifiers[*]} ; do [ "${x}" == "${_set_min}" ] && _e "${j}" ; ((j++)) ; done) ;;
r) mode_random="yes" ; set_min_num="$(_random $((${#_sets_minifiers[*]}-1)) )" ;;
l) list_mins="yes" ;;
v) set_verbose="-v" ;;
esac ; done
case $set_min_num in
0)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/default.asp" "Orig_URL=${_url_enc}&show_ve=1&Categ=Humor" | egrep -o "http://${_url_host}/[a-Z0-9]+'" | sort -u | sed "s|'||g;s|http://||g") ;;
1)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/create.php" "URL=${_url_enc}" | egrep -o "http://${_url_host}/[a-Z0-9]+\" target" | sed 's|\" target||g;s|http://||g') ;;
2)
_url_enc=$(_e "${url_path}" | _urlencode)
_url_host="${_sets_minifiers[$set_min_num]}"
_obtained=$(_post_page "http://${_url_host}/create.php" "url=${_url_enc}" | egrep -o "http://${_url_host}/\?[a-Z0-9]+" | sed 's|http://||g') ;;
esac
[ -z "$1" ] && _help
[ -n "$set_min_num" ] && _e "Link: ${_obtained}"
[ -n "$list_mins" ] && _e "Minifiers:\n\n$(for i in ${_sets_minifiers[*]} ; do _e " ${i}" ; done)\n"
# eof urlmin.sh
url minifier
# typical define:
-=>> ./urlmin.sh -s is.gd -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1& m=b'
Link: is.gd/ckjsg
# random minifier:
-=>> ./urlmin.sh -r -u 'http://wikimapia.org/#lat=36.7923994&lon=53.1100881&z=18&l=1& m=b'
Link: minify.me/?qkvbp2
+165
<?php
define('URL', 'http://shop.megafonnw.ru/spb/?pageid=5&subpageid=5&rnd=18');
$fp = fopen('URL', 'r');
$fpt = fopen('script.txt', 'r+');
$fpn = fopen('new.txt', 'r+');
$cont = file_get_contents(URL);
$man = substr($cont, 14900, 7636);
$script = file_get_contents('script.txt');
$new = file_get_contents('new.txt');
if($script == "") {
fwrite($fpt, $man);
print "script zapisan!";
}else {
if($script == $new) {
$ret = fwrite($fpn, $man);
print $ret."<br/>";
$sost = "No changed!";
ftruncate($fpn, 0);
}else {
$ret = fwrite($fpn, $man);
print $ret."<br/>";
$sost = "Text has been changed!";
ftruncate($fpt, 0);
$ret2 = fwrite($fpt, $new);
print $ret2."<br/>";
print strlen($new);
ftruncate($fpn, 0);
}
print "script ne zapisan";
}
print "\n\t<br/>".$sost;
fclose($fpn);
fclose($fpt);
fclose($fp);
?>
особо порадовала строка substr($cont, 14900, 7636);
+162
static public function checkFingerprint($fingerprint = null)
{
$user = ServiceFactory::getServiceUsers()->getByID((int)$_COOKIE['__MW__accountID']);
$fingerprint = (isset($fingerprint)) ? $fingerprint : Users::getFingerprint();
$flag = (bool)($fingerprint == $user->generateFingerprint());
if ( $flag )
return $user->userID;
else
return 0;
}
не только индусские разработчики бывают весёлыми - это творение взрослого афроамериканского собрата. Перестраховался везде где только мог. Особенно доставляет приведение к bool результата сравнения :)
+121
<div onmouseover="this.style.cursor = 'pointer';" onmouseout="this.style.cursor = 'default';">
+163
require_once(HTML2PS_DIR.'utils_array.php');
require_once(HTML2PS_DIR.'utils_graphic.php');
require_once(HTML2PS_DIR.'utils_url.php');
require_once(HTML2PS_DIR.'utils_text.php');
require_once(HTML2PS_DIR.'utils_units.php');
require_once(HTML2PS_DIR.'utils_number.php');
require_once(HTML2PS_DIR.'value.color.php');
require_once(HTML2PS_DIR.'config.parse.php');
require_once(HTML2PS_DIR.'flow_context.class.inc.php');
require_once(HTML2PS_DIR.'flow_viewport.class.inc.php');
require_once(HTML2PS_DIR.'output._interface.class.php');
require_once(HTML2PS_DIR.'output._generic.class.php');
require_once(HTML2PS_DIR.'output._generic.pdf.class.php');
require_once(HTML2PS_DIR.'output._generic.ps.class.php');
require_once(HTML2PS_DIR.'output.pdflib.old.class.php');
require_once(HTML2PS_DIR.'output.pdflib.1.6.class.php');
require_once(HTML2PS_DIR.'output.fpdf.class.php');
require_once(HTML2PS_DIR.'output.fastps.class.php');
require_once(HTML2PS_DIR.'output.fastps.l2.class.php');
require_once(HTML2PS_DIR.'output.png.class.php');
// require_once(HTML2PS_DIR.'output.pcl.class.php');
require_once(HTML2PS_DIR.'stubs.common.inc.php');
require_once(HTML2PS_DIR.'media.layout.inc.php');
require_once(HTML2PS_DIR.'box.php');
require_once(HTML2PS_DIR.'box.generic.php');
require_once(HTML2PS_DIR.'box.generic.formatted.php');
require_once(HTML2PS_DIR.'box.container.php');
require_once(HTML2PS_DIR.'box.generic.inline.php');
require_once(HTML2PS_DIR.'box.inline.php');
require_once(HTML2PS_DIR.'box.inline.control.php');
require_once(HTML2PS_DIR.'font.class.php');
require_once(HTML2PS_DIR.'font_factory.class.php');
require_once(HTML2PS_DIR.'box.br.php');
require_once(HTML2PS_DIR.'box.block.php');
require_once(HTML2PS_DIR.'box.page.php');
require_once(HTML2PS_DIR.'box.page.margin.class.php');
require_once(HTML2PS_DIR.'box.body.php');
require_once(HTML2PS_DIR.'box.block.inline.php');
require_once(HTML2PS_DIR.'box.button.php');
require_once(HTML2PS_DIR.'box.button.submit.php');
require_once(HTML2PS_DIR.'box.button.reset.php');
require_once(HTML2PS_DIR.'box.checkbutton.php');
require_once(HTML2PS_DIR.'box.form.php');
require_once(HTML2PS_DIR.'box.frame.php');
require_once(HTML2PS_DIR.'box.iframe.php');
require_once(HTML2PS_DIR.'box.input.text.php');
require_once(HTML2PS_DIR.'box.input.textarea.php');
require_once(HTML2PS_DIR.'box.input.password.php');
require_once(HTML2PS_DIR.'box.legend.php');
require_once(HTML2PS_DIR.'box.list-item.php');
require_once(HTML2PS_DIR.'box.null.php');
require_once(HTML2PS_DIR.'box.radiobutton.php');
require_once(HTML2PS_DIR.'box.select.php');
require_once(HTML2PS_DIR.'box.table.php');
require_once(HTML2PS_DIR.'box.table.cell.php');
require_once(HTML2PS_DIR.'box.table.cell.fake.php');
require_once(HTML2PS_DIR.'box.table.row.php');
require_once(HTML2PS_DIR.'box.table.section.php');
require_once(HTML2PS_DIR.'box.text.php');
require_once(HTML2PS_DIR.'box.text.string.php');
require_once(HTML2PS_DIR.'box.field.pageno.php');
require_once(HTML2PS_DIR.'box.field.pages.php');
........
и так до 284й строки включительно...
в самописном модуле к Drupal нашел сий шедевр
+165
function month($n){
switch ($n) {
case 1: $m = "сiчнi" ; break;
case 2: $m = "лютому" ; break;
case 3: $m = "березнi"; break;
case 4: $m = "квiтнi" ; break;
case 5: $m = "травнi" ; break;
case 6: $m = "червнi" ; break;
case 7: $m = "липнi" ; break;
case 8: $m = "серпнi" ; break;
case 9: $m = "вереснi"; break;
case 10: $m = "жовтнi" ; break;
case 11: $m = "листопадi"; break;
case 12: $m = "груднi" ; break;
}
return $m;
}
function month2($n)
{
switch ($n)
{
case 1: $m = "сiчень" ; break;
case 2: $m = "лютий" ; break;
case 3: $m = "березень"; break;
case 4: $m = "квiтень" ; break;
case 5: $m = "травень" ; break;
case 6: $m = "червень" ; break;
case 7: $m = "липень" ; break;
case 8: $m = "серпень" ; break;
case 9: $m = "вересень"; break;
case 10: $m = "жовтень" ; break;
case 11: $m = "листопад"; break;
case 12: $m = "грудень" ; break;
}
return $m;
}
/*... всяко разно ...*/
if($month==1)$month="сiчнi";
if($month==2)$month="лютому";
if($month==3)$month="березнi";
if($month==4)$month="квiтнi";
if($month==5)$month="травнi";
if($month==6)$month="червнi";
if($month==7)$month="липнi";
if($month==8)$month="серпнi";
if($month==9)$month="вереснi";
if($month==10)$month="жовтнi";
if($month==11)$month="листопадi";
if($month==12)$month="груднi";
// дебажный комментарий тут был
if($month1==1)$month1="сiчнi";
if($month1==2)$month1="лютому";
if($month1==3)$month1="березнi";
if($month1==4)$month1="квiтнi";
if($month1==5)$month1="травнi";
if($month1==6)$month1="червнi";
if($month1==7)$month1="липнi";
if($month1==8)$month1="серпнi";
if($month1==9)$month1="вереснi";
if($month1==10)$month1="жовтнi";
if($month1==11)$month1="листопадi";
if($month1==12)$month1="груднi";
/*...еще немного...*/
if($month==1)$month1="сiчнi";
if($month==2)$month1="лютому";
if($month==3)$month1="березнi";
if($month==4)$month1="квiтнi";
if($month==5)$month1="травнi";
if($month==6)$month1="червнi";
if($month==7)$month1="липнi";
if($month==8)$month1="серпнi";
if($month==9)$month1="вереснi";
if($month==10)$month1="жовтнi";
if($month==11)$month1="листопадi";
if($month==12)$month1="груднi";
+73.6
package psorter;
import java.util.Vector;
public class CArray extends Vector {
String type="";
/**
* constructor of /array/
* @param i set capacity increment
*/
public CArray(int i) {
this.capacityIncrement=i;
}
/**
* add object to end of vector with check of type
* if type same as @ first added - add this object
* safer than add
* @param o object to add
*/
public void append(Object o) {
if ( this.type.equals("") )
this.type=o.getClass().toString();
if ( o.getClass().toString().equals(this.type) ){
this.add(o);
} else {
if ( this.type.contains("Float") && o.getClass().toString().contains("Integer") )
this.add( Float.valueOf(o.toString()) );
if ( this.type.contains("Double") && o.getClass().toString().contains("Integer") )
this.add( Double.valueOf(o.toString()) );
if ( this.type.contains("Double") && o.getClass().toString().contains("Float") )
this.add( Double.valueOf(o.toString()) );
if ( this.type.contains("String") && o.getClass().toString().contains("Char") )
this.add( o.toString() );
}
}
public byte compare(int i, int j) throws Exception {
if (type.contains("Integer")) {
if ((Integer) (this.get(i)) > (Integer) (this.get(j)))
return 1;
if ((Integer) (this.get(i)) < (Integer) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Float")) {
if ((Float) (this.get(i)) > (Float) (this.get(j)))
return 1;
if ((Float) (this.get(i)) < (Float) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Double")) {
if ((Double) (this.get(i)) > (Double) (this.get(j)))
return 1;
if ((Double) (this.get(i)) < (Double) (this.get(j)))
return -1;
return 0;
}
if (type.contains("Char")) {
if ((Character) (this.get(i)) > (Character) (this.get(j)))
return 1;
if ((Character) (this.get(i)) < (Character) (this.get(j)))
return -1;
return 0;
}
if (type.contains("String")) {
if ( this.get(i).toString().compareTo(this.get(j).toString())>0 )
return 1;
if ( this.get(i).toString().compareTo(this.get(j).toString())<0 )
return -1;
return 0;
}
return 0;
}
}
сел писать 3 лабы естественно в последнюю ночь. начал в 11. эта была около 3х. самому потом стыдно было нести такое
+159.8
function AbstractControl_getProperty (propertyName) {
var targetElement = this.getTargetPath(propertyName);
var result = null;
if (this.isTargetAttribute(propertyName)) {
eval("result = targetElement." + this.getAttributeName(propertyName));
} else {
var getter = this.getGetterName(propertyName);
var expression = "result = targetElement." + getter + "();";
eval(expression);
}
return result;
}
Вот так наши "суровые челябинские" программисты, не имеющие представления об интроспективности javascript-а, повсюду злоупотребляют eval-ом, усложняя отладку и понимание кода.
По хорошему, вместо первого eval-а должно бы быть:
result = targetElement[this.getAttributeName(propertyName)];
а вместо второго:
result = targetElement[this.getGetterName(propertyName)]();