- 1
- 2
https://habr.com/ru/post/449368/
Ко-ко-ко-ко-ко-кой багор )))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
https://habr.com/ru/post/449368/
Ко-ко-ко-ко-ко-кой багор )))
−1
<?php $connection = mysqli_connect ('localhost','root','','userlistdb');
// Проверка, если это общий клиент
if (!empty($_SERVER['HTTP_CLIENT_IP'])){
$ip=$_SERVER['HTTP_CLIENT_IP'];
//Is it a proxy address
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}
// Значение $ ip в этот момент будет выглядеть примерно так: "192.0.34.166"
$ip = ip2long($ip);
// Теперь $ ip будет выглядеть примерно так: 1073732954
$sql = "INSERT INTO user(ip) VALUES('$ip')";
$dbQuery = mysql_query($sql,$dbLink);
$stmt = $dbh->prepare("INSERT INTO usertbl(ip) VALUES(ip)");
$stmt->bindParam(1, $ip);
$stmt->execute();
?>
выдаёт ошибку:
Примечание : Не определено переменная: DBLink в C: \ XAMPP \ HTDOCS \ офсетные \ testip.php на линии 21
Внимание : mysql_query () ожидает параметр 2 , чтобы быть ресурсом, приведены в нуль C: \ XAMPP \ HTDOCS \ кормили \ testip.php на строка 21
Примечание : неопределенная переменная: dbh в C: \ xampp \ htdocs \ fed \ testip.php в строке 25
Фатальная ошибка : вызов функции-члена prepare () для null в C: \ xampp \ htdocs \ fed \ testip.php на линии 25
$dbQuery = mysql_query($sql,$dbLink);
$stmt = $dbh->prepare("INSERT INTO usertbl(ip) VALUES(ip)");
Кто знает как записать IP из формы и сохранить в базу даных MySQL
+3
// A sample standard C++20 program that prints
// the first N Pythagorean triples.
#include <iostream>
#include <optional>
#include <ranges> // New header!
using namespace std;
// maybe_view defines a view over zero or one
// objects.
template<Semiregular T>
struct maybe_view : view_interface<maybe_view<T>> {
maybe_view() = default;
maybe_view(T t) : data_(std::move(t)) {
}
T const *begin() const noexcept {
return data_ ? &*data_ : nullptr;
}
T const *end() const noexcept {
return data_ ? &*data_ + 1 : nullptr;
}
private:
optional<T> data_{};
};
// "for_each" creates a new view by applying a
// transformation to each element in an input
// range, and flattening the resulting range of
// ranges.
// (This uses one syntax for constrained lambdas
// in C++20.)
inline constexpr auto for_each =
[]<Range R,
Iterator I = iterator_t<R>,
IndirectUnaryInvocable<I> Fun>(R&& r, Fun fun)
requires Range<indirect_result_t<Fun, I>> {
return std::forward<R>(r)
| view::transform(std::move(fun))
| view::join;
};
// "yield_if" takes a bool and a value and
// returns a view of zero or one elements.
inline constexpr auto yield_if =
[]<Semiregular T>(bool b, T x) {
return b ? maybe_view{std::move(x)}
: maybe_view<T>{};
};
int main() {
// Define an infinite range of all the
// Pythagorean triples:
using view::iota;
auto triples =
for_each(iota(1), [](int z) {
return for_each(iota(1, z+1), [=](int x) {
return for_each(iota(x, z+1), [=](int y) {
return yield_if(x*x + y*y == z*z,
make_tuple(x, y, z));
});
});
});
// Display the first 10 triples
for(auto triple : triples | view::take(10)) {
cout << '('
<< get<0>(triple) << ','
<< get<1>(triple) << ','
<< get<2>(triple) << ')' << '\n';
}
}
«C++20»: ещё больше модерна! Ещё больше шаблонов! Ещё больше ебанутых конструкций! Ещё больше блядского цирка!
s: http://aras-p.info/blog/2018/12/28/Modern-C-Lamentations/
+2
if (!(fs_info->workers && fs_info->delalloc_workers &&
fs_info->submit_workers && fs_info->flush_workers &&
fs_info->endio_workers && fs_info->endio_meta_workers &&
fs_info->endio_meta_write_workers &&
fs_info->endio_write_workers && fs_info->endio_raid56_workers &&
fs_info->endio_freespace_worker && fs_info->rmw_workers &&
fs_info->caching_workers && fs_info->readahead_workers &&
fs_info->fixup_workers && fs_info->delayed_workers && // <===
fs_info->fixup_workers && fs_info->extent_workers && // <===
fs_info->qgroup_rescan_workers)) {
err = -ENOMEM;
goto fail_sb_buffer;
}
https://bugzilla.kernel.org/show_bug.cgi?id=820210
switch ($city) {
case $city == 'Москва':
$tel['work'] = '+7 (495) www-ww-22';
$tel['entire'] = '8 (800) xxx-xx-49';
break;
case $city == 'Нижний-Новгород':
$tel['work'] = '+7 (495) zzz-zz-02';
$tel['entire'] = '8 (800) zzz-zz-02';
break;
case $city == 'Ростов-на-Дону':
$tel['work'] = '+7 (495) zzz-zz-03';
$tel['entire'] = '8 (800) zzz-zz-03';
break;
case $city == 'Казань':
$tel['work'] = '+7 (495) zzz-zz-04';
$tel['entire'] = '8 (800) zzz-zz-04';
break;
case $city == 'Тюмень':
$tel['work'] = '+7 (495) zzz-zz-05';
$tel['entire'] = '8 (800) zzz-zz-05';
break;
Мало того, что странное использование case, так это ещё повторяется для 28 городов.
Одинаковые части номеров заменил на zzz-zz
−715
return instruction emitted twice with branch target inbetween
function
unsigned int fact( unsigned int n) { return n < 1 ? 1 : n*fact(n-1); }
produces
fact:
.LFB0:
.cfi_startproc
testl %edi, %edi
movl $1, %eax
je .L4
.p2align 4,,10
.p2align 3
.L3:
imull %edi, %eax
subl $1, %edi
jne .L3
rep ret # <-- this instruction can be removed
.L4:
rep ret
.cfi_endproc
.LFE0:
.size fact, .-fact
.section .text.unlikely
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71923 даже факториал не могут скомпилировать нормально
0
if (strpos($route, ':') !== false) {
$route = str_replace(':any', '([^/]+)', str_replace(':num', '([0-9]+)', str_replace(':all', '(.+)', $route)));
}
Очередная обезьяна села высерать свои мысли на PHP ... Уже много говорили тут о mpak и его "cms", вот вам еще одно "чудо": https://github.com/wolfcms/wolfcms
0
public function actionView($id = null) {
$user = Yii::$app->user->identity;
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : $id;
$new_model = 0;
if (empty($id)) {
$draft_model = Applicant::find()->where(['draft' => 1, 'created_by' => $user->id])->one();
if (empty($draft_model)) {
$draft_model = new Applicant();
$new_model = 1;
$draft_model->draft = 1;
$draft_model->save();
}
if (!empty($draft_model->id)) {
$id = $draft_model->id;
}
}
$model = $this->findModel($id);
$allow_sections = [];
if (empty($model->draft)) {
$updateRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
if (!empty($updateRequest)) {
$allow_sections = explode(";", $updateRequest->additional_info);
}
}
if (isset($_GET['done']) && $_GET['done'] == 1) {
$result['success'] = false;
$userRequest = \app\models\UserRequest::find()->where(['user_id' => $user->id, 'object_id' => $id, 'status' => 2])->one();
if (!empty($userRequest)) {
$userRequest->status = 3;
if ($userRequest->save()) {
$result['success'] = true;
} else {
$error = \yii\widgets\ActiveForm::validate($userRequest);
if ($error != '[]') {
$result['msg'] = $error;
}
}
}
echo(json_encode($result));
exit;
} elseif (isset($_FILES['files']['name'][0]) && isset($_FILES['files']['type'][0]) && isset($_FILES['files']['tmp_name'][0]) && isset($_FILES['files']['size'][0])) {
$result['success'] = false;
$filename = strtotime("now") . "_" . $_FILES['files']['name'][0];
$size = $_FILES['files']['size'][0];
$uploaddir = realpath('../web') . '/images/applicant/';
if (!file_exists($uploaddir)) {
mkdir($uploaddir);
}
$uploadfile = $uploaddir . basename($filename);
$path_image = '/images/applicant/' . basename($filename);
if (move_uploaded_file($_FILES['files']['tmp_name'][0], $uploadfile)) {
if (!empty($model->photo_id)) {
$photo_model = \app\models\File::findOne($model->photo_id);
}
if (empty($photo_model->id)) {
$photo_model = new \app\models\File();
}
$photo_model->original = $filename;
$photo_model->name = $filename;
$photo_model->size = $size;
$photo_model->mime = $_FILES['files']['type'][0];
$photo_model->hash = $photo_model->generateHash();
if ($photo_model->save()) {
$model->photo_id = $photo_model->id;
if ($model->save()) {
$result['img'] = $filename;
$result['success'] = true;
}
}
$image = new Image();
$image->load($uploadfile);
if($image->getWidth()>640){
$image->resizeToWidth(640);
$image->save($uploadfile);
}
}
echo(json_encode($result));
exit;
} elseif (isset($_REQUEST['name'])) {
$result['success'] = false;
$model_attributes = $model->getAttributes();
$model_attributes['education'] = '';
unset($model_attributes['id']);
if ($_REQUEST['name'] == 'address_properties') {
$values = json_decode($_REQUEST['value'], true);
$names_values = ['address_region', 'address_city', 'address_street', 'address_house'];
yii 2
+2
/***
*assert.h - define the assert macro
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* Defines the assert(exp) macro.
* [ANSI/System V]
*
* [Public]
*
****/
/*
#include <crtdefs.h>
#undef assert
#ifdef NDEBUG
#define assert(_Expression) ((void)0)
#else
#ifdef __cplusplus
extern "C" {
#endif
_CRTIMP void __cdecl _wassert(_In_z_ const wchar_t * _Message, _In_z_ const wchar_t *_File, _In_ unsigned _Line);
#ifdef __cplusplus
}
#endif
#define assert(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
#endif */
#pragma once
#ifdef NDEBUG
#define assert(expr)
#else
inline void CheckExpression_(bool expr)
{
if (!expr)
{
expr=true; // put breakpoint here, happy user;
CheckExpression_(expr);
}
}
inline void CheckExpression_(void* expr)
{
if (!expr)
{
expr=(void*)(1); // put breakpoint here, happy user;
CheckExpression_(expr);
}
}
#define assert(expr) CheckExpression_(expr);
#endif
Сука я не знаю, почему в студии-2008 родной ассерт показывает не ту строку, на которой он произошёл и в стеке вызовов хуйня какая-то, и как подключить DebugBreak я тоже не знаю, потому что в windef.h куча хуеты, выдающей 100500 ошибок компиляции. Чтобы хоть как-то можно было жить, пришлось сделать так.
+64
XmlWriter<xhtml11::XHtmlDocument>(stream)
<html
<head
<title
<"Hello world!"
>title
>head
<body
<p
<"Some nice paragraph text."
>p
<img(src="http://example.com/hello.jpg",alt="Hello")>img
>body
>html;
кресты в квадрате. любителям темплейтов посвящается.
http://www.vandenoever.info/blog/2015/07/05/literal-xml-in-c++.html
Creating and processing XML feels awkward in most programming languages. With Blasien, a tiny C++11 header library, XML in C++ feels easy and natural. As an extra the XML that is written is mostly validated at compile time.