- 1
npm install
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+1
npm install
очередной npm пакет с трояном
https://www.bleepingcomputer.com/news/security/popular-coa-npm-library-hijacked-to-steal-user-passwords/
0
make_process_name("client", {Node,Key}) when is_atom(Node) ->
%% This function is going to be called enough to warrant a less pretty
%% process name in order to avoid calling costly functions
KeyStr = erlang:integer_to_list(erlang:phash2(Key)),
NodeStr = erlang:atom_to_list(Node),
erlang:list_to_atom("gen_rpc.client." ++ NodeStr ++ "/" ++ KeyStr);
Самый страшный грех, который только возможен в Erlang.
0
switch ($group) {
case 'Root':
break;
case 'Admin':
break;
case 'Accountant':
break;
case 'Manager':
break;
}
return $group;
Вот так можно проверить что ничего не надо делать
+1
// https://github.com/shanecoughlan/OpenGEM/blob/ac06b1a3fec3f3e8defcaaf7ea0338c38c3cef46/source/OpenGEM-7-RC3-SDK/OpenGEM-7-SDK/GEM%20AES%20AND%20SOURCE%20CODE/FreeGEM%20AES%203.0%20(source%20code)/GEMEVLIB.C#L143
/*
* Do a multi-wait on the specified events.
*/
WORD
ev_multi(flags, pmo1, pmo2, tmcount, buparm, mebuff, prets)
REG WORD flags;
REG MOBLK *pmo1;
MOBLK *pmo2;
LONG tmcount;
LONG buparm;
LPVOID mebuff;
WORD prets[];
{
QPB m;
REG EVSPEC which;
REG WORD what;
REG CQUEUE *pc;
#if MULTIAPP
WORD evbuff[8];
WORD pid;
SHELL *psh;
LONG ljunk;
pid = rlr->p_pid;
psh = &sh[pid];
if ( psh->sh_state & SHRINK ) /* shrink accessory */
{
if (pr_shrink(pid, TRUE, &ljunk, &ljunk))
ap_exit(TRUE); /* if no swap space terminate acc */
psh->sh_state &= ~SHRINK;
}
#endif
/* say nothing has */
/* happened yet */
what = 0x0;
/* do a pre-check for a */
/* keystroke & then */
/* clear out the forkq*/
chkkbd();
forker();
/* a keystroke */
if (flags & MU_KEYBD)
{
/* if a character is */
/* ready then get it */
pc = &rlr->p_cda->c_q;
if ( pc->c_cnt )
{
prets[4] = (UWORD) dq(pc);
what |= MU_KEYBD;
}
}
/* if we own the mouse */
/* then do quick chks */
if ( rlr == gl_mowner )
{
/* quick check button */
if (flags & MU_BUTTON)
{
if ( (mtrans > 1) &&
(downorup(pr_button, buparm)) )
{
what |= MU_BUTTON;
prets[5] = pr_mclick;
}
else
{
if ( downorup(button, buparm) )
{
what |= MU_BUTTON;
prets[5] = mclick;
}
}
}
/* quick check mouse rec*/
if ( ( flags & MU_M1 ) &&
( in_mrect(pmo1) ) )
what |= MU_M1;
/* quick check mouse rec*/
if ( ( flags & MU_M2 ) &&
( in_mrect(pmo2) ) )
what |= MU_M2;
}
/* quick check timer */
if (flags & MU_TIMER)
{
if ( tmcount == 0x0L )
what |= MU_TIMER;
}
/* quick check message */
if (flags & MU_MESAG)
{
if ( rlr->p_qindex > 0 )
{
#if MULTIAPP
ap_rdwr(MU_MESAG, rlr, 16, ADDR(&evbuff[0]) );
#endif
#if SINGLAPP
Уххх бля
0
int main(void)
{
std::string data = "HELLO WORLD!\n";
std::transform(
data.begin(), data.end(),
std::ostream_iterator<char>(std::cout, ""),
std::bind(std::plus<char>(), std::placeholders::_1, 1));
return 0;
}
А как сделать это ещё короче?
+1
// Define the module
define(function(require) {
// Require empty list error
var EmptyListError = require('../errors/property_errors').EmptyListError;
// Character-rank list class
function WeightedList(/* ...keys */) {
this._total = 0;
this._generateList.apply(this, arguments);
}
WeightedList.prototype._generateList = function() {
var collection;
if (typeof arguments[0] == 'object') {
collection = arguments[0];
} else {
collection = arguments;
}
for (var i = 0; i < collection.length; i++) {
this[collection[i]] = this[collection[i]] === undefined ? 1 : this[collection[i]] + 1;
this._total++;
}
}
WeightedList.prototype.getRandomKey = function() {
if (this._total < 1)
throw new EmptyListError();
var num = Math.random();
var lowerBound = 0;
var keys = Object.keys(this);
for (var i = 0; i < keys.length; i++) {
if (keys[i] != "_total") {
if (num < lowerBound + this[keys[i]] / this._total) {
return keys[i];
}
lowerBound += this[keys[i]] / this._total;
}
}
return keys[keys.length - 1];
};
WeightedList.prototype.increaseRank = function(key) {
if (key !== undefined && key != "_total") {
if (this[key] !== undefined) {
this[key]++;
} else {
this[key] = 1;
}
this._total++;
}
};
WeightedList.prototype.clearRanks = function() {
var keys = Object.keys(this);
for (var i = 0; i < keys.length; i++) {
if (keys[i] != "_total") {
this._total -= this[keys[i]] - 1;
this[keys[i]] = 1;
}
}
};
return WeightedList;
});
Вот почему я за четкое разделение объектов/структур и хэшей (ассоциативных массивов).
0
function f1()
{
print("Hello World!");
}
function run(f: () => void)
{
f();
}
function main() {
const x = f1;
x();
run(x);
}
// LLVM IL
; 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_11208736881023205110 = internal constant [14 x i8] c"Hello World!\00\00"
declare i8* @malloc(i64)
declare void @free(i8*)
declare i32 @printf(i8*, ...)
define void @f1() !dbg !3 {
%1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @frmt_11120820245497078329, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @s_11208736881023205110, i64 0, i64 0)), !dbg !7
br label %2, !dbg !9
2: ; preds = %0
ret void, !dbg !9
}
define void @run(void ()* %0) !dbg !10 {
%2 = alloca void ()*, align 8, !dbg !11
store void ()* %0, void ()** %2, align 8, !dbg !11
%3 = load void ()*, void ()** %2, align 8, !dbg !11
call void %3(), !dbg !13
br label %4, !dbg !14
4: ; preds = %1
ret void, !dbg !14
}
define void @main() !dbg !15 {
%1 = alloca void ()*, align 8, !dbg !16
%2 = alloca void ()*, align 8, !dbg !19
store void ()* @f1, void ()** %2, align 8, !dbg !19
%3 = load void ()*, void ()** %2, align 8, !dbg !19
call void %3(), !dbg !20
%4 = load void ()*, void ()** %2, align 8, !dbg !19
%5 = bitcast void ()** %1 to i8*, !dbg !16
call void @llvm.lifetime.start.p0i8(i64 8, i8* %5), !dbg !16
store void ()* %4, void ()** %1, align 8, !dbg !16
%6 = load void ()*, void ()** %1, align 8, !dbg !16
call void %6(), !dbg !21
%7 = bitcast void ()** %1 to i8*, !dbg !22
call void @llvm.lifetime.end.p0i8(i64 8, i8* %7), !dbg !22
br label %8, !dbg !23
8: ; preds = %0
ret void, !dbg !23
}
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
; Function Attrs: argmemonly nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
attributes #0 = { argmemonly nofree nosync nounwind willreturn }
продолжаем говнокодить компилятор аля TypeScript в нативный код. ну это как С компилятор только без тупо-уродо-* у имен переменных
1) компилим точно также как и до этого в постах
2) получаем результат
>> Hello World!
Hello World!
+1
there are java.io.FileNotFoundException and java.nio.file.NoSuchFileException . Both are subclasses of IOException, neither of them is a subclass of the opposite.
+1
// если пользователь авторизован
if($user->get('id')) {
$_SESSION['city-select'] = '';
// если пользователь авторизован - определяем город
$profile = $user->getOne('Profile');
if ($profile) {
$city = $profile->get('city');
}
// проходим все города и ищем подходящий
$cities = $modx->runSnippet('pdoResources', array(
'parents' => 205,
'limit' => 0,
'includeTVs' => 'setCityForHome',
'where' => '{ "template" : "25" }',
'tpl' => '@CODE:{"id":"[[+id]]","city":"[[+tv.setCityForHome]]"}',
'outputSeparator' => ','
));
$redirectTo = 0;
if($cities) {
$cities = $modx->fromJson('['.$cities.']');
foreach( $cities as $c ) {
if($c['city'] == $city) {
$redirectTo = $c['id'];
break;
}
}
}
} else {
// если не авторизован - проверяем сессию
$session = $_SESSION['city-select'];
// если сессия пустая - проверяем, на какой странице находимся
// если страница города и пустая сессия - записываем в сессию
if($modx->resource->get('template') == 25) {
$_SESSION['city-select'] = $modx->resource->get('pagetitle');
$city = $modx->resource->get('pagetitle');
} else {
$city = (!empty($_SESSION['city-select']))? $_SESSION['city-select'] : $city;
}
}
Сумрачный гений, сука. Строки 11-28 особенно примечательны.
+1
namespace detail {
template<entity_event_t Event>
struct EventHasEntityStateConstructor {
// Sanity check
static_assert(static_cast<int32_t>(Event) >= 0
&& static_cast<int32_t>(Event) < ENTITY_EVENTS_COUNT);
private:
struct TwoChar {
char a, b;
};
template<typename T>
constexpr static TwoChar _check(
decltype(
T(std::declval<const entityState_t &>())
)*
);
template<typename T>
constexpr static char _check(...);
public:
constexpr inline static bool value = (sizeof(_check<EntityEvent<Event>>(nullptr)) == sizeof(TwoChar));
};
template<typename BusT, entity_event_t Event>
bool defaultEntityEventPublisher(const BusT & bus, const entityState_t & eventEntity)
{
static_assert(EventHasEntityStateConstructor<Event>::value,
"defaultEntityEventFactory<Event>() instantiated for a custom\n"
"event that does not have a (const entityState_t & eventEntity) constructor.\n"
"This should not happen (you'll get a more obscured compiler error anyway)!");
return bus.publishEmplace<EntityEvent<Event>>(eventEntity);
}
template<typename BusT, typename T, T... Is>
constexpr std::array<EntityEventPublisherPtr<BusT>, sizeof...(Is)>
createDefaultEntityEventFactories(std::integer_sequence<T, Is...>)
{
return {
[](auto i) -> EntityEventPublisherPtr<BusT> {
if constexpr (EventHasEntityStateConstructor<static_cast<entity_event_t>(i.value)>::value) {
return &defaultEntityEventPublisher<BusT, static_cast<entity_event_t>(i.value)>;
} else {
return nullptr;
}
}(std::integral_constant<T, Is>{})...
};
}
}
// An (event_number -> EntityState<event_number> 'publishing factory' function) mapping;
// if event N could not be constructed from a single entityState_t reference
// then this table would contain nullptr at the index N
template<typename BusT>
const std::array<EntityEventPublisherPtr<BusT>, ENTITY_EVENTS_COUNT> & getDefaultEntityEventsPublishers() noexcept
{
static auto factories = detail::createDefaultEntityEventFactories<BusT>(std::make_integer_sequence<int32_t, ENTITY_EVENTS_COUNT>());
return factories;
}
template<typename BusT>
EntityEventPublisherPtr<BusT> tryGetDefaultEntityEventPublisher(entity_event_t event) noexcept
{
auto eventNum = static_cast<int32_t>(event);
if (eventNum >= 0 && eventNum < ENTITY_EVENTS_COUNT) {
return getDefaultEntityEventsPublishers<BusT>()[eventNum];
} else {
return nullptr;
}
}