- 1
- 2
- 3
- 4
- 5
- 6
- 7
function line(){
$line = '';
for ($i=0; $i != 40; $i++){
$line .= '-';
}
echo($line.PHP_EOL);
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
function line(){
$line = '';
for ($i=0; $i != 40; $i++){
$line .= '-';
}
echo($line.PHP_EOL);
}
+1
<!doctype html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta charset="utf-8" />
<?
$title = filter_var($_REQUEST["title"], FILTER_SANITIZE_STRING);
$image = filter_var($_REQUEST["image"], FILTER_SANITIZE_STRING);
$text = filter_var($_REQUEST["text"], FILTER_SANITIZE_STRING);
?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?=$_REQUEST['title'];?>" />
<meta property="og:description" content="<?=$_REQUEST['text'];?>" />
<meta property="og:image" content="<?=$_REQUEST['image']?>" />
<?$d = 'Некий URL?title='.urlencode($title).'&image='.urlencode($image).'&text='.urlencode($text);?>
<meta property="og:url" content="<?=$d?>" />
<title><?=$_REQUEST['title'];?></title>
<script type="text/javascript">
window.location = "Еще один захардкоженый URL";
</script>
</head>
<body>
<img src="<?=$_REQUEST['image']?>" />
</body>
</html>
все секурно
+1
static inline void set0b (const uint8_t at, uint64_t bm[static 4])
{
bm[at / 64] &= ~(1ULL << (at % 64));
}
static inline void set1b (const uint8_t at, uint64_t bm[static 4])
{
bm[at / 64] |= 1ULL << (at % 64);
}
static inline void inv_b (const uint8_t at, uint64_t bm[static 4])
{
bm[at / 64] ^= 1ULL << (at % 64);
}
static inline uint8_t find_empt_pos (const uint64_t bm[static 4])
{
if (bm[0] != UINT64_MAX)
{
return __builtin_ctzll(~bm[0]) + 64 * 0; // __builtin_ctzll - https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html
}
if (bm[1] != UINT64_MAX)
{
return __builtin_ctzll(~bm[1]) + 64 * 1;
}
if (bm[2] != UINT64_MAX)
{
return __builtin_ctzll(~bm[2]) + 64 * 2;
}
if (bm[3] != UINT64_MAX)
{
return __builtin_ctzll(~bm[3]) + 64 * 3;
}
fprintf(stderr, "ERROR! No empty space!\n");
exit (-1);
}
static inline uint8_t allocate_ll (uint64_t bm[static 4])
{
uint8_t tmp = find_empt_pos (bm);
set1b (tmp, bm);
return tmp;
}
static inline void inject(const uint8_t prev_p, const uint8_t next_p, const uint8_t at, struct ll_data a[static 256])
{
a[next_p].ll.prev = at;
a[prev_p].ll.next = at;
a[at].ll.prev = prev_p;
a[at].ll.next = next_p;
}
static inline void remove_betw(const uint8_t prev_p, const uint8_t next_p, struct ll_data a[static 256])
{
a[prev_p].ll.next = next_p;
a[next_p].ll.prev = prev_p;
}
static inline void remove_at(const uint8_t at, struct ll_data a[static 256], uint64_t bm[static 4])
{
uint8_t prev_t = a[at].ll.prev;
uint8_t next_t = a[at].ll.next;
set0b (at, bm);
a[at].ll.prev = next_t;
a[at].ll.next = prev_t;
}
void add_elem_next (struct ll_all *a, const uint8_t elm, const int value)
{
uint8_t pos = allocate_ll (a->bm);
inject(elm, a->arr[elm].ll.next, pos, a->arr);
set_elm (pos, value, a->arr);
}
void add_elem_prev (struct ll_all *a, const uint8_t elm, const int value)
{
uint8_t pos = allocate_ll (a->bm);
inject(a->arr[elm].ll.prev, elm, pos, a->arr);
a->arr[pos].data = value;
}
void rem_elem_next (struct ll_all *a, const uint8_t elm)
{
set0b (a->arr[elm].ll.next, a->bm);
remove_betw (elm, a->arr[a->arr[elm].ll.next].ll.next, a->arr);
}
void rem_elem_prev (struct ll_all *a, const uint8_t elm)
{
set0b (a->arr[elm].ll.next, a->bm);
remove_betw (a->arr[a->arr[elm].ll.prev].ll.prev, elm, a->arr);
}
Тру-царская неанскилльная реализация двусвязного списка внутри массива.
К сожалению, весь код не помещается, см https://wandbox.org/permlink/Ky8fnuqyE0Ahxftm
+1
function is_tor_network($ip)
{
$tor = array(
'101.142.102.237' => 1,'101.98.134.31' => 1,'103.246.244.1' => 1,'106.187.34.237' => 1,'106.187.36.183' => 1,'106.187.36.240' => 1,'106.187.37.158' => 1, /* ... Такой длинный код врядли может быть смешным. Пожалуйста, ограничьтесь сотней строк и 6000 символами. */
);
return isset( $tor[$ip]) ? true : false;
}
Почему бы не захардкодить тор?..
+1
// GetBlockingMode возвращает: 1 - nonblocking | 0 - blocking | -1 - error | -2 - timeout reseted!
int GetBlockingMode(int Sock)
{
int iSize, iValOld, iValNew, retgso;
iSize = sizeof(iValOld);
retgso = getsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValOld, &iSize); // Save current timeout value
if (retgso == SOCKET_ERROR) return (-1);
iValNew = 1;
retgso = setsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValNew, iSize); // Set new timeout to 1 ms
if (retgso == SOCKET_ERROR) return (-1);
// Ok! Try read 0 bytes.
char buf[1]; // 1 - why not :)
int retrcv = recv(Sock, buf, 0, MSG_OOB); // try read MSG_OOB
int werr = WSAGetLastError();
retgso = setsockopt(Sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&iValOld, iSize); // Set timeout to initial value
if (retgso == SOCKET_ERROR) return (-2);
if (werr == WSAENOTCONN) return (-1);
if (werr == WSAEWOULDBLOCK) return 1;
return 0;
}
+1
#if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
namespace __detail {
template<typename _Tp, size_t ..._Extra> struct __repeat;
template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
typedef __integer_sequence<_Tp,
_Np...,
sizeof...(_Np) + _Np...,
2 * sizeof...(_Np) + _Np...,
3 * sizeof...(_Np) + _Np...,
4 * sizeof...(_Np) + _Np...,
5 * sizeof...(_Np) + _Np...,
6 * sizeof...(_Np) + _Np...,
7 * sizeof...(_Np) + _Np...,
_Extra...> type;
};
template<size_t _Np> struct __parity;
template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
} // namespace detail
Накопипащенная параша из стандартной библиотеки плюсов для clang/llvm, имеющая отношение к реализации integer_sequence и tuple
https://github.com/llvm-mirror/libcxx/blob/191f075c6fe7440659781f2603088b2df337c06a/include/__tuple#L101-L139
https://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160627/163531.html
+1
void* createMap() {
mp = new Map(); //it's a global variable
return reinterpret_cast<void*> (new Map());
}
+1
SUM(
CAST (
SUBSTRING(CAST([PercentAmount] AS VARCHAR),1, CHARINDEX ('.',[PercentAmount])-1)
+ '.'
+ SUBSTRING(CAST([PercentAmount] AS VARCHAR),CHARINDEX('.',[PercentAmount])+1, 2+CHARINDEX ('.',[PercentAmount]))
AS MONEY))
А как вы достигаете точности в 2 знака после запятой?
+1
switch (DAEMONS_ENV) {
case "development": {
break;
}
case "staging": {
break;
}
case "production": {
break;
}
default: {
break;
}
}
+1
CoolIntf::GetInstance().DoSomething();
CoolIntf::GetInstance().DoSomethingElse();
CoolIntf::GetInstance().DoAnything()
для случая когда GetInstance() не инлайнится, кто-нибудь в крестах какое решение (без ручного введения временной переменной) для такого кода придумал?
единственное что нашел это вот это: https://stackoverflow.com/a/2279253 .
потому что "with" слишком общее слово которое в ж не гуглится.