- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
static double E( double epsilon )
{
int n = 1, nf = 1;
double e = 0;
while (Math.Abs(e - Math.E) > epsilon)
{
e += 1.0 / nf;
nf *= n;
n++;
}
return e;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+117
static double E( double epsilon )
{
int n = 1, nf = 1;
double e = 0;
while (Math.Abs(e - Math.E) > epsilon)
{
e += 1.0 / nf;
nf *= n;
n++;
}
return e;
}
Вычисление числа e как суммы обратных факториалов. По мотивам реальных событий.
+153
<option value="0"
<?
if($_SESSION['ttype'] == 0){ echo "SELECTED"; }
echo ">Подключение\n<option value=\"0last\" ";
if($_SESSION['ttype'] == '0last'){ echo "SELECTED"; }
echo ">История - Подключение\n<option value=\"1\" ";
if($_SESSION['ttype'] == 1){ echo "SELECTED"; }
echo ">Саппорт\n<option value=\"1last\" ";
if($_SESSION['ttype'] == '1last'){ echo "SELECTED"; }
echo ">История - саппорт\n<option value=\"all\" ";
if($_SESSION['ttype'] == 'all'){ echo "SELECTED"; }
?>
>Все
</select>
Вывод селекта для выбора типа заявки. 0.001% сочно наговнокоженного проекта
+114
if (FindNumber.Text.Length > 0)
{
string Num = FindNumber.Text;
FindNom FN=new FindNom();
Num = FN.ReplFindNumer(Num);
if (Num != null && Num.Length > 0)
{
StringBuilder sb = new StringBuilder(Num.Length);
foreach (char c in Num)
{
if (Char.IsControl(c) == true)
continue;
sb.Append(c);
}
Num = sb.ToString();
}
я пришел работать в фирму на развитие проекта интернет магазина, в ней уже работает программист, работает 6 лет!
я открыл его код и увидел ЭТО. причем чувак щеки от важности раздувает
+161
void convert_bglfile(std::string infile, std::string source_charset, std::string target_charset)
{
std::string outfile;
const char *p = infile.c_str();
const char *p1 = strrchr(p, '.');
if (p1) {
outfile.assign(p, p1-p);
} else {
outfile = infile;
}
...
Из опенсорсного словаря StarDict. Товарисч на форуме написал, что не комилируется - не иклюдился cstring. А там такое :o
+142
else
{
if(i == 0)
{
if(j == 0)
{
if(cells[i][j+1].label == 1)
{
cells[i][2].label = 2;
cells[i][2].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j].label == 1)
{
cells[2][j].label = 2;
cells[2][j].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j+1].label == 1)
{
cells[2][2].label = 2;
cells[2][2].empty = false;
playerIsTurn = true;
numTurns++;
}
}else if(j == 1)
{
if(cells[i][j-1].label == 1)
{
cells[i][2].label = 2;
cells[i][2].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j].label == 1)
{
cells[2][j].label = 2;
cells[2][j].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i][j+1].label == 1)
{
cells[0][0].label = 2;
cells[0][0].empty = false;
playerIsTurn = true;
numTurns++;
}
}else
{
if(cells[i][j-1].label == 1)
{
cells[i][0].label = 2;
cells[i][0].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j].label == 1)
{
cells[2][2].label = 2;
cells[2][2].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j-1].label == 1)
{
cells[2][0].label = 2;
cells[2][0].empty = false;
playerIsTurn = true;
numTurns++;
}
}
}else if(cells[i-1][j].label == 1)
часть 3 полный код можно посмотреть на http://www.gamedev.ru/projects/forum/?id=160346&page=2
+141
else if(numTurns != 1)
{
{
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
if(cells[i][j].label == 1)
{
if(i == 1 && j == 1)
{
if(cells[i][j-1].label == 1)
{
cells[i][j+1].label = 2;
cells[i][j+1].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i][j+1].label == 1)
{
cells[i][j-1].label = 2;
cells[i][j-1].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i-1][j].label == 1)
{
cells[i+1][j].label = 2;
cells[i+1][j].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j].label == 1)
{
cells[i-1][j].label = 2;
cells[i-1][j].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i-1][j-1].label == 1)
{
cells[i+1][j+1].label = 2;
cells[i+1][j+1].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i-1][j+1].label == 1)
{
cells[i+1][j-1].label = 2;
cells[i+1][j-1].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j+1].label == 1)
{
cells[i-1][j-1].label = 2;
cells[i-1][j-1].empty = false;
playerIsTurn = true;
numTurns++;
}else if(cells[i+1][j-1].label == 1)
{
cells[i-1][j+1].label = 2;
cells[i-1][j+1].empty = false;
playerIsTurn = true;
numTurns++;
}
}
часть 2
+156
public function session_set_lifetime($time){
/*NOT USED with cookies, can be used with sessions*/
return null;
}
тотже мастер класа что и тут:
http://govnokod.ru/9765/
http://govnokod.ru/9777/
+114
private void button8_Click(object sender, EventArgs e)
{
string fn = "";
string st = "";
string value = "";
string dirfile = "";
StreamWriter sw;
if (textBox1.Text != "")
{
dirfile = textBox1.Text + "\\" + GetFileName(openFileDialog1.FileName) + comboBox1.SelectedValue.ToString() + ".csv";
sw = new StreamWriter(dirfile, false, System.Text.Encoding.UTF8);
}
else
{
sw = new StreamWriter(openFileDialog1.FileName + comboBox1.SelectedValue.ToString() + ".csv", false, System.Text.Encoding.UTF8);
}
// Создаем колонки
for (int cl = 0; cl < dt.Columns.Count; cl++)
{
fn = dt.Columns[cl].ColumnName;
if (cl == 0)
{
st = fn.Replace("\n", "").Replace(";", "");
}
else
{
st += ";" + fn.Replace("\n", "").Replace(";", "");
}
}
sw.WriteLine(st);
progressBar1.Minimum = 1;
progressBar1.Maximum = dt.Rows.Count;
for (int i = 0; i < dt.Rows.Count; i++)
{
progressBar1.Value = i + 1;
Application.DoEvents();
for (int j = 0; j < dt.Columns.Count; j++)
{
value = dt.Rows[i][j].ToString();
if (value == "") { value = " "; }
try
{
Convert.ToInt16(value);
if (j == 0)
{
st = value.Replace("\n", "").Replace(";", "");
}
else
{
st += ";" + value.Replace("\n", "").Replace(";", "");
}
}
catch (System.FormatException exp)
{
if (j == 0)
{
st = value.Replace("\n", "").Replace(";", "");
}
else
{
st += ";" + value.Replace("\n", "").Replace(";", "") ;
}
}
catch (OverflowException oe)
{
if (j == 0)
{
st = value.Replace("\n", "").Replace(";", "");
}
else
{
st += ";" + value.Replace("\n", "").Replace(";", "");
}
}
}
sw.WriteLine(st);
}
sw.Close();
MessageBox.Show("Ok");
досталось в наследство, сохранение DataTable в CSV :)
+109
public static MyResultData SqlReturnDataset(string sql, string connection)
{
MyResultData result = new MyResultData();
try
{
MySql.Data.MySqlClient.MySqlConnection connRC = new MySql.Data.MySqlClient.MySqlConnection(connection);
MySql.Data.MySqlClient.MySqlCommand commRC = new MySql.Data.MySqlClient.MySqlCommand(sql, connRC);
connRC.Open();
try
{
MySql.Data.MySqlClient.MySqlDataAdapter AdapterP = new MySql.Data.MySqlClient.MySqlDataAdapter();
AdapterP.SelectCommand = commRC;
DataSet ds1 = new DataSet();
AdapterP.Fill(ds1);
result.ResultData = ds1.Tables[0];
}
catch (Exception ex)
{
result.HasError = true;
result.ErrorText = ex.Message;
}
connRC.Close();
}
catch (Exception ex)//Этот эксепшн на случай отсутствия соединения с сервером.
{
result.ErrorText = ex.Message;
result.HasError = true;
}
return result;
}
+114
private int GetInsertion(byte[] firstArr, byte[] secondArr)
{
int result = -1;
int counter = 0;
if (firstArr.Count() >= secondArr.Count())
{
for (int i = 0; i < firstArr.Count(); i++)
{
if (firstArr[i] == secondArr[counter])
{
counter++;
if (counter == secondArr.Count())
{
result = i - counter + 1;
break;
}
}
else
{
counter = 0;
}
}
}
return result;
}
находит индекс вхождения одного массива в другой