- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
Процедура Таймаут(ЧислоСекунд)
НачВремя = ТекущаяДата();
Пока 1 = 1 Цикл
Если ТекущаяДата() - НачВремя > ЧислоСекунд Тогда
Прервать;
КонецЕсли;
КонецЦикла;
КонецПроцедуры
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−96
Процедура Таймаут(ЧислоСекунд)
НачВремя = ТекущаяДата();
Пока 1 = 1 Цикл
Если ТекущаяДата() - НачВремя > ЧислоСекунд Тогда
Прервать;
КонецЕсли;
КонецЦикла;
КонецПроцедуры
Вот это я понимаю!!! Таймаут...
Это из той же конфигурации, что и прошлые мои кладки.
По прежнему коплю на патроны.
Открыт для любых конструктивных идей.
+4
IEnumerable<SmartCurrencyPriceRule> rules = _smartRuleService.GetCurrencyPriceRules(id).OrderBy(r => r.Title).ThenBy(r => r.Updated).ThenBy(r => r.Created);
var oldPriceRule = rules.SingleOrDefault(r => r.RuleId == postData.RuleId) ?? new SmartCurrencyPriceRule();
Давайте три раза отсортируем, а то мало ли что, а потом возьмём тот, у которого id совпадает.
Вот что значит - любит человек порядок.
+1
[DllImport("quickusb.dll", CharSet = CharSet.Ansi)]
static extern int QuickUsbWriteData(IntPtr Handle, byte[] outData, int length);
// ...
public bool Write(byte[] data)
{
// ...
int result = QuickUsbWriteData(handle, data, data.Length);
if (result != 0)
return true;
else if (result == 0)
{
LastError = "QUSB returned 0";
return false;
}
else
{
LastError = "Unknown error inside WriteData";
return false;
}
// ...
}
Видимо, последняя ветка - на случай зомби-апокалипсиса или особо сильных глюков после передоза.
+2
<div class="form-group">
<label for="inputName" class="col-sm-2 control-label">День рождения:</label>
<div class="col-sm-3">
<select class="form-control" id="day">
<option <?php if($explode[2] == 01) Echo "selected"; ?> value="01">01</option>
<option <?php if($explode[2] == 02) Echo "selected"; ?> value="02">02</option>
<option <?php if($explode[2] == 03) Echo "selected"; ?> value="03">03</option>
<option <?php if($explode[2] == 04) Echo "selected"; ?> value="04">04</option>
<option <?php if($explode[2] == 05) Echo "selected"; ?> value="05">05</option>
<option <?php if($explode[2] == 06) Echo "selected"; ?> value="06">06</option>
<option <?php if($explode[2] == 07) Echo "selected"; ?> value="07">07</option>
<option <?php if($explode[2] == 08) Echo "selected"; ?> value="08">08</option>
<option <?php if($explode[2] == 09) Echo "selected"; ?> value="09">09</option>
<option <?php if($explode[2] == 10) Echo "selected"; ?> value="10">10</option>
<option <?php if($explode[2] == 11) Echo "selected"; ?> value="11">11</option>
<option <?php if($explode[2] == 12) Echo "selected"; ?> value="12">12</option>
<option <?php if($explode[2] == 13) Echo "selected"; ?> value="13">13</option>
<option <?php if($explode[2] == 14) Echo "selected"; ?> value="14">14</option>
<option <?php if($explode[2] == 15) Echo "selected"; ?> value="15">15</option>
<option <?php if($explode[2] == 16) Echo "selected"; ?> value="16">16</option>
<option <?php if($explode[2] == 17) Echo "selected"; ?> value="17">17</option>
<option <?php if($explode[2] == 18) Echo "selected"; ?> value="18">18</option>
<option <?php if($explode[2] == 19) Echo "selected"; ?> value="19">19</option>
<option <?php if($explode[2] == 20) Echo "selected"; ?> value="20">20</option>
<option <?php if($explode[2] == 21) Echo "selected"; ?> value="21">21</option>
<option <?php if($explode[2] == 22) Echo "selected"; ?> value="22">22</option>
<option <?php if($explode[2] == 23) Echo "selected"; ?> value="23">23</option>
<option <?php if($explode[2] == 24) Echo "selected"; ?> value="24">24</option>
<option <?php if($explode[2] == 25) Echo "selected"; ?> value="25">25</option>
<option <?php if($explode[2] == 26) Echo "selected"; ?> value="26">26</option>
<option <?php if($explode[2] == 27) Echo "selected"; ?> value="27">27</option>
<option <?php if($explode[2] == 28) Echo "selected"; ?> value="28">28</option>
<option <?php if($explode[2] == 29) Echo "selected"; ?> value="29">29</option>
<option <?php if($explode[2] == 30) Echo "selected"; ?> value="30">30</option>
<option <?php if($explode[2] == 31) Echo "selected"; ?> value="31">31</option>
</select>
</div>
<div class="col-sm-4">
<select class="form-control" id="month">
<option <?php if($explode[3] == 01) Echo "selected"; ?> value="01">Января</option>
<option <?php if($explode[3] == 02) Echo "selected"; ?> value="02">Февраля</option>
<option <?php if($explode[3] == 03) Echo "selected"; ?> value="03">Марта</option>
<option <?php if($explode[3] == 04) Echo "selected"; ?> value="04">Апреля</option>
<option <?php if($explode[3] == 05) Echo "selected"; ?> value="05">Мая</option>
<option <?php if($explode[3] == 06) Echo "selected"; ?> value="06">Июня</option>
<option <?php if($explode[3] == 07) Echo "selected"; ?> value="07">Июля</option>
<option <?php if($explode[3] == 08) Echo "selected"; ?> value="08">Августа</option>
<option <?php if($explode[3] == 09) Echo "selected"; ?> value="09">Сентября</option>
<option <?php if($explode[3] == 10) Echo "selected"; ?> value="10">Октября</option>
<option <?php if($explode[3] == 11) Echo "selected"; ?> value="11">Ноября</option>
<option <?php if($explode[3] == 12) Echo "selected"; ?> value="12">Декабря</option>
</select>
</div>
</div>
Суровые челябинские программисты :)
−1
#ifndef H112
#define H112 201004L
#include<iostream>
#include<fstream>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include<stdexcept>
//------------------------------------------------------------------------------
#ifdef _MSC_VER
#include <hash_map>
using stdext::hash_map;
#else
#include <ext/hash_map>
using __gnu_cxx::hash_map;
namespace __gnu_cxx {
template<> struct hash<std::string>
{
size_t operator()(const std::string& s) const
{
return hash<char*>()(s.c_str());
}
};
} // of namespace __gnu_cxx
#endif
//------------------------------------------------------------------------------
#define unordered_map hash_map
//------------------------------------------------------------------------------
typedef long Unicode;
//------------------------------------------------------------------------------
using namespace std;
template<class T> string to_string(const T& t)
{
ostringstream os;
os << t;
return os.str();
}
struct Range_error : out_of_range { // enhanced vector range error reporting
int index;
Range_error(int i) :out_of_range("Range error: "+to_string(i)), index(i) { }
};
// trivially range-checked vector (no iterator checking):
template< class T> struct Vector : public std::vector<T> {
typedef typename std::vector<T>::size_type size_type;
Vector() { }
explicit Vector(size_type n) :std::vector<T>(n) {}
Vector(size_type n, const T& v) :std::vector<T>(n,v) {}
template <class I>
Vector(I first, I last) :std::vector<T>(first,last) {}
T& operator[](unsigned int i) // rather than return at(i);
{
if (i<0||this->size()<=i) throw Range_error(i);
return std::vector<T>::operator[](i);
}
const T& operator[](unsigned int i) const
{
if (i<0||this->size()<=i) throw Range_error(i);
return std::vector<T>::operator[](i);
}
};
// disgusting macro hack to get a range checked vector:
#define vector Vector
// trivially range-checked string (no iterator checking):
struct String : std::string {
String() { }
String(const char* p) :std::string(p) {}
String(const string& s) :std::string(s) {}
template<class S> String(S s) :std::string(s) {}
String(int sz, char val) :std::string(sz,val) {}
template<class Iter> String(Iter p1, Iter p2) : std::string(p1,p2) { }
char& operator[](unsigned int i) // rather than return at(i);
{
if (i<0||size()<=i) throw Range_error(i);
return std::string::operator[](i);
−2
[HttpPost]
[Route("api/Pateikimai/SaveList")]
public OperacijosRezultatas SaveList(List<PateikimasEditItem> models)
{
var atsakymas = new OperacijosRezultatas();
int failCounter = 0;
foreach (var model in models) {
try {
PateikimaiBll.SaveOrUpdate(model);
}
catch (Exception ex) {
failCounter++;
}
}
if (failCounter > 0)
{
atsakymas.SekmingaOperacija = false;
atsakymas.PridetiKlaida("Ne visi įrašai buvo išsaugoti");
}
else {
atsakymas.PridetiSekme("Pateikimų įrašas sėkmingai išsaugotas");
}
return atsakymas;
}
Смесь литовского с английским. Try/catch, который не записывает в лог и юзается для того, чтобы в front-end'e не запариватся с масивами (повторяющееся элементы). Уже не говорю об отсутсвии транзакций и foreach'e в контроллере.
−1
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
if(Checksquare()){
Cut(_point(x, y), true);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Здесь уместно вспомнить пословицу "Семь раз отмерь,(в данном случае 32 раза) один раз отрежь"
+1
define('OKVED_TRY_BUILD_CHUNK_IF_IT_NOT_FOUND_IN_CHUNKCACHE', TRUE);
Написал строчку и думаю - то ли я наговнокодил с названием, то ли соломки подстелил, так, что через месяц я ТОЧНО вспомню, зачем оно нужно...
0
class Program
{
static void Main(string[] args)
{
Cell[] cells = new Cell[15];
cells[1] = new Cell(); //и ещё 14 подобных строк
cells[1].AddAdjacentCell(cells[2], 1);
cells[1].AddAdjacentCell(cells[5], 2); //и так для всех 15 ячеек
Spore spore01 = new Spore(true, false, true, true, false, true);
Spore spore02 = new Spore(true, true, true, true, true, true);
for(Int16 i = 1; i <= 14; i++)
for (Int16 k = 1; k <= 14; k++)
{
if (i != k)
{
Console.Write("Trying " + i + " " + k + "... ");
cells[i].AddSpore(spore01);
cells[k].AddSpore(spore02);
bool badAttempt = false;
for(Int16 c = 1; c <= 14; c++)
{
if (cells[c].state == CellState.Empty)
{
badAttempt = true;
break;
}
}
Console.WriteLine(badAttempt.ToString());
}
}
Console.ReadLine();
}
}
class Cell
{
public CellState state;
private Cell[] adjacentCells = new Cell[6];
private Spore currentSpore = null;
public Cell()
{
this.state = CellState.Empty;
for (Int16 i = 0; i <= 5; i++)
{
this.adjacentCells[i] = null;
}
}
public void AddAdjacentCell(Cell cell, Int16 direction)
{
if (direction >= 6)
return;
this.adjacentCells[direction] = cell;
}
public void Ray(Int16 direction)
{
if (this.adjacentCells[direction] == null)
return;
if (this.adjacentCells[direction].state == CellState.Spore)
return;
this.state = CellState.Light;
this.adjacentCells[direction].Ray(direction);
}
public void AddSpore(Spore spore)
{
this.state = CellState.Spore;
this.currentSpore = spore;
for (Int16 i = 0; i <= 5; i++)
{
if (this.currentSpore.directions[i] == true)
this.Ray(i);
}
}
public void Reset()
{
this.state = CellState.Empty;
this.currentSpore = null;
for (Int16 i = 0; i <= 5; i++)
{
this.adjacentCells[i] = null;
}
}
}
enum CellState
{
Empty,
Light,
Spore
}
class Spore
{
public bool[] directions = new bool[6];
public Spore(params bool[] rays)
{
for (Int16 i = 0; i <= 5; i++)
this.directions[i] = rays[i];
}
}
}
(обсуждение программы для поиска решений для одной головоломки под Андроид)
- Да щас напишем, хуль там делать то?
(через 5 минут)
- Ой, переполнение стека...
- ...
−2
type Speaker interface {
SayHello()
}
type Human struct {
Greeting string
}
func (Human) SayHello() {
fmt.Println("Hello")
}
...
var s Speaker
s = Human{Greeting: "Hello"}
s.SayHello()
Отсюда: https://habrahabr.ru/post/276981/