- 1
- 2
- 3
a=5; l=0;
.....
l= (l>a) ? 0 : l++;
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+156
a=5; l=0;
.....
l= (l>a) ? 0 : l++;
Писал вчера свою задумку и были там вот эти строки... Я долго не мог вкурить, почему же у меня l все время рвано 0 ...)
+117
[TestInitialize]
public void Init()
{
relashions = new List<PersonRelationship>();
relashions.Add( new PersonRelationship()
{
PersonId = 1,
RalationshipPersonId = 2,
RelationshipTypeId = (int)DAL.Dictionaries.RelationshipType.Friend
});
relashions.Add(new PersonRelationship()
{
PersonId = 1,
RalationshipPersonId = 2,
RelationshipTypeId = (int)DAL.Dictionaries.RelationshipType.Friend
});
relashions.Add(new PersonRelationship()
{
PersonId = 2,
RalationshipPersonId = 1,
RelationshipTypeId = (int)DAL.Dictionaries.RelationshipType.Friend
});
}
[TestMethod()]
public void GetMyFriends_Get_Success()
{
long personId = 1;
var relationService = new Mock<IRelationService>();
relationService.Setup(c => c.GetMyFriends(personId)).Returns
(
from rl in relashions.Where(r => r.PersonId == personId && r.RelationshipTypeId == (int)DAL.Dictionaries.RelationshipType.Friend)
select new PersonShortDescriptionViewModel()
{
FirstName = personId.ToString(),
LastName = personId.ToString(),
}
);
var friends = relationService.Object.GetMyFriends(personId);
Assert.IsNotNull(friends);
}
Найден правильный метод написания тестов!
−107
GraphicsWindow.Width = 640
GraphicsWindow.Height = 480
GraphicsWindow.PenColor = "Yellow"
For i = 0 To 250
GraphicsWindow.DrawLine(0 + i, 480 - i, 640 - i, 480 - i )
EndFor
GraphicsWindow.PenColor = "Orange"
For i = 0 To 250 Step 10
GraphicsWindow.DrawLine(0 + i, 480 - i, 640 - i, 480 - i)
EndFor
GraphicsWindow.BrushColor = "SteelBlue"
GraphicsWindow.FillRectangle (0,0, 640 , 230)
GraphicsWindow.BrushColor = "lightGreen"
GraphicsWindow.FillTriangle(0, 480, 0, 230, 250, 230)
GraphicsWindow.FillTriangle(640, 480, 640, 230, 390, 230)
GraphicsWindow.BrushColor = "Orange"
GraphicsWindow.FillEllipse (10, 30, 50, 50)
GraphicsWindow.PenColor = "Yellow"
Turtle.Show()
y = 0
For i = 0 To 360 Step 30
Turtle.X =35
Turtle.Y = 55
Turtle.Angle = i
Turtle.PenUp()
Turtle.Move(25)
Turtle.PenDown()
If y = 1 Then
Turtle.Move(10)
y = 0
else
Turtle.Move(20)
y = 1
endif
endfor
+147
if($element_id===false)
{
//этот код не должен работать
$sql = 'SELECT `countmessage` FROM `mes_topic` WHERE `id`='.(int)$board_id;
}else{
....
}
А зачем его писать?!
+154
public function invokeMethod($method, $params = array()) {
switch (count($params)) {
case 0:
return $this->{$method}();
case 1:
return $this->{$method}($params[0]);
case 2:
return $this->{$method}($params[0], $params[1]);
case 3:
return $this->{$method}($params[0], $params[1], $params[2]);
case 4:
return $this->{$method}($params[0], $params[1], $params[2], $params[3]);
case 5:
return $this->{$method}($params[0], $params[1], $params[2], $params[3], $params[4]);
default:
return call_user_func_array(array(&$this, $method), $params);
}
}
Из сорцов Lithium
+76
private static List<Character> englishAlphabet;
public static final Integer ENGLISH_ALPHABET_LENGTH = 26;
static {
englishAlphabet = new ArrayList<Character>();
englishAlphabet.add('#');
for (int i = 0; i < ENGLISH_ALPHABET_LENGTH; i++) {
englishAlphabet.add((char) ('A' + i));
}
}
Товарищ уже уволился :)
+111
while (true)
{
if (sec > 10)
{
sec = 0;
// Вызор функции
}
else
sec++;
Thread.Sleep(1000);
}
Боевой код, который допиливаю(
+150
if (!isset($pmas_table[0][3])) $pmas_table[0][3]='';
if (!isset($pmas_table[0][5])) $pmas_table[0][5]='';
if (!isset($pmas_table[0][6])) $pmas_table[0][6]='';
if (!isset($pmas_table[0][7])) $pmas_table[0][7]='';
UserSide v2.48 again. Так как там каждая строчка имеет право быть на этом сайте, выкладываю The best of the best =)
+126
public static bool IsLong(string tmpStr)
{
bool blRetVal = true;
for (int i = 0; i < tmpStr.Length; i++)
{
if (tmpStr[i] != '0' && tmpStr[i] != '1' && tmpStr[i] != '2' &&
tmpStr[i] != '3' && tmpStr[i] != '4' && tmpStr[i] != '5' &&
tmpStr[i] != '6' && tmpStr[i] != '7' && tmpStr[i] != '8' &&
tmpStr[i] != '9')
blRetVal = false;
}
return blRetVal;
}
static public string ConvertDateTimeForSQL(DateTime tmpDateTime)
{
return (
tmpDateTime.Year.ToString() + "-" +
(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString() + " " +
(tmpDateTime.Hour < 10 ? "0" : "") + tmpDateTime.Hour.ToString() + ":" +
(tmpDateTime.Minute < 10 ? "0" : "") + tmpDateTime.Minute.ToString() + ":" +
(tmpDateTime.Second < 10 ? "0" : "") + tmpDateTime.Second.ToString());
}
static public string ConvertDateTimeShortForSQL(DateTime tmpDateTime)
{
return (tmpDateTime.Year.ToString() + "-" +
(tmpDateTime.Month < 10 ? "0" : "") + tmpDateTime.Month.ToString() + "-" +
(tmpDateTime.Day < 10 ? "0" : "") + tmpDateTime.Day.ToString());
}
-----------------------------------
P.S. Версия .NET 3.5
+65
for (...) {
Comparator<Date> date_comparator = new Comparator<Date>() {
@Override
public int compare(Date s1, Date s2) {
long n1 = s1.getTime();
long n2 = s2.getTime();
if (n1 < n2)
return -1;
else if (n1 > n2)
return 1;
else
return 0;
}
};
Date beforeSaveDate = (Date) beforeSaveParam.getValue();
beforeSaveDate.setSeconds(0);
Date toSaveDate = (Date) toSaveParam.getValue();
comparedValue = date_comparator.compare(beforeSaveDate, toSaveDate);
}
Задача была сравнить две даты, игнорируя при этом секунды.