typedef signed int sint;
#define N 100
static int n = N;
inline int f(const int n, int& i, int* j, int t[2], int p=11)
{
i*=i;
(*j)--;
if ( n<=0 )
{
cout << ::n << ">\n";
return t[0];
}
else return f(n-1, i, j, t) + t[n];
}
int main()
{
int n = 4;
int x = 1U;
sint y = 10;
int (*fptr)(const int, int&, int*, int*, int) = f;
int* t = new int[n];
int& r = *(t+3);
(*t) = 1;
*(t+1) = 2;
t[2] = 3;
r = 4;
int z = (*fptr)(5, x, &y, t, 12);
for(int i = 0; i < 2*n; i++)
{
if( i == n )
continue;
if( i > n )
break;
cout << t[i] << "\n";
};
cout << x << ", " << y << ", " << z << "\n";
delete[] t;
}
This is what my professor gave as part of the final exam. The purpose of giving us this code was to get us used to seeing different ways the C++ syntax can be used and figure out what the output is.
public showOrHideLegends(seriesList: any[]) {
if (seriesList.length === 0)
return false;
else
return true;
}
more code lines => more money; that's how our contractor company thinks
.stepper a{
}
.stepper>div>div>div>div>a{
color: transparent !important;
}
stepper>div>div>div>div>span{
color: transparent !important;
}
.stepper>div>div>div:nth-child(1)>div>a:after, .stepper>div>div>div:nth-child(1)>div>span:after{
color: rgb(52, 58, 64);
content: '4' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(2)>div>a:after{
color: rgb(52, 58, 64);
content: '3' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(3)>div>a:after{
color: rgb(52, 58, 64);
content: '2' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(4)>div>a:after{
color: rgb(52, 58, 64);
content: '1' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(4)>div>span:after{
color: rgb(52, 58, 64);
background-color: rgb(108, 117, 125);
content: '1' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(3)>div>span:after{
color: rgb(52, 58, 64);
background-color: rgb(108, 117, 125);
content: '2' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(2)>div>span:after{
color: rgb(52, 58, 64);
background-color: rgb(108, 117, 125);
content: '3' !important;
margin-left: -10px;
}
.stepper>div>div>div:nth-child(1)>div>span:after{
color: rgb(52, 58, 64);
background-color: rgb(108, 117, 125);
content: '4' !important;
margin-left: -10px;
}
'use strict'
// exports //
module.exports = Math.sqrt
var None = null;
if ({{ post.pk }} == None) {
// reset to draft
$("#id_status")[0].value = 1;
}
[HttpPost]
[Route("validaPrepacks")]
public IHttpActionResult ValidaPrepacks(ValidaPrepackVO validacion)
{
try
{
return Ok();
}
catch (Exception e)
{
return Ok(e.Message);
}
}
A code that "validate" a pack in the backend
const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
function showItem(index) {
visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
visibleItems[index] = true
}
It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.
const handleBoolean = value => {
switch (value) {
case "true":
return true;
case true:
return "true";
case "false":
return false;
case false:
return "false"
default:
return null;
}
}
<?php
public function parse($package)
{
if(isset($package["type"]) && $package["type"] == "unavailable")
{
if(((time() - self::$xmpp->users[(string)$package["from"]]["jointime"] < 30 && (isset(self::$xmpp->users[(string)$package["from"]]["messages"]) && self::$xmpp->users[(string)$package["from"]]["messages"] < 2) && (time() - self::$xmpp->startTime) > 50)) || (!isset(self::$xmpp->users[(string)$package["from"]]["messages"]) && time() - self::$xmpp->users[(string)$package["from"]]["jointime"] < 900 && (time() - self::$xmpp->startTime) > 900))
{
if(!array_search(strstr(self::$xmpp->users[(string)$package["from"]]["jid"], "/", true), explode("\n", file_get_contents("friends.txt"))))
{
self::$xmpp->ban(strstr($package["from"], "/", true), self::$xmpp->users[(string)$package["from"]]["jid"]);
self::$xmpp->groupMessage(strstr($package["from"], "/", true), substr(strstr($package["from"], "/"), 1)." został zbanowany/a za przeciąg!");
}
}
else
if(!array_search(strstr(self::$xmpp->users[(string)$package["from"]]["jid"], "/", true), explode("\n", file_get_contents("friends.txt"))))
file_put_contents("friends.txt", file_get_contents("friends.txt")."\n".strstr(self::$xmpp->users[(string)$package["from"]]["jid"], "/", true));
}
}
In fact whole project is shitty as hell, if you want have some fun grab popcorn and read all the sources: XPBot on sourceforge
$command = 'curl -X GET -H "application/json" -H "X-Api-Key: '.$key.'" https://some-api.com/resource';
exec($command, $output);
$array = json_decode($output[0], true);
Using curl in PHP is boring. Let execute a command for
.black {
color: #000;
}
.not-black {
color: #999;
}
function IsAOrB(const p_Id: string): boolean;
begin
if ((p_Id = 'A') or (p_Id = 'B')) then begin
Result := true;
Exit;
end;
Result := false;
end;
Result := ((p_Id = 'A') or (p_Id = 'B'));
That would have been enough. But this also features Exit and an asymmetrical if.
boolean darkModeSelected = (!darkModeSelected ? true : false);
$config = Config::getConfig('common');
$contract_carriers = $config[$market . "_" . $clearing . '_contract_carriers']; // f**ing php array
$interline_carriers = $config[$market . "_" . $clearing . '_interline_carriers']; // another f**ing array
// $marketing_carriers - is also array
$sets = [];
foreach ($marketing_carriers as $mc) {
$sets[] = array_unique(array_intersect(
array_merge(
[$mc],
array_intersect(
isset(self::$interlines[$mc]) ? self::$interlines[$mc] : [],
array_merge(
$marketing_carriers,
$interline_carriers
)
)
),
$contract_carriers
));
}
in_array($this->market, ["ru"])
There is an old mysterious legend, which says that those conditions are lightening fast which are using in_array($source, ["target"]) instead of just "==". Is says always that probably you never do code refactoring, and keep all shit alive