- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
public static DBFactory getInstance() throws SQLException
{
synchronized (DBFactory.class)
{
if (_dbinstance == null)
_dbinstance = new DBFactory();
}
return _dbinstance;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+78
public static DBFactory getInstance() throws SQLException
{
synchronized (DBFactory.class)
{
if (_dbinstance == null)
_dbinstance = new DBFactory();
}
return _dbinstance;
}
Серийный и беспощадный доступ к инстансу ДБ-Фэктори -_-
Причем, данный код фурычит в многопоточной среде, где порой по 20-30 потоков одновременно обращаются к Фэктори, чтобы взять коннект с пула.
−179
a=0
b=0
c=0
d=0
...
z=0
A=0
B=0
C=0
D=0
...
Z=0
ile=int(input())
while ile>0:
pom=0
ile-=1
slowo=input()
dlugosc=len(slowo)
while dlugosc>0:
dlugosc-=1
if slowo[pom]=='a':
a=a+1;
if slowo[pom]=='b':
b=b+1
if slowo[pom]=='c':
c=c+1
if slowo[pom]=='d':
d=d+1
...
if slowo[pom]=='z':
z=z+1
if slowo[pom]=='A':
A=A+1
if slowo[pom]=='B':
B=B+1
if slowo[pom]=='C':
C=C+1
if slowo[pom]=='D':
D=D+1
...
if slowo[pom]=='Z':
Z=Z+1
pom+=1
if(a>0):
print('a', a)
if(b>0):
print('b', b)
if(c>0):
print('c', c)
if(d>0):
print('d', d)
...
if(z>0):
print('z', z)
if(A>0):
print('A', A)
if(B>0):
print('B', B)
if(C>0):
print('C', C)
if(D>0):
print('D', D)
...
if(Z>0):
print('Z', Z)
Чел походу не знает о существовании массивов и циклов.
... заменено, уж больно код длинный.
Типичный пример китайского кода.
Оригинал - http://ideone.com/kkZ51,8lrxt
З.Ы. Да, в питоне не массивы, а списки, но так понятнее
+162
switch ($size) {
case 'small':
if ($crop_thumbnail == 3 || $crop_thumbnail == 5 || $crop_thumbnail == 6 || $crop_thumbnail == 7 ) {
$crop = 1;
}
break;
case 'medium':
if ($crop_thumbnail == 2 || $crop_thumbnail == 4 || $crop_thumbnail == 5 || $crop_thumbnail == 7 ) {
$crop = 1;
}
break;
case 'large':
Default:
if ($crop_thumbnail == 1 || $crop_thumbnail == 4 || $crop_thumbnail == 6 || $crop_thumbnail == 7 ) {
$crop = 1;
}
break;
}
Phocagallery module, Joomla!
−134
# Fallback static file handler, now with XSendfile support.
if not if(test -f $local_path) {
if(! ~ $#xsendfile 0) {
if(! ~ $#xsendfile_alternate 0)
XSendfileHeader='X-Accel-Redirect'
if not
XSendfileHeader='X-Sendfile'
echo $XSendfileHeader': '`{pwd}^'/'$local_path
}
if not
static_file $local_path
}
if not if(~ $req_path /pub/* && test -f .$req_path) {
if(! ~ $#xsendfile 0) {
if(! ~ $#xsendfile_alternate 0)
XSendfileHeader='X-Accel-Redirect'
if not
XSendfileHeader='X-Sendfile'
echo $XSendfileHeader': '`{pwd}^'/'$req_path
}
if not
static_file .$req_path
}
+175
// The blank option to make sure the DropDownList keeps its width
var BlankOption = new Option(' ', 0);
+147
printf("%10.4lg ", 0);
В процессе копипасты...
+157
$day = date('w');
if($day == 0 || $day == 3 || $day == 4)
{
$me->handsDown();
$words = $music = $strength = false;
$me->separateWith($you);
$me->askForHelp($words);
}
try{
$key = md5(rand(0, 100));
$me->closeHouse($key);
unset($key);
}
catch(e){
while($light && $candle->getLight())
$me->believe($_GLOBALS);
}
doSilence();
try{
$me->sing();
}
catch(e){
$me->spreadShoulders($_GLOBALS['song']);
$difficulty = $me->silent(); //often big (bug?)
}
$days_rest = $time_end - time(); //often small (bug!)
/*
you may uncomment - that doesn't matter
$snow(); //true
$warm_blood(); //false
*/
while($light && $candle->getLight())
for($i = 0; $i < 100; ++$i)
$me->beginFrom(BEGINNING);
Если есть желание, попробуйте угадать песню. ;)
Все остальные могут минусовать.
+168
$new_array=array();
foreach ($old_array as $k => $v)
$new_array[$k] = $v;
Таким образом чел создаёт копию массива...
+116
mainDays = 0;
for (var d = emplDoc.EventDate.AddMonths(1).AddDays(-1).Date; d <= emplDoc.DateEndWork.Date; d = d.AddMonths(1)) {
mainDays += 2;
}
+125
/// <summary>
/// Return a DateTime version of the given Jabber date. Example date: 20020504T20:39:42
/// </summary>
/// <param name="dt">The pseudo-ISO-8601 formatted date (no milliseconds)</param>
/// <returns>A (usually UTC) DateTime</returns>
public static DateTime JabberDate(string dt)
{
if ((dt == null) || (dt == ""))
return DateTime.MinValue;
try
{
return new DateTime(int.Parse(dt.Substring(0, 4)),
int.Parse(dt.Substring(4, 2)),
int.Parse(dt.Substring(6, 2)),
int.Parse(dt.Substring(9,2)),
int.Parse(dt.Substring(12,2)),
int.Parse(dt.Substring(15,2)));
}
catch
{
return DateTime.MinValue;
}
}
/// <summary>
/// Get a jabber-formated date for the DateTime. Example date: 20020504T20:39:42
/// </summary>
/// <param name="dt">The (usually UTC) DateTime to format</param>
/// <returns>The pseudo-ISO-8601 formatted date (no milliseconds)</returns>
public static string JabberDate(DateTime dt)
{
return string.Format("{0:yyyy}{0:MM}{0:dd}T{0:HH}:{0:mm}:{0:ss}", dt);
}
Перевод DateTime в строку вида "20020504T20:39:42" и обратно. Из исходников библиотеки Jabber-net.
TryParseExact и ToString с форматом "yyyyMMddTHH:mm:ss" - это пусть лентяи используют.