- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
type a = 1;
type i = a & a;
type j = a | a;
function main() {
let v1: i;
let v2: j;
assert(sizeof(i) != sizeof(j));
print("done.");
}
ну все я понял вам скучно... как насчет такого примера?
+6
Раскрытие покровов. Настя, облачные технологии и Настенька.
−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
+1
fn main() {
println!("Hello World!");
}
rustc --version --verbose:
rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: powerpc-unknown-linux-gnu
release: 1.52.1
LLVM version: 12.0.0
Error output
rustc ./hello.rs
Illegal instruction (core dumped)
https://github.com/rust-lang/rust/issues/85238
Open: clienthax opened this issue on May 12 · 6 comments
0
//Let me introduce you, to the most stupidly long and complicated solution!.
using System.Linq;
public class TwoToOne
{
static string final;
public static string Longest (string s1, string s2)
{
final = "";
if (s1.ToLower().Contains("a")){final += "a";}
else if (s2.ToLower().Contains("a")){final += "a";}
if (s1.ToLower().Contains("b")){final += "b";}
else if (s2.ToLower().Contains("b")){final += "b";}
if (s1.ToLower().Contains("c")){final += "c";}
else if (s2.ToLower().Contains("c")){final += "c";}
if (s1.ToLower().Contains("d")){final += "d";}
else if (s2.ToLower().Contains("d")){final += "d";}
if (s1.ToLower().Contains("e")){final += "e";}
else if (s2.ToLower().Contains("e")){final += "e";}
if (s1.ToLower().Contains("f")){final += "f";}
else if (s2.ToLower().Contains("f")){final += "f";}
if (s1.ToLower().Contains("g")){final += "g";}
else if (s2.ToLower().Contains("g")){final += "g";}
if (s1.ToLower().Contains("h")){final += "h";}
else if (s2.ToLower().Contains("h")){final += "h";}
if (s1.ToLower().Contains("i")){final += "i";}
else if (s2.ToLower().Contains("i")){final += "i";}
if (s1.ToLower().Contains("j")){final += "j";}
else if (s2.ToLower().Contains("j")){final += "j";}
if (s1.ToLower().Contains("k")){final += "k";}
else if (s2.ToLower().Contains("k")){final += "k";}
if (s1.ToLower().Contains("l")){final += "l";}
else if (s2.ToLower().Contains("l")){final += "l";}
if (s1.ToLower().Contains("m")){final += "m";}
else if (s2.ToLower().Contains("m")){final += "m";}
if (s1.ToLower().Contains("n")){final += "n";}
else if (s2.ToLower().Contains("n")){final += "n";}
if (s1.ToLower().Contains("o")){final += "o";}
else if (s2.ToLower().Contains("o")){final += "o";}
if (s1.ToLower().Contains("p")){final += "p";}
else if (s2.ToLower().Contains("p")){final += "p";}
if (s1.ToLower().Contains("q")){final += "q";}
else if (s2.ToLower().Contains("q")){final += "q";}
if (s1.ToLower().Contains("r")){final += "r";}
else if (s2.ToLower().Contains("r")){final += "r";}
if (s1.ToLower().Contains("s")){final += "s";}
else if (s2.ToLower().Contains("s")){final += "s";}
if (s1.ToLower().Contains("t")){final += "t";}
else if (s2.ToLower().Contains("t")){final += "t";}
if (s1.ToLower().Contains("u")){final += "u";}
else if (s2.ToLower().Contains("u")){final += "u";}
if (s1.ToLower().Contains("v")){final += "v";}
else if (s2.ToLower().Contains("v")){final += "v";}
if (s1.ToLower().Contains("w")){final += "w";}
else if (s2.ToLower().Contains("w")){final += "w";}
if (s1.ToLower().Contains("x")){final += "x";}
else if (s2.ToLower().Contains("x")){final += "x";}
if (s1.ToLower().Contains("y")){final += "y";}
else if (s2.ToLower().Contains("y")){final += "y";}
if (s1.ToLower().Contains("z")){final += "z";}
else if (s2.ToLower().Contains("z")){final += "z";}
return final;
}
}
https://www.codewars.com/kata/reviews/5656b9ee8e40eb0a4a000005/groups/5895b9cc4839ff4573001512
Если бы платили за количество, а не качество..
+2
if($account['lvl']=="1"){ $exp=round($account['exp']*100/52);}
if($account['lvl']=="2"){ $exp=round((($account['exp']-52)/(110))*100,2);}
if($account['lvl']=="3"){ $exp=round((($account['exp']-135)/(832-135))*100,2);}
if($account['lvl']=="4"){ $exp=round((($account['exp']-832)/(3547-832))*100,2);}
if($account['lvl']=="5"){ $exp=round((($account['exp']-3547)/(9658-3547))*100,2);}
if($account['lvl']=="6"){ $exp=round((($account['exp']-9658)/(15478-9658))*100,2);}
if($account['lvl']=="7"){ $exp=round((($account['exp']-15478)/(18478-15478))*100,2);}
if($account['lvl']=="8"){ $exp=round((($account['exp']-18478)/(30789-18478))*100,2);}
if($account['lvl']=="9"){ $exp=round((($account['exp']-30789)/(72394-30789))*100,2);}
if($account['lvl']=="10"){ $exp=round((($account['exp']-72394)/(138789-72394))*100,2);}
if($account['lvl']=="11"){ $exp=round((($account['exp']-138789)/(214787-138789))*100,2);}
if($account['lvl']=="12"){ $exp=round((($account['exp']-214787)/(398747-214787))*100,2);}
if($account['lvl']=="13"){ $exp=round((($account['exp']-398747)/(587058-398747))*100,2);}
if($account['lvl']=="14"){ $exp=round((($account['exp']-587058)/(824585-587058))*100,2);}
if($account['lvl']=="15"){ $exp=round((($account['exp']-824585)/(1247858-824585))*100,2);}
if($account['lvl']=="16"){ $exp=round((($account['exp']-1247858)/(1558789-1247858))*100,2);}
if($account['lvl']=="17"){ $exp=round((($account['exp']-1558789)/(1985478-1558789))*100,2);}
if($account['lvl']=="18"){ $exp=round((($account['exp']-1985478)/(2245857-1985478))*100,2);}
if($account['lvl']=="19"){ $exp=round((($account['exp']-2245857)/(2785896-2245857))*100,2);}
if($account['lvl']=="20"){ $exp=round((($account['exp']-2785896)/(3685478-2785896))*100,2);}
if($account['lvl']=="21"){ $exp=round((($account['exp']-3685478)/(4169875-3685478))*100,2);}
if($account['lvl']=="22"){ $exp=round((($account['exp']-4169875)/(5125478-4169875))*100,2);}
if($account['lvl']=="23"){ $exp=round((($account['exp']-5125478)/(5999999-5125478))*100,2);}
if($account['lvl']=="24"){ $exp=round((($account['exp']-5999999)/(7145877-5999999))*100,2);}
if($account['lvl']=="25"){ $exp=round((($account['exp']-7145877)/(8791755-7145877))*100,2);}
if($account['lvl']=="26"){ $exp=round((($account['exp']-8791755)/(10691755-8791755))*100,2);}
if($account['lvl']=="27"){ $exp=round((($account['exp']-10691755)/(12791755-10691755))*100,2);}
if($account['lvl']=="28"){ $exp=round((($account['exp']-12791755)/(15191755-12791755))*100,2);}
if($account['lvl']=="29"){ $exp=round((($account['exp']-15191755)/(18091755-15191755))*100,2);}
if($account['lvl']=="30"){ $exp=round((($account['exp']-18091755)/(21191755-18091755))*100,2);}
if($account['lvl']=="31"){ $exp=round((($account['exp']-21191755)/(24491755-21191755))*100,2);}
if($account['lvl']=="32"){ $exp=round((($account['exp']-24491755)/(27991755-24491755))*100,2);}
if($account['lvl']=="33"){ $exp=round((($account['exp']-27991755)/(31691755-27991755))*100,2);}
if($account['lvl']=="34"){ $exp=round((($account['exp']-31691755)/(35791755-31691755))*100,2);}
if($account['lvl']=="35"){ $exp=round((($account['exp']-35791755)/(40391755-35791755))*100,2);}
if($account['lvl']=="36"){ $exp=round((($account['exp']-40391755)/(45591755-40391755))*100,2);}
if($account['lvl']=="37"){ $exp=round((($account['exp']-45591755)/(51491755-45591755))*100,2);}
if($account['lvl']=="38"){ $exp=round((($account['exp']-51491755)/(58191755-51491755))*100,2);}
if($account['lvl']=="39"){ $exp=round((($account['exp']-58191755)/(65791755-58191755))*100,2);}
if($account['lvl']=="40"){ $exp=round((($account['exp']-65791755)/(74391755-65791755))*100,2);}
if($account['lvl']=="41"){ $exp=round((($account['exp']-74391755)/(83991755-74391755))*100,2);}
if($account['lvl']=="42"){ $exp=round((($account['exp']-83991755)/(94591755-83991755))*100,2);}
if($account['lvl']=="43"){ $exp=round((($account['exp']-94591755)/(106191755-94591755))*100,2);}
if($account['lvl']=="44"){ $exp=round((($account['exp']-106191755)/(118791755-106191755))*100,2);}
if($account['lvl']=="45"){ $exp=round((($account['exp']-118791755)/(132391755-118791755))*100,2);}
if($account['lvl']=="46"){ $exp=round((($account['exp']-132391755)/(146991755-132391755))*100,2);}
if($account['lvl']=="47"){ $exp=round((($account['exp']-146991755)/(162591755-146991755))*100,2);}
if($account['lvl']=="48"){ $exp=round((($account['exp']-162591755)/(179191755-162591755))*100,2);}
if($account['lvl']=="49"){ $exp=round((($account['exp']-179191755)/(196791755-179191755))*100,2);}
if($account['lvl']=="50"){ $exp=round((($account['exp']-196791755)/(215391755-196791755))*100,2);}
Расчет % заполнения шкалы уровня в зависимости от опыта
0
function main() {
const o = {
v: "Hi",
toString() {
return this.v;
},
};
print(o);
}
Хочу напомнить о себе, а то люди начали забывать :)...
+2
wrapOnException(() -> file.writeTo(env.getFiler()));
https://www.youtube.com/watch?v=nCkpzqqog4k
+5
// And then I replaced the idiomatic Rust code for working with block like
for (dline, (sline0, sline1)) in dst.chunks_mut(dstride).zip(tmp.chunks(TMP_BUF_STRIDE).zip(tmp2.chunks(TMP_BUF_STRIDE))).take(h) {
for (pix, (&a, &b)) in dline.iter_mut().zip(sline0.iter().zip(sline1.iter())).take(w) {
*pix = ((u16::from(a) + u16::from(b) + 1) >> 1) as u8;
}
}
// with raw pointers:
unsafe {
let mut src1 = tmp.as_ptr();
let mut src2 = tmp2.as_ptr();
let mut dst = dst.as_mut_ptr();
for _ in 0..h {
for x in 0..w {
let a = *src1.add(x);
let b = *src2.add(x);
*dst.add(x) = ((u16::from(a) + u16::from(b) + 1) >> 1) as u8;
}
dst = dst.add(dstride);
src1 = src1.add(TMP_BUF_STRIDE);
src2 = src2.add(TMP_BUF_STRIDE);
}
}
What do you know, the total decoding time for the test clip I used shrank from 6.6 seconds to 4.9 seconds. That’s just three quarters of the original time!
And here is the problem. In theory if Rust compiler knew that the input satisfies certain parameters i.e. that there’s always enough data
to perform full block operation in this case, it would be able to optimise code as good as the one I wrote using pointers or even better.
But unfortunately there is no way to tell the compiler that input slices are large enough to perform the operation required amount of times.
Even if I added mathematically correct check in the beginning it would not eliminate most of the checks.
https://codecs.multimedia.cx/2021/05/missing-optimisation-opportunity-in-rust/
+7
console.log(parseInt(0.5)); // 0
console.log(parseInt(0.05)); // 0
console.log(parseInt(0.005)); // 0
console.log(parseInt(0.0005)); // 0
console.log(parseInt(0.00005)); // 0
console.log(parseInt(0.000005)); // 0
console.log(parseInt(0.0000005)); // 5
https://ideone.com/YMWUGq
Возможно баян, спижжено с https://vk.com/wall-72495085_1267978