- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
// HTML:
// <input type="hidden" name="comm_validation" value="true" tabindex="3" />
// wp-comments-post.php
if ($_POST['comm_validation'] != 'true')
{
exit();
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+164.6
// HTML:
// <input type="hidden" name="comm_validation" value="true" tabindex="3" />
// wp-comments-post.php
if ($_POST['comm_validation'] != 'true')
{
exit();
}
Эффективная защита от спама без помощи плагинов. Нашел в каментах http://nutwin.net.ru/effektivnaya-zashhita-ot-spama-bez-plaginov/
+93.9
if (cmd[1] == RESET) // если принятая команда RESET
{((void(*)(void))0)();} // что-то из черной магии
Сломай себе голову!!!!
друг прислал, незнаю где накопал, но выглядит круто!
+61.1
void funcMir()
{
...
if ( __mir0>5 )
goto vihod;
TMir1 __mir1; // Конструктор не вызывается. (Оператор goto перескакивает через него.)
...
vihod:
...
// Здесь вызывается деструктор для __mir1 при выходе __mir1 из области видимости.
};
Код оригинальный из инета. Комментарии добавил мой друг.
+1122.2
int SUM(int A, int B)
{
if (0 == A) return B;
if (0 == B) return A;
return (1 + (SUM(A, B - 1) + SUM(A - 1, B)) / 2);
}
рекурсивное вычисление суммы двух чисел.
0
// https://github.com/santiontanon/stransball2/blob/dff413c6ed236b4be23e0152557a26d7d902976c/sources/state_changepack.cpp#L67
bool state_changepack_cycle(SDL_Surface *screen,int sx,int sy,unsigned char *keyboard)
{
if (SUBSTATE==0) {
if (image!=0) SDL_FreeSurface(image);
image=IMG_Load("graphics/tittle.pcx");
{
levelpacks.Delete();
#ifdef _WIN32
/* Find files: */
WIN32_FIND_DATA finfo;
HANDLE h;
h=FindFirstFile("maps/*.lp",&finfo);
if (h!=INVALID_HANDLE_VALUE) {
char *tmp;
tmp=new char[strlen(finfo.cFileName)+1];
strcpy(tmp,finfo.cFileName);
levelpacks.Add(tmp);
while(FindNextFile(h,&finfo)==TRUE) {
char *tmp;
tmp=new char[strlen(finfo.cFileName)+1];
strcpy(tmp,finfo.cFileName);
levelpacks.Add(tmp);
} /* while */
} /* if */
#else
DIR *dp;
struct dirent *ep;
dp = opendir ("maps");
if (dp != NULL)
{
while (ep = readdir (dp))
{
char *tmp;
if (strlen(ep->d_name)>4 &&
ep->d_name[strlen(ep->d_name)-3]=='.' &&
ep->d_name[strlen(ep->d_name)-2]=='l' &&
ep->d_name[strlen(ep->d_name)-1]=='p') {
tmp=new char[strlen(ep->d_name)+1];
strcpy(tmp,ep->d_name);
levelpacks.Add(tmp);
} /* if */
}
(void) closedir (dp);
}
#endif
Super Transball 2 (супер трансшары 2)
+1
// @param n `0 <= n`
// @param m `1 <= m`
// @return `(x ** n) % m`
constexpr long long pow_mod_constexpr(long long x, long long n, int m) {
if (m == 1) return 0;
unsigned int _m = (unsigned int)(m);
unsigned long long r = 1;
unsigned long long y = safe_mod(x, m);
while (n) {
if (n & 1) r = (r * y) % _m;
y = (y * y) % _m;
n >>= 1;
}
return r;
}
// Reference:
// M. Forisek and J. Jancina,
// Fast Primality Testing for Integers That Fit into a Machine Word
// @param n `0 <= n`
constexpr bool is_prime_constexpr(int n) {
if (n <= 1) return false;
if (n == 2 || n == 7 || n == 61) return true;
if (n % 2 == 0) return false;
long long d = n - 1;
while (d % 2 == 0) d /= 2;
constexpr long long bases[3] = {2, 7, 61};
for (long long a : bases) {
long long t = d;
long long y = pow_mod_constexpr(a, t, n);
while (t != n - 1 && y != 1 && y != n - 1) {
y = y * y % n;
t <<= 1;
}
if (y != n - 1 && t % 2 == 0) {
return false;
}
}
return true;
}
template <int n> constexpr bool is_prime = is_prime_constexpr(n);
https://codeforces.com/contest/1508/submission/113222414
> if (n == 2 || n == 7 || n == 61) return true;
Помню я как делал: подобрал 3 базовых числа, прогнал на всех интах, там где алгоритм ошибался - проифал вручную )))
0
package com.example
import kotlinx.coroutines.*
import io.ktor.network.selector.*
import io.ktor.network.sockets.*
import io.ktor.utils.io.*
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.channels.ReceiveChannel
import java.io.IOException
import java.lang.StringBuilder
import java.nio.ByteBuffer
suspend fun ByteReadChannel.readString(): String {
val result = StringBuilder()
val decoder = Charsets.US_ASCII.newDecoder()
val buffer = ByteBuffer.allocate(1)
while (!isClosedForRead) {
val byte = readByte()
if (byte > 127 || byte < 0) {
continue
}
val c = decoder.decode(buffer.also {
it.put(byte)
it.rewind()
})[0]
result.append(c)
if (c == '\n') {
return result.toString().trim('\r', '\n')
}
buffer.rewind()
decoder.reset()
}
return ""
}
suspend fun ByteWriteChannel.println(text: String) {
writeStringUtf8(text)
writeStringUtf8("\r\n")
}
class Client(private val clientSocket: Socket, private val room: BroadcastChannel<String>) {
private val output = clientSocket.openWriteChannel(autoFlush = true)
private val input = clientSocket.openReadChannel()
var nick: String? = null
private set
suspend fun start() = coroutineScope {
input.discard(input.availableForRead.toLong())
output.writeStringUtf8("Welcome! And your name: ")
val nick = input.readString()
room.send("$nick is here")
output.println("Welcome $nick")
[email protected] = nick
val roomSubscription = room.openSubscription()
launch {
for (message in roomSubscription) {
output.println(message)
}
}
launch {
processUserInput(nick)
}.join()
roomSubscription.cancel()
}
private suspend fun processUserInput(nick: String) {
while (!clientSocket.isClosed) {
val text = input.readString()
room.send("$nick: $text")
if (text == "bye") {
room.send("$nick left")
return
}
}
}
}
suspend fun stdoutRoomProcessor(input: ReceiveChannel<String>) {
for (message in input) {
println(message)
}
}
suspend fun server(port: Int) = coroutineScope {
val serverSocket = aSocket(ActorSelectorManager(coroutineContext)).tcp().bind(port = port)
val room = ConflatedBroadcastChannel<String>()
launch {
stdoutRoomProcessor(room.openSubscription())
}
while (coroutineContext.isActive) {
val clientSocket = serverSocket.accept()
room.send("Client connected ${clientSocket.remoteAddress}")
launch {
val client = Client(clientSocket, room)
try {
client.start()
0
function main()
{
let a: [string, number] = ["asd", 1.0];
print(a[0], a[1]);
const b: [string, number] = ["asd", 1.0];
print(b[0], b[1]);
const c = ["asd", 1.0];
print(c[0], c[1]);
}
Продолжаем будни говнописания говнокомпилятора. Хотел спросить а ваш компилятор может так, но думаю может. В кратце - это работа с таплами(tuples) а не с масивами :)
0
function main()
{
const ac = [1, 2, 3];
let a = ac;
print(ac[0]);
print(ac[1]);
print(ac[2]);
print(a[0]);
print(a[1]);
print(a[2]);
const ac2 = [1.0, 2.0, 3.0];
let a2 = ac2;
print(ac2[0]);
print(ac2[1]);
print(ac2[2]);
print(a2[0]);
print(a2[1]);
print(a2[2]);
const ac3 = ["item 1", "item 2", "item 3"];
let a3 = ac3;
print(ac3[0]);
print(ac3[1]);
print(ac3[2]);
print(a3[0]);
print(a3[1]);
print(a3[2]);
}
// LLVM output
; 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"
@frmt_11120820245497078329 = internal constant [4 x i8] c"%s\0A\00"
@s_13298922352840505641 = internal constant [8 x i8] c"item 3\00\00"
@s_13297965777724151296 = internal constant [8 x i8] c"item 2\00\00"
@s_13300835503073214331 = internal constant [8 x i8] c"item 1\00\00"
@a_14124738666956595718 = internal constant [3 x i8*] [i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13300835503073214331, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13297965777724151296, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @s_13298922352840505641, i64 0, i64 0)]
@frmt_11108397963124010376 = internal constant [4 x i8] c"%f\0A\00"
@a_17125214420326958200 = internal constant [3 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00]
@frmt_11106471618751763154 = internal constant [4 x i8] c"%d\0A\00"
@a_2366260266165782651 = internal constant [3 x i32] [i32 1, i32 2, i32 3]
declare i8* @malloc(i64)
declare void @free(i8*)
declare i32 @printf(i8*, ...)
define void @main() !dbg !3 {
%1 = alloca i32*, align 8, !dbg !7
store i32* getelementptr inbounds ([3 x i32], [3 x i32]* @a_2366260266165782651, i64 0, i64 0), i32** %1, align 8, !dbg !7
%2 = load i32*, i32** %1, align 8, !dbg !7
%3 = alloca i32*, align 8, !dbg !9
store i32* %2, i32** %3, align 8, !dbg !9
%4 = load i32*, i32** %1, align 8, !dbg !7
%5 = getelementptr i32, i32* %4, i32 0, !dbg !10
%6 = load i32, i32* %5, align 4, !dbg !10
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %6), !dbg !11
%8 = load i32*, i32** %1, align 8, !dbg !7
%9 = getelementptr i32, i32* %8, i32 1, !dbg !12
%10 = load i32, i32* %9, align 4, !dbg !12
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %10), !dbg !13
%12 = load i32*, i32** %1, align 8, !dbg !7
%13 = getelementptr i32, i32* %12, i32 2, !dbg !14
%14 = load i32, i32* %13, align 4, !dbg !14
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %14), !dbg !15
%16 = load i32*, i32** %3, align 8, !dbg !9
%17 = getelementptr i32, i32* %16, i32 0, !dbg !16
%18 = load i32, i32* %17, align 4, !dbg !16
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %18), !dbg !17
%20 = load i32*, i32** %3, align 8, !dbg !9
%21 = getelementptr i32, i32* %20, i32 1, !dbg !18
%22 = load i32, i32* %21, align 4, !dbg !18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %22), !dbg !19
%24 = load i32*, i32** %3, align 8, !dbg !9
%25 = getelementptr i32, i32* %24, i32 2, !dbg !20
%26 = load i32, i32* %25, align 4, !dbg !20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11106471618751763154, i64 0, i64 0), i32 %26), !dbg !21
%28 = alloca float*, align 8, !dbg !22
store float* getelementptr inbounds ([3 x float], [3 x float]* @a_17125214420326958200, i64 0, i64 0), float** %28, align 8, !dbg !22
%29 = load float*, float** %28, align 8, !dbg !22
%30 = alloca float*, align 8, !dbg !23
store float* %29, float** %30, align 8, !dbg !23
%31 = load float*, float** %28, align 8, !dbg !22
%32 = getelementptr float, float* %31, i32 0, !dbg !24
%33 = load float, float* %32, align 4, !dbg !24
%34 = fpext float %33 to double, !dbg !25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11108397963124010376, i64 0, i64 0), double %34), !dbg !25
%36 = load float*, float** %28, align 8, !dbg !22
%37 = getelementptr float, float* %36, i32 1, !dbg !26
%38 = load float, float* %37, align 4, !dbg !26
%39 = fpext float %38 to double, !dbg !27
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11108397963124010376, i64 0, i64 0), double %39), !dbg !27
продолжаем нашу е..блю с компилятором а ля "C" но только используя синтакс TypeScript
дальше это гвно при запуска tsc.exe --emit=llvm c:\1.ts
получаем равернутую раскладку го-в-на которе можно перевести в Obj файл
а если запустим EXE получим такую Х типа "1 2 3 1 2 3 1.0 2.0 3.0 1.0 2.0 3.0 item 1 item 2 item 3 item 1 item 2 item 3"
и никакой е..бли в указателями все сука компилятор делает сам
+2
ShipType Ship::getShipTypeByLength(int length)
{
switch (length) {
case 1: return BOAT;
case 2: return CRUISER;
case 3: return DESTROYER;
case 4: return BATTLESHIP;
case 5: return AIRCRAFT_CARRIER;
default:
std::cout << "No ship meets the given length: " << length << std::endl;
return ERROR_SHIP;
}
}
int Ship::getShipLengthByType(ShipType type)
{
switch (type) {
case BOAT: return 1;
case CRUISER: return 2;
case DESTROYER: return 3;
case BATTLESHIP: return 4;
case AIRCRAFT_CARRIER: return 5;
default:
std::cout << "No ship meets the given type: " << type << std::endl;
return 0;
}
}
int Ship::getShipAmountByType(ShipType type)
{
switch (type) {
case BOAT: return 4;
case CRUISER: return 3;
case DESTROYER: return 2;
case BATTLESHIP: return 1;
case AIRCRAFT_CARRIER: return 1;
default:
std::cout << "No ship meets the given type: " << type << std::endl;
return 0;
}
}
Coordinates Ship::getFirstBlockCoordinatesByShipData(int x, int y, int length, Orientation orientation)
{
Coordinates result;
if (orientation == HORIZONTAL) {
result.x = x - (length / 2);
result.y = y;
} else {
result.x = x;
result.y = y - (length / 2);
}
return result;
}
Coordinates Ship::getLastBlockCoordinatesByShipData(int x, int y, int length, Orientation orientation)
{
Coordinates result;
if (orientation == HORIZONTAL) {
result.x = x + (length / 2) + (length % 2) - 1;
result.y = y;
} else {
result.x = x;
result.y = y + (length / 2) + (length % 2) - 1;
}
return result;
}
Вот некоторые полезные функции из игры «Морской Бой», которую я зачем-то написал.