- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
func getTransport(tt string) (iTransport, error) {
if tt == "scooter" {
return newElectricScooter(), nil
}
if tt == "quadcopter" {
return newQuadcopter(), nil
}
return nil, fmt.Errorf("Wrong type")
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
func getTransport(tt string) (iTransport, error) {
if tt == "scooter" {
return newElectricScooter(), nil
}
if tt == "quadcopter" {
return newQuadcopter(), nil
}
return nil, fmt.Errorf("Wrong type")
}
https://habr.com/ru/post/556512/
> Factory Method Pattern
> Привет, друзья. С вами Alex Versus.
> Ранее мы говорили про шаблоны проектирования Одиночка и Стратегия, про тонкости реализации на языке Golang.
> Сегодня расскажу про Фабричный метод.
0
* Returns the largest value among all values produced by [selector] function
* applied to each element in the collection.
*
* @throws NoSuchElementException if the collection is empty.
*/
@SinceKotlin("1.4")
@OptIn(kotlin.experimental.ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
@kotlin.internal.InlineOnly
public inline fun <T, R : Comparable<R>> Iterable<T>.maxOf(selector: (T) -> R): R {
val iterator = iterator()
0
CASE WHEN DAY(saledate)<10 THEN '0'+STR(DAY(saledate),1) ELSE STR(DAY(saledate),2) END + '.' + CASE WHEN MONTH(saledate)<10 THEN '0'+ STR(MONTH(saledate),1) ELSE STR(MONTH(saledate),2) END + '.'+ STR(YEAR(saledate),4) as SaleDate
Я у мамы программист...
convert(varchar, saledate, 104) as SaleDate
+1
Микросервисы - это хорошо или плохо?
+2
private static final String CITY_PREFIX = "г.";
private static final Map<String, String> CITIES = new HashMap<>() {
{
put("В.Новгород", "Великий Новгород");
put("Н.Новгород", "Нижний Новгород");
put("В. Новгород", "Великий Новгород");
put("Н. Новгород", "Нижний Новгород");
put("Великий Новгород", "Великий Новгород");
put("Нижний Новгород", "Нижний Новгород");
put("Петербург", "Санкт-Петербург");
put("Челны", "Набережные Челны");
put("Уренгой", "Новый Уренгой");
put("ПсковS", "Псков");
}
};
private static final Map<String, String> CITIES_WITH_PREFIX = new HashMap<>() {
{
put("г.Пушкино", "Пушкино");
}
};
ну просто офигенный мапинг
0
int ACMEncoder::Encode(int framepos, void *in, int in_avail, int *in_used, void *out, int out_avail)
{
char *pin = (char *)in;
char *pout = (char *)out;
int retval = 0;
if (!m_did_header && do_header)
{
int s = 44;
s = 4 + 4 + 12 - 4;
int t;
if (m_convert_wfx.wfx.wFormatTag == WAVE_FORMAT_PCM) t = 0x10;
else t = sizeof(WAVEFORMATEX) + m_convert_wfx.wfx.cbSize;
s += 4 + t;
if (s&1) s++;
if (m_convert_wfx.wfx.wFormatTag != WAVE_FORMAT_PCM)
s += 12;
s += 8;
if (out_avail < s) return 0;
//xx bytes of randomness
m_hlen = s;
m_did_header = 1;
out_avail -= s;
pout += s;
retval = s;
}
«Winamp» спиздили.
0
Код с продакшена рабочего проекта :-D
Dim got_new_batch As Boolean = False
Dim batch_numb As Integer = 0
Dim temp_batch As Integer = 0
While got_new_batch = False
temp_batch = objRandom.Next(400000000)
If check_batch_avaliable(temp_batch) = True Then
got_new_batch = True
batch_numb = temp_batch
End If
End While
Public Function check_batch_avaliable(ByVal batch_number As Integer) As Boolean
'CWC-7/11/2016-Rewritten to avoid runtime error
Dim RC As Integer = -1
Dim DBConnection As New IfxConnection(INFXConnectionStr_RPCentral)
'Try
Dim SQL As String = ""
SQL = " select first 1 batch_numb from " + System.Configuration.ConfigurationManager.AppSettings("InformixTable") + " where batch_numb = " & batch_number
Dim DBCommand As New IfxCommand(SQL, DBConnection)
DBCommand.CommandType = CommandType.Text
DBCommand.CommandTimeout = 200
DBConnection.Open()
RC = CInt(DBCommand.ExecuteScalar())
DBConnection.Close()
' Catch ex As Exception
' Dim ErrMsg = ex.Message
' Finally
If Not DBConnection Is Nothing Then
If DBConnection.State = ConnectionState.Open Then
DBConnection.Close()
End If
DBConnection = Nothing
End If
' End Try
If RC > 0 Then
Return False
Else
Return True
End If
End Function
+2
// https://shitcode.net/557
int getChar(char charachter){
int returnValue = Z;
switch(charachter){
case 'A': returnValue = A; break;
case 'a': returnValue = A; break;
case 'B': returnValue = B; break;
case 'b': returnValue = B; break;
case 'C': returnValue = C; break;
case 'c': returnValue = C; break;
case 'D': returnValue = D; break;
case 'd': returnValue = D; break;
case 'E': returnValue = E; break;
case 'e': returnValue = E; break;
case 'F': returnValue = F; break;
case 'f': returnValue = F; break;
case 'G': returnValue = G; break;
case 'g': returnValue = G; break;
case 'H': returnValue = H; break;
case 'h': returnValue = H; break;
case 'I': returnValue = I; break;
case 'i': returnValue = I; break;
case 'J': returnValue = J; break;
case 'j': returnValue = J; break;
case 'K': returnValue = K; break;
case 'k': returnValue = K; break;
case 'L': returnValue = L; break;
case 'l': returnValue = L; break;
case 'M': returnValue = M; break;
case 'm': returnValue = M; break;
case 'N': returnValue = N; break;
case 'n': returnValue = N; break;
case 'O': returnValue = O; break;
case 'o': returnValue = O; break;
case 'P': returnValue = P; break;
case 'p': returnValue = P; break;
case 'Q': returnValue = Q; break;
case 'q': returnValue = Q; break;
case 'R': returnValue = R; break;
case 'r': returnValue = R; break;
case 'S': returnValue = S; break;
case 's': returnValue = S; break;
case 'T': returnValue = T; break;
case 't': returnValue = T; break;
case 'U': returnValue = U; break;
case 'u': returnValue = U; break;
case 'V': returnValue = V; break;
case 'v': returnValue = V; break;
case 'W': returnValue = W; break;
case 'w': returnValue = W; break;
case 'X': returnValue = X; break;
case 'x': returnValue = X; break;
case 'Y': returnValue = Y; break;
case 'y': returnValue = Y; break;
case 'Z': returnValue = Z; break;
case 'z': returnValue = Z; break;
case ' ': returnValue = _; break;
case '3': returnValue = B2; break;
case '<': returnValue = TEMP; break;
case '*': returnValue = FULL; break;
case '|': returnValue = LINE; break;
case '_': returnValue = _; break;
case ':': returnValue = COL; break;
case '-': returnValue = DASH; break;
case ')': returnValue = BRA2; break;
case '%': returnValue = SMILE; break;
case '.': returnValue = DOT; break;
case '^': returnValue = COLDOT; break;
}
return returnValue; //RETORNO DE INFORMAÇÃO
}
Тут IsBukva до getChar допромоутили
+1
Есть случаи когда нужно 2 вызывать сборку помойки...
A = {x = "this is A"}
B = {f = A}
setmetatable(B, {__gc = function (o) print(o.f.x) end})
A, B = nil
collectgarbage() -- this is A
Роберту это называет Воскресение (Воскрешение)
https://stackoverflow.com/questions/28320213/why-do-we-need-to-call-luas-collectgarbage-twice
0
GET