- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
#define as ;while
int main(int argc, char* argv[])
{
int n = atoi(argv[1]);
do printf("n is %d\n", n) as ( n --> 0);
return 0;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
#define as ;while
int main(int argc, char* argv[])
{
int n = atoi(argv[1]);
do printf("n is %d\n", n) as ( n --> 0);
return 0;
}
0
class Foo {
std::atomic<bool> a{false};
std::atomic<bool> b{false};
public:
Foo()
{
}
void first(function<void()> printFirst) {
printFirst();
a.store(true, std::memory_order_release);
}
void second(function<void()> printSecond) {
while (!a.load(std::memory_order_acquire))
;
printSecond();
b.store(true, std::memory_order_release);
}
void third(function<void()> printThird) {
while (!b.load(std::memory_order_acquire))
;
printThird();
}
};
https://leetcode.com/problems/print-in-order/
36 / 36 test cases passed.
Runtime: 1697 ms
Memory Usage: 7 MB
Хочу, чтобы начался срач по поводу того, как достичь рантайма в 200мс
0
.org 80h
fib:
push %b
push %d
push %c
mov %d [%sp + 8h]
mov %b 1h
mov %a 0h
.loop:
add %b %a
mov %c %a
mov %a %b
sub %a %c
dec %d
jnz @.loop
pop %c
pop %d
pop %b
ret
start:
mov %sp 2000h
push Fh
call @fib
pop
int 0h
один чел захотел написать для моей вмки компилятор лиспоподобного языка с некими S-выражениями и попросил пример вычисления ряда фибоначчи.
пришлось накопипастить с вики.
0
Be gone, malicious spirit from the anus!
We don't say "amen", because we may step on the mines; we say "True"!
Херня рулит.
+1
$bIsExpressDelivery = !empty($arDeliveryTariff["UF_EXPRESS_DELIVERY"]) ? true : false;
Чтобы наверняка true или наверняка false...
0
/**
* Возвращает сумму прописью
* @param $num
* @return string
*/
public static function num2str($num) {
$nul='ноль';
$ten=[
['','один','два','три','четыре','пять','шесть','семь', 'восемь','девять'],
['','одна','две','три','четыре','пять','шесть','семь', 'восемь','девять'],
];
$a20=['десять','одиннадцать','двенадцать','тринадцать','четырнадцать' ,'пятнадцать','шестнадцать','семнадцать','восемнадцать','девятнадцать'];
$tens=[2=>'двадцать','тридцать','сорок','пятьдесят','шестьдесят','семьдесят' ,'восемьдесят','девяносто'];
$hundred=['','сто','двести','триста','четыреста','пятьсот','шестьсот', 'семьсот','восемьсот','девятьсот'];
$unit=[ // Units
['копейка' ,'копейки' ,'копеек', 1],
['рубль' ,'рубля' ,'рублей' ,0],
['тысяча' ,'тысячи' ,'тысяч' ,1],
['миллион' ,'миллиона','миллионов' ,0],
['миллиард','милиарда','миллиардов',0],
];
//
list($rub,$kop) = explode('.',sprintf("%015.2f", floatval($num)));
$out = [];
if (intval($rub)>0) {
foreach(str_split($rub,3) as $uk=>$v) { // by 3 symbols
if (!intval($v)) continue;
$uk = sizeof($unit)-$uk-1; // unit key
$gender = $unit[$uk][3];
list($i1,$i2,$i3) = array_map('intval',str_split($v,1));
// mega-logic
$out[] = $hundred[$i1]; # 1xx-9xx
if ($i2>1) $out[]= $tens[$i2].' '.$ten[$gender][$i3]; # 20-99
else $out[]= $i2>0 ? $a20[$i3] : $ten[$gender][$i3]; # 10-19 | 1-9
// units without rub & kop
if ($uk>1) $out[]= self::morph($v,$unit[$uk][0],$unit[$uk][1],$unit[$uk][2]);
} //foreach
}
else $out[] = $nul;
$out[] = self::morph(intval($rub), $unit[1][0],$unit[1][1],$unit[1][2]); // rub
$out[] = $kop.' '.self::morph($kop,$unit[0][0],$unit[0][1],$unit[0][2]); // kop
return trim(preg_replace('/ {2,}/', ' ', join(' ',$out)));
}
Один большой проект...
−1
type int = 1;
type int64 = 4294967296;
declare function GC_get_heap_size(): int64;
function main() {
let i = 0;
for (i = 0; i < 10000000; ++i) {
const p = new int[1];
if (i % 100000 == 0) print("Heap size = ", GC_get_heap_size());
}
}
вот такая лабуда подкатили.. называется GC.. для тех кто не любит GC я добавил опцию -nogc :)
вот так можно JIT запускать без компиляции
tsc.exe --emit=jit --shared-libs=TypeScriptGCWrapper.dll 1.ts
tsc.exe --emit=jit -nogc 1.ts
+2
wrapOnException(() -> file.writeTo(env.getFiler()));
https://www.youtube.com/watch?v=nCkpzqqog4k
+3
do {
$entries = $xpath->query("//div[@class='identity']/img");
if(isset($entries[0])) break;
$entries = $xpath->query("//h1[@class='avatared']/a/img");
if(isset($entries[0])) break;
$entries = $xpath->query("//div[@class='avatared']/a/img");
if(isset($entries[0])) break;
$entries = $xpath->query("//div[@itemtype='http://schema.org/Person']/a/img");
} while(false);
if(!isset($entries[0])) continue;
$src = $entries[0]->getAttribute('src');
if(!preg_match('#[/=]([0-9a-f]{32})[\?&]#', $src, $matches)) continue;
$hash = $matches[1];
// спустя несколько строк
do {
$entries = $xpath->query("//div[@class='email']/script");
if(isset($entries[0])) break;
$entries = $xpath->query("//dl/dd[@class='email']/script");
} while(false);
if(isset($entries[0])) {
$rawcode = $entries[0]->textContent;
if(!preg_match("#eval\(decodeURIComponent\('(.*)'\)\)#", $rawcode, $matches)) continue;
$rawcode2 = urldecode($matches[1]);
if(!preg_match('#href=\\\\?"mailto:([^"\\\\]*)\\\\?"#', $rawcode2, $matches)) continue;
$email = $matches[1];
unset($entries);
} else do {
$entries = $xpath->query("//div[@class='avatared']/div[@class='details']/dl/dd/a[@data-email]");
if(isset($entries[0])) break;
$entries = $xpath->query("//ul[@class='vcard-details']/li[@class='vcard-detail']/a[@data-email]");
} while(false);
if(isset($entries[0])) {
$email = urldecode($entries[0]->getAttribute('data-email'));
}
Прототип программы, вытягивающей хэш аватарки и е-мейл из архивной копии профиля в «Гитхабе».
0
С Днём Победы!
rJlaBHblu_nemyx