- 1
https://habr.com/ru/company/ruvds/blog/514776/
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
https://habr.com/ru/company/ruvds/blog/514776/
0
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdint.h>
#define GEN_NAME(type) struct myvec_ ## type
#define MK_VEC_TYPE(type) GEN_NAME(type) {size_t sz; type arr[];};
#define MK_VEC_NEW(type) \
GEN_NAME(type) *myvec_new_ ## type (size_t num) \
{ \
struct myvec_ ## type *tmp = malloc(sizeof(type) * num); \
if (tmp == NULL) \
{ \
return NULL; \
} \
tmp->sz = num; \
return tmp; \
}
#define MK_VEC_DELETE(type) \
void myvec_delete_ ## type (GEN_NAME(type) *v) \
{ \
free(v); \
}
#define MK_VEC_GET(type) \
type myvec_get_ ## type (GEN_NAME(type) *v, size_t pos) \
{ \
if(pos < v->sz) \
{ \
return v->arr[pos]; \
} \
else \
{ \
exit(-1); \
} \
}
// исключения - говно
#define MK_VEC_SET(type) \
void myvec_set_ ## type (GEN_NAME(type) *v, size_t pos, type val) \
{ \
if(pos < v->sz) \
{ \
v->arr[pos] = val; \
} \
else \
{ \
exit(-1); \
} \
}
#define MK_VEC_GETSZ(type) \
size_t myvec_getsz_ ## type (GEN_NAME(type) v) \
{ \
return v.sz; \
}
#define MK_SHIT(type) \
MK_VEC_TYPE(type) \
MK_VEC_NEW(type) \
MK_VEC_DELETE(type) \
MK_VEC_GET(type) \
MK_VEC_GETSZ(type) \
MK_VEC_SET(type)
MK_SHIT(int)
MK_SHIT(float)
MK_SHIT(double)
#define test(a) _Generic(a, int : 1, GEN_NAME(int) : 2, default : 0)
#define MTD_C(val,mtd) _Generic( val,\
GEN_NAME(int): myvec_ ## mtd ##_int, \
GEN_NAME(float): myvec_ ## mtd ##_float, \
GEN_NAME(double): myvec_ ## mtd ##_double, \
default: 0) // хуй там!
#define GET(vec,pos) MTD_C(vec,get)(&vec,pos)
#define SET(vec, pos, val) MTD_C(vec,set)(&vec,pos,val)
#define GETSZ(vec) MTD_C(vec,getsz)(vec)
int main(void)
{
GEN_NAME(int) *vec1 = myvec_new_int(10);
SET(*vec1, 0, 123);
size_t size = GETSZ(*vec1);
printf("vector size is %zu\n", size);
printf("vector vec1[0] is %d\n", GET(*vec1,0));
return 0;
}
Какое ООП)))
+1
// Both set_time_limit(...) and ini_set('max_execution_time',...); won't count the time cost of sleep,
// file_get_contents,shell_exec,mysql_query etc, so i build this function my_background_exec(),
// to run static method/function in background/detached process and time is out kill it:
// my_exec.php:
<?php
function my_background_exec($function_name, $params, $str_requires, $timeout=600)
{$map=array('"'=>'\"', '$'=>'\$', '`'=>'\`', '\\'=>'\\\\', '!'=>'\!');
$str_requires=strtr($str_requires, $map);
$path_run=dirname($_SERVER['SCRIPT_FILENAME']);
$my_target_exec="/usr/bin/php -r \"chdir('{$path_run}');{$str_requires} \\\$params=json_decode(file_get_contents('php://stdin'),true);call_user_func_array('{$function_name}', \\\$params);\"";
$my_target_exec=strtr(strtr($my_target_exec, $map), $map);
$my_background_exec="(/usr/bin/php -r \"chdir('{$path_run}');{$str_requires} my_timeout_exec(\\\"{$my_target_exec}\\\", file_get_contents('php://stdin'), {$timeout});\" <&3 &) 3<&0";//php by default use "sh", and "sh" don't support "<&0"
my_timeout_exec($my_background_exec, json_encode($params), 2);
}
// ...
Шедевр (заплюсованный) из https://www.php.net/manual/ru/function.set-time-limit.php.
−1
else if (BallToDown(paddle_2, paddle_2_pos, new Rectangle((int)ball_pos.X, (int)ball_pos.Y, ball.Width, ball.Height)))
{
Paddle_s.Play();
ballSpeed = new Vector2(9.0f, 4.5f);
}
/*Левая Ракетка*/
//Ограничения по Оси Y
if (paddle_2_pos.Y < 0)
paddle_2_pos.Y = 0;
else if (paddle_2_pos.Y > Window.ClientBounds.Height - paddle_2.Height)
paddle_2_pos.Y = Window.ClientBounds.Height - paddle_2.Height;
//Управление Ракеткой
if (Keyboard.GetState().IsKeyDown(Keys.W))
paddle_2_pos.Y -= speed;
else if (Keyboard.GetState().IsKeyDown(Keys.S))
paddle_2_pos.Y += speed;
/*Правая Ракетка*/
//Ограниччения по Оси Y
if (paddle_1_pos.Y < 0)
paddle_1_pos.Y = 0;
else if (paddle_1_pos.Y > Window.ClientBounds.Height - paddle_1.Height)
paddle_1_pos.Y = Window.ClientBounds.Height - paddle_1.Height;
//Управление Ракеткой
if (Keyboard.GetState().IsKeyDown(Keys.Up))
paddle_1_pos.Y -= speed;
else if (Keyboard.GetState().IsKeyDown(Keys.Down))
paddle_1_pos.Y += speed;
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(paddle_1, paddle_1_pos, Color.White);
spriteBatch.Draw(paddle_2, paddle_2_pos, Color.White);
spriteBatch.Draw(ball, ball_pos, Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
public bool BallToUp(Texture2D paddle, Vector2 paddle_pos, Rectangle ballRect)
{
/*Создаётся прямоугольник размером 1/3 от всей ракетки*/
Rectangle paddleRect = new Rectangle((int)paddle_pos.X, (int)paddle_pos.Y, paddle.Width, (int)paddle.Height / 2);
return ballRect.Intersects(paddleRect);
}
public bool BallToDown(Texture2D paddle, Vector2 paddle_pos, Rectangle ballRect)
{
/*Создаётся прямоугольник размером 1/3 от всей ракетки*/
Rectangle paddleRect = new Rectangle((int)paddle_pos.X, (int)paddle_pos.Y + (paddle.Height / 2), paddle.Width, (int)paddle.Height / 2);
return ballRect.Intersects(paddleRect);
}
}
}
Недавно начал программировать на C#, Решил написать Пин-Понг на моногейм, Плучилось нечто но работает отлично: отрывок кода сверху
+2
List<UserScoreDTO> userScores = users.stream()
.map((u) -> ScoreUtils.aggregateUserAndFlagData(u, maxTestScore))
.collect(toList());
return userScores.stream();
Collect to List<UserScoreDTO> then stream the list to Stream<UserScoreDTO>
0
# while 1 через for
shits = ['говно']
for shit in shits:
print('Говно')
shits.append('говно')
Прост while 1 через for
+1
吾有一術。名之曰「斐波那契」。欲行是術。必先得一數。曰「甲」。乃行是術曰。
若「甲」等於零者乃得零也
若「甲」等於一者乃得一也
減「甲」以一。減「甲」以二。名之曰「乙」。曰「丙」。
施「斐波那契」於「乙」。名之曰「丁」。
施「斐波那契」於「丙」。名之曰「戊」。
加「丁」以「戊」。名之曰「己」。
乃得「己」。
是謂「斐波那契」之術也。
施「斐波那契」於十二。書之。
文言 wenyan-lang
Числа Фибоначчи.
https://github.com/wenyan-lang/wenyan
+3
class Person {
protected name: string;
constructor(name: string) { this.name = name; }
}
class Employee extends Person {
private department: string;
constructor(name: string, department: string) {
super(name);
this.department = department;
}
public get ElevatorPitch() {
return `Hello, my name is ${this.name} and I work in ${this.department}.`;
}
}
const howard = new Employee("Howard", "Sales");
console.log(howard.ElevatorPitch);
//===============================================>>>>>>>>>>>>>>>>>>
#ifndef TEST_H
#define TEST_H
#include "core.h"
using namespace js;
class Person;
class Employee;
class Person : public object, public std::enable_shared_from_this<Person> {
public:
string name;
Person(string name);
};
class Employee : public Person, public std::enable_shared_from_this<Employee> {
public:
string department;
Employee(string name, string department);
virtual any get_ElevatorPitch();
Employee(string name);
};
extern std::shared_ptr<Employee> howard;
#endif
#include "test.h"
using namespace js;
Person::Person(string name) {
this->name = name;
}
Employee::Employee(string name, string department) : Person(name) {
this->department = department;
}
any Employee::get_ElevatorPitch()
{
return "Hello, my name is "_S + this->name + " and I work in "_S + this->department + "."_S;
}
Employee::Employee(string name) : Person(name) {
}
std::shared_ptr<Employee> howard = std::make_shared<Employee>("Howard"_S, "Sales"_S);
void Main(void)
{
console->log(howard->get_ElevatorPitch());
}
int main(int argc, char** argv)
{
Main();
return 0;
}
Было делать нехрен в жизни и решил наговнокодить транспайлер с TypeScript в С++
https://github.com/ASDAlexander77/TypeScript2Cxx
+1
<?php
function qes2_key ( $key = null ) {
$key = str_split( $key );
$keycount = count( $key );
$xspos = 1;
$summ = 0;
foreach( $key as $letter ) {
$summ += ord( $letter ) * 2 + $xspos + ( $keycount / $xspos );
$xspos++;
}
$summ = explode('.', $summ );
return $summ[0];
}
function qes2_encrypt ( $input, $key ) {
$input = str_split( $input );
$icount = count( $input );
$rsumm = qes2_key( $key );
$result = '';
$xspos = 1;
$xsdisp = 1;
foreach( $input as $letter ) {
$char = ord( $letter ) + ( $rsumm * $xspos ) - $xsdisp ;
$result .= chr( $char );
$xspos++;
$xsdisp += 1;
}
return $result;
}
function qes2_decrypt ( $input, $key ) {
$input = str_split( $input );
$icount = count( $input );
$rsumm = qes2_key( $key );
$result = '';
$xspos = 1;
$xsdisp = 1;
foreach( $input as $letter ) {
$char = ord( $letter ) - ( $rsumm * $xspos ) + $xsdisp ;
$result .= chr( $char );
$xspos++;
$xsdisp += 1;
}
return $result;
}
qes2a encryption (c)
+1
public function cutPoly($business_id)
{
$done = [];
$red = Isochrone::where('business_id', $business_id)->where('color', 'red')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
$blue = Isochrone::where('business_id', $business_id)->where('color', 'blue')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
$green = Isochrone::where('business_id', $business_id)->where('color', 'green')->selectRaw('id, color, ST_AsText(path) as p_path')->get()->first();
if ($red && $blue) {
if (!$red['p_path'] || !$blue['p_path']) {
$done['red'] = 'already';
} else {
$isoString = 'POLYGON((';
$blue_path = $blue['p_path'];
$red_path = $red['p_path'];
if (!array_key_exists('lat', $blue['p_path'][0])) {
$blue_path = $blue['p_path'][0];
}
if (!array_key_exists('lat', $red['p_path'][0])) {
$red_path = $red['p_path'][0];
}
$isoString .= implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $red_path))
. '),('.
implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $blue_path))
.'))';
Isochrone::where('business_id', $business_id)->where('color', 'red')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
$done['red'] = 'ok';
}
} else if ($red && $green) {
if (!$red['p_path'] || !$green['p_path']) {
$done['red'] = 'already';
} else {
$isoString = 'POLYGON((';
$green_path = $green['p_path'];
$red_path = $red['p_path'];
if (!array_key_exists('lat', $green['p_path'][0])) {
$green_path = $green['p_path'][0];
}
if (!array_key_exists('lat', $red['p_path'][0])) {
$red_path = $red['p_path'][0];
}
$isoString .= implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $red_path))
. '),('.
implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $green_path))
.'))';
Isochrone::where('business_id', $business_id)->where('color', 'red')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
$done['red'] = 'ok green';
}
}
if ($blue && $green) {
if (!$blue['p_path'] || !$green['p_path']) {
$done['blue'] = 'already';
} else {
$isoString = 'POLYGON((';
$green_path = $green['p_path'];
$blue_path = $blue['p_path'];
if (!array_key_exists('lat', $green['p_path'][0])) {
$green_path = $green['p_path'][0];
}
if (!array_key_exists('lat', $blue['p_path'][0])) {
$blue_path = $blue['p_path'][0];
}
$isoString .= implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $blue_path))
. '),('.
implode(',', array_map(function ($entry) {
return $entry['lat'] . ' ' . $entry['lng'];
}, $green_path))
.'))';
Isochrone::where('business_id', $business_id)->where('color', 'blue')->update(['path' => \DB::raw("ST_GeomFromText('$isoString')")]);
$done['blue'] = 'ok';
}
}
return $done;
}
Он же через час - три дня будет разбиратся что написал