- 1
День системного администратора
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
День системного администратора
Особые поздравления к:
bormand
defacate-plusplus
gost
Ещё админы есть?
+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.
+2
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ N T M a p M e m o r y %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Mmap() emulates the Unix method of the same name.
%
% The format of the NTMapMemory method is:
%
% MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
% int access,int file,MagickOffsetType offset)
%
*/
MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
int flags,int file,MagickOffsetType offset)
{
DWORD
access_mode,
high_length,
high_offset,
low_length,
low_offset,
protection_mode;
HANDLE
file_handle,
map_handle;
void
*map;
(void) address;
access_mode=0;
file_handle=INVALID_HANDLE_VALUE;
low_length=(DWORD) (length & 0xFFFFFFFFUL);
high_length=(DWORD) ((((MagickOffsetType) length) >> 32) & 0xFFFFFFFFUL);
map_handle=INVALID_HANDLE_VALUE;
map=(void *) NULL;
low_offset=(DWORD) (offset & 0xFFFFFFFFUL);
high_offset=(DWORD) ((offset >> 32) & 0xFFFFFFFFUL);
protection_mode=0;
if (protection & PROT_WRITE)
{
access_mode=FILE_MAP_WRITE;
if (!(flags & MAP_PRIVATE))
protection_mode=PAGE_READWRITE;
else
{
access_mode=FILE_MAP_COPY;
protection_mode=PAGE_WRITECOPY;
}
}
else
if (protection & PROT_READ)
{
access_mode=FILE_MAP_READ;
protection_mode=PAGE_READONLY;
}
if ((file == -1) && (flags & MAP_ANONYMOUS))
file_handle=INVALID_HANDLE_VALUE;
else
file_handle=(HANDLE) _get_osfhandle(file);
map_handle=CreateFileMapping(file_handle,0,protection_mode,high_length,
low_length,0);
if (map_handle)
{
map=(void *) MapViewOfFile(map_handle,access_mode,high_offset,low_offset,
length);
CloseHandle(map_handle);
}
if (map == (void *) NULL)
return((void *) ((char *) MAP_FAILED));
return((void *) ((char *) map));
}
Мумуляция «mmap» в «Винде». Это даже работает, если пофиксить две строчки (кто угадает, какие именно, тому ничего).
Отсюда:
https://github.com/ImageMagick/ImageMagick/blob/master/MagickCore/nt-base.c
0
Именно поэтому я за «PHP».
+1
var xc = /^true$/.test("false");
var yc = xc;
google ad manager (gpt.js)
−1
System.out.println("\nNames in alphabetical order: ");
if(name1.compareTo(name2) > 0) {
if(name2.compareTo(name3) > 0) {
System.out.printf("%s\n%s\n%s\n",
name3,
name2,
name1); //cba 2
}
else if(name3.compareTo(name2) > 0) {
System.out.printf("%s\n%s\n%s\n",
name2,
name3,
name1); //bca 3
}
}
else if(name2.compareTo(name1) > 0) {
if(name1.compareTo(name3) > 0) {
System.out.printf("%s\n%s\n%s\n",
name3,
name1,
name2); //cab 1
}
else if(name3.compareTo(name1) > 0) {
System.out.printf("%s\n%s\n%s\n",
name1,
name3,
name2); //acb 5
}
}//bac i abc
else if(name3.compareTo(name1) > 0) {
if(name1.compareTo(name2) > 0) {
System.out.printf("%s\n%s\n%s\n",
name2,
name1,
name3);
}
else if(name2.compareTo(name1) > 0) {
System.out.printf("%s\n%s\n%s\n",
name1,
name2,
name3);
}
}
Снова пытался отсортировать три строки по алфавиту.
У меня опять получилась вместо нескольких строк простыня.
Что со мной не так?
Но, по крайней мере, она работает как надо.
0
def __init__(self, text: str, description: str, category_id: int, auth_cookie: str) -> None:
Form.__init__(self)
CsrfForm.__init__(self)
CaptchaForm.__init__(self)
self.text: str = text
self.description: str = description
self.category_id = category_id
self.auth_cookie = auth_cookie
Какое наследование )))
−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#, Решил написать Пин-Понг на моногейм, Плучилось нечто но работает отлично: отрывок кода сверху
0
> Improved People Nearby
Profile videos make meeting new people a dozen times more interesting, and we've beefed up the People Nearby section for the occasion.
When people contact you via the People Nearby section, you will see how far away they are. And when you start a chat with someone nearby,
Telegram will suggest a greeting sticker to break the ice. Luckily, all our stickers are extroverts.
самый секьюрный мессенджер теперь палит еще и локацию юзеров
теперь это у нас тиндер такой
https://telegram.org/blog/profile-videos-people-nearby-and-more
https://telegram.org/blog/new-profiles-people-nearby
0
import { combineEpics, ofType } from 'redux-observable'
import { map, switchMap, catchError, filter, mergeAll } from 'rxjs/operators'
import { of, from } from 'rxjs'
import * as R from 'ramda'
import * as TICKETS_ACTION_TYPES from './tickets.types'
import * as TicketsActions from './tickets.actions'
import * as TicketsSelectors from './tickets.selectors'
import { /* TICKET_TYPES,*/ TICKET_STEPS } from './constants'
import mockAPI from 'services/mockAPI'
export const getTicketsEpic = (action$, state$) =>
from(
R.map(
(step) =>
action$.pipe(
filter(
R.either(
R.both(R.propEq('type', TICKETS_ACTION_TYPES.GET_TICKETS_BY_STEP), R.pathEq(['payload', 'step'], step)),
R.propEq('type', TICKETS_ACTION_TYPES.GET_ALL_TICKETS)
)
),
switchMap((action) => {
if (
action.type !== TICKETS_ACTION_TYPES.GET_ALL_TICKETS &&
TicketsSelectors.ticketsAllDirtySelector(state$.value)
) {
return of(TicketsActions.getAllTickets())
} else if (!TicketsSelectors.ticketsByStepDirtySelector(step, state$.value)) {
return of(TicketsActions.getTicketsByStepSuccess(step, null, true))
}
return from(
// Mocks tickets API
// TODO: Replace by real request
mockAPI.getTicketsByStep(step)
).pipe(
map((data) => TicketsActions.getTicketsByStepSuccess(step, data)),
catchError((err) => of(TicketsActions.getTicketsByStepError(step, err)))
)
})
),
R.values(TICKET_STEPS)
)
).pipe(mergeAll())
Редукс нам уже не интересен, нам с поподвыподвертами подавай, чтоб тупо болванку показать.