- 1
- 2
- 3
- 4
- 5
- 6
require(ggplot2)
x=-10:10
X = data.frame(x=x, y=x^2, col=ifelse(x > 0, 1, 2))
ggplot(X, aes(x, y)) + geom_point(aes(colour=col))
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
require(ggplot2)
x=-10:10
X = data.frame(x=x, y=x^2, col=ifelse(x > 0, 1, 2))
ggplot(X, aes(x, y)) + geom_point(aes(colour=col))
Очевидный и понятный интерфейс, да?
0
var object = {a: 123, b:"abc"};
var newObject = ko.observableProps(object);
newObject.a(345);
newObject.b("def");
newObject.a(); => 345
newObject.b(); => "def"
Ко-ко-ко-ко-ко-обсервабле
0
import math
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--type")
parser.add_argument("--principal", type=int)
parser.add_argument("--periods", type=int)
parser.add_argument("--interest", type=float)
parser.add_argument("--payment", type=float)
args = parser.parse_args()
choose = args.type
p = args.principal
n = args.periods
i = args.interest
a = args.payment
if i is None or p is None and a is None:
print("Incorrect parameters.")
exit(0)
i = (i * 0.01) / (12 * 1)
if choose == "diff":
m = 1
overpayment_all = 0
while m <= n:
d = math.ceil(p / n + i * (p - ((p * (m - 1)) / n)))
m += 1
overpayment_all += d
print(f"Month {m - 1}: payment is {d}")
print()
print(f"Overpayment = {overpayment_all - p}")
elif choose == "annuity" and a is None:
a = math.ceil(p * (i * math.pow((1 + i), n)) / (math.pow((1 + i), n) - 1))
print(f"Your monthly payment = {a}!")
over = a * n - p
print(f"Overpayment = {math.ceil(over)}")
elif choose == "annuity" and p is None:
p = int(a / (i * math.pow(1 + i, n) / (math.pow(1 + i, n) - 1)))
print(f"Your loan principal = {p}!")
m = 1
over = a * n - p
print(f"Overpayment = {math.ceil(over)}")
elif choose == "annuity":
n = math.ceil(math.log(a / (a - i * p), 1 + i))
zxc = math.ceil(math.log(a / (a - i * p), 1 + i))
years = 0
while n >= 12:
n -= 12
years += 1
if years == 0:
print(f"It will take {n} months to repay this loan!")
over = a * zxc - p
print(f"Overpayment = {math.ceil(over)}")
elif n == 0:
print(f"It will take {years} years to repay this loan!")
over = a * zxc - p
print(f"Overpayment = {math.ceil(over)}")
else:
print(f"It will take {years} years and {n} months to repay this loan!")
over = a * zxc - p
print(f"Overpayment = {math.ceil(over)}")
Ебучий универ и ебучее задание на питоне. Всё было бы збс, если бы не математика.
Прога считает проценты, бабки, переплаты и чёт ещё, наверное
0
var utils = require('util');
module.exports = class Client {
constructor(Socket) {
this.Socket = Socket;
this.TLSSocket = require('tls');
this.XmlParser = new require('xml2js').Parser();
this.XmlBuilder = require('xmlbuilder');
this.Client = this;
this.Authorized = false;
this.OnlineId = '1';
this.Socket.on('data', (Packet) => this.OnData(Packet));
this.Player = null;
this.Status = 0;
}
// Авторизация.
OnData(Packet) {
if (Packet[0] == 0xad || Packet[1] == 0xde || Packet[2] == 0xed || Packet[3] == 0xfe) {
var PacketBuffer = Buffer.alloc(Number(Packet.readBigInt64LE(4)));
Packet.copy(PacketBuffer, 0, 12);
var Query = PacketBuffer.toString();
console.log('[CLIENT] ',Query);
this.XmlParser.parseString(PacketBuffer.toString(), (err, result) => {
if (result)
{
if (result.starttls && !this.TLSSocket.Authorized && !this.Authorized) {
this.Send(this.XmlBuilder.create({
proceed: {
'@xmlns': 'urn:ietf:params:xml:ns:xmpp-tls'
}
}, {
headless: true
}).end({
pretty: false
}));
this.TLSSocket = new this.TLSSocket.TLSSocket(this.Socket, {
cert: global.Cert,
key: global.CertKey,
ca: global.CertBundle,
minVersion: 'TLSv1',
isServer: true
})
this.TLSSocket.once('secure', () => {
this.TLSSocket.Authorized = true;
console.log('TLS Connection established!');
});
this.TLSSocket.on('data', (Packet)=>this.OnData(Packet));
}
else if (result.iq && result.iq.bind) {
this.Send(this.XmlBuilder.create({
iq: {
'@id': result.iq.$.id,
'@type': 'result',
bind: {
'@xmlns': 'urn:ietf:params:xml:ns:xmpp-bind',
jid: this.OnlineId
}
}
}, {
headless: true
}).end({
pretty: false
}));
} else if (result.iq && result.iq.session) {
this.Send(this.XmlBuilder.create({
iq: {
'@id': result.iq.$.id,
'@type': 'result',
'@to': this.OnlineId,
session: {
'@xmlns': 'urn:ietf:params:xml:ns:xmpp-session'
}
}
}, {
headless: true
}).end({
pretty: false
}));
}
else if (result.iq && result.iq.query) {
var QueryName = Object.keys(result.iq.query[0]).filter(function (str) {
return str != '_' && str != '$'
})[0];
var QueryFunction = global.PacketFactory[QueryName];
if (QueryFunction) {
var Stanza = result.iq.query[0][QueryName][0];
console.log(`\x1b[32mQueryname: ${QueryName} ${utils.inspect(Stanza.$)}\x1b[0m`);
global.PacketFactory[QueryName].handle(this, Stanza, result.iq.$.to, result.iq.$.id);
}
Nodejs вход пользователя
0
// -------------------------------------------
// 2.2. binary calls
// -------------------------------------------
/*
combination table:
+- | c a n
---|-------
c | C A N
a | A A N
n | N N N
* | c a n
---|-------
c | C A N
a | A N N
n | N N N
/ | c a n
---|-------
c | C N N
a | A N N
n | N N N
argument:
c : constant, as scalar, point, tensor, ect
l : affine homogeneous expr argument: as field, field_indirect or field_expr_node::is_affine_homogeneous
n : function, functor or ! field_expr_node::is_affine_homogeneous
result:
C : constant : this combination is not implemented here
A,N : are implemented here
rules:
at least one of the two args is not of type "c"
when c: c value is embeded in bind_first or bind_second
and the operation reduces to an unary one
when a: if it is a field_convertible, it should be wrapped
in field_expr_v2_nonlinear_terminal_field
when c: no wrapper is need
implementation:
The a and n cases are grouped, thanks to the wrapper_traits
and it remains to cases :
1) both args are field_expr_v2_nonlinear or a function
2) one arg is a field_expr_v2_nonlinear or a function and the second argument is a constant
*/
#define _RHEOLEF_make_field_expr_v2_nonlinear_binary(FUNCTION,FUNCTOR) \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_field_expr_v2_nonlinear_arg<Expr1>::value \
&& details::is_field_expr_v2_nonlinear_arg<Expr2>::value \
&& ! details::is_field_expr_v2_constant <Expr1>::value \
&& ! details::is_field_expr_v2_constant <Expr2>::value \
,details::field_expr_v2_nonlinear_node_binary< \
FUNCTOR \
,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type \
,typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type \
> \
>::type \
FUNCTION (const Expr1& expr1, const Expr2& expr2) \
{ \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr1>::type wrap1_t; \
typedef typename details::field_expr_v2_nonlinear_terminal_wrapper_traits<Expr2>::type wrap2_t; \
return details::field_expr_v2_nonlinear_node_binary <FUNCTOR,wrap1_t,wrap2_t> \
(FUNCTOR(), wrap1_t(expr1), wrap2_t(expr2)); \
} \
template<class Expr1, class Expr2> \
inline \
typename \
std::enable_if< \
details::is_field_expr_v2_constant <Expr1>::value \
&& details::is_field_expr_v2_nonlinear_arg<Expr2>::value \
&& ! details::is_field_expr_v2_constant <Expr2>::value \
,details::field_expr_v2_nonlinear_node_unary< \
details::binder_first< \
FUNCTOR \
,typename details::field_promote_first_argument< \
Expr1
0
IT Оффтоп #80
#50: https://govnokod.ru/26804 https://govnokod.xyz/_26804
#51: https://govnokod.ru/26809 https://govnokod.xyz/_26809
#52: https://govnokod.ru/26817 https://govnokod.xyz/_26817
#53: https://govnokod.ru/26833 https://govnokod.xyz/_26833
#54: https://govnokod.ru/26840 https://govnokod.xyz/_26840
#55: https://govnokod.ru/26844 https://govnokod.xyz/_26844
#56: https://govnokod.ru/26862 https://govnokod.xyz/_26862
#57: https://govnokod.ru/26890 https://govnokod.xyz/_26890
#58: https://govnokod.ru/26916 https://govnokod.xyz/_26916
#59: https://govnokod.ru/26934 https://govnokod.xyz/_26934
#60: https://govnokod.ru/26949 https://govnokod.xyz/_26949
#61: https://govnokod.ru/26980 https://govnokod.xyz/_26980
#62: https://govnokod.ru/26999 https://govnokod.xyz/_26999
#63: https://govnokod.ru/27004 https://govnokod.xyz/_27004
#64: https://govnokod.ru/27020 https://govnokod.xyz/_27020
#65: https://govnokod.ru/27027 https://govnokod.xyz/_27027
#66: https://govnokod.ru/27040 https://govnokod.xyz/_27040
#67: https://govnokod.ru/27049 https://govnokod.xyz/_27049
#68: https://govnokod.ru/27061 https://govnokod.xyz/_27061
#69: https://govnokod.ru/27071 https://govnokod.xyz/_27071
#70: https://govnokod.ru/27097 https://govnokod.xyz/_27097
#71: https://govnokod.ru/27115 https://govnokod.xyz/_27115
#72: https://govnokod.ru/27120 https://govnokod.xyz/_27120
#73: https://govnokod.ru/27136 https://govnokod.xyz/_27136
#74: https://govnokod.ru/27160 https://govnokod.xyz/_27160
#75: https://govnokod.ru/27166 https://govnokod.xyz/_27166
#76: https://govnokod.ru/27168 https://govnokod.xyz/_27168
#77: https://govnokod.ru/27186 https://govnokod.xyz/_27186
#78: https://govnokod.ru/27219 https://govnokod.xyz/_27219
#79: https://govnokod.ru/27254 https://govnokod.xyz/_27254
0
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if($_POST['SESS_PARAM'] && $_POST['SESS_PARAM'] !='' && $_POST['SESS_PARAM_VALUE'] && $_POST['SESS_PARAM_VALUE'] !=''){
$_SESSION[$_POST['SESS_PARAM']] = $_POST['SESS_PARAM_VALUE'];
echo 'ok';
}else{
echo 'error';
}
утверждают что сайт им писали лучшие из лучших
0
$ find ~ -name .git -type d -prune -printf "***\n%p\n***\n" -exec git -C '{}/..' status \;
0
#include <iostream>
#include <ctime>
using namespace std;
#define SIZE 200000000
struct StackRazrivator {
int data[SIZE];
};
void razorvi() {
cout << "nachinau razrivat\n";
StackRazrivator r;
}
void razrivator() {
cout << "razrivator\n";
razorvi();
}
int main() {
cout << "start" << endl;
razrivator();
return 0;
}
Что выведет программа, если скомпилировать без оптимизаций и почему?
https://godbolt.org/z/75Yzer
+3
// https://deadlockempire.github.io/
// Игра, где надо играть за планировщик чтоб вызвать дедлок
// https://deadlockempire.github.io/#2-flags
// First Army
while (true) {
while (flag != false) {
;
}
flag = true;
critical_section();
flag = false;
}
// Second Army
while (true) {
while (flag != false) {
;
}
flag = true;
critical_section();
flag = false;
}
The day finally came. The Deadlock Empire opened its gates and from them surged massive amounts of soldiers, loyal servants of the evil Parallel Wizard. The Wizard has many strengths - his armies are fast, and he can do a lot of stuff that we can't. But now he set out to conquer the world, and we cannot have that.
You are our best Scheduler, commander! We have fewer troops and simpler ones, so we will need your help. Already two armies of the Deadlock Empire are approaching our border keeps. They are poorly equipped and poorly trained, however. You might be able to desync them and break their morale.