- 1
- 2
- 3
- 4
- 5
- 6
public static class IntExtension
{
public static int NotMoreThan(this int i, int thanWhat){
return i < thanWhat ? thanWhat : i;
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+942
public static class IntExtension
{
public static int NotMoreThan(this int i, int thanWhat){
return i < thanWhat ? thanWhat : i;
}
}
непонятно что
+144
public string[] razborstroki(string str)
{
string[] array = new string[100];
int j = 0;
for (int i = 0; i < str.Length; i++)
{
if (str[i] != ';')
array[j] += str[i];
else
j++;
}
return array;
}
Обнаружил недавно в одном из переданных нам проектов. Правильно, у нас будет свой split с маджонгом и гейшами!!!!
−92
errors[:please] « "fill one more field"
Ruby On Rails. Крутяк)
+143
void MyWindow::OkButtonClicked()
{
if((!cb1->isChecked()) && (!cb2->isChecked()))
emit Simple(line->text());
if((cb1->isChecked()) && (!cb2->isChecked()))
emit Register(line->text());
if((!cb1->isChecked()) && (cb2->isChecked()))
emit Invers(line->text());
if((cb1->isChecked()) && (cb2->isChecked()))
emit RegVers(line->text());
}
+143
function CopyEx(s:string; index,count:integer):string;
var
len,ln:integer;
begin
ln:=0;
if index <1 then index:=1;
len:=length(s);
ln:=len-count;
dec(ln);
dec(len,(index+ln));
result:=copy(s,index,len);
end;
+144
<?php
$startNumber = 0;
function LittlePart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
echo $BigPart . ' + (' . $i . ') = ' . number_format($number, 2, ',', ' ') . PHP_EOL;
$i++;
} while ($i <= 3);
}
function MidPart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
LittlePart ($BigPart . ' + (' . $i . ')·π', $number);
$i++;
} while ($i <= 3);
}
function QuadradPart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
MidPart ($BigPart . ' + (' . $i . ')·π²', $number);
$i++;
} while ($i <= 3);
}
function CubePart($BigPart, $startNumber) {
$i = -3;
$number = $startNumber * M_PI + ($i - 1);
do {
$number += M_PI;
QuadradPart ($BigPart . '(' . $i . ')·π³', $number);
$i++;
} while ($i <= 3);
}
CubePart('', 0);
Система счисления по основанию π. Пока с целыми числами.
http://ideone.com/EUYEKA
+142
function num_to_sxg($n) {
$s = "";
$m = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz";
if ($n===undefined || $n===0) { return 0; }
while ($n>0) {
$d = $n % 60;
$s = strcat($m[$d],$s);
$n = ($n-$d)/60;
}
return $s;
}
function num_to_sxgf($n, $f) {
$s = num_to_sxg($n);
if ($f===undefined) {
$f=1;
}
$f -= strlen($s);
while ($f > 0) {
$s = strcat("0",$s);
--$f;
}
return $s;
}
function sxg_to_num($s) {
$n = 0;
$j = strlen($s);
for ($i=0;$i<$j;$i++) { // iterate from first to last char of $s
$c = ord($s[$i]); // put current ASCII of char into $c
if ($c>=48 && $c<=57) { $c=$c-48; }
else if ($c>=65 && $c<=72) { $c-=55; }
else if ($c==73 || $c==108) { $c=1; } // typo capital I, lowercase l to 1
else if ($c>=74 && $c<=78) { $c-=56; }
else if ($c==79) { $c=0; } // error correct typo capital O to 0
else if ($c>=80 && $c<=90) { $c-=57; }
else if ($c==95) { $c=34; } // underscore
else if ($c>=97 && $c<=107) { $c-=62; }
else if ($c>=109 && $c<=122) { $c-=63; }
else { $c = 0; } // treat all other noise as 0
$n = 60*$n + $c;
}
return $n;
}
Угадайте, какой это язык и что пил автор.
http://ideone.com/87cVrr
http://ideone.com/Z8j7ve
+143
// Exported Functions
#ifdef __cplusplus
extern "C" {
#endif
...
DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document, int index, void* buffer, long& buflen);
#ifdef __cplusplus
};
#endif
https://pdfium.googlesource.com/pdfium/+/master/fpdfsdk/include/fpdfview.h
Intended to be C-compatible source.
+148
//G++ now allows typename in a template template parameter.
template<template<typename> typename X> struct D; // xzibit.jpeg
Пятый gcc вышел. Больше крестоблядства за те же деньги.
https://gcc.gnu.org/gcc-5/changes.html
+143
MyNumber(String n) {
try {
for (int i = 0; i < n.length(); i++) {
numbers[i] = charToInt(n.charAt(i));
}
} catch (InvalidArgumentException e) {
e.printStackTrace();
}
}
public int charToInt(char c) throws InvalidArgumentException{
char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
for (int i = 0; i < 10; i++) {
if (digits[i] == c) return i;
}
throw new InvalidArgumentException(null);
}
Попросили быстро написать перевод числа, закодированного в строку, в массив его цифр.