- 1
- 2
- 3
- 4
- 5
vector<int> res;
...
for (int i = 0; i < res.size(); i++) {
printf("%d%c", res[i], " \n"[i + 1 == res.size()]);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
vector<int> res;
...
for (int i = 0; i < res.size(); i++) {
printf("%d%c", res[i], " \n"[i + 1 == res.size()]);
}
Решил вспомнить как олимпиадные задачки решать.
+2
function main()
{
f1();
}
function f1(a = 10)
{
return a;
}
// code for 1
module @"1.ts" {
func @main() {
%c0_i32 = constant 0 : i32
%0 = typescript.undef : i32
%1 = call @f1(%c0_i32, %0) : (i32, i32) -> i32
return
}
func private @f1(%arg0: i32, %arg1: i32) -> i32 attributes {OptionalFrom = 1 : i8} {
%c10_i32 = constant 10 : i32
%c1_i32 = constant 1 : i32
%0 = alloca() : memref<i32>
%1 = cmpi ult, %arg0, %c1_i32 : i32
%2 = scf.if %1 -> (i32) {
scf.yield %c10_i32 : i32
} else {
scf.yield %arg1 : i32
}
store %2, %0[] : memref<i32>
%3 = load %0[] : memref<i32>
return %3 : i32
}
}
// code for 2
; ModuleID = 'LLVMDialectModule'
source_filename = "LLVMDialectModule"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"
declare i8* @malloc(i64)
declare void @free(i8*)
define void @main() !dbg !3 {
%1 = call i32 @f1(i32 0, i32 undef), !dbg !7
ret void, !dbg !9
}
define i32 @f1(i32 %0, i32 %1) !dbg !10 {
%3 = alloca i32, i64 ptrtoint (i32* getelementptr (i32, i32* null, i64 1) to i64), align 4, !dbg !11
%4 = insertvalue { i32*, i32*, i64 } undef, i32* %3, 0, !dbg !11
%5 = insertvalue { i32*, i32*, i64 } %4, i32* %3, 1, !dbg !11
%6 = insertvalue { i32*, i32*, i64 } %5, i64 0, 2, !dbg !11
%7 = icmp ult i32 %0, 1, !dbg !11
br i1 %7, label %8, label %9, !dbg !11
8: ; preds = %2
br label %10, !dbg !11
9: ; preds = %2
br label %10, !dbg !11
10: ; preds = %8, %9
%11 = phi i32 [ %1, %9 ], [ 10, %8 ]
br label %12, !dbg !11
12: ; preds = %10
%13 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
store i32 %11, i32* %13, align 4, !dbg !11
%14 = extractvalue { i32*, i32*, i64 } %6, 1, !dbg !11
%15 = load i32, i32* %14, align 4, !dbg !11
ret i32 %15, !dbg !13
}
История о том как я компайлер писал. (предисторию знают думаю все). Посмотрите на код и сравните с ужасным кодом на С. Это простенький javascript который тоже може быть скомпиленным в исполняемый год. а что для этого надо. просто несколько шагов.
1) компилим код через чудо компилятор tsc.exe --emit=mlir-affine c:\1.ts
llc.exe --filetype=obj -o=out.o 1.ll0
# ------------------- fUnicodeToUTF8----------------------
:global fUnicodeToUTF8
:if (!any $fUnicodeToUTF8) do={ :global fUnicodeToUTF8 do={
:global fByteToEscapeChar
# :local Ubytes [:tonum $1]
:local Nbyte
:local EscapeStr ""
:if ($1 < 0x80) do={
:set EscapeStr [$fByteToEscapeChar $1]
} else={
:if ($1 < 0x800) do={
:set Nbyte 2
} else={
:if ($1 < 0x10000) do={
:set Nbyte 3
} else={
:if ($1 < 0x20000) do={
:set Nbyte 4
} else={
:if ($1 < 0x4000000) do={
:set Nbyte 5
} else={
:if ($1 < 0x80000000) do={
:set Nbyte 6
}
}
}
}
}
:for i from=2 to=$Nbyte do={
:set EscapeStr ([$fByteToEscapeChar ($1 & 0x3F | 0x80)] . $EscapeStr)
:set $1 ($1 >> 6)
}
:set EscapeStr ([$fByteToEscapeChar (((0xFF00 >> $Nbyte) & 0xFF) | $1)] . $EscapeStr)
}
:return $EscapeStr
}}
угадай язык
+1
void tick(void)
{
for (auto&& x : registry.objects)
(x? std::function<void(void)>([&](void) {((IObject*)(x))->tick(); }) : [&]() {})();
}
Мозг сказал что "((IObject*)(x))->tick();" написать слишком сложно и повелел написать вот это.
+3
function strEqual(string a, string b) private returns (bool) {
return sha3(a) == sha3(b);
}
Как проверить идентичность строк, если ты криптовалютчик?
https://github.com/axic/mango/blob/83ef808eba1571097fecd8d8e08303a82f69d68c/MangoRepo.sol#L83-L85
0
// ==UserScript==
// @name Unnamed Script 230178
// @version 1
// @grant none
// @include https://www.instagram.com/*
// ==/UserScript==
window.addEventListener('load', function(){
console.log("my script starting...");
const body = document.querySelector('body');
const config = {
attributes: true,
attributeFilter: ["style"]
};
const callback = function(mutationsList, observer) {
console.log("mutation aaargh-aaarghrghrhg");
for (let mutation of mutationsList) {
console.log('zaloop');
// if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
try {
body.setAttribute('style', '');
document.querySelector('.RnEpo').setAttribute('style', 'display: none;');
observer.disconnect();
console.log("#hide");
} catch (e) {
console.log(e);
}
// }
}
};
const observer = new MutationObserver(callback);
observer.observe(body, config);
console.log("my script stop");
});
Ночью не спал
Инстаграм листал
Чтобы баннер не мешал
Такой скрипт написал.
+1
<?php
namespace App\Http\Controllers\Admin;
use App\Command\Admin\User\Create\Command as UserCreateCommand;
use App\Command\Admin\User\Update\Command as UserUpdateCommand;
use App\Command\Admin\User\Remove\Command as UserRemoveCommand;
use App\Command\User\Auth\Verify\Command as UserVerifyCommand;
use App\Command\Admin\User\Draft\Command as UserDraftCommand;
use App\Command\CommandBus;
use App\Entity\User\User;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Users\CreateRequest;
use App\Http\Requests\Admin\Users\UpdateRequest;
use App\Query\Admin\User\FindUsersByDescQuery;
use App\Query\Admin\User\Role\GetUserRolesQuery;
use App\Query\Admin\User\Status\GetUserStatusesQuery;
use App\Query\QueryBus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
class UsersController extends Controller
{
private $commandBus;
private $queryBus;
public function __construct(CommandBus $commandBus, QueryBus $queryBus)
{
$this->commandBus = $commandBus;
$this->queryBus = $queryBus;
}
public function index()
{
$query = $this->queryBus->query(new FindUsersByDescQuery());
$users = $query->paginate(20);
$statuses = $this->queryBus->query(new GetUserStatusesQuery());
$roles = $this->queryBus->query(new GetUserRolesQuery());
return view('admin.users.index', compact('users', 'statuses', 'roles'));
}
public function create()
{
return view('admin.users.create');
}
public function store(CreateRequest $request)
{
$this->commandBus->handle(new UserCreateCommand($request));
return redirect()->route('admin.users.index');
}
public function show(User $user)
{
return view('admin.users.show', compact('user'));
}
public function edit(User $user)
{
$roles = $this->queryBus->query(new GetUserRolesQuery());
return view('admin.users.edit', compact('user', 'roles'));
}
public function update(UpdateRequest $request, User $user)
{
$this->commandBus->handle(new UserUpdateCommand($request, $user));
return redirect()->route('admin.users.index');
}
public function destroy(User $user)
{
$this->commandBus->handle(new UserRemoveCommand($user));
return redirect()->route('admin.users.index');
}
public function verify(User $user)
{
$this->commandBus->handle(new UserVerifyCommand($user));
return redirect()->route('admin.users.show', $user);
}
public function draft(User $user)
{
$this->commandBus->handle(new UserDraftCommand($user));
return redirect()->route('admin.users.show', $user);
}
}
−2
#include <stdio.h>
int* laɡ(int memory) {
int* hui = malloc(memory);
if (hui == NULL) {
fprintf(stderr, "malloc failed\n");
}
laɡ(memory);
return hui;
}
int main() {
laɡ(1048576); // any number
return 0;
}
Просто оставлю это здесь
−1
book = open("Kniga_Lolita.txt", "r")
intab = ""
outtab = ""
deltab = '"?.,![]«»:()123456789-;#%'
trantab = str.maketrans(intab, outtab, deltab)
st = book.read()
final = st.translate(trantab)
you = ''
fok = 0
stak = 0
def dekod(kod):
lkod = len(kod)
llkod = lkod
kody = ''
i = 0
if lkod % 3 != 0:
print('Т.к. вы написали слово кол-во символов которого')
print('Дешифратор не сможет понять, последнии символы будут стерты из кода')
print('Впредь будте внимательны, из этого код может расшифроваться неправильно!')
while llkod % 3 != 0:
i += 1
llkod -= 1
kody += kod[0:lkod - i]
print('Чистый код: ')
print(kody)
dekod2(kody)
else:
kody += kod
dekod2(kody)
def dekod2(kody):
i = 0
j = 0
dek = []
lkody = len(kody)
while j != lkody:
j += 3
dek += [kody[i:j]]
i += 3
print('Код разделенный по буквам: ')
print(dek)
dekod3(dek)
def dekod3(dek):
x = 0
for i in range(len(dek)):
for x in permutations(dek[i]):
#print (x)
dekod4(x)
def dekod4 (x):
new = open("prog.txt", "w")
aa = new.write(final)
new.close()
new = open("prog.txt", "r")
st1 = ''
st2 = ''
for num, line in enumerate(new):
if num == int(x[0]):
lis = line.split()
for num1, line1 in enumerate(lis):
if num1 == int(x[1]):
ss = ''
ss = line1
try:
st2 += ss[int(x[2])]
bild(st2)
except IndexError:
return 0
def bild(st2): #000105202 Пример шифра: Лес
global you
global fok
if st2:
if len(st2) == 1:
you += st2
fok += 1
if fok == 13: #Это число 13 просто потому, Если сделать не под магическую цифру, то можно будет испольновать и для 4-х буквенных слов и т.д.
blin(you)
def blin(you):
tt =[]
i = 0
j = 6
c = len(you)
while c > 0:
tt += [[you[i:j]]]
i += 6
j += 6
c -= 6
print('Возможно не работающая лабутень!')
for y in range(len(tt)):
print(tt[y])
print ('За книгу-код взято произведение Владимирa Набоковa - Лолита')
print ('Список операций')
print ('1.Закодировать')
print ('3.Показать текст книги-кода')
print ('4.Показать текст без знаков препинания и других символов')
print ('Введите операцию: ')
Попытка создать (де)кодировщик
Оно не работает
Интерфейс додумайте сами
−1
// Microsoft открыла код Калькулятора Windows
// https://github.com/Microsoft/calculator/blob/057401f5f2b4bb1ea143da02c773ac18d1bb9a2e/src/CalcViewModel/Common/CalculatorButtonUser.h#L8
namespace CalculatorApp
{
namespace CM = CalculationManager;
public enum class NumbersAndOperatorsEnum
{
Zero = (int) CM::Command::Command0,
One = (int) CM::Command::Command1,
Two = (int) CM::Command::Command2,
Three = (int) CM::Command::Command3,
Four = (int) CM::Command::Command4,
Five = (int) CM::Command::Command5,
Six = (int) CM::Command::Command6,
Seven = (int) CM::Command::Command7,
Eight = (int) CM::Command::Command8,
Nine = (int) CM::Command::Command9,
Add = (int) CM::Command::CommandADD,
Subtract = (int) CM::Command::CommandSUB,
Multiply = (int) CM::Command::CommandMUL,
Divide = (int) CM::Command::CommandDIV,
Invert = (int) CM::Command::CommandREC,
Equals = (int) CM::Command::CommandEQU,
Decimal = (int) CM::Command::CommandPNT,
Sqrt = (int) CM::Command::CommandSQRT,
Percent = (int) CM::Command::CommandPERCENT,
Negate = (int) CM::Command::CommandSIGN,
Backspace = (int) CM::Command::CommandBACK,
ClearEntry = (int) CM::Command::CommandCENTR,
Clear = (int) CM::Command::CommandCLEAR,
Degree = (int) CM::Command::CommandDEG,
Radians = (int) CM::Command::CommandRAD,
Grads = (int) CM::Command::CommandGRAD,
Degrees = (int) CM::Command::CommandDegrees,
OpenParenthesis = (int) CM::Command::CommandOPENP,
CloseParenthesis = (int) CM::Command::CommandCLOSEP,
Pi = (int) CM::Command::CommandPI,
Sin = (int) CM::Command::CommandSIN,
Cos = (int) CM::Command::CommandCOS,
Tan = (int) CM::Command::CommandTAN,
Factorial = (int) CM::Command::CommandFAC,
XPower2 = (int) CM::Command::CommandSQR,
Mod = (int) CM::Command::CommandMOD,
FToE = (int) CM::Command::CommandFE,
LogBaseE = (int) CM::Command::CommandLN,
InvSin = (int) CM::Command::CommandASIN,
InvCos = (int) CM::Command::CommandACOS,
InvTan = (int) CM::Command::CommandATAN,
LogBase10 = (int) CM::Command::CommandLOG,
XPowerY = (int) CM::Command::CommandPWR,
YRootX = (int) CM::Command::CommandROOT,
TenPowerX = (int) CM::Command::CommandPOW10,
EPowerX = (int) CM::Command::CommandPOWE,
Exp = (int) CM::Command::CommandEXP,
IsScientificMode = (int) CM::Command::ModeScientific,
IsStandardMode = (int) CM::Command::ModeBasic,
None = (int) CM::Command::CommandNULL,
IsProgrammerMode = (int) CM::Command::ModeProgrammer,
DecButton = (int) CM::Command::CommandDec,
OctButton = (int) CM::Command::CommandOct,
HexButton = (int) CM::Command::CommandHex,
BinButton = (int) CM::Command::CommandBin,
And = (int) CM::Command::CommandAnd,
Ror = (int) CM::Command::CommandROR,
Rol = (int) CM::Command::CommandROL,
Or = (int) CM::Command::CommandOR,
Lsh = (int) CM::Command::CommandLSHF,
Rsh = (int) CM::Command::CommandRSHF,
Xor = (int) CM::Command::CommandXor,
Not = (int) CM::Command::CommandNot,
A = (int) CM::Command::CommandA,
B = (int) CM::Command::CommandB,
C = (int) CM::Command::CommandC,
D = (int) CM::Command::CommandD,
E = (int) CM::Command::CommandE,
F = (int) CM::Command::CommandF,
Memory, // This is the memory button. Doesn't have a direct mapping to the CalcEngine.
Sinh = (int) CM::Command::CommandSINH,
Cosh = (int) CM::Command::CommandCOSH,
Tanh = (int) CM::Command::CommandTANH,
InvSinh = (int) CM::Command::CommandASINH,
InvCosh = (int) CM::Command::CommandACOSH,
InvTanh = (int) CM::Command::CommandATANH,
Qword = (int) CM::Command::CommandQword,
Dword = (int) CM::Command::CommandDword,
Word = (int) CM::Command::CommandWord,
Byte = (int) CM::Command::CommandByte,
Cube = (int) CM::Command::CommandCUB,
DMS = (int) CM::Command::CommandDMS,
BINSTART = (int) CM::Command::CommandBINEDITSTART,
BINPOS0 = (int) CM::Command::CommandBINPOS0,
BINPOS1 = (int) CM::Command::CommandBINPOS1,
BINPOS2 = (int) CM::Command::CommandBINPOS2,
BINPOS3 = (int) CM::Command::CommandBINPOS3,
BINPOS4 = (int) CM::Command::CommandBINPOS4,
BINPOS5 = (int) CM::Command::CommandBINPOS5,
Интересно, а эту херню кодогенерировали? Или это всё ручной труд?