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.

By Anonymous, 2019-12-07 11:59:58
function getJSType(cppType: string) {
    let typeMap = new Map<string, string>([
        ["Bool", "boolean"],
        ["Int32", "number"],
        ["UInt32", "number"],
        ["Int64", "number"],
        ["UInt64", "number"],
        ["Double", "number"],
        ["String", "string"],
        ["Object", "any"]
    ]);

    if (typeMap.get(cppType) === undefined) {
        console.error("Invalid type in getJavascriptType: " + cppType);
        process.exit(1);
    }
    return typeMap.get(cppType);
}
By Anonymous, 2017-12-15 11:58:04
  $(".alarmBell").on("click", () => {

    let icon = $(".alarm-bell__icon")
    icon.attr('data', icon.attr('data') == 'images/icon/alarm-bell.svg' ? 'images/icon/alarm-bell-filled-new.svg' : 'images/icon/alarm-bell.svg');

    // $(".alarm-bell__icon").attr('data', function (index, data) {
    //   if (data == 'images/icon/alarm-bell-filled-new.svg') {
    //     return 'images/icon/alarm-bell.svg';
    //   } else if (data == 'images/icon/alarm-bell.svg') {
    //     return 'images/icon/alarm-bell-filled-new.svg';
    //   } else {
    //     return 'images/icon/alarm-bell.svg';
    //   }
    // });

  });

...after yet another icons change request

By Desperate Dev..., 2020-01-21 17:28:18
<?php

$payload = '{ "products": [';
foreach ($products as $product) {
    $payload .= $product->toJson() . ',';
}
$payload = substr($payload, 0, \strlen($payload) - 1);
$payload .= ']}';
By sijolas, 2019-03-15 14:47:06
#1344 PHP +37
$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

By Anonymous, 2020-07-14 20:28:49

string date = user.RegistrationDate.ToShortDateString().ToString();
By Anonymous, 2019-02-13 14:51:41
from itertools import combinations as comb
from functools import reduce
  
def all_arrangements(k):
	m=k*(k+1)/2
	m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in comb(range(2*m+1),m)])
	return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on])

Returns all arrangements in the Bulgarian solitaire game with k piles https://en.wikipedia.org/wiki/Bulgarian_solitaire

By Uri Goren, 2017-12-13 11:48:22
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

By Anonymous, 2018-03-12 14:47:24
    self.isOptionsVisible = ko.computed(function() {
        if((self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

    self.isNameVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

    self.isBeforeAfterImagesVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

    self.isTooltipVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

    self.isLabelVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload') || (self.type() == 'info')) {
            return true;
        }

        return false;
    }, this);

    self.isClassVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

    self.isStyleVisible = ko.computed(function() {
        if((self.type() == 'text') || (self.type() == 'textarea') || (self.type() == 'select') || (self.type() == 'multiselect') || (self.type() == 'radio') || (self.type() == 'checkbox') || (self.type() == 'upload')) {
            return true;
        }

        return false;
    }, this);

object orientation overrated. let's check the fields in several places ...

By Dude, 2020-12-16 12:25:17
doit({txs, [Tx]}) ->
    X = tx_pool_feeder:absorb(Tx),
    Y = case X of
	    ok -> hash:doit(testnet_sign:data(Tx));
	    _ -> <<"error">>
		     end,
    {ok, Y};

In my opinion api response should be as confusing as possible. This method is used for sending tx into Amoveo blockchain. It returns ["ok", ] in success, and ["ok", <base64 encoded «error» word>] I hope I inspired you to make your code totally confusing and irrational.

By Zack Hess, 2019-01-24 12:19:04
$net_price = "var net_price = " . json_encode($net_price) . ";";

This is a Javascript variable being created inside of a PHP string.

By notmycode, 2017-12-12 16:47:24
if ((bool)greenButton.IsChecked)
{
    CurrentColor = Color.FromArgb(0xFF, 0x00, 0xCC, 0x00);
}
else if ((bool)greyButton.IsChecked)
{
    CurrentColor = Color.FromArgb(0xFF, 0x79, 0x79, 0x79);
}

foreach (var item in ItemsList.Items)
{
    if ((grid.Background as SolidColorBrush).Color == CurrentColor)
    {
        selectedItems.Add(item);
    }
}
By Anonymous, 2019-09-13 15:41:19
{k: v for d in [{ key: { 0: x[0], } for key in x["name"] } for x in items] for k, v in d.items()}
By nooooooo, 2018-01-02 14:54:31
$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
  ));
}
By Anonymous, 2018-01-16 10:56:13
$_POST = $this->db->mres($_POST);
$_SESSION['post'] = $_POST;

$sql = "SELECT id, documento, nombre1, nombre2, apellido1, apellido2 "
        . "FROM usuarios "
        . "WHERE " .
    "REPLACE(" .
        "REPLACE(" .
            "REPLACE(" .
                "REPLACE(telefono,' ','')," .
                "'(','')," .
            "')','')," .
        "'-','') LIKE '%{$searchTel}'";
By Carlos Correa, 2016-09-16 22:11:38