- 1
- 2
- 3
- 4
- 5
QByteArray ba;
char x;
x = 0x05;
ba.append (&x, sizeof (x));
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+55
QByteArray ba;
char x;
x = 0x05;
ba.append (&x, sizeof (x));
Qt. Продолжаем мучить QByteArray :)
+50
char parser_msg(char *data, char size)
{
//<...>
QByteArray bt;
//<...>
x=(char *) malloc(size);
bt.clear();
for (i=0; i<size; i++) {
x[i]=*data;
bt.append(*data);
*data++;
}
printf("Data parser! >> '%s'\n", bt.toHex().constData());
if (x[0]==0x06) {
//<...>
}
if (x[0]==...) {
//<...>
}
//<...>
}
Разбор команд из COM-порта. Используется Qt. QByteArray, кстати, заведен здесь только ради дебаг-принта.
При вызове функции в кач. data передается указатель, возвращаемый data() другого байтаррэя, живущего на стеке.
+71
public static int activeThreadsCount(List<Thread> threadList)
{
int i = 0;
for (Thread thread : threadList)
{
i += thread.isAlive() ? 1 : 0;
}
return i;
}
+54
virtual bool IsUnlockedAll(){bool temp = false;return temp^temp;};
Код с боевого проекта. Комментариев не будет.
−99
com.google.ui:ShadowButtonTextUiConfigFactory
Разбираюсь с гуглокодом для Ютуб плеера. Как думаете, что может делать этот класс?
+161
if (array_key_exists('COUPON', $_POST) && !array_key_exists('coupon', $_POST))
{
$_POST["coupon"] = $_POST["COUPON"];
}
В глубинах битрикса...
+134
public void OnKillEvent_ServerOnly(PhotonPlayer player)
{
case MatchTypeInfo.TDM:
if (player != null)
{
var hash = player.customProperties;
if (hash != null)
{
var team = (int) hash["team"];
var realScore = match.GetTeamScores();
var teamAScor = team == 0 ? realScore.x + TeamDeathScores : realScore.x;
var teamBScor = team == 1 ? realScore.y + TeamDeathScores : realScore.y;
//DebugModule("Kill Processed On Server completed: " + team + "// " + teamAScor + "/" + teamBScor);
match.ChangeTeamScores((int)teamAScor, (int)teamBScor);
}
else
{
Debug.LogError("OnKillEvent_ServerOnly ERROR Team hash");
}
}
break;
} {
//через 500 строк кода
private void LocalUpdate()
{
if (Application.isEditor)
{
if (Input.GetKeyDown(KeyCode.Y))
{
switch (MatchType)
{
case MatchTypeInfo.TDM:
ChangeTeamScores((int)(_teamScores.x - 1), (int)(_teamScores.y - 1), true);
break; }
SendTeamScoresToUI();
}
}
switch (MatchType)
{
case MatchTypeInfo.TDM:
// DebugModule("Load TDM type game");
break;
}
}
//ещё 500 строк
public void ChangeTeamScores(int a, int b, bool force = false)
{
if (PhotonNetwork.isMasterClient)
{
// check server rules
var rules = GetGameRules();
if (rules != null)
{
if (!rules.CheckPlayerCountRules() && !force)
{
Debug.LogError("Game is not started, beacuse server has no players: " + rules.MinimumPlayerToPlay + "/" +
PhotonNetwork.room.playerCount);
return;
}
}
else
{
Debug.LogError("Rule error");
return;
}
_teamScores.x = Mathf.Clamp(a, 0, float.MaxValue);
_teamScores.y = Mathf.Clamp(b, 0, float.MaxValue);
var matchIsCompleted = false;
switch (MatchType)
{
case MatchTypeInfo.TDM:
matchIsCompleted = _teamScores.x <= 0 || _teamScores.y <= 0;
break;
}
if (matchIsCompleted)
{
Server_CallEndRound();
}
else
{
// Call Event??
}
}
}
Чтобы я ещё раз полез помогать инди-разработчикам, мать их за ногу.
−103
if [ "valid" == "$x" ]; then
echo "x has the value 'valid'"
fi
One last point (of style): <...> is better because it avoids the possibility of accidentally assigning the string "valid" to x.
Йода-стайл теперь и в вашем баше.
+134
protected static DataTable[] ExecuteDataTablesReader(string ProcedureName, SqlParameter[] Params = null) {
SqlConnection cnn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand(ProcedureName, cnn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
if (Params != null && Params.Count() > 0) {
cmd.Parameters.AddRange(Params);
}
cnn.Open();
IDataReader rd = cmd.ExecuteReader();
List<DataTable> tables = new List<DataTable>();
do {
DataTable dt = new DataTable();
dt.Load(rd);
tables.Add(dt);
} while (rd.NextResult());
return tables.ToArray();
}
может я чего не понимаю, но какого хера rd.NextResult() кидает мне exception, что ридер закрыт?
+135
public void Login(ClientHandlers<int> actions)
{
var request = GetGetRequest("/user/xml/{0}", _login);
var act = new Action<IRestResponse<GetUserInfoResult>>(response =>
{
if (CheckUserInfo(response))
{
throw new Exception("Невозможно получить информацию о пользователе\r\nНеобработанное исключение");
}
UserInfo = response.Data.UserInfo;
actions.Completed(UserInfo.idUser);
});
_client.ExecuteAsync(request, act);
}
private bool CheckUserInfo(IRestResponse<GetUserInfoResult> response)
{
if (response != null && response.Data != null && response.Data.UserInfo != null && response.Data.UserInfo.idUser != 0)
{
return true;
}
var message = "Невозможно получить информацию о пользователе";
if (response == null)
{
message = string.Format("{0}\r\n{1}",
message,
"Response is null");
throw new Exception(message);
}
message = string.Format("{0}\r\nResponse data is null\r\nContext: {1}",
message,
response.Content);
if (response.Data == null)
{
throw new Exception(message);
}
message = string.Format("{0}\r\nIs exception: {1}\r\nMessage: {2}",
message,
response.Data.IsException,
response.Data.Message);
if (response.Data.UserInfo == null)
{
throw new Exception(message);
}
message = string.Format("{0}\r\nSiteName: {1}\r\nUserName: {2}\r\nUserRole: {3}",
message,
response.Data.UserInfo.SiteName,
response.Data.UserInfo.UserName,
response.Data.UserInfo.UserRole);
if (response.Data.UserInfo.idUser == 0)
{
throw new Exception(message);
}
return false;
}
Внимательность, внимательность и еще раз внимательность...