- 1
- 2
- 3
- 4
- 5
- 6
if($errors == 0){
$filename = 'films.txt';
if(!file_exists($filename)){
flose(fopen($filename,'w'));
}
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+163
if($errors == 0){
$filename = 'films.txt';
if(!file_exists($filename)){
flose(fopen($filename,'w'));
}
}
+162
function reverseStack()
{
$this->stackNotation = array_reverse($this->stackNotation);
$this->lenght = count($this->stackNotation);
return $this->lenght;
}
function calculateNotation()
{
$this->result = $this->stackNotation[0];
for($this->i = 1; $this->i < $this->lenght; $this->i++) {
$this->j = $this->i — 1;
switch($this->arifmeticSign[$this->j] ) {
case ’*’:
$this->result = $this->result * $this->stackNotation[$this->i];
...
новое слово в пэхэпэ-оопэ.
http://dou.ua/forums/topic/5548/
+154
#include "stdafx.h"
#include "expression.h"
#include <vector>
int _tmain(int argc, _TCHAR* argv[]) {
//Инициализация
std::vector<expression> arrayOfExpressions;
std::string inputString;
//Ввод количества выражений
printf( "Enter expressions count: " );
int countOfExpressions = 0;
scanf( "%d", &countOfExpressions );
//Ввод самих выражений
for ( int i = 1; i <= countOfExpressions; i++ ) {
printf( "Enter expression: " );
scanf( "%s", inputString );
arrayOfExpressions.push_back( expression( inputString ) );
}
//Подсчёт операторов
int total = 0;
for (int i = 0; i < arrayOfExpressions.size(); i++)
total += arrayOfExpressions.at(i).operatorsCount();
printf( "Total operators = %d", total );
//Освобождение памяти
arrayOfExpressions.erase(arrayOfExpressions.begin(),arrayOfExpressions.end());
return 0;
}
Один из уже известных вам студентов написал вот это. Вроде получше.
+77
Superclass s = new Subclass();
((Subclass)s).useSubclassMethod();
Чудеса полиморфизма.
+110
public abstract class AbstractSegment<P extends Number, V extends IOffsettable<P, V>,
U extends AbstractSegment<P, V, U>> implements IOffsettable<P, U>, Iterable<V>, Serializable {
...
protected final List<V> offsetHelper(final P dx, final P dy) {
return Lists.transform(points, new Function<V, V>() {
@Override
public V apply(final V input) {
return input.offset(dx, dy);
}
});
}
public final class FloatSegment extends AbstractSegment<Float, FloatPoint, FloatSegment> {
...
@Override
public FloatSegment offset(final Float dx, final Float dy) {
return new FloatSegment(offsetHelper(dx, dy));
}
}
+114
EventTypeId = (int)Enum.Parse(typeof(AmazonMailingLogEventType), Enum.GetName(typeof(AmazonMailingLogEventType), AmazonMailingLogEventType.SendEmailError))
вместо
EventTypeId = (int)AmazonMailingLogEventType.SendEmail Error
+108
string result = Encoding.GetEncoding(CharSet).GetString(resultData);
// сам паттерн \[\[\[\"([^"]*)
String commonString = "";
commonString += @"\";
commonString += @"[";
commonString += @"\";
commonString += @"[";
commonString += @"\";
commonString += @"[";
commonString += @"\";
commonString += "\"";
commonString += @"(";
commonString += "[";
commonString += "^";
commonString += "\"";
commonString += @"]";
commonString += @"*";
commonString += @")";
String pattern = commonString;
Regex reg = new Regex(pattern);
var mathces = reg.Match(result);
String stringResult = mathces.ToString().Replace("[[[\"", "");
Сборка паттерна регулярки, скажите как можно такое покороче собрать
+159
bool THotKeysRepository::TKeyCombination::operator<( const TKeyCombination& y ) const
{
return this->_AltKeyState<y._AltKeyState && this->_ScanCode<y._ScanCode;
}
+140
long long int temp;
temp=a-b;
if (temp<0) temp=temp*(-1);
.....
r = b*(2^g);
Из работ студентов.
Первый фрагмент - взятие по модулю.
Второй - вызвал вопрос "почему неправильно работает возведение в степень?".
+150
<tr class="cursor-over">
<td><i class="fs12">Сегодня</i></td>
<td><?= isset($today_stat['Отправлен']) ? $today_stat['Отправлен'] : 0 ?> <?=
HTML::image('media/img/private/good.png',
array('class' => 'png_bg', 'alt' => ''))
?></td>
<td><?= isset($today_stat['В обработке']) ? $today_stat['В обработке'] : 0 ?></td>
<td><?= isset($today_stat['Возврат']) ? $today_stat['Возврат'] : 0 ?></td>
<td><?= isset($today_stat['Отказ']) ? $today_stat['Отказ'] : 0 ?> <?=
HTML::image('media/img/private/error.png',
array('class' => 'png_bg', 'alt' => ''))
?></td>
</tr>
<tr class="cursor-over">
<td><i class="fs12">Вчера</i></td>
<td><?= isset($yesterday_stat['Отправлен']) ? $yesterday_stat['Отправлен'] : 0 ?> <?=
HTML::image('media/img/private/good.png',
array('class' => 'png_bg', 'alt' => ''))
?></td>
<td><?= isset($yesterday_stat['В обработке']) ? $yesterday_stat['В обработке'] : 0 ?></td>
<td><?= isset($yesterday_stat['Возврат']) ? $yesterday_stat['Возврат'] : 0 ?></td>
<td><?= isset($yesterday_stat['Отказ']) ? $yesterday_stat['Отказ'] : 0 ?> <?=
HTML::image('media/img/private/error.png',
array('class' => 'png_bg', 'alt' => ''))
?></td>
</tr>
это кусок шаблона, в котором, "опытный" программист выводит некую статистику за некий период