- 1
- 2
- 3
- 4
- 5
- 6
- 7
return coroutine.create(function(x)
while true do
socket.sleep(1);
collectgarbage()
coroutine.yield()
end
end)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−2
return coroutine.create(function(x)
while true do
socket.sleep(1);
collectgarbage()
coroutine.yield()
end
end)
Выделил сборщик мусора в отдельный поток, и чтоб он вечно собирал за мной всякую срань, но раз в секунду.
Ожидание: Поток спит в течении 1 секунды.
Реальность: Вся программа спит в течении 1 секунды.
−4
stack = []
def stdout(x):
if x == "puts":
print(stack.pop())
else:
raise Exception("иди нахуй")
def stdin(x):
global stack
if x == "gets":
stack.append(input())
else:
raise Exception("иди нахуй")
math = {
"add": lambda: stack.append(float(stack.pop()) + float(stack.pop())),
"sub": lambda: stack.append((-float(stack.pop())) + float(stack.pop())),
"mul": lambda: stack.append(float(stack.pop()) * float(stack.pop())),
"div": lambda: stack.append(1 / float(stack.pop()) * float(stack.pop())),
}
def stack_commands(x):
global stack
if x == "swap":
stack[-1], stack[-2] = stack[-2:]
elif x == "drop":
stack.pop()
elif x == "dup":
stack.append(stack[-1])
else:
raise Exception("иди нахуй")
string = {
"concat": lambda: stack.append(str(stack.pop()) + str(stack.pop()))
}
commands = {
"comment": lambda x: x,
"push": lambda x: stack.append(x),
"stdout": stdout,
"stdin": stdin,
"math": lambda x: print(math[x]()),
"stack": stack_commands,
"string": lambda x: string[x]()
}
def do(x):
if '@' not in x:
raise Exception(x + " is not email.")
a, b = x.split('@')
b = b.split('.')[0]
commands[b](a)
def eval(s):
for i in s.lower().split():
do(i)
eval("""
[email protected]
[email protected] [email protected]
[email protected]
[email protected] [email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected] [email protected] [email protected]
""")
−4
https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsaasyncselect
int WSAAsyncSelect(
SOCKET s,
HWND hWnd,
u_int wMsg,
long lEvent
);
/*
hWnd
A handle that identifies the window that will receive a message when a network event occurs.
*/
Почему виндовые асинхронные (или правильно говорить "небликирующиеся") сокеты так черезжопно сделаны? Нафига им через HWND надо месседжи слать? Что, другого способа нет для оповещений?
Требовать для работы асинхронных сокетов чтоб какое-то окно было это как требовать зубную щетку для входа в туалет чтоб посрать
−1
#!/l_l5l2/8IN/l>Y7l-lON3
IMl>Ol27 5Y5
41l>l-l4 = {
'4': '4',
'8': '8',
'(': '(',
')': ')',
'3': '3',
'#': '#',
'9': '9',
'l-l': '1-1',
'1': '1',
'_l': '_1',
'l<': '1<',
'l>': '1>',
'&': '&',
'l2': '12',
'5': '5',
'7': '7',
'l_l': '1_1',
'\/': '\/',
'\/\/': '\/\/',
'><': '><',
'Y': 'Y',
'2': '2'
}
I# 13N(5Y5.4l29\/) > 1:
# = Ol>3N(5Y5.4l29\/[1])
3153:
# = 5Y5.57)IN
8l_l##3l2 = []
#Ol2 ( IN #.l234)().l_ll>l>3l2():
8l_l##3l2.4l>l>3N)(41l>l-l4[(] I# ( IN 41l>l-l4 3153 ()
l>l2IN7(''._lOIN(8l_l##3l2))
+1
class TaxStorage {
public:
using TaxCode = Code<3>; // Code<int N, typename Storage = uint32_t> тип для маленьких строк
using TaxType = Code<3>;
using TaxId = std::tuple<TaxCode, TaxType>;
using TaxMap = std::map<TaxId, int>
using CityId = int;
using TaxPointMap = std::unordered_map<CityId, TaxMap>;
TaxMap forCityOrOther(const TaxPointMap& map, const CityId cityId) const {
const auto found = map.find(cityId);
return found == map.cend() ? map.at(OTHER_CITY) : *found; // должно быть found->second
}
}
Dev: Ok GCC, tell me what is wrong.
GCC: /home/whatever/project/TaxStorage.h:102: error: incompatible operand types ('const std::unordered_map<int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > > > >::mapped_type' (aka 'const std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > >') and 'const std::pair<const int, std::map<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> >, std::less<std::tuple<Code<3, unsigned int>, Code<3, unsigned int> > >, std::allocator<std::pair<const std::tuple<Code<3, unsigned int>, Code<3, unsigned int> >, std::vector<unsigned long, std::allocator<unsigned long> > > > > >')
ДОКОЛЕ?!!
−1
$query = "SELECT * FROM archivo_mhora WHERE id_aparato=" . $aparatos_row->id;
$query .= " && DATE_FORMAT(fecha, '%Y.%m.%d')='" . date('Y.m.d', $cur_fecha) . "' ORDER BY energy";
Я не знаю, к какой секции следует отнести этот высер:
1) Автор решил учить испанский. Таблицы имеют имена `aparatos`, `abonandos`, etc
2) Само собой, SQL injection
3) Порнография при работе с датой
−1
def $qmark = 1
def ? = 1
// Error:(2, 6) method ? is defined twice
Scala-way
0
<!-- todo: put this in a different file!!! -->
<script>
function authenticateUser(username, password) {
var accounts = apiService.sql(
"SELECT * FROM users"
);
for (var i = 0; i < accounts.length; i++) {
var account = accounts[i];
if (account.username === username &&
account.password === password)
{
return true;
}
}
if ("true" === "true") {
return false;
}
}
$('#login').click(function() {
var username = $("#username").val();
var password = $("#password").val();
var authenticated = authenticateUser(username, password);
if (authenticated === true) {
$.cookie('loggedin', 'yes', { expires: 1});
} else if (authenticated === false) {
$("#error_message").show();
}
});
</script>
This JavaScript code powers a 1,500 user intranet application
−2
private static function preparePostProperty(&$data, $propName = [], $type = 'float'){
if(!in_array($type, ['float', 'integer', 'string']))
return;
if(is_array($data) && !empty($propName)){
$key = '$data["' . implode('"]["', $propName) . '"]';
@eval("if(isset($key)) $key = ($type)$key;");
}
}
public static function preparePost($data, $documentsObjects = []){
if(is_array($data)){
self::preparePostProperty($data, ['general', 'fromMtender', 'lotDetails', 'lotAmount']);
self::preparePostProperty($data, ['general', 'additionalData', 'budgetDetails', 'amountBrutto']);
self::preparePostProperty($data, ['general', 'additionalData', 'budgetDetails', 'amountNetto']);
self::preparePostProperty($data, ['general', 'additionalData', 'budgetDetails', 'amountPrepayment']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'amountGuarantee']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'amountGE']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'amountWithdraw']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'amountMaxWithdraw']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'transferDuration']);
self::preparePostProperty($data, ['general', 'additionalData', 'bankGuarantee', 'nonPaymentMax']);
self::preparePostProperty($data, ['general', 'additionalData', 'executionShouldStart']);
self::preparePostProperty($data, ['general', 'additionalData', 'executionDuration']);
foreach ($data['subject'] as $k => $subjects){
//data[subject][0][fromMtender][itemQuantity]
self::preparePostProperty($data, ['subject', $k, 'fromMtender', 'itemQuantity']);
self::preparePostProperty($data, ['subject', $k, 'additionalData', 'itemDetails', 'itemPrice', 'unitPrice', 'withoutVAT']);
self::preparePostProperty($data, ['subject', $k, 'additionalData', 'itemDetails', 'itemPrice', 'unitPrice', 'withVAT']);
self::preparePostProperty($data, ['subject', $k, 'additionalData', 'itemDetails', 'itemPrice', 'amountPrice', 'withoutVAT']);
self::preparePostProperty($data, ['subject', $k, 'additionalData', 'itemDetails', 'itemPrice', 'amountPrice', 'withVAT']);
foreach ($subjects['additionalData']['budget'] as $kb => $budgets){
self::preparePostProperty($data, ['subject', $k, 'additionalData', 'budget', $kb, 'budgetAmount']);
}
}
self::preparePostProperty($data, ['ca', 'additionalData', 'caPerson', 'caPersonCode']);
self::preparePostProperty($data, ['eo', 'fromMtender', 'eoCode']);
self::preparePostProperty($data, ['eo', 'additionalData', 'eoLicenses', 'eoValidityDuration']);
self::preparePostProperty($data, ['eo', 'additionalData', 'eoPerson', 'eoPersonCode']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'deliveryDelayLiability', 'liabilityPercent']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'deliveryDelayLiability', 'liabilityPercentMax']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'paymentDelayLiability', 'liabilityPercent']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'paymentDelayLiability', 'liabilityPercentMax']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'maxPenalty']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'maxDelay']);
self::preparePostProperty($data, ['otherConditions', 'sla', 'warrantyPeriod']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'informOnSigned']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'informOnFM']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'informOnTermination']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'respondOnTermination']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'submitClaimsMax']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'respondClaimsMax']);
self::preparePostProperty($data, ['otherConditions', 'timeline', 'deliverOnClaims']);
}
self::appendPostDocuments($data, $documentsObjects);
return $data;
}
ЧТОЕТА?
−1
public Pattern waitNotEmptyRegex(){
String read;
Pattern pattern;
while (true) {
try {
try {
read = in.readLine();
if (!read.trim().isEmpty()) {
pattern = Pattern.compile(read);
} else {
context.getOut().write(context.localizKey("console.messages.emptyString") + "\n");
}
} catch (PatternSyntaxException e) {
context.getOut().write(context.localizKey("console.messages.invalidPattern") + "\n");
}
}catch (IOException e){
throw new IllegalStateException(e);
}
}
}
Боооольше вложенных блоков